LuaFunctions.cpp 412 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461
  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. safe_delete(item);
  829. }
  830. lua_interface->ResetFunctionStack(state);
  831. return 0;
  832. }
  833. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  834. if (!lua_interface)
  835. return 0;
  836. Spawn* spawn = lua_interface->GetSpawn(state);
  837. if (spawn) {
  838. int32 val = lua_interface->GetInt32Value(state, 2);
  839. spawn->AddLootCoins(val);
  840. }
  841. lua_interface->ResetFunctionStack(state);
  842. return 0;
  843. }
  844. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  845. if (!lua_interface)
  846. return 0;
  847. Spawn* entity = lua_interface->GetSpawn(state);
  848. Spawn* player = lua_interface->GetSpawn(state, 2);
  849. if (entity && player && player->IsPlayer()) {
  850. int32 coins = lua_interface->GetInt32Value(state, 3);
  851. vector<Item*>* items = 0;
  852. int i = 0;
  853. int32 item_id = 0;
  854. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  855. if (items == 0)
  856. items = new vector<Item*>;
  857. if (master_item_list.GetItem(item_id))
  858. items->push_back(master_item_list.GetItem(item_id));
  859. i++;
  860. }
  861. Client* client = 0;
  862. client = ((Player*)player)->GetClient();
  863. if (client)
  864. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  865. if(coins > 0)
  866. entity->AddLootCoins(coins);
  867. safe_delete(items);
  868. }
  869. lua_interface->ResetFunctionStack(state);
  870. return 0;
  871. }
  872. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  873. if (!lua_interface)
  874. return 0;
  875. Spawn* entity = lua_interface->GetSpawn(state);
  876. Spawn* player = lua_interface->GetSpawn(state, 2);
  877. int32 item_id = lua_interface->GetInt32Value(state, 3);
  878. lua_interface->ResetFunctionStack(state);
  879. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  880. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  881. return 1;
  882. }
  883. return 0;
  884. }
  885. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  886. if (!lua_interface)
  887. return 0;
  888. Spawn* entity = lua_interface->GetSpawn(state);
  889. Spawn* player = lua_interface->GetSpawn(state, 2);
  890. lua_interface->ResetFunctionStack(state);
  891. if (entity && player && player->IsPlayer()) {
  892. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  893. return 1;
  894. }
  895. return 0;
  896. }
  897. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  898. if (!lua_interface)
  899. return 0;
  900. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = ((Player*)player)->GetClient();
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = ((Player*)player)->GetClient();
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = ((Player*)player)->GetClient();
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. safe_delete(conversation);
  994. lua_interface->SetConversationValue(state, NULL);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = ((Player*)player)->GetClient();
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. safe_delete(conversation);
  1020. lua_interface->SetConversationValue(state, NULL);
  1021. }
  1022. else
  1023. 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);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = ((Player*)player)->GetClient();
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = ((Player*)player)->GetClient();
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = ((Player*)player)->GetClient();
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = ((Player*)player)->GetClient();
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. return 0;
  1247. }
  1248. Spawn* caster = luaspell->caster;
  1249. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1250. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1251. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1252. Spawn* target = lua_interface->GetSpawn(state, 4);
  1253. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1254. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1255. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1256. lua_interface->ResetFunctionStack(state);
  1257. boost::to_lower(heal_type);
  1258. if (caster && caster->IsEntity()) {
  1259. bool success = false;
  1260. luaspell->resisted = false;
  1261. if (target) {
  1262. float distance = caster->GetDistance(target, true);
  1263. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1264. success = true;
  1265. }
  1266. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1267. Spawn* target = 0;
  1268. ZoneServer* zone = luaspell->caster->GetZone();
  1269. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1270. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1271. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1272. float distance = caster->GetDistance(target, true);
  1273. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1274. }
  1275. }
  1276. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1277. success = true;
  1278. }
  1279. if (success) {
  1280. if (caster->GetZone())
  1281. caster->GetZone()->TriggerCharSheetTimer();
  1282. }
  1283. }
  1284. return 0;
  1285. }
  1286. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1287. if (!lua_interface)
  1288. return 0;
  1289. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1290. if(!luaspell || luaspell->resisted) {
  1291. return 0;
  1292. }
  1293. Spawn* caster = luaspell->caster;
  1294. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1295. float percentage = lua_interface->GetFloatValue(state, 2);
  1296. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1297. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1298. Spawn* target = lua_interface->GetSpawn(state, 5);
  1299. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1300. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1301. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1302. lua_interface->ResetFunctionStack(state);
  1303. boost::to_lower(heal_type);
  1304. int32 min_heal = 0, max_heal = 0;
  1305. if (caster && caster->IsEntity() && target) {
  1306. if(percentage <= 0.0f)
  1307. {
  1308. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1309. return 0;
  1310. }
  1311. if(heal_type == "power")
  1312. {
  1313. if(current_value)
  1314. {
  1315. if(caster_value)
  1316. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1317. else
  1318. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1319. }
  1320. else
  1321. {
  1322. if(caster_value)
  1323. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1324. else
  1325. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1326. }
  1327. }
  1328. else
  1329. {
  1330. if(current_value)
  1331. {
  1332. if(caster_value)
  1333. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1334. else
  1335. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1336. }
  1337. else
  1338. {
  1339. if(caster_value)
  1340. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1341. else
  1342. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1343. }
  1344. }
  1345. bool success = false;
  1346. luaspell->resisted = false;
  1347. if (target) {
  1348. float distance = caster->GetDistance(target, true);
  1349. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1350. success = true;
  1351. }
  1352. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1353. Spawn* target = 0;
  1354. ZoneServer* zone = luaspell->caster->GetZone();
  1355. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1356. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1357. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1358. float distance = caster->GetDistance(target, true);
  1359. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1360. }
  1361. }
  1362. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1363. success = true;
  1364. }
  1365. if (success) {
  1366. if (caster->GetZone())
  1367. caster->GetZone()->TriggerCharSheetTimer();
  1368. }
  1369. }
  1370. return 0;
  1371. }
  1372. int EQ2Emu_lua_AddItem(lua_State* state) {
  1373. if (!lua_interface)
  1374. return 0;
  1375. Spawn* spawn = lua_interface->GetSpawn(state);
  1376. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1377. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1378. lua_interface->ResetFunctionStack(state);
  1379. // default of 1 quantity to add
  1380. if (quantity == 0)
  1381. quantity = 1;
  1382. if (spawn && spawn->IsPlayer()) {
  1383. Client* client = ((Player*)spawn)->GetClient();
  1384. if (client && item_id > 0) {
  1385. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1386. return 1;
  1387. }
  1388. }
  1389. lua_interface->SetBooleanValue(state, false);
  1390. return 1;
  1391. }
  1392. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1393. if (!lua_interface)
  1394. return 0;
  1395. Spawn* spawn = lua_interface->GetSpawn(state);
  1396. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1397. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1398. string location = lua_interface->GetStringValue(state, 4);
  1399. int16 item_count = lua_interface->GetInt16Value(state,5);
  1400. //devn00b: if we dont have a count, assume 1 item.
  1401. if(!item_count) {
  1402. item_count = 1;
  1403. }
  1404. lua_interface->ResetFunctionStack(state);
  1405. if (spawn && spawn->IsPlayer()) {
  1406. Client* client = ((Player*)spawn)->GetClient();
  1407. if (client && item_id > 0) {
  1408. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1409. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1410. else
  1411. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1412. if (send_messages) {
  1413. Item* item = master_item_list.GetItem(item_id);
  1414. if (item) {
  1415. if(item_count > 1) {
  1416. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1417. string popup_text1 = "You receive "+ item_count;
  1418. string popup_text2 = " " + item->name;
  1419. string popup_text = popup_text1 + popup_text2;
  1420. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1421. // return 1;
  1422. } else {
  1423. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1424. string popup_text = "You receive " + item->name;
  1425. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1426. }
  1427. }
  1428. }
  1429. return 1;
  1430. }
  1431. }
  1432. lua_interface->SetBooleanValue(state, false);
  1433. return 1;
  1434. }
  1435. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1436. Spawn* spawn = lua_interface->GetSpawn(state);
  1437. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1438. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1439. lua_interface->ResetFunctionStack(state);
  1440. // default of 1 to remove
  1441. if (quantity == 0)
  1442. quantity = 1;
  1443. Client* client;
  1444. Item* item;
  1445. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1446. if ((client = ((Player*)spawn)->GetClient())) {
  1447. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1448. if (client->RemoveItem(item, quantity)) {
  1449. lua_interface->SetBooleanValue(state, true);
  1450. return 1;
  1451. }
  1452. }
  1453. }
  1454. }
  1455. lua_interface->SetBooleanValue(state, false);
  1456. return 1;
  1457. }
  1458. int EQ2Emu_lua_HasItem(lua_State* state) {
  1459. Spawn* player = lua_interface->GetSpawn(state);
  1460. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1461. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1462. lua_interface->ResetFunctionStack(state);
  1463. if (player && player->IsPlayer()) {
  1464. bool hasItem = false;
  1465. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1466. if (!hasItem)
  1467. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1468. lua_interface->SetBooleanValue(state, hasItem);
  1469. return 1;
  1470. }
  1471. lua_interface->SetBooleanValue(state, false);
  1472. return 1;
  1473. }
  1474. int EQ2Emu_lua_Spawn(lua_State* state) {
  1475. if (!lua_interface)
  1476. return 0;
  1477. ZoneServer* zone = lua_interface->GetZone(state);
  1478. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1479. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1480. float x = lua_interface->GetFloatValue(state, 4);
  1481. float y = lua_interface->GetFloatValue(state, 5);
  1482. float z = lua_interface->GetFloatValue(state, 6);
  1483. float heading = lua_interface->GetFloatValue(state, 7);
  1484. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1485. Spawn* spawn = zone->GetSpawn(spawn_id);
  1486. if (!spawn)
  1487. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1488. else {
  1489. spawn->SetX(x);
  1490. spawn->SetZ(z);
  1491. spawn->SetY(y,true,true);
  1492. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1493. spawn->SetHeading(heading);
  1494. if (restricted_npc)
  1495. spawn->AddAllowAccessSpawn(spawn);
  1496. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1497. bool scriptActive = false;
  1498. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1499. scriptActive = true;
  1500. spawn->SetSpawnScript(string(spawn_script));
  1501. }
  1502. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1503. zone->AddSpawn(spawn);
  1504. if (scriptActive) {
  1505. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1506. }
  1507. lua_interface->ResetFunctionStack(state);
  1508. lua_interface->SetSpawnValue(state, spawn);
  1509. return 1;
  1510. }
  1511. }
  1512. else {
  1513. string output = "Invalid paramaters to LUA Spawn command: \n";
  1514. if (!zone)
  1515. output = output.append("\t").append("Missing zone reference. \n");
  1516. if (spawn_id == 0)
  1517. output = output.append("\t").append("Missing spawn_id.");
  1518. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1519. }
  1520. lua_interface->ResetFunctionStack(state);
  1521. return 0;
  1522. }
  1523. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1524. if (!lua_interface)
  1525. return 0;
  1526. ZoneServer* zone = lua_interface->GetZone(state);
  1527. lua_interface->ResetFunctionStack(state);
  1528. if (zone) {
  1529. lua_interface->SetStringValue(state, zone->GetZoneName());
  1530. return 1;
  1531. }
  1532. return 0;
  1533. }
  1534. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1535. if (!lua_interface)
  1536. return 0;
  1537. ZoneServer* zone = lua_interface->GetZone(state);
  1538. lua_interface->ResetFunctionStack(state);
  1539. if (zone) {
  1540. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1541. return 1;
  1542. }
  1543. return 0;
  1544. }
  1545. int EQ2Emu_lua_GetZone(lua_State* state) {
  1546. if (!lua_interface)
  1547. return 0;
  1548. int32 zone_id = lua_interface->GetInt32Value(state);
  1549. ZoneServer* zone = 0;
  1550. if (zone_id > 0)
  1551. zone = zone_list.Get(zone_id);
  1552. else {
  1553. string zone_name = lua_interface->GetStringValue(state);
  1554. if (zone_name.length() > 0) {
  1555. zone = zone_list.Get(zone_name.c_str());
  1556. }
  1557. else {
  1558. Spawn* spawn = lua_interface->GetSpawn(state);
  1559. if (spawn)
  1560. zone = spawn->GetZone();
  1561. }
  1562. }
  1563. lua_interface->ResetFunctionStack(state);
  1564. if (zone) {
  1565. lua_interface->SetZoneValue(state, zone);
  1566. return 1;
  1567. }
  1568. return 0;
  1569. }
  1570. int EQ2Emu_lua_AddHate(lua_State* state) {
  1571. Spawn* entity = lua_interface->GetSpawn(state);
  1572. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1573. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1574. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1575. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1576. if(!luaspell || luaspell->resisted) {
  1577. return 0;
  1578. }
  1579. if (entity && entity->IsEntity() && amount != 0) {
  1580. if (luaspell) {
  1581. ZoneServer* zone = luaspell->caster->GetZone();
  1582. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1583. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1584. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1585. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1586. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1587. if (send_packet)
  1588. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1589. }
  1590. }
  1591. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1592. }
  1593. else if (npc && npc->IsNPC() && npc->GetZone())
  1594. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1595. }
  1596. lua_interface->ResetFunctionStack(state);
  1597. return 0;
  1598. }
  1599. int EQ2Emu_lua_Zone(lua_State* state) {
  1600. if (!lua_interface)
  1601. return 0;
  1602. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1603. ZoneServer* zone = lua_interface->GetZone(state);
  1604. Spawn* player = lua_interface->GetSpawn(state, 2);
  1605. Client* client = 0;
  1606. if (player && player->IsPlayer())
  1607. client = ((Player*)player)->GetClient();
  1608. float x = lua_interface->GetFloatValue(state, 3);
  1609. float y = lua_interface->GetFloatValue(state, 4);
  1610. float z = lua_interface->GetFloatValue(state, 5);
  1611. float heading = lua_interface->GetFloatValue(state, 6);
  1612. if (zone && client) {
  1613. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1614. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1615. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1616. {
  1617. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1618. return 0;
  1619. }
  1620. if (x != 0 || y != 0 || z != 0) {
  1621. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1622. player->SetX(x);
  1623. player->SetY(y);
  1624. player->SetZ(z);
  1625. player->SetHeading(heading);
  1626. client->Zone(zone->GetZoneName(), false);
  1627. }
  1628. else
  1629. client->Zone(zone->GetZoneName());
  1630. }
  1631. else
  1632. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1633. lua_interface->ResetFunctionStack(state);
  1634. return 0;
  1635. }
  1636. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1637. if (!lua_interface)
  1638. return 0;
  1639. Spawn* spawn = lua_interface->GetSpawn(state);
  1640. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1641. if (spawn && spawn2)
  1642. spawn->AddAllowAccessSpawn(spawn2);
  1643. lua_interface->ResetFunctionStack(state);
  1644. return 0;
  1645. }
  1646. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1647. if (!lua_interface)
  1648. return 0;
  1649. Spawn* target = lua_interface->GetSpawn(state);
  1650. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1651. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1652. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1653. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1654. lua_interface->ResetFunctionStack(state);
  1655. if (!target) {
  1656. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1657. return 0;
  1658. }
  1659. if (!target->IsEntity()) {
  1660. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1661. return 0;
  1662. }
  1663. if (spell_id <= 0) {
  1664. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1665. return 0;
  1666. }
  1667. if (caster && !caster->IsEntity()) {
  1668. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1669. return 0;
  1670. }
  1671. if (spell_tier == 0)
  1672. spell_tier = 1;
  1673. if (!caster)
  1674. caster = target;
  1675. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1676. return 0;
  1677. }
  1678. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1679. if (!lua_interface)
  1680. return 0;
  1681. Spawn* target = lua_interface->GetSpawn(state);
  1682. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1683. if(!luaspell || luaspell->resisted) {
  1684. return 0;
  1685. }
  1686. Spawn* caster = luaspell->caster;
  1687. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1688. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1689. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1690. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1691. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1692. //lua_interface->ResetFunctionStack(state);
  1693. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1694. vector<int16> faction_req;
  1695. vector<int16> race_req;
  1696. int32 class_req = 0;
  1697. int32 i = 0;
  1698. int8 f = 0;
  1699. int8 r = 0;
  1700. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1701. if (class_id < 100) {
  1702. class_req += pow(2.0, double(class_id - 1));
  1703. }
  1704. else if (class_id > 100 && class_id < 1000) {
  1705. race_req.push_back(class_id);
  1706. r++;
  1707. }
  1708. else {
  1709. faction_req.push_back(class_id);
  1710. f++;
  1711. }
  1712. i++;
  1713. }
  1714. lua_interface->ResetFunctionStack(state);
  1715. if (caster && caster->IsEntity()) {
  1716. bool race_match = false;
  1717. bool success = false;
  1718. luaspell->resisted = false;
  1719. if (luaspell->targets.size() > 0) {
  1720. ZoneServer* zone = luaspell->caster->GetZone();
  1721. Spawn* target = 0;
  1722. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1723. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1724. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1725. if (race_req.size() > 0) {
  1726. for (int8 i = 0; i < race_req.size(); i++) {
  1727. if(race_req[i] == target->GetRace() ||
  1728. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1729. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1730. race_match = true;
  1731. }
  1732. }
  1733. }
  1734. else
  1735. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1736. if (race_match == true) {
  1737. float distance = caster->GetDistance(target, true);
  1738. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1739. }
  1740. }
  1741. }
  1742. success = true;
  1743. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1744. }
  1745. else if (target) {
  1746. //check class and race/faction here
  1747. if (race_req.size() > 0) {
  1748. for (int8 i = 0; i < race_req.size(); i++) {
  1749. if(race_req[i] == target->GetRace() ||
  1750. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1751. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1752. race_match = true;
  1753. }
  1754. }
  1755. }
  1756. else
  1757. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1758. if (race_match == true) {
  1759. float distance = caster->GetDistance(target, true);
  1760. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1761. success = true;
  1762. }
  1763. }
  1764. if (success) {
  1765. Spell* spell = luaspell->spell;
  1766. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1767. ((Player*)caster)->InCombat(true);
  1768. if (caster->GetZone())
  1769. caster->GetZone()->TriggerCharSheetTimer();
  1770. }
  1771. }
  1772. }
  1773. return 0;
  1774. }
  1775. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1776. if (!lua_interface)
  1777. return 0;
  1778. Spawn* spawn = lua_interface->GetSpawn(state);
  1779. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1780. lua_interface->ResetFunctionStack(state);
  1781. if (spawn && value != 0) {
  1782. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1783. spawn->SetPower(spawn->GetTotalPower());
  1784. else
  1785. spawn->SetPower(spawn->GetPower() + value);
  1786. }
  1787. return 0;
  1788. }
  1789. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1790. if (!lua_interface)
  1791. return 0;
  1792. Spawn* spawn = lua_interface->GetSpawn(state);
  1793. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1794. lua_interface->ResetFunctionStack(state);
  1795. if (spawn && value != 0) {
  1796. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1797. spawn->SetHP(spawn->GetTotalHP());
  1798. else
  1799. spawn->SetHP(spawn->GetHP() + value);
  1800. }
  1801. return 0;
  1802. }
  1803. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1804. if (!lua_interface)
  1805. return 0;
  1806. Spawn* spawn = lua_interface->GetSpawn(state);
  1807. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1808. lua_interface->ResetFunctionStack(state);
  1809. if (spawn && value != 0) {
  1810. spawn->SetPower(spawn->GetPower() + value);
  1811. if (value > spawn->GetTotalHPBase())
  1812. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1813. }
  1814. return 0;
  1815. }
  1816. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1817. if (!lua_interface)
  1818. return 0;
  1819. Spawn* spawn = lua_interface->GetSpawn(state);
  1820. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1821. lua_interface->ResetFunctionStack(state);
  1822. if (spawn && value != 0) {
  1823. spawn->SetHP(spawn->GetHP() + value);
  1824. if (value > spawn->GetTotalHPBase())
  1825. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1826. }
  1827. return 0;
  1828. }
  1829. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1830. if (!lua_interface)
  1831. return 0;
  1832. Spawn* spawn = lua_interface->GetSpawn(state);
  1833. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1834. lua_interface->ResetFunctionStack(state);
  1835. if (spawn) {
  1836. spawn->SetHP(value);
  1837. if (value > spawn->GetTotalHPBase())
  1838. spawn->SetTotalHP(value);
  1839. }
  1840. return 0;
  1841. }
  1842. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1843. if (!lua_interface)
  1844. return 0;
  1845. Spawn* spawn = lua_interface->GetSpawn(state);
  1846. float value = lua_interface->GetFloatValue(state, 2);
  1847. lua_interface->ResetFunctionStack(state);
  1848. if (spawn && spawn->IsEntity() && value > 0)
  1849. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1850. if (spawn->IsPlayer())
  1851. ((Player*)spawn)->SetCharSheetChanged(true);
  1852. return 0;
  1853. }
  1854. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1855. if (!lua_interface)
  1856. return 0;
  1857. Spawn* spawn = lua_interface->GetSpawn(state);
  1858. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1859. lua_interface->ResetFunctionStack(state);
  1860. if (spawn && spawn->IsEntity() && value > 0)
  1861. ((Entity*)spawn)->SetTotalHPBase(value);
  1862. return 0;
  1863. }
  1864. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1865. if (!lua_interface)
  1866. return 0;
  1867. Spawn* spawn = lua_interface->GetSpawn(state);
  1868. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1869. lua_interface->ResetFunctionStack(state);
  1870. if (spawn && value > 0) {
  1871. spawn->SetPower(value);
  1872. if (value > spawn->GetTotalPowerBase())
  1873. spawn->SetTotalPower(value);
  1874. }
  1875. return 0;
  1876. }
  1877. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1878. if (!lua_interface)
  1879. return 0;
  1880. Spawn* spawn = lua_interface->GetSpawn(state);
  1881. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1882. lua_interface->ResetFunctionStack(state);
  1883. if (spawn && spawn->IsEntity() && value > 0)
  1884. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1885. return 0;
  1886. }
  1887. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1888. if (!lua_interface)
  1889. return 0;
  1890. Spawn* spawn = lua_interface->GetSpawn(state);
  1891. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1892. lua_interface->ResetFunctionStack(state);
  1893. if (spawn && spawn->IsEntity() && value > 0)
  1894. ((Entity*)spawn)->SetTotalPowerBase(value);
  1895. return 0;
  1896. }
  1897. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1898. if (!lua_interface)
  1899. return 0;
  1900. Spawn* spawn = lua_interface->GetSpawn(state);
  1901. float x = lua_interface->GetFloatValue(state, 2);
  1902. float y = lua_interface->GetFloatValue(state, 3);
  1903. float z = lua_interface->GetFloatValue(state, 4);
  1904. float heading = lua_interface->GetFloatValue(state, 5);
  1905. lua_interface->ResetFunctionStack(state);
  1906. if (spawn) {
  1907. spawn->SetX(x);
  1908. spawn->SetY(y);
  1909. spawn->SetZ(z);
  1910. if (heading != 0)
  1911. spawn->SetHeading(heading);
  1912. spawn->SetSpawnOrigX(spawn->GetX());
  1913. spawn->SetSpawnOrigY(spawn->GetY());
  1914. spawn->SetSpawnOrigZ(spawn->GetZ());
  1915. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1916. if (spawn->IsPlayer()) {
  1917. Client* client = ((Player*)spawn)->GetClient();
  1918. if (client) {
  1919. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1920. client->QueuePacket(packet);
  1921. }
  1922. }
  1923. }
  1924. return 0;
  1925. }
  1926. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1927. if (!lua_interface)
  1928. return 0;
  1929. Spawn* spawn = lua_interface->GetSpawn(state);
  1930. float value = lua_interface->GetFloatValue(state, 2);
  1931. lua_interface->ResetFunctionStack(state);
  1932. if (spawn) {
  1933. spawn->SetHeading(value);
  1934. if (spawn->IsPlayer()) {
  1935. Client* client = ((Player*)spawn)->GetClient();
  1936. if (client) {
  1937. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1938. client->QueuePacket(packet);
  1939. }
  1940. }
  1941. }
  1942. return 0;
  1943. }
  1944. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1945. if (!lua_interface)
  1946. return 0;
  1947. Spawn* spawn = lua_interface->GetSpawn(state);
  1948. int16 value = lua_interface->GetInt16Value(state, 2);
  1949. lua_interface->ResetFunctionStack(state);
  1950. if (spawn)
  1951. spawn->SetModelType(value);
  1952. return 0;
  1953. }
  1954. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1955. if (!lua_interface)
  1956. return 0;
  1957. Spawn* spawn = lua_interface->GetSpawn(state);
  1958. int8 value = lua_interface->GetInt8Value(state, 2);
  1959. lua_interface->ResetFunctionStack(state);
  1960. if (spawn) {
  1961. if (spawn->IsPlayer())
  1962. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1963. else
  1964. spawn->SetAdventureClass(value);
  1965. }
  1966. return 0;
  1967. }
  1968. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1969. if (!lua_interface)
  1970. return 0;
  1971. Spawn* spawn = lua_interface->GetSpawn(state);
  1972. int8 value = lua_interface->GetInt8Value(state, 2);
  1973. lua_interface->ResetFunctionStack(state);
  1974. if (spawn) {
  1975. spawn->SetTradeskillClass(value);
  1976. if (spawn->IsEntity()) {
  1977. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1978. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1979. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1980. }
  1981. if (spawn->IsPlayer())
  1982. ((Player*)spawn)->SetCharSheetChanged(true);
  1983. }
  1984. return 0;
  1985. }
  1986. int EQ2Emu_lua_SetMount(lua_State* state) {
  1987. if (!lua_interface)
  1988. return 0;
  1989. Spawn* spawn = lua_interface->GetSpawn(state);
  1990. int16 value = lua_interface->GetInt16Value(state, 2);
  1991. if (spawn && spawn->IsEntity()) {
  1992. ((Entity*)spawn)->SetMount(value);
  1993. EQ2_Color color;
  1994. color.red = 255;
  1995. color.green = 255;
  1996. color.blue = 255;
  1997. ((Entity*)spawn)->SetMountColor(&color);
  1998. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1999. }
  2000. return 0;
  2001. }
  2002. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2003. if (!lua_interface)
  2004. return 0;
  2005. Spawn* spawn = lua_interface->GetSpawn(state);
  2006. EQ2_Color mount_color;
  2007. EQ2_Color saddle_color;
  2008. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2009. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2010. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2011. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2012. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2013. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2014. if (spawn && spawn->IsEntity()) {
  2015. ((Entity*)spawn)->SetMountColor(&mount_color);
  2016. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2017. }
  2018. return 0;
  2019. }
  2020. int EQ2Emu_lua_GetMount(lua_State* state) {
  2021. if (!lua_interface)
  2022. return 0;
  2023. Spawn* spawn = lua_interface->GetSpawn(state);
  2024. if (spawn && spawn->IsEntity()) {
  2025. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2026. return 1;
  2027. }
  2028. return 0;
  2029. }
  2030. int EQ2Emu_lua_GetRace(lua_State* state) {
  2031. if (!lua_interface)
  2032. return 0;
  2033. Spawn* spawn = lua_interface->GetSpawn(state);
  2034. if (spawn)
  2035. {
  2036. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2037. lua_interface->SetInt32Value(state, spawn->GetRace());
  2038. return 1;
  2039. }
  2040. return 0;
  2041. }
  2042. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2043. if (!lua_interface)
  2044. return 0;
  2045. Spawn* spawn = lua_interface->GetSpawn(state);
  2046. if (spawn) {
  2047. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2048. return 1;
  2049. }
  2050. return 0;
  2051. }
  2052. int EQ2Emu_lua_GetClass(lua_State* state) {
  2053. Spawn* spawn = lua_interface->GetSpawn(state);
  2054. if (spawn) {
  2055. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2056. return 1;
  2057. }
  2058. return 0;
  2059. }
  2060. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2061. Spawn* spawn = lua_interface->GetSpawn(state);
  2062. if (spawn) {
  2063. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2064. return 1;
  2065. }
  2066. return 0;
  2067. }
  2068. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2069. if (!lua_interface)
  2070. return 0;
  2071. Spawn* spawn = lua_interface->GetSpawn(state);
  2072. float value = lua_interface->GetFloatValue(state, 2);
  2073. lua_interface->ResetFunctionStack(state);
  2074. if (spawn) {
  2075. spawn->SetSpeed(value);
  2076. if(spawn->IsEntity())
  2077. ((Entity*)spawn)->SetSpeed(value);
  2078. if (spawn->IsPlayer()) {
  2079. Client* client = ((Player*)spawn)->GetClient();
  2080. if (client) {
  2081. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2082. if (packet) {
  2083. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2084. packet->setDataByName("speed", value);
  2085. packet->setDataByName("size", 0.51);
  2086. EQ2Packet* app = packet->serialize();
  2087. client->QueuePacket(app);
  2088. safe_delete(packet);
  2089. }
  2090. }
  2091. }
  2092. }
  2093. return 0;
  2094. }
  2095. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2096. if (!lua_interface)
  2097. return 0;
  2098. Spawn* spawn = lua_interface->GetSpawn(state);
  2099. const int16 type = lua_interface->GetInt16Value(state, 2);
  2100. const float value = lua_interface->GetFloatValue(state, 3);
  2101. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2102. if(!luaspell || luaspell->resisted) {
  2103. return 0;
  2104. }
  2105. int64 class_req = 0;
  2106. int32 class_id = 0;
  2107. vector<int16> faction_req;
  2108. vector<int16> race_req;
  2109. int32 i = 0;
  2110. int8 f = 0;
  2111. int8 r = 0;
  2112. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2113. if (class_id < 100) {
  2114. class_req += pow(2.0, double(class_id - 1));
  2115. }
  2116. else if (class_id > 100 && class_id < 1000) {
  2117. race_req.push_back(class_id);
  2118. r++;
  2119. }
  2120. else {
  2121. faction_req.push_back(class_id);
  2122. f++;
  2123. }
  2124. i++;
  2125. }
  2126. if (value != 0 && type >= 0) {
  2127. if (luaspell && luaspell->spell && luaspell->caster) {
  2128. ZoneServer* zone = luaspell->caster->GetZone();
  2129. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2130. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2131. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2132. if (target) {
  2133. if (target->IsPlayer()) {
  2134. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2135. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2136. if (((Player*)target)->GetGroupMemberInfo())
  2137. ((Player*)target)->UpdateGroupMemberInfo();
  2138. ((Player*)target)->SetCharSheetChanged(true);
  2139. }
  2140. else if (target->IsNPC())
  2141. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2142. else
  2143. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2144. }
  2145. }
  2146. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2147. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2148. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2149. }
  2150. else if (spawn && spawn->IsEntity()) {
  2151. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2152. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2153. if (spawn->IsPlayer())
  2154. ((Player*)spawn)->SetCharSheetChanged(true);
  2155. }
  2156. else
  2157. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2158. }
  2159. else
  2160. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2161. return 0;
  2162. }
  2163. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2164. if (!lua_interface)
  2165. return 0;
  2166. Spawn* spawn = lua_interface->GetSpawn(state);
  2167. int16 type = lua_interface->GetInt16Value(state, 2);
  2168. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2169. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2170. if (!spawn) {
  2171. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2172. return 0;
  2173. }
  2174. if (!spawn->IsEntity()) {
  2175. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2176. return 0;
  2177. }
  2178. if (value == 0) {
  2179. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2180. return 0;
  2181. }
  2182. if (!luaspell || !luaspell->spell) {
  2183. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2184. return 0;
  2185. }
  2186. if(luaspell->resisted) {
  2187. return 0;
  2188. }
  2189. int32 class_req = 0;
  2190. vector<int16> faction_req;
  2191. vector<int16> race_req;
  2192. int32 class_id = 0;
  2193. int32 i = 0;
  2194. int8 f = 0;
  2195. int8 r = 0;
  2196. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2197. if (class_id < 100) {
  2198. class_req += pow(2.0, double(class_id - 1));
  2199. }
  2200. else if (class_id > 100 && class_id < 1000) {
  2201. race_req.push_back(class_id);
  2202. r++;
  2203. }
  2204. else {
  2205. faction_req.push_back(class_id);
  2206. f++;
  2207. }
  2208. i++;
  2209. }
  2210. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2211. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2212. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2213. if (spawn->IsPlayer())
  2214. ((Player*)spawn)->SetCharSheetChanged(true);
  2215. return 0;
  2216. }
  2217. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2218. if (!lua_interface)
  2219. return 0;
  2220. Spawn* spawn = lua_interface->GetSpawn(state);
  2221. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2222. if (!spawn) {
  2223. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2224. return 0;
  2225. }
  2226. if (!spawn->IsEntity()) {
  2227. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2228. return 0;
  2229. }
  2230. if (!luaspell || !luaspell->spell) {
  2231. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2232. return 0;
  2233. }
  2234. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2235. if (spawn->IsPlayer())
  2236. ((Player*)spawn)->SetCharSheetChanged(true);
  2237. return 0;
  2238. }
  2239. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2240. if (!lua_interface)
  2241. return 0;
  2242. Spawn* spawn = lua_interface->GetSpawn(state);
  2243. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2244. if (luaspell && luaspell->spell) {
  2245. ZoneServer* zone = luaspell->caster->GetZone();
  2246. Spawn* target = 0;
  2247. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2248. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2249. target = zone->GetSpawnByID(luaspell->targets[i]);
  2250. if (target && target->IsEntity()) {
  2251. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2252. if (target->IsPlayer())
  2253. ((Player*)target)->SetCharSheetChanged(true);
  2254. }
  2255. }
  2256. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2257. }
  2258. else if (spawn && spawn->IsEntity()) {
  2259. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2260. if (spawn->IsPlayer())
  2261. ((Player*)spawn)->SetCharSheetChanged(true);
  2262. }
  2263. return 0;
  2264. }
  2265. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2266. if (!lua_interface)
  2267. return 0;
  2268. Spawn* spawn = lua_interface->GetSpawn(state);
  2269. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2270. float value = lua_interface->GetFloatValue(state, 3);
  2271. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2272. if (value != 0) {
  2273. int32 spell_id = 0;
  2274. if (luaspell && luaspell->spell && luaspell->caster) {
  2275. if(luaspell->resisted) {
  2276. return 0;
  2277. }
  2278. spell_id = luaspell->spell->GetSpellID();
  2279. ZoneServer* zone = luaspell->caster->GetZone();
  2280. Spawn* target = 0;
  2281. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2282. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2283. target = zone->GetSpawnByID(luaspell->targets[i]);
  2284. if (target && target->Alive()) {
  2285. if (target->IsPlayer()) {
  2286. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2287. Client* client = ((Player*)target)->GetClient();
  2288. if (client) {
  2289. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2290. if (packet)
  2291. client->QueuePacket(packet);
  2292. }
  2293. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2294. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2295. }
  2296. else if (target->IsNPC()) {
  2297. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2298. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2299. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2300. }
  2301. else
  2302. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2303. }
  2304. }
  2305. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2306. }
  2307. else if (spawn) {
  2308. if (spawn->IsPlayer()) {
  2309. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2310. Client* client = ((Player*)spawn)->GetClient();
  2311. if (client) {
  2312. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2313. if (packet)
  2314. client->QueuePacket(packet);
  2315. }
  2316. }
  2317. else if (spawn->IsNPC())
  2318. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2319. else
  2320. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2321. }
  2322. }
  2323. else
  2324. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2325. return 0;
  2326. }
  2327. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2328. if (!lua_interface)
  2329. return 0;
  2330. Spawn* spawn = lua_interface->GetSpawn(state);
  2331. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2332. if (spawn && spawn->IsPlayer()) {
  2333. int32 spell_id = 0;
  2334. if (luaspell && luaspell->spell) {
  2335. if(luaspell->resisted) {
  2336. return 0;
  2337. }
  2338. spell_id = luaspell->spell->GetSpellID();
  2339. ZoneServer* zone = luaspell->caster->GetZone();
  2340. Spawn* target = 0;
  2341. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2342. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2343. target = zone->GetSpawnByID(luaspell->targets[i]);
  2344. if (target) {
  2345. if (target->IsPlayer()) {
  2346. ((Player*)target)->RemoveSkillBonus(spell_id);
  2347. Client* client = ((Player*)target)->GetClient();
  2348. if (client) {
  2349. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2350. if (packet)
  2351. client->QueuePacket(packet);
  2352. }
  2353. }
  2354. else if (target->IsNPC())
  2355. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2356. else
  2357. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2358. }
  2359. }
  2360. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2361. }
  2362. else if (spawn) {
  2363. if (spawn->IsPlayer()) {
  2364. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2365. Client* client = ((Player*)spawn)->GetClient();
  2366. if (client) {
  2367. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2368. if (packet)
  2369. client->QueuePacket(packet);
  2370. }
  2371. }
  2372. else if (spawn->IsNPC())
  2373. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2374. else
  2375. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2376. }
  2377. }
  2378. return 0;
  2379. }
  2380. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2381. if (!lua_interface)
  2382. return 0;
  2383. Spawn* spawn = lua_interface->GetSpawn(state);
  2384. int8 type = lua_interface->GetInt32Value(state, 2);
  2385. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2386. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2387. if(luaspell && luaspell->resisted) {
  2388. return 0;
  2389. }
  2390. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2391. ZoneServer* zone = luaspell->caster->GetZone();
  2392. Spawn* target = 0;
  2393. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2394. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2395. target = zone->GetSpawnByID(luaspell->targets[i]);
  2396. if (target && target->IsEntity()) {
  2397. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2398. ((Entity*)target)->AddMezSpell(luaspell);
  2399. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2400. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2401. if (target->IsNPC())
  2402. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2403. }
  2404. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2405. ((Entity*)target)->AddStifleSpell(luaspell);
  2406. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2407. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2408. if (target->IsNPC())
  2409. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2410. }
  2411. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2412. ((Entity*)target)->AddDazeSpell(luaspell);
  2413. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2414. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2415. if (target->IsNPC())
  2416. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2417. }
  2418. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2419. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2420. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2421. ((Entity*)target)->AddStunSpell(luaspell);
  2422. if (target->IsNPC())
  2423. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2424. }
  2425. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2428. ((Entity*)target)->AddRootSpell(luaspell);
  2429. if (target->IsNPC())
  2430. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2431. }
  2432. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2433. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2434. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2435. ((Entity*)target)->AddFearSpell(luaspell);
  2436. if (target->IsNPC())
  2437. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2438. }
  2439. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2440. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2441. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2442. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2443. }
  2444. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2445. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2446. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2447. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2448. }
  2449. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2450. ((Entity*)target)->AddSnareSpell(luaspell);
  2451. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2452. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2453. if (target->IsNPC())
  2454. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2455. }
  2456. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2457. ((Entity*)target)->AddFlightSpell(luaspell);
  2458. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2459. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2460. }
  2461. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2462. ((Entity*)target)->AddGlideSpell(luaspell);
  2463. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2464. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2465. }
  2466. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2467. ((Entity*)target)->AddSafefallSpell(luaspell);
  2468. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2469. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2470. }
  2471. else
  2472. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2473. }
  2474. else
  2475. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2476. }
  2477. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2478. }
  2479. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2480. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2481. ((Entity*)spawn)->AddMezSpell(luaspell);
  2482. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2483. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2484. }
  2485. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2486. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2487. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2488. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2489. }
  2490. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2491. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2492. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2493. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2494. }
  2495. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2496. ((Entity*)spawn)->AddStunSpell(luaspell);
  2497. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2498. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2499. }
  2500. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2501. ((Entity*)spawn)->AddRootSpell(luaspell);
  2502. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2503. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2504. }
  2505. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2506. ((Entity*)spawn)->AddFearSpell(luaspell);
  2507. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2508. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2509. }
  2510. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2511. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2512. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2513. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2514. }
  2515. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2516. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2517. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2518. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2519. }
  2520. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2521. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2522. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2523. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2524. }
  2525. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2526. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2527. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2528. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2529. }
  2530. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2531. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2532. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2533. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2534. }
  2535. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2536. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2537. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2538. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2539. }
  2540. else
  2541. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2542. }
  2543. else
  2544. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2545. return 0;
  2546. }
  2547. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2548. if (!lua_interface)
  2549. return 0;
  2550. Spawn* spawn = lua_interface->GetSpawn(state);
  2551. int8 type = lua_interface->GetInt8Value(state, 2);
  2552. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2553. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2554. if (spawn && spawn->IsEntity()) {
  2555. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2556. ZoneServer* zone = luaspell->caster->GetZone();
  2557. Spawn* target = 0;
  2558. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2559. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2560. target = zone->GetSpawnByID(luaspell->targets[i]);
  2561. if (target) {
  2562. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2563. ((Entity*)target)->RemoveMezSpell(luaspell);
  2564. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2565. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2566. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2567. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2568. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2569. ((Entity*)target)->RemoveStunSpell(luaspell);
  2570. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2571. ((Entity*)target)->RemoveRootSpell(luaspell);
  2572. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2573. ((Entity*)target)->RemoveFearSpell(luaspell);
  2574. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2575. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2576. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2577. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2579. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2581. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2583. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2584. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2585. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2586. else
  2587. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2588. }
  2589. }
  2590. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2591. }
  2592. else if (only_remove_spawn) {
  2593. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2594. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2595. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2596. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2597. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2598. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2599. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2600. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2601. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2602. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2603. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2604. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2605. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2606. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2607. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2608. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2609. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2610. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2611. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2612. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2613. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2614. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2615. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2616. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2617. else
  2618. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2619. }
  2620. }
  2621. return 0;
  2622. }
  2623. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2624. if (!lua_interface)
  2625. return 0;
  2626. Spawn* spawn = lua_interface->GetSpawn(state);
  2627. int8 type = lua_interface->GetInt8Value(state, 2);
  2628. bool hasEffect = false;
  2629. if (!spawn)
  2630. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2631. else if (!spawn->IsEntity())
  2632. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2633. else if (type < CONTROL_MAX_EFFECTS)
  2634. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2635. else
  2636. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2637. lua_interface->SetBooleanValue(state, hasEffect);
  2638. return 1;
  2639. }
  2640. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2641. if (!lua_interface)
  2642. return 0;
  2643. Spawn* spawn = lua_interface->GetSpawn(state);
  2644. float distance = 0.0f;
  2645. if (!spawn)
  2646. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2647. else if (!spawn->IsNPC())
  2648. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2649. else
  2650. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2651. lua_interface->SetFloatValue(state, distance);
  2652. return 1;
  2653. }
  2654. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2655. if (!lua_interface)
  2656. return 0;
  2657. Spawn* spawn = lua_interface->GetSpawn(state);
  2658. float distance = 0.0f;
  2659. if (!spawn)
  2660. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2661. else if (!spawn->IsNPC())
  2662. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2663. else
  2664. distance = ((NPC*)spawn)->GetAggroRadius();
  2665. lua_interface->SetFloatValue(state, distance);
  2666. return 1;
  2667. }
  2668. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2669. if (!lua_interface)
  2670. return 0;
  2671. Spawn* spawn = lua_interface->GetSpawn(state);
  2672. float distance = lua_interface->GetFloatValue(state, 2);
  2673. bool override = lua_interface->GetBooleanValue(state, 3);
  2674. bool result = false;
  2675. lua_interface->ResetFunctionStack(state);
  2676. if (!spawn)
  2677. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2678. else if (!spawn->IsNPC())
  2679. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2680. else
  2681. {
  2682. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2683. result = true;
  2684. }
  2685. lua_interface->SetBooleanValue(state, result);
  2686. return 1;
  2687. }
  2688. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2689. if (!lua_interface)
  2690. return 0;
  2691. Spawn* spawn = lua_interface->GetSpawn(state);
  2692. int16 value = lua_interface->GetInt16Value(state, 2);
  2693. if (spawn && spawn->IsEntity()) {
  2694. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2695. if (spawn->IsPlayer())
  2696. ((Player*)spawn)->SetCharSheetChanged(true);
  2697. }
  2698. return 0;
  2699. }
  2700. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2701. if (!lua_interface)
  2702. return 0;
  2703. Spawn* spawn = lua_interface->GetSpawn(state);
  2704. int16 value = lua_interface->GetInt16Value(state, 2);
  2705. if (spawn && spawn->IsEntity()) {
  2706. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2707. if (spawn->IsPlayer())
  2708. ((Player*)spawn)->SetCharSheetChanged(true);
  2709. }
  2710. return 0;
  2711. }
  2712. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2713. if (!lua_interface)
  2714. return 0;
  2715. Spawn* spawn = lua_interface->GetSpawn(state);
  2716. int16 value = lua_interface->GetInt16Value(state, 2);
  2717. if (spawn && spawn->IsEntity()) {
  2718. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2719. if (spawn->IsPlayer())
  2720. ((Player*)spawn)->SetCharSheetChanged(true);
  2721. }
  2722. return 0;
  2723. }
  2724. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2725. if (!lua_interface)
  2726. return 0;
  2727. Spawn* spawn = lua_interface->GetSpawn(state);
  2728. int16 value = lua_interface->GetInt16Value(state, 2);
  2729. if (spawn && spawn->IsEntity()) {
  2730. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2731. if (spawn->IsPlayer())
  2732. ((Player*)spawn)->SetCharSheetChanged(true);
  2733. }
  2734. return 0;
  2735. }
  2736. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2737. if (!lua_interface)
  2738. return 0;
  2739. Spawn* spawn = lua_interface->GetSpawn(state);
  2740. int16 value = lua_interface->GetInt16Value(state, 2);
  2741. if (spawn && spawn->IsEntity()) {
  2742. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2743. if (spawn->IsPlayer())
  2744. ((Player*)spawn)->SetCharSheetChanged(true);
  2745. }
  2746. return 0;
  2747. }
  2748. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2749. if (!lua_interface)
  2750. return 0;
  2751. Spawn* spawn = lua_interface->GetSpawn(state);
  2752. int8 value = lua_interface->GetInt8Value(state, 2);
  2753. if (spawn && spawn->IsEntity()) {
  2754. ((Entity*)spawn)->SetDeity(value);
  2755. if (spawn->IsPlayer())
  2756. ((Player*)spawn)->SetCharSheetChanged(true);
  2757. }
  2758. lua_interface->ResetFunctionStack(state);
  2759. return 0;
  2760. }
  2761. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2762. if (!lua_interface)
  2763. return 0;
  2764. Spawn* spawn = lua_interface->GetSpawn(state);
  2765. if (spawn && spawn->IsEntity()) {
  2766. int8 deity = ((Entity*)spawn)->GetDeity();
  2767. lua_interface->SetInt32Value(state, deity);
  2768. return 1;
  2769. }
  2770. return 0;
  2771. }
  2772. int EQ2Emu_lua_SetInt(lua_State* state) {
  2773. if (!lua_interface)
  2774. return 0;
  2775. Spawn* spawn = lua_interface->GetSpawn(state);
  2776. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2777. if (spawn && spawn->IsEntity()) {
  2778. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2779. if (spawn->IsPlayer())
  2780. ((Player*)spawn)->SetCharSheetChanged(true);
  2781. }
  2782. return 0;
  2783. }
  2784. int EQ2Emu_lua_SetWis(lua_State* state) {
  2785. if (!lua_interface)
  2786. return 0;
  2787. Spawn* spawn = lua_interface->GetSpawn(state);
  2788. float value = lua_interface->GetFloatValue(state, 2);
  2789. if (spawn && spawn->IsEntity()) {
  2790. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2791. if (spawn->IsPlayer())
  2792. ((Player*)spawn)->SetCharSheetChanged(true);
  2793. }
  2794. return 0;
  2795. }
  2796. int EQ2Emu_lua_SetSta(lua_State* state) {
  2797. if (!lua_interface)
  2798. return 0;
  2799. Spawn* spawn = lua_interface->GetSpawn(state);
  2800. float value = lua_interface->GetFloatValue(state, 2);
  2801. if (spawn && spawn->IsEntity()) {
  2802. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2803. if (spawn->IsPlayer())
  2804. ((Player*)spawn)->SetCharSheetChanged(true);
  2805. }
  2806. return 0;
  2807. }
  2808. int EQ2Emu_lua_SetStr(lua_State* state) {
  2809. if (!lua_interface)
  2810. return 0;
  2811. Spawn* spawn = lua_interface->GetSpawn(state);
  2812. float value = lua_interface->GetFloatValue(state, 2);
  2813. if (spawn && spawn->IsEntity()) {
  2814. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2815. if (spawn->IsPlayer())
  2816. ((Player*)spawn)->SetCharSheetChanged(true);
  2817. }
  2818. return 0;
  2819. }
  2820. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2821. if (!lua_interface)
  2822. return 0;
  2823. Spawn* spawn = lua_interface->GetSpawn(state);
  2824. float value = lua_interface->GetFloatValue(state, 2);
  2825. if (spawn && spawn->IsEntity()) {
  2826. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2827. if (spawn->IsPlayer())
  2828. ((Player*)spawn)->SetCharSheetChanged(true);
  2829. }
  2830. return 0;
  2831. }
  2832. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2833. if (!lua_interface)
  2834. return 0;
  2835. Spawn* spawn = lua_interface->GetSpawn(state);
  2836. if (spawn) {
  2837. lua_interface->SetInt32Value(state, spawn->GetHP());
  2838. return 1;
  2839. }
  2840. return 0;
  2841. }
  2842. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2843. if (!lua_interface)
  2844. return 0;
  2845. Spawn* spawn = lua_interface->GetSpawn(state);
  2846. if (spawn) {
  2847. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2848. return 1;
  2849. }
  2850. return 0;
  2851. }
  2852. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2853. if (!lua_interface)
  2854. return 0;
  2855. Spawn* spawn = lua_interface->GetSpawn(state);
  2856. if (spawn) {
  2857. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2858. return 1;
  2859. }
  2860. return 0;
  2861. }
  2862. int EQ2Emu_lua_GetName(lua_State* state) {
  2863. if (!lua_interface)
  2864. return 0;
  2865. Spawn* spawn = lua_interface->GetSpawn(state);
  2866. if (spawn) {
  2867. lua_interface->SetStringValue(state, spawn->GetName());
  2868. return 1;
  2869. }
  2870. return 0;
  2871. }
  2872. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2873. Spawn* spawn = lua_interface->GetSpawn(state);
  2874. if (spawn) {
  2875. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2876. return 1;
  2877. }
  2878. return 0;
  2879. }
  2880. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2881. if (!lua_interface)
  2882. return 0;
  2883. Spawn* spawn = lua_interface->GetSpawn(state);
  2884. if (spawn) {
  2885. lua_interface->SetInt32Value(state, spawn->GetPower());
  2886. return 1;
  2887. }
  2888. return 0;
  2889. }
  2890. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2891. if (!lua_interface)
  2892. return 0;
  2893. Spawn* spawn = lua_interface->GetSpawn(state);
  2894. if (spawn) {
  2895. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2896. return 1;
  2897. }
  2898. return 0;
  2899. }
  2900. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2901. if (!lua_interface)
  2902. return 0;
  2903. Spawn* spawn = lua_interface->GetSpawn(state);
  2904. if (spawn) {
  2905. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2906. return 1;
  2907. }
  2908. return 0;
  2909. }
  2910. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2911. if (!lua_interface)
  2912. return 0;
  2913. Spawn* spawn = lua_interface->GetSpawn(state);
  2914. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2915. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2916. if (spawn && spawn2) {
  2917. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2918. lua_interface->SetFloatValue(state, distance);
  2919. return 1;
  2920. }
  2921. return 0;
  2922. }
  2923. int EQ2Emu_lua_GetX(lua_State* state) {
  2924. if (!lua_interface)
  2925. return 0;
  2926. Spawn* spawn = lua_interface->GetSpawn(state);
  2927. if (spawn) {
  2928. lua_interface->SetFloatValue(state, spawn->GetX());
  2929. return 1;
  2930. }
  2931. return 0;
  2932. }
  2933. int EQ2Emu_lua_GetY(lua_State* state) {
  2934. if (!lua_interface)
  2935. return 0;
  2936. Spawn* spawn = lua_interface->GetSpawn(state);
  2937. if (spawn) {
  2938. lua_interface->SetFloatValue(state, spawn->GetY());
  2939. return 1;
  2940. }
  2941. return 0;
  2942. }
  2943. int EQ2Emu_lua_GetZ(lua_State* state) {
  2944. if (!lua_interface)
  2945. return 0;
  2946. Spawn* spawn = lua_interface->GetSpawn(state);
  2947. if (spawn) {
  2948. lua_interface->SetFloatValue(state, spawn->GetZ());
  2949. return 1;
  2950. }
  2951. return 0;
  2952. }
  2953. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2954. if (!lua_interface)
  2955. return 0;
  2956. Spawn* spawn = lua_interface->GetSpawn(state);
  2957. if (spawn) {
  2958. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2959. return 1;
  2960. }
  2961. return 0;
  2962. }
  2963. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2964. if (!lua_interface)
  2965. return 0;
  2966. Spawn* spawn = lua_interface->GetSpawn(state);
  2967. if (spawn) {
  2968. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2969. return 1;
  2970. }
  2971. return 0;
  2972. }
  2973. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2974. if (!lua_interface)
  2975. return 0;
  2976. Spawn* spawn = lua_interface->GetSpawn(state);
  2977. if (spawn) {
  2978. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2979. return 1;
  2980. }
  2981. return 0;
  2982. }
  2983. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2984. if (!lua_interface)
  2985. return 0;
  2986. Spawn* spawn = lua_interface->GetSpawn(state);
  2987. if (spawn && spawn->IsEntity()) {
  2988. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2989. return 1;
  2990. }
  2991. return 0;
  2992. }
  2993. int EQ2Emu_lua_GetInt(lua_State* state) {
  2994. if (!lua_interface)
  2995. return 0;
  2996. Spawn* spawn = lua_interface->GetSpawn(state);
  2997. if (spawn && spawn->IsEntity()) {
  2998. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2999. return 1;
  3000. }
  3001. return 0;
  3002. }
  3003. int EQ2Emu_lua_GetWis(lua_State* state) {
  3004. if (!lua_interface)
  3005. return 0;
  3006. Spawn* spawn = lua_interface->GetSpawn(state);
  3007. if (spawn && spawn->IsEntity()) {
  3008. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3009. return 1;
  3010. }
  3011. return 0;
  3012. }
  3013. int EQ2Emu_lua_GetSta(lua_State* state) {
  3014. if (!lua_interface)
  3015. return 0;
  3016. Spawn* spawn = lua_interface->GetSpawn(state);
  3017. if (spawn && spawn->IsEntity()) {
  3018. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3019. return 1;
  3020. }
  3021. return 0;
  3022. }
  3023. int EQ2Emu_lua_GetStr(lua_State* state) {
  3024. if (!lua_interface)
  3025. return 0;
  3026. Spawn* spawn = lua_interface->GetSpawn(state);
  3027. if (spawn && spawn->IsEntity()) {
  3028. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3029. return 1;
  3030. }
  3031. return 0;
  3032. }
  3033. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3034. if (!lua_interface)
  3035. return 0;
  3036. Spawn* spawn = lua_interface->GetSpawn(state);
  3037. if (spawn && spawn->IsEntity()) {
  3038. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3039. return 1;
  3040. }
  3041. return 0;
  3042. }
  3043. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3044. if (!lua_interface)
  3045. return 0;
  3046. Spawn* spawn = lua_interface->GetSpawn(state);
  3047. if (spawn && spawn->IsEntity()) {
  3048. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3049. return 1;
  3050. }
  3051. return 0;
  3052. }
  3053. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3054. if (!lua_interface)
  3055. return 0;
  3056. Spawn* spawn = lua_interface->GetSpawn(state);
  3057. if (spawn && spawn->IsEntity()) {
  3058. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3059. return 1;
  3060. }
  3061. return 0;
  3062. }
  3063. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3064. if (!lua_interface)
  3065. return 0;
  3066. Spawn* spawn = lua_interface->GetSpawn(state);
  3067. if (spawn && spawn->IsEntity()) {
  3068. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3069. return 1;
  3070. }
  3071. return 0;
  3072. }
  3073. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3074. if (!lua_interface)
  3075. return 0;
  3076. Spawn* spawn = lua_interface->GetSpawn(state);
  3077. if (spawn && spawn->IsEntity()) {
  3078. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3079. return 1;
  3080. }
  3081. return 0;
  3082. }
  3083. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3084. if (!lua_interface)
  3085. return 0;
  3086. Spawn* spawn = lua_interface->GetSpawn(state);
  3087. if (spawn && spawn->IsEntity()) {
  3088. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3089. return 1;
  3090. }
  3091. return 0;
  3092. }
  3093. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3094. if (!lua_interface)
  3095. return 0;
  3096. Spawn* player = lua_interface->GetSpawn(state);
  3097. if (!player || !player->IsPlayer()) {
  3098. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3099. return 0;
  3100. }
  3101. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3102. if (quest_id <= 0) {
  3103. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3104. return 0;
  3105. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3106. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3107. return 0;
  3108. }
  3109. int32 step = lua_interface->GetInt32Value(state, 3);
  3110. if (step > 0) {
  3111. Client* client = ((Player*)player)->GetClient();
  3112. if (client)
  3113. client->AddPendingQuestUpdate(quest_id, step);
  3114. } else {
  3115. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3116. }
  3117. return 0;
  3118. }
  3119. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3120. Spawn* player = lua_interface->GetSpawn(state);
  3121. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3122. int32 step = lua_interface->GetInt32Value(state, 3);
  3123. int32 progress = lua_interface->GetInt32Value(state, 4);
  3124. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3125. Client* client = ((Player*)player)->GetClient();
  3126. if (client)
  3127. client->AddPendingQuestUpdate(quest_id, step, progress);
  3128. }
  3129. return 0;
  3130. }
  3131. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3132. if (!lua_interface)
  3133. return 0;
  3134. Spawn* player = lua_interface->GetSpawn(state);
  3135. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3136. if (player && player->IsPlayer() && quest_id > 0) {
  3137. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3138. return 1;
  3139. }
  3140. return 0;
  3141. }
  3142. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3143. if (!lua_interface)
  3144. return 0;
  3145. Spawn* player = lua_interface->GetSpawn(state);
  3146. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3147. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3148. if (player && player->IsPlayer() && quest_id > 0) {
  3149. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3150. return 1;
  3151. }
  3152. return 0;
  3153. }
  3154. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3155. if (!lua_interface)
  3156. return 0;
  3157. Spawn* player = lua_interface->GetSpawn(state);
  3158. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3159. if (player && player->IsPlayer() && quest_id > 0) {
  3160. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3161. return 1;
  3162. }
  3163. return 0;
  3164. }
  3165. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3166. if (!lua_interface)
  3167. return 0;
  3168. Quest* quest = lua_interface->GetQuest(state);
  3169. string name = lua_interface->GetStringValue(state, 2);
  3170. string type = lua_interface->GetStringValue(state, 3);
  3171. string zone = lua_interface->GetStringValue(state, 4);
  3172. int16 level = lua_interface->GetInt16Value(state, 5);
  3173. string description = lua_interface->GetStringValue(state, 6);
  3174. bool load = true;
  3175. if (!quest) {
  3176. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3177. load = false;
  3178. }
  3179. if (load && name.length() == 0) {
  3180. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3181. load = false;
  3182. }
  3183. if (load && type.length() == 0) {
  3184. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3185. load = false;
  3186. }
  3187. if (load && zone.length() == 0) {
  3188. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3189. load = false;
  3190. }
  3191. if (load && description.length() == 0) {
  3192. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3193. load = false;
  3194. }
  3195. if (load && level == 0) {
  3196. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3197. load = false;
  3198. }
  3199. if (load)
  3200. quest->RegisterQuest(name, type, zone, level, description);
  3201. return 0;
  3202. }
  3203. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3204. if (!lua_interface)
  3205. return 0;
  3206. Quest* quest = lua_interface->GetQuest(state);
  3207. if (quest) {
  3208. int8 level = lua_interface->GetInt16Value(state, 2);
  3209. quest->SetPrereqLevel(level);
  3210. }
  3211. return 0;
  3212. }
  3213. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3214. if (!lua_interface)
  3215. return 0;
  3216. Quest* quest = lua_interface->GetQuest(state);
  3217. if (quest) {
  3218. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3219. quest->AddPrereqQuest(quest_id);
  3220. }
  3221. return 0;
  3222. }
  3223. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3224. if (!lua_interface)
  3225. return 0;
  3226. Quest* quest = lua_interface->GetQuest(state);
  3227. if (quest) {
  3228. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3229. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3230. if (quantity == 0)
  3231. quantity = 1;
  3232. Item* master_item = master_item_list.GetItem(item_id);
  3233. if (master_item) {
  3234. Item* item = new Item(master_item);
  3235. item->details.count = quantity;
  3236. quest->AddPrereqItem(item);
  3237. }
  3238. }
  3239. return 0;
  3240. }
  3241. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3242. if (!lua_interface)
  3243. return 0;
  3244. Spawn* player = lua_interface->GetSpawn(state);
  3245. if(!player || !player->IsPlayer()) {
  3246. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3247. return 0;
  3248. }
  3249. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3250. if (quest_id > 0) {
  3251. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3252. return 1;
  3253. } else {
  3254. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3255. }
  3256. return 0;
  3257. }
  3258. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3259. if (!lua_interface)
  3260. return 0;
  3261. Quest* quest = lua_interface->GetQuest(state);
  3262. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3263. lua_interface->ResetFunctionStack(state);
  3264. if (quest && spawn_id > 0)
  3265. quest->SetQuestReturnNPC(spawn_id);
  3266. return 0;
  3267. }
  3268. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3269. if (!lua_interface)
  3270. return 0;
  3271. Spawn* spawn = lua_interface->GetSpawn(state);
  3272. int32 time = lua_interface->GetInt32Value(state, 2);
  3273. string function = lua_interface->GetStringValue(state, 3);
  3274. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3275. Spawn* player = lua_interface->GetSpawn(state, 5);
  3276. lua_interface->ResetFunctionStack(state);
  3277. if (!spawn) {
  3278. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3279. return 0;
  3280. }
  3281. if (time <= 0) {
  3282. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3283. return 0;
  3284. }
  3285. if (function.length() == 0) {
  3286. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3287. return 0;
  3288. }
  3289. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3290. if ( time < 10)
  3291. time = 10;
  3292. timer->timer = Timer::GetCurrentTime2() + time;
  3293. timer->function = function;
  3294. timer->spawn = spawn->GetID();
  3295. timer->player = player ? player->GetID() : 0;
  3296. if (max_count == 0)
  3297. max_count = 1;
  3298. timer->max_count = max_count;
  3299. timer->current_count = 0;
  3300. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3301. return 0;
  3302. }
  3303. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3304. if (!lua_interface)
  3305. return 0;
  3306. Spawn* spawn = lua_interface->GetSpawn(state);
  3307. string function = lua_interface->GetStringValue(state, 2);
  3308. lua_interface->ResetFunctionStack(state);
  3309. if (!spawn) {
  3310. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3311. return 0;
  3312. }
  3313. if(!spawn->GetZone()) {
  3314. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3315. return 0;
  3316. }
  3317. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3318. return 0;
  3319. }
  3320. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3321. if (!lua_interface)
  3322. return 0;
  3323. Spawn* player = lua_interface->GetSpawn(state);
  3324. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3325. lua_interface->ResetFunctionStack(state);
  3326. if (player && player->IsPlayer() && quest_id > 0) {
  3327. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3328. return 1;
  3329. }
  3330. return 0;
  3331. }
  3332. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3333. if (!lua_interface)
  3334. return 0;
  3335. Spawn* player = lua_interface->GetSpawn(state);
  3336. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3337. lua_interface->ResetFunctionStack(state);
  3338. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3339. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3340. if (quest)
  3341. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3342. return 1;
  3343. }
  3344. return 0;
  3345. }
  3346. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3347. if (!lua_interface)
  3348. return 0;
  3349. Spawn* player = lua_interface->GetSpawn(state);
  3350. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3351. lua_interface->ResetFunctionStack(state);
  3352. if (player && player->IsPlayer() && quest_id > 0) {
  3353. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3354. return 1;
  3355. }
  3356. return 0;
  3357. }
  3358. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3359. if (!lua_interface)
  3360. return 0;
  3361. Spawn* npc = lua_interface->GetSpawn(state);
  3362. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3363. lua_interface->ResetFunctionStack(state);
  3364. if (npc && !npc->IsPlayer() && quest_id > 0)
  3365. npc->AddProvidedQuest(quest_id);
  3366. return 0;
  3367. }
  3368. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3369. if (!lua_interface)
  3370. return 0;
  3371. Spawn* npc = lua_interface->GetSpawn(state);
  3372. Spawn* player = lua_interface->GetSpawn(state, 2);
  3373. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3374. bool forced = lua_interface->GetBooleanValue(state, 4);
  3375. lua_interface->ResetFunctionStack(state);
  3376. /* NPC is allowed to be null */
  3377. if (player && player->IsPlayer() && quest_id > 0) {
  3378. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3379. if (master_quest) {
  3380. Client* client = ((Player*)player)->GetClient();
  3381. if (!client) {
  3382. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3383. }
  3384. Quest* quest = new Quest(master_quest);
  3385. if (!quest) {
  3386. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3387. }
  3388. if (client && quest) {
  3389. if (npc)
  3390. quest->SetQuestGiver(npc->GetDatabaseID());
  3391. else
  3392. quest->SetQuestGiver(0);
  3393. client->AddPendingQuest(quest, forced);
  3394. }
  3395. }
  3396. else {
  3397. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3398. }
  3399. }
  3400. else {
  3401. 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);
  3402. }
  3403. return 0;
  3404. }
  3405. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3406. if (!lua_interface)
  3407. return 0;
  3408. Quest* quest = lua_interface->GetQuest(state);
  3409. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3410. lua_interface->ResetFunctionStack(state);
  3411. if (quest) {
  3412. quest->AddPrereqClass(class_id);
  3413. }
  3414. return 0;
  3415. }
  3416. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3417. if (!lua_interface)
  3418. return 0;
  3419. Quest* quest = lua_interface->GetQuest(state);
  3420. int8 race = lua_interface->GetInt8Value(state, 2);
  3421. lua_interface->ResetFunctionStack(state);
  3422. if (quest) {
  3423. quest->AddPrereqRace(race);
  3424. }
  3425. return 0;
  3426. }
  3427. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3428. if (!lua_interface)
  3429. return 0;
  3430. Quest* quest = lua_interface->GetQuest(state);
  3431. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3432. lua_interface->ResetFunctionStack(state);
  3433. if (quest) {
  3434. quest->AddPrereqModelType(model_type);
  3435. }
  3436. return 0;
  3437. }
  3438. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3439. if (!lua_interface)
  3440. return 0;
  3441. Quest* quest = lua_interface->GetQuest(state);
  3442. int8 level = lua_interface->GetInt8Value(state, 2);
  3443. lua_interface->ResetFunctionStack(state);
  3444. if (!quest) {
  3445. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3446. return 0;
  3447. }
  3448. quest->SetPrereqTSLevel(level);
  3449. return 0;
  3450. }
  3451. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3452. if (!lua_interface)
  3453. return 0;
  3454. Quest* quest = lua_interface->GetQuest(state);
  3455. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3456. lua_interface->ResetFunctionStack(state);
  3457. if (!quest) {
  3458. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3459. return 0;
  3460. }
  3461. quest->AddPrereqTradeskillClass(class_id);
  3462. return 0;
  3463. }
  3464. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3465. if (!lua_interface)
  3466. return 0;
  3467. Quest* quest = lua_interface->GetQuest(state);
  3468. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3469. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3470. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3471. lua_interface->ResetFunctionStack(state);
  3472. if (quest) {
  3473. quest->AddPrereqFaction(faction_id, min, max);
  3474. }
  3475. return 0;
  3476. }
  3477. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3478. if (!lua_interface)
  3479. return 0;
  3480. Quest* quest = lua_interface->GetQuest(state);
  3481. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3482. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3483. lua_interface->ResetFunctionStack(state);
  3484. if (quest) {
  3485. if (quantity == 0)
  3486. quantity = 1;
  3487. Item* master_item = master_item_list.GetItem(item_id);
  3488. if (master_item) {
  3489. Item* item = new Item(master_item);
  3490. item->details.count = quantity;
  3491. quest->AddSelectableRewardItem(item);
  3492. }
  3493. }
  3494. return 0;
  3495. }
  3496. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3497. if (!lua_interface)
  3498. return 0;
  3499. Quest* quest = lua_interface->GetQuest(state);
  3500. if (quest) {
  3501. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3502. vector<Item*>* items = quest->GetRewardItems();
  3503. if (items) {
  3504. vector<Item*>::iterator itr;
  3505. for (itr = items->begin(); itr != items->end(); itr++) {
  3506. if (*itr && (*itr)->details.item_id == item_id) {
  3507. lua_interface->SetBooleanValue(state, true);
  3508. return 1;
  3509. }
  3510. }
  3511. }
  3512. }
  3513. lua_interface->SetBooleanValue(state, false);
  3514. return 1;
  3515. }
  3516. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3517. if (!lua_interface)
  3518. return 0;
  3519. Quest* quest = lua_interface->GetQuest(state);
  3520. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3521. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3522. lua_interface->ResetFunctionStack(state);
  3523. if (quest) {
  3524. if (quantity == 0)
  3525. quantity = 1;
  3526. Item* master_item = master_item_list.GetItem(item_id);
  3527. if (master_item) {
  3528. Item* item = new Item(master_item);
  3529. item->details.count = quantity;
  3530. quest->AddRewardItem(item);
  3531. }
  3532. }
  3533. return 0;
  3534. }
  3535. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3536. if (!lua_interface)
  3537. return 0;
  3538. Quest* quest = lua_interface->GetQuest(state);
  3539. int32 copper = lua_interface->GetInt32Value(state, 2);
  3540. int32 silver = lua_interface->GetInt32Value(state, 3);
  3541. int32 gold = lua_interface->GetInt32Value(state, 4);
  3542. int32 plat = lua_interface->GetInt32Value(state, 5);
  3543. lua_interface->ResetFunctionStack(state);
  3544. if (quest) {
  3545. quest->AddRewardCoins(copper, silver, gold, plat);
  3546. }
  3547. return 0;
  3548. }
  3549. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3550. if (!lua_interface)
  3551. return 0;
  3552. Quest* quest = lua_interface->GetQuest(state);
  3553. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3554. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3555. lua_interface->ResetFunctionStack(state);
  3556. if (quest && faction_id > 0 && amount != 0)
  3557. quest->AddRewardFaction(faction_id, amount);
  3558. return 0;
  3559. }
  3560. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3561. if (!lua_interface)
  3562. return 0;
  3563. Quest* quest = lua_interface->GetQuest(state);
  3564. int32 status = lua_interface->GetInt32Value(state, 2);
  3565. lua_interface->ResetFunctionStack(state);
  3566. if (quest) {
  3567. quest->SetRewardStatus(status);
  3568. }
  3569. return 0;
  3570. }
  3571. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3572. if (!lua_interface)
  3573. return 0;
  3574. Quest* quest = lua_interface->GetQuest(state);
  3575. int32 status = lua_interface->GetInt32Value(state, 2);
  3576. lua_interface->ResetFunctionStack(state);
  3577. if (quest) {
  3578. quest->SetStatusTmpReward(status);
  3579. }
  3580. return 0;
  3581. }
  3582. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3583. if (!lua_interface)
  3584. return 0;
  3585. Quest* quest = lua_interface->GetQuest(state);
  3586. int64 coins = lua_interface->GetInt64Value(state, 2);
  3587. lua_interface->ResetFunctionStack(state);
  3588. if (quest) {
  3589. quest->SetCoinTmpReward(coins);
  3590. }
  3591. return 0;
  3592. }
  3593. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3594. if (!lua_interface)
  3595. return 0;
  3596. Quest* quest = lua_interface->GetQuest(state);
  3597. string comment = lua_interface->GetStringValue(state, 2);
  3598. lua_interface->ResetFunctionStack(state);
  3599. if (quest) {
  3600. quest->SetRewardComment(comment);
  3601. }
  3602. return 0;
  3603. }
  3604. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3605. if (!lua_interface)
  3606. return 0;
  3607. Quest* quest = lua_interface->GetQuest(state);
  3608. int32 exp = lua_interface->GetInt32Value(state, 2);
  3609. lua_interface->ResetFunctionStack(state);
  3610. if (quest) {
  3611. quest->SetRewardXP(exp);
  3612. }
  3613. return 0;
  3614. }
  3615. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3616. Quest* quest = lua_interface->GetQuest(state);
  3617. int32 step = lua_interface->GetInt32Value(state, 2);
  3618. string description = lua_interface->GetStringValue(state, 3);
  3619. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3620. float percentage = lua_interface->GetFloatValue(state, 5);
  3621. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3622. int16 icon = lua_interface->GetInt16Value(state, 7);
  3623. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3624. if (quest) {
  3625. const char* taskgroup = 0;
  3626. if (str_taskgroup.length() > 0)
  3627. taskgroup = str_taskgroup.c_str();
  3628. int32 id = 0;
  3629. vector<int32>* ids = 0;
  3630. int i = 0;
  3631. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3632. if (ids == 0)
  3633. ids = new vector<int32>;
  3634. ids->push_back(id);
  3635. i++;
  3636. }
  3637. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3638. if (quest_step && icon && quantity > 0)
  3639. quest_step->SetIcon(icon);
  3640. if (quest->GetPlayer()) {
  3641. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3642. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3643. }
  3644. }
  3645. lua_interface->ResetFunctionStack(state);
  3646. return 0;
  3647. }
  3648. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3649. {
  3650. if (!lua_interface)
  3651. return 0;
  3652. Quest* quest = lua_interface->GetQuest(state);
  3653. int32 step = lua_interface->GetInt32Value(state, 2);
  3654. string description = lua_interface->GetStringValue(state, 3);
  3655. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3656. float percentage = lua_interface->GetFloatValue(state, 5);
  3657. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3658. int16 icon = lua_interface->GetInt16Value(state, 7);
  3659. if (quest) {
  3660. const char* taskgroup = 0;
  3661. if (str_taskgroup.length() > 0)
  3662. taskgroup = str_taskgroup.c_str();
  3663. int32 id = 0;
  3664. vector<int32>* ids = 0;
  3665. int i = 0;
  3666. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3667. if (ids == 0)
  3668. ids = new vector<int32>;
  3669. ids->push_back(id);
  3670. i++;
  3671. }
  3672. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3673. if (quest_step && icon > 0 && quantity > 0)
  3674. quest_step->SetIcon(icon);
  3675. if (quest->GetPlayer()) {
  3676. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3677. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3678. }
  3679. safe_delete(ids);
  3680. }
  3681. lua_interface->ResetFunctionStack(state);
  3682. return 0;
  3683. }
  3684. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3685. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3686. }
  3687. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3688. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3689. }
  3690. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3691. if (!lua_interface)
  3692. return 0;
  3693. Quest* quest = lua_interface->GetQuest(state);
  3694. int32 step = lua_interface->GetInt32Value(state, 2);
  3695. string description = lua_interface->GetStringValue(state, 3);
  3696. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3697. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3698. int16 icon = lua_interface->GetInt16Value(state, 6);
  3699. if (quest) {
  3700. const char* taskgroup = 0;
  3701. if (str_taskgroup.length() > 0)
  3702. taskgroup = str_taskgroup.c_str();
  3703. int32 npc_id = 0;
  3704. vector<int32>* ids = 0;
  3705. int i = 0;
  3706. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3707. if (ids == 0)
  3708. ids = new vector<int32>;
  3709. ids->push_back(npc_id);
  3710. i++;
  3711. }
  3712. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3713. if (quest_step && icon > 0)
  3714. quest_step->SetIcon(icon);
  3715. if (quest->GetPlayer()) {
  3716. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3717. if(client)
  3718. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3719. }
  3720. safe_delete(ids);
  3721. }
  3722. lua_interface->ResetFunctionStack(state);
  3723. return 0;
  3724. }
  3725. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3726. if (!lua_interface)
  3727. return 0;
  3728. Quest* quest = lua_interface->GetQuest(state);
  3729. int32 step = lua_interface->GetInt32Value(state, 2);
  3730. string description = lua_interface->GetStringValue(state, 3);
  3731. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3732. float percentage = lua_interface->GetFloatValue(state, 5);
  3733. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3734. int16 icon = lua_interface->GetInt16Value(state, 7);
  3735. if (quest) {
  3736. const char* taskgroup = 0;
  3737. if (str_taskgroup.length() > 0)
  3738. taskgroup = str_taskgroup.c_str();
  3739. int32 item_id = 0;
  3740. vector<int32>* ids = 0;
  3741. int i = 0;
  3742. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3743. if (ids == 0)
  3744. ids = new vector<int32>;
  3745. ids->push_back(item_id);
  3746. i++;
  3747. }
  3748. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3749. if (quest_step && icon > 0 && quantity > 0)
  3750. quest_step->SetIcon(icon);
  3751. if (quest->GetPlayer()) {
  3752. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3753. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3754. }
  3755. safe_delete(ids);
  3756. }
  3757. lua_interface->ResetFunctionStack(state);
  3758. return 0;
  3759. }
  3760. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3761. if (!lua_interface)
  3762. return 0;
  3763. Quest* quest = lua_interface->GetQuest(state);
  3764. int32 step = lua_interface->GetInt32Value(state, 2);
  3765. string description = lua_interface->GetStringValue(state, 3);
  3766. float max_variation = lua_interface->GetFloatValue(state, 4);
  3767. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3768. int16 icon = lua_interface->GetInt16Value(state, 6);
  3769. if (quest) {
  3770. const char* taskgroup = 0;
  3771. if (str_taskgroup.length() > 0)
  3772. taskgroup = str_taskgroup.c_str();
  3773. vector<Location>* locations = 0;
  3774. int8 i = 7;
  3775. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3776. while (true) {
  3777. Location loc;
  3778. loc.x = lua_interface->GetFloatValue(state, i);
  3779. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3780. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3781. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3782. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3783. break;
  3784. if (locations == 0)
  3785. locations = new vector<Location>;
  3786. locations->push_back(loc);
  3787. i += 4;
  3788. }
  3789. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3790. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3791. if (quest_step && icon > 0)
  3792. quest_step->SetIcon(icon);
  3793. if (quest->GetPlayer()) {
  3794. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3795. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3796. }
  3797. }
  3798. lua_interface->ResetFunctionStack(state);
  3799. return 0;
  3800. }
  3801. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3802. if (!lua_interface)
  3803. return 0;
  3804. Quest* quest = lua_interface->GetQuest(state);
  3805. int32 step = lua_interface->GetInt32Value(state, 2);
  3806. string description = lua_interface->GetStringValue(state, 3);
  3807. float max_variation = lua_interface->GetFloatValue(state, 4);
  3808. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3809. int16 icon = lua_interface->GetInt16Value(state, 6);
  3810. if (quest) {
  3811. const char* taskgroup = 0;
  3812. if (str_taskgroup.length() > 0)
  3813. taskgroup = str_taskgroup.c_str();
  3814. vector<Location>* locations = 0;
  3815. int8 i = 7;
  3816. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3817. while (true) {
  3818. Location loc;
  3819. loc.x = lua_interface->GetFloatValue(state, i);
  3820. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3821. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3822. loc.zone_id = 0;
  3823. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3824. break;
  3825. if (locations == 0)
  3826. locations = new vector<Location>;
  3827. locations->push_back(loc);
  3828. i += 3;
  3829. }
  3830. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3831. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3832. if (quest_step && icon > 0)
  3833. quest_step->SetIcon(icon);
  3834. if (quest->GetPlayer()) {
  3835. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3836. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3837. }
  3838. }
  3839. lua_interface->ResetFunctionStack(state);
  3840. return 0;
  3841. }
  3842. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3843. if (!lua_interface)
  3844. return 0;
  3845. Quest* quest = lua_interface->GetQuest(state);
  3846. int32 step = lua_interface->GetInt32Value(state, 2);
  3847. string description = lua_interface->GetStringValue(state, 3);
  3848. float max_variation = lua_interface->GetFloatValue(state, 4);
  3849. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3850. int16 icon = lua_interface->GetInt16Value(state, 6);
  3851. if (quest) {
  3852. const char* taskgroup = 0;
  3853. if (str_taskgroup.length() > 0)
  3854. taskgroup = str_taskgroup.c_str();
  3855. vector<Location>* locations = 0;
  3856. int i = 7;
  3857. while (true) {
  3858. Location loc;
  3859. loc.x = lua_interface->GetFloatValue(state, i);
  3860. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3861. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3862. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3863. break;
  3864. if (locations == 0)
  3865. locations = new vector<Location>;
  3866. locations->push_back(loc);
  3867. i += 3;
  3868. }
  3869. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3870. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3871. if (quest_step && icon > 0)
  3872. quest_step->SetIcon(icon);
  3873. if (quest->GetPlayer()) {
  3874. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3875. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3876. }
  3877. }
  3878. lua_interface->ResetFunctionStack(state);
  3879. return 0;
  3880. }
  3881. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3882. Quest* quest = lua_interface->GetQuest(state);
  3883. int32 step = lua_interface->GetInt32Value(state, 2);
  3884. string description = lua_interface->GetStringValue(state, 3);
  3885. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3886. float percentage = lua_interface->GetFloatValue(state, 5);
  3887. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3888. int16 icon = lua_interface->GetInt16Value(state, 7);
  3889. if (quest) {
  3890. const char* taskgroup = 0;
  3891. if (str_taskgroup.length() > 0)
  3892. taskgroup = str_taskgroup.c_str();
  3893. int32 spell_id = 0;
  3894. vector<int32>* ids = 0;
  3895. int i = 0;
  3896. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3897. if (ids == 0)
  3898. ids = new vector<int32>;
  3899. ids->push_back(spell_id);
  3900. i++;
  3901. }
  3902. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3903. if (quest_step && icon > 0 && quantity > 0)
  3904. quest_step->SetIcon(icon);
  3905. if (quest->GetPlayer()) {
  3906. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3907. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3908. }
  3909. safe_delete(ids);
  3910. }
  3911. lua_interface->ResetFunctionStack(state);
  3912. return 0;
  3913. }
  3914. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3915. if (!lua_interface)
  3916. return 0;
  3917. Quest* quest = lua_interface->GetQuest(state);
  3918. int32 step = lua_interface->GetInt32Value(state, 2);
  3919. string description = lua_interface->GetStringValue(state, 3);
  3920. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3921. float percentage = lua_interface->GetFloatValue(state, 5);
  3922. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3923. int16 icon = lua_interface->GetInt16Value(state, 7);
  3924. if (quest) {
  3925. const char* taskgroup = 0;
  3926. if (str_taskgroup.length() > 0)
  3927. taskgroup = str_taskgroup.c_str();
  3928. int32 item_id = 0;
  3929. vector<int32>* ids = 0;
  3930. int i = 0;
  3931. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3932. if (ids == 0)
  3933. ids = new vector<int32>;
  3934. ids->push_back(item_id);
  3935. i++;
  3936. }
  3937. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3938. if (quest_step && icon > 0 && quantity > 0)
  3939. quest_step->SetIcon(icon);
  3940. if (quest->GetPlayer()) {
  3941. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3942. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3943. }
  3944. safe_delete(ids);
  3945. }
  3946. lua_interface->ResetFunctionStack(state);
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3950. if (!lua_interface)
  3951. return 0;
  3952. Quest* quest = lua_interface->GetQuest(state);
  3953. int32 step = lua_interface->GetInt32Value(state, 2);
  3954. string description = lua_interface->GetStringValue(state, 3);
  3955. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3956. float percentage = lua_interface->GetFloatValue(state, 5);
  3957. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3958. int16 icon = lua_interface->GetInt16Value(state, 7);
  3959. if (quest) {
  3960. const char* taskgroup = 0;
  3961. if (str_taskgroup.length() > 0)
  3962. taskgroup = str_taskgroup.c_str();
  3963. int32 item_id = 0;
  3964. vector<int32>* ids = 0;
  3965. int i = 0;
  3966. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3967. if (ids == 0)
  3968. ids = new vector<int32>;
  3969. ids->push_back(item_id);
  3970. i++;
  3971. }
  3972. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3973. if (quest_step && icon > 0 && quantity > 0)
  3974. quest_step->SetIcon(icon);
  3975. if (quest->GetPlayer()) {
  3976. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3977. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3978. }
  3979. safe_delete(ids);
  3980. }
  3981. lua_interface->ResetFunctionStack(state);
  3982. return 0;
  3983. }
  3984. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3985. if (!lua_interface)
  3986. return 0;
  3987. Quest* quest = lua_interface->GetQuest(state);
  3988. string action = lua_interface->GetStringValue(state, 2);
  3989. lua_interface->ResetFunctionStack(state);
  3990. if (quest) {
  3991. if (action.length() > 0)
  3992. quest->SetCompleteAction(action);
  3993. }
  3994. return 0;
  3995. }
  3996. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3997. if (!lua_interface)
  3998. return 0;
  3999. Quest* quest = lua_interface->GetQuest(state);
  4000. int32 step = lua_interface->GetInt32Value(state, 2);
  4001. string action = lua_interface->GetStringValue(state, 3);
  4002. lua_interface->ResetFunctionStack(state);
  4003. if (quest) {
  4004. if (step > 0 && action.length() > 0)
  4005. quest->AddCompleteAction(step, action);
  4006. }
  4007. return 0;
  4008. }
  4009. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4010. if (!lua_interface)
  4011. return 0;
  4012. Quest* quest = lua_interface->GetQuest(state);
  4013. int32 step = lua_interface->GetInt32Value(state, 2);
  4014. string action = lua_interface->GetStringValue(state, 3);
  4015. lua_interface->ResetFunctionStack(state);
  4016. if (quest) {
  4017. if (step > 0 && action.length() > 0)
  4018. quest->AddProgressAction(step, action);
  4019. }
  4020. return 0;
  4021. }
  4022. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4023. if (!lua_interface)
  4024. return 0;
  4025. Quest* quest = lua_interface->GetQuest(state);
  4026. string description = lua_interface->GetStringValue(state, 2);
  4027. lua_interface->ResetFunctionStack(state);
  4028. if (quest && description.length() > 0)
  4029. quest->SetDescription(description);
  4030. return 0;
  4031. }
  4032. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4033. if (!lua_interface)
  4034. return 0;
  4035. Quest* quest = lua_interface->GetQuest(state);
  4036. string description = lua_interface->GetStringValue(state, 2);
  4037. lua_interface->ResetFunctionStack(state);
  4038. if (quest && description.length() > 0)
  4039. quest->SetCompletedDescription(description);
  4040. return 0;
  4041. }
  4042. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4043. if (!lua_interface)
  4044. return 0;
  4045. Quest* quest = lua_interface->GetQuest(state);
  4046. int32 step = lua_interface->GetInt32Value(state, 2);
  4047. string description = lua_interface->GetStringValue(state, 3);
  4048. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4049. lua_interface->ResetFunctionStack(state);
  4050. if (quest && step > 0 && description.length() > 0) {
  4051. quest->SetTaskGroupDescription(step, description, display_bullets);
  4052. /* if (quest->GetPlayer()) {
  4053. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4054. if (client)
  4055. client->SendQuestUpdateStep(quest, step, false);
  4056. }*/
  4057. }
  4058. return 0;
  4059. }
  4060. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4061. if (!lua_interface)
  4062. return 0;
  4063. Quest* quest = lua_interface->GetQuest(state);
  4064. int32 step = lua_interface->GetInt32Value(state, 2);
  4065. string description = lua_interface->GetStringValue(state, 3);
  4066. lua_interface->ResetFunctionStack(state);
  4067. if (quest && step > 0 && description.length() > 0) {
  4068. quest->SetStepDescription(step, description);
  4069. /*if (quest->GetPlayer()) {
  4070. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4071. if (client)
  4072. client->SendQuestUpdateStepImmediately(quest, step);
  4073. }*/
  4074. }
  4075. return 0;
  4076. }
  4077. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4078. Quest* quest = lua_interface->GetQuest(state);
  4079. string zone = lua_interface->GetStringValue(state, 2);
  4080. lua_interface->ResetFunctionStack(state);
  4081. if (quest && zone.length() > 0)
  4082. quest->SetZone(zone);
  4083. return 0;
  4084. }
  4085. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4086. if (!lua_interface)
  4087. return 0;
  4088. Quest* quest = lua_interface->GetQuest(state);
  4089. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4090. lua_interface->ResetFunctionStack(state);
  4091. if (quest && spawn) {
  4092. if (spawn->IsPlayer()) {
  4093. Client* client = ((Player*)spawn)->GetClient();
  4094. if (client) {
  4095. client->AddPendingQuestReward(quest);
  4096. }
  4097. }
  4098. }
  4099. return 0;
  4100. }
  4101. int EQ2Emu_lua_Harvest(lua_State* state) {
  4102. if (!lua_interface)
  4103. return 0;
  4104. Spawn* player = lua_interface->GetSpawn(state);
  4105. Spawn* node = lua_interface->GetSpawn(state, 2);
  4106. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4107. Client* client = ((Player*)player)->GetClient();
  4108. if (client) {
  4109. ((GroundSpawn*)node)->ProcessHarvest(client);
  4110. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4111. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4112. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4113. }
  4114. }
  4115. }
  4116. else if (player && player->IsPlayer()) {
  4117. Client* client = ((Player*)player)->GetClient();
  4118. if (client)
  4119. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4120. }
  4121. lua_interface->ResetFunctionStack(state);
  4122. return 0;
  4123. }
  4124. int EQ2Emu_lua_Bind(lua_State* state) {
  4125. if (!lua_interface)
  4126. return 0;
  4127. Spawn* spawn = lua_interface->GetSpawn(state);
  4128. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4129. float x = lua_interface->GetFloatValue(state, 3);
  4130. float y = lua_interface->GetFloatValue(state, 4);
  4131. float z = lua_interface->GetFloatValue(state, 5);
  4132. float h = lua_interface->GetFloatValue(state, 6);
  4133. lua_interface->ResetFunctionStack(state);
  4134. if (!spawn) {
  4135. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4136. return 0;
  4137. }
  4138. if (!spawn->IsPlayer()) {
  4139. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4140. return 0;
  4141. }
  4142. if (zone_id == 0) {
  4143. Client* client = ((Player*)spawn)->GetClient();
  4144. if (!client) {
  4145. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4146. return 0;
  4147. }
  4148. if (!client->Bind())
  4149. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4150. }
  4151. else {
  4152. Player* player = (Player*)spawn;
  4153. player->GetPlayerInfo()->SetBindZone(zone_id);
  4154. player->GetPlayerInfo()->SetBindX(x);
  4155. player->GetPlayerInfo()->SetBindY(y);
  4156. player->GetPlayerInfo()->SetBindZ(z);
  4157. player->GetPlayerInfo()->SetBindHeading(h);
  4158. }
  4159. return 0;
  4160. }
  4161. int EQ2Emu_lua_Gate(lua_State* state) {
  4162. if (!lua_interface)
  4163. return 0;
  4164. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4165. Spawn* spawn = lua_interface->GetSpawn(state);
  4166. lua_interface->ResetFunctionStack(state);
  4167. if (spawn) {
  4168. if (spawn->IsPlayer()) {
  4169. Client* client = ((Player*)spawn)->GetClient();
  4170. if (client) {
  4171. if (!client->Gate((spell != nullptr) ? true : false))
  4172. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4173. }
  4174. }
  4175. }
  4176. return 0;
  4177. }
  4178. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4179. if (!lua_interface)
  4180. return 0;
  4181. bool ret = false;
  4182. Spawn* spawn = lua_interface->GetSpawn(state);
  4183. lua_interface->ResetFunctionStack(state);
  4184. if (spawn) {
  4185. if (spawn->IsPlayer()) {
  4186. Client* client = ((Player*)spawn)->GetClient();
  4187. if (client)
  4188. ret = client->BindAllowed();
  4189. }
  4190. }
  4191. lua_interface->SetBooleanValue(state, ret);
  4192. return 1;
  4193. }
  4194. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4195. if (!lua_interface)
  4196. return 0;
  4197. bool ret = false;
  4198. Spawn* spawn = lua_interface->GetSpawn(state);
  4199. lua_interface->ResetFunctionStack(state);
  4200. if (spawn) {
  4201. if (spawn->IsPlayer()) {
  4202. Client* client = ((Player*)spawn)->GetClient();
  4203. ZoneServer* zone = lua_interface->GetZone(state);
  4204. if (client && zone){
  4205. ret = zone->GetCanGate();
  4206. }
  4207. }
  4208. }
  4209. lua_interface->SetBooleanValue(state, ret);
  4210. return 1;
  4211. }
  4212. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4213. Spawn* spawn = lua_interface->GetSpawn(state);
  4214. lua_interface->ResetFunctionStack(state);
  4215. if (spawn) {
  4216. lua_interface->SetBooleanValue(state, spawn->Alive());
  4217. return 1;
  4218. }
  4219. return 0;
  4220. }
  4221. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4222. if (!lua_interface)
  4223. return 0;
  4224. Spawn* spawn = lua_interface->GetSpawn(state);
  4225. lua_interface->ResetFunctionStack(state);
  4226. if (spawn && spawn->IsEntity()) {
  4227. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4228. return 1;
  4229. }
  4230. return 0;
  4231. }
  4232. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4233. Spawn* spawn = lua_interface->GetSpawn(state);
  4234. string message = lua_interface->GetStringValue(state, 2);
  4235. string color_str = lua_interface->GetStringValue(state, 3);
  4236. lua_interface->ResetFunctionStack(state);
  4237. int8 color = CHANNEL_NARRATIVE;
  4238. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4239. Client* client = ((Player*)spawn)->GetClient();
  4240. if (client) {
  4241. if (color_str.length() > 0) {
  4242. // leave for backwards compat, but all future should just use the number
  4243. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4244. color = CHANNEL_COLOR_RED;
  4245. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4246. color = CHANNEL_COLOR_YELLOW;
  4247. else
  4248. {
  4249. // use a number to specify the channel as per Commands/Commands.h defines
  4250. color = (int8)atoul(color_str.c_str());
  4251. }
  4252. }
  4253. client->SimpleMessage(color, message.c_str());
  4254. }
  4255. }
  4256. return 0;
  4257. }
  4258. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4259. Spawn* spawn = lua_interface->GetSpawn(state);
  4260. string message = lua_interface->GetStringValue(state, 2);
  4261. int8 red = lua_interface->GetInt8Value(state, 3);
  4262. int8 green = lua_interface->GetInt8Value(state, 4);
  4263. int8 blue = lua_interface->GetInt8Value(state, 5);
  4264. lua_interface->ResetFunctionStack(state);
  4265. if (!spawn) {
  4266. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4267. return 0;
  4268. }
  4269. if (!spawn->IsPlayer()) {
  4270. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4271. return 0;
  4272. }
  4273. int32 words = ::CountWordsInString(message.c_str());
  4274. if (words < 5)
  4275. words = 5;
  4276. Client* client = ((Player*)spawn)->GetClient();
  4277. if (client)
  4278. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4279. return 0;
  4280. }
  4281. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4282. Spawn* spawn = lua_interface->GetSpawn(state);
  4283. int8 param = lua_interface->GetInt8Value(state, 2);
  4284. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4285. int8 value = lua_interface->GetInt8Value(state, 4);
  4286. lua_interface->ResetFunctionStack(state);
  4287. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4288. Client* client = ((Player*)spawn)->GetClient();
  4289. if (client) {
  4290. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4291. switch (param) {
  4292. case 1: {
  4293. packet->setDataByName("parameter1", param_value);
  4294. break;
  4295. }
  4296. case 2: {
  4297. packet->setDataByName("parameter2", param_value);
  4298. break;
  4299. }
  4300. case 3: {
  4301. packet->setDataByName("parameter3", param_value);
  4302. break;
  4303. }
  4304. case 4: {
  4305. packet->setDataByName("parameter4", param_value);
  4306. break;
  4307. }
  4308. case 5: {
  4309. packet->setDataByName("parameter5", param_value);
  4310. break;
  4311. }
  4312. }
  4313. packet->setDataByName("value", value);
  4314. client->QueuePacket(packet->serialize());
  4315. safe_delete(packet);
  4316. }
  4317. }
  4318. return 0;
  4319. }
  4320. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4321. Spawn* spawn = lua_interface->GetSpawn(state);
  4322. lua_interface->ResetFunctionStack(state);
  4323. if (spawn && spawn->IsPlayer()) {
  4324. if (((Player*)spawn)->GetIsTracking())
  4325. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4326. else
  4327. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4328. }
  4329. return 0;
  4330. }
  4331. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4332. Spawn* player = lua_interface->GetSpawn(state);
  4333. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4334. string name = lua_interface->GetStringValue(state, 3);
  4335. float distance = lua_interface->GetFloatValue(state, 4);
  4336. string command = lua_interface->GetStringValue(state, 5);
  4337. string error_text = lua_interface->GetStringValue(state, 6);
  4338. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4339. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4340. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4341. lua_interface->ResetFunctionStack(state);
  4342. if (spawn) {
  4343. if (distance == 0)
  4344. distance = 10.0f;
  4345. if (command.length() == 0)
  4346. command = name;
  4347. if (command.length() < 1 && name.length() < 1)
  4348. {
  4349. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4350. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4351. spawn->RemovePrimaryCommands();
  4352. }
  4353. else
  4354. {
  4355. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4356. }
  4357. }
  4358. return 0;
  4359. }
  4360. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4361. if (!lua_interface)
  4362. return 0;
  4363. Spawn* player = lua_interface->GetSpawn(state);
  4364. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4365. int16 tier = lua_interface->GetInt16Value(state, 3);
  4366. lua_interface->ResetFunctionStack(state);
  4367. if (player && player->IsPlayer()) {
  4368. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4369. return 1;
  4370. }
  4371. return 0;
  4372. }
  4373. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4374. if (!lua_interface)
  4375. return 0;
  4376. Spawn* player = lua_interface->GetSpawn(state);
  4377. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4378. int16 tier = lua_interface->GetInt16Value(state, 3);
  4379. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4380. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4381. bool add_to_hotbar = true;
  4382. if (num_args > 4) {
  4383. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4384. }
  4385. lua_interface->ResetFunctionStack(state);
  4386. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4387. if (player && spell && player->IsPlayer()) {
  4388. Client* client = player->GetClient();
  4389. if (client) {
  4390. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4391. {
  4392. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4393. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4394. client->GetPlayer()->UnlockSpell(spell);
  4395. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4396. }
  4397. else
  4398. {
  4399. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4400. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4401. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4402. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4403. client->GetPlayer()->UnlockSpell(spell);
  4404. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4405. }
  4406. //if (client ) {
  4407. // ((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);
  4408. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4409. if (outapp)
  4410. client->QueuePacket(outapp);
  4411. }
  4412. }
  4413. return 0;
  4414. }
  4415. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4416. if (!lua_interface)
  4417. return 0;
  4418. Spawn* player = lua_interface->GetSpawn(state);
  4419. lua_interface->ResetFunctionStack(state);
  4420. if (player && player->IsPlayer()) {
  4421. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4422. return 1;
  4423. }
  4424. return 0;
  4425. }
  4426. int EQ2Emu_lua_Attack(lua_State* state) {
  4427. if (lua_interface) {
  4428. Spawn* npc = lua_interface->GetSpawn(state);
  4429. Spawn* player = lua_interface->GetSpawn(state, 2);
  4430. lua_interface->ResetFunctionStack(state);
  4431. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4432. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4433. }
  4434. return 0;
  4435. }
  4436. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4437. if (lua_interface) {
  4438. Spawn* target = lua_interface->GetSpawn(state);
  4439. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4440. lua_interface->ResetFunctionStack(state);
  4441. if (target && target->GetZone())
  4442. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4443. }
  4444. return 0;
  4445. }
  4446. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4447. Spawn* player;
  4448. if (lua_interface) {
  4449. player = lua_interface->GetSpawn(state);
  4450. lua_interface->ResetFunctionStack(state);
  4451. if (player && player->IsPlayer()) {
  4452. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4453. return 1;
  4454. }
  4455. }
  4456. return 0;
  4457. }
  4458. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4459. Spawn* player;
  4460. Client* client;
  4461. if (lua_interface) {
  4462. player = lua_interface->GetSpawn(state);
  4463. lua_interface->ResetFunctionStack(state);
  4464. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4465. if ((client = ((Player*)player)->GetClient()))
  4466. client->HandInCollections();
  4467. }
  4468. return 0;
  4469. }
  4470. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4471. Spawn* widget;
  4472. if (lua_interface) {
  4473. widget = lua_interface->GetSpawn(state);
  4474. lua_interface->ResetFunctionStack(state);
  4475. if (widget && widget->IsWidget())
  4476. ((Widget*)widget)->HandleUse(nullptr, "");
  4477. }
  4478. return 0;
  4479. }
  4480. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4481. Spawn* spawn = 0;
  4482. int32 primary_list = 0;
  4483. int32 secondary_list = 0;
  4484. if (lua_interface) {
  4485. spawn = lua_interface->GetSpawn(state);
  4486. primary_list = lua_interface->GetInt32Value(state, 2);
  4487. secondary_list = lua_interface->GetInt32Value(state, 3);
  4488. lua_interface->ResetFunctionStack(state);
  4489. if (!spawn->IsNPC()) {
  4490. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4491. return 0;
  4492. }
  4493. NPC* npc = (NPC*)spawn;
  4494. npc->SetPrimarySpellList(primary_list);
  4495. npc->SetSecondarySpellList(secondary_list);
  4496. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4497. }
  4498. return 0;
  4499. }
  4500. int EQ2Emu_lua_GetPet(lua_State* state) {
  4501. if (!lua_interface)
  4502. return 0;
  4503. Spawn* spawn = lua_interface->GetSpawn(state);
  4504. lua_interface->ResetFunctionStack(state);
  4505. if (spawn) {
  4506. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4507. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4508. return 1;
  4509. }
  4510. }
  4511. return 0;
  4512. }
  4513. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4514. if (!lua_interface)
  4515. return 0;
  4516. Spawn* spawn = lua_interface->GetSpawn(state);
  4517. lua_interface->ResetFunctionStack(state);
  4518. if (spawn) {
  4519. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4520. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4521. return 1;
  4522. }
  4523. }
  4524. return 0;
  4525. }
  4526. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4527. if (!lua_interface)
  4528. return 0;
  4529. Spawn* spawn = lua_interface->GetSpawn(state);
  4530. lua_interface->ResetFunctionStack(state);
  4531. if (spawn) {
  4532. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4533. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4534. return 1;
  4535. }
  4536. }
  4537. return 0;
  4538. }
  4539. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4540. if (!lua_interface)
  4541. return 0;
  4542. Spawn* spawn = lua_interface->GetSpawn(state);
  4543. lua_interface->ResetFunctionStack(state);
  4544. if (spawn) {
  4545. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4546. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4547. return 1;
  4548. }
  4549. }
  4550. return 0;
  4551. }
  4552. int EQ2Emu_lua_Charm(lua_State* state) {
  4553. if (!lua_interface)
  4554. return 0;
  4555. Spawn* owner = lua_interface->GetSpawn(state);
  4556. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4557. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4558. lua_interface->ResetFunctionStack(state);
  4559. if (!luaspell) {
  4560. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4561. return 0;
  4562. }
  4563. if(luaspell->resisted) {
  4564. return 0;
  4565. }
  4566. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4567. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4568. pet->SetPet(true);
  4569. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4570. ((NPC*)pet)->SetOwner((Entity*)owner);
  4571. // If owner is player and player does not have a summoned pet set the players charsheet
  4572. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4573. Player* player = (Player*)owner;
  4574. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4575. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4576. player->GetInfoStruct()->set_pet_movement(2);
  4577. player->GetInfoStruct()->set_pet_behavior(3);
  4578. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4579. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4580. // Make sure the values get sent to the client
  4581. player->SetCharSheetChanged(true);
  4582. }
  4583. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4584. pet->SetSpawnScript("");
  4585. // Set faction to the same as the owner
  4586. pet->SetFactionID(owner->GetFactionID());
  4587. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4588. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4589. // Clear hate list
  4590. ((NPC*)pet)->Brain()->ClearHate();
  4591. // Set the brain to a pet brain
  4592. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4593. }
  4594. return 0;
  4595. }
  4596. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4597. if (!lua_interface)
  4598. return 0;
  4599. Spawn* spawn = lua_interface->GetSpawn(state);
  4600. lua_interface->ResetFunctionStack(state);
  4601. if (!spawn) {
  4602. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4603. return 0;
  4604. }
  4605. vector<Spawn*> groupMembers;
  4606. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4607. groupMembers = *spawn->GetSpawnGroup();
  4608. }
  4609. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4610. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4611. deque<GroupMemberInfo*>::iterator itr;
  4612. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4613. if (group)
  4614. {
  4615. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4616. deque<GroupMemberInfo*>* members = group->GetMembers();
  4617. GroupMemberInfo* info = 0;
  4618. for (itr = members->begin(); itr != members->end(); itr++) {
  4619. info = *itr;
  4620. if (info->client)
  4621. groupMembers.push_back(info->client->GetPlayer());
  4622. }
  4623. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4624. }
  4625. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4626. }
  4627. else
  4628. return 0;
  4629. lua_createtable(state, groupMembers.size(), 0);
  4630. int newTable = lua_gettop(state);
  4631. for (int32 i = 0; i < groupMembers.size(); i++) {
  4632. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4633. lua_rawseti(state, newTable, i + 1);
  4634. }
  4635. return 1;
  4636. }
  4637. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4638. if (!lua_interface)
  4639. return 0;
  4640. lua_interface->ResetFunctionStack(state);
  4641. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4642. lua_interface->SetOptionWindowValue(state, option_window);
  4643. return 1;
  4644. }
  4645. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4646. if (!lua_interface)
  4647. return 0;
  4648. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4649. if (option_window) {
  4650. OptionWindowOption option_window_option;
  4651. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4652. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4653. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4654. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4655. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4656. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4657. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4658. option_window->push_back(option_window_option);
  4659. }
  4660. lua_interface->ResetFunctionStack(state);
  4661. return 0;
  4662. }
  4663. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4664. if (!lua_interface)
  4665. return 0;
  4666. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4667. Spawn* player = lua_interface->GetSpawn(state, 2);
  4668. string window_title = lua_interface->GetStringValue(state, 3);
  4669. string cancel_command = lua_interface->GetStringValue(state, 4);
  4670. lua_interface->ResetFunctionStack(state);
  4671. if (!player->IsPlayer()) {
  4672. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4673. return 0;
  4674. }
  4675. Client* client = ((Player*)player)->GetClient();
  4676. if (option_window && window_title.length() > 0 && client) {
  4677. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4678. if (!packet)
  4679. return 0;
  4680. packet->setDataByName("title_text", window_title.c_str());
  4681. if (cancel_command.length() > 0)
  4682. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4683. packet->setArrayLengthByName("num_selections", option_window->size());
  4684. vector<OptionWindowOption>::iterator itr;
  4685. int8 i = 0;
  4686. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4687. OptionWindowOption opt = *itr;
  4688. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4689. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4690. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4691. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4692. if (opt.optionCommand.length() > 0)
  4693. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4694. if (opt.optionConfirmTitle.length() > 0)
  4695. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4696. i++;
  4697. }
  4698. client->QueuePacket(packet->serialize());
  4699. safe_delete(option_window);
  4700. safe_delete(packet);
  4701. }
  4702. return 0;
  4703. }
  4704. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4705. if (!lua_interface)
  4706. return 0;
  4707. Spawn* spawn = lua_interface->GetSpawn(state);
  4708. lua_interface->ResetFunctionStack(state);
  4709. if (spawn) {
  4710. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4711. return 1;
  4712. }
  4713. else
  4714. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4715. return 0;
  4716. }
  4717. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4718. if (!lua_interface)
  4719. return 0;
  4720. Spawn* spawn = lua_interface->GetSpawn(state);
  4721. lua_interface->ResetFunctionStack(state);
  4722. if (spawn) {
  4723. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4724. return 1;
  4725. }
  4726. else
  4727. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4728. return 0;
  4729. }
  4730. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4731. if (!lua_interface)
  4732. return 0;
  4733. Spawn* spawn = lua_interface->GetSpawn(state);
  4734. lua_interface->ResetFunctionStack(state);
  4735. if (spawn) {
  4736. int8 class_id = spawn->GetTradeskillClass();
  4737. // Need to add 42 for the offset in the array
  4738. class_id += 44;
  4739. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4740. return 1;
  4741. }
  4742. else
  4743. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4744. return 0;
  4745. }
  4746. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4747. if (!lua_interface)
  4748. return 0;
  4749. Spawn* spawn = lua_interface->GetSpawn(state);
  4750. int16 level = lua_interface->GetInt8Value(state, 2);
  4751. lua_interface->ResetFunctionStack(state);
  4752. if (spawn) {
  4753. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4754. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4755. else
  4756. spawn->SetTSLevel(level);
  4757. }
  4758. else
  4759. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4760. return 0;
  4761. }
  4762. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4763. if (!lua_interface)
  4764. return 0;
  4765. Spawn* spawn = lua_interface->GetSpawn(state);
  4766. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4767. lua_interface->ResetFunctionStack(state);
  4768. if (spawn) {
  4769. spawn->SetAttackable(attackable);
  4770. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4771. }
  4772. return 0;
  4773. }
  4774. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4775. // Check to see if we have a valid lua_interface
  4776. if (!lua_interface)
  4777. return 0;
  4778. // Get the spawn that is getting the pet
  4779. Spawn* spawn = lua_interface->GetSpawn(state);
  4780. // Get the DB ID of the pet
  4781. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4782. // The max level the pet can gain
  4783. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4784. // Get the spell that this command was called from
  4785. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4786. lua_interface->ResetFunctionStack(state);
  4787. // Check to make sure the spawn pointer is valid
  4788. if (!spawn) {
  4789. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4790. return 0;
  4791. }
  4792. // Check to make sure the spawn is an entity
  4793. if (!spawn->IsEntity()) {
  4794. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4795. return 0;
  4796. }
  4797. // Check to make sure the spawn doesn't already have a pet of this type
  4798. if (((Entity*)spawn)->GetPet()) {
  4799. if (spawn->IsPlayer()) {
  4800. Client* client = ((Player*)spawn)->GetClient();
  4801. if (client)
  4802. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4803. }
  4804. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4805. return 0;
  4806. }
  4807. // Check to see if the DB ID for the pet is set
  4808. if (pet_id == 0) {
  4809. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4810. return 0;
  4811. }
  4812. // Check to see if the pointer to the spell is valid
  4813. if (!luaspell) {
  4814. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4815. return 0;
  4816. }
  4817. if(luaspell->resisted) {
  4818. return 0;
  4819. }
  4820. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4821. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4822. if (!pet) {
  4823. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4824. return 0;
  4825. }
  4826. // Check to make sure the pet is an npc
  4827. if (!pet->IsNPC()) {
  4828. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4829. return 0;
  4830. }
  4831. // Spawn the pet at the same location as the owner
  4832. pet->SetX(spawn->GetX());
  4833. pet->SetY(spawn->GetY());
  4834. pet->SetZ(spawn->GetZ());
  4835. pet->SetLocation(spawn->GetLocation());
  4836. pet->SetHeading(spawn->GetHeading());
  4837. spawn->GetZone()->AddSpawn(pet);
  4838. /*
  4839. const char* spawn_script = world.GetSpawnScript(pet_id);
  4840. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4841. spawn->SetSpawnScript(string(spawn_script));
  4842. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4843. }*/
  4844. // Get a random pet name
  4845. string random_pet_name;
  4846. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4847. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4848. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4849. // If player set various values for the char sheet (pet window)
  4850. if (spawn->IsPlayer()) {
  4851. Player* player = (Player*)spawn;
  4852. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4853. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4854. player->GetInfoStruct()->set_pet_movement(2);
  4855. player->GetInfoStruct()->set_pet_behavior(3);
  4856. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4857. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4858. // Make sure the values get sent to the client
  4859. player->SetCharSheetChanged(true);
  4860. }
  4861. // Set the pets name
  4862. pet->SetName(random_pet_name.c_str());
  4863. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4864. if (max_level > 0)
  4865. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4866. else
  4867. pet->SetLevel(spawn->GetLevel());
  4868. // Set the max level this pet can reach
  4869. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4870. // Set the faction of the pet to the same faction as the owner
  4871. pet->SetFactionID(spawn->GetFactionID());
  4872. // Set the spawn as a pet
  4873. pet->SetPet(true);
  4874. // Give a pointer of the owner to the pet
  4875. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4876. // Give a pointer of the pet to the owner
  4877. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4878. // Set the pet type
  4879. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4880. // Set the spell id used to create this pet
  4881. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4882. // Set the spell tier used to create this pet
  4883. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4884. // Set the pets spawn type to 6
  4885. pet->SetSpawnType(6);
  4886. // Set the pets brain
  4887. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4888. // Check to see if the pet has a subtitle
  4889. if (strlen(pet->GetSubTitle()) > 0) {
  4890. // Add the players name to the front of the sub title
  4891. string pet_subtitle;
  4892. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4893. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4894. // Set the pets subtitle to the new one
  4895. pet->SetSubTitle(pet_subtitle.c_str());
  4896. }
  4897. // Add the "Pet Options" entity command to the pet
  4898. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4899. // Set the pet as the return value for this function
  4900. lua_interface->SetSpawnValue(state, pet);
  4901. return 1;
  4902. }
  4903. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4904. if (!lua_interface)
  4905. return 0;
  4906. Spawn* spawn = lua_interface->GetSpawn(state);
  4907. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4908. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4909. lua_interface->ResetFunctionStack(state);
  4910. if (!spawn) {
  4911. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4912. return 0;
  4913. }
  4914. if (!spawn->IsEntity()) {
  4915. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4916. return 0;
  4917. }
  4918. if (((Entity*)spawn)->GetDeityPet()) {
  4919. if (spawn->IsPlayer()) {
  4920. Client* client = ((Player*)spawn)->GetClient();
  4921. if (client)
  4922. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4923. }
  4924. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4925. return 0;
  4926. }
  4927. if (pet_id == 0) {
  4928. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4929. return 0;
  4930. }
  4931. if (!luaspell) {
  4932. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4933. return 0;
  4934. }
  4935. if(luaspell->resisted) {
  4936. return 0;
  4937. }
  4938. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4939. if (!pet) {
  4940. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4941. return 0;
  4942. }
  4943. if (!pet->IsNPC()) {
  4944. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4945. return 0;
  4946. }
  4947. pet->SetX(spawn->GetX());
  4948. pet->SetY(spawn->GetY());
  4949. pet->SetZ(spawn->GetZ());
  4950. pet->SetLocation(spawn->GetLocation());
  4951. pet->SetHeading(spawn->GetHeading());
  4952. spawn->GetZone()->AddSpawn(pet);
  4953. string random_pet_name;
  4954. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4955. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4956. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4957. pet->SetName(random_pet_name.c_str());
  4958. pet->SetLevel(spawn->GetLevel());
  4959. pet->SetFactionID(spawn->GetFactionID());
  4960. pet->SetPet(true);
  4961. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4962. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4963. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4964. pet->SetSpawnType(6);
  4965. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4966. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4967. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4968. if (strlen(pet->GetSubTitle()) > 0) {
  4969. string pet_subtitle;
  4970. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4971. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4972. pet->SetSubTitle(pet_subtitle.c_str());
  4973. }
  4974. // deity and cosmetic pets are not attackable
  4975. pet->SetAttackable(false);
  4976. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4977. lua_interface->SetSpawnValue(state, pet);
  4978. return 1;
  4979. }
  4980. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4981. if (!lua_interface)
  4982. return 0;
  4983. Spawn* spawn = lua_interface->GetSpawn(state);
  4984. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4985. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4986. lua_interface->ResetFunctionStack(state);
  4987. if (!spawn) {
  4988. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4989. return 0;
  4990. }
  4991. if (!spawn->IsEntity()) {
  4992. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4993. return 0;
  4994. }
  4995. if (((Entity*)spawn)->GetCosmeticPet()) {
  4996. if (spawn->IsPlayer()) {
  4997. Client* client = ((Player*)spawn)->GetClient();
  4998. if (client)
  4999. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5000. }
  5001. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5002. return 0;
  5003. }
  5004. if (pet_id == 0) {
  5005. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5006. return 0;
  5007. }
  5008. if (!luaspell) {
  5009. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5010. return 0;
  5011. }
  5012. if(luaspell->resisted) {
  5013. return 0;
  5014. }
  5015. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5016. if (!pet) {
  5017. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5018. return 0;
  5019. }
  5020. if (!pet->IsNPC()) {
  5021. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5022. return 0;
  5023. }
  5024. pet->SetX(spawn->GetX());
  5025. pet->SetY(spawn->GetY());
  5026. pet->SetZ(spawn->GetZ());
  5027. pet->SetLocation(spawn->GetLocation());
  5028. pet->SetHeading(spawn->GetHeading());
  5029. spawn->GetZone()->AddSpawn(pet);
  5030. string random_pet_name;
  5031. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5032. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5033. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5034. pet->SetName(random_pet_name.c_str());
  5035. pet->SetLevel(spawn->GetLevel());
  5036. pet->SetFactionID(spawn->GetFactionID());
  5037. pet->SetPet(true);
  5038. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5039. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5040. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5041. pet->SetSpawnType(6);
  5042. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5043. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5044. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5045. if (strlen(pet->GetSubTitle()) > 0) {
  5046. string pet_subtitle;
  5047. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5048. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5049. pet->SetSubTitle(pet_subtitle.c_str());
  5050. }
  5051. pet->SetAttackable(false);
  5052. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5053. lua_interface->SetSpawnValue(state, pet);
  5054. return 1;
  5055. }
  5056. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5057. if (!lua_interface)
  5058. return 0;
  5059. Spawn* spawn = lua_interface->GetSpawn(state);
  5060. lua_interface->ResetFunctionStack(state);
  5061. if (!spawn) {
  5062. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5063. return 0;
  5064. }
  5065. if (!spawn->IsPet()) {
  5066. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5067. return 0;
  5068. }
  5069. if (!((NPC*)spawn)->IsDismissing())
  5070. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5071. return 0;
  5072. }
  5073. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5074. if (!lua_interface)
  5075. return 0;
  5076. Quest* quest = lua_interface->GetQuest(state);
  5077. if (!quest) {
  5078. 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));
  5079. lua_interface->ResetFunctionStack(state);
  5080. return 0;
  5081. }
  5082. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5083. lua_interface->ResetFunctionStack(state);
  5084. if (feather_color > 0)
  5085. quest->SetFeatherColor(feather_color);
  5086. return 0;
  5087. }
  5088. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5089. if (!lua_interface)
  5090. return 0;
  5091. Spawn* spawn = lua_interface->GetSpawn(state);
  5092. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5093. lua_interface->ResetFunctionStack(state);
  5094. if (!spawn) {
  5095. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5096. return 0;
  5097. }
  5098. if (!spawn2) {
  5099. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5100. return 0;
  5101. }
  5102. spawn->RemoveSpawnAccess(spawn2);
  5103. return 0;
  5104. }
  5105. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5106. if (!lua_interface)
  5107. return 0;
  5108. ZoneServer* zone = lua_interface->GetZone(state);
  5109. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5110. lua_interface->ResetFunctionStack(state);
  5111. if (!zone) {
  5112. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5113. return 0;
  5114. }
  5115. if (location_id == 0) {
  5116. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5117. return 0;
  5118. }
  5119. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5120. if (!location) {
  5121. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5122. return 0;
  5123. }
  5124. Spawn* spawn = 0;
  5125. if (location->entities[0]) {
  5126. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5127. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5128. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5129. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5130. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5131. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5132. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5133. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5134. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5135. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5136. if(spawn && spawn->IsOmittedByDBFlag())
  5137. {
  5138. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5139. safe_delete(spawn);
  5140. spawn = 0;
  5141. return 0;
  5142. }
  5143. if (spawn) {
  5144. const char* script = 0;
  5145. for (int x = 0; x < 3; x++) {
  5146. switch (x) {
  5147. case 0:
  5148. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5149. break;
  5150. case 1:
  5151. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5152. break;
  5153. case 2:
  5154. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5155. break;
  5156. }
  5157. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5158. spawn->SetSpawnScript(string(script));
  5159. break;
  5160. }
  5161. }
  5162. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5163. lua_interface->SetSpawnValue(state, spawn);
  5164. return 1;
  5165. }
  5166. else {
  5167. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5168. safe_delete(spawn);
  5169. }
  5170. }
  5171. return 0;
  5172. }
  5173. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5174. if (!lua_interface)
  5175. return 0;
  5176. Spawn* caster = lua_interface->GetSpawn(state);
  5177. Spawn* target = lua_interface->GetSpawn(state, 2);
  5178. int32 id = lua_interface->GetInt32Value(state, 3);
  5179. string command = lua_interface->GetStringValue(state, 4);
  5180. lua_interface->ResetFunctionStack(state);
  5181. if (!caster) {
  5182. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5183. return 0;
  5184. }
  5185. if (!target) {
  5186. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5187. return 0;
  5188. }
  5189. if (!caster->IsPlayer()) {
  5190. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5191. return 0;
  5192. }
  5193. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5194. if (!entity_command) {
  5195. 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());
  5196. return 0;
  5197. }
  5198. Client* client = ((Player*)caster)->GetClient();
  5199. if (!client) {
  5200. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5201. return 0;
  5202. }
  5203. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5204. return 0;
  5205. }
  5206. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5207. if (!lua_interface)
  5208. return 0;
  5209. Spawn* spawn = lua_interface->GetSpawn(state);
  5210. lua_interface->ResetFunctionStack(state);
  5211. if (!spawn) {
  5212. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5213. return 0;
  5214. }
  5215. if (!spawn->IsNPC()) {
  5216. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5217. return 0;
  5218. }
  5219. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5220. return 0;
  5221. }
  5222. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5223. if (!lua_interface)
  5224. return 0;
  5225. Spawn* spawn = lua_interface->GetSpawn(state);
  5226. int16 tick = lua_interface->GetInt16Value(state, 2);
  5227. lua_interface->ResetFunctionStack(state);
  5228. if (!spawn) {
  5229. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5230. return 0;
  5231. }
  5232. if (!spawn->IsNPC()) {
  5233. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5234. return 0;
  5235. }
  5236. if (tick < 20) {
  5237. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5238. return 0;
  5239. }
  5240. ((NPC*)spawn)->Brain()->SetTick(tick);
  5241. return 0;
  5242. }
  5243. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5244. if (!lua_interface)
  5245. return 0;
  5246. Spawn* spawn = lua_interface->GetSpawn(state);
  5247. Spawn* target = lua_interface->GetSpawn(state, 2);
  5248. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5249. lua_interface->ResetFunctionStack(state);
  5250. if (!spawn) {
  5251. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5252. return 0;
  5253. }
  5254. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5255. spawn->SetFollowTarget(target, follow_distance);
  5256. return 0;
  5257. }
  5258. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5259. if (!lua_interface)
  5260. return 0;
  5261. Spawn* spawn = lua_interface->GetSpawn(state);
  5262. lua_interface->ResetFunctionStack(state);
  5263. if (!spawn) {
  5264. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5265. return 0;
  5266. }
  5267. Spawn* target = spawn->GetFollowTarget();
  5268. if (target) {
  5269. lua_interface->SetSpawnValue(state, target);
  5270. return 1;
  5271. }
  5272. return 0;
  5273. }
  5274. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5275. if (!lua_interface)
  5276. return 0;
  5277. Spawn* spawn = lua_interface->GetSpawn(state);
  5278. lua_interface->ResetFunctionStack(state);
  5279. if (!spawn) {
  5280. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5281. return 0;
  5282. }
  5283. if (spawn->following)
  5284. spawn->following = false;
  5285. else
  5286. spawn->following = true;
  5287. return 0;
  5288. }
  5289. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5290. if (!lua_interface)
  5291. return 0;
  5292. Spawn* spawn = lua_interface->GetSpawn(state);
  5293. lua_interface->ResetFunctionStack(state);
  5294. if (!spawn) {
  5295. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5296. return 0;
  5297. }
  5298. lua_interface->SetBooleanValue(state, spawn->following);
  5299. return 1;
  5300. }
  5301. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5302. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5303. // I will attempt to explain how this function works for future refrence
  5304. // Fist lets make sure lua_interface is valid, if not return out
  5305. if (!lua_interface)
  5306. return 0;
  5307. // Next we grab the first 2 params same as we usually would
  5308. Spawn* spawn = lua_interface->GetSpawn(state);
  5309. string var = lua_interface->GetStringValue(state, 2);
  5310. // 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
  5311. // 1 = Spawn
  5312. // 2 = Zone
  5313. // 3 = Item
  5314. // 4 = Quest
  5315. // 5 = String
  5316. // 6 = nil (null)
  5317. int8 dataType = 0;
  5318. // Define pointers for each potential type
  5319. Spawn* spawnVal = 0;
  5320. ZoneServer* zone = 0;
  5321. Item* item = 0;
  5322. Quest* quest = 0;
  5323. string val;
  5324. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5325. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5326. // options window are also light user data be we do not handle those.
  5327. // We check with lua_islightuserdata(lua_State*, index)
  5328. if (lua_islightuserdata(state, 3)) {
  5329. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5330. // and convert it to LUAUserData*
  5331. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5332. // Check to make sure the data we got is valid, if not give an error
  5333. if (!data || !data->IsCorrectlyInitialized()) {
  5334. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5335. }
  5336. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5337. else if (data->IsSpawn()) {
  5338. spawnVal = data->spawn;
  5339. dataType = 1;
  5340. }
  5341. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5342. else if (data->IsZone()) {
  5343. zone = data->zone;
  5344. dataType = 2;
  5345. }
  5346. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5347. else if (data->IsItem()) {
  5348. item = data->item;
  5349. dataType = 3;
  5350. }
  5351. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5352. else if (data->IsQuest()) {
  5353. quest = data->quest;
  5354. dataType = 4;
  5355. }
  5356. }
  5357. // Wasn't light user data, check if it is nil(null)
  5358. else if (lua_isnil(state, 3)) {
  5359. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5360. dataType = 6;
  5361. }
  5362. // Wasn't light user data or nil (null), must be a string
  5363. else {
  5364. // Set the string and dataType variable
  5365. val = lua_interface->GetStringValue(state, 3);
  5366. dataType = 5;
  5367. }
  5368. lua_interface->ResetFunctionStack(state);
  5369. // We now have all the params, lets check to make sure they are valid
  5370. if (!spawn) {
  5371. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5372. return 0;
  5373. }
  5374. if (var.length() == 0) {
  5375. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5376. return 0;
  5377. }
  5378. if (dataType == 0) {
  5379. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5380. return 0;
  5381. }
  5382. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5383. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5384. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5385. switch (dataType) {
  5386. case 1:
  5387. // 1 = Spawn
  5388. spawn->AddTempVariable(var, spawnVal);
  5389. break;
  5390. case 2:
  5391. // 2 = Zone
  5392. spawn->AddTempVariable(var, zone);
  5393. break;
  5394. case 3:
  5395. // 3 = Item
  5396. spawn->AddTempVariable(var, item);
  5397. break;
  5398. case 4:
  5399. // 4 = Quest
  5400. spawn->AddTempVariable(var, quest);
  5401. break;
  5402. case 5:
  5403. // 5 = String
  5404. spawn->AddTempVariable(var, val);
  5405. break;
  5406. case 6:
  5407. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5408. spawn->DeleteTempVariable(var);
  5409. break;
  5410. }
  5411. // And we are done so return out
  5412. return 0;
  5413. }
  5414. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5415. if (!lua_interface)
  5416. return 0;
  5417. Spawn* spawn = lua_interface->GetSpawn(state);
  5418. string var = lua_interface->GetStringValue(state, 2);
  5419. lua_interface->ResetFunctionStack(state);
  5420. if (!spawn) {
  5421. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5422. return 0;
  5423. }
  5424. if (var.length() == 0) {
  5425. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5426. return 0;
  5427. }
  5428. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5429. int8 type = spawn->GetTempVariableType(var);
  5430. Spawn* spawn2 = 0;
  5431. ZoneServer* zone = 0;
  5432. Item* item = 0;
  5433. Quest* quest = 0;
  5434. // Set the lua function return value based on the type of data the variable contains
  5435. switch (type) {
  5436. case 1:
  5437. spawn2 = spawn->GetTempVariableSpawn(var);
  5438. if (!spawn2)
  5439. return 0;
  5440. lua_interface->SetSpawnValue(state, spawn2);
  5441. break;
  5442. case 2:
  5443. zone = spawn->GetTempVariableZone(var);
  5444. if (!zone)
  5445. return 0;
  5446. lua_interface->SetZoneValue(state, zone);
  5447. break;
  5448. case 3:
  5449. item = spawn->GetTempVariableItem(var);
  5450. if (!item)
  5451. return 0;
  5452. lua_interface->SetItemValue(state, item);
  5453. break;
  5454. case 4:
  5455. quest = spawn->GetTempVariableQuest(var);
  5456. if (!quest)
  5457. return 0;
  5458. lua_interface->SetQuestValue(state, quest);
  5459. break;
  5460. case 5:
  5461. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5462. break;
  5463. default:
  5464. // Not a valid type then the variable was not set so return out
  5465. return 0;
  5466. }
  5467. // Return value was set so return out
  5468. return 1;
  5469. }
  5470. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5471. {
  5472. if (!lua_interface)
  5473. return 0;
  5474. Quest* quest = lua_interface->GetQuest(state);
  5475. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5476. string description = lua_interface->GetStringValue(state, 3);
  5477. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5478. if (!quest) {
  5479. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5480. lua_interface->ResetFunctionStack(state);
  5481. lua_interface->SetBooleanValue(state, false);
  5482. return 1;
  5483. }
  5484. if (!spawn) {
  5485. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5486. lua_interface->ResetFunctionStack(state);
  5487. lua_interface->SetBooleanValue(state, false);
  5488. return 1;
  5489. }
  5490. if (!spawn->IsPlayer()) {
  5491. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5492. lua_interface->ResetFunctionStack(state);
  5493. lua_interface->SetBooleanValue(state, false);
  5494. return 1;
  5495. }
  5496. if (item_id == 0) {
  5497. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5498. lua_interface->ResetFunctionStack(state);
  5499. lua_interface->SetBooleanValue(state, false);
  5500. return 1;
  5501. }
  5502. Client* client = ((Player*)spawn)->GetClient();
  5503. if (!client) {
  5504. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5505. lua_interface->ResetFunctionStack(state);
  5506. lua_interface->SetBooleanValue(state, false);
  5507. return 1;
  5508. }
  5509. Item* item = master_item_list.GetItem(item_id);
  5510. if (!item) {
  5511. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5512. lua_interface->ResetFunctionStack(state);
  5513. lua_interface->SetBooleanValue(state, false);
  5514. return 1;
  5515. }
  5516. Item* firstItem = new Item(item);
  5517. quest->AddTmpRewardItem(firstItem);
  5518. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5519. bool itemsAddedSuccessfully = true;
  5520. if(num_args > 4)
  5521. {
  5522. for(int8 n=5;n<num_args+1;n++)
  5523. {
  5524. int32 new_item = lua_interface->GetInt32Value(state, n);
  5525. Item* tmpItem = master_item_list.GetItem(new_item);
  5526. if(tmpItem)
  5527. {
  5528. Item* newTmpItem = new Item(tmpItem);
  5529. quest->AddTmpRewardItem(newTmpItem);
  5530. }
  5531. else
  5532. itemsAddedSuccessfully = false;
  5533. }
  5534. }
  5535. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5536. lua_interface->ResetFunctionStack(state);
  5537. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5538. return 1;
  5539. }
  5540. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5541. if (!lua_interface)
  5542. return 0;
  5543. Quest* quest = lua_interface->GetQuest(state);
  5544. lua_interface->ResetFunctionStack(state);
  5545. if (!quest) {
  5546. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5547. return 0;
  5548. }
  5549. quest->SetRepeatable(true);
  5550. return 0;
  5551. }
  5552. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5553. if (!lua_interface)
  5554. return 0;
  5555. Spawn* spawn = lua_interface->GetSpawn(state);
  5556. lua_interface->ResetFunctionStack(state);
  5557. if (!spawn) {
  5558. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5559. return 0;
  5560. }
  5561. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5562. string ret = classes.GetClassNameCase(base_class);
  5563. if (ret.length() > 0) {
  5564. lua_interface->SetStringValue(state, ret.c_str());
  5565. return 1;
  5566. }
  5567. return 0;
  5568. }
  5569. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5570. if (!lua_interface)
  5571. return 0;
  5572. Spawn* player = lua_interface->GetSpawn(state);
  5573. lua_interface->ResetFunctionStack(state);
  5574. if (player && player->IsPlayer()) {
  5575. Client* client = player->GetClient();
  5576. if (client)
  5577. client->SendWaypoints();
  5578. }
  5579. return 0;
  5580. }
  5581. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5582. if (!lua_interface)
  5583. return 0;
  5584. Spawn* player = lua_interface->GetSpawn(state);
  5585. string name = lua_interface->GetStringValue(state, 2);
  5586. int32 type = lua_interface->GetInt32Value(state, 3);
  5587. lua_interface->ResetFunctionStack(state);
  5588. if (type == 0)
  5589. type = 2;
  5590. if (name.length() > 0) {
  5591. if (player && player->IsPlayer()) {
  5592. Client* client = player->GetClient();
  5593. if (client)
  5594. client->AddWaypoint(name, type);
  5595. }
  5596. }
  5597. return 0;
  5598. }
  5599. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5600. if (!lua_interface)
  5601. return 0;
  5602. Spawn* player = lua_interface->GetSpawn(state);
  5603. string name = lua_interface->GetStringValue(state, 2);
  5604. lua_interface->ResetFunctionStack(state);
  5605. if (name.length() > 0) {
  5606. if (player && player->IsPlayer()) {
  5607. Client* client = player->GetClient();
  5608. if (client)
  5609. client->RemoveWaypoint(name);
  5610. }
  5611. }
  5612. return 0;
  5613. }
  5614. int EQ2Emu_lua_AddWard(lua_State* state) {
  5615. if (!lua_interface)
  5616. return 0;
  5617. int32 damage = lua_interface->GetInt32Value(state);
  5618. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5619. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5620. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5621. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5622. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5623. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5624. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5625. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5626. lua_interface->ResetFunctionStack(state);
  5627. if(!spell || spell->resisted) {
  5628. return 0;
  5629. }
  5630. bool ward_was_added = false;
  5631. ZoneServer* zone = spell->caster->GetZone();
  5632. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5633. for (int32 i = 0; i < spell->targets.size(); i++) {
  5634. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5635. if (!target)
  5636. continue;
  5637. if (target->IsEntity()) {
  5638. // If the ward is already active remove it
  5639. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5640. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5641. // Create new ward info
  5642. WardInfo* ward = new WardInfo;
  5643. ward->Spell = spell;
  5644. ward->BaseDamage = damage;
  5645. ward->DamageLeft = damage;
  5646. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5647. ward->keepWard = keepWard;
  5648. ward->WardType = wardType;
  5649. if (damageAbsorptionPercent > 100)
  5650. damageAbsorptionPercent = 100;
  5651. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5652. if (damageAbsorptionMaxHealthPercent > 100)
  5653. damageAbsorptionMaxHealthPercent = 100;
  5654. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5655. ward->RedirectDamagePercent = redirectDamagePercent;
  5656. ward->LastRedirectDamage = 0;
  5657. ward->LastAbsorbedDamage = 0;
  5658. ward->HitCount = 0;
  5659. spell->num_triggers = maxHitCount;
  5660. spell->had_triggers = true;
  5661. spell->cancel_after_all_triggers = false;
  5662. ward->MaxHitCount = maxHitCount;
  5663. if (wardType == WARD_TYPE_MAGICAL)
  5664. ward->DamageType = damageTypes;
  5665. // Add the ward to the entity
  5666. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5667. ward_was_added = true;
  5668. }
  5669. }
  5670. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5671. if (ward_was_added && spell->caster->IsPlayer()) {
  5672. spell->had_dmg_remaining = true;
  5673. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5674. }
  5675. return 0;
  5676. }
  5677. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5678. if (!lua_interface)
  5679. return 0;
  5680. int32 amount = lua_interface->GetInt32Value(state);
  5681. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5682. lua_interface->ResetFunctionStack(state);
  5683. WardInfo* ward = 0;
  5684. if(!spell || spell->resisted) {
  5685. return 0;
  5686. }
  5687. ZoneServer* zone = spell->caster->GetZone();
  5688. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5689. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5690. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5691. ward = target->GetWard(spell->spell->GetSpellID());
  5692. if (target && ward) {
  5693. ward->DamageLeft += amount;
  5694. if (ward->DamageLeft > ward->BaseDamage)
  5695. ward->DamageLeft = ward->BaseDamage;
  5696. for (int32 i = 0; i < spell->targets.size(); i++) {
  5697. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5698. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5699. }
  5700. }
  5701. }
  5702. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5703. if (ward && spell->caster->IsPlayer())
  5704. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5705. return 0;
  5706. }
  5707. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5708. if (!lua_interface)
  5709. return 0;
  5710. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5711. lua_interface->ResetFunctionStack(state);
  5712. if (!spell) {
  5713. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5714. return 0;
  5715. }
  5716. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5717. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5718. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5719. if (ward) {
  5720. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5721. return 1;
  5722. }
  5723. }
  5724. return 0;
  5725. }
  5726. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5727. if (!lua_interface)
  5728. return 0;
  5729. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5730. if (!spell) {
  5731. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5732. lua_interface->ResetFunctionStack(state);
  5733. return 0;
  5734. }
  5735. string type = lua_interface->GetStringValue(state, 2);
  5736. lua_interface->ResetFunctionStack(state);
  5737. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5738. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5739. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5740. if (ward) {
  5741. if (boost::iequals(type, "damageleft"))
  5742. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5743. else if (boost::iequals(type, "basedamage"))
  5744. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5745. else if (boost::iequals(type, "keepward"))
  5746. lua_interface->SetBooleanValue(state, ward->keepWard);
  5747. else if (boost::iequals(type, "wardtype"))
  5748. lua_interface->SetInt32Value(state, ward->WardType);
  5749. else if (boost::iequals(type, "dmgabsorptionpct"))
  5750. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5751. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5752. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5753. else if (boost::iequals(type, "redirectdamagepercent"))
  5754. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5755. else if (boost::iequals(type, "lastredirectdamage"))
  5756. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5757. else if (boost::iequals(type, "lastabsorbeddamage"))
  5758. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5759. else if (boost::iequals(type, "hitcount"))
  5760. lua_interface->SetInt32Value(state, ward->HitCount);
  5761. else if (boost::iequals(type, "maxhitcount"))
  5762. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5763. else
  5764. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5765. return 1;
  5766. }
  5767. }
  5768. return 0;
  5769. }
  5770. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5771. if (!lua_interface)
  5772. return 0;
  5773. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5774. lua_interface->ResetFunctionStack(state);
  5775. if(!spell) {
  5776. return 0;
  5777. }
  5778. ZoneServer* zone = spell->caster->GetZone();
  5779. Spawn* target = 0;
  5780. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5781. for (int32 i = 0; i < spell->targets.size(); i++) {
  5782. target = zone->GetSpawnByID(spell->targets.at(i));
  5783. if (target && target->IsEntity()) {
  5784. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5785. }
  5786. }
  5787. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5788. return 0;
  5789. }
  5790. int EQ2Emu_lua_Interrupt(lua_State* state)
  5791. {
  5792. if (!lua_interface)
  5793. return 0;
  5794. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5795. Spawn* target = lua_interface->GetSpawn(state, 2);
  5796. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5797. lua_interface->ResetFunctionStack(state);
  5798. if (!caster)
  5799. {
  5800. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5801. return 0;
  5802. }
  5803. if (!target)
  5804. {
  5805. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5806. return 0;
  5807. }
  5808. if (!spell) {
  5809. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5810. return 0;
  5811. }
  5812. if (!target->IsEntity() && !spell)
  5813. {
  5814. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5815. return 0;
  5816. }
  5817. if (!target && spell) {
  5818. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5819. for (int8 i = 0; i < spell->targets.size(); i++) {
  5820. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5821. if (!target || !target->IsEntity())
  5822. continue;
  5823. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5824. }
  5825. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5826. }
  5827. else
  5828. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5829. return 0;
  5830. }
  5831. int EQ2Emu_lua_Stealth(lua_State* state) {
  5832. if (!lua_interface)
  5833. return 0;
  5834. int8 type = lua_interface->GetInt8Value(state);
  5835. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5836. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5837. lua_interface->ResetFunctionStack(state);
  5838. if (!spell) {
  5839. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5840. return 0;
  5841. }
  5842. ZoneServer* zone = spell->caster->GetZone();
  5843. if (spawn) {
  5844. if (spawn->IsEntity()) {
  5845. if (type == 1) {
  5846. ((Entity*)spawn)->AddStealthSpell(spell);
  5847. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5848. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5849. }
  5850. else if (type == 2) {
  5851. ((Entity*)spawn)->AddInvisSpell(spell);
  5852. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5853. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5854. }
  5855. return 0;
  5856. }
  5857. else {
  5858. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5859. return 0;
  5860. }
  5861. }
  5862. else {
  5863. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5864. for (int32 i = 0; i < spell->targets.size(); i++) {
  5865. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5866. if (!spawn || !spawn->IsEntity())
  5867. continue;
  5868. if (type == 1) {
  5869. ((Entity*)spawn)->AddStealthSpell(spell);
  5870. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5871. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5872. }
  5873. else if (type == 2) {
  5874. ((Entity*)spawn)->AddInvisSpell(spell);
  5875. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5876. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5877. }
  5878. else {
  5879. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5880. break;
  5881. }
  5882. }
  5883. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5884. }
  5885. return 0;
  5886. }
  5887. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5888. if (!lua_interface)
  5889. return 0;
  5890. Spawn* spawn = lua_interface->GetSpawn(state);
  5891. lua_interface->ResetFunctionStack(state);
  5892. if (!spawn) {
  5893. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5894. return 0;
  5895. }
  5896. if (spawn->IsEntity()) {
  5897. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5898. return 1;
  5899. }
  5900. else
  5901. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5902. return 0;
  5903. }
  5904. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5905. if (!lua_interface)
  5906. return 0;
  5907. Spawn* spawn = lua_interface->GetSpawn(state);
  5908. lua_interface->ResetFunctionStack(state);
  5909. if (!spawn) {
  5910. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5911. return 0;
  5912. }
  5913. if (spawn->IsEntity()) {
  5914. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5915. return 1;
  5916. }
  5917. else
  5918. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5919. return 0;
  5920. }
  5921. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5922. if (!lua_interface)
  5923. return 0;
  5924. Spawn* player = lua_interface->GetSpawn(state);
  5925. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5926. lua_interface->ResetFunctionStack(state);
  5927. if (!player->IsPlayer()) {
  5928. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5929. return 0;
  5930. }
  5931. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5932. return 1;
  5933. }
  5934. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5935. if (!lua_interface)
  5936. return 0;
  5937. Spawn* player = lua_interface->GetSpawn(state);
  5938. int8 slot = lua_interface->GetInt8Value(state, 2);
  5939. lua_interface->ResetFunctionStack(state);
  5940. if (!player) {
  5941. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5942. return 0;
  5943. }
  5944. if (!player->IsPlayer()) {
  5945. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5946. return 0;
  5947. }
  5948. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5949. if (!item) {
  5950. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5951. return 0;
  5952. }
  5953. lua_interface->SetItemValue(state, item);
  5954. return 1;
  5955. }
  5956. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5957. if (!lua_interface)
  5958. return 0;
  5959. Spawn* player = lua_interface->GetSpawn(state);
  5960. int32 id = lua_interface->GetInt32Value(state, 2);
  5961. lua_interface->ResetFunctionStack(state);
  5962. if (!player) {
  5963. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5964. return 0;
  5965. }
  5966. if (!player->IsPlayer()) {
  5967. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5968. return 0;
  5969. }
  5970. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5971. if (!item) {
  5972. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5973. return 0;
  5974. }
  5975. lua_interface->SetItemValue(state, item);
  5976. return 1;
  5977. }
  5978. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5979. if (!lua_interface)
  5980. return 0;
  5981. Spawn* spawn = lua_interface->GetSpawn(state);
  5982. int8 slot = lua_interface->GetInt8Value(state, 2);
  5983. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5984. lua_interface->ResetFunctionStack(state);
  5985. if (!spawn) {
  5986. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5987. return 0;
  5988. }
  5989. if (!spawn->IsEntity()) {
  5990. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5991. return 0;
  5992. }
  5993. Item* item = master_item_list.GetItem(item_id);
  5994. if (!item) {
  5995. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5996. return 0;
  5997. }
  5998. Item* copy = new Item(item);
  5999. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6000. if(result)
  6001. {
  6002. ((Entity*)spawn)->SetEquipment(copy, slot);
  6003. spawn->vis_changed = true;
  6004. if(spawn->IsPlayer())
  6005. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6006. }
  6007. else
  6008. {
  6009. safe_delete(copy);
  6010. }
  6011. lua_interface->SetBooleanValue(state, result);
  6012. return 1;
  6013. }
  6014. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6015. if (!lua_interface)
  6016. return 0;
  6017. Spawn* spawn = lua_interface->GetSpawn(state);
  6018. int8 slot = lua_interface->GetInt8Value(state, 2);
  6019. Item* item = lua_interface->GetItem(state, 3);
  6020. lua_interface->ResetFunctionStack(state);
  6021. if (!spawn) {
  6022. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6023. return 0;
  6024. }
  6025. if (!spawn->IsEntity()) {
  6026. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6027. return 0;
  6028. }
  6029. if (!item) {
  6030. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6031. return 0;
  6032. }
  6033. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6034. if(result)
  6035. {
  6036. ((Entity*)spawn)->SetEquipment(item, slot);
  6037. spawn->vis_changed = true;
  6038. if(spawn->IsPlayer())
  6039. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6040. }
  6041. lua_interface->SetBooleanValue(state, result);
  6042. return 1;
  6043. }
  6044. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6045. if (!lua_interface)
  6046. return 0;
  6047. Spawn* spawn = lua_interface->GetSpawn(state);
  6048. int8 slot = lua_interface->GetInt8Value(state, 2);
  6049. 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
  6050. lua_interface->ResetFunctionStack(state);
  6051. if (!spawn) {
  6052. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6053. return 0;
  6054. }
  6055. if (!spawn->IsEntity()) {
  6056. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6057. return 0;
  6058. }
  6059. if(slot >= NUM_SLOTS) {
  6060. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6061. return 0;
  6062. }
  6063. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6064. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6065. if(item) {
  6066. item->save_needed = true;
  6067. if(no_delete_item) {
  6068. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6069. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6070. }
  6071. else{
  6072. Client* client = ((Player*)spawn)->GetClient();
  6073. client->UnequipItem(item->details.index);
  6074. }
  6075. }
  6076. }
  6077. else
  6078. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6079. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6080. spawn->vis_changed = true;
  6081. if(spawn->IsPlayer())
  6082. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6083. lua_interface->SetBooleanValue(state, true);
  6084. return 1;
  6085. }
  6086. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6087. if (!lua_interface)
  6088. return 0;
  6089. Spawn* spawn = lua_interface->GetSpawn(state);
  6090. int8 slot = lua_interface->GetInt8Value(state, 2);
  6091. int16 type = lua_interface->GetInt16Value(state, 3);
  6092. int8 r = lua_interface->GetInt8Value(state, 4);
  6093. int8 g = lua_interface->GetInt8Value(state, 5);
  6094. int8 b = lua_interface->GetInt8Value(state, 6);
  6095. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6096. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6097. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6098. lua_interface->ResetFunctionStack(state);
  6099. if (!spawn) {
  6100. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6101. return 0;
  6102. }
  6103. if (!spawn->IsEntity()) {
  6104. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6105. return 0;
  6106. }
  6107. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6108. spawn->vis_changed = true;
  6109. lua_interface->SetBooleanValue(state, true);
  6110. return 1;
  6111. }
  6112. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6113. if (!lua_interface)
  6114. return 0;
  6115. Spawn* player = lua_interface->GetSpawn(state);
  6116. int32 id = lua_interface->GetInt32Value(state, 2);
  6117. int8 count = lua_interface->GetInt8Value(state, 3);
  6118. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6119. lua_interface->ResetFunctionStack(state);
  6120. if (!player) {
  6121. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6122. return 0;
  6123. }
  6124. if (!player->IsPlayer()) {
  6125. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6126. return 0;
  6127. }
  6128. if (!count)
  6129. count = 1;
  6130. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6131. if (!item) {
  6132. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6133. return 0;
  6134. }
  6135. lua_interface->SetItemValue(state, item);
  6136. return 1;
  6137. }
  6138. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6139. if (!lua_interface)
  6140. return 0;
  6141. Spawn* spawn = lua_interface->GetSpawn(state);
  6142. int32 anim = lua_interface->GetInt32Value(state, 2);
  6143. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6144. int8 type = lua_interface->GetInt8Value(state, 4);
  6145. lua_interface->ResetFunctionStack(state);
  6146. if (!spawn) {
  6147. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6148. return 0;
  6149. }
  6150. if (spawn2) {
  6151. if (spawn2->IsPlayer()) {
  6152. if (type != 1 && type != 2)
  6153. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6154. else
  6155. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6156. return 0;
  6157. }
  6158. else {
  6159. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6160. return 0;
  6161. }
  6162. }
  6163. else
  6164. spawn->GetZone()->PlayAnimation(spawn, anim);
  6165. return 0;
  6166. }
  6167. int EQ2Emu_lua_IsPet(lua_State* state) {
  6168. if (!lua_interface)
  6169. return 0;
  6170. Spawn* spawn = lua_interface->GetSpawn(state);
  6171. lua_interface->ResetFunctionStack(state);
  6172. if (!spawn) {
  6173. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6174. return 0;
  6175. }
  6176. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6177. return 1;
  6178. }
  6179. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6180. if (!lua_interface)
  6181. return 0;
  6182. Spawn* spawn = lua_interface->GetSpawn(state);
  6183. lua_interface->ResetFunctionStack(state);
  6184. if (!spawn) {
  6185. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6186. return 0;
  6187. }
  6188. if (!spawn->IsNPC()) {
  6189. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6190. return 0;
  6191. }
  6192. if (((NPC*)spawn)->GetOwner()) {
  6193. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6194. return 1;
  6195. }
  6196. return 0;
  6197. }
  6198. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6199. if (!lua_interface)
  6200. return 0;
  6201. Spawn* spawn = lua_interface->GetSpawn(state);
  6202. Spawn* target = lua_interface->GetSpawn(state, 2);
  6203. lua_interface->ResetFunctionStack(state);
  6204. if (!spawn) {
  6205. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6206. return 0;
  6207. }
  6208. if (!spawn) {
  6209. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6210. return 0;
  6211. }
  6212. spawn->SetTarget(target);
  6213. return 0;
  6214. }
  6215. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6216. if (!lua_interface)
  6217. return 0;
  6218. Spawn* spawn = lua_interface->GetSpawn(state);
  6219. bool val = lua_interface->GetBooleanValue(state, 2);
  6220. lua_interface->ResetFunctionStack(state);
  6221. if (!spawn) {
  6222. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6223. return 0;
  6224. }
  6225. if (!spawn->IsEntity()) {
  6226. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6227. return 0;
  6228. }
  6229. ((Entity*)spawn)->InCombat(val);
  6230. if (val) {
  6231. spawn->ClearRunningLocations();
  6232. spawn->CalculateRunningLocation(true);
  6233. }
  6234. return 0;
  6235. }
  6236. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6237. if (!lua_interface)
  6238. return 0;
  6239. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6240. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6241. lua_interface->ResetFunctionStack(state);
  6242. if (!spawn1) {
  6243. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6244. return 0;
  6245. }
  6246. if (!spawn2) {
  6247. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6248. return 0;
  6249. }
  6250. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6251. return 1;
  6252. }
  6253. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6254. if (!lua_interface)
  6255. return 0;
  6256. Spawn* spawn = lua_interface->GetSpawn(state);
  6257. lua_interface->ResetFunctionStack(state);
  6258. if (!spawn) {
  6259. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6260. return 0;
  6261. }
  6262. if (!spawn->IsNPC()) {
  6263. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6264. return 0;
  6265. }
  6266. ((NPC*)spawn)->ClearRunback();
  6267. return 0;
  6268. }
  6269. int EQ2Emu_lua_Runback(lua_State* state) {
  6270. if (!lua_interface)
  6271. return 0;
  6272. Spawn* spawn = lua_interface->GetSpawn(state);
  6273. lua_interface->ResetFunctionStack(state);
  6274. if (!spawn) {
  6275. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6276. return 0;
  6277. }
  6278. if (!spawn->IsNPC()) {
  6279. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6280. return 0;
  6281. }
  6282. ((NPC*)spawn)->Runback();
  6283. return 0;
  6284. }
  6285. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6286. if (!lua_interface)
  6287. return 0;
  6288. Spawn* spawn = lua_interface->GetSpawn(state);
  6289. lua_interface->ResetFunctionStack(state);
  6290. if (!spawn) {
  6291. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6292. return 0;
  6293. }
  6294. if (!spawn->IsNPC()) {
  6295. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6296. return 0;
  6297. }
  6298. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6299. return 1;
  6300. }
  6301. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6302. if (!lua_interface)
  6303. return 0;
  6304. Spawn* spawn = lua_interface->GetSpawn(state);
  6305. lua_interface->ResetFunctionStack(state);
  6306. if (!spawn) {
  6307. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6308. return 0;
  6309. }
  6310. if (!spawn->IsEntity()) {
  6311. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6312. return 0;
  6313. }
  6314. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6315. return 1;
  6316. }
  6317. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6318. if (!lua_interface)
  6319. return 0;
  6320. Spawn* spawn = lua_interface->GetSpawn(state);
  6321. lua_interface->ResetFunctionStack(state);
  6322. if (!spawn) {
  6323. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6324. return 0;
  6325. }
  6326. if (!spawn->IsEntity()) {
  6327. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6328. return 0;
  6329. }
  6330. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6331. return 1;
  6332. }
  6333. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6334. if (!lua_interface)
  6335. return 0;
  6336. Spawn* spawn = lua_interface->GetSpawn(state);
  6337. lua_interface->ResetFunctionStack(state);
  6338. if (!spawn) {
  6339. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6340. return 0;
  6341. }
  6342. if (!spawn->IsEntity()) {
  6343. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6344. return 0;
  6345. }
  6346. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6347. return 1;
  6348. }
  6349. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6350. if (!lua_interface)
  6351. return 0;
  6352. Spawn* spawn = lua_interface->GetSpawn(state);
  6353. lua_interface->ResetFunctionStack(state);
  6354. if (!spawn) {
  6355. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6356. return 0;
  6357. }
  6358. if (!spawn->IsEntity()) {
  6359. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6360. return 0;
  6361. }
  6362. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6363. return 1;
  6364. }
  6365. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6366. if (!lua_interface)
  6367. return 0;
  6368. Spawn* spawn = lua_interface->GetSpawn(state);
  6369. Spawn* target = lua_interface->GetSpawn(state, 2);
  6370. float distance = lua_interface->GetFloatValue(state, 3);
  6371. lua_interface->ResetFunctionStack(state);
  6372. if (!spawn) {
  6373. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6374. return 0;
  6375. }
  6376. if (!target) {
  6377. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6378. return 0;
  6379. }
  6380. if (!spawn->IsNPC()) {
  6381. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6382. return 0;
  6383. }
  6384. if (!target->IsEntity()) {
  6385. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6386. return 0;
  6387. }
  6388. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6389. return 1;
  6390. }
  6391. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6392. if (!lua_interface)
  6393. return 0;
  6394. Spawn* spawn = lua_interface->GetSpawn(state);
  6395. Spawn* target = lua_interface->GetSpawn(state, 2);
  6396. float distance = lua_interface->GetFloatValue(state, 3);
  6397. lua_interface->ResetFunctionStack(state);
  6398. if (!spawn) {
  6399. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6400. return 0;
  6401. }
  6402. if (!target) {
  6403. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6404. return 0;
  6405. }
  6406. if (!spawn->IsNPC()) {
  6407. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6408. return 0;
  6409. }
  6410. if (!target->IsEntity()) {
  6411. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6412. return 0;
  6413. }
  6414. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6415. return 0;
  6416. }
  6417. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6418. if (!lua_interface)
  6419. return 0;
  6420. Spawn* spawn = lua_interface->GetSpawn(state);
  6421. lua_interface->ResetFunctionStack(state);
  6422. if (!spawn) {
  6423. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6424. return 0;
  6425. }
  6426. if (!spawn->IsNPC()) {
  6427. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6428. return 0;
  6429. }
  6430. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6431. return 1;
  6432. }
  6433. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6434. if (!lua_interface)
  6435. return 0;
  6436. Spawn* spawn = lua_interface->GetSpawn(state);
  6437. lua_interface->ResetFunctionStack(state);
  6438. if (!spawn) {
  6439. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6440. return 0;
  6441. }
  6442. if (!spawn->IsNPC()) {
  6443. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6444. return 0;
  6445. }
  6446. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6447. return 1;
  6448. }
  6449. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6450. if (!lua_interface)
  6451. return 0;
  6452. Spawn* spawn = lua_interface->GetSpawn(state);
  6453. lua_interface->ResetFunctionStack(state);
  6454. if (!spawn) {
  6455. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6456. return 0;
  6457. }
  6458. if (!spawn->IsNPC()) {
  6459. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6460. return 0;
  6461. }
  6462. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6463. if (hated) {
  6464. lua_interface->SetSpawnValue(state, hated);
  6465. return 1;
  6466. }
  6467. return 0;
  6468. }
  6469. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6470. if (!lua_interface)
  6471. return 0;
  6472. Spawn* spawn = lua_interface->GetSpawn(state);
  6473. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6474. lua_interface->ResetFunctionStack(state);
  6475. if (!spawn) {
  6476. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6477. return 0;
  6478. }
  6479. if (!spawn->IsNPC()) {
  6480. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6481. return 0;
  6482. }
  6483. if (!hated) {
  6484. ((NPC*)spawn)->Brain()->ClearHate();
  6485. return 0;
  6486. }
  6487. else
  6488. {
  6489. if (!hated->IsEntity()) {
  6490. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6494. return 0;
  6495. }
  6496. return 0;
  6497. }
  6498. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6499. if (!lua_interface)
  6500. return 0;
  6501. Spawn* spawn = lua_interface->GetSpawn(state);
  6502. lua_interface->ResetFunctionStack(state);
  6503. if (!spawn) {
  6504. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6505. return 0;
  6506. }
  6507. if (!spawn->IsNPC()) {
  6508. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6509. return 0;
  6510. }
  6511. ((NPC*)spawn)->Brain()->ClearEncounter();
  6512. return 0;
  6513. }
  6514. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6515. if (!lua_interface)
  6516. return 0;
  6517. Spawn* spawn = lua_interface->GetSpawn(state);
  6518. lua_interface->ResetFunctionStack(state);
  6519. if (!spawn) {
  6520. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6521. return 0;
  6522. }
  6523. if (!spawn->IsNPC()) {
  6524. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6525. return 0;
  6526. }
  6527. // Temp list to store hate list
  6528. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6529. if (encounterList->size() == 0) {
  6530. safe_delete(encounterList);
  6531. return 0;
  6532. }
  6533. lua_createtable(state, encounterList->size(), 0);
  6534. int newTable = lua_gettop(state);
  6535. for (int32 i = 0; i < encounterList->size(); i++) {
  6536. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6537. if (temp)
  6538. lua_interface->SetSpawnValue(state, temp);
  6539. lua_rawseti(state, newTable, i + 1);
  6540. }
  6541. safe_delete(encounterList);
  6542. return 1;
  6543. }
  6544. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6545. if (!lua_interface)
  6546. return 0;
  6547. Spawn* spawn = lua_interface->GetSpawn(state);
  6548. lua_interface->ResetFunctionStack(state);
  6549. if (!spawn) {
  6550. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6551. return 0;
  6552. }
  6553. if (!spawn->IsNPC()) {
  6554. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6555. return 0;
  6556. }
  6557. // Temp list to store hate list
  6558. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6559. if (hateList->size() == 0) {
  6560. safe_delete(hateList);
  6561. return 0;
  6562. }
  6563. lua_createtable(state, hateList->size(), 0);
  6564. int newTable = lua_gettop(state);
  6565. for (int32 i = 0; i < hateList->size(); i++) {
  6566. lua_interface->SetSpawnValue(state, hateList->at(i));
  6567. lua_rawseti(state, newTable, i + 1);
  6568. }
  6569. safe_delete(hateList);
  6570. return 1;
  6571. }
  6572. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6573. if (!lua_interface)
  6574. return 0;
  6575. Spawn* spawn = lua_interface->GetSpawn(state);
  6576. lua_interface->ResetFunctionStack(state);
  6577. if (!spawn) {
  6578. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6579. return 0;
  6580. }
  6581. if (spawn->IsPlayer()) {
  6582. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6583. lua_interface->SetBooleanValue(state, true);
  6584. else
  6585. lua_interface->SetBooleanValue(state, false);
  6586. return 1;
  6587. }
  6588. else {
  6589. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6590. return 1;
  6591. }
  6592. }
  6593. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6594. if (!lua_interface)
  6595. return 0;
  6596. Quest* quest = lua_interface->GetQuest(state);
  6597. lua_interface->ResetFunctionStack(state);
  6598. if (!quest) {
  6599. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6600. return 0;
  6601. }
  6602. quest->SetCompletedFlag(true);
  6603. return 0;
  6604. }
  6605. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6606. if (!lua_interface)
  6607. return 0;
  6608. Spawn* spawn = lua_interface->GetSpawn(state);
  6609. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6610. int8 tier = lua_interface->GetInt8Value(state, 3);
  6611. lua_interface->ResetFunctionStack(state);
  6612. if (!spawn) {
  6613. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6614. return 0;
  6615. }
  6616. if (!spawn->IsEntity()) {
  6617. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6618. return 0;
  6619. }
  6620. if (spellID == 0) {
  6621. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6622. return 0;
  6623. }
  6624. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6625. if (effect) {
  6626. if (tier > 0) {
  6627. // If a tier was passed chec to see if it is the same as the effect
  6628. if (tier == effect->tier)
  6629. lua_interface->SetBooleanValue(state, true);
  6630. else
  6631. lua_interface->SetBooleanValue(state, false);
  6632. return 1;
  6633. }
  6634. else {
  6635. // Have an effect but no tier was passed so return true
  6636. lua_interface->SetBooleanValue(state, true);
  6637. }
  6638. return 1;
  6639. }
  6640. // no effect so return false
  6641. lua_interface->SetBooleanValue(state, false);
  6642. return 1;
  6643. }
  6644. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6645. if (!lua_interface)
  6646. return 0;
  6647. Spawn* spawn = lua_interface->GetSpawn(state);
  6648. int32 id = lua_interface->GetInt32Value(state, 2);
  6649. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6650. lua_interface->ResetFunctionStack(state);
  6651. Spawn* spawn2 = 0;
  6652. vector<Spawn*> list;
  6653. if (!spawn) {
  6654. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6655. return 0;
  6656. }
  6657. //If zone not provided, use spawn's zone
  6658. if (!zone)
  6659. zone = spawn->GetZone();
  6660. list = zone->GetSpawnsByID(id);
  6661. if (list.size() == 0) {
  6662. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6663. return 0;
  6664. }
  6665. vector<Spawn*>::iterator itr = list.begin();
  6666. for (int8 i = 0; i < list.size(); i++) {
  6667. spawn2 = itr[i];
  6668. if (spawn2)
  6669. spawn2->AddAllowAccessSpawn(spawn);
  6670. }
  6671. return 0;
  6672. }
  6673. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6674. if (!lua_interface)
  6675. return 0;
  6676. Spawn* spawn = lua_interface->GetSpawn(state);
  6677. int32 id = lua_interface->GetInt32Value(state, 2);
  6678. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6679. lua_interface->ResetFunctionStack(state);
  6680. Spawn* spawn2 = 0;
  6681. if (!spawn) {
  6682. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6683. return 0;
  6684. }
  6685. //If zone not provided, use spawn's zone
  6686. if (!zone)
  6687. zone = spawn->GetZone();
  6688. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6689. vector<Spawn*>::iterator itr = list.begin();
  6690. if (list.size() == 0) {
  6691. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6692. return 0;
  6693. }
  6694. for (int8 i = 0; i < list.size(); i++) {
  6695. spawn2 = itr[i];
  6696. if (spawn2)
  6697. spawn2->RemoveSpawnAccess(spawn);
  6698. }
  6699. return 0;
  6700. }
  6701. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6702. if (!lua_interface)
  6703. return 0;
  6704. Quest* quest = lua_interface->GetQuest(state);
  6705. lua_interface->ResetFunctionStack(state);
  6706. if (!quest) {
  6707. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6708. return 0;
  6709. }
  6710. quest->SetYellowName(true);
  6711. return 0;
  6712. }
  6713. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6714. if (!lua_interface)
  6715. return 0;
  6716. Spawn* spawn = lua_interface->GetSpawn(state);
  6717. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6718. lua_interface->ResetFunctionStack(state);
  6719. if (!spawn) {
  6720. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6721. return 0;
  6722. }
  6723. if (!spawn->IsPlayer()) {
  6724. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6725. return 0;
  6726. }
  6727. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6728. return 1;
  6729. }
  6730. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6731. if (!lua_interface)
  6732. return 0;
  6733. Spawn* spawn = lua_interface->GetSpawn(state);
  6734. lua_interface->ResetFunctionStack(state);
  6735. if (!spawn) {
  6736. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6737. return 0;
  6738. }
  6739. if (!spawn->IsPlayer()) {
  6740. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6741. return 0;
  6742. }
  6743. ZoneServer* zone = spawn->GetZone();
  6744. if (!zone) {
  6745. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6746. return 0;
  6747. }
  6748. Instance_Type iType = zone->GetInstanceType();
  6749. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6750. iType == GROUP_LOCKOUT_INSTANCE ||
  6751. iType == RAID_LOCKOUT_INSTANCE ||
  6752. iType == SOLO_PERSIST_INSTANCE ||
  6753. iType == GROUP_PERSIST_INSTANCE ||
  6754. iType == RAID_PERSIST_INSTANCE) {
  6755. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6756. if (data) {
  6757. // Check to see if the timer has already been set, if it has return out.
  6758. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6759. return 0;
  6760. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6761. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6762. if(spawn->IsPlayer()) {
  6763. Client* client = ((Player*)spawn)->GetClient();
  6764. if (client) {
  6765. string time_msg = "";
  6766. int32 time = data->success_lockout_time;
  6767. int16 hour;
  6768. int8 min;
  6769. int8 sec;
  6770. hour = time / 3600;
  6771. time = time % 3600;
  6772. min = time / 60;
  6773. time = time % 60;
  6774. sec = time;
  6775. if (hour > 0) {
  6776. char temp[10];
  6777. sprintf(temp, " %i", hour);
  6778. time_msg.append(temp);
  6779. time_msg.append(" hour");
  6780. time_msg.append((hour > 1) ? "s" : "");
  6781. }
  6782. if (min > 0) {
  6783. char temp[5];
  6784. sprintf(temp, " %i", min);
  6785. time_msg.append(temp);
  6786. time_msg.append(" minute");
  6787. time_msg.append((min > 1) ? "s" : "");
  6788. }
  6789. // Only add seconds if minutes and hours are 0
  6790. if (hour == 0 && min == 0 && sec > 0) {
  6791. char temp[5];
  6792. sprintf(temp, " %i", sec);
  6793. time_msg.append(temp);
  6794. time_msg.append(" second");
  6795. time_msg.append((sec > 1) ? "s" : "");
  6796. }
  6797. 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());
  6798. }
  6799. else {
  6800. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6801. }
  6802. }
  6803. }
  6804. else
  6805. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6806. }
  6807. else
  6808. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6809. return 0;
  6810. }
  6811. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6812. if (!lua_interface)
  6813. return 0;
  6814. Spawn* spawn = lua_interface->GetSpawn(state);
  6815. lua_interface->ResetFunctionStack(state);
  6816. if (!spawn) {
  6817. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6818. return 0;
  6819. }
  6820. if (!spawn->IsPlayer()) {
  6821. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6822. return 0;
  6823. }
  6824. ZoneServer* zone = spawn->GetZone();
  6825. if (!zone) {
  6826. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6827. return 0;
  6828. }
  6829. Instance_Type iType = zone->GetInstanceType();
  6830. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6831. iType == GROUP_LOCKOUT_INSTANCE ||
  6832. iType == RAID_LOCKOUT_INSTANCE ||
  6833. iType == SOLO_PERSIST_INSTANCE ||
  6834. iType == GROUP_PERSIST_INSTANCE ||
  6835. iType == RAID_PERSIST_INSTANCE) {
  6836. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6837. if (data) {
  6838. // Check to see if the timer has already been set, if it has return out.
  6839. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6840. return 0;
  6841. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6842. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6843. if(spawn->IsPlayer()) {
  6844. Client* client = ((Player*)spawn)->GetClient();
  6845. if (client) {
  6846. string time_msg = "";
  6847. int32 time = data->failure_lockout_time;
  6848. int16 hour;
  6849. int8 min;
  6850. int8 sec;
  6851. hour = time / 3600;
  6852. time = time % 3600;
  6853. min = time / 60;
  6854. time = time % 60;
  6855. sec = time;
  6856. if (hour > 0) {
  6857. char temp[10];
  6858. sprintf(temp, " %i", hour);
  6859. time_msg.append(temp);
  6860. time_msg.append(" hour");
  6861. time_msg.append((hour > 1) ? "s" : "");
  6862. }
  6863. if (min > 0) {
  6864. char temp[5];
  6865. sprintf(temp, " %i", min);
  6866. time_msg.append(temp);
  6867. time_msg.append(" minute");
  6868. time_msg.append((min > 1) ? "s" : "");
  6869. }
  6870. // Only add seconds if minutes and hours are 0
  6871. if (hour == 0 && min == 0 && sec > 0) {
  6872. char temp[5];
  6873. sprintf(temp, " %i", sec);
  6874. time_msg.append(temp);
  6875. time_msg.append(" second");
  6876. time_msg.append((sec > 1) ? "s" : "");
  6877. }
  6878. 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());
  6879. }
  6880. }
  6881. else {
  6882. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6883. }
  6884. }
  6885. else
  6886. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6887. }
  6888. else
  6889. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6890. return 0;
  6891. }
  6892. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6893. if (!lua_interface)
  6894. return 0;
  6895. Spawn* spawn = lua_interface->GetSpawn(state);
  6896. lua_interface->ResetFunctionStack(state);
  6897. if (!spawn) {
  6898. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6899. return 0;
  6900. }
  6901. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6902. return 1;
  6903. }
  6904. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6905. if (!lua_interface)
  6906. return 0;
  6907. Spawn* player = lua_interface->GetSpawn(state);
  6908. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6909. if (!player) {
  6910. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6911. lua_interface->ResetFunctionStack(state);
  6912. return 0;
  6913. }
  6914. if (!player->IsPlayer()) {
  6915. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6916. lua_interface->ResetFunctionStack(state);
  6917. return 0;
  6918. }
  6919. if (!ground) {
  6920. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6921. lua_interface->ResetFunctionStack(state);
  6922. return 0;
  6923. }
  6924. if (!ground->IsGroundSpawn()) {
  6925. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6926. lua_interface->ResetFunctionStack(state);
  6927. return 0;
  6928. }
  6929. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6930. if (!groundspawn_entries) {
  6931. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6932. lua_interface->ResetFunctionStack(state);
  6933. return 0;
  6934. }
  6935. Skill* skill = 0;
  6936. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6937. if (collection_skill == "Collecting")
  6938. skill = ((Player*)player)->GetSkillByName("Gathering");
  6939. else
  6940. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6941. if (!skill) {
  6942. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6943. lua_interface->ResetFunctionStack(state);
  6944. return 0;
  6945. }
  6946. vector<GroundSpawnEntry*>::iterator itr;
  6947. GroundSpawnEntry* entry = 0;
  6948. bool can_harvest = false;
  6949. sint32 min_skill = -1;
  6950. int16 totalSkill = skill->current_val;
  6951. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6952. if(skillID != 0xFFFFFFFF)
  6953. {
  6954. ((Entity*)player)->MStats.lock();
  6955. totalSkill += ((Entity*)player)->stats[skillID];
  6956. ((Entity*)player)->MStats.unlock();
  6957. }
  6958. // first, iterate through groundspawn_entries, discard tables player cannot use
  6959. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6960. {
  6961. entry = *itr;
  6962. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6963. min_skill = entry->min_skill_level;
  6964. // if player lacks skill, skip table
  6965. if (entry->min_skill_level > totalSkill)
  6966. continue;
  6967. // if bonus, but player lacks level, skip table
  6968. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6969. continue;
  6970. can_harvest = true;
  6971. break;
  6972. }
  6973. lua_interface->SetBooleanValue(state, can_harvest);
  6974. // If false, send the message to the client
  6975. if (!can_harvest) {
  6976. Client* client = ((Player*)player)->GetClient();
  6977. if (client) {
  6978. string msg = "You do not have enough skill to ";
  6979. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6980. msg.append("gather");
  6981. else if (collection_skill == "Mining")
  6982. msg.append("mine");
  6983. else if (collection_skill == "Trapping")
  6984. msg.append("trap");
  6985. else if (collection_skill == "Foresting")
  6986. msg.append("forest");
  6987. else if (collection_skill == "Fishing")
  6988. msg.append("catch");
  6989. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6990. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6991. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6992. }
  6993. }
  6994. lua_interface->ResetFunctionStack(state);
  6995. return 1;
  6996. }
  6997. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6998. if (!lua_interface)
  6999. return 0;
  7000. Spawn* player = lua_interface->GetSpawn(state);
  7001. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7002. lua_interface->ResetFunctionStack(state);
  7003. if (!player) {
  7004. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7005. return 0;
  7006. }
  7007. if (!player->IsPlayer()) {
  7008. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7009. return 0;
  7010. }
  7011. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7012. lua_interface->SetBooleanValue(state, ret);
  7013. return 1;
  7014. }
  7015. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7016. // Check to see if we have a valid lua_interface
  7017. if (!lua_interface)
  7018. return 0;
  7019. // Get the spawn that is getting the pet
  7020. Spawn* spawn = lua_interface->GetSpawn(state);
  7021. Spawn* target = lua_interface->GetSpawn(state, 2);
  7022. // Get the DB ID of the pet
  7023. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7024. float x = lua_interface->GetFloatValue(state, 4);
  7025. float y = lua_interface->GetFloatValue(state, 5);
  7026. float z = lua_interface->GetFloatValue(state, 6);
  7027. // Get the spell that this command was called from
  7028. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7029. lua_interface->ResetFunctionStack(state);
  7030. // Check to make sure the spawn pointer is valid
  7031. if (!spawn) {
  7032. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7033. return 0;
  7034. }
  7035. // Check to make sure the spawn is an entity
  7036. if (!spawn->IsEntity()) {
  7037. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7038. return 0;
  7039. }
  7040. if (!target) {
  7041. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7042. return 0;
  7043. }
  7044. if (!target->IsEntity()) {
  7045. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7046. return 0;
  7047. }
  7048. // Check to see if the DB ID for the pet is set
  7049. if (pet_id == 0) {
  7050. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7051. return 0;
  7052. }
  7053. // Check to see if the pointer to the spell is valid
  7054. if (!luaspell) {
  7055. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7056. return 0;
  7057. }
  7058. if(luaspell->resisted) {
  7059. return 0;
  7060. }
  7061. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7062. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7063. if (!pet) {
  7064. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7065. return 0;
  7066. }
  7067. // Check to make sure the pet is an npc
  7068. if (!pet->IsNPC()) {
  7069. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7070. return 0;
  7071. }
  7072. if (x == 0)
  7073. x = spawn->GetX();
  7074. if (y == 0)
  7075. y = spawn->GetY();
  7076. if (z == 0)
  7077. z = spawn->GetZ();
  7078. // Spawn the pet at the same location as the owner
  7079. pet->SetX(x);
  7080. pet->SetY(y);
  7081. pet->SetZ(z);
  7082. pet->SetLocation(spawn->GetLocation());
  7083. pet->SetHeading(spawn->GetHeading());
  7084. spawn->GetZone()->AddSpawn(pet);
  7085. /*
  7086. const char* spawn_script = world.GetSpawnScript(pet_id);
  7087. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7088. spawn->SetSpawnScript(string(spawn_script));
  7089. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7090. }*/
  7091. // Get a random pet name
  7092. string random_pet_name;
  7093. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7094. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  7095. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  7096. // Set the pets name
  7097. pet->SetName(random_pet_name.c_str());
  7098. // Set the level of the pet to the owners level
  7099. pet->SetLevel(spawn->GetLevel());
  7100. // Set the faction of the pet to the same faction as the owner
  7101. pet->SetFactionID(spawn->GetFactionID());
  7102. // Set the spawn as a pet
  7103. pet->SetPet(true);
  7104. // Give a pointer of the owner to the pet
  7105. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7106. // Set the pet type
  7107. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7108. // Set the spell id used to create this pet
  7109. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7110. // Set the spell tier used to create this pet
  7111. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7112. // Set the pets spawn type to 6
  7113. pet->SetSpawnType(6);
  7114. // Set the pets brain
  7115. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7116. // Check to see if the pet has a subtitle
  7117. if (strlen(pet->GetSubTitle()) > 0) {
  7118. // Add the players name to the front of the sub title
  7119. string pet_subtitle;
  7120. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7121. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7122. // Set the pets subtitle to the new one
  7123. pet->SetSubTitle(pet_subtitle.c_str());
  7124. }
  7125. // Set the pet as the return value for this function
  7126. lua_interface->SetSpawnValue(state, pet);
  7127. return 1;
  7128. }
  7129. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7130. if (!lua_interface)
  7131. return 0;
  7132. Spawn* spawn = lua_interface->GetSpawn(state);
  7133. Spawn* player = lua_interface->GetSpawn(state, 2);
  7134. float max_distance = lua_interface->GetFloatValue(state, 3);
  7135. string type = lua_interface->GetStringValue(state, 4);
  7136. lua_interface->ResetFunctionStack(state);
  7137. if (!spawn || (spawn && spawn->IsPlayer())) {
  7138. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7139. return 0;
  7140. }
  7141. if (!player || !player->IsPlayer()) {
  7142. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7143. return 0;
  7144. }
  7145. Client* client = ((Player*)player)->GetClient();
  7146. if (!client) {
  7147. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7148. return 0;
  7149. }
  7150. //Set max_distance to default if not set or not proper value
  7151. if (max_distance <= 0)
  7152. max_distance = 500;
  7153. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7154. if (packet) {
  7155. float unknown2_3 = 0;
  7156. int8 placement_mode = 0;
  7157. if (type == "wall") {
  7158. placement_mode = 2;
  7159. unknown2_3 = 150;
  7160. }
  7161. else if (type == "ceiling")
  7162. placement_mode = 1;
  7163. packet->setDataByName("placement_mode", placement_mode);
  7164. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7165. packet->setDataByName("model_type", spawn->GetModelType());
  7166. packet->setDataByName("unknown", 1); //size
  7167. packet->setDataByName("unknown2", 1); //size 2
  7168. packet->setDataByName("unknown2", .5, 1); //size 3
  7169. packet->setDataByName("unknown2", 3, 2);
  7170. packet->setDataByName("unknown2", unknown2_3, 3);
  7171. packet->setDataByName("max_distance", max_distance);
  7172. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7173. client->QueuePacket(packet->serialize());
  7174. safe_delete(packet);
  7175. }
  7176. return 0;
  7177. }
  7178. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7179. if (!lua_interface)
  7180. return 0;
  7181. Item* item = lua_interface->GetItem(state);
  7182. lua_interface->ResetFunctionStack(state);
  7183. if (!item) {
  7184. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7185. return 0;
  7186. }
  7187. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7188. return 1;
  7189. }
  7190. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7191. if (!lua_interface)
  7192. return 0;
  7193. Item* item = lua_interface->GetItem(state);
  7194. lua_interface->ResetFunctionStack(state);
  7195. if (!item) {
  7196. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7197. return 0;
  7198. }
  7199. lua_interface->SetInt32Value(state, item->effect_type);
  7200. return 1;
  7201. }
  7202. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7203. if (!lua_interface)
  7204. return 0;
  7205. Spawn* spawn = lua_interface->GetSpawn(state);
  7206. lua_interface->ResetFunctionStack(state);
  7207. if (!spawn) {
  7208. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7209. return 0;
  7210. }
  7211. if (spawn->GetZone())
  7212. spawn->GetZone()->AddTransportSpawn(spawn);
  7213. return 0;
  7214. }
  7215. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7216. if (!lua_interface)
  7217. return 0;
  7218. Spawn* spawn = lua_interface->GetSpawn(state);
  7219. lua_interface->ResetFunctionStack(state);
  7220. if (!spawn) {
  7221. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7222. return 0;
  7223. }
  7224. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7225. return 1;
  7226. }
  7227. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7228. if (!lua_interface)
  7229. return 0;
  7230. Skill* skill = lua_interface->GetSkill(state);
  7231. lua_interface->ResetFunctionStack(state);
  7232. if (!skill) {
  7233. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7234. return 0;
  7235. }
  7236. lua_interface->SetInt32Value(state, skill->current_val);
  7237. return 1;
  7238. }
  7239. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7240. if (!lua_interface)
  7241. return 0;
  7242. Skill* skill = lua_interface->GetSkill(state);
  7243. lua_interface->ResetFunctionStack(state);
  7244. if (!skill) {
  7245. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7246. return 0;
  7247. }
  7248. lua_interface->SetInt32Value(state, skill->max_val);
  7249. return 1;
  7250. }
  7251. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7252. if (!lua_interface)
  7253. return 0;
  7254. Skill* skill = lua_interface->GetSkill(state);
  7255. lua_interface->ResetFunctionStack(state);
  7256. if (!skill) {
  7257. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7258. return 0;
  7259. }
  7260. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7261. return 1;
  7262. }
  7263. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7264. if (!lua_interface)
  7265. return 0;
  7266. Skill* skill = lua_interface->GetSkill(state);
  7267. int16 value = lua_interface->GetInt16Value(state, 2);
  7268. lua_interface->ResetFunctionStack(state);
  7269. if (!skill) {
  7270. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7271. return 0;
  7272. }
  7273. skill->max_val = value;
  7274. if (skill->max_val < skill->current_val)
  7275. skill->current_val = skill->max_val;
  7276. return 0;
  7277. }
  7278. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7279. if (!lua_interface)
  7280. return 0;
  7281. Skill* skill = lua_interface->GetSkill(state);
  7282. int16 value = lua_interface->GetInt16Value(state, 2);
  7283. lua_interface->ResetFunctionStack(state);
  7284. if (!skill) {
  7285. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7286. return 0;
  7287. }
  7288. if (value > skill->max_val)
  7289. skill->current_val = skill->max_val;
  7290. else
  7291. skill->current_val = value;
  7292. return 0;
  7293. }
  7294. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7295. if (!lua_interface)
  7296. return 0;
  7297. Spawn* player = lua_interface->GetSpawn(state);
  7298. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7299. lua_interface->ResetFunctionStack(state);
  7300. if (skill_id > 0 && player && player->IsPlayer()) {
  7301. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7302. return 1;
  7303. }
  7304. return 0;
  7305. }
  7306. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7307. if (!lua_interface)
  7308. return 0;
  7309. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7310. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7311. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7312. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7313. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7314. lua_interface->ResetFunctionStack(state);
  7315. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7316. if (player_spawn && player_spawn->IsPlayer()) {
  7317. Player* player = (Player*)player_spawn;
  7318. bool added = false;
  7319. if (!player->skill_list.HasSkill(skill_id)) {
  7320. player->AddSkill(skill_id, current_val, max_val, true);
  7321. added = true;
  7322. }
  7323. 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
  7324. Client* client = player->GetClient();
  7325. if (client) {
  7326. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7327. if (packet)
  7328. client->QueuePacket(packet);
  7329. }
  7330. }
  7331. if (added) {
  7332. lua_interface->SetBooleanValue(state, true);
  7333. return 1;
  7334. }
  7335. }
  7336. else {
  7337. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7338. }
  7339. }
  7340. else {
  7341. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7342. }
  7343. lua_interface->SetBooleanValue(state, false);
  7344. return 1;
  7345. }
  7346. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7347. if (!lua_interface)
  7348. return 0;
  7349. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7350. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7351. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7352. lua_interface->ResetFunctionStack(state);
  7353. if (skill_id > 0) {
  7354. if (player_spawn && player_spawn->IsPlayer()) {
  7355. Player* player = (Player*)player_spawn;
  7356. if (player->skill_list.HasSkill(skill_id)) {
  7357. player->RemovePlayerSkill(skill_id);
  7358. if (!more_to_remove) {
  7359. Client* client = player->GetClient();
  7360. if (client) {
  7361. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7362. if (packet)
  7363. client->QueuePacket(packet);
  7364. }
  7365. }
  7366. }
  7367. }
  7368. else {
  7369. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7370. }
  7371. }
  7372. else {
  7373. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7374. }
  7375. return 0;
  7376. }
  7377. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7378. if (!lua_interface)
  7379. return 0;
  7380. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7381. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7382. int16 amount = lua_interface->GetInt8Value(state, 3);
  7383. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7384. lua_interface->ResetFunctionStack(state);
  7385. if (amount > 0 && skill_type < 100) {
  7386. if (player_spawn && player_spawn->IsPlayer()) {
  7387. Player* player = (Player*)player_spawn;
  7388. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7389. if (!more_to_increase) {
  7390. Client* client = player->GetClient();
  7391. if (client) {
  7392. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7393. if (packet)
  7394. client->QueuePacket(packet);
  7395. }
  7396. }
  7397. }
  7398. else {
  7399. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7400. }
  7401. }
  7402. else {
  7403. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7404. }
  7405. return 0;
  7406. }
  7407. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7408. if (!lua_interface)
  7409. return 0;
  7410. Spawn* spawn = lua_interface->GetSpawn(state);
  7411. string name = lua_interface->GetStringValue(state, 2);
  7412. lua_interface->ResetFunctionStack(state);
  7413. if (!spawn) {
  7414. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7415. return 0;
  7416. }
  7417. if (!spawn->IsEntity()) {
  7418. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7419. return 0;
  7420. }
  7421. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7422. if (skill) {
  7423. lua_interface->SetSkillValue(state, skill);
  7424. return 1;
  7425. }
  7426. return 0;
  7427. }
  7428. int EQ2Emu_lua_AddProc(lua_State* state) {
  7429. if (!lua_interface)
  7430. return 0;
  7431. Spawn* spawn = lua_interface->GetSpawn(state);
  7432. int8 type = lua_interface->GetInt8Value(state, 2);
  7433. float chance = lua_interface->GetFloatValue(state, 3);
  7434. Item* item = lua_interface->GetItem(state, 4);
  7435. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7436. LuaSpell* spell = 0;
  7437. if (!spawn && (!spell || !use_all_spelltargets)) {
  7438. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7439. return 0;
  7440. }
  7441. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7442. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7443. return 0;
  7444. }
  7445. if (!item)
  7446. spell = lua_interface->GetCurrentSpell(state);
  7447. if (!item && !spell) {
  7448. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7449. return 0;
  7450. }
  7451. if(spell && spell->resisted) {
  7452. return 0;
  7453. }
  7454. if (spell && use_all_spelltargets) {
  7455. Spawn* target;
  7456. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7457. for (int8 i = 0; i < spell->targets.size(); i++) {
  7458. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7459. if (!target || !target->IsEntity())
  7460. continue;
  7461. ((Entity*)target)->AddProc(type, chance, item, spell);
  7462. }
  7463. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7464. }
  7465. else
  7466. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7467. return 0;
  7468. }
  7469. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7470. if (!lua_interface)
  7471. return 0;
  7472. Spawn* spawn = lua_interface->GetSpawn(state);
  7473. Item* item = lua_interface->GetItem(state, 2);
  7474. LuaSpell* spell = 0;
  7475. if (!spawn) {
  7476. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7477. lua_interface->ResetFunctionStack(state);
  7478. return 0;
  7479. }
  7480. if (!spawn->IsEntity()) {
  7481. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7482. lua_interface->ResetFunctionStack(state);
  7483. return 0;
  7484. }
  7485. if (!item)
  7486. spell = lua_interface->GetCurrentSpell(state);
  7487. lua_interface->ResetFunctionStack(state);
  7488. if (!item && !spell) {
  7489. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7490. return 0;
  7491. }
  7492. if (spell) {
  7493. Spawn* target;
  7494. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7495. for (int8 i = 0; i < spell->targets.size(); i++) {
  7496. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7497. if (!target || !target->IsEntity())
  7498. continue;
  7499. ((Entity*)target)->RemoveProc(item, spell);
  7500. }
  7501. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7502. spell->caster->RemoveProc(item, spell);
  7503. }
  7504. else
  7505. ((Entity*)spawn)->RemoveProc(item, spell);
  7506. return 0;
  7507. }
  7508. int EQ2Emu_lua_Knockback(lua_State* state) {
  7509. if (!lua_interface)
  7510. return 0;
  7511. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7512. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7513. int32 duration = lua_interface->GetInt32Value(state, 3);
  7514. float vertical = lua_interface->GetFloatValue(state, 4);
  7515. float horizontal = lua_interface->GetFloatValue(state, 5);
  7516. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7517. lua_interface->ResetFunctionStack(state);
  7518. if (!target_spawn) {
  7519. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7520. return 0;
  7521. }
  7522. if (!spawn) {
  7523. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7524. return 0;
  7525. }
  7526. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7527. Client* client = ((Player*)spawn)->GetClient();
  7528. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7529. if (packet) {
  7530. packet->setDataByName("target_x", target_spawn->GetX());
  7531. packet->setDataByName("target_y", target_spawn->GetY());
  7532. packet->setDataByName("target_z", target_spawn->GetZ());
  7533. packet->setDataByName("vertical_movement", vertical);
  7534. packet->setDataByName("horizontal_movement", horizontal);
  7535. if (use_heading)
  7536. packet->setDataByName("use_player_heading", 1);
  7537. client->QueuePacket(packet->serialize());
  7538. }
  7539. safe_delete(packet);
  7540. }
  7541. return 0;
  7542. }
  7543. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7544. if (!lua_interface)
  7545. return 0;
  7546. Spawn* spawn = lua_interface->GetSpawn(state);
  7547. lua_interface->ResetFunctionStack(state);
  7548. if (!spawn) {
  7549. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7550. return 0;
  7551. }
  7552. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7553. return 1;
  7554. }
  7555. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7556. if (!lua_interface)
  7557. return 0;
  7558. Spawn* caster = lua_interface->GetSpawn(state);
  7559. Spawn* target = lua_interface->GetSpawn(state, 2);
  7560. string name = lua_interface->GetStringValue(state, 3);
  7561. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7562. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7563. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7564. string success_msg = lua_interface->GetStringValue(state, 7);
  7565. string effect_msg = lua_interface->GetStringValue(state, 8);
  7566. lua_interface->ResetFunctionStack(state);
  7567. if (!caster) {
  7568. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7569. return 0;
  7570. }
  7571. if (!caster->IsEntity()) {
  7572. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7573. return 0;
  7574. }
  7575. if (!target) {
  7576. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7577. return 0;
  7578. }
  7579. if (!target->IsEntity()) {
  7580. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7581. return 0;
  7582. }
  7583. if (name.length() == 0) {
  7584. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7585. return 0;
  7586. }
  7587. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7588. return 0;
  7589. }
  7590. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7591. if (!lua_interface)
  7592. return 0;
  7593. string name = lua_interface->GetStringValue(state);
  7594. lua_interface->ResetFunctionStack(state);
  7595. if (name.length() == 0) {
  7596. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7597. return 0;
  7598. }
  7599. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7600. if (!skill) {
  7601. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7602. return 0;
  7603. }
  7604. lua_interface->SetInt32Value(state, skill->skill_id);
  7605. return 1;
  7606. }
  7607. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7608. if (!lua_interface)
  7609. return 0;
  7610. Spawn* spawn = lua_interface->GetSpawn(state);
  7611. lua_interface->ResetFunctionStack(state);
  7612. if (!spawn) {
  7613. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7614. return 0;
  7615. }
  7616. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7617. return 1;
  7618. }
  7619. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7620. if (!lua_interface)
  7621. return 0;
  7622. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7623. lua_interface->ResetFunctionStack(state);
  7624. if (!luaspell) {
  7625. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7626. return 0;
  7627. }
  7628. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7629. return 1;
  7630. }
  7631. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7632. if (!lua_interface)
  7633. return 0;
  7634. Spawn* spawn = lua_interface->GetSpawn(state);
  7635. Spawn* target = lua_interface->GetSpawn(state, 2);
  7636. lua_interface->ResetFunctionStack(state);
  7637. if (!spawn) {
  7638. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7639. return 0;
  7640. }
  7641. if (!spawn->IsEntity()) {
  7642. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7643. return 0;
  7644. }
  7645. if (!target) {
  7646. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7647. return 0;
  7648. }
  7649. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7650. return 1;
  7651. }
  7652. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7653. if (!lua_interface)
  7654. return 0;
  7655. Spawn* spawn = lua_interface->GetSpawn(state);
  7656. Spawn* target = lua_interface->GetSpawn(state, 2);
  7657. lua_interface->ResetFunctionStack(state);
  7658. if (!spawn) {
  7659. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7660. return 0;
  7661. }
  7662. if (!spawn->IsEntity()) {
  7663. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7664. return 0;
  7665. }
  7666. if (!target) {
  7667. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7668. return 0;
  7669. }
  7670. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7671. return 1;
  7672. }
  7673. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7674. if (!lua_interface)
  7675. return 0;
  7676. Item* item = lua_interface->GetItem(state);
  7677. lua_interface->ResetFunctionStack(state);
  7678. if (!item) {
  7679. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7680. return 0;
  7681. }
  7682. lua_interface->SetInt32Value(state, item->details.count);
  7683. return 1;
  7684. }
  7685. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7686. if (!lua_interface)
  7687. return 0;
  7688. Item* item = lua_interface->GetItem(state);
  7689. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7690. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7691. lua_interface->ResetFunctionStack(state);
  7692. if (!item) {
  7693. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7694. return 0;
  7695. }
  7696. if (!owner) {
  7697. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7698. return 0;
  7699. }
  7700. if (!owner->IsPlayer()) {
  7701. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7702. return 0;
  7703. }
  7704. if (item->stack_count < new_count) {
  7705. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7706. return 0;
  7707. }
  7708. if (new_count > 0) {
  7709. item->details.count = new_count;
  7710. item->save_needed = true;
  7711. }
  7712. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7713. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7714. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7715. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7716. else
  7717. {
  7718. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7719. return 0;
  7720. }
  7721. Client* client = ((Player*)owner)->GetClient();
  7722. if (!client)
  7723. return 0;
  7724. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7725. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7726. if (app)
  7727. client->QueuePacket(app);
  7728. return 0;
  7729. }
  7730. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7731. if (!lua_interface)
  7732. return 0;
  7733. int32 time = lua_interface->GetInt32Value(state);
  7734. string function = lua_interface->GetStringValue(state, 2);
  7735. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7736. Spawn* target = lua_interface->GetSpawn(state, 4);
  7737. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7738. lua_interface->ResetFunctionStack(state);
  7739. if (time == 0) {
  7740. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7741. return 0;
  7742. }
  7743. if (function.length() == 0) {
  7744. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7745. return 0;
  7746. }
  7747. if (!spell) {
  7748. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7749. return 0;
  7750. }
  7751. SpellScriptTimer* timer = new SpellScriptTimer;
  7752. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7753. #ifdef WIN32
  7754. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7755. #else
  7756. bzero(timer, sizeof(SpellScriptTimer));
  7757. #endif*/
  7758. timer->caster = 0;
  7759. timer->deleteWhenDone = false;
  7760. timer->target = 0;
  7761. timer->time = Timer::GetCurrentTime2() + time;
  7762. timer->customFunction = function;
  7763. timer->spell = spell;
  7764. if (caster)
  7765. timer->caster = caster->GetID();
  7766. if (target)
  7767. timer->target = target->GetID();
  7768. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7769. return 0;
  7770. }
  7771. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7772. if (!lua_interface)
  7773. return 0;
  7774. float hp_perc = lua_interface->GetFloatValue(state);
  7775. float power_perc = lua_interface->GetFloatValue(state, 2);
  7776. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7777. Spawn* target = lua_interface->GetSpawn(state, 4);
  7778. string heal_name = lua_interface->GetStringValue(state, 5);
  7779. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7780. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7781. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7782. lua_interface->ResetFunctionStack(state);
  7783. if (!spell) {
  7784. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7785. return 0;
  7786. }
  7787. Entity* caster = spell->caster;
  7788. if (!caster) {
  7789. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7790. return 0;
  7791. }
  7792. Client* client = 0;
  7793. PendingResurrection* rez = 0;
  7794. ZoneServer* zone = spell->caster->GetZone();
  7795. if (!target) {
  7796. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7797. if (spell->targets.size() > 0) {
  7798. vector<int32> spell_targets = spell->targets;
  7799. for (int8 i = 0; i < spell_targets.size(); i++) {
  7800. target = zone->GetSpawnByID(spell_targets.at(i));
  7801. if (!target)
  7802. continue;
  7803. if (!target->IsPlayer())
  7804. continue;
  7805. client = ((Player*)target)->GetClient();
  7806. if (!client)
  7807. continue;
  7808. rez = client->GetCurrentRez();
  7809. if (rez->active)
  7810. continue;
  7811. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7812. rez->active = true;
  7813. rez->caster = caster;
  7814. rez->expire_timer = new Timer;
  7815. int32 duration = spell->spell->GetSpellDuration();
  7816. rez->expire_timer->Start(duration * 100);
  7817. rez->hp_perc = hp_perc;
  7818. rez->mp_perc = power_perc;
  7819. rez->range = spell->spell->GetSpellData()->range;
  7820. rez->spell_name = spell->spell->GetName();
  7821. if (heal_name.length() > 0)
  7822. rez->heal_name = heal_name;
  7823. else
  7824. rez->heal_name = rez->spell_name;
  7825. rez->no_calcs = no_calcs;
  7826. rez->crit_mod = crit_mod;
  7827. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7828. if (send_window)
  7829. client->SendResurrectionWindow();
  7830. else {
  7831. target->GetZone()->ResurrectSpawn(target, client);
  7832. rez->should_delete = true;
  7833. }
  7834. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7835. }
  7836. }
  7837. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7838. }
  7839. else {
  7840. if(!target->IsPlayer())
  7841. return 0;
  7842. client = ((Player*)target)->GetClient();
  7843. if (!client)
  7844. return 0;
  7845. rez = client->GetCurrentRez();
  7846. if (rez->active)
  7847. return 0;
  7848. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7849. rez->active = true;
  7850. rez->caster = caster;
  7851. rez->expire_timer = new Timer;
  7852. int32 duration = spell->spell->GetSpellDuration();
  7853. rez->expire_timer->Start(duration * 100);
  7854. rez->hp_perc = hp_perc;
  7855. rez->mp_perc = power_perc;
  7856. rez->range = spell->spell->GetSpellData()->range;
  7857. rez->spell_name = spell->spell->GetName();
  7858. if (heal_name.length() > 0)
  7859. rez->heal_name = heal_name;
  7860. else
  7861. rez->heal_name = rez->spell_name;
  7862. rez->no_calcs = no_calcs;
  7863. rez->crit_mod = crit_mod;
  7864. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7865. if (send_window)
  7866. client->SendResurrectionWindow();
  7867. else {
  7868. target->GetZone()->ResurrectSpawn(target, client);
  7869. rez->should_delete = true;
  7870. }
  7871. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7872. }
  7873. return 0;
  7874. }
  7875. int EQ2Emu_lua_SetVision(lua_State* state) {
  7876. if (!lua_interface)
  7877. return 0;
  7878. Spawn* spawn = lua_interface->GetSpawn(state);
  7879. int8 vision = lua_interface->GetInt8Value(state, 2);
  7880. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7881. lua_interface->ResetFunctionStack(state);
  7882. if (!spawn) {
  7883. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7884. return 0;
  7885. }
  7886. if (!spawn->IsEntity()) {
  7887. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7888. return 0;
  7889. }
  7890. if (spell && spell->targets.size() > 0) {
  7891. ZoneServer* zone = spell->caster->GetZone();
  7892. for (int8 i = 0; i < spell->targets.size(); i++) {
  7893. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7894. if (target && target->IsEntity()) {
  7895. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7896. if (target->IsPlayer())
  7897. ((Player*)target)->SetCharSheetChanged(true);
  7898. }
  7899. }
  7900. }
  7901. else {
  7902. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7903. if (spawn->IsPlayer())
  7904. ((Player*)spawn)->SetCharSheetChanged(true);
  7905. }
  7906. return 0;
  7907. }
  7908. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7909. if (!lua_interface)
  7910. return 0;
  7911. Spawn* spawn = lua_interface->GetSpawn(state);
  7912. float intensity = lua_interface->GetFloatValue(state, 2);
  7913. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7914. lua_interface->ResetFunctionStack(state);
  7915. if (!spawn) {
  7916. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7917. return 0;
  7918. }
  7919. if (!spawn->IsEntity()) {
  7920. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7921. return 0;
  7922. }
  7923. if (spell && spell->targets.size() > 0) {
  7924. ZoneServer* zone = spell->caster->GetZone();
  7925. for (int8 i = 0; i < spell->targets.size(); i++) {
  7926. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7927. if (target && target->IsEntity()) {
  7928. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7929. if (target->IsPlayer())
  7930. ((Player*)target)->SetCharSheetChanged(true);
  7931. }
  7932. }
  7933. }
  7934. else {
  7935. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7936. if (spawn->IsPlayer())
  7937. ((Player*)spawn)->SetCharSheetChanged(true);
  7938. }
  7939. return 0;
  7940. }
  7941. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7942. if (!lua_interface)
  7943. return 0;
  7944. Spawn* spawn = lua_interface->GetSpawn(state);
  7945. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7946. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7947. lua_interface->ResetFunctionStack(state);
  7948. if (!spawn) {
  7949. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7950. return 0;
  7951. }
  7952. if (!spawn->IsEntity()) {
  7953. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7954. return 0;
  7955. }
  7956. if (spell && spell->targets.size() > 0) {
  7957. ZoneServer* zone = spell->caster->GetZone();
  7958. for (int8 i = 0; i < spell->targets.size(); i++) {
  7959. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7960. if (target && target->IsEntity()) {
  7961. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7962. if (target->IsPlayer())
  7963. ((Player*)target)->SetCharSheetChanged(true);
  7964. }
  7965. }
  7966. }
  7967. else {
  7968. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7969. if (spawn->IsPlayer())
  7970. ((Player*)spawn)->SetCharSheetChanged(true);
  7971. }
  7972. return 0;
  7973. }
  7974. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7975. if (!lua_interface)
  7976. return 0;
  7977. Item* item = lua_interface->GetItem(state);
  7978. int8 type = lua_interface->GetInt32Value(state, 2);
  7979. lua_interface->ResetFunctionStack(state);
  7980. if (!item) {
  7981. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7982. return 0;
  7983. }
  7984. if (type == 1)
  7985. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7986. else if (type == 2)
  7987. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7988. return 1;
  7989. }
  7990. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7991. if (!lua_interface)
  7992. return 0;
  7993. Spawn* target = lua_interface->GetSpawn(state);
  7994. float val = lua_interface->GetFloatValue(state, 2);
  7995. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7996. lua_interface->ResetFunctionStack(state);
  7997. // Added from Gangrenous post
  7998. if (spell && spell->resisted)
  7999. return 0;
  8000. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8001. if (val > 1.0f)
  8002. val = 1.0f - (val / 100.0f);
  8003. if (spell && spell->spell && spell->targets.size() > 0) {
  8004. ZoneServer* zone = spell->caster->GetZone();
  8005. for (int32 i = 0; i != spell->targets.size(); i++) {
  8006. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8007. if (spawn && spawn->IsEntity()) {
  8008. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8009. if (spawn->IsPlayer())
  8010. ((Player*)spawn)->SetCharSheetChanged(true);
  8011. }
  8012. }
  8013. }
  8014. else {
  8015. if (target && target->IsEntity()) {
  8016. ((Entity*)target)->SetSpeedMultiplier(val);
  8017. if (target->IsPlayer())
  8018. ((Player*)target)->SetCharSheetChanged(true);
  8019. }
  8020. }
  8021. return 0;
  8022. }
  8023. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8024. if (!lua_interface)
  8025. return 0;
  8026. Spawn* spawn = lua_interface->GetSpawn(state);
  8027. int16 model = lua_interface->GetInt16Value(state, 2);
  8028. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8029. lua_interface->ResetFunctionStack(state);
  8030. if (spell && spell->spell && spell->targets.size() > 0) {
  8031. ZoneServer* zone = spell->caster->GetZone();
  8032. for (int32 i = 0; i < spell->targets.size(); i++) {
  8033. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8034. if (target)
  8035. target->SetIllusionModel(model);
  8036. }
  8037. }
  8038. else {
  8039. if (!spawn) {
  8040. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8041. return 0;
  8042. }
  8043. spawn->SetIllusionModel(model);
  8044. }
  8045. return 0;
  8046. }
  8047. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8048. if (!lua_interface)
  8049. return 0;
  8050. Spawn* spawn = lua_interface->GetSpawn(state);
  8051. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8052. lua_interface->ResetFunctionStack(state);
  8053. if (spell && spell->spell && spell->targets.size() > 0) {
  8054. ZoneServer* zone = spell->caster->GetZone();
  8055. for (int32 i = 0; i < spell->targets.size(); i++) {
  8056. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8057. if (target)
  8058. target->SetIllusionModel(0);
  8059. }
  8060. }
  8061. else {
  8062. if (!spawn) {
  8063. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8064. return 0;
  8065. }
  8066. spawn->SetIllusionModel(0);
  8067. }
  8068. return 0;
  8069. }
  8070. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8071. if (!lua_interface)
  8072. return 0;
  8073. Spawn* caster = lua_interface->GetSpawn(state);
  8074. Spawn* target = lua_interface->GetSpawn(state, 2);
  8075. float chance = lua_interface->GetFloatValue(state, 3);
  8076. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8077. lua_interface->ResetFunctionStack(state);
  8078. if (!caster) {
  8079. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8080. return 0;
  8081. }
  8082. if (!caster->IsEntity()) {
  8083. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8084. return 0;
  8085. }
  8086. if (!target) {
  8087. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8088. return 0;
  8089. }
  8090. if (!target->IsEntity()) {
  8091. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8092. return 0;
  8093. }
  8094. if (chance <= 0) {
  8095. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8096. return 0;
  8097. }
  8098. if (!spell) {
  8099. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8100. return 0;
  8101. }
  8102. if(spell->resisted) {
  8103. return 0;
  8104. }
  8105. if (((Entity*)caster)->GetThreatTransfer()) {
  8106. return 0;
  8107. }
  8108. ThreatTransfer* transfer = new ThreatTransfer;
  8109. transfer->Target = target->GetID();
  8110. transfer->Amount = chance;
  8111. transfer->Spell = spell;
  8112. ((Entity*)caster)->SetThreatTransfer(transfer);
  8113. return 0;
  8114. }
  8115. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8116. if (!lua_interface)
  8117. return 0;
  8118. Spawn* spawn = lua_interface->GetSpawn(state);
  8119. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8120. lua_interface->ResetFunctionStack(state);
  8121. if (!spawn) {
  8122. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8123. return 0;
  8124. }
  8125. if (!spell) {
  8126. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8127. return 0;
  8128. }
  8129. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8130. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8131. if(transfer && transfer->Spell != spell) {
  8132. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8133. return 0;
  8134. }
  8135. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8136. }
  8137. return 0;
  8138. }
  8139. int EQ2Emu_lua_CureByType(lua_State* state) {
  8140. if (!lua_interface)
  8141. return 0;
  8142. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8143. int8 cure_count = lua_interface->GetInt8Value(state);
  8144. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8145. string cure_name = lua_interface->GetStringValue(state, 3);
  8146. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8147. Spawn* target = lua_interface->GetSpawn(state, 5);
  8148. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8149. lua_interface->ResetFunctionStack(state);
  8150. if(spell && spell->resisted) {
  8151. return 0;
  8152. }
  8153. if (target) {
  8154. if (!target->IsEntity()) {
  8155. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8156. return 0;
  8157. }
  8158. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8159. std::string alternate_name = "item";
  8160. if(spell)
  8161. alternate_name = std::string(spell->spell->GetName());
  8162. if(!caster && spell)
  8163. caster = (Spawn*)spell->caster;
  8164. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8165. }
  8166. }
  8167. else {
  8168. ZoneServer* zone = spell->caster->GetZone();
  8169. vector<int32> targets = spell->targets;
  8170. vector<Entity*> targets_to_cure;
  8171. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8172. for (int8 i = 0; i < targets.size(); i++) {
  8173. target = zone->GetSpawnByID(targets.at(i));
  8174. if (!target || !target->IsEntity())
  8175. continue;
  8176. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8177. targets_to_cure.push_back((Entity*)target);
  8178. }
  8179. }
  8180. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8181. vector<Entity*>::iterator itr;
  8182. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8183. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8184. }
  8185. }
  8186. return 0;
  8187. }
  8188. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8189. if (!lua_interface)
  8190. return 0;
  8191. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8192. if (!spell) {
  8193. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8194. lua_interface->ResetFunctionStack(state);
  8195. return 0;
  8196. }
  8197. if(spell->resisted) {
  8198. lua_interface->ResetFunctionStack(state);
  8199. return 0;
  8200. }
  8201. int8 cure_count = lua_interface->GetInt8Value(state);
  8202. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8203. string cure_name = lua_interface->GetStringValue(state, 3);
  8204. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8205. Spawn* target = lua_interface->GetSpawn(state, 5);
  8206. lua_interface->ResetFunctionStack(state);
  8207. if (target) {
  8208. if (!target->IsEntity()) {
  8209. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8210. return 0;
  8211. }
  8212. if (((Entity*)target)->GetDetCount() > 0)
  8213. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8214. }
  8215. else {
  8216. ZoneServer* zone = spell->caster->GetZone();
  8217. vector<int32> targets = spell->targets;
  8218. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8219. for (int8 i = 0; i < targets.size(); i++) {
  8220. target = zone->GetSpawnByID(targets.at(i));
  8221. if (!target || !target->IsEntity())
  8222. continue;
  8223. if (((Entity*)target)->GetDetCount() > 0)
  8224. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8225. }
  8226. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8227. }
  8228. return 0;
  8229. }
  8230. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8231. if (!lua_interface)
  8232. return 0;
  8233. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8234. lua_interface->ResetFunctionStack(state);
  8235. if (!spell) {
  8236. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8237. return 0;
  8238. }
  8239. if (!spell->caster) {
  8240. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8241. return 0;
  8242. }
  8243. if (!spell->caster->GetZone()) {
  8244. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8248. return 0;
  8249. }
  8250. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8251. if (!lua_interface)
  8252. return 0;
  8253. Spawn* spawn = lua_interface->GetSpawn(state);
  8254. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8255. lua_interface->ResetFunctionStack(state);
  8256. if (!spell) {
  8257. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8258. return 0;
  8259. }
  8260. if (spawn && spawn->IsEntity())
  8261. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8262. else {
  8263. ZoneServer* zone = spell->caster->GetZone();
  8264. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8265. for (int32 i = 0; i < spell->targets.size(); i++) {
  8266. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8267. if (!spawn || !spawn->IsEntity())
  8268. continue;
  8269. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8270. }
  8271. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8272. }
  8273. return 0;
  8274. }
  8275. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8276. if (!lua_interface)
  8277. return 0;
  8278. Spawn* spawn = lua_interface->GetSpawn(state);
  8279. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8280. lua_interface->ResetFunctionStack(state);
  8281. if (!spell) {
  8282. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8283. return 0;
  8284. }
  8285. if (spawn && spawn->IsEntity())
  8286. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8287. else {
  8288. ZoneServer* zone = spell->caster->GetZone();
  8289. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8290. for (int32 i = 0; i < spell->targets.size(); i++) {
  8291. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8292. if (!spawn || !spawn->IsEntity())
  8293. continue;
  8294. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8295. }
  8296. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8297. }
  8298. return 0;
  8299. }
  8300. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8301. if (!lua_interface)
  8302. return 0;
  8303. Spawn* caster = lua_interface->GetSpawn(state);
  8304. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8305. lua_interface->ResetFunctionStack(state);
  8306. if (!caster) {
  8307. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8308. return 0;
  8309. }
  8310. if (!caster->IsPlayer()) {
  8311. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8312. return 0;
  8313. }
  8314. Spawn* target = caster->GetTarget();
  8315. if (!target) {
  8316. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8317. return 0;
  8318. }
  8319. Client* client = ((Player*)caster)->GetClient();
  8320. if (!client) {
  8321. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8325. if (ho) {
  8326. ho->SetTarget(target->GetID());
  8327. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8328. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8329. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8330. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8331. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8332. deque<GroupMemberInfo*>::iterator itr;
  8333. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8334. if (group)
  8335. {
  8336. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8337. deque<GroupMemberInfo*>* members = group->GetMembers();
  8338. for (itr = members->begin(); itr != members->end(); itr++) {
  8339. if ((*itr)->client)
  8340. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8341. }
  8342. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8343. }
  8344. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8345. }
  8346. else
  8347. safe_delete(ho);
  8348. }
  8349. else {
  8350. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8351. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8352. }
  8353. else
  8354. safe_delete(ho);
  8355. }
  8356. }
  8357. return 0;
  8358. }
  8359. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8360. if (!lua_interface)
  8361. return 0;
  8362. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8363. if (!spell) {
  8364. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8365. return 0;
  8366. }
  8367. int16 triggerCount = lua_interface->GetInt16Value(state);
  8368. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8369. if (!triggerCount) {
  8370. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8371. return 0;
  8372. }
  8373. spell->num_triggers = triggerCount;
  8374. spell->had_triggers = true;
  8375. spell->cancel_after_all_triggers = cancel_after_triggers;
  8376. return 0;
  8377. }
  8378. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8379. if (!lua_interface)
  8380. return 0;
  8381. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8382. lua_interface->ResetFunctionStack(state);
  8383. if (!spell) {
  8384. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8385. return 0;
  8386. }
  8387. lua_interface->SetInt32Value(state, spell->num_triggers);
  8388. return 1;
  8389. }
  8390. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8391. if (!lua_interface)
  8392. return 0;
  8393. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8394. if (!spell) {
  8395. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8396. lua_interface->ResetFunctionStack(state);
  8397. return 0;
  8398. }
  8399. int16 remove_count = lua_interface->GetInt16Value(state);
  8400. lua_interface->ResetFunctionStack(state);
  8401. if (!remove_count)
  8402. remove_count = 1;
  8403. if (remove_count >= spell->num_triggers) {
  8404. spell->num_triggers = 0;
  8405. if (spell->cancel_after_all_triggers)
  8406. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8407. }
  8408. else {
  8409. spell->num_triggers -= remove_count;
  8410. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8411. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8412. }
  8413. return 0;
  8414. }
  8415. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8416. if (!lua_interface)
  8417. return 0;
  8418. Spawn* spawn = lua_interface->GetSpawn(state);
  8419. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8420. lua_interface->ResetFunctionStack(state);
  8421. if (!spawn) {
  8422. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. if (!copy_spawn) {
  8426. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8427. return 0;
  8428. }
  8429. spawn->CopySpawnAppearance(copy_spawn);
  8430. return 0;
  8431. }
  8432. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8433. Spawn* spawn = lua_interface->GetSpawn(state);
  8434. int8 type = lua_interface->GetInt8Value(state, 2);
  8435. lua_interface->ResetFunctionStack(state);
  8436. if (!spawn) {
  8437. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8438. return 0;
  8439. }
  8440. else if (!spawn->IsEntity()) {
  8441. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8442. return 0;
  8443. }
  8444. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8445. return 1;
  8446. }
  8447. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8448. if (!lua_interface)
  8449. return 0;
  8450. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8451. int8 type = lua_interface->GetInt8Value(state);
  8452. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8453. lua_interface->ResetFunctionStack(state);
  8454. if (!spell) {
  8455. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. if(spell->resisted) {
  8459. return 0;
  8460. }
  8461. if (spawn) {
  8462. if (!spawn->IsEntity()) {
  8463. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8464. return 0;
  8465. }
  8466. Entity* entity = ((Entity*)spawn);
  8467. entity->AddImmunity(spell, type);
  8468. }
  8469. else {
  8470. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8471. for (int8 i = 0; i < spell->targets.size(); i++) {
  8472. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8473. if (!spawn || !spawn->IsEntity())
  8474. continue;
  8475. Entity* entity = ((Entity*)spawn);
  8476. entity->AddImmunity(spell, type);
  8477. }
  8478. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8479. }
  8480. return 0;
  8481. }
  8482. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8483. if (!lua_interface)
  8484. return 0;
  8485. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8486. int8 type = lua_interface->GetInt8Value(state);
  8487. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8488. lua_interface->ResetFunctionStack(state);
  8489. if (!spell) {
  8490. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8491. return 0;
  8492. }
  8493. if (spawn) {
  8494. if (!spawn->IsEntity()) {
  8495. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8496. return 0;
  8497. }
  8498. Entity* entity = ((Entity*)spawn);
  8499. entity->RemoveImmunity(spell, type);
  8500. }
  8501. else {
  8502. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8503. for (int8 i = 0; i < spell->targets.size(); i++) {
  8504. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8505. if (!spawn || !spawn->IsEntity())
  8506. continue;
  8507. Entity* entity = ((Entity*)spawn);
  8508. entity->RemoveImmunity(spell, type);
  8509. }
  8510. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8511. }
  8512. return 0;
  8513. }
  8514. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8515. if (!lua_interface)
  8516. return 0;
  8517. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8518. if (!spell) {
  8519. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8520. lua_interface->ResetFunctionStack(state);
  8521. return 0;
  8522. }
  8523. if(spell->resisted) {
  8524. lua_interface->ResetFunctionStack(state);
  8525. return 0;
  8526. }
  8527. float snare = lua_interface->GetFloatValue(state);
  8528. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8529. lua_interface->ResetFunctionStack(state);
  8530. // convert the val to the speed multipler value (100 - val)
  8531. float val = 100.0 - snare;
  8532. val /= 100.0;
  8533. if (spawn) {
  8534. if (!spawn->IsEntity()) {
  8535. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. ((Entity*)spawn)->SetSnareValue(spell, val);
  8539. }
  8540. else {
  8541. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8542. for (int8 i = 0; i < spell->targets.size(); i++) {
  8543. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8544. if (!spawn || !spawn->IsEntity())
  8545. continue;
  8546. ((Entity*)spawn)->SetSnareValue(spell, val);
  8547. }
  8548. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8549. }
  8550. return 0;
  8551. }
  8552. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8553. if (!lua_interface)
  8554. return 0;
  8555. Spawn* spawn = lua_interface->GetSpawn(state);
  8556. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8557. lua_interface->ResetFunctionStack(state);
  8558. if (!spawn) {
  8559. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8560. return 0;
  8561. }
  8562. if (race_id == 0) {
  8563. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8564. return 0;
  8565. }
  8566. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8567. return 1;
  8568. }
  8569. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8570. if (!lua_interface)
  8571. return 0;
  8572. Spawn* spawn = lua_interface->GetSpawn(state);
  8573. lua_interface->ResetFunctionStack(state);
  8574. if (!spawn) {
  8575. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8576. return 0;
  8577. }
  8578. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8579. return 1;
  8580. }
  8581. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8582. if (!lua_interface)
  8583. return 0;
  8584. Spawn* spawn = lua_interface->GetSpawn(state);
  8585. lua_interface->ResetFunctionStack(state);
  8586. if (!spawn) {
  8587. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8588. return 0;
  8589. }
  8590. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8591. return 1;
  8592. }
  8593. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8594. if (!lua_interface)
  8595. return 0;
  8596. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8597. lua_interface->ResetFunctionStack(state);
  8598. if (!spell) {
  8599. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8600. return 0;
  8601. }
  8602. lua_interface->SetStringValue(state, spell->spell->GetName());
  8603. return 1;
  8604. }
  8605. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8606. if (!lua_interface)
  8607. return 0;
  8608. Quest* quest = lua_interface->GetQuest(state);
  8609. lua_interface->ResetFunctionStack(state);
  8610. if (!quest) {
  8611. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8612. return 0;
  8613. }
  8614. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8615. return 1;
  8616. }
  8617. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8618. if (!lua_interface)
  8619. return 0;
  8620. Quest* quest = lua_interface->GetQuest(state);
  8621. int32 flags = lua_interface->GetInt32Value(state, 2);
  8622. lua_interface->ResetFunctionStack(state);
  8623. if (!quest) {
  8624. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8625. return 0;
  8626. }
  8627. quest->SetQuestFlags(flags);
  8628. return 0;
  8629. }
  8630. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8631. if (!lua_interface)
  8632. return 0;
  8633. Quest* quest = lua_interface->GetQuest(state);
  8634. Spawn* player = lua_interface->GetSpawn(state, 2);
  8635. int32 step = lua_interface->GetInt32Value(state, 3);
  8636. int32 duration = lua_interface->GetInt32Value(state, 4);
  8637. string action = lua_interface->GetStringValue(state, 5);
  8638. lua_interface->ResetFunctionStack(state);
  8639. if (!quest) {
  8640. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8641. return 0;
  8642. }
  8643. if (!player) {
  8644. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8645. return 0;
  8646. }
  8647. if (!player->IsPlayer()) {
  8648. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8649. return 0;
  8650. }
  8651. if (step == 0) {
  8652. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8653. return 0;
  8654. }
  8655. if (duration == 0) {
  8656. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8657. return 0;
  8658. }
  8659. if (action.length() == 0) {
  8660. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8661. return 0;
  8662. }
  8663. Client* client = ((Player*)player)->GetClient();
  8664. if (!client) {
  8665. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8666. return 0;
  8667. }
  8668. quest->SetTimerStep(step);
  8669. quest->AddFailedAction(step, action);
  8670. quest->SetStepTimer(duration);
  8671. client->AddQuestTimer(quest->GetQuestID());
  8672. return 0;
  8673. }
  8674. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8675. if (!lua_interface)
  8676. return 0;
  8677. Quest* quest = lua_interface->GetQuest(state);
  8678. Spawn* player = lua_interface->GetSpawn(state, 2);
  8679. lua_interface->ResetFunctionStack(state);
  8680. if (!quest) {
  8681. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8682. return 0;
  8683. }
  8684. if (!player) {
  8685. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8686. return 0;
  8687. }
  8688. if (!player->IsPlayer()) {
  8689. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8690. return 0;
  8691. }
  8692. Client* client = ((Player*)player)->GetClient();
  8693. if (!client) {
  8694. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8695. return 0;
  8696. }
  8697. quest->SetTimerStep(0);
  8698. quest->SetStepTimer(0);
  8699. client->RemoveQuestTimer(quest->GetQuestID());
  8700. return 0;
  8701. }
  8702. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8703. if (!lua_interface)
  8704. return 0;
  8705. Spawn* player = lua_interface->GetSpawn(state);
  8706. Quest* quest = lua_interface->GetQuest(state, 2);
  8707. int32 step = lua_interface->GetInt32Value(state, 3);
  8708. lua_interface->ResetFunctionStack(state);
  8709. if (!player) {
  8710. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8711. return 0;
  8712. }
  8713. if (!player->IsPlayer()) {
  8714. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8715. return 0;
  8716. }
  8717. if (!quest) {
  8718. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8719. return 0;
  8720. }
  8721. if (step == 0) {
  8722. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8723. return 0;
  8724. }
  8725. Client* client = ((Player*)player)->GetClient();
  8726. if (!client) {
  8727. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8728. return 0;
  8729. }
  8730. if (quest->RemoveQuestStep(step, client)) {
  8731. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8732. client->GetCurrentZone()->SendQuestUpdates(client);
  8733. }
  8734. else
  8735. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8736. return 0;
  8737. }
  8738. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8739. if (!lua_interface)
  8740. return 0;
  8741. Quest* quest = lua_interface->GetQuest(state, 1);
  8742. int32 step = lua_interface->GetInt32Value(state, 2);
  8743. string desc = lua_interface->GetStringValue(state, 3);
  8744. string task_group = lua_interface->GetStringValue(state, 4);
  8745. lua_interface->ResetFunctionStack(state);
  8746. if (!quest) {
  8747. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8748. return 0;
  8749. }
  8750. if (step == 0) {
  8751. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8752. return 0;
  8753. }
  8754. QuestStep* quest_step = quest->GetQuestStep(step);
  8755. if (!quest_step) {
  8756. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8757. return 0;
  8758. }
  8759. quest_step->SetStepProgress(0);
  8760. quest_step->SetTaskGroup(task_group);
  8761. quest_step->SetDescription(desc);
  8762. return 0;
  8763. }
  8764. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8765. if (!lua_interface)
  8766. return 0;
  8767. Quest* quest = lua_interface->GetQuest(state);
  8768. int32 step = lua_interface->GetInt32Value(state, 2);
  8769. string action = lua_interface->GetStringValue(state, 3);
  8770. lua_interface->ResetFunctionStack(state);
  8771. if (!quest) {
  8772. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8773. return 0;
  8774. }
  8775. if (step == 0) {
  8776. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8777. return 0;
  8778. }
  8779. if (action.length() == 0) {
  8780. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8781. return 0;
  8782. }
  8783. quest->AddFailedAction(step, action);
  8784. return 0;
  8785. }
  8786. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8787. if (!lua_interface)
  8788. return 0;
  8789. Spawn* player = lua_interface->GetSpawn(state);
  8790. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8791. int32 step = lua_interface->GetInt32Value(state, 3);
  8792. lua_interface->ResetFunctionStack(state);
  8793. if (!player) {
  8794. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8795. return 0;
  8796. }
  8797. if (!player->IsPlayer()) {
  8798. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8799. return 0;
  8800. }
  8801. if (quest_id == 0) {
  8802. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8803. return 0;
  8804. }
  8805. if (step == 0) {
  8806. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8807. return 0;
  8808. }
  8809. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8810. if (!quest) {
  8811. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8812. return 0;
  8813. }
  8814. quest->StepFailed(step);
  8815. return 0;
  8816. }
  8817. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8818. if (!lua_interface)
  8819. return 0;
  8820. Spawn* player = lua_interface->GetSpawn(state);
  8821. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8822. lua_interface->ResetFunctionStack(state);
  8823. if (!player) {
  8824. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8825. return 0;
  8826. }
  8827. if (!player->IsPlayer()) {
  8828. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8829. return 0;
  8830. }
  8831. if (quest_id == 0) {
  8832. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8833. return 0;
  8834. }
  8835. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8836. if (!quest) {
  8837. lua_interface->SetInt32Value(state, 0);
  8838. return 1;
  8839. }
  8840. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8841. return 1;
  8842. }
  8843. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8844. if (!lua_interface)
  8845. return 0;
  8846. string name = lua_interface->GetStringValue(state);
  8847. string value = lua_interface->GetStringValue(state, 2);
  8848. string comment = lua_interface->GetStringValue(state, 3);
  8849. lua_interface->ResetFunctionStack(state);
  8850. if (name.length() == 0) {
  8851. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8852. return 0;
  8853. }
  8854. if (value.length() == 0) {
  8855. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8856. return 0;
  8857. }
  8858. string varname = string("lua_").append(name);
  8859. Variable* var = variables.FindVariable(varname);
  8860. if (var)
  8861. var->SetValue(value.c_str());
  8862. else {
  8863. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8864. variables.AddVariable(var);
  8865. }
  8866. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8867. return 0;
  8868. }
  8869. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8870. if (!lua_interface)
  8871. return 0;
  8872. string name = lua_interface->GetStringValue(state);
  8873. lua_interface->ResetFunctionStack(state);
  8874. if (name.length() == 0) {
  8875. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8876. return 0;
  8877. }
  8878. string varname = string("lua_").append(name);
  8879. Variable* var = variables.FindVariable(varname);
  8880. if (var)
  8881. lua_interface->SetStringValue(state, var->GetValue());
  8882. else
  8883. lua_interface->SetStringValue(state, "NULL");
  8884. return 1;
  8885. }
  8886. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8887. if (!lua_interface)
  8888. return 0;
  8889. Spawn* player = lua_interface->GetSpawn(state);
  8890. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8891. lua_interface->ResetFunctionStack(state);
  8892. if (!player) {
  8893. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8894. return 0;
  8895. }
  8896. if (!player->IsPlayer()) {
  8897. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8898. return 0;
  8899. }
  8900. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8901. return 1;
  8902. }
  8903. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8904. if (!lua_interface)
  8905. return 0;
  8906. Spawn* player = lua_interface->GetSpawn(state);
  8907. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8908. lua_interface->ResetFunctionStack(state);
  8909. if (!player) {
  8910. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8911. return 0;
  8912. }
  8913. if (!player->IsPlayer()) {
  8914. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8915. return 0;
  8916. }
  8917. Language* language = master_languages_list.GetLanguage(language_id);
  8918. if (language)
  8919. {
  8920. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8921. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8922. }
  8923. return 0;
  8924. }
  8925. int EQ2Emu_lua_IsNight(lua_State* state) {
  8926. if (!lua_interface)
  8927. return 0;
  8928. ZoneServer* zone = lua_interface->GetZone(state);
  8929. lua_interface->ResetFunctionStack(state);
  8930. if (!zone) {
  8931. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8932. return 0;
  8933. }
  8934. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8935. return 1;
  8936. }
  8937. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8938. if (!lua_interface)
  8939. return 0;
  8940. Spawn* spawn = lua_interface->GetSpawn(state);
  8941. lua_interface->ResetFunctionStack(state);
  8942. if (!spawn) {
  8943. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8944. return 0;
  8945. }
  8946. if (!spawn->IsWidget()) {
  8947. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8948. return 0;
  8949. }
  8950. ((Widget*)spawn)->SetMultiFloorLift(true);
  8951. if (spawn->GetZone())
  8952. spawn->GetZone()->AddTransportSpawn(spawn);
  8953. return 0;
  8954. }
  8955. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8956. if (!lua_interface)
  8957. return 0;
  8958. Spawn* player = lua_interface->GetSpawn(state);
  8959. int32 path = lua_interface->GetInt32Value(state, 2);
  8960. lua_interface->ResetFunctionStack(state);
  8961. if (!player) {
  8962. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8963. return 0;
  8964. }
  8965. if (!player->IsPlayer()) {
  8966. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8967. return 0;
  8968. }
  8969. if (path == 0) {
  8970. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8971. return 0;
  8972. }
  8973. Client* client = ((Player*)player)->GetClient();
  8974. if (!client) {
  8975. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8976. return 0;
  8977. }
  8978. client->SendFlightAutoMount(path);
  8979. return 0;
  8980. }
  8981. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8982. if (!lua_interface)
  8983. return 0;
  8984. Spawn* player = lua_interface->GetSpawn(state);
  8985. if (!player) {
  8986. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8987. return 0;
  8988. }
  8989. if (!player->IsPlayer()) {
  8990. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8991. return 0;
  8992. }
  8993. Client* client = ((Player*)player)->GetClient();
  8994. if (!client) {
  8995. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8996. return 0;
  8997. }
  8998. client->EndAutoMount();
  8999. return 0;
  9000. }
  9001. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9002. if (!lua_interface)
  9003. return 0;
  9004. Spawn* player = lua_interface->GetSpawn(state);
  9005. lua_interface->ResetFunctionStack(state);
  9006. if (!player) {
  9007. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9008. return 0;
  9009. }
  9010. if (!player->IsPlayer()) {
  9011. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9012. return 0;
  9013. }
  9014. Client* client = ((Player*)player)->GetClient();
  9015. if (!client) {
  9016. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9017. return 0;
  9018. }
  9019. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9020. return 1;
  9021. }
  9022. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9023. if (!lua_interface)
  9024. return 0;
  9025. Spawn* player = lua_interface->GetSpawn(state);
  9026. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9027. int32 value = lua_interface->GetInt32Value(state, 3);
  9028. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9029. lua_interface->ResetFunctionStack(state);
  9030. if (!player) {
  9031. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9032. return 0;
  9033. }
  9034. if (!player->IsPlayer()) {
  9035. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9036. return 0;
  9037. }
  9038. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9039. return 0;
  9040. }
  9041. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9042. if (!lua_interface)
  9043. return 0;
  9044. Spawn* player = lua_interface->GetSpawn(state);
  9045. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9046. lua_interface->ResetFunctionStack(state);
  9047. if (!player) {
  9048. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9049. return 0;
  9050. }
  9051. if (!player->IsPlayer()) {
  9052. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9053. return 0;
  9054. }
  9055. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9056. if (!hd)
  9057. return 0;
  9058. lua_interface->SetInt32Value(state, hd->Value);
  9059. lua_interface->SetInt32Value(state, hd->Value2);
  9060. return 2;
  9061. }
  9062. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9063. if (!lua_interface)
  9064. return 0;
  9065. Spawn* spawn = lua_interface->GetSpawn(state);
  9066. int32 grid = lua_interface->GetInt32Value(state, 2);
  9067. lua_interface->ResetFunctionStack(state);
  9068. if (!spawn) {
  9069. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9070. return 0;
  9071. }
  9072. if (grid == 0) {
  9073. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9074. return 0;
  9075. }
  9076. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  9077. return 0;
  9078. }
  9079. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9080. if (!lua_interface)
  9081. return 0;
  9082. Spawn* spawn = lua_interface->GetSpawn(state);
  9083. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9084. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9085. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9086. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9087. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9088. lua_interface->ResetFunctionStack(state);
  9089. if (!spawn) {
  9090. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9091. return 0;
  9092. }
  9093. //Add this quest to the list of required quests for this spawn
  9094. spawn->SetRequiredHistory(event_id, value1, value2);
  9095. //If private spawn value set
  9096. if (private_spawn) {
  9097. //Set the spawn to be private when not granted access via history
  9098. spawn->AddAllowAccessSpawn(spawn);
  9099. spawn->SetPrivateQuestSpawn(true);
  9100. }
  9101. //This value will override vis_flags in the vis packet
  9102. if (flag_override > 0)
  9103. spawn->SetQuestsRequiredOverride(flag_override);
  9104. return 0;
  9105. }
  9106. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9107. if (!lua_interface)
  9108. return 0;
  9109. Spawn* player = lua_interface->GetSpawn(state);
  9110. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9111. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9112. lua_interface->ResetFunctionStack(state);
  9113. if (!player) {
  9114. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9115. return 0;
  9116. }
  9117. if (!player->IsPlayer()) {
  9118. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9119. return 0;
  9120. }
  9121. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9122. return 1;
  9123. }
  9124. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9125. if (!lua_interface)
  9126. return 0;
  9127. Spawn* player = lua_interface->GetSpawn(state);
  9128. int8 level = lua_interface->GetInt8Value(state, 2);
  9129. lua_interface->ResetFunctionStack(state);
  9130. if (!player) {
  9131. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9132. return 0;
  9133. }
  9134. if (!player->IsPlayer()) {
  9135. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9136. return 0;
  9137. }
  9138. if (level == 0) {
  9139. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9140. return 0;
  9141. }
  9142. Client* client = ((Player*)player)->GetClient();
  9143. if (!client) {
  9144. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9145. return 0;
  9146. }
  9147. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9148. return 0;
  9149. }
  9150. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9151. if (!lua_interface)
  9152. return 0;
  9153. Spawn* player = lua_interface->GetSpawn(state);
  9154. int32 amount = lua_interface->GetInt32Value(state, 2);
  9155. lua_interface->ResetFunctionStack(state);
  9156. if (!player) {
  9157. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9158. return 0;
  9159. }
  9160. if (!player->IsPlayer()) {
  9161. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9162. return 0;
  9163. }
  9164. if (amount == 0) {
  9165. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9166. return 0;
  9167. }
  9168. ((Player*)player)->AddCoins(amount);
  9169. return 0;
  9170. }
  9171. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9172. if (!lua_interface)
  9173. return 0;
  9174. Spawn* player = lua_interface->GetSpawn(state);
  9175. int32 amount = lua_interface->GetInt32Value(state, 2);
  9176. lua_interface->ResetFunctionStack(state);
  9177. if (!player) {
  9178. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9179. return 0;
  9180. }
  9181. if (!player->IsPlayer()) {
  9182. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9183. return 0;
  9184. }
  9185. if (amount == 0) {
  9186. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9187. return 0;
  9188. }
  9189. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9190. return 1;
  9191. }
  9192. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9193. if (!lua_interface)
  9194. return 0;
  9195. ZoneServer* zone = lua_interface->GetZone(state);
  9196. lua_interface->ResetFunctionStack(state);
  9197. if (!zone) {
  9198. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9199. return 0;
  9200. }
  9201. vector<Entity*> players = zone->GetPlayers();
  9202. if (players.size() == 0)
  9203. return 0;
  9204. lua_createtable(state, players.size(), 0);
  9205. int newTable = lua_gettop(state);
  9206. for (int32 i = 0; i < players.size(); i++) {
  9207. lua_interface->SetSpawnValue(state, players.at(i));
  9208. lua_rawseti(state, newTable, i + 1);
  9209. }
  9210. return 1;
  9211. }
  9212. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9213. if (!lua_interface)
  9214. return 0;
  9215. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9216. if (!zone) {
  9217. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9218. return 0;
  9219. }
  9220. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9221. lua_interface->ResetFunctionStack(state);
  9222. //Map of <placement_id, location_id>
  9223. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9224. map<int32, int32>::iterator itr;
  9225. vector<Spawn*> group;
  9226. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9227. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9228. if (!location) {
  9229. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9230. return 0;
  9231. }
  9232. Spawn* spawn = 0;
  9233. if (location->entities[0]) {
  9234. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9235. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9236. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9237. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9238. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9239. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9240. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9241. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9242. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9243. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9244. if(spawn && spawn->IsOmittedByDBFlag())
  9245. {
  9246. 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);
  9247. safe_delete(spawn);
  9248. continue;
  9249. }
  9250. if (spawn) {
  9251. const char* script = 0;
  9252. for (int x = 0; x < 3; x++) {
  9253. switch (x) {
  9254. case 0:
  9255. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9256. break;
  9257. case 1:
  9258. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9259. break;
  9260. case 2:
  9261. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9262. break;
  9263. }
  9264. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9265. spawn->SetSpawnScript(string(script));
  9266. break;
  9267. }
  9268. }
  9269. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9270. lua_interface->SetSpawnValue(state, spawn);
  9271. group.push_back(spawn);
  9272. }
  9273. else {
  9274. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9275. safe_delete(spawn);
  9276. }
  9277. }
  9278. }
  9279. if (!group.empty()) {
  9280. lua_createtable(state, group.size(), 0);
  9281. int newTable = lua_gettop(state);
  9282. for (int32 i = 0; i < group.size(); i++) {
  9283. lua_interface->SetSpawnValue(state, group[i]);
  9284. lua_rawseti(state, newTable, i + 1);
  9285. }
  9286. }
  9287. else
  9288. lua_pushnil(state);
  9289. return 1;
  9290. }
  9291. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9292. if (!lua_interface)
  9293. return 0;
  9294. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9295. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9296. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9297. lua_interface->ResetFunctionStack(state);
  9298. if (!spawn) {
  9299. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9300. return 0;
  9301. }
  9302. if (anim_id == 0) {
  9303. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9304. return 0;
  9305. }
  9306. if (leeway == 0)
  9307. leeway = 5000;
  9308. spawn->SetSpawnAnim(anim_id);
  9309. spawn->SetSpawnAnimLeeway(leeway);
  9310. return 0;
  9311. }
  9312. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9313. if (!lua_interface)
  9314. return 0;
  9315. Spawn* player = lua_interface->GetSpawn(state);
  9316. lua_interface->ResetFunctionStack(state);
  9317. if (!player || !player->IsPlayer()) {
  9318. return 0;
  9319. }
  9320. Client* client = ((Player*)player)->GetClient();
  9321. if (!client) {
  9322. return 0;
  9323. }
  9324. lua_interface->SetInt32Value(state, client->GetVersion());
  9325. return 1;
  9326. }
  9327. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9328. if (!lua_interface)
  9329. return 0;
  9330. Item* item = lua_interface->GetItem(state);
  9331. lua_interface->ResetFunctionStack(state);
  9332. if (!item) {
  9333. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9334. return 0;
  9335. }
  9336. lua_interface->SetInt32Value(state, item->details.item_id);
  9337. return 1;
  9338. }
  9339. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9340. if (!lua_interface)
  9341. return 0;
  9342. Spawn* spawn = lua_interface->GetSpawn(state);
  9343. lua_interface->ResetFunctionStack(state);
  9344. if (!spawn) {
  9345. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9346. return 0;
  9347. }
  9348. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9349. return 1;
  9350. }
  9351. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9352. if (!lua_interface)
  9353. return 0;
  9354. Spawn* spawn = lua_interface->GetSpawn(state);
  9355. lua_interface->ResetFunctionStack(state);
  9356. if (!spawn) {
  9357. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9358. return 0;
  9359. }
  9360. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9361. return 1;
  9362. }
  9363. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9364. if (!lua_interface)
  9365. return 0;
  9366. Spawn* spawn = lua_interface->GetSpawn(state);
  9367. lua_interface->ResetFunctionStack(state);
  9368. if (!spawn) {
  9369. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9370. return 0;
  9371. }
  9372. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9373. return 1;
  9374. }
  9375. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9376. if (!lua_interface)
  9377. return 0;
  9378. Spawn* spawn = lua_interface->GetSpawn(state);
  9379. lua_interface->ResetFunctionStack(state);
  9380. if (!spawn) {
  9381. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9382. return 0;
  9383. }
  9384. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9385. return 1;
  9386. }
  9387. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9388. if (!lua_interface)
  9389. return 0;
  9390. Spawn* spawn = lua_interface->GetSpawn(state);
  9391. float pct = lua_interface->GetFloatValue(state, 2);
  9392. lua_interface->ResetFunctionStack(state);
  9393. if (!spawn) {
  9394. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9395. return 0;
  9396. }
  9397. if (pct == 0) {
  9398. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9399. return 0;
  9400. }
  9401. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9402. lua_interface->SetInt32Value(state, amount);
  9403. return 1;
  9404. }
  9405. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9406. if (!lua_interface)
  9407. return 0;
  9408. Spawn* spawn = lua_interface->GetSpawn(state);
  9409. float pct = lua_interface->GetFloatValue(state, 2);
  9410. lua_interface->ResetFunctionStack(state);
  9411. if (!spawn) {
  9412. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9413. return 0;
  9414. }
  9415. if (pct == 0) {
  9416. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9417. return 0;
  9418. }
  9419. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9420. lua_interface->SetInt32Value(state, amount);
  9421. return 1;
  9422. }
  9423. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9424. if (!lua_interface)
  9425. return 0;
  9426. Spawn* spawn = lua_interface->GetSpawn(state);
  9427. lua_interface->ResetFunctionStack(state);
  9428. if (!spawn) {
  9429. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9430. return 0;
  9431. }
  9432. if (!spawn->IsPlayer()) {
  9433. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9434. return 0;
  9435. }
  9436. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9437. return 1;
  9438. }
  9439. int EQ2Emu_lua_Evac(lua_State* state) {
  9440. if (!lua_interface)
  9441. return 0;
  9442. Spawn* target = lua_interface->GetSpawn(state);
  9443. if (target) {
  9444. float x = target->GetZone()->GetSafeX();
  9445. float y = target->GetZone()->GetSafeY();
  9446. float z = target->GetZone()->GetSafeZ();
  9447. float h = target->GetZone()->GetSafeHeading();
  9448. target->SetX(x);
  9449. target->SetY(y);
  9450. target->SetZ(z);
  9451. target->SetHeading(h);
  9452. target->SetSpawnOrigX(x);
  9453. target->SetSpawnOrigY(y);
  9454. target->SetSpawnOrigZ(z);
  9455. target->SetSpawnOrigHeading(h);
  9456. if (target->IsPlayer()) {
  9457. Client* client = ((Player*)target)->GetClient();
  9458. if (client) {
  9459. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9460. int numargs = lua_interface->GetNumberOfArgs(state);
  9461. if(numargs == 4) {
  9462. x = lua_interface->GetFloatValue(state,1);
  9463. y = lua_interface->GetFloatValue(state,2);
  9464. z = lua_interface->GetFloatValue(state,3);
  9465. h = lua_interface->GetFloatValue(state,4);
  9466. }
  9467. client->SetReloadingZone(true);
  9468. target->SetX(x);
  9469. target->SetY(y);
  9470. target->SetZ(z);
  9471. target->SetHeading(h);
  9472. target->SetSpawnOrigX(x);
  9473. target->SetSpawnOrigY(y);
  9474. target->SetSpawnOrigZ(z);
  9475. target->SetSpawnOrigHeading(h);
  9476. target->SetAppearancePosition(x,y,z);
  9477. client->SetZoningCoords(x,y,z,h);
  9478. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9479. if (packet)
  9480. {
  9481. packet->setDataByName("x", x);
  9482. packet->setDataByName("y", y);
  9483. packet->setDataByName("z", z);
  9484. client->QueuePacket(packet->serialize());
  9485. safe_delete(packet);
  9486. }
  9487. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9488. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9489. }
  9490. }
  9491. lua_interface->ResetFunctionStack(state);
  9492. }
  9493. else {
  9494. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9495. if(!spell) {
  9496. lua_interface->ResetFunctionStack(state);
  9497. return 0;
  9498. }
  9499. ZoneServer* zone = spell->caster->GetZone();
  9500. float x = spell->caster->GetZone()->GetSafeX();
  9501. float y = spell->caster->GetZone()->GetSafeY();
  9502. float z = spell->caster->GetZone()->GetSafeZ();
  9503. float h = spell->caster->GetZone()->GetSafeHeading();
  9504. int numargs = lua_interface->GetNumberOfArgs(state);
  9505. if(numargs == 4) {
  9506. x = lua_interface->GetFloatValue(state,1);
  9507. y = lua_interface->GetFloatValue(state,2);
  9508. z = lua_interface->GetFloatValue(state,3);
  9509. h = lua_interface->GetFloatValue(state,4);
  9510. }
  9511. lua_interface->ResetFunctionStack(state);
  9512. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9513. for (int32 i = 0; i < spell->targets.size(); i++) {
  9514. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9515. if (!target2)
  9516. continue;
  9517. if (target2->IsPlayer()) {
  9518. Client* client = ((Player*)target2)->GetClient();
  9519. if (client) {
  9520. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9521. client->SetReloadingZone(true);
  9522. target2->SetX(x);
  9523. target2->SetY(y);
  9524. target2->SetZ(z);
  9525. target2->SetHeading(h);
  9526. target2->SetSpawnOrigX(x);
  9527. target2->SetSpawnOrigY(y);
  9528. target2->SetSpawnOrigZ(z);
  9529. target2->SetSpawnOrigHeading(h);
  9530. target2->SetAppearancePosition(x,y,z);
  9531. client->SetZoningCoords(x,y,z,h);
  9532. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9533. if (packet)
  9534. {
  9535. packet->setDataByName("x", x);
  9536. packet->setDataByName("y", y);
  9537. packet->setDataByName("z", z);
  9538. client->QueuePacket(packet->serialize());
  9539. safe_delete(packet);
  9540. }
  9541. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9542. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9543. }
  9544. }
  9545. }
  9546. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9547. }
  9548. return 0;
  9549. }
  9550. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9551. if (!lua_interface)
  9552. return 0;
  9553. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9554. lua_interface->ResetFunctionStack(state);
  9555. if (!luaspell) {
  9556. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9557. return 0;
  9558. }
  9559. int8 tier = luaspell->spell->GetSpellTier();
  9560. lua_interface->SetInt32Value(state, tier);
  9561. return 1;
  9562. }
  9563. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9564. if (!lua_interface)
  9565. return 0;
  9566. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9567. lua_interface->ResetFunctionStack(state);
  9568. if (!luaspell) {
  9569. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9570. return 0;
  9571. }
  9572. int32 spell_id = luaspell->spell->GetSpellID();
  9573. lua_interface->SetInt32Value(state, spell_id);
  9574. return 1;
  9575. }
  9576. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9577. if (!lua_interface)
  9578. return 0;
  9579. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9580. lua_interface->ResetFunctionStack(state);
  9581. if (!spawn) {
  9582. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9583. return 0;
  9584. }
  9585. if (!spawn->IsPlayer()) {
  9586. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9587. return 0;
  9588. }
  9589. ZoneServer* zone = spawn->GetZone();
  9590. if (!zone) {
  9591. return 0;
  9592. }
  9593. Client* client = ((Player*)spawn)->GetClient();
  9594. if (!client) {
  9595. return 0;
  9596. }
  9597. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9598. return 0;
  9599. }
  9600. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9601. if (!lua_interface)
  9602. return 0;
  9603. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9604. lua_interface->ResetFunctionStack(state);
  9605. if (!spawn) {
  9606. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9607. return 0;
  9608. }
  9609. if (!spawn->IsPlayer()) {
  9610. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9611. return 0;
  9612. }
  9613. ZoneServer* zone = spawn->GetZone();
  9614. if (!zone) {
  9615. return 0;
  9616. }
  9617. Client* client = ((Player*)spawn)->GetClient();
  9618. if (!client) {
  9619. return 0;
  9620. }
  9621. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9622. return 0;
  9623. }
  9624. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9625. if (!lua_interface)
  9626. return 0;
  9627. Spawn* caster = lua_interface->GetSpawn(state);
  9628. Spawn* target = lua_interface->GetSpawn(state, 2);
  9629. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9630. string spell_name = lua_interface->GetStringValue(state, 4);
  9631. lua_interface->ResetFunctionStack(state);
  9632. if (!caster) {
  9633. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9634. return 0;
  9635. }
  9636. if (!caster->IsEntity()) {
  9637. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9638. return 0;
  9639. }
  9640. if (!target) {
  9641. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9642. return 0;
  9643. }
  9644. if (!target->IsEntity()) {
  9645. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9646. return 0;
  9647. }
  9648. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9649. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9650. return 0;
  9651. }
  9652. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9653. if (!lua_interface)
  9654. return 0;
  9655. Spawn* player = lua_interface->GetSpawn(state);
  9656. int32 amount = lua_interface->GetInt32Value(state, 2);
  9657. lua_interface->ResetFunctionStack(state);
  9658. if (player && player->IsPlayer() && amount > 0) {
  9659. ((Player*)player)->AddXP(amount);
  9660. }
  9661. return 0;
  9662. }
  9663. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9664. if (!lua_interface)
  9665. return 0;
  9666. Spawn* player = lua_interface->GetSpawn(state);
  9667. int8 type = lua_interface->GetInt8Value(state, 2);
  9668. string text = lua_interface->GetStringValue(state, 3);
  9669. lua_interface->ResetFunctionStack(state);
  9670. Client* client = 0;
  9671. if (player && player->IsPlayer())
  9672. client = ((Player*)player)->GetClient();
  9673. if (!client || text.length() == 0) {
  9674. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9675. return 0;
  9676. }
  9677. client->SimpleMessage(type, text.c_str());
  9678. return 0;
  9679. }
  9680. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9681. if (!lua_interface)
  9682. return 0;
  9683. Spawn* player = lua_interface->GetSpawn(state);
  9684. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9685. lua_interface->ResetFunctionStack(state);
  9686. Client* client = 0;
  9687. if (player && player->IsPlayer())
  9688. client = ((Player*)player)->GetClient();
  9689. if (!client || !spawn) {
  9690. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9691. return 0;
  9692. }
  9693. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9694. if (!items) {
  9695. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9696. return 0;
  9697. }
  9698. client->Loot(spawn->GetLootCoins(), items, spawn);
  9699. return 0;
  9700. }
  9701. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9702. if (!lua_interface)
  9703. return 0;
  9704. Spawn* spawnref = lua_interface->GetSpawn(state);
  9705. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9706. lua_interface->ResetFunctionStack(state);
  9707. if (spawn_id > 0 && spawnref) {
  9708. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9709. if (spawns.size() == 0) {
  9710. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9711. return 0;
  9712. }
  9713. Spawn* spawn = 0;
  9714. int16 index = MakeRandomInt(0, spawns.size());
  9715. if (index >= spawns.size() || index < 0)
  9716. index = 0;
  9717. spawn = spawns[index];
  9718. lua_interface->SetSpawnValue(state, spawn);
  9719. return 1;
  9720. }
  9721. else {
  9722. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9723. }
  9724. return 0;
  9725. }
  9726. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9727. Spawn* player = lua_interface->GetSpawn(state);
  9728. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9729. string name = lua_interface->GetStringValue(state, 3);
  9730. float distance = lua_interface->GetFloatValue(state, 4);
  9731. string command = lua_interface->GetStringValue(state, 5);
  9732. string error_text = lua_interface->GetStringValue(state, 6);
  9733. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9734. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9735. lua_interface->ResetFunctionStack(state);
  9736. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9737. if (distance == 0)
  9738. distance = 10.0f;
  9739. if (command.length() == 0)
  9740. command = name;
  9741. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9742. if (spawns.size() == 0) {
  9743. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9744. return 0;
  9745. }
  9746. Spawn* spawn = 0;
  9747. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9748. spawn = *itr;
  9749. if (spawn) {
  9750. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9751. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9752. }
  9753. }
  9754. }
  9755. return 0;
  9756. }
  9757. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9758. if (!lua_interface)
  9759. return 0;
  9760. Client* client = 0;
  9761. Spawn* player = lua_interface->GetSpawn(state);
  9762. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9763. lua_interface->ResetFunctionStack(state);
  9764. if (player && player->IsPlayer() && player->GetZone())
  9765. client = ((Player*)player)->GetClient();
  9766. else{
  9767. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9768. return 0;
  9769. }
  9770. if (client) {
  9771. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9772. if (packet) {
  9773. packet->setDataByName("goal_num", goal_num);
  9774. client->QueuePacket(packet->serialize());
  9775. safe_delete(packet);
  9776. }
  9777. }
  9778. return 0;
  9779. }
  9780. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9781. if (!lua_interface)
  9782. return 0;
  9783. Client* client = 0;
  9784. Spawn* player = lua_interface->GetSpawn(state);
  9785. lua_interface->ResetFunctionStack(state);
  9786. if (player && player->IsPlayer() && player->GetZone())
  9787. client = ((Player*)player)->GetClient();
  9788. else {
  9789. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9790. return 0;
  9791. }
  9792. if (client) {
  9793. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9794. }
  9795. return 0;
  9796. }
  9797. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9798. if (!lua_interface)
  9799. return 0;
  9800. Client* client = 0;
  9801. Spawn* player = lua_interface->GetSpawn(state);
  9802. float duration = lua_interface->GetFloatValue(state, 2);
  9803. string text = lua_interface->GetStringValue(state, 3);
  9804. string voice = lua_interface->GetStringValue(state, 4);
  9805. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9806. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9807. string signal = lua_interface->GetStringValue(state, 7);
  9808. string goal1 = lua_interface->GetStringValue(state, 8);
  9809. string task1 = lua_interface->GetStringValue(state, 9);
  9810. string goal2 = lua_interface->GetStringValue(state, 10);
  9811. string task2 = lua_interface->GetStringValue(state, 11);
  9812. string goal3 = lua_interface->GetStringValue(state, 12);
  9813. string task3 = lua_interface->GetStringValue(state, 13);
  9814. string goal4 = lua_interface->GetStringValue(state, 14);
  9815. string task4 = lua_interface->GetStringValue(state, 15);
  9816. lua_interface->ResetFunctionStack(state);
  9817. if (!player) {
  9818. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9819. return 0;
  9820. }
  9821. if (!player->IsPlayer()) {
  9822. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9823. return 0;
  9824. }
  9825. else
  9826. client = ((Player*)player)->GetClient();
  9827. if (!client) {
  9828. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9829. return 0;
  9830. }
  9831. if (text.length() == 0) {
  9832. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9833. return 0;
  9834. }
  9835. if (duration >= 0 && duration < 2)
  9836. duration = 2;
  9837. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9838. if (packet) {
  9839. packet->setDataByName("open_seconds_max", duration);
  9840. packet->setDataByName("text", text.c_str());
  9841. packet->setDataByName("voice", voice.c_str());
  9842. int8 num_goals = 1;
  9843. if (task2.length() > 0)
  9844. num_goals++;
  9845. if (task3.length() > 0)
  9846. num_goals++;
  9847. if (task4.length() > 0)
  9848. num_goals++;
  9849. packet->setArrayLengthByName("num_goals", num_goals);
  9850. for (int8 i = 0; i < num_goals; i++) {
  9851. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9852. }
  9853. if (goal1.length() > 0)
  9854. packet->setArrayDataByName("goal_text", goal1.c_str());
  9855. if (goal2.length() > 0)
  9856. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9857. if (goal3.length() > 0)
  9858. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9859. if (goal4.length() > 0)
  9860. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9861. packet->setSubArrayDataByName("task_text", task1.c_str());
  9862. if (task2.length() > 0)
  9863. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9864. if (task3.length() > 0)
  9865. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9866. if (task4.length() > 0)
  9867. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9868. packet->setDataByName("complete_sound", "click");
  9869. packet->setDataByName("signal", signal.c_str());
  9870. packet->setDataByName("voice_key1", voice_key1);
  9871. packet->setDataByName("voice_key2", voice_key2);
  9872. client->QueuePacket(packet->serialize());
  9873. safe_delete(packet);
  9874. }
  9875. return 0;
  9876. }
  9877. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9878. if (!lua_interface)
  9879. return 0;
  9880. Client* client = 0;
  9881. Spawn* player = lua_interface->GetSpawn(state);
  9882. string window = lua_interface->GetStringValue(state, 2);
  9883. int8 show = lua_interface->GetInt8Value(state, 3);
  9884. lua_interface->ResetFunctionStack(state);
  9885. if (!player) {
  9886. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9887. return 0;
  9888. }
  9889. if (!player->IsPlayer()) {
  9890. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9891. return 0;
  9892. }
  9893. else
  9894. client = ((Player*)player)->GetClient();
  9895. if (!client) {
  9896. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9897. return 0;
  9898. }
  9899. if (window.length() == 0) {
  9900. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9901. return 0;
  9902. }
  9903. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9904. if (packet) {
  9905. packet->setDataByName("window", window.c_str());
  9906. packet->setDataByName("show", show);
  9907. client->QueuePacket(packet->serialize());
  9908. safe_delete(packet);
  9909. }
  9910. return 0;
  9911. }
  9912. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9913. //See GameEvents.txt for options that can be used for this function
  9914. if (!lua_interface)
  9915. return 0;
  9916. Client* client = 0;
  9917. Spawn* player = lua_interface->GetSpawn(state);
  9918. string event_name = lua_interface->GetStringValue(state, 2);
  9919. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9920. lua_interface->ResetFunctionStack(state);
  9921. if (!player || !player->IsPlayer()) {
  9922. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9923. return 0;
  9924. }
  9925. client = ((Player*)player)->GetClient();
  9926. if (!client) {
  9927. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9928. return 0;
  9929. }
  9930. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9931. if (packet) {
  9932. packet->setDataByName("event_name", event_name.c_str());
  9933. packet->setDataByName("enabled", enabled);
  9934. client->QueuePacket(packet->serialize());
  9935. safe_delete(packet);
  9936. }
  9937. return 0;
  9938. }
  9939. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9940. if (!lua_interface)
  9941. return 0;
  9942. Spawn* player = lua_interface->GetSpawn(state);
  9943. lua_interface->ResetFunctionStack(state);
  9944. if (player && player->IsPlayer()) {
  9945. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9946. return 1;
  9947. }
  9948. return 0;
  9949. }
  9950. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9951. if (!lua_interface)
  9952. return 0;
  9953. Spawn* player = lua_interface->GetSpawn(state);
  9954. int8 step = lua_interface->GetInt8Value(state, 2);
  9955. lua_interface->ResetFunctionStack(state);
  9956. if (player && player->IsPlayer() && step > 0) {
  9957. ((Player*)player)->SetTutorialStep(step);
  9958. }
  9959. return 0;
  9960. }
  9961. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9962. if (!lua_interface)
  9963. return 0;
  9964. Client* client = 0;
  9965. Spawn* player = lua_interface->GetSpawn(state);
  9966. string window = lua_interface->GetStringValue(state, 2);
  9967. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9968. lua_interface->ResetFunctionStack(state);
  9969. if (!player) {
  9970. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9971. return 0;
  9972. }
  9973. if (!player->IsPlayer()) {
  9974. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9975. return 0;
  9976. }
  9977. else
  9978. client = ((Player*)player)->GetClient();
  9979. if (!client) {
  9980. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9981. return 0;
  9982. }
  9983. if (window.length() == 0) {
  9984. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9985. return 0;
  9986. }
  9987. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9988. if (packet) {
  9989. packet->setDataByName("window", window.c_str());
  9990. packet->setDataByName("flash_seconds", flash_seconds);
  9991. client->QueuePacket(packet->serialize());
  9992. safe_delete(packet);
  9993. }
  9994. return 0;
  9995. }
  9996. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9997. if (!lua_interface)
  9998. return 0;
  9999. Spawn* spawn = lua_interface->GetSpawn(state);
  10000. Spawn* target = lua_interface->GetSpawn(state, 2);
  10001. lua_interface->ResetFunctionStack(state);
  10002. if (spawn && target)
  10003. return spawn->CheckLoS(target);
  10004. return 0;
  10005. }
  10006. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10007. if (!lua_interface)
  10008. return 0;
  10009. Spawn* spawn = lua_interface->GetSpawn(state);
  10010. float x = lua_interface->GetFloatValue(state, 2);
  10011. float y = lua_interface->GetFloatValue(state, 3);
  10012. float z = lua_interface->GetFloatValue(state, 4);
  10013. lua_interface->ResetFunctionStack(state);
  10014. if (spawn)
  10015. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10016. return 0;
  10017. }
  10018. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10019. if (!lua_interface)
  10020. return 0;
  10021. ZoneServer* zone = lua_interface->GetZone(state);
  10022. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10023. lua_interface->ResetFunctionStack(state);
  10024. if (zone)
  10025. zone->SetExpansionFlag(xpackFlag);
  10026. return 0;
  10027. }
  10028. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10029. if (!lua_interface)
  10030. return 0;
  10031. ZoneServer* zone = lua_interface->GetZone(state);
  10032. lua_interface->ResetFunctionStack(state);
  10033. if (zone) {
  10034. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10035. return 1;
  10036. }
  10037. return 0;
  10038. }
  10039. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10040. if (!lua_interface)
  10041. return 0;
  10042. ZoneServer* zone = lua_interface->GetZone(state);
  10043. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10044. lua_interface->ResetFunctionStack(state);
  10045. if (zone)
  10046. zone->SetHolidayFlag(holidayFlag);
  10047. return 0;
  10048. }
  10049. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10050. if (!lua_interface)
  10051. return 0;
  10052. ZoneServer* zone = lua_interface->GetZone(state);
  10053. lua_interface->ResetFunctionStack(state);
  10054. if (zone) {
  10055. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10056. return 1;
  10057. }
  10058. return 0;
  10059. }
  10060. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10061. if (!lua_interface)
  10062. return 0;
  10063. Spawn* player = lua_interface->GetSpawn(state);
  10064. ZoneServer* zone = player->GetZone();
  10065. bool canbind = lua_interface->GetInt32Value(state, 2);
  10066. lua_interface->ResetFunctionStack(state);
  10067. if (zone)
  10068. zone->SetCanBind(canbind);
  10069. return 0;
  10070. }
  10071. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10072. if (!lua_interface)
  10073. return 0;
  10074. Spawn* player = lua_interface->GetSpawn(state);
  10075. ZoneServer* zone = player->GetZone();
  10076. lua_interface->ResetFunctionStack(state);
  10077. if (zone) {
  10078. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10079. return 1;
  10080. }
  10081. return 0;
  10082. }
  10083. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10084. if (!lua_interface)
  10085. return 0;
  10086. Spawn* player = lua_interface->GetSpawn(state);
  10087. ZoneServer* zone = player->GetZone();
  10088. bool cangate = lua_interface->GetInt32Value(state, 2);
  10089. lua_interface->ResetFunctionStack(state);
  10090. if (zone)
  10091. zone->SetCanGate(cangate);
  10092. return 0;
  10093. }
  10094. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10095. if (!lua_interface)
  10096. return 0;
  10097. Spawn* player = lua_interface->GetSpawn(state);
  10098. ZoneServer* zone = player->GetZone();
  10099. lua_interface->ResetFunctionStack(state);
  10100. if (zone) {
  10101. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10102. return 1;
  10103. }
  10104. return 0;
  10105. }
  10106. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10107. if (!lua_interface)
  10108. return 0;
  10109. Spawn* spawn = lua_interface->GetSpawn(state);
  10110. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10111. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10112. float distance = lua_interface->GetFloatValue(state, 4);
  10113. string in_range_function = lua_interface->GetStringValue(state, 5);
  10114. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10115. lua_interface->ResetFunctionStack(state);
  10116. if (spawn && distance > 0 && in_range_function.length() > 0)
  10117. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10118. return 0;
  10119. }
  10120. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10121. if (!lua_interface)
  10122. return 0;
  10123. Spawn* spawn = lua_interface->GetSpawn(state);
  10124. Spawn* target = lua_interface->GetSpawn(state, 2);
  10125. lua_interface->ResetFunctionStack(state);
  10126. if (spawn && target)
  10127. {
  10128. if (spawn->IsPlayer() && target->IsEntity())
  10129. {
  10130. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10131. return 1;
  10132. }
  10133. else if (spawn->IsEntity() && target->IsEntity())
  10134. {
  10135. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10136. return 1;
  10137. }
  10138. }
  10139. return 0;
  10140. }
  10141. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10142. if (!lua_interface)
  10143. return 0;
  10144. Spawn* spawn = lua_interface->GetSpawn(state);
  10145. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10146. lua_interface->ResetFunctionStack(state);
  10147. if (spawn && spawn->IsEntity())
  10148. {
  10149. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10150. if (spawn->IsPlayer())
  10151. {
  10152. Client* client = ((Player*)spawn)->GetClient();
  10153. if (client)
  10154. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10155. }
  10156. }
  10157. return 0;
  10158. }
  10159. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10160. if (!lua_interface)
  10161. return 0;
  10162. Spawn* spawn = lua_interface->GetSpawn(state);
  10163. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10164. lua_interface->ResetFunctionStack(state);
  10165. if (spawn && spawn->IsEntity())
  10166. {
  10167. ((Entity*)spawn)->SetSeeHideSpell(val);
  10168. if (spawn->IsPlayer())
  10169. {
  10170. Client* client = ((Player*)spawn)->GetClient();
  10171. if (client)
  10172. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10173. }
  10174. }
  10175. return 0;
  10176. }
  10177. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10178. {
  10179. if (!lua_interface)
  10180. return 0;
  10181. Spawn* player = lua_interface->GetSpawn(state);
  10182. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10183. string command = lua_interface->GetStringValue(state, 3);
  10184. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10185. lua_interface->ResetFunctionStack(state);
  10186. if (spawn && player && player->IsPlayer())
  10187. {
  10188. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10189. bool res = false;
  10190. if (cmd)
  10191. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10192. lua_interface->SetBooleanValue(state, res);
  10193. return 1;
  10194. }
  10195. return 0;
  10196. }
  10197. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10198. {
  10199. if (!lua_interface)
  10200. return 0;
  10201. Spawn* spawn = lua_interface->GetSpawn(state);
  10202. int32 charID = lua_interface->GetInt32Value(state, 2);
  10203. string command = lua_interface->GetStringValue(state, 3);
  10204. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10205. lua_interface->ResetFunctionStack(state);
  10206. if (spawn && charID)
  10207. {
  10208. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10209. bool res = false;
  10210. if (cmd)
  10211. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10212. lua_interface->SetBooleanValue(state, res);
  10213. return 1;
  10214. }
  10215. return 0;
  10216. }
  10217. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10218. {
  10219. if (!lua_interface)
  10220. return 0;
  10221. Spawn* spawn = lua_interface->GetSpawn(state);
  10222. string command = lua_interface->GetStringValue(state, 2);
  10223. lua_interface->ResetFunctionStack(state);
  10224. if (spawn && command.length() > 0)
  10225. spawn->RemovePrimaryEntityCommand(command.c_str());
  10226. return 0;
  10227. }
  10228. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10229. if (!lua_interface)
  10230. return 0;
  10231. Spawn* spawn = lua_interface->GetSpawn(state);
  10232. float distance = lua_interface->GetFloatValue(state, 2);
  10233. string command = lua_interface->GetStringValue(state, 3);
  10234. Spawn* player = lua_interface->GetSpawn(state, 4);
  10235. lua_interface->ResetFunctionStack(state);
  10236. if (spawn) {
  10237. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10238. }
  10239. return 0;
  10240. }
  10241. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10242. if (!lua_interface)
  10243. return 0;
  10244. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10245. Spawn* spawn = lua_interface->GetSpawn(state);
  10246. Spawn* player = lua_interface->GetSpawn(state, 2);
  10247. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10248. lua_interface->ResetFunctionStack(state);
  10249. if (spawn && player && transport_id && player->IsPlayer()) {
  10250. Client* client = 0;
  10251. if (player && player->IsPlayer())
  10252. client = ((Player*)player)->GetClient();
  10253. if (!client)
  10254. return 0;
  10255. vector<TransportDestination*> destinations;
  10256. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10257. if (destinations.size())
  10258. {
  10259. client->SetTemporaryTransportID(transport_id);
  10260. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10261. }
  10262. else
  10263. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10264. }
  10265. return 0;
  10266. }
  10267. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10268. if (!lua_interface)
  10269. return 0;
  10270. Spawn* player = lua_interface->GetSpawn(state);
  10271. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10272. lua_interface->ResetFunctionStack(state);
  10273. if (player && player->IsPlayer()) {
  10274. Client* client = 0;
  10275. if (player && player->IsPlayer())
  10276. client = ((Player*)player)->GetClient();
  10277. if (!client)
  10278. return 0;
  10279. client->SetTemporaryTransportID(transport_id);
  10280. }
  10281. return 0;
  10282. }
  10283. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10284. if (!lua_interface)
  10285. return 0;
  10286. Spawn* player = lua_interface->GetSpawn(state);
  10287. lua_interface->ResetFunctionStack(state);
  10288. if (player && player->IsPlayer()) {
  10289. Client* client = 0;
  10290. if (player && player->IsPlayer())
  10291. client = ((Player*)player)->GetClient();
  10292. if (!client)
  10293. return 0;
  10294. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10295. return 1;
  10296. }
  10297. return 0;
  10298. }
  10299. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10300. if (!lua_interface)
  10301. return 0;
  10302. Spawn* spawn = lua_interface->GetSpawn(state);
  10303. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10304. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10305. if (!spawn) {
  10306. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10307. return 0;
  10308. }
  10309. if (!spawn->IsEntity()) {
  10310. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10311. return 0;
  10312. }
  10313. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10314. {
  10315. 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);
  10316. return 0;
  10317. }
  10318. lua_interface->ResetFunctionStack(state);
  10319. if (spell && spell->targets.size() > 0) {
  10320. ZoneServer* zone = spell->caster->GetZone();
  10321. for (int8 i = 0; i < spell->targets.size(); i++) {
  10322. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10323. if (target && target->IsEntity()) {
  10324. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10325. if (target->IsPlayer())
  10326. ((Player*)target)->SetCharSheetChanged(true);
  10327. }
  10328. }
  10329. }
  10330. else {
  10331. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10332. if (spawn->IsPlayer())
  10333. ((Player*)spawn)->SetCharSheetChanged(true);
  10334. }
  10335. return 0;
  10336. }
  10337. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10338. if (!lua_interface)
  10339. return 0;
  10340. Spawn* spawn = lua_interface->GetSpawn(state);
  10341. lua_interface->ResetFunctionStack(state);
  10342. if (!spawn) {
  10343. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10344. return 0;
  10345. }
  10346. if (!spawn->IsEntity()) {
  10347. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10348. return 0;
  10349. }
  10350. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10351. return 1;
  10352. }
  10353. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10354. if (!lua_interface)
  10355. return 0;
  10356. int32 spell_id = lua_interface->GetInt32Value(state);
  10357. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10358. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10359. if (spell_id > 0) {
  10360. if (spell_tier == 0)
  10361. spell_tier = 1;
  10362. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10363. LuaSpell* lua_spell = 0;
  10364. if(custom_lua_script.size() > 0)
  10365. {
  10366. // attempt to load the custom script since it isn't already loaded
  10367. // we will re-obtain the lua_spell further below
  10368. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10369. {
  10370. 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());
  10371. lua_interface->LoadLuaSpell(custom_lua_script);
  10372. }
  10373. }
  10374. else
  10375. custom_lua_script = spell->GetSpellData()->lua_script;
  10376. if (!lua_spell && lua_interface)
  10377. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10378. if (!lua_spell)
  10379. {
  10380. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10381. return 0;
  10382. }
  10383. lua_spell->spell = new Spell(spell);
  10384. lua_interface->AddCustomSpell(lua_spell);
  10385. lua_interface->SetSpellValue(state, lua_spell);
  10386. return 1;
  10387. }
  10388. return 0;
  10389. }
  10390. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10391. if (!lua_interface)
  10392. return 0;
  10393. LuaSpell* spell = lua_interface->GetSpell(state);
  10394. string field = lua_interface->GetStringValue(state, 2);
  10395. if (!spell) {
  10396. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10397. return 0;
  10398. }
  10399. if (!spell->spell || !spell->spell->GetSpellData()) {
  10400. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10401. return 0;
  10402. }
  10403. boost::to_lower(field);
  10404. return spell->spell->GetSpellData(state, field);
  10405. }
  10406. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10407. if (!lua_interface)
  10408. return 0;
  10409. LuaSpell* spell = lua_interface->GetSpell(state);
  10410. string field = lua_interface->GetStringValue(state, 2);
  10411. int8 fieldArg = 3; // field value after the initial set
  10412. if (!spell) {
  10413. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10414. return 0;
  10415. }
  10416. if (!spell->spell || !spell->spell->GetSpellData()) {
  10417. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10418. return 0;
  10419. }
  10420. boost::to_lower(field);
  10421. bool valSet = false;
  10422. spell->spell->SetSpellData(state, field, fieldArg);
  10423. return valSet;
  10424. }
  10425. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10426. if (!lua_interface)
  10427. return 0;
  10428. LuaSpell* spell = lua_interface->GetSpell(state);
  10429. int8 idx = lua_interface->GetInt32Value(state, 2);
  10430. if (!spell) {
  10431. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10432. return 0;
  10433. }
  10434. if (!spell->spell || !spell->spell->GetSpellData()) {
  10435. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10436. return 0;
  10437. }
  10438. if (spell->spell->lua_data.size() <= idx)
  10439. {
  10440. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10441. return 0;
  10442. }
  10443. bool setVal = true;
  10444. LUAData* data = spell->spell->lua_data[idx];
  10445. switch (data->type)
  10446. {
  10447. case 0:
  10448. {
  10449. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10450. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10451. data->int_value = value;
  10452. data->int_value2 = value2;
  10453. break;
  10454. }
  10455. case 1:
  10456. {
  10457. float value = lua_interface->GetFloatValue(state, 3);
  10458. float value2 = lua_interface->GetFloatValue(state, 4);
  10459. data->float_value = value;
  10460. data->float_value2 = value2;
  10461. break;
  10462. }
  10463. case 2:
  10464. {
  10465. bool value = lua_interface->GetBooleanValue(state, 3);
  10466. data->bool_value = value;
  10467. break;
  10468. }
  10469. case 3:
  10470. {
  10471. string value = lua_interface->GetStringValue(state, 3);
  10472. string value2 = lua_interface->GetStringValue(state, 4);
  10473. data->string_value = value;
  10474. data->string_value2 = value2;
  10475. break;
  10476. }
  10477. default:
  10478. setVal = false;
  10479. }
  10480. return setVal;
  10481. }
  10482. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10483. if (!lua_interface)
  10484. return 0;
  10485. LuaSpell* spell = lua_interface->GetSpell(state);
  10486. int8 idx = lua_interface->GetInt32Value(state, 2);
  10487. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10488. if (!spell) {
  10489. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10490. return 0;
  10491. }
  10492. if (!spell->spell || !spell->spell->GetSpellData()) {
  10493. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10494. return 0;
  10495. }
  10496. if (spell->spell->lua_data.size() <= idx)
  10497. {
  10498. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10499. return 0;
  10500. }
  10501. bool setVal = true;
  10502. LUAData* data = spell->spell->lua_data[idx];
  10503. switch (data->type)
  10504. {
  10505. case 0:
  10506. {
  10507. if(!secondfield)
  10508. lua_interface->SetSInt32Value(state, data->int_value);
  10509. else
  10510. lua_interface->SetSInt32Value(state, data->int_value2);
  10511. break;
  10512. }
  10513. case 1:
  10514. {
  10515. if (!secondfield)
  10516. lua_interface->SetFloatValue(state, data->float_value);
  10517. else
  10518. lua_interface->SetFloatValue(state, data->float_value2);
  10519. break;
  10520. }
  10521. case 2:
  10522. {
  10523. lua_interface->SetBooleanValue(state, data->bool_value);
  10524. break;
  10525. }
  10526. case 3:
  10527. {
  10528. if (!secondfield)
  10529. lua_interface->SetStringValue(state, data->string_value.c_str());
  10530. else
  10531. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10532. break;
  10533. }
  10534. default:
  10535. setVal = false;
  10536. }
  10537. return setVal;
  10538. }
  10539. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10540. if (!lua_interface)
  10541. return 0;
  10542. LuaSpell* spell = lua_interface->GetSpell(state);
  10543. int8 idx = lua_interface->GetInt32Value(state, 2);
  10544. string field = lua_interface->GetStringValue(state, 3);
  10545. boost::to_lower(field);
  10546. if (!spell) {
  10547. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10548. return 0;
  10549. }
  10550. if (!spell->spell || !spell->spell->GetSpellData()) {
  10551. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10552. return 0;
  10553. }
  10554. if (spell->spell->effects.size() <= idx)
  10555. {
  10556. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10557. return 0;
  10558. }
  10559. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10560. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10561. if (field == "description")
  10562. effect->description = string(lua_interface->GetStringValue(state, 4));
  10563. else if (field == "bullet")
  10564. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10565. else if (field == "percentage")
  10566. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10567. else // no match
  10568. return 0;
  10569. return 1;
  10570. }
  10571. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10572. if (!lua_interface)
  10573. return 0;
  10574. LuaSpell* spell = lua_interface->GetSpell(state);
  10575. int8 idx = lua_interface->GetInt32Value(state, 2);
  10576. string field = lua_interface->GetStringValue(state, 3);
  10577. boost::to_lower(field);
  10578. if (!spell) {
  10579. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10580. return 0;
  10581. }
  10582. if (!spell->spell || !spell->spell->GetSpellData()) {
  10583. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10584. return 0;
  10585. }
  10586. if (spell->spell->effects.size() <= idx)
  10587. {
  10588. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10589. return 0;
  10590. }
  10591. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10592. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10593. if (field == "description")
  10594. lua_interface->SetStringValue(state, effect->description.c_str());
  10595. else if (field == "bullet")
  10596. lua_interface->SetInt32Value(state, effect->subbullet);
  10597. else if (field == "percentage")
  10598. lua_interface->SetInt32Value(state, effect->percentage);
  10599. else // no match
  10600. return 0;
  10601. return 1;
  10602. }
  10603. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10604. if (!lua_interface)
  10605. return 0;
  10606. LuaSpell* spell = lua_interface->GetSpell(state);
  10607. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10608. Spawn* target = lua_interface->GetSpawn(state, 3);
  10609. if (!target) {
  10610. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10611. return 0;
  10612. }
  10613. if (!target->IsEntity()) {
  10614. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10615. return 0;
  10616. }
  10617. if (!spell) {
  10618. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10619. return 0;
  10620. }
  10621. if (caster && !caster->IsEntity()) {
  10622. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10623. return 0;
  10624. }
  10625. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10626. return 0;
  10627. }
  10628. int EQ2Emu_lua_InWater(lua_State* state) {
  10629. if (!lua_interface)
  10630. return 0;
  10631. Spawn* spawn = lua_interface->GetSpawn(state);
  10632. lua_interface->ResetFunctionStack(state);
  10633. if (spawn) {
  10634. lua_interface->SetBooleanValue(state, spawn->InWater());
  10635. return 1;
  10636. }
  10637. return 0;
  10638. }
  10639. int EQ2Emu_lua_InLava(lua_State* state) {
  10640. if (!lua_interface)
  10641. return 0;
  10642. Spawn* spawn = lua_interface->GetSpawn(state);
  10643. lua_interface->ResetFunctionStack(state);
  10644. if (spawn) {
  10645. lua_interface->SetBooleanValue(state, spawn->InLava());
  10646. return 1;
  10647. }
  10648. return 0;
  10649. }
  10650. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10651. if (!lua_interface)
  10652. return 0;
  10653. Spawn* attacker = lua_interface->GetSpawn(state);
  10654. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10655. int8 type = lua_interface->GetInt8Value(state, 3);
  10656. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10657. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10658. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10659. string spell_name = lua_interface->GetStringValue(state, 7);
  10660. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10661. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10662. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10663. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10664. lua_interface->ResetFunctionStack(state);
  10665. if (!attacker) {
  10666. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10667. return 0;
  10668. }
  10669. if (!attacker->IsEntity()) {
  10670. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10671. return 0;
  10672. }
  10673. if (!victim) {
  10674. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10675. return 0;
  10676. }
  10677. if (!victim->IsEntity()) {
  10678. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10679. return 0;
  10680. }
  10681. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10682. return 0;
  10683. }
  10684. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10685. if (!lua_interface)
  10686. return 0;
  10687. Spawn* spawn = lua_interface->GetSpawn(state);
  10688. lua_interface->ResetFunctionStack(state);
  10689. if (spawn) {
  10690. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10691. return 1;
  10692. }
  10693. return 0;
  10694. }
  10695. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10696. if (!lua_interface)
  10697. return 0;
  10698. Spawn* spawn = lua_interface->GetSpawn(state);
  10699. bool invul = lua_interface->GetBooleanValue(state, 2);
  10700. lua_interface->ResetFunctionStack(state);
  10701. if (spawn) {
  10702. spawn->SetInvulnerable(invul);
  10703. }
  10704. return 0;
  10705. }
  10706. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10707. if (!lua_interface)
  10708. return 0;
  10709. string category = lua_interface->GetStringValue(state);
  10710. string name = lua_interface->GetStringValue(state, 2);
  10711. lua_interface->ResetFunctionStack(state);
  10712. Rule *ret = 0;
  10713. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10714. lua_interface->SetBooleanValue(state, ret->GetBool());
  10715. return 1;
  10716. }
  10717. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10718. return 0;
  10719. }
  10720. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10721. if (!lua_interface)
  10722. return 0;
  10723. string category = lua_interface->GetStringValue(state);
  10724. string name = lua_interface->GetStringValue(state, 2);
  10725. lua_interface->ResetFunctionStack(state);
  10726. Rule *ret = 0;
  10727. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10728. lua_interface->SetInt32Value(state, ret->GetInt32());
  10729. return 1;
  10730. }
  10731. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10732. return 0;
  10733. }
  10734. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10735. if (!lua_interface)
  10736. return 0;
  10737. string category = lua_interface->GetStringValue(state);
  10738. string name = lua_interface->GetStringValue(state, 2);
  10739. lua_interface->ResetFunctionStack(state);
  10740. Rule *ret = 0;
  10741. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10742. lua_interface->SetFloatValue(state, ret->GetFloat());
  10743. return 1;
  10744. }
  10745. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10746. return 0;
  10747. }
  10748. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10749. if (!lua_interface)
  10750. return 0;
  10751. Spawn* spawn = lua_interface->GetSpawn(state);
  10752. string type = lua_interface->GetStringValue(state, 2);
  10753. lua_interface->ResetFunctionStack(state);
  10754. if (spawn) {
  10755. int res = 1;
  10756. boost::to_lower(type);
  10757. if(type == "assigned_aa")
  10758. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10759. else if ( type == "unassigned_aa")
  10760. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10761. else if ( type == "assigned_tradeskill_aa")
  10762. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10763. else if ( type == "unassigned_tradeskill_aa")
  10764. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10765. else if ( type == "assigned_prestige_aa")
  10766. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10767. else if ( type == "unassigned_prestige_aa")
  10768. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10769. else if ( type == "assigned_tradeskill_prestige_aa")
  10770. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10771. else if ( type == "unassigned_tradeskill_prestige_aa")
  10772. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10773. else
  10774. res = 0;
  10775. return res;
  10776. }
  10777. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10778. return 0;
  10779. }
  10780. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10781. if (!lua_interface)
  10782. return 0;
  10783. Spawn* spawn = lua_interface->GetSpawn(state);
  10784. string type = lua_interface->GetStringValue(state, 2);
  10785. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10786. lua_interface->ResetFunctionStack(state);
  10787. if (spawn) {
  10788. boost::to_lower(type);
  10789. if(type == "assigned_aa")
  10790. spawn->SetAssignedAA((sint16)value);
  10791. else if ( type == "unassigned_aa")
  10792. spawn->SetUnassignedAA((sint16)value);
  10793. else if ( type == "assigned_tradeskill_aa")
  10794. spawn->SetTradeskillAA((sint16)value);
  10795. else if ( type == "unassigned_tradeskill_aa")
  10796. spawn->SetUnassignedTradeskillAA((sint16)value);
  10797. else if ( type == "assigned_prestige_aa")
  10798. spawn->SetPrestigeAA((sint16)value);
  10799. else if ( type == "unassigned_prestige_aa")
  10800. spawn->SetUnassignedPrestigeAA((sint16)value);
  10801. else if ( type == "assigned_tradeskill_prestige_aa")
  10802. spawn->SetTradeskillPrestigeAA((sint16)value);
  10803. else if ( type == "unassigned_tradeskill_prestige_aa")
  10804. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10805. if(spawn->IsPlayer())
  10806. ((Player*)spawn)->SetCharSheetChanged(true);
  10807. }
  10808. return 0;
  10809. }
  10810. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10811. if (!lua_interface)
  10812. return 0;
  10813. string titleName = lua_interface->GetStringValue(state);
  10814. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10815. lua_interface->ResetFunctionStack(state);
  10816. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10817. lua_interface->SetSInt32Value(state, index);
  10818. return 1;
  10819. }
  10820. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10821. if (!lua_interface)
  10822. return 0;
  10823. Spawn* spawn = lua_interface->GetSpawn(state);
  10824. string titleName = lua_interface->GetStringValue(state, 2);
  10825. lua_interface->ResetFunctionStack(state);
  10826. if(!spawn->IsPlayer())
  10827. {
  10828. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10829. lua_interface->SetSInt32Value(state, -1);
  10830. return 1;
  10831. }
  10832. Player* player = (Player*)spawn;
  10833. // check if player already has the title, don't need to add twice
  10834. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10835. if ( playerHasTitle)
  10836. {
  10837. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10838. return 1;
  10839. }
  10840. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10841. if(!title)
  10842. {
  10843. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10844. lua_interface->SetSInt32Value(state, -1);
  10845. return 1;
  10846. }
  10847. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10848. if(returnIdx < 0)
  10849. {
  10850. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10851. }
  10852. lua_interface->SetSInt32Value(state, returnIdx);
  10853. player->GetClient()->SendTitleUpdate();
  10854. return 1;
  10855. }
  10856. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10857. if (!lua_interface)
  10858. return 0;
  10859. Spawn* spawn = lua_interface->GetSpawn(state);
  10860. string titleName = lua_interface->GetStringValue(state, 2);
  10861. lua_interface->ResetFunctionStack(state);
  10862. if(!spawn->IsPlayer())
  10863. {
  10864. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10865. return 0;
  10866. }
  10867. Player* player = (Player*)spawn;
  10868. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10869. if(!title)
  10870. {
  10871. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10872. return 0;
  10873. }
  10874. if(title->GetPrefix())
  10875. {
  10876. 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());
  10877. return 0;
  10878. }
  10879. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10880. player->GetClient()->SendTitleUpdate();
  10881. return 1;
  10882. }
  10883. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10884. if (!lua_interface)
  10885. return 0;
  10886. Spawn* spawn = lua_interface->GetSpawn(state);
  10887. string titleName = lua_interface->GetStringValue(state, 2);
  10888. lua_interface->ResetFunctionStack(state);
  10889. if(!spawn->IsPlayer())
  10890. {
  10891. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10892. return 0;
  10893. }
  10894. Player* player = (Player*)spawn;
  10895. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10896. if(!title)
  10897. {
  10898. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10899. return 0;
  10900. }
  10901. if(!title->GetPrefix())
  10902. {
  10903. 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());
  10904. return 0;
  10905. }
  10906. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10907. player->GetClient()->SendTitleUpdate();
  10908. return 1;
  10909. }
  10910. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10911. if (!lua_interface)
  10912. return 0;
  10913. Spawn* spawn = lua_interface->GetSpawn(state);
  10914. lua_interface->ResetFunctionStack(state);
  10915. if(!spawn->IsPlayer())
  10916. {
  10917. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10918. return 0;
  10919. }
  10920. Player* player = (Player*)spawn;
  10921. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10922. player->GetClient()->SendTitleUpdate();
  10923. return 1;
  10924. }
  10925. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10926. if (!lua_interface)
  10927. return 0;
  10928. Spawn* spawn = lua_interface->GetSpawn(state);
  10929. lua_interface->ResetFunctionStack(state);
  10930. if(!spawn->IsPlayer())
  10931. {
  10932. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10933. return 0;
  10934. }
  10935. Player* player = (Player*)spawn;
  10936. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10937. player->GetClient()->SendTitleUpdate();
  10938. return 1;
  10939. }
  10940. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10941. if (!lua_interface)
  10942. return 0;
  10943. Spawn* spawn = lua_interface->GetSpawn(state);
  10944. string field = lua_interface->GetStringValue(state, 2);
  10945. lua_interface->ResetFunctionStack(state);
  10946. if(!spawn || !spawn->IsEntity())
  10947. {
  10948. 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));
  10949. return 0;
  10950. }
  10951. Entity* ent = (Entity*)spawn;
  10952. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10953. return 1;
  10954. }
  10955. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10956. if (!lua_interface)
  10957. return 0;
  10958. Spawn* spawn = lua_interface->GetSpawn(state);
  10959. string field = lua_interface->GetStringValue(state, 2);
  10960. lua_interface->ResetFunctionStack(state);
  10961. if(!spawn || !spawn->IsEntity())
  10962. {
  10963. 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));
  10964. return 0;
  10965. }
  10966. Entity* ent = (Entity*)spawn;
  10967. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10968. return 1;
  10969. }
  10970. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10971. if (!lua_interface)
  10972. return 0;
  10973. Spawn* spawn = lua_interface->GetSpawn(state);
  10974. string field = lua_interface->GetStringValue(state, 2);
  10975. lua_interface->ResetFunctionStack(state);
  10976. if(!spawn || !spawn->IsEntity())
  10977. {
  10978. 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));
  10979. return 0;
  10980. }
  10981. Entity* ent = (Entity*)spawn;
  10982. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10983. return 1;
  10984. }
  10985. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10986. if (!lua_interface)
  10987. return 0;
  10988. Spawn* spawn = lua_interface->GetSpawn(state);
  10989. string field = lua_interface->GetStringValue(state, 2);
  10990. lua_interface->ResetFunctionStack(state);
  10991. if(!spawn || !spawn->IsEntity())
  10992. {
  10993. 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));
  10994. return 0;
  10995. }
  10996. Entity* ent = (Entity*)spawn;
  10997. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10998. return 1;
  10999. }
  11000. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11001. if (!lua_interface)
  11002. return 0;
  11003. Spawn* spawn = lua_interface->GetSpawn(state);
  11004. string field = lua_interface->GetStringValue(state, 2);
  11005. string value = lua_interface->GetStringValue(state, 3);
  11006. lua_interface->ResetFunctionStack(state);
  11007. if(!spawn || !spawn->IsEntity())
  11008. {
  11009. 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));
  11010. return 0;
  11011. }
  11012. Entity* ent = (Entity*)spawn;
  11013. bool set_ = ent->SetInfoStructString(field, value);
  11014. lua_interface->SetBooleanValue(state, set_);
  11015. return 1;
  11016. }
  11017. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11018. if (!lua_interface)
  11019. return 0;
  11020. Spawn* spawn = lua_interface->GetSpawn(state);
  11021. string field = lua_interface->GetStringValue(state, 2);
  11022. int64 value = lua_interface->GetInt64Value(state, 3);
  11023. lua_interface->ResetFunctionStack(state);
  11024. if(!spawn || !spawn->IsEntity())
  11025. {
  11026. 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));
  11027. return 0;
  11028. }
  11029. Entity* ent = (Entity*)spawn;
  11030. bool set_ = ent->SetInfoStructUInt(field, value);
  11031. lua_interface->SetBooleanValue(state, set_);
  11032. return 1;
  11033. }
  11034. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11035. if (!lua_interface)
  11036. return 0;
  11037. Spawn* spawn = lua_interface->GetSpawn(state);
  11038. string field = lua_interface->GetStringValue(state, 2);
  11039. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11040. lua_interface->ResetFunctionStack(state);
  11041. if(!spawn || !spawn->IsEntity())
  11042. {
  11043. 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));
  11044. return 0;
  11045. }
  11046. Entity* ent = (Entity*)spawn;
  11047. bool set_ = ent->SetInfoStructSInt(field, value);
  11048. lua_interface->SetBooleanValue(state, set_);
  11049. return 1;
  11050. }
  11051. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11052. if (!lua_interface)
  11053. return 0;
  11054. Spawn* spawn = lua_interface->GetSpawn(state);
  11055. string field = lua_interface->GetStringValue(state, 2);
  11056. float value = lua_interface->GetFloatValue(state, 3);
  11057. lua_interface->ResetFunctionStack(state);
  11058. if(!spawn || !spawn->IsEntity())
  11059. {
  11060. 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));
  11061. return 0;
  11062. }
  11063. Entity* ent = (Entity*)spawn;
  11064. bool set_ = ent->SetInfoStructFloat(field, value);
  11065. lua_interface->SetBooleanValue(state, set_);
  11066. return 1;
  11067. }
  11068. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11069. if (!lua_interface)
  11070. return 0;
  11071. Spawn* spawn = lua_interface->GetSpawn(state);
  11072. bool value = lua_interface->GetBooleanValue(state, 2);
  11073. lua_interface->ResetFunctionStack(state);
  11074. if(!spawn || !spawn->IsPlayer())
  11075. {
  11076. 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));
  11077. return 0;
  11078. }
  11079. ((Player*)spawn)->SetCharSheetChanged(value);
  11080. return 0;
  11081. }
  11082. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11083. if (!lua_interface)
  11084. return 0;
  11085. Spawn* spawn = lua_interface->GetSpawn(state);
  11086. std::string fromName = lua_interface->GetStringValue(state, 2);
  11087. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11088. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11089. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11090. int32 copper = lua_interface->GetInt32Value(state, 6);
  11091. int32 silver = lua_interface->GetInt32Value(state, 7);
  11092. int32 gold = lua_interface->GetInt32Value(state, 8);
  11093. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11094. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11095. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11096. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11097. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11098. lua_interface->ResetFunctionStack(state);
  11099. if(!spawn || !spawn->IsPlayer())
  11100. {
  11101. 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));
  11102. lua_interface->SetBooleanValue(state, false);
  11103. return 1;
  11104. }
  11105. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11106. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11107. lua_interface->SetBooleanValue(state, true);
  11108. return 1;
  11109. }
  11110. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11111. if (!lua_interface)
  11112. return 0;
  11113. int32 char_id = lua_interface->GetInt32Value(state);
  11114. std::string fromName = lua_interface->GetStringValue(state, 2);
  11115. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11116. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11117. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11118. int32 copper = lua_interface->GetInt32Value(state, 6);
  11119. int32 silver = lua_interface->GetInt32Value(state, 7);
  11120. int32 gold = lua_interface->GetInt32Value(state, 8);
  11121. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11122. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11123. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11124. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11125. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11126. lua_interface->ResetFunctionStack(state);
  11127. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11128. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11129. lua_interface->SetBooleanValue(state, true);
  11130. return 1;
  11131. }
  11132. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11133. Spawn* widget;
  11134. if (lua_interface) {
  11135. widget = lua_interface->GetSpawn(state);
  11136. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11137. lua_interface->ResetFunctionStack(state);
  11138. if (widget && widget->IsWidget())
  11139. {
  11140. ((Widget*)widget)->OpenDoor();
  11141. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11142. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11143. }
  11144. else
  11145. 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));
  11146. }
  11147. return 0;
  11148. }
  11149. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11150. Spawn* widget;
  11151. if (lua_interface) {
  11152. widget = lua_interface->GetSpawn(state);
  11153. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11154. lua_interface->ResetFunctionStack(state);
  11155. if (widget && widget->IsWidget())
  11156. {
  11157. ((Widget*)widget)->CloseDoor();
  11158. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11159. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11160. }
  11161. else
  11162. 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));
  11163. }
  11164. return 0;
  11165. }
  11166. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11167. if (!lua_interface)
  11168. return 0;
  11169. Spawn* widget = lua_interface->GetSpawn(state);
  11170. lua_interface->ResetFunctionStack(state);
  11171. if (widget && widget->IsWidget())
  11172. {
  11173. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11174. return 1;
  11175. }
  11176. return 0;
  11177. }
  11178. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11179. if (!lua_interface)
  11180. return 0;
  11181. sint32 min = lua_interface->GetSInt32Value(state);
  11182. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11183. lua_interface->ResetFunctionStack(state);
  11184. sint32 result = MakeRandomInt(min, max);
  11185. lua_interface->SetSInt32Value(state, result);
  11186. return 1;
  11187. }
  11188. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11189. if (!lua_interface)
  11190. return 0;
  11191. float min = lua_interface->GetFloatValue(state);
  11192. float max = lua_interface->GetFloatValue(state, 2);
  11193. lua_interface->ResetFunctionStack(state);
  11194. float result = MakeRandomFloat(min, max);
  11195. lua_interface->SetFloatValue(state, result);
  11196. return 1;
  11197. }
  11198. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11199. if (!lua_interface)
  11200. return 0;
  11201. Spawn* spawn = lua_interface->GetSpawn(state);
  11202. int32 value = lua_interface->GetInt32Value(state, 2);
  11203. lua_interface->ResetFunctionStack(state);
  11204. if(!spawn)
  11205. {
  11206. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11207. lua_interface->SetBooleanValue(state, false);
  11208. return 1;
  11209. }
  11210. spawn->AddIconValue(value);
  11211. lua_interface->SetBooleanValue(state, true);
  11212. return 1;
  11213. }
  11214. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11215. if (!lua_interface)
  11216. return 0;
  11217. Spawn* spawn = lua_interface->GetSpawn(state);
  11218. int32 value = lua_interface->GetInt32Value(state, 2);
  11219. lua_interface->ResetFunctionStack(state);
  11220. if(!spawn)
  11221. {
  11222. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11223. lua_interface->SetBooleanValue(state, false);
  11224. return 1;
  11225. }
  11226. spawn->RemoveIconValue(value);
  11227. lua_interface->SetBooleanValue(state, true);
  11228. return 1;
  11229. }
  11230. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11231. Spawn* npc = lua_interface->GetSpawn(state);
  11232. lua_interface->ResetFunctionStack(state);
  11233. if (npc && npc->IsNPC()) {
  11234. NPC* shard = (NPC*)npc;
  11235. int32 shardid = shard->GetShardID();
  11236. lua_interface->SetInt32Value(state, shardid);
  11237. return 1;
  11238. }
  11239. lua_interface->SetInt32Value(state, 0);
  11240. return 1;
  11241. }
  11242. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11243. Spawn* npc = lua_interface->GetSpawn(state);
  11244. lua_interface->ResetFunctionStack(state);
  11245. if (npc && npc->IsNPC()) {
  11246. NPC* shard = (NPC*)npc;
  11247. int32 charid = shard->GetShardCharID();
  11248. lua_interface->SetInt32Value(state, charid);
  11249. return 1;
  11250. }
  11251. lua_interface->SetInt32Value(state, 0);
  11252. return 1;
  11253. }
  11254. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11255. Spawn* npc = lua_interface->GetSpawn(state);
  11256. lua_interface->ResetFunctionStack(state);
  11257. if (npc && npc->IsNPC()) {
  11258. NPC* shard = (NPC*)npc;
  11259. int64 timestamp = shard->GetShardCreatedTimestamp();
  11260. lua_interface->SetSInt64Value(state, timestamp);
  11261. return 1;
  11262. }
  11263. lua_interface->SetSInt64Value(state, 0);
  11264. return 1;
  11265. }
  11266. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11267. if (!lua_interface)
  11268. return 0;
  11269. int32 shardid = lua_interface->GetInt32Value(state);
  11270. lua_interface->ResetFunctionStack(state);
  11271. if(shardid < 1)
  11272. lua_interface->SetBooleanValue(state, false);
  11273. else
  11274. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11275. return 1;
  11276. }
  11277. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11278. if (!lua_interface)
  11279. return 0;
  11280. Spawn* spawn = lua_interface->GetSpawn(state);
  11281. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11282. if (spawn) {
  11283. spawn->PauseMovement(delay_in_ms);
  11284. }
  11285. lua_interface->ResetFunctionStack(state);
  11286. return 0;
  11287. }
  11288. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11289. if (!lua_interface)
  11290. return 0;
  11291. Spawn* spawn = lua_interface->GetSpawn(state);
  11292. if (spawn) {
  11293. spawn->StopMovement();
  11294. }
  11295. lua_interface->ResetFunctionStack(state);
  11296. return 0;
  11297. }
  11298. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11299. Player* player = (Player*)lua_interface->GetSpawn(state);
  11300. int8 level = lua_interface->GetInt8Value(state, 2);
  11301. lua_interface->ResetFunctionStack(state);
  11302. if (player && player->IsPlayer() && level > 0) {
  11303. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11304. return 1;
  11305. }
  11306. return 0;
  11307. }
  11308. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11309. Player* player = (Player*)lua_interface->GetSpawn(state);
  11310. int8 level = lua_interface->GetInt8Value(state, 2);
  11311. lua_interface->ResetFunctionStack(state);
  11312. if (player && player->IsPlayer() && level > 0) {
  11313. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11314. return 1;
  11315. }
  11316. return 0;
  11317. }
  11318. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11319. ZoneServer* zone = lua_interface->GetZone(state);
  11320. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11321. lua_interface->ResetFunctionStack(state);
  11322. if (zone) {
  11323. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11324. if (spawn) {
  11325. lua_interface->SetSpawnValue(state, spawn);
  11326. return 1;
  11327. }
  11328. }
  11329. return 0;
  11330. }
  11331. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11332. if (!lua_interface)
  11333. return 0;
  11334. Spawn* spawn = lua_interface->GetSpawn(state);
  11335. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11336. lua_interface->ResetFunctionStack(state);
  11337. bool res = false;
  11338. if(spawn && spawn->IsTransportSpawn())
  11339. {
  11340. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11341. spawn->SetRailID(rail_id);
  11342. res = true;
  11343. }
  11344. else if (!spawn) {
  11345. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11346. }
  11347. else if(!spawn->IsTransportSpawn()) {
  11348. 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());
  11349. }
  11350. lua_interface->SetBooleanValue(state, res);
  11351. return 1;
  11352. }
  11353. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11354. if (!lua_interface)
  11355. return 0;
  11356. ZoneServer* zone = lua_interface->GetZone(state);
  11357. lua_interface->ResetFunctionStack(state);
  11358. if (zone) {
  11359. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11360. return 1;
  11361. }
  11362. return 0;
  11363. }
  11364. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11365. if (!lua_interface)
  11366. return 0;
  11367. Spawn* spawn = lua_interface->GetSpawn(state);
  11368. lua_interface->ResetFunctionStack(state);
  11369. if (spawn) {
  11370. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11371. return 1;
  11372. }
  11373. return 0;
  11374. }
  11375. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11376. if (!lua_interface)
  11377. return 0;
  11378. Spawn* player = lua_interface->GetSpawn(state);
  11379. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11380. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11381. lua_interface->ResetFunctionStack(state);
  11382. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11383. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11384. }
  11385. else if(!zoneID) {
  11386. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11387. }
  11388. else
  11389. {
  11390. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11391. return 1;
  11392. }
  11393. return 0;
  11394. }
  11395. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11396. if (!lua_interface)
  11397. return 0;
  11398. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11399. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11400. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11401. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11402. lua_interface->ResetFunctionStack(state);
  11403. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11404. world.GetWorldTimeStruct()->year = newYear;
  11405. world.GetWorldTimeStruct()->month = newMonth;
  11406. world.GetWorldTimeStruct()->hour = newHour;
  11407. world.GetWorldTimeStruct()->minute = newMinute;
  11408. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11409. return 0;
  11410. }
  11411. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11412. if (!lua_interface)
  11413. return 0;
  11414. lua_interface->ResetFunctionStack(state);
  11415. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11416. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11417. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11418. return 1;
  11419. }
  11420. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11421. if (!lua_interface)
  11422. return 0;
  11423. lua_interface->ResetFunctionStack(state);
  11424. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11425. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11426. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11427. return 1;
  11428. }
  11429. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11430. if (!lua_interface)
  11431. return 0;
  11432. lua_interface->ResetFunctionStack(state);
  11433. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11434. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11435. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11436. return 1;
  11437. }
  11438. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11439. if (!lua_interface)
  11440. return 0;
  11441. lua_interface->ResetFunctionStack(state);
  11442. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11443. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11444. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11445. return 1;
  11446. }
  11447. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11448. if (!lua_interface)
  11449. return 0;
  11450. lua_interface->ResetFunctionStack(state);
  11451. world.SendTimeUpdate();
  11452. return 0;
  11453. }
  11454. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11455. bool update_result = false;
  11456. Faction* faction = 0;
  11457. Spawn* spawn = lua_interface->GetSpawn(state);
  11458. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11459. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11460. lua_interface->ResetFunctionStack(state);
  11461. if(!spawn || !spawn->IsPlayer()) {
  11462. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11463. return 0;
  11464. }
  11465. Player* player = (Player*)spawn;
  11466. Client* client = player->GetClient();
  11467. if (faction_id > 0) {
  11468. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11469. if(hasfaction == 0) {
  11470. //they do not have the faction. Lets get the default value and feed it in.
  11471. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11472. //add the default faction for the player.
  11473. player->SetFactionValue(faction_id, defaultfaction);
  11474. }
  11475. if(increase >= 0) {
  11476. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11477. faction = master_faction_list.GetFaction(faction_id);
  11478. if(faction && update_result)
  11479. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11480. else if(faction)
  11481. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11482. lua_interface->SetBooleanValue(state, true);
  11483. return 1;
  11484. }
  11485. if(increase < 0){
  11486. //change the negative to a positive, since thats how decreasefaction() likes it.
  11487. increase *= -1;
  11488. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11489. faction = master_faction_list.GetFaction(faction_id);
  11490. if(faction && update_result)
  11491. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11492. else if(faction)
  11493. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11494. lua_interface->SetBooleanValue(state, true);
  11495. return 1;
  11496. }
  11497. }
  11498. lua_interface->SetBooleanValue(state, false);
  11499. return 1;
  11500. }
  11501. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11502. bool hascoin = 0;
  11503. Player* player = (Player*)lua_interface->GetSpawn(state);
  11504. int32 coins = lua_interface->GetInt32Value(state, 2);
  11505. lua_interface->ResetFunctionStack(state);
  11506. if (player && player->IsPlayer()) {
  11507. hascoin = player->HasCoins(coins);
  11508. if(hascoin == 0) {
  11509. lua_interface->SetBooleanValue(state, false);
  11510. return 1;
  11511. }
  11512. if(hascoin == 1) {
  11513. lua_interface->SetBooleanValue(state, true);
  11514. return 1;
  11515. }
  11516. }
  11517. return 0;
  11518. }
  11519. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11520. int32 loot_tier = 0;
  11521. Spawn* spawn = lua_interface->GetSpawn(state);
  11522. lua_interface->ResetFunctionStack(state);
  11523. if (spawn) {
  11524. loot_tier = spawn->GetLootTier();
  11525. lua_interface->SetInt32Value(state, loot_tier);
  11526. return 1;
  11527. }
  11528. return 0;
  11529. }
  11530. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11531. if (!lua_interface)
  11532. return 0;
  11533. Spawn* spawn = lua_interface->GetSpawn(state);
  11534. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11535. lua_interface->ResetFunctionStack(state);
  11536. if (spawn) {
  11537. spawn->SetLootTier(loot_tier);
  11538. lua_interface->SetBooleanValue(state, true);
  11539. return 1;
  11540. }
  11541. lua_interface->SetBooleanValue(state, false);
  11542. return 1;
  11543. }
  11544. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11545. int32 loot_drop_type = 0;
  11546. Spawn* spawn = lua_interface->GetSpawn(state);
  11547. lua_interface->ResetFunctionStack(state);
  11548. if (spawn) {
  11549. loot_drop_type = spawn->GetLootDropType();
  11550. lua_interface->SetInt32Value(state, loot_drop_type);
  11551. return 1;
  11552. }
  11553. return 0;
  11554. }
  11555. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11556. if (!lua_interface)
  11557. return 0;
  11558. Spawn* spawn = lua_interface->GetSpawn(state);
  11559. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11560. lua_interface->ResetFunctionStack(state);
  11561. if (spawn) {
  11562. spawn->SetLootDropType(loot_drop_type);
  11563. lua_interface->SetBooleanValue(state, true);
  11564. return 1;
  11565. }
  11566. lua_interface->SetBooleanValue(state, false);
  11567. return 1;
  11568. }
  11569. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11570. if (!lua_interface)
  11571. return 0;
  11572. Spawn* spawn = lua_interface->GetSpawn(state);
  11573. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11574. if(damage_amount > 100) {
  11575. damage_amount = 100;
  11576. }
  11577. if (!spawn) {
  11578. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11579. return 0;
  11580. }
  11581. if (spawn->IsPlayer()) {
  11582. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11583. lua_interface->SetBooleanValue(state, true);
  11584. else
  11585. lua_interface->SetBooleanValue(state, false);
  11586. }
  11587. else {
  11588. lua_interface->SetBooleanValue(state, false);
  11589. }
  11590. return 1;
  11591. }
  11592. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11593. ZoneServer* zone = lua_interface->GetZone(state);
  11594. int32 version = lua_interface->GetInt32Value(state, 2);
  11595. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11596. if(region_map == nullptr) {
  11597. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11598. return 0;
  11599. }
  11600. string region_name = lua_interface->GetStringValue(state, 3);
  11601. string env_name = lua_interface->GetStringValue(state, 4);
  11602. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11603. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11604. float dist = lua_interface->GetFloatValue(state, 7);
  11605. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11606. lua_interface->ResetFunctionStack(state);
  11607. lua_interface->SetBooleanValue(state, true);
  11608. return 1;
  11609. }
  11610. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11611. ZoneServer* zone = lua_interface->GetZone(state);
  11612. int32 version = lua_interface->GetInt32Value(state, 2);
  11613. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11614. if(region_map == nullptr) {
  11615. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11616. return 0;
  11617. }
  11618. string region_name = lua_interface->GetStringValue(state, 3);
  11619. region_map->RemoveRegionNode(region_name);
  11620. lua_interface->ResetFunctionStack(state);
  11621. lua_interface->SetBooleanValue(state, true);
  11622. return 1;
  11623. }
  11624. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11625. Client* client = nullptr;
  11626. Spawn* player = lua_interface->GetSpawn(state);
  11627. if (!player) {
  11628. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11629. lua_interface->SetBooleanValue(state, false);
  11630. return 1;
  11631. }
  11632. if (!player->IsPlayer()) {
  11633. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11634. lua_interface->SetBooleanValue(state, false);
  11635. return 1;
  11636. }
  11637. client = player->GetClient();
  11638. if (!client) {
  11639. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11640. lua_interface->SetBooleanValue(state, false);
  11641. return 1;
  11642. }
  11643. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11644. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11645. lua_interface->ResetFunctionStack(state);
  11646. lua_interface->SetBooleanValue(state, success_sight);
  11647. return 1;
  11648. }
  11649. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11650. if (!lua_interface)
  11651. return 0;
  11652. bool result = false;
  11653. Spawn* spawn = lua_interface->GetSpawn(state);
  11654. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11655. lua_interface->ResetFunctionStack(state);
  11656. if (!spawn)
  11657. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11658. else if (!spawn->IsNPC())
  11659. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11660. else
  11661. {
  11662. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11663. result = true;
  11664. }
  11665. lua_interface->SetBooleanValue(state, result);
  11666. return 1;
  11667. }
  11668. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11669. if (!lua_interface)
  11670. return 0;
  11671. bool result = false;
  11672. Spawn* spawn = lua_interface->GetSpawn(state);
  11673. lua_interface->ResetFunctionStack(state);
  11674. if (!spawn)
  11675. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11676. else if (!spawn->IsNPC())
  11677. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11678. else
  11679. {
  11680. if(((NPC*)spawn)->cast_on_aggro_completed)
  11681. result = true;
  11682. }
  11683. lua_interface->SetBooleanValue(state, result);
  11684. return 1;
  11685. }