LuaFunctions.cpp 285 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266
  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 "../common/Log.h"
  29. #include <math.h>
  30. #include "HeroicOp/HeroicOp.h"
  31. #include "RaceTypes/RaceTypes.h"
  32. #include "ClientPacketFunctions.h"
  33. #include "Transmute.h"
  34. extern WorldDatabase database;
  35. extern LuaInterface* lua_interface;
  36. extern ConfigReader configReader;
  37. extern MasterQuestList master_quest_list;
  38. extern MasterItemList master_item_list;
  39. extern MasterSpellList master_spell_list;
  40. extern World world;
  41. extern Commands commands;
  42. extern ZoneList zone_list;
  43. extern Races races;
  44. extern Classes classes;
  45. extern Variables variables;
  46. extern MasterSkillList master_skill_list;
  47. extern MasterHeroicOPList master_ho_list;
  48. extern MasterRaceTypeList race_types_list;
  49. extern MasterLanguagesList master_languages_list;
  50. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  51. if (!lua_interface)
  52. return 0;
  53. Spawn* spawn = lua_interface->GetSpawn(state);
  54. string mp3_string = lua_interface->GetStringValue(state, 2);
  55. string text_string = lua_interface->GetStringValue(state, 3);
  56. string emote_string = lua_interface->GetStringValue(state, 4);
  57. int32 key1 = lua_interface->GetInt32Value(state, 5);
  58. int32 key2 = lua_interface->GetInt32Value(state, 6);
  59. Spawn* player = lua_interface->GetSpawn(state, 7);
  60. int8 language = lua_interface->GetInt8Value(state, 8);
  61. if (spawn) {
  62. const char* mp3 = 0;
  63. const char* text = 0;
  64. const char* emote = 0;
  65. if (mp3_string.length() > 0)
  66. mp3 = mp3_string.c_str();
  67. if (text_string.length() > 0)
  68. text = text_string.c_str();
  69. if (emote_string.length() > 0)
  70. emote = emote_string.c_str();
  71. Client* client = 0;
  72. if (player && player->IsPlayer())
  73. client = spawn->GetZone()->GetClientBySpawn(player);
  74. if (client) {
  75. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  76. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  77. }
  78. else
  79. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  80. }
  81. return 0;
  82. }
  83. int EQ2Emu_lua_PlaySound(lua_State* state) {
  84. if (!lua_interface)
  85. return 0;
  86. Spawn* spawn = lua_interface->GetSpawn(state);
  87. string sound_string = lua_interface->GetStringValue(state, 2);
  88. float x = lua_interface->GetFloatValue(state, 3);
  89. float y = lua_interface->GetFloatValue(state, 4);
  90. float z = lua_interface->GetFloatValue(state, 5);
  91. Spawn* player = lua_interface->GetSpawn(state, 6);
  92. if (spawn && sound_string.length() > 0) {
  93. Client* client = 0;
  94. if (player && player->IsPlayer())
  95. client = spawn->GetZone()->GetClientBySpawn(player);
  96. if (client)
  97. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  98. else
  99. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  100. }
  101. return 0;
  102. }
  103. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  104. if (!lua_interface)
  105. return 0;
  106. Spawn* spawn = lua_interface->GetSpawn(state);
  107. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  108. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  109. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  110. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  111. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  112. if (!spawn) {
  113. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  114. return 0;
  115. }
  116. if (quest_id > 0) {
  117. //Add this quest to the list of required quests for this spawn
  118. spawn->SetQuestsRequired(quest_id, quest_step);
  119. //If private spawn value set
  120. if (private_spawn) {
  121. //Set the spawn to be private when not granted access through this quest
  122. spawn->AddAllowAccessSpawn(spawn);
  123. spawn->SetPrivateQuestSpawn(true);
  124. }
  125. //This value allows access after a quest step, or the whole quest has been completed
  126. if (continued_access)
  127. spawn->SetQuestsRequiredContinuedAccess(true);
  128. //This value will override vis_flags in the vis packet
  129. if (flag_override > 0)
  130. spawn->SetQuestsRequiredOverride(flag_override);
  131. }
  132. return 0;
  133. }
  134. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  135. if (!lua_interface)
  136. return 0;
  137. Spawn* spawn = lua_interface->GetSpawn(state);
  138. float max_distance = lua_interface->GetFloatValue(state, 2);
  139. string variable = lua_interface->GetStringValue(state, 3);
  140. string value = lua_interface->GetStringValue(state, 4);
  141. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  142. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  143. return 0;
  144. }
  145. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  146. if (!lua_interface)
  147. return 0;
  148. Client* client = 0;
  149. Spawn* player = lua_interface->GetSpawn(state);
  150. if (!player) {
  151. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  152. return 0;
  153. }
  154. if (!player->IsPlayer()) {
  155. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  156. return 0;
  157. }
  158. if (player->GetZone())
  159. client = player->GetZone()->GetClientBySpawn(player);
  160. if (!client) {
  161. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  162. return 0;
  163. }
  164. int16 value1 = lua_interface->GetInt16Value(state, 2);
  165. int16 value2 = lua_interface->GetInt16Value(state, 3);
  166. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  167. if (packet) {
  168. packet->setDataByName("unknown1", value1);
  169. packet->setDataByName("unknown2", value2);
  170. client->QueuePacket(packet->serialize());
  171. safe_delete(packet);
  172. }
  173. return 0;
  174. }
  175. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  176. if (!lua_interface)
  177. return 0;
  178. Spawn* dead = lua_interface->GetSpawn(state);
  179. Spawn* killer = lua_interface->GetSpawn(state, 2);
  180. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  181. if (dead && dead->Alive() && dead->GetZone())
  182. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  183. return 0;
  184. }
  185. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  186. if (!lua_interface)
  187. return 0;
  188. Spawn* spawn = lua_interface->GetSpawn(state);
  189. float max_distance = lua_interface->GetFloatValue(state, 2);
  190. bool include_players = lua_interface->GetInt8Value(state, 3);
  191. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  192. if (max_distance > 0 && spawn && spawn->GetZone())
  193. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  194. return 0;
  195. }
  196. int EQ2Emu_lua_Despawn(lua_State* state) {
  197. if (!lua_interface)
  198. return 0;
  199. Spawn* spawn = lua_interface->GetSpawn(state);
  200. int32 delay = lua_interface->GetInt32Value(state, 2);
  201. if (spawn && spawn->GetZone())
  202. spawn->GetZone()->Despawn(spawn, delay);
  203. return 0;
  204. }
  205. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  206. if (!lua_interface)
  207. return 0;
  208. Spawn* spawn = lua_interface->GetSpawn(state);
  209. string variable = lua_interface->GetStringValue(state, 2);
  210. string value = lua_interface->GetStringValue(state, 3);
  211. int32 type = commands.GetSpawnSetType(variable);
  212. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  213. commands.SetSpawnCommand(0, spawn, type, value.c_str());
  214. return 0;
  215. }
  216. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  217. if (!lua_interface)
  218. return 0;
  219. Spawn* spawn = lua_interface->GetSpawn(state);
  220. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  221. if (spawn && spawn_id > 0) {
  222. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  223. if (closest_spawn) {
  224. lua_interface->SetSpawnValue(state, closest_spawn);
  225. return 1;
  226. }
  227. }
  228. return 0;
  229. }
  230. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  231. if (!lua_interface)
  232. return 0;
  233. string variable_name = lua_interface->GetStringValue(state);
  234. Variable* var = variables.FindVariable(variable_name);
  235. if (var) {
  236. lua_interface->SetStringValue(state, var->GetValue());
  237. return 1;
  238. }
  239. return 0;
  240. }
  241. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  242. if (!lua_interface)
  243. return 0;
  244. int32 total_coins = lua_interface->GetInt32Value(state);
  245. if (total_coins == 0) {
  246. lua_interface->SetStringValue(state, "0 copper");
  247. return 1;
  248. }
  249. char tmp[64] = { 0 };
  250. string message = "";
  251. int32 val = 0;
  252. if (total_coins >= 1000000) {
  253. val = total_coins / 1000000;
  254. total_coins -= 1000000 * val;
  255. sprintf(tmp, " %u Platinum", val);
  256. message.append(tmp);
  257. memset(tmp, 0, 64);
  258. }
  259. if (total_coins >= 10000) {
  260. val = total_coins / 10000;
  261. total_coins -= 10000 * val;
  262. sprintf(tmp, " %u Gold", val);
  263. message.append(tmp);
  264. memset(tmp, 0, 64);
  265. }
  266. if (total_coins >= 100) {
  267. val = total_coins / 100;
  268. total_coins -= 100 * val;
  269. sprintf(tmp, " %u Silver", val);
  270. message.append(tmp);
  271. memset(tmp, 0, 64);
  272. }
  273. if (total_coins > 0) {
  274. sprintf(tmp, " %u Copper", (int32)total_coins);
  275. message.append(tmp);
  276. }
  277. lua_interface->SetStringValue(state, message.c_str());
  278. return 1;
  279. }
  280. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  281. ZoneServer* zone = lua_interface->GetZone(state);
  282. int32 group_id = lua_interface->GetInt32Value(state, 2);
  283. if (zone) {
  284. Spawn* spawn = zone->GetSpawnGroup(group_id);
  285. if (spawn) {
  286. lua_interface->SetSpawnValue(state, spawn);
  287. return 1;
  288. }
  289. }
  290. return 0;
  291. }
  292. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  293. ZoneServer* zone = lua_interface->GetZone(state);
  294. int32 location_id = lua_interface->GetInt32Value(state, 2);
  295. if (zone) {
  296. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  297. if (spawn) {
  298. lua_interface->SetSpawnValue(state, spawn);
  299. return 1;
  300. }
  301. }
  302. return 0;
  303. }
  304. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  305. Spawn* spawn = lua_interface->GetSpawn(state);
  306. if (spawn) {
  307. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  308. return 1;
  309. }
  310. return 0;
  311. }
  312. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  313. Spawn* spawn = lua_interface->GetSpawn(state);
  314. if (spawn) {
  315. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  316. return 1;
  317. }
  318. return 0;
  319. }
  320. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. if (spawn) {
  323. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  324. return 1;
  325. }
  326. return 0;
  327. }
  328. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  329. Spawn* spawn = lua_interface->GetSpawn(state);
  330. if (spawn) {
  331. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  332. return 1;
  333. }
  334. return 0;
  335. }
  336. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  337. Player* player = (Player*)lua_interface->GetSpawn(state);
  338. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  339. if (player && player->IsPlayer() && faction_id > 0) {
  340. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  341. return 1;
  342. }
  343. return 0;
  344. }
  345. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  346. if (!lua_interface)
  347. return 0;
  348. Spawn* spawn = lua_interface->GetSpawn(state);
  349. int32 value = lua_interface->GetInt32Value(state, 2);
  350. if (spawn) {
  351. spawn->SetFactionID(value);
  352. }
  353. return 0;
  354. }
  355. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  356. Spawn* spawn = lua_interface->GetSpawn(state);
  357. if (spawn) {
  358. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  359. return 1;
  360. }
  361. return 0;
  362. }
  363. int EQ2Emu_lua_GetGender(lua_State* state) {
  364. Spawn* spawn = lua_interface->GetSpawn(state);
  365. if (spawn) {
  366. lua_interface->SetInt32Value(state, spawn->GetGender());
  367. return 1;
  368. }
  369. return 0;
  370. }
  371. int EQ2Emu_lua_GetTarget(lua_State* state) {
  372. Spawn* spawn = lua_interface->GetSpawn(state);
  373. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  374. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  375. return 1;
  376. }
  377. return 0;
  378. }
  379. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  380. if (!lua_interface)
  381. return 0;
  382. Spawn* spawn = lua_interface->GetSpawn(state);
  383. string mp3_string = lua_interface->GetStringValue(state, 2);
  384. int32 key1 = lua_interface->GetInt32Value(state, 3);
  385. int32 key2 = lua_interface->GetInt32Value(state, 4);
  386. Spawn* player = lua_interface->GetSpawn(state, 5);
  387. if (spawn && mp3_string.length() > 0) {
  388. Client* client = 0;
  389. if (player && player->IsPlayer())
  390. client = spawn->GetZone()->GetClientBySpawn(player);
  391. if (client) {
  392. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  393. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  394. }
  395. else
  396. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  397. }
  398. return 0;
  399. }
  400. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  401. if (!lua_interface)
  402. return 0;
  403. Spawn* spawn = lua_interface->GetSpawn(state);
  404. if (spawn) {
  405. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  406. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  407. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  408. return 3;
  409. }
  410. return 0;
  411. }
  412. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  413. if (!lua_interface)
  414. return 0;
  415. Spawn* spawn = lua_interface->GetSpawn(state);
  416. if (spawn && spawn->IsEntity()) {
  417. int32 item_id = lua_interface->GetInt32Value(state, 2);
  418. int16 charges = lua_interface->GetInt16Value(state, 3);
  419. if (charges == 0)
  420. charges = 1;
  421. ((Entity*)spawn)->AddLootItem(item_id, charges);
  422. }
  423. return 0;
  424. }
  425. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  426. if (!lua_interface)
  427. return 0;
  428. Spawn* spawn = lua_interface->GetSpawn(state);
  429. if (spawn && spawn->IsEntity()) {
  430. int32 item_id = lua_interface->GetInt32Value(state, 2);
  431. ((Entity*)spawn)->LootItem(item_id);
  432. }
  433. return 0;
  434. }
  435. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  436. if (!lua_interface)
  437. return 0;
  438. Spawn* spawn = lua_interface->GetSpawn(state);
  439. if (spawn && spawn->IsEntity()) {
  440. int32 val = lua_interface->GetInt32Value(state, 2);
  441. ((Entity*)spawn)->AddLootCoins(val);
  442. }
  443. return 0;
  444. }
  445. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  446. if (!lua_interface)
  447. return 0;
  448. Spawn* entity = lua_interface->GetSpawn(state);
  449. Spawn* player = lua_interface->GetSpawn(state, 2);
  450. if (entity && entity->IsEntity() && player && player->IsPlayer()) {
  451. int32 coins = lua_interface->GetInt32Value(state, 3);
  452. vector<Item*>* items = 0;
  453. int i = 0;
  454. int32 item_id = 0;
  455. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  456. if (items == 0)
  457. items = new vector<Item*>;
  458. if (master_item_list.GetItem(item_id))
  459. items->push_back(master_item_list.GetItem(item_id));
  460. i++;
  461. }
  462. Client* client = 0;
  463. client = entity->GetZone()->GetClientBySpawn(player);
  464. if (client) {
  465. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  466. client->Loot(coins, ((Player*)player)->GetPendingLootItems(entity->GetID()), (Entity*)entity);
  467. }
  468. safe_delete(items);
  469. }
  470. return 0;
  471. }
  472. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  473. if (!lua_interface)
  474. return 0;
  475. Spawn* entity = lua_interface->GetSpawn(state);
  476. Spawn* player = lua_interface->GetSpawn(state, 2);
  477. int32 item_id = lua_interface->GetInt32Value(state, 3);
  478. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  479. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  480. return 1;
  481. }
  482. return 0;
  483. }
  484. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  485. if (!lua_interface)
  486. return 0;
  487. Spawn* entity = lua_interface->GetSpawn(state);
  488. Spawn* player = lua_interface->GetSpawn(state, 2);
  489. if (entity && entity->IsEntity() && player && player->IsPlayer()) {
  490. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  491. return 1;
  492. }
  493. return 0;
  494. }
  495. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  496. if (!lua_interface)
  497. return 0;
  498. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  499. safe_delete(conversation);
  500. conversation = new vector<ConversationOption>();
  501. lua_interface->SetConversationValue(state, conversation);
  502. return 1;
  503. }
  504. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  505. if (!lua_interface)
  506. return 0;
  507. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  508. if (conversation) {
  509. ConversationOption conv_option;
  510. conv_option.option = lua_interface->GetStringValue(state, 2);
  511. conv_option.function = lua_interface->GetStringValue(state, 3);
  512. if (conv_option.option.length() > 0)
  513. conversation->push_back(conv_option);
  514. }
  515. return 0;
  516. }
  517. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  518. if (!lua_interface)
  519. return 0;
  520. Spawn* npc = lua_interface->GetSpawn(state);
  521. Spawn* player = lua_interface->GetSpawn(state, 2);
  522. if (npc && player && player->IsPlayer() && player->GetZone()) {
  523. Client* client = player->GetZone()->GetClientBySpawn(player);
  524. if (client) {
  525. int32 conversation_id = client->GetConversationID(npc, 0);
  526. client->CloseDialog(conversation_id);
  527. }
  528. }
  529. return 0;
  530. }
  531. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  532. if (!lua_interface)
  533. return 0;
  534. Item* item = lua_interface->GetItem(state);
  535. Spawn* player = lua_interface->GetSpawn(state, 2);
  536. if (item && player && player->IsPlayer() && player->GetZone()) {
  537. Client* client = player->GetZone()->GetClientBySpawn(player);
  538. if (client) {
  539. int32 conversation_id = client->GetConversationID(0, item);
  540. client->CloseDialog(conversation_id);
  541. }
  542. }
  543. return 0;
  544. }
  545. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  546. if (!lua_interface)
  547. return 0;
  548. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  549. Spawn* spawn = 0;
  550. Item* item = 0;
  551. int8 type = lua_interface->GetInt8Value(state, 2);
  552. if (type == 1 || type == 3)
  553. spawn = lua_interface->GetSpawn(state, 3);
  554. else if (type == 2 || type == 4)
  555. item = lua_interface->GetItem(state, 3);
  556. Spawn* player = lua_interface->GetSpawn(state, 4);
  557. string text = lua_interface->GetStringValue(state, 5);
  558. string mp3 = lua_interface->GetStringValue(state, 6);
  559. int32 key1 = lua_interface->GetInt32Value(state, 7);
  560. int32 key2 = lua_interface->GetInt32Value(state, 8);
  561. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  562. Client* client = player->GetZone()->GetClientBySpawn(player);
  563. if (client) {
  564. if (spawn) {
  565. // Need to do this so the function works the same as it did before
  566. if (type == 1)
  567. type++;
  568. if (mp3.length() > 0)
  569. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  570. else
  571. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  572. }
  573. else {
  574. if (mp3.length() > 0)
  575. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  576. else
  577. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  578. }
  579. }
  580. }
  581. safe_delete(conversation);
  582. lua_interface->SetConversationValue(state, NULL);
  583. return 0;
  584. }
  585. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  586. if(!lua_interface)
  587. return 0;
  588. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  589. Item* item = lua_interface->GetItem(state, 2);
  590. Spawn* player = lua_interface->GetSpawn(state, 3);
  591. string text = lua_interface->GetStringValue(state, 4);
  592. string mp3 = lua_interface->GetStringValue(state, 5);
  593. int32 key1 = lua_interface->GetInt32Value(state, 6);
  594. int32 key2 = lua_interface->GetInt32Value(state, 7);
  595. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  596. Client* client = player->GetZone()->GetClientBySpawn(player);
  597. if(client){
  598. if(mp3.length() > 0)
  599. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  600. else
  601. client->DisplayConversation(item, conversation, (char*)text.c_str());
  602. }
  603. safe_delete(conversation);
  604. }
  605. return 0;
  606. }*/
  607. int EQ2Emu_lua_StartConversation(lua_State* state) {
  608. if (!lua_interface)
  609. return 0;
  610. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  611. Spawn* npc = lua_interface->GetSpawn(state, 2);
  612. Spawn* player = lua_interface->GetSpawn(state, 3);
  613. string text = lua_interface->GetStringValue(state, 4);
  614. string mp3 = lua_interface->GetStringValue(state, 5);
  615. int32 key1 = lua_interface->GetInt32Value(state, 6);
  616. int32 key2 = lua_interface->GetInt32Value(state, 7);
  617. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  618. Client* client = npc->GetZone()->GetClientBySpawn(player);
  619. if (mp3.length() > 0)
  620. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  621. else
  622. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  623. safe_delete(conversation);
  624. lua_interface->SetConversationValue(state, NULL);
  625. }
  626. else
  627. 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.", npc ? npc->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  628. return 0;
  629. }
  630. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  631. if (!lua_interface)
  632. return 0;
  633. Spawn* spawn = lua_interface->GetSpawn(state);
  634. float distance = lua_interface->GetFloatValue(state, 2);
  635. string in_range_function = lua_interface->GetStringValue(state, 3);
  636. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  637. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  638. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  639. return 0;
  640. }
  641. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  642. ZoneServer* zone = lua_interface->GetZone(state);
  643. float x = lua_interface->GetFloatValue(state, 2);
  644. float y = lua_interface->GetFloatValue(state, 3);
  645. float z = lua_interface->GetFloatValue(state, 4);
  646. float max_variation = lua_interface->GetFloatValue(state, 5);
  647. string in_range_function = lua_interface->GetStringValue(state, 6);
  648. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  649. if (zone && in_range_function.length() > 0)
  650. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  651. return 0;
  652. }
  653. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  654. if (!lua_interface)
  655. return 0;
  656. Spawn* spawn = lua_interface->GetSpawn(state);
  657. if (spawn && spawn->IsEntity()) {
  658. int32 val = lua_interface->GetInt32Value(state, 2);
  659. ((Entity*)spawn)->SetLootCoins(val);
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. if (spawn && spawn->IsEntity()) {
  668. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  669. return 1;
  670. }
  671. return 0;
  672. }
  673. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  674. if (!lua_interface)
  675. return 0;
  676. Spawn* spawn = lua_interface->GetSpawn(state);
  677. float x = lua_interface->GetFloatValue(state, 2);
  678. float y = lua_interface->GetFloatValue(state, 3);
  679. float z = lua_interface->GetFloatValue(state, 4);
  680. float speed = lua_interface->GetFloatValue(state, 5);
  681. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  682. string function = lua_interface->GetStringValue(state, 7);
  683. if (spawn) {
  684. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  685. spawn->GetZone()->AddMovementNPC(spawn);
  686. }
  687. lua_interface->ResetFunctionStack(state);
  688. return 0;
  689. }
  690. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  691. if (!lua_interface)
  692. return 0;
  693. Spawn* spawn = lua_interface->GetSpawn(state);
  694. if (spawn) {
  695. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  701. if (!lua_interface)
  702. return 0;
  703. Spawn* spawn = lua_interface->GetSpawn(state);
  704. Spawn* target = lua_interface->GetSpawn(state, 2);
  705. if (spawn && target) {
  706. if (spawn->IsEntity())
  707. // ((Entity*)spawn)->FaceTarget(target);
  708. static_cast<Entity*>(spawn)->FaceTarget(target);
  709. }
  710. lua_interface->ResetFunctionStack(state);
  711. return 0;
  712. }
  713. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  714. if (!lua_interface)
  715. return 0;
  716. Spawn* spawn = lua_interface->GetSpawn(state);
  717. float x = lua_interface->GetFloatValue(state, 2);
  718. float y = lua_interface->GetFloatValue(state, 3);
  719. float z = lua_interface->GetFloatValue(state, 4);
  720. float speed = lua_interface->GetFloatValue(state, 5);
  721. string lua_function = lua_interface->GetStringValue(state, 6);
  722. bool more_points = lua_interface->GetBooleanValue(state, 7);
  723. if (spawn) {
  724. if (speed == 0)
  725. speed = spawn->GetSpeed();
  726. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  727. }
  728. lua_interface->ResetFunctionStack(state);
  729. return 0;
  730. }
  731. int EQ2Emu_lua_Say(lua_State* state) {
  732. if (!lua_interface)
  733. return 0;
  734. Spawn* spawn = lua_interface->GetSpawn(state);
  735. string message = lua_interface->GetStringValue(state, 2);
  736. Spawn* player = lua_interface->GetSpawn(state, 3);
  737. int32 language = lua_interface->GetInt32Value(state, 4);
  738. if (spawn && message.length() > 0) {
  739. Client* client = 0;
  740. if (player && player->IsPlayer())
  741. client = spawn->GetZone()->GetClientBySpawn(player);
  742. if (client)
  743. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  744. else
  745. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  746. }
  747. lua_interface->ResetFunctionStack(state);
  748. return 0;
  749. }
  750. int EQ2Emu_lua_Shout(lua_State* state) {
  751. if (!lua_interface)
  752. return 0;
  753. Spawn* spawn = lua_interface->GetSpawn(state);
  754. string message = lua_interface->GetStringValue(state, 2);
  755. Spawn* player = lua_interface->GetSpawn(state, 3);
  756. if (spawn && message.length() > 0) {
  757. Client* client = 0;
  758. if (player && player->IsPlayer())
  759. client = spawn->GetZone()->GetClientBySpawn(player);
  760. if (client)
  761. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  762. else
  763. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  764. }
  765. lua_interface->ResetFunctionStack(state);
  766. return 0;
  767. }
  768. int EQ2Emu_lua_SayOOC(lua_State* state) {
  769. if (!lua_interface)
  770. return 0;
  771. Spawn* spawn = lua_interface->GetSpawn(state);
  772. string message = lua_interface->GetStringValue(state, 2);
  773. Spawn* player = lua_interface->GetSpawn(state, 3);
  774. if (spawn && message.length() > 0) {
  775. Client* client = 0;
  776. if (player && player->IsPlayer())
  777. client = spawn->GetZone()->GetClientBySpawn(player);
  778. if (client)
  779. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OOC, message.c_str(), 30);
  780. else
  781. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OOC, message.c_str(), 30);
  782. }
  783. lua_interface->ResetFunctionStack(state);
  784. return 0;
  785. }
  786. int EQ2Emu_lua_Emote(lua_State* state) {
  787. if (!lua_interface)
  788. return 0;
  789. Spawn* spawn = lua_interface->GetSpawn(state);
  790. string message = lua_interface->GetStringValue(state, 2);
  791. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  792. Spawn* player = lua_interface->GetSpawn(state, 4);
  793. char* to = 0;
  794. if (spawn2)
  795. to = spawn2->GetName();
  796. if (spawn && message.length() > 0) {
  797. Client* client = 0;
  798. if (player && player->IsPlayer())
  799. client = spawn->GetZone()->GetClientBySpawn(player);
  800. if (client)
  801. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  802. else
  803. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  804. }
  805. lua_interface->ResetFunctionStack(state);
  806. return 0;
  807. }
  808. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  809. if (!lua_interface)
  810. return 0;
  811. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  812. if (!luaspell)
  813. return 0;
  814. Spawn* caster = luaspell->caster;
  815. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  816. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  817. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  818. Spawn* target = lua_interface->GetSpawn(state, 4);
  819. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  820. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  821. lua_interface->ResetFunctionStack(state);
  822. if (caster && caster->IsEntity()) {
  823. bool success = false;
  824. luaspell->resisted = false;
  825. if (target) {
  826. float distance = caster->GetDistance(target, true);
  827. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs))
  828. success = true;
  829. }
  830. if (luaspell->targets.size() > 0) {
  831. Spawn* target = 0;
  832. ZoneServer* zone = luaspell->caster->GetZone();
  833. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  834. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  835. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  836. float distance = caster->GetDistance(target, true);
  837. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs);
  838. }
  839. }
  840. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  841. success = true;
  842. }
  843. if (success) {
  844. if (caster->GetZone())
  845. caster->GetZone()->TriggerCharSheetTimer();
  846. }
  847. }
  848. return 0;
  849. }
  850. int EQ2Emu_lua_SummonItem(lua_State* state) {
  851. if (!lua_interface)
  852. return 0;
  853. Spawn* spawn = lua_interface->GetSpawn(state);
  854. int32 item_id = lua_interface->GetInt32Value(state, 2);
  855. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  856. string location = lua_interface->GetStringValue(state, 4);
  857. if (spawn && spawn->IsPlayer()) {
  858. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  859. if (client && item_id > 0) {
  860. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  861. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  862. else
  863. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  864. if (send_messages) {
  865. Item* item = master_item_list.GetItem(item_id);
  866. if (item) {
  867. client->Message(CHANNEL_COLOR_YELLOW, "You receive \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  868. string popup_text = "You receive " + item->name;
  869. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  870. }
  871. }
  872. return 1;
  873. }
  874. }
  875. lua_interface->SetBooleanValue(state, false);
  876. return 1;
  877. }
  878. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  879. Spawn* spawn = lua_interface->GetSpawn(state);
  880. int32 item_id = lua_interface->GetInt32Value(state, 2);
  881. Client* client;
  882. Item* item;
  883. if (spawn && spawn->IsPlayer() && item_id > 0) {
  884. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  885. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  886. if (client->RemoveItem(item, 1)) {
  887. lua_interface->SetBooleanValue(state, true);
  888. return 1;
  889. }
  890. }
  891. }
  892. }
  893. lua_interface->SetBooleanValue(state, false);
  894. return 1;
  895. }
  896. int EQ2Emu_lua_HasItem(lua_State* state) {
  897. Spawn* player = lua_interface->GetSpawn(state);
  898. int32 item_id = lua_interface->GetInt32Value(state, 2);
  899. bool include_bank = lua_interface->GetInt8Value(state, 3);
  900. if (player && player->IsPlayer()) {
  901. bool hasItem = false;
  902. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  903. if (!hasItem)
  904. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  905. lua_interface->SetBooleanValue(state, hasItem);
  906. return 1;
  907. }
  908. lua_interface->SetBooleanValue(state, false);
  909. return 1;
  910. }
  911. int EQ2Emu_lua_Spawn(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. ZoneServer* zone = lua_interface->GetZone(state);
  915. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  916. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  917. float x = lua_interface->GetFloatValue(state, 4);
  918. float y = lua_interface->GetFloatValue(state, 5);
  919. float z = lua_interface->GetFloatValue(state, 6);
  920. float heading = lua_interface->GetFloatValue(state, 7);
  921. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  922. Spawn* spawn = zone->GetSpawn(spawn_id);
  923. if (!spawn)
  924. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  925. else {
  926. spawn->SetX(x);
  927. spawn->SetZ(z);
  928. spawn->SetY(y,true,true);
  929. spawn->SetLocation(zone->GetClosestLocation(spawn));
  930. spawn->SetHeading(heading);
  931. if (restricted_npc)
  932. spawn->AddAllowAccessSpawn(spawn);
  933. const char* spawn_script = world.GetSpawnScript(spawn_id);
  934. bool scriptActive = false;
  935. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  936. scriptActive = true;
  937. spawn->SetSpawnScript(string(spawn_script));
  938. }
  939. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  940. zone->AddSpawn(spawn);
  941. if (scriptActive) {
  942. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  943. }
  944. lua_interface->SetSpawnValue(state, spawn);
  945. return 1;
  946. }
  947. }
  948. else {
  949. string output = "Invalid paramaters to LUA Spawn command: \n";
  950. if (!zone)
  951. output = output.append("\t").append("Missing zone reference. \n");
  952. if (spawn_id == 0)
  953. output = output.append("\t").append("Missing spawn_id.");
  954. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone - %s", lua_interface->GetScriptName(state), output.c_str());
  955. }
  956. return 0;
  957. }
  958. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  959. if (!lua_interface)
  960. return 0;
  961. ZoneServer* zone = lua_interface->GetZone(state);
  962. if (zone) {
  963. lua_interface->SetStringValue(state, zone->GetZoneName());
  964. return 1;
  965. }
  966. return 0;
  967. }
  968. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  969. if (!lua_interface)
  970. return 0;
  971. ZoneServer* zone = lua_interface->GetZone(state);
  972. if (zone) {
  973. lua_interface->SetInt32Value(state, zone->GetZoneID());
  974. return 1;
  975. }
  976. return 0;
  977. }
  978. int EQ2Emu_lua_GetZone(lua_State* state) {
  979. if (!lua_interface)
  980. return 0;
  981. int32 zone_id = lua_interface->GetInt32Value(state);
  982. ZoneServer* zone = 0;
  983. if (zone_id > 0)
  984. zone = zone_list.Get(zone_id);
  985. else {
  986. string zone_name = lua_interface->GetStringValue(state);
  987. if (zone_name.length() > 0) {
  988. zone = zone_list.Get(zone_name.c_str());
  989. }
  990. else {
  991. Spawn* spawn = lua_interface->GetSpawn(state);
  992. if (spawn)
  993. zone = spawn->GetZone();
  994. }
  995. }
  996. if (zone) {
  997. lua_interface->SetZoneValue(state, zone);
  998. return 1;
  999. }
  1000. return 0;
  1001. }
  1002. int EQ2Emu_lua_AddHate(lua_State* state) {
  1003. Spawn* entity = lua_interface->GetSpawn(state);
  1004. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1005. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1006. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1007. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1008. if (entity && entity->IsEntity() && amount != 0) {
  1009. if (luaspell) {
  1010. ZoneServer* zone = luaspell->caster->GetZone();
  1011. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1012. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1013. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1014. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1015. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1016. if (send_packet)
  1017. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1018. }
  1019. }
  1020. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1021. }
  1022. else if (npc && npc->IsNPC() && npc->GetZone())
  1023. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1024. }
  1025. return 0;
  1026. }
  1027. int EQ2Emu_lua_Zone(lua_State* state) {
  1028. if (!lua_interface)
  1029. return 0;
  1030. ZoneServer* zone = lua_interface->GetZone(state);
  1031. Spawn* player = lua_interface->GetSpawn(state, 2);
  1032. Client* client = 0;
  1033. if (player && player->IsPlayer())
  1034. client = player->GetZone()->GetClientBySpawn(player);
  1035. float x = lua_interface->GetFloatValue(state, 3);
  1036. float y = lua_interface->GetFloatValue(state, 4);
  1037. float z = lua_interface->GetFloatValue(state, 5);
  1038. float heading = lua_interface->GetFloatValue(state, 6);
  1039. if (zone && client) {
  1040. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1041. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1042. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1043. {
  1044. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1045. return 0;
  1046. }
  1047. if (x != 0 || y != 0 || z != 0) {
  1048. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1049. player->SetX(x);
  1050. player->SetY(y);
  1051. player->SetZ(z);
  1052. player->SetHeading(heading);
  1053. client->Zone(zone->GetZoneName(), false);
  1054. }
  1055. else
  1056. client->Zone(zone->GetZoneName());
  1057. }
  1058. else
  1059. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1060. return 0;
  1061. }
  1062. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1063. if (!lua_interface)
  1064. return 0;
  1065. Spawn* spawn = lua_interface->GetSpawn(state);
  1066. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1067. if (spawn && spawn2)
  1068. spawn->AddAllowAccessSpawn(spawn2);
  1069. return 0;
  1070. }
  1071. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1072. if (!lua_interface)
  1073. return 0;
  1074. Spawn* target = lua_interface->GetSpawn(state);
  1075. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1076. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1077. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1078. if (!target) {
  1079. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1080. return 0;
  1081. }
  1082. if (!target->IsEntity()) {
  1083. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1084. return 0;
  1085. }
  1086. if (spell_id <= 0) {
  1087. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1088. return 0;
  1089. }
  1090. if (caster && !caster->IsEntity()) {
  1091. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1092. return 0;
  1093. }
  1094. if (spell_tier == 0)
  1095. spell_tier = 1;
  1096. if (!caster)
  1097. caster = target;
  1098. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target);
  1099. return 0;
  1100. }
  1101. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1102. if (!lua_interface)
  1103. return 0;
  1104. Spawn* target = lua_interface->GetSpawn(state);
  1105. int32 target_id = 0;
  1106. if (target)
  1107. target_id = target->GetID();
  1108. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1109. if (!luaspell)
  1110. return 0;
  1111. Spawn* caster = luaspell->caster;
  1112. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1113. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1114. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1115. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1116. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1117. //lua_interface->ResetFunctionStack(state);
  1118. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1119. vector<int16> faction_req;
  1120. vector<int16> race_req;
  1121. int32 class_req = 0;
  1122. int32 i = 0;
  1123. int8 f = 0;
  1124. int8 r = 0;
  1125. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1126. if (class_id < 100) {
  1127. class_req += pow(2.0, double(class_id - 1));
  1128. }
  1129. else if (class_id > 100 && class_id < 1000) {
  1130. race_req.push_back(class_id);
  1131. r++;
  1132. }
  1133. else {
  1134. faction_req.push_back(class_id);
  1135. f++;
  1136. }
  1137. i++;
  1138. }
  1139. if (caster && caster->IsEntity()) {
  1140. bool race_match = false;
  1141. bool success = false;
  1142. luaspell->resisted = false;
  1143. if (luaspell->initial_target == target_id) {
  1144. int xxx = 0;
  1145. }
  1146. if (luaspell->targets.size() > 0) {
  1147. ZoneServer* zone = luaspell->caster->GetZone();
  1148. Spawn* target = 0;
  1149. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1150. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1151. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1152. if (race_req.size() > 0) {
  1153. for (int8 i = 0; i < race_req.size(); i++) {
  1154. int32 xxx = target->GetLuaRaceId();
  1155. if (target->GetLuaRaceId() == race_req[i]) {
  1156. race_match = true;
  1157. }
  1158. }
  1159. }
  1160. else
  1161. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1162. if (race_match == true) {
  1163. float distance = caster->GetDistance(target, true);
  1164. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1165. }
  1166. }
  1167. }
  1168. success = true;
  1169. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1170. }
  1171. else if (target) {
  1172. //check class and race/faction here
  1173. if (race_req.size() > 0) {
  1174. for (int8 i = 0; i < race_req.size(); i++) {
  1175. if (target->GetLuaRaceId() == race_req[i]) {
  1176. race_match = true;
  1177. }
  1178. }
  1179. }
  1180. else
  1181. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1182. if (race_match == true) {
  1183. float distance = caster->GetDistance(target, true);
  1184. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1185. success = true;
  1186. }
  1187. }
  1188. if (success) {
  1189. Spell* spell = luaspell->spell;
  1190. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1191. ((Player*)caster)->InCombat(true);
  1192. if (caster->GetZone())
  1193. caster->GetZone()->TriggerCharSheetTimer();
  1194. }
  1195. }
  1196. }
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1204. lua_interface->ResetFunctionStack(state);
  1205. if (spawn && value != 0) {
  1206. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1207. spawn->SetPower(spawn->GetTotalPower());
  1208. else
  1209. spawn->SetPower(spawn->GetPower() + value);
  1210. }
  1211. return 0;
  1212. }
  1213. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1214. if (!lua_interface)
  1215. return 0;
  1216. Spawn* spawn = lua_interface->GetSpawn(state);
  1217. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1218. lua_interface->ResetFunctionStack(state);
  1219. if (spawn && value != 0) {
  1220. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1221. spawn->SetHP(spawn->GetTotalHP());
  1222. else
  1223. spawn->SetHP(spawn->GetHP() + value);
  1224. }
  1225. return 0;
  1226. }
  1227. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1228. if (!lua_interface)
  1229. return 0;
  1230. Spawn* spawn = lua_interface->GetSpawn(state);
  1231. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1232. lua_interface->ResetFunctionStack(state);
  1233. if (spawn && value != 0) {
  1234. spawn->SetPower(spawn->GetPower() + value);
  1235. if (value > spawn->GetTotalHPBase())
  1236. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1237. }
  1238. return 0;
  1239. }
  1240. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1241. if (!lua_interface)
  1242. return 0;
  1243. Spawn* spawn = lua_interface->GetSpawn(state);
  1244. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1245. lua_interface->ResetFunctionStack(state);
  1246. if (spawn && value != 0) {
  1247. spawn->SetHP(spawn->GetHP() + value);
  1248. if (value > spawn->GetTotalHPBase())
  1249. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1250. }
  1251. return 0;
  1252. }
  1253. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1254. if (!lua_interface)
  1255. return 0;
  1256. Spawn* spawn = lua_interface->GetSpawn(state);
  1257. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1258. lua_interface->ResetFunctionStack(state);
  1259. if (spawn && value > 0) {
  1260. spawn->SetHP(value);
  1261. if (value > spawn->GetTotalHPBase())
  1262. spawn->SetTotalHP(value);
  1263. }
  1264. return 0;
  1265. }
  1266. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1267. if (!lua_interface)
  1268. return 0;
  1269. Spawn* spawn = lua_interface->GetSpawn(state);
  1270. float value = lua_interface->GetFloatValue(state, 2);
  1271. lua_interface->ResetFunctionStack(state);
  1272. if (spawn && spawn->IsEntity() && value > 0)
  1273. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1274. if (spawn->IsPlayer())
  1275. ((Player*)spawn)->SetCharSheetChanged(true);
  1276. return 0;
  1277. }
  1278. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1279. if (!lua_interface)
  1280. return 0;
  1281. Spawn* spawn = lua_interface->GetSpawn(state);
  1282. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1283. lua_interface->ResetFunctionStack(state);
  1284. if (spawn && spawn->IsEntity() && value > 0)
  1285. ((Entity*)spawn)->SetTotalHPBase(value);
  1286. return 0;
  1287. }
  1288. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1289. if (!lua_interface)
  1290. return 0;
  1291. Spawn* spawn = lua_interface->GetSpawn(state);
  1292. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1293. lua_interface->ResetFunctionStack(state);
  1294. if (spawn && value > 0) {
  1295. spawn->SetPower(value);
  1296. if (value > spawn->GetTotalPowerBase())
  1297. spawn->SetTotalPower(value);
  1298. }
  1299. return 0;
  1300. }
  1301. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1302. if (!lua_interface)
  1303. return 0;
  1304. Spawn* spawn = lua_interface->GetSpawn(state);
  1305. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1306. lua_interface->ResetFunctionStack(state);
  1307. if (spawn && spawn->IsEntity() && value > 0)
  1308. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1309. return 0;
  1310. }
  1311. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1312. if (!lua_interface)
  1313. return 0;
  1314. Spawn* spawn = lua_interface->GetSpawn(state);
  1315. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1316. lua_interface->ResetFunctionStack(state);
  1317. if (spawn && spawn->IsEntity() && value > 0)
  1318. ((Entity*)spawn)->SetTotalPowerBase(value);
  1319. return 0;
  1320. }
  1321. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1322. if (!lua_interface)
  1323. return 0;
  1324. Spawn* spawn = lua_interface->GetSpawn(state);
  1325. float x = lua_interface->GetFloatValue(state, 2);
  1326. float y = lua_interface->GetFloatValue(state, 3);
  1327. float z = lua_interface->GetFloatValue(state, 4);
  1328. float heading = lua_interface->GetFloatValue(state, 5);
  1329. lua_interface->ResetFunctionStack(state);
  1330. if (spawn) {
  1331. spawn->SetX(x);
  1332. spawn->SetY(y);
  1333. spawn->SetZ(z);
  1334. if (heading != 0)
  1335. spawn->SetHeading(heading);
  1336. spawn->SetSpawnOrigX(spawn->GetX());
  1337. spawn->SetSpawnOrigY(spawn->GetY());
  1338. spawn->SetSpawnOrigZ(spawn->GetZ());
  1339. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1340. if (spawn->IsPlayer()) {
  1341. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1342. if (client) {
  1343. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1344. client->QueuePacket(packet);
  1345. }
  1346. }
  1347. }
  1348. return 0;
  1349. }
  1350. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1351. if (!lua_interface)
  1352. return 0;
  1353. Spawn* spawn = lua_interface->GetSpawn(state);
  1354. float value = lua_interface->GetFloatValue(state, 2);
  1355. lua_interface->ResetFunctionStack(state);
  1356. if (spawn) {
  1357. spawn->SetHeading(value);
  1358. if (spawn->IsPlayer()) {
  1359. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1360. if (client) {
  1361. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1362. client->QueuePacket(packet);
  1363. }
  1364. }
  1365. }
  1366. return 0;
  1367. }
  1368. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1369. if (!lua_interface)
  1370. return 0;
  1371. Spawn* spawn = lua_interface->GetSpawn(state);
  1372. int16 value = lua_interface->GetInt16Value(state, 2);
  1373. lua_interface->ResetFunctionStack(state);
  1374. if (spawn)
  1375. spawn->SetModelType(value);
  1376. return 0;
  1377. }
  1378. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1379. if (!lua_interface)
  1380. return 0;
  1381. Spawn* spawn = lua_interface->GetSpawn(state);
  1382. int8 value = lua_interface->GetInt8Value(state, 2);
  1383. lua_interface->ResetFunctionStack(state);
  1384. if (spawn) {
  1385. if (spawn->IsPlayer())
  1386. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1387. else
  1388. spawn->SetAdventureClass(value);
  1389. }
  1390. return 0;
  1391. }
  1392. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1393. if (!lua_interface)
  1394. return 0;
  1395. Spawn* spawn = lua_interface->GetSpawn(state);
  1396. int8 value = lua_interface->GetInt8Value(state, 2);
  1397. lua_interface->ResetFunctionStack(state);
  1398. if (spawn) {
  1399. spawn->SetTradeskillClass(value);
  1400. if (spawn->IsEntity()) {
  1401. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1402. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1403. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1404. }
  1405. if (spawn->IsPlayer())
  1406. ((Player*)spawn)->SetCharSheetChanged(true);
  1407. }
  1408. return 0;
  1409. }
  1410. int EQ2Emu_lua_SetMount(lua_State* state) {
  1411. if (!lua_interface)
  1412. return 0;
  1413. Spawn* spawn = lua_interface->GetSpawn(state);
  1414. int16 value = lua_interface->GetInt16Value(state, 2);
  1415. if (spawn && spawn->IsEntity()) {
  1416. ((Entity*)spawn)->SetMount(value);
  1417. EQ2_Color color;
  1418. color.red = 255;
  1419. color.green = 255;
  1420. color.blue = 255;
  1421. ((Entity*)spawn)->SetMountColor(&color);
  1422. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1423. }
  1424. return 0;
  1425. }
  1426. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1427. if (!lua_interface)
  1428. return 0;
  1429. Spawn* spawn = lua_interface->GetSpawn(state);
  1430. EQ2_Color mount_color;
  1431. EQ2_Color saddle_color;
  1432. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1433. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1434. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1435. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1436. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1437. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1438. if (spawn && spawn->IsEntity()) {
  1439. ((Entity*)spawn)->SetMountColor(&mount_color);
  1440. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1441. }
  1442. return 0;
  1443. }
  1444. int EQ2Emu_lua_GetMount(lua_State* state) {
  1445. if (!lua_interface)
  1446. return 0;
  1447. Spawn* spawn = lua_interface->GetSpawn(state);
  1448. if (spawn && spawn->IsEntity()) {
  1449. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1450. return 1;
  1451. }
  1452. return 0;
  1453. }
  1454. int EQ2Emu_lua_GetRace(lua_State* state) {
  1455. if (!lua_interface)
  1456. return 0;
  1457. Spawn* spawn = lua_interface->GetSpawn(state);
  1458. if (spawn)
  1459. {
  1460. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1461. lua_interface->SetInt32Value(state, spawn->GetRace());
  1462. return 1;
  1463. }
  1464. return 0;
  1465. }
  1466. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1467. if (!lua_interface)
  1468. return 0;
  1469. Spawn* spawn = lua_interface->GetSpawn(state);
  1470. if (spawn) {
  1471. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1472. return 1;
  1473. }
  1474. return 0;
  1475. }
  1476. int EQ2Emu_lua_GetClass(lua_State* state) {
  1477. Spawn* spawn = lua_interface->GetSpawn(state);
  1478. if (spawn) {
  1479. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1480. return 1;
  1481. }
  1482. return 0;
  1483. }
  1484. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1485. Spawn* spawn = lua_interface->GetSpawn(state);
  1486. if (spawn) {
  1487. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1488. return 1;
  1489. }
  1490. return 0;
  1491. }
  1492. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1493. if (!lua_interface)
  1494. return 0;
  1495. Spawn* spawn = lua_interface->GetSpawn(state);
  1496. float value = lua_interface->GetFloatValue(state, 2);
  1497. lua_interface->ResetFunctionStack(state);
  1498. if (spawn) {
  1499. spawn->SetSpeed(value);
  1500. ((Entity*)spawn)->SetSpeed(value);
  1501. if (spawn->IsPlayer()) {
  1502. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1503. if (client) {
  1504. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1505. if (packet) {
  1506. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1507. packet->setDataByName("speed", value);
  1508. packet->setDataByName("size", 0.51);
  1509. EQ2Packet* app = packet->serialize();
  1510. client->QueuePacket(app);
  1511. safe_delete(packet);
  1512. }
  1513. }
  1514. }
  1515. }
  1516. return 0;
  1517. }
  1518. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1519. if (!lua_interface)
  1520. return 0;
  1521. Spawn* spawn = lua_interface->GetSpawn(state);
  1522. const int16 type = lua_interface->GetInt16Value(state, 2);
  1523. const float value = lua_interface->GetFloatValue(state, 3);
  1524. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1525. int64 class_req = 0;
  1526. int32 class_id = 0;
  1527. vector<int16> faction_req;
  1528. vector<int16> race_req;
  1529. int32 i = 0;
  1530. int8 f = 0;
  1531. int8 r = 0;
  1532. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1533. if (class_id < 100) {
  1534. class_req += pow(2.0, double(class_id - 1));
  1535. }
  1536. else if (class_id > 100 && class_id < 1000) {
  1537. race_req.push_back(class_id);
  1538. r++;
  1539. }
  1540. else {
  1541. faction_req.push_back(class_id);
  1542. f++;
  1543. }
  1544. i++;
  1545. }
  1546. if (value != 0 && type >= 0) {
  1547. if (luaspell && luaspell->spell && luaspell->caster) {
  1548. ZoneServer* zone = luaspell->caster->GetZone();
  1549. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1550. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1551. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1552. if (target) {
  1553. if (target->IsPlayer()) {
  1554. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1555. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1556. if (((Player*)target)->GetGroupMemberInfo())
  1557. ((Player*)target)->UpdateGroupMemberInfo();
  1558. ((Player*)target)->SetCharSheetChanged(true);
  1559. }
  1560. else if (target->IsNPC())
  1561. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1562. else
  1563. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1564. }
  1565. }
  1566. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1567. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1568. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1569. }
  1570. else if (spawn && spawn->IsEntity()) {
  1571. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1572. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1573. if (spawn->IsPlayer())
  1574. ((Player*)spawn)->SetCharSheetChanged(true);
  1575. }
  1576. else
  1577. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1578. }
  1579. else
  1580. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1581. return 0;
  1582. }
  1583. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1584. if (!lua_interface)
  1585. return 0;
  1586. Spawn* spawn = lua_interface->GetSpawn(state);
  1587. int16 type = lua_interface->GetInt16Value(state, 2);
  1588. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1589. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1590. if (!spawn) {
  1591. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1592. return 0;
  1593. }
  1594. if (!spawn->IsEntity()) {
  1595. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1596. return 0;
  1597. }
  1598. if (value == 0) {
  1599. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1600. return 0;
  1601. }
  1602. if (!luaspell || !luaspell->spell) {
  1603. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1604. return 0;
  1605. }
  1606. int32 class_req = 0;
  1607. vector<int16> faction_req;
  1608. vector<int16> race_req;
  1609. int32 class_id = 0;
  1610. int32 i = 0;
  1611. int8 f = 0;
  1612. int8 r = 0;
  1613. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1614. if (class_id < 100) {
  1615. class_req += pow(2.0, double(class_id - 1));
  1616. }
  1617. else if (class_id > 100 && class_id < 1000) {
  1618. race_req.push_back(class_id);
  1619. r++;
  1620. }
  1621. else {
  1622. faction_req.push_back(class_id);
  1623. f++;
  1624. }
  1625. i++;
  1626. }
  1627. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1628. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1629. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1630. if (spawn->IsPlayer())
  1631. ((Player*)spawn)->SetCharSheetChanged(true);
  1632. return 0;
  1633. }
  1634. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1635. if (!lua_interface)
  1636. return 0;
  1637. Spawn* spawn = lua_interface->GetSpawn(state);
  1638. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1639. if (luaspell && luaspell->spell) {
  1640. ZoneServer* zone = luaspell->caster->GetZone();
  1641. Spawn* target = 0;
  1642. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1643. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1644. target = zone->GetSpawnByID(luaspell->targets[i]);
  1645. if (target && target->IsEntity()) {
  1646. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1647. if (target->IsPlayer())
  1648. ((Player*)target)->SetCharSheetChanged(true);
  1649. }
  1650. }
  1651. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1652. }
  1653. else if (spawn && spawn->IsEntity()) {
  1654. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1655. if (spawn->IsPlayer())
  1656. ((Player*)spawn)->SetCharSheetChanged(true);
  1657. }
  1658. return 0;
  1659. }
  1660. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1661. if (!lua_interface)
  1662. return 0;
  1663. Spawn* spawn = lua_interface->GetSpawn(state);
  1664. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1665. float value = lua_interface->GetFloatValue(state, 3);
  1666. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1667. if (value != 0) {
  1668. int32 spell_id = 0;
  1669. if (luaspell && luaspell->spell && luaspell->caster) {
  1670. spell_id = luaspell->spell->GetSpellID();
  1671. ZoneServer* zone = luaspell->caster->GetZone();
  1672. Spawn* target = 0;
  1673. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1674. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1675. target = zone->GetSpawnByID(luaspell->targets[i]);
  1676. if (target && target->Alive()) {
  1677. if (target->IsPlayer()) {
  1678. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1679. Client* client = target->GetZone()->GetClientBySpawn(target);
  1680. if (client) {
  1681. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1682. if (packet)
  1683. client->QueuePacket(packet);
  1684. }
  1685. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1686. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1687. }
  1688. else if (target->IsNPC()) {
  1689. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1690. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1691. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1692. }
  1693. else
  1694. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1695. }
  1696. }
  1697. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1698. }
  1699. else if (spawn) {
  1700. if (spawn->IsPlayer()) {
  1701. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1702. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1703. if (client) {
  1704. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1705. if (packet)
  1706. client->QueuePacket(packet);
  1707. }
  1708. }
  1709. else if (spawn->IsNPC())
  1710. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1711. else
  1712. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1713. }
  1714. }
  1715. else
  1716. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1717. return 0;
  1718. }
  1719. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1720. if (!lua_interface)
  1721. return 0;
  1722. Spawn* spawn = lua_interface->GetSpawn(state);
  1723. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1724. if (spawn && spawn->IsPlayer()) {
  1725. int32 spell_id = 0;
  1726. if (luaspell && luaspell->spell) {
  1727. spell_id = luaspell->spell->GetSpellID();
  1728. ZoneServer* zone = luaspell->caster->GetZone();
  1729. Spawn* target = 0;
  1730. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1731. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1732. target = zone->GetSpawnByID(luaspell->targets[i]);
  1733. if (target) {
  1734. if (target->IsPlayer()) {
  1735. ((Player*)target)->RemoveSkillBonus(spell_id);
  1736. Client* client = target->GetZone()->GetClientBySpawn(target);
  1737. if (client) {
  1738. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1739. if (packet)
  1740. client->QueuePacket(packet);
  1741. }
  1742. }
  1743. else if (target->IsNPC())
  1744. ((NPC*)target)->RemoveSkillBonus(spell_id);
  1745. else
  1746. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1747. }
  1748. }
  1749. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1750. }
  1751. else if (spawn) {
  1752. if (spawn->IsPlayer()) {
  1753. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  1754. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1755. if (client) {
  1756. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1757. if (packet)
  1758. client->QueuePacket(packet);
  1759. }
  1760. }
  1761. else if (spawn->IsNPC())
  1762. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  1763. else
  1764. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1765. }
  1766. }
  1767. return 0;
  1768. }
  1769. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  1770. if (!lua_interface)
  1771. return 0;
  1772. Spawn* spawn = lua_interface->GetSpawn(state);
  1773. int8 type = lua_interface->GetInt32Value(state, 2);
  1774. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  1775. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1776. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  1777. ZoneServer* zone = luaspell->caster->GetZone();
  1778. Spawn* target = 0;
  1779. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1780. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1781. target = zone->GetSpawnByID(luaspell->targets[i]);
  1782. if (target && target->IsEntity()) {
  1783. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  1784. ((Entity*)target)->AddMezSpell(luaspell);
  1785. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  1786. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  1787. if (target->IsNPC())
  1788. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1789. }
  1790. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  1791. ((Entity*)target)->AddStifleSpell(luaspell);
  1792. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  1793. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  1794. if (target->IsNPC())
  1795. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1796. }
  1797. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  1798. ((Entity*)target)->AddDazeSpell(luaspell);
  1799. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  1800. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  1801. if (target->IsNPC())
  1802. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1803. }
  1804. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  1805. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  1806. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  1807. ((Entity*)target)->AddStunSpell(luaspell);
  1808. if (target->IsNPC())
  1809. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1810. }
  1811. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  1812. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  1813. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  1814. ((Entity*)target)->AddRootSpell(luaspell);
  1815. if (target->IsNPC())
  1816. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1817. }
  1818. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  1819. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  1820. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  1821. ((Entity*)target)->AddFearSpell(luaspell);
  1822. if (target->IsNPC())
  1823. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1824. }
  1825. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  1826. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  1827. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  1828. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  1829. }
  1830. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  1831. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  1832. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  1833. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  1834. }
  1835. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  1836. ((Entity*)target)->AddSnareSpell(luaspell);
  1837. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  1838. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  1839. if (target->IsNPC())
  1840. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1841. }
  1842. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  1843. ((Entity*)target)->AddFlightSpell(luaspell);
  1844. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  1845. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  1846. }
  1847. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  1848. ((Entity*)target)->AddGlideSpell(luaspell);
  1849. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  1850. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  1851. }
  1852. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  1853. ((Entity*)target)->AddSafefallSpell(luaspell);
  1854. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  1855. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  1856. }
  1857. else
  1858. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1859. }
  1860. else
  1861. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  1862. }
  1863. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1864. }
  1865. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  1866. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  1867. ((Entity*)spawn)->AddMezSpell(luaspell);
  1868. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  1869. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  1870. }
  1871. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  1872. ((Entity*)spawn)->AddStifleSpell(luaspell);
  1873. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  1874. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  1875. }
  1876. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  1877. ((Entity*)spawn)->AddDazeSpell(luaspell);
  1878. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  1879. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  1880. }
  1881. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  1882. ((Entity*)spawn)->AddStunSpell(luaspell);
  1883. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  1884. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  1885. }
  1886. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  1887. ((Entity*)spawn)->AddRootSpell(luaspell);
  1888. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  1889. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  1890. }
  1891. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  1892. ((Entity*)spawn)->AddFearSpell(luaspell);
  1893. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  1894. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  1895. }
  1896. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  1897. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  1898. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  1899. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  1900. }
  1901. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  1902. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  1903. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  1904. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  1905. }
  1906. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  1907. ((Entity*)spawn)->AddSnareSpell(luaspell);
  1908. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  1909. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  1910. }
  1911. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  1912. ((Entity*)spawn)->AddFlightSpell(luaspell);
  1913. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  1914. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  1915. }
  1916. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  1917. ((Entity*)spawn)->AddGlideSpell(luaspell);
  1918. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  1919. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  1920. }
  1921. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  1922. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  1923. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  1924. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  1925. }
  1926. else
  1927. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1928. }
  1929. else
  1930. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  1931. return 0;
  1932. }
  1933. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  1934. if (!lua_interface)
  1935. return 0;
  1936. Spawn* spawn = lua_interface->GetSpawn(state);
  1937. int8 type = lua_interface->GetInt8Value(state, 2);
  1938. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  1939. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1940. if (spawn && spawn->IsEntity()) {
  1941. if (!only_remove_spawn && luaspell && luaspell->spell) {
  1942. ZoneServer* zone = luaspell->caster->GetZone();
  1943. Spawn* target = 0;
  1944. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1945. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1946. target = zone->GetSpawnByID(luaspell->targets[i]);
  1947. if (target) {
  1948. if (type == CONTROL_EFFECT_TYPE_MEZ)
  1949. ((Entity*)target)->RemoveMezSpell(luaspell);
  1950. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  1951. ((Entity*)target)->RemoveStifleSpell(luaspell);
  1952. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  1953. ((Entity*)target)->RemoveDazeSpell(luaspell);
  1954. else if (type == CONTROL_EFFECT_TYPE_STUN)
  1955. ((Entity*)target)->RemoveStunSpell(luaspell);
  1956. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  1957. ((Entity*)target)->RemoveRootSpell(luaspell);
  1958. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  1959. ((Entity*)target)->RemoveFearSpell(luaspell);
  1960. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  1961. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  1962. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  1963. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  1964. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  1965. ((Entity*)target)->RemoveSnareSpell(luaspell);
  1966. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  1967. ((Entity*)target)->RemoveFlightSpell(luaspell);
  1968. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  1969. ((Entity*)target)->RemoveGlideSpell(luaspell);
  1970. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  1971. ((Entity*)target)->RemoveGlideSpell(luaspell);
  1972. else
  1973. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1974. }
  1975. }
  1976. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1977. }
  1978. else if (only_remove_spawn) {
  1979. if (type == CONTROL_EFFECT_TYPE_MEZ)
  1980. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  1981. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  1982. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  1983. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  1984. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  1985. else if (type == CONTROL_EFFECT_TYPE_STUN)
  1986. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  1987. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  1988. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  1989. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  1990. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  1991. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  1992. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  1993. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  1994. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  1995. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  1996. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  1997. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  1998. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  1999. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2000. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2001. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2002. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2003. else
  2004. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2005. }
  2006. }
  2007. return 0;
  2008. }
  2009. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2010. if (!lua_interface)
  2011. return 0;
  2012. Spawn* spawn = lua_interface->GetSpawn(state);
  2013. int16 value = lua_interface->GetInt16Value(state, 2);
  2014. if (spawn && spawn->IsEntity()) {
  2015. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2016. if (spawn->IsPlayer())
  2017. ((Player*)spawn)->SetCharSheetChanged(true);
  2018. }
  2019. return 0;
  2020. }
  2021. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2022. if (!lua_interface)
  2023. return 0;
  2024. Spawn* spawn = lua_interface->GetSpawn(state);
  2025. int16 value = lua_interface->GetInt16Value(state, 2);
  2026. if (spawn && spawn->IsEntity()) {
  2027. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2028. if (spawn->IsPlayer())
  2029. ((Player*)spawn)->SetCharSheetChanged(true);
  2030. }
  2031. return 0;
  2032. }
  2033. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2034. if (!lua_interface)
  2035. return 0;
  2036. Spawn* spawn = lua_interface->GetSpawn(state);
  2037. int16 value = lua_interface->GetInt16Value(state, 2);
  2038. if (spawn && spawn->IsEntity()) {
  2039. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2040. if (spawn->IsPlayer())
  2041. ((Player*)spawn)->SetCharSheetChanged(true);
  2042. }
  2043. return 0;
  2044. }
  2045. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2046. if (!lua_interface)
  2047. return 0;
  2048. Spawn* spawn = lua_interface->GetSpawn(state);
  2049. int16 value = lua_interface->GetInt16Value(state, 2);
  2050. if (spawn && spawn->IsEntity()) {
  2051. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2052. if (spawn->IsPlayer())
  2053. ((Player*)spawn)->SetCharSheetChanged(true);
  2054. }
  2055. return 0;
  2056. }
  2057. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2058. if (!lua_interface)
  2059. return 0;
  2060. Spawn* spawn = lua_interface->GetSpawn(state);
  2061. int16 value = lua_interface->GetInt16Value(state, 2);
  2062. if (spawn && spawn->IsEntity()) {
  2063. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2064. if (spawn->IsPlayer())
  2065. ((Player*)spawn)->SetCharSheetChanged(true);
  2066. }
  2067. return 0;
  2068. }
  2069. int EQ2Emu_lua_SetInt(lua_State* state) {
  2070. if (!lua_interface)
  2071. return 0;
  2072. Spawn* spawn = lua_interface->GetSpawn(state);
  2073. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2074. if (spawn && spawn->IsEntity()) {
  2075. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2076. if (spawn->IsPlayer())
  2077. ((Player*)spawn)->SetCharSheetChanged(true);
  2078. }
  2079. return 0;
  2080. }
  2081. int EQ2Emu_lua_SetWis(lua_State* state) {
  2082. if (!lua_interface)
  2083. return 0;
  2084. Spawn* spawn = lua_interface->GetSpawn(state);
  2085. float value = lua_interface->GetFloatValue(state, 2);
  2086. if (spawn && spawn->IsEntity()) {
  2087. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2088. if (spawn->IsPlayer())
  2089. ((Player*)spawn)->SetCharSheetChanged(true);
  2090. }
  2091. return 0;
  2092. }
  2093. int EQ2Emu_lua_SetSta(lua_State* state) {
  2094. if (!lua_interface)
  2095. return 0;
  2096. Spawn* spawn = lua_interface->GetSpawn(state);
  2097. float value = lua_interface->GetFloatValue(state, 2);
  2098. if (spawn && spawn->IsEntity()) {
  2099. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2100. if (spawn->IsPlayer())
  2101. ((Player*)spawn)->SetCharSheetChanged(true);
  2102. }
  2103. return 0;
  2104. }
  2105. int EQ2Emu_lua_SetStr(lua_State* state) {
  2106. if (!lua_interface)
  2107. return 0;
  2108. Spawn* spawn = lua_interface->GetSpawn(state);
  2109. float value = lua_interface->GetFloatValue(state, 2);
  2110. if (spawn && spawn->IsEntity()) {
  2111. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2112. if (spawn->IsPlayer())
  2113. ((Player*)spawn)->SetCharSheetChanged(true);
  2114. }
  2115. return 0;
  2116. }
  2117. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2118. if (!lua_interface)
  2119. return 0;
  2120. Spawn* spawn = lua_interface->GetSpawn(state);
  2121. float value = lua_interface->GetFloatValue(state, 2);
  2122. if (spawn && spawn->IsEntity()) {
  2123. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2124. if (spawn->IsPlayer())
  2125. ((Player*)spawn)->SetCharSheetChanged(true);
  2126. }
  2127. return 0;
  2128. }
  2129. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2130. if (!lua_interface)
  2131. return 0;
  2132. Spawn* spawn = lua_interface->GetSpawn(state);
  2133. if (spawn) {
  2134. lua_interface->SetInt32Value(state, spawn->GetHP());
  2135. return 1;
  2136. }
  2137. return 0;
  2138. }
  2139. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2140. if (!lua_interface)
  2141. return 0;
  2142. Spawn* spawn = lua_interface->GetSpawn(state);
  2143. if (spawn) {
  2144. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2145. return 1;
  2146. }
  2147. return 0;
  2148. }
  2149. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2150. if (!lua_interface)
  2151. return 0;
  2152. Spawn* spawn = lua_interface->GetSpawn(state);
  2153. if (spawn) {
  2154. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2155. return 1;
  2156. }
  2157. return 0;
  2158. }
  2159. int EQ2Emu_lua_GetName(lua_State* state) {
  2160. if (!lua_interface)
  2161. return 0;
  2162. Spawn* spawn = lua_interface->GetSpawn(state);
  2163. if (spawn) {
  2164. lua_interface->SetStringValue(state, spawn->GetName());
  2165. return 1;
  2166. }
  2167. return 0;
  2168. }
  2169. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2170. Spawn* spawn = lua_interface->GetSpawn(state);
  2171. if (spawn) {
  2172. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2173. return 1;
  2174. }
  2175. return 0;
  2176. }
  2177. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2178. if (!lua_interface)
  2179. return 0;
  2180. Spawn* spawn = lua_interface->GetSpawn(state);
  2181. if (spawn) {
  2182. lua_interface->SetInt32Value(state, spawn->GetPower());
  2183. return 1;
  2184. }
  2185. return 0;
  2186. }
  2187. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2188. if (!lua_interface)
  2189. return 0;
  2190. Spawn* spawn = lua_interface->GetSpawn(state);
  2191. if (spawn) {
  2192. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2193. return 1;
  2194. }
  2195. return 0;
  2196. }
  2197. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2198. if (!lua_interface)
  2199. return 0;
  2200. Spawn* spawn = lua_interface->GetSpawn(state);
  2201. if (spawn) {
  2202. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2203. return 1;
  2204. }
  2205. return 0;
  2206. }
  2207. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2208. if (!lua_interface)
  2209. return 0;
  2210. Spawn* spawn = lua_interface->GetSpawn(state);
  2211. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2212. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2213. if (spawn && spawn2) {
  2214. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2215. lua_interface->SetFloatValue(state, distance);
  2216. return 1;
  2217. }
  2218. return 0;
  2219. }
  2220. int EQ2Emu_lua_GetX(lua_State* state) {
  2221. if (!lua_interface)
  2222. return 0;
  2223. Spawn* spawn = lua_interface->GetSpawn(state);
  2224. if (spawn) {
  2225. lua_interface->SetFloatValue(state, spawn->GetX());
  2226. return 1;
  2227. }
  2228. return 0;
  2229. }
  2230. int EQ2Emu_lua_GetY(lua_State* state) {
  2231. if (!lua_interface)
  2232. return 0;
  2233. Spawn* spawn = lua_interface->GetSpawn(state);
  2234. if (spawn) {
  2235. lua_interface->SetFloatValue(state, spawn->GetY());
  2236. return 1;
  2237. }
  2238. return 0;
  2239. }
  2240. int EQ2Emu_lua_GetZ(lua_State* state) {
  2241. if (!lua_interface)
  2242. return 0;
  2243. Spawn* spawn = lua_interface->GetSpawn(state);
  2244. if (spawn) {
  2245. lua_interface->SetFloatValue(state, spawn->GetZ());
  2246. return 1;
  2247. }
  2248. return 0;
  2249. }
  2250. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2251. if (!lua_interface)
  2252. return 0;
  2253. Spawn* spawn = lua_interface->GetSpawn(state);
  2254. if (spawn) {
  2255. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2256. return 1;
  2257. }
  2258. return 0;
  2259. }
  2260. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2261. if (!lua_interface)
  2262. return 0;
  2263. Spawn* spawn = lua_interface->GetSpawn(state);
  2264. if (spawn) {
  2265. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2266. return 1;
  2267. }
  2268. return 0;
  2269. }
  2270. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2271. if (!lua_interface)
  2272. return 0;
  2273. Spawn* spawn = lua_interface->GetSpawn(state);
  2274. if (spawn) {
  2275. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2276. return 1;
  2277. }
  2278. return 0;
  2279. }
  2280. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2281. if (!lua_interface)
  2282. return 0;
  2283. Spawn* spawn = lua_interface->GetSpawn(state);
  2284. if (spawn && spawn->IsEntity()) {
  2285. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2286. return 1;
  2287. }
  2288. return 0;
  2289. }
  2290. int EQ2Emu_lua_GetInt(lua_State* state) {
  2291. if (!lua_interface)
  2292. return 0;
  2293. Spawn* spawn = lua_interface->GetSpawn(state);
  2294. if (spawn && spawn->IsEntity()) {
  2295. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2296. return 1;
  2297. }
  2298. return 0;
  2299. }
  2300. int EQ2Emu_lua_GetWis(lua_State* state) {
  2301. if (!lua_interface)
  2302. return 0;
  2303. Spawn* spawn = lua_interface->GetSpawn(state);
  2304. if (spawn && spawn->IsEntity()) {
  2305. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2306. return 1;
  2307. }
  2308. return 0;
  2309. }
  2310. int EQ2Emu_lua_GetSta(lua_State* state) {
  2311. if (!lua_interface)
  2312. return 0;
  2313. Spawn* spawn = lua_interface->GetSpawn(state);
  2314. if (spawn && spawn->IsEntity()) {
  2315. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2316. return 1;
  2317. }
  2318. return 0;
  2319. }
  2320. int EQ2Emu_lua_GetStr(lua_State* state) {
  2321. if (!lua_interface)
  2322. return 0;
  2323. Spawn* spawn = lua_interface->GetSpawn(state);
  2324. if (spawn && spawn->IsEntity()) {
  2325. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2326. return 1;
  2327. }
  2328. return 0;
  2329. }
  2330. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2331. if (!lua_interface)
  2332. return 0;
  2333. Spawn* spawn = lua_interface->GetSpawn(state);
  2334. if (spawn && spawn->IsEntity()) {
  2335. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2336. return 1;
  2337. }
  2338. return 0;
  2339. }
  2340. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2341. if (!lua_interface)
  2342. return 0;
  2343. Spawn* spawn = lua_interface->GetSpawn(state);
  2344. if (spawn && spawn->IsEntity()) {
  2345. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2346. return 1;
  2347. }
  2348. return 0;
  2349. }
  2350. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2351. if (!lua_interface)
  2352. return 0;
  2353. Spawn* spawn = lua_interface->GetSpawn(state);
  2354. if (spawn && spawn->IsEntity()) {
  2355. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2356. return 1;
  2357. }
  2358. return 0;
  2359. }
  2360. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2361. if (!lua_interface)
  2362. return 0;
  2363. Spawn* spawn = lua_interface->GetSpawn(state);
  2364. if (spawn && spawn->IsEntity()) {
  2365. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2366. return 1;
  2367. }
  2368. return 0;
  2369. }
  2370. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2371. if (!lua_interface)
  2372. return 0;
  2373. Spawn* spawn = lua_interface->GetSpawn(state);
  2374. if (spawn && spawn->IsEntity()) {
  2375. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2376. return 1;
  2377. }
  2378. return 0;
  2379. }
  2380. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2381. if (!lua_interface)
  2382. return 0;
  2383. Spawn* spawn = lua_interface->GetSpawn(state);
  2384. if (spawn && spawn->IsEntity()) {
  2385. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2386. return 1;
  2387. }
  2388. return 0;
  2389. }
  2390. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2391. if (!lua_interface)
  2392. return 0;
  2393. Spawn* player = lua_interface->GetSpawn(state);
  2394. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2395. int32 step = lua_interface->GetInt32Value(state, 3);
  2396. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2397. Client* client = player->GetZone()->GetClientBySpawn(player);
  2398. if (client)
  2399. client->AddPendingQuestUpdate(quest_id, step);
  2400. }
  2401. return 0;
  2402. }
  2403. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2404. Spawn* player = lua_interface->GetSpawn(state);
  2405. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2406. int32 step = lua_interface->GetInt32Value(state, 3);
  2407. int32 progress = lua_interface->GetInt32Value(state, 4);
  2408. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2409. Client* client = player->GetZone()->GetClientBySpawn(player);
  2410. if (client)
  2411. client->AddPendingQuestUpdate(quest_id, step, progress);
  2412. }
  2413. return 0;
  2414. }
  2415. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2416. if (!lua_interface)
  2417. return 0;
  2418. Spawn* player = lua_interface->GetSpawn(state);
  2419. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2420. if (player && player->IsPlayer() && quest_id > 0) {
  2421. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2422. return 1;
  2423. }
  2424. return 0;
  2425. }
  2426. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2427. if (!lua_interface)
  2428. return 0;
  2429. Spawn* player = lua_interface->GetSpawn(state);
  2430. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2431. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2432. if (player && player->IsPlayer() && quest_id > 0) {
  2433. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2434. return 1;
  2435. }
  2436. return 0;
  2437. }
  2438. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2439. if (!lua_interface)
  2440. return 0;
  2441. Spawn* player = lua_interface->GetSpawn(state);
  2442. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2443. if (player && player->IsPlayer() && quest_id > 0) {
  2444. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2445. return 1;
  2446. }
  2447. return 0;
  2448. }
  2449. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2450. if (!lua_interface)
  2451. return 0;
  2452. Quest* quest = lua_interface->GetQuest(state);
  2453. string name = lua_interface->GetStringValue(state, 2);
  2454. string type = lua_interface->GetStringValue(state, 3);
  2455. string zone = lua_interface->GetStringValue(state, 4);
  2456. int16 level = lua_interface->GetInt16Value(state, 5);
  2457. string description = lua_interface->GetStringValue(state, 6);
  2458. bool load = true;
  2459. if (!quest) {
  2460. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2461. load = false;
  2462. }
  2463. if (load && name.length() == 0) {
  2464. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2465. load = false;
  2466. }
  2467. if (load && type.length() == 0) {
  2468. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2469. load = false;
  2470. }
  2471. if (load && zone.length() == 0) {
  2472. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2473. load = false;
  2474. }
  2475. if (load && description.length() == 0) {
  2476. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2477. load = false;
  2478. }
  2479. if (load && level == 0) {
  2480. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2481. load = false;
  2482. }
  2483. if (load)
  2484. quest->RegisterQuest(name, type, zone, level, description);
  2485. return 0;
  2486. }
  2487. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2488. if (!lua_interface)
  2489. return 0;
  2490. Quest* quest = lua_interface->GetQuest(state);
  2491. if (quest) {
  2492. int8 level = lua_interface->GetInt16Value(state, 2);
  2493. quest->SetPrereqLevel(level);
  2494. }
  2495. return 0;
  2496. }
  2497. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2498. if (!lua_interface)
  2499. return 0;
  2500. Quest* quest = lua_interface->GetQuest(state);
  2501. if (quest) {
  2502. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2503. quest->AddPrereqQuest(quest_id);
  2504. }
  2505. return 0;
  2506. }
  2507. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2508. if (!lua_interface)
  2509. return 0;
  2510. Quest* quest = lua_interface->GetQuest(state);
  2511. if (quest) {
  2512. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2513. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2514. if (quantity == 0)
  2515. quantity = 1;
  2516. Item* master_item = master_item_list.GetItem(item_id);
  2517. if (master_item) {
  2518. Item* item = new Item(master_item);
  2519. item->details.count = quantity;
  2520. quest->AddPrereqItem(item);
  2521. }
  2522. }
  2523. return 0;
  2524. }
  2525. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2526. if (!lua_interface)
  2527. return 0;
  2528. Spawn* player = lua_interface->GetSpawn(state);
  2529. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2530. if (player && player->IsPlayer() && quest_id > 0) {
  2531. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2532. return 1;
  2533. }
  2534. return 0;
  2535. }
  2536. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2537. if (!lua_interface)
  2538. return 0;
  2539. Quest* quest = lua_interface->GetQuest(state);
  2540. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2541. if (quest && spawn_id > 0)
  2542. quest->SetQuestReturnNPC(spawn_id);
  2543. return 0;
  2544. }
  2545. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2546. if (!lua_interface)
  2547. return 0;
  2548. Spawn* spawn = lua_interface->GetSpawn(state);
  2549. if (!spawn) {
  2550. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2551. return 0;
  2552. }
  2553. int32 time = lua_interface->GetInt32Value(state, 2);
  2554. if (time <= 0) {
  2555. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2556. return 0;
  2557. }
  2558. string function = lua_interface->GetStringValue(state, 3);
  2559. if (function.length() == 0) {
  2560. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2561. return 0;
  2562. }
  2563. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2564. Spawn* player = lua_interface->GetSpawn(state, 5);
  2565. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2566. timer->timer = Timer::GetCurrentTime2() + time;
  2567. timer->function = function;
  2568. timer->spawn = spawn->GetID();
  2569. timer->player = player ? player->GetID() : 0;
  2570. if (max_count == 0)
  2571. max_count = 1;
  2572. timer->max_count = max_count;
  2573. timer->current_count = 0;
  2574. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2575. return 0;
  2576. }
  2577. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2578. if (!lua_interface)
  2579. return 0;
  2580. Spawn* player = lua_interface->GetSpawn(state);
  2581. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2582. if (player && player->IsPlayer() && quest_id > 0) {
  2583. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2584. return 1;
  2585. }
  2586. return 0;
  2587. }
  2588. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2589. if (!lua_interface)
  2590. return 0;
  2591. Spawn* player = lua_interface->GetSpawn(state);
  2592. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2593. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2594. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2595. if (quest)
  2596. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2597. return 1;
  2598. }
  2599. return 0;
  2600. }
  2601. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2602. if (!lua_interface)
  2603. return 0;
  2604. Spawn* player = lua_interface->GetSpawn(state);
  2605. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2606. if (player && player->IsPlayer() && quest_id > 0) {
  2607. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2608. return 1;
  2609. }
  2610. return 0;
  2611. }
  2612. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2613. if (!lua_interface)
  2614. return 0;
  2615. Spawn* npc = lua_interface->GetSpawn(state);
  2616. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2617. if (npc && !npc->IsPlayer() && quest_id > 0)
  2618. npc->AddProvidedQuest(quest_id);
  2619. return 0;
  2620. }
  2621. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2622. if (!lua_interface)
  2623. return 0;
  2624. Spawn* npc = lua_interface->GetSpawn(state);
  2625. Spawn* player = lua_interface->GetSpawn(state, 2);
  2626. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  2627. /* NPC is allowed to be null */
  2628. if (player && player->IsPlayer() && quest_id > 0) {
  2629. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  2630. if (master_quest) {
  2631. Client* client = player->GetZone()->GetClientBySpawn(player);
  2632. Quest* quest = new Quest(master_quest);
  2633. if (client && quest) {
  2634. client->AddPendingQuest(quest);
  2635. if (npc)
  2636. quest->SetQuestGiver(npc->GetDatabaseID());
  2637. else
  2638. quest->SetQuestGiver(0);
  2639. }
  2640. }
  2641. }
  2642. return 0;
  2643. }
  2644. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  2645. if (!lua_interface)
  2646. return 0;
  2647. Quest* quest = lua_interface->GetQuest(state);
  2648. if (quest) {
  2649. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2650. quest->AddPrereqClass(class_id);
  2651. }
  2652. return 0;
  2653. }
  2654. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  2655. if (!lua_interface)
  2656. return 0;
  2657. Quest* quest = lua_interface->GetQuest(state);
  2658. if (quest) {
  2659. int8 race = lua_interface->GetInt8Value(state, 2);
  2660. quest->AddPrereqRace(race);
  2661. }
  2662. return 0;
  2663. }
  2664. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  2665. if (!lua_interface)
  2666. return 0;
  2667. Quest* quest = lua_interface->GetQuest(state);
  2668. if (quest) {
  2669. int16 model_type = lua_interface->GetInt16Value(state, 2);
  2670. quest->AddPrereqModelType(model_type);
  2671. }
  2672. return 0;
  2673. }
  2674. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  2675. if (!lua_interface)
  2676. return 0;
  2677. Quest* quest = lua_interface->GetQuest(state);
  2678. if (!quest) {
  2679. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  2680. return 0;
  2681. }
  2682. int8 level = lua_interface->GetInt8Value(state, 2);
  2683. quest->SetPrereqTSLevel(level);
  2684. return 0;
  2685. }
  2686. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  2687. if (!lua_interface)
  2688. return 0;
  2689. Quest* quest = lua_interface->GetQuest(state);
  2690. if (!quest) {
  2691. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  2692. return 0;
  2693. }
  2694. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2695. quest->AddPrereqTradeskillClass(class_id);
  2696. return 0;
  2697. }
  2698. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  2699. if (!lua_interface)
  2700. return 0;
  2701. Quest* quest = lua_interface->GetQuest(state);
  2702. if (quest) {
  2703. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2704. sint32 min = lua_interface->GetSInt32Value(state, 3);
  2705. sint32 max = lua_interface->GetSInt32Value(state, 4);
  2706. quest->AddPrereqFaction(faction_id, min, max);
  2707. }
  2708. return 0;
  2709. }
  2710. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  2711. if (!lua_interface)
  2712. return 0;
  2713. Quest* quest = lua_interface->GetQuest(state);
  2714. if (quest) {
  2715. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2716. int8 quantity = lua_interface->GetInt8Value(state, 3);
  2717. if (quantity == 0)
  2718. quantity = 1;
  2719. Item* master_item = master_item_list.GetItem(item_id);
  2720. if (master_item) {
  2721. Item* item = new Item(master_item);
  2722. item->details.count = quantity;
  2723. quest->AddSelectableRewardItem(item);
  2724. }
  2725. }
  2726. return 0;
  2727. }
  2728. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  2729. if (!lua_interface)
  2730. return 0;
  2731. Quest* quest = lua_interface->GetQuest(state);
  2732. if (quest) {
  2733. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2734. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2735. if (quantity == 0)
  2736. quantity = 1;
  2737. Item* master_item = master_item_list.GetItem(item_id);
  2738. if (master_item) {
  2739. Item* item = new Item(master_item);
  2740. item->details.count = quantity;
  2741. quest->AddRewardItem(item);
  2742. }
  2743. }
  2744. return 0;
  2745. }
  2746. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  2747. if (!lua_interface)
  2748. return 0;
  2749. Quest* quest = lua_interface->GetQuest(state);
  2750. if (quest) {
  2751. int32 copper = lua_interface->GetInt32Value(state, 2);
  2752. int32 silver = lua_interface->GetInt32Value(state, 3);
  2753. int32 gold = lua_interface->GetInt32Value(state, 4);
  2754. int32 plat = lua_interface->GetInt32Value(state, 5);
  2755. quest->AddRewardCoins(copper, silver, gold, plat);
  2756. }
  2757. return 0;
  2758. }
  2759. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  2760. if (!lua_interface)
  2761. return 0;
  2762. Quest* quest = lua_interface->GetQuest(state);
  2763. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2764. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  2765. if (quest && faction_id > 0 && amount != 0)
  2766. quest->AddRewardFaction(faction_id, amount);
  2767. return 0;
  2768. }
  2769. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  2770. if (!lua_interface)
  2771. return 0;
  2772. Quest* quest = lua_interface->GetQuest(state);
  2773. if (quest) {
  2774. int32 status = lua_interface->GetInt32Value(state, 2);
  2775. quest->SetRewardStatus(status);
  2776. }
  2777. return 0;
  2778. }
  2779. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  2780. if (!lua_interface)
  2781. return 0;
  2782. Quest* quest = lua_interface->GetQuest(state);
  2783. if (quest) {
  2784. string comment = lua_interface->GetStringValue(state, 2);
  2785. quest->SetRewardComment(comment);
  2786. }
  2787. return 0;
  2788. }
  2789. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  2790. if (!lua_interface)
  2791. return 0;
  2792. Quest* quest = lua_interface->GetQuest(state);
  2793. if (quest) {
  2794. int32 exp = lua_interface->GetInt32Value(state, 2);
  2795. quest->SetRewardXP(exp);
  2796. }
  2797. return 0;
  2798. }
  2799. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  2800. Quest* quest = lua_interface->GetQuest(state);
  2801. if (quest) {
  2802. int32 step = lua_interface->GetInt32Value(state, 2);
  2803. string description = lua_interface->GetStringValue(state, 3);
  2804. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2805. float percentage = lua_interface->GetFloatValue(state, 5);
  2806. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2807. int16 icon = lua_interface->GetInt16Value(state, 7);
  2808. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  2809. const char* taskgroup = 0;
  2810. if (str_taskgroup.length() > 0)
  2811. taskgroup = str_taskgroup.c_str();
  2812. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  2813. if (quest_step && icon && quantity > 0)
  2814. quest_step->SetIcon(icon);
  2815. }
  2816. return 0;
  2817. }
  2818. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  2819. if (!lua_interface)
  2820. return 0;
  2821. Quest* quest = lua_interface->GetQuest(state);
  2822. if (quest) {
  2823. int32 step = lua_interface->GetInt32Value(state, 2);
  2824. string description = lua_interface->GetStringValue(state, 3);
  2825. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2826. float percentage = lua_interface->GetFloatValue(state, 5);
  2827. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2828. int16 icon = lua_interface->GetInt16Value(state, 7);
  2829. const char* taskgroup = 0;
  2830. if (str_taskgroup.length() > 0)
  2831. taskgroup = str_taskgroup.c_str();
  2832. int32 npc_id = 0;
  2833. vector<int32>* ids = 0;
  2834. Spawn* spawn = nullptr;
  2835. int i = 0;
  2836. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2837. if (ids == 0)
  2838. ids = new vector<int32>;
  2839. ids->push_back(npc_id);
  2840. i++;
  2841. }
  2842. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2843. if (quest_step && icon > 0 && quantity > 0)
  2844. quest_step->SetIcon(icon);
  2845. }
  2846. return 0;
  2847. }
  2848. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  2849. if (!lua_interface)
  2850. return 0;
  2851. Quest* quest = lua_interface->GetQuest(state);
  2852. if (quest) {
  2853. int32 step = lua_interface->GetInt32Value(state, 2);
  2854. string description = lua_interface->GetStringValue(state, 3);
  2855. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2856. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2857. int16 icon = lua_interface->GetInt16Value(state, 6);
  2858. const char* taskgroup = 0;
  2859. if (str_taskgroup.length() > 0)
  2860. taskgroup = str_taskgroup.c_str();
  2861. int32 npc_id = 0;
  2862. vector<int32>* ids = 0;
  2863. int i = 0;
  2864. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  2865. if (ids == 0)
  2866. ids = new vector<int32>;
  2867. ids->push_back(npc_id);
  2868. i++;
  2869. }
  2870. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  2871. if (quest_step && icon > 0)
  2872. quest_step->SetIcon(icon);
  2873. if (quest->GetPlayer()) {
  2874. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  2875. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  2876. }
  2877. }
  2878. return 0;
  2879. }
  2880. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  2881. if (!lua_interface)
  2882. return 0;
  2883. Quest* quest = lua_interface->GetQuest(state);
  2884. if (quest) {
  2885. int32 step = lua_interface->GetInt32Value(state, 2);
  2886. string description = lua_interface->GetStringValue(state, 3);
  2887. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2888. float percentage = lua_interface->GetFloatValue(state, 5);
  2889. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2890. int16 icon = lua_interface->GetInt16Value(state, 7);
  2891. const char* taskgroup = 0;
  2892. if (str_taskgroup.length() > 0)
  2893. taskgroup = str_taskgroup.c_str();
  2894. int32 item_id = 0;
  2895. vector<int32>* ids = 0;
  2896. int i = 0;
  2897. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2898. if (ids == 0)
  2899. ids = new vector<int32>;
  2900. ids->push_back(item_id);
  2901. i++;
  2902. }
  2903. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2904. if (quest_step && icon > 0 && quantity > 0)
  2905. quest_step->SetIcon(icon);
  2906. }
  2907. return 0;
  2908. }
  2909. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  2910. if (!lua_interface)
  2911. return 0;
  2912. Quest* quest = lua_interface->GetQuest(state);
  2913. if (quest) {
  2914. int32 step = lua_interface->GetInt32Value(state, 2);
  2915. string description = lua_interface->GetStringValue(state, 3);
  2916. float max_variation = lua_interface->GetFloatValue(state, 4);
  2917. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2918. int16 icon = lua_interface->GetInt16Value(state, 6);
  2919. const char* taskgroup = 0;
  2920. if (str_taskgroup.length() > 0)
  2921. taskgroup = str_taskgroup.c_str();
  2922. vector<Location>* locations = 0;
  2923. int i = 7;
  2924. while (true) {
  2925. Location loc;
  2926. loc.x = lua_interface->GetFloatValue(state, i);
  2927. loc.y = lua_interface->GetFloatValue(state, i + 1);
  2928. loc.z = lua_interface->GetFloatValue(state, i + 2);
  2929. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  2930. break;
  2931. if (locations == 0)
  2932. locations = new vector<Location>;
  2933. locations->push_back(loc);
  2934. i += 3;
  2935. }
  2936. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  2937. if (quest_step && icon > 0)
  2938. quest_step->SetIcon(icon);
  2939. }
  2940. return 0;
  2941. }
  2942. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  2943. if (!lua_interface)
  2944. return 0;
  2945. Quest* quest = lua_interface->GetQuest(state);
  2946. if (quest) {
  2947. int32 step = lua_interface->GetInt32Value(state, 2);
  2948. string description = lua_interface->GetStringValue(state, 3);
  2949. float max_variation = lua_interface->GetFloatValue(state, 4);
  2950. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2951. int16 icon = lua_interface->GetInt16Value(state, 6);
  2952. const char* taskgroup = 0;
  2953. if (str_taskgroup.length() > 0)
  2954. taskgroup = str_taskgroup.c_str();
  2955. vector<Location>* locations = 0;
  2956. int i = 7;
  2957. while (true) {
  2958. Location loc;
  2959. loc.x = lua_interface->GetFloatValue(state, i);
  2960. loc.y = lua_interface->GetFloatValue(state, i + 1);
  2961. loc.z = lua_interface->GetFloatValue(state, i + 2);
  2962. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  2963. break;
  2964. if (locations == 0)
  2965. locations = new vector<Location>;
  2966. locations->push_back(loc);
  2967. i += 3;
  2968. }
  2969. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  2970. if (quest_step && icon > 0)
  2971. quest_step->SetIcon(icon);
  2972. }
  2973. return 0;
  2974. }
  2975. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  2976. Quest* quest = lua_interface->GetQuest(state);
  2977. if (quest) {
  2978. int32 step = lua_interface->GetInt32Value(state, 2);
  2979. string description = lua_interface->GetStringValue(state, 3);
  2980. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2981. float percentage = lua_interface->GetFloatValue(state, 5);
  2982. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2983. int16 icon = lua_interface->GetInt16Value(state, 7);
  2984. const char* taskgroup = 0;
  2985. if (str_taskgroup.length() > 0)
  2986. taskgroup = str_taskgroup.c_str();
  2987. int32 spell_id = 0;
  2988. vector<int32>* ids = 0;
  2989. int i = 0;
  2990. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2991. if (ids == 0)
  2992. ids = new vector<int32>;
  2993. ids->push_back(spell_id);
  2994. i++;
  2995. }
  2996. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2997. if (quest_step && icon > 0 && quantity > 0)
  2998. quest_step->SetIcon(icon);
  2999. }
  3000. return 0;
  3001. }
  3002. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3003. if (!lua_interface)
  3004. return 0;
  3005. Quest* quest = lua_interface->GetQuest(state);
  3006. if (quest) {
  3007. int32 step = lua_interface->GetInt32Value(state, 2);
  3008. string description = lua_interface->GetStringValue(state, 3);
  3009. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3010. float percentage = lua_interface->GetFloatValue(state, 5);
  3011. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3012. int16 icon = lua_interface->GetInt16Value(state, 7);
  3013. const char* taskgroup = 0;
  3014. if (str_taskgroup.length() > 0)
  3015. taskgroup = str_taskgroup.c_str();
  3016. int32 item_id = 0;
  3017. vector<int32>* ids = 0;
  3018. int i = 0;
  3019. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3020. if (ids == 0)
  3021. ids = new vector<int32>;
  3022. ids->push_back(item_id);
  3023. i++;
  3024. }
  3025. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3026. if (quest_step && icon > 0 && quantity > 0)
  3027. quest_step->SetIcon(icon);
  3028. }
  3029. return 0;
  3030. }
  3031. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3032. if (!lua_interface)
  3033. return 0;
  3034. Quest* quest = lua_interface->GetQuest(state);
  3035. if (quest) {
  3036. int32 step = lua_interface->GetInt32Value(state, 2);
  3037. string description = lua_interface->GetStringValue(state, 3);
  3038. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3039. float percentage = lua_interface->GetFloatValue(state, 5);
  3040. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3041. int16 icon = lua_interface->GetInt16Value(state, 7);
  3042. const char* taskgroup = 0;
  3043. if (str_taskgroup.length() > 0)
  3044. taskgroup = str_taskgroup.c_str();
  3045. int32 item_id = 0;
  3046. vector<int32>* ids = 0;
  3047. int i = 0;
  3048. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3049. if (ids == 0)
  3050. ids = new vector<int32>;
  3051. ids->push_back(item_id);
  3052. i++;
  3053. }
  3054. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3055. if (quest_step && icon > 0 && quantity > 0)
  3056. quest_step->SetIcon(icon);
  3057. }
  3058. return 0;
  3059. }
  3060. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3061. if (!lua_interface)
  3062. return 0;
  3063. Quest* quest = lua_interface->GetQuest(state);
  3064. if (quest) {
  3065. string action = lua_interface->GetStringValue(state, 2);
  3066. if (action.length() > 0)
  3067. quest->SetCompleteAction(action);
  3068. }
  3069. return 0;
  3070. }
  3071. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3072. if (!lua_interface)
  3073. return 0;
  3074. Quest* quest = lua_interface->GetQuest(state);
  3075. if (quest) {
  3076. int32 step = lua_interface->GetInt32Value(state, 2);
  3077. string action = lua_interface->GetStringValue(state, 3);
  3078. if (step > 0 && action.length() > 0)
  3079. quest->AddCompleteAction(step, action);
  3080. }
  3081. return 0;
  3082. }
  3083. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3084. if (!lua_interface)
  3085. return 0;
  3086. Quest* quest = lua_interface->GetQuest(state);
  3087. if (quest) {
  3088. int32 step = lua_interface->GetInt32Value(state, 2);
  3089. string action = lua_interface->GetStringValue(state, 3);
  3090. if (step > 0 && action.length() > 0)
  3091. quest->AddProgressAction(step, action);
  3092. }
  3093. return 0;
  3094. }
  3095. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3096. if (!lua_interface)
  3097. return 0;
  3098. Quest* quest = lua_interface->GetQuest(state);
  3099. string description = lua_interface->GetStringValue(state, 2);
  3100. if (quest && description.length() > 0)
  3101. quest->SetDescription(description);
  3102. return 0;
  3103. }
  3104. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3105. if (!lua_interface)
  3106. return 0;
  3107. Quest* quest = lua_interface->GetQuest(state);
  3108. string description = lua_interface->GetStringValue(state, 2);
  3109. if (quest && description.length() > 0)
  3110. quest->SetCompletedDescription(description);
  3111. return 0;
  3112. }
  3113. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3114. if (!lua_interface)
  3115. return 0;
  3116. Quest* quest = lua_interface->GetQuest(state);
  3117. int32 step = lua_interface->GetInt32Value(state, 2);
  3118. string description = lua_interface->GetStringValue(state, 3);
  3119. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3120. if (quest && step > 0 && description.length() > 0) {
  3121. quest->SetTaskGroupDescription(step, description, display_bullets);
  3122. if (quest->GetPlayer()) {
  3123. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3124. if (client)
  3125. client->SendQuestUpdateStep(quest, step, false);
  3126. }
  3127. }
  3128. return 0;
  3129. }
  3130. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3131. if (!lua_interface)
  3132. return 0;
  3133. Quest* quest = lua_interface->GetQuest(state);
  3134. int32 step = lua_interface->GetInt32Value(state, 2);
  3135. string description = lua_interface->GetStringValue(state, 3);
  3136. if (quest && step > 0 && description.length() > 0) {
  3137. quest->SetStepDescription(step, description);
  3138. if (quest->GetPlayer()) {
  3139. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3140. if (client)
  3141. client->SendQuestUpdateStep(quest, step);
  3142. }
  3143. }
  3144. return 0;
  3145. }
  3146. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3147. Quest* quest = lua_interface->GetQuest(state);
  3148. string zone = lua_interface->GetStringValue(state, 2);
  3149. if (quest && zone.length() > 0)
  3150. quest->SetZone(zone);
  3151. return 0;
  3152. }
  3153. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3154. if (!lua_interface)
  3155. return 0;
  3156. Quest* quest = lua_interface->GetQuest(state);
  3157. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3158. if (quest && spawn) {
  3159. if (spawn->IsPlayer()) {
  3160. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3161. if (client)
  3162. client->AddPendingQuestReward(quest);
  3163. }
  3164. }
  3165. return 0;
  3166. }
  3167. int EQ2Emu_lua_Harvest(lua_State* state) {
  3168. if (!lua_interface)
  3169. return 0;
  3170. Spawn* player = lua_interface->GetSpawn(state);
  3171. Spawn* node = lua_interface->GetSpawn(state, 2);
  3172. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3173. Client* client = player->GetZone()->GetClientBySpawn(player);
  3174. if (client) {
  3175. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3176. ((GroundSpawn*)node)->ProcessHarvest(client);
  3177. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3178. player->GetZone()->RemoveSpawn(true, node, true);
  3179. }
  3180. }
  3181. else if (player && player->IsPlayer()) {
  3182. Client* client = player->GetZone()->GetClientBySpawn(player);
  3183. if (client)
  3184. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3185. }
  3186. return 0;
  3187. }
  3188. int EQ2Emu_lua_Bind(lua_State* state) {
  3189. if (!lua_interface)
  3190. return 0;
  3191. Spawn* spawn = lua_interface->GetSpawn(state);
  3192. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3193. float x = lua_interface->GetFloatValue(state, 3);
  3194. float y = lua_interface->GetFloatValue(state, 4);
  3195. float z = lua_interface->GetFloatValue(state, 5);
  3196. float h = lua_interface->GetFloatValue(state, 6);
  3197. if (!spawn) {
  3198. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3199. return 0;
  3200. }
  3201. if (!spawn->IsPlayer()) {
  3202. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3203. return 0;
  3204. }
  3205. if (zone_id == 0) {
  3206. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3207. if (!client) {
  3208. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3209. return 0;
  3210. }
  3211. if (!client->Bind())
  3212. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3213. }
  3214. else {
  3215. Player* player = (Player*)spawn;
  3216. player->GetPlayerInfo()->SetBindZone(zone_id);
  3217. player->GetPlayerInfo()->SetBindX(x);
  3218. player->GetPlayerInfo()->SetBindY(y);
  3219. player->GetPlayerInfo()->SetBindZ(z);
  3220. player->GetPlayerInfo()->SetBindHeading(h);
  3221. }
  3222. return 0;
  3223. }
  3224. int EQ2Emu_lua_Gate(lua_State* state) {
  3225. if (!lua_interface)
  3226. return 0;
  3227. Spawn* spawn = lua_interface->GetSpawn(state);
  3228. if (spawn) {
  3229. if (spawn->IsPlayer()) {
  3230. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3231. if (client) {
  3232. if (!client->Gate())
  3233. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3234. }
  3235. }
  3236. }
  3237. return 0;
  3238. }
  3239. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3240. if (!lua_interface)
  3241. return 0;
  3242. bool ret = false;
  3243. Spawn* spawn = lua_interface->GetSpawn(state);
  3244. if (spawn) {
  3245. if (spawn->IsPlayer()) {
  3246. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3247. if (client)
  3248. ret = client->BindAllowed();
  3249. }
  3250. }
  3251. lua_interface->SetBooleanValue(state, ret);
  3252. return 1;
  3253. }
  3254. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3255. if (!lua_interface)
  3256. return 0;
  3257. bool ret = false;
  3258. Spawn* spawn = lua_interface->GetSpawn(state);
  3259. if (spawn) {
  3260. if (spawn->IsPlayer()) {
  3261. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3262. if (client)
  3263. ret = client->GateAllowed();
  3264. }
  3265. }
  3266. lua_interface->SetBooleanValue(state, ret);
  3267. return 1;
  3268. }
  3269. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3270. Spawn* spawn = lua_interface->GetSpawn(state);
  3271. if (spawn) {
  3272. lua_interface->SetBooleanValue(state, spawn->Alive());
  3273. return 1;
  3274. }
  3275. return 0;
  3276. }
  3277. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3278. if (!lua_interface)
  3279. return 0;
  3280. Spawn* spawn = lua_interface->GetSpawn(state);
  3281. if (spawn && spawn->IsEntity()) {
  3282. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3283. return 1;
  3284. }
  3285. return 0;
  3286. }
  3287. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3288. Spawn* spawn = lua_interface->GetSpawn(state);
  3289. string message = lua_interface->GetStringValue(state, 2);
  3290. string color_str = lua_interface->GetStringValue(state, 3);
  3291. int8 color = CHANNEL_COLOR_WHITE;
  3292. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3293. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3294. if (client) {
  3295. if (color_str.length() > 0) {
  3296. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3297. color = CHANNEL_COLOR_RED;
  3298. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3299. color = CHANNEL_COLOR_YELLOW;
  3300. }
  3301. client->SimpleMessage(color, message.c_str());
  3302. }
  3303. }
  3304. return 0;
  3305. }
  3306. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3307. Spawn* spawn = lua_interface->GetSpawn(state);
  3308. string message = lua_interface->GetStringValue(state, 2);
  3309. int8 red = lua_interface->GetInt8Value(state, 3);
  3310. int8 green = lua_interface->GetInt8Value(state, 4);
  3311. int8 blue = lua_interface->GetInt8Value(state, 5);
  3312. if (!spawn) {
  3313. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3314. return 0;
  3315. }
  3316. int32 words = ::CountWordsInString(message.c_str());
  3317. if (words < 5)
  3318. words = 5;
  3319. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3320. if (client)
  3321. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3322. return 0;
  3323. }
  3324. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3325. Spawn* spawn = lua_interface->GetSpawn(state);
  3326. int8 param = lua_interface->GetInt8Value(state, 2);
  3327. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3328. int8 value = lua_interface->GetInt8Value(state, 4);
  3329. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3330. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3331. if (client) {
  3332. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3333. switch (param) {
  3334. case 1: {
  3335. packet->setDataByName("parameter1", param_value);
  3336. break;
  3337. }
  3338. case 2: {
  3339. packet->setDataByName("parameter2", param_value);
  3340. break;
  3341. }
  3342. case 3: {
  3343. packet->setDataByName("parameter3", param_value);
  3344. break;
  3345. }
  3346. case 4: {
  3347. packet->setDataByName("parameter4", param_value);
  3348. break;
  3349. }
  3350. case 5: {
  3351. packet->setDataByName("parameter5", param_value);
  3352. break;
  3353. }
  3354. }
  3355. packet->setDataByName("value", value);
  3356. client->QueuePacket(packet->serialize());
  3357. safe_delete(packet);
  3358. }
  3359. }
  3360. return 0;
  3361. }
  3362. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3363. Spawn* spawn = lua_interface->GetSpawn(state);
  3364. if (spawn && spawn->IsPlayer()) {
  3365. if (((Player*)spawn)->GetIsTracking())
  3366. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3367. else
  3368. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3369. }
  3370. return 0;
  3371. }
  3372. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3373. Spawn* player = lua_interface->GetSpawn(state);
  3374. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3375. string name = lua_interface->GetStringValue(state, 3);
  3376. float distance = lua_interface->GetFloatValue(state, 4);
  3377. string command = lua_interface->GetStringValue(state, 5);
  3378. string error_text = lua_interface->GetStringValue(state, 6);
  3379. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3380. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3381. if (spawn && player && player->IsPlayer() && name.length() > 0) {
  3382. if (distance == 0)
  3383. distance = 10.0f;
  3384. if (command.length() == 0)
  3385. command = name;
  3386. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  3387. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3388. }
  3389. return 0;
  3390. }
  3391. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3392. if (!lua_interface)
  3393. return 0;
  3394. Spawn* player = lua_interface->GetSpawn(state);
  3395. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3396. int16 tier = lua_interface->GetInt16Value(state, 3);
  3397. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3398. if (player && spell && player->IsPlayer()) {
  3399. Client* client = player->GetZone()->GetClientBySpawn(player);
  3400. if (client) {
  3401. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3402. {
  3403. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3404. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3405. client->GetPlayer()->UnlockSpell(spell);
  3406. client->SendSpellUpdate(spell);
  3407. }
  3408. else
  3409. {
  3410. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3411. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3412. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3413. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3414. client->GetPlayer()->UnlockSpell(spell);
  3415. client->SendSpellUpdate(spell);
  3416. }
  3417. //if (client ) {
  3418. // ((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);
  3419. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3420. if (outapp)
  3421. client->QueuePacket(outapp);
  3422. }
  3423. }
  3424. return 0;
  3425. }
  3426. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3427. if (!lua_interface)
  3428. return 0;
  3429. Spawn* player = lua_interface->GetSpawn(state);
  3430. if (player && player->IsPlayer()) {
  3431. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3432. return 1;
  3433. }
  3434. return 0;
  3435. }
  3436. int EQ2Emu_lua_Attack(lua_State* state) {
  3437. if (lua_interface) {
  3438. Spawn* npc = lua_interface->GetSpawn(state);
  3439. Spawn* player = lua_interface->GetSpawn(state, 2);
  3440. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3441. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3442. }
  3443. return 0;
  3444. }
  3445. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3446. if (lua_interface) {
  3447. Spawn* target = lua_interface->GetSpawn(state);
  3448. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3449. if (target && target->GetZone())
  3450. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3451. }
  3452. return 0;
  3453. }
  3454. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3455. Spawn* player;
  3456. if (lua_interface) {
  3457. player = lua_interface->GetSpawn(state);
  3458. if (player && player->IsPlayer()) {
  3459. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3460. return 1;
  3461. }
  3462. }
  3463. return 0;
  3464. }
  3465. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3466. Spawn* player;
  3467. Client* client;
  3468. if (lua_interface) {
  3469. player = lua_interface->GetSpawn(state);
  3470. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3471. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3472. client->HandInCollections();
  3473. }
  3474. return 0;
  3475. }
  3476. int EQ2Emu_lua_UseWidget(lua_State* state) {
  3477. Spawn* widget;
  3478. if (lua_interface) {
  3479. widget = lua_interface->GetSpawn(state);
  3480. if (widget && widget->IsWidget())
  3481. ((Widget*)widget)->HandleUse(NULL, "");
  3482. }
  3483. return 0;
  3484. }
  3485. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  3486. Spawn* spawn = 0;
  3487. int32 primary_list = 0;
  3488. int32 secondary_list = 0;
  3489. if (lua_interface) {
  3490. spawn = lua_interface->GetSpawn(state);
  3491. primary_list = lua_interface->GetInt32Value(state, 2);
  3492. secondary_list = lua_interface->GetInt32Value(state, 3);
  3493. if (!spawn->IsNPC()) {
  3494. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  3495. return 0;
  3496. }
  3497. NPC* npc = (NPC*)spawn;
  3498. npc->SetPrimarySpellList(primary_list);
  3499. npc->SetSecondarySpellList(secondary_list);
  3500. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  3501. }
  3502. return 0;
  3503. }
  3504. int EQ2Emu_lua_GetPet(lua_State* state) {
  3505. if (!lua_interface)
  3506. return 0;
  3507. Spawn* spawn = lua_interface->GetSpawn(state);
  3508. if (spawn) {
  3509. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  3510. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  3511. return 1;
  3512. }
  3513. }
  3514. return 0;
  3515. }
  3516. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  3517. if (!lua_interface)
  3518. return 0;
  3519. Spawn* spawn = lua_interface->GetSpawn(state);
  3520. if (spawn) {
  3521. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  3522. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  3523. return 1;
  3524. }
  3525. }
  3526. return 0;
  3527. }
  3528. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  3529. if (!lua_interface)
  3530. return 0;
  3531. Spawn* spawn = lua_interface->GetSpawn(state);
  3532. if (spawn) {
  3533. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  3534. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  3535. return 1;
  3536. }
  3537. }
  3538. return 0;
  3539. }
  3540. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  3541. if (!lua_interface)
  3542. return 0;
  3543. Spawn* spawn = lua_interface->GetSpawn(state);
  3544. if (spawn) {
  3545. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  3546. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  3547. return 1;
  3548. }
  3549. }
  3550. return 0;
  3551. }
  3552. int EQ2Emu_lua_Charm(lua_State* state) {
  3553. if (!lua_interface)
  3554. return 0;
  3555. Spawn* owner = lua_interface->GetSpawn(state);
  3556. Spawn* pet = lua_interface->GetSpawn(state, 2);
  3557. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3558. if (!luaspell) {
  3559. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  3560. return 0;
  3561. }
  3562. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  3563. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  3564. pet->SetPet(true);
  3565. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  3566. ((NPC*)pet)->SetOwner((Entity*)owner);
  3567. // If owner is player and player does not have a summoned pet set the players charsheet
  3568. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  3569. Player* player = (Player*)owner;
  3570. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3571. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  3572. player->GetInfoStruct()->pet_movement = 2;
  3573. player->GetInfoStruct()->pet_behavior = 3;
  3574. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3575. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3576. // Make sure the values get sent to the client
  3577. player->SetCharSheetChanged(true);
  3578. }
  3579. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  3580. pet->SetSpawnScript("");
  3581. // Set faction to the same as the owner
  3582. pet->SetFactionID(owner->GetFactionID());
  3583. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3584. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3585. // Clear hate list
  3586. ((NPC*)pet)->Brain()->ClearHate();
  3587. // Set the brain to a pet brain
  3588. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  3589. }
  3590. return 0;
  3591. }
  3592. int EQ2Emu_lua_GetGroup(lua_State* state) {
  3593. if (!lua_interface)
  3594. return 0;
  3595. Spawn* spawn = lua_interface->GetSpawn(state);
  3596. if (!spawn) {
  3597. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  3598. return 0;
  3599. }
  3600. vector<Spawn*> groupMembers;
  3601. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  3602. groupMembers = *spawn->GetSpawnGroup();
  3603. }
  3604. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  3605. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  3606. deque<GroupMemberInfo*>::iterator itr;
  3607. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  3608. GroupMemberInfo* info = 0;
  3609. for (itr = members->begin(); itr != members->end(); itr++) {
  3610. info = *itr;
  3611. if (info->client)
  3612. groupMembers.push_back(info->client->GetPlayer());
  3613. }
  3614. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  3615. }
  3616. else
  3617. return 0;
  3618. lua_createtable(state, groupMembers.size(), 0);
  3619. int newTable = lua_gettop(state);
  3620. for (int32 i = 0; i < groupMembers.size(); i++) {
  3621. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  3622. lua_rawseti(state, newTable, i + 1);
  3623. }
  3624. return 1;
  3625. }
  3626. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  3627. if (!lua_interface)
  3628. return 0;
  3629. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  3630. lua_interface->SetOptionWindowValue(state, option_window);
  3631. return 1;
  3632. }
  3633. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  3634. if (!lua_interface)
  3635. return 0;
  3636. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  3637. if (option_window) {
  3638. OptionWindowOption option_window_option;
  3639. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  3640. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  3641. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  3642. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  3643. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  3644. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  3645. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  3646. option_window->push_back(option_window_option);
  3647. }
  3648. return 0;
  3649. }
  3650. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  3651. if (!lua_interface)
  3652. return 0;
  3653. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  3654. Spawn* player = lua_interface->GetSpawn(state, 2);
  3655. string window_title = lua_interface->GetStringValue(state, 3);
  3656. string cancel_command = lua_interface->GetStringValue(state, 4);
  3657. Client* client = player->GetZone()->GetClientBySpawn(player);
  3658. if (option_window && window_title.length() > 0 && client) {
  3659. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  3660. if (!packet)
  3661. return 0;
  3662. packet->setDataByName("title_text", window_title.c_str());
  3663. if (cancel_command.length() > 0)
  3664. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  3665. packet->setArrayLengthByName("num_selections", option_window->size());
  3666. vector<OptionWindowOption>::iterator itr;
  3667. int8 i = 0;
  3668. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  3669. OptionWindowOption opt = *itr;
  3670. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  3671. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  3672. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  3673. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  3674. if (opt.optionCommand.length() > 0)
  3675. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  3676. if (opt.optionConfirmTitle.length() > 0)
  3677. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  3678. i++;
  3679. }
  3680. client->QueuePacket(packet->serialize());
  3681. safe_delete(option_window);
  3682. safe_delete(packet);
  3683. }
  3684. return 0;
  3685. }
  3686. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  3687. if (!lua_interface)
  3688. return 0;
  3689. Spawn* spawn = lua_interface->GetSpawn(state);
  3690. if (spawn) {
  3691. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  3692. return 1;
  3693. }
  3694. else
  3695. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3696. return 0;
  3697. }
  3698. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  3699. if (!lua_interface)
  3700. return 0;
  3701. Spawn* spawn = lua_interface->GetSpawn(state);
  3702. if (spawn) {
  3703. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  3704. return 1;
  3705. }
  3706. else
  3707. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  3708. return 0;
  3709. }
  3710. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  3711. if (!lua_interface)
  3712. return 0;
  3713. Spawn* spawn = lua_interface->GetSpawn(state);
  3714. if (spawn) {
  3715. int8 class_id = spawn->GetTradeskillClass();
  3716. // Need to add 42 for the offset in the array
  3717. class_id += 44;
  3718. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  3719. return 1;
  3720. }
  3721. else
  3722. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3723. return 0;
  3724. }
  3725. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  3726. if (!lua_interface)
  3727. return 0;
  3728. Spawn* spawn = lua_interface->GetSpawn(state);
  3729. int16 level = lua_interface->GetInt8Value(state, 2);
  3730. if (spawn) {
  3731. if (spawn->IsPlayer())
  3732. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  3733. else
  3734. spawn->SetTSLevel(level);
  3735. }
  3736. else
  3737. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3738. return 0;
  3739. }
  3740. int EQ2Emu_lua_SummonPet(lua_State* state) {
  3741. // Check to see if we have a valid lua_interface
  3742. if (!lua_interface)
  3743. return 0;
  3744. // Get the spawn that is getting the pet
  3745. Spawn* spawn = lua_interface->GetSpawn(state);
  3746. // Get the DB ID of the pet
  3747. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3748. // The max level the pet can gain
  3749. int8 max_level = lua_interface->GetInt8Value(state, 3);
  3750. // Get the spell that this command was called from
  3751. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3752. // Check to make sure the spawn pointer is valid
  3753. if (!spawn) {
  3754. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3755. return 0;
  3756. }
  3757. // Check to make sure the spawn is an entity
  3758. if (!spawn->IsEntity()) {
  3759. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3760. return 0;
  3761. }
  3762. // Check to make sure the spawn doesn't already have a pet of this type
  3763. if (((Entity*)spawn)->GetPet()) {
  3764. if (spawn->IsPlayer()) {
  3765. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3766. if (client)
  3767. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  3768. }
  3769. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3770. return 0;
  3771. }
  3772. // Check to see if the DB ID for the pet is set
  3773. if (pet_id == 0) {
  3774. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3775. return 0;
  3776. }
  3777. // Check to see if the pointer to the spell is valid
  3778. if (!luaspell) {
  3779. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3780. return 0;
  3781. }
  3782. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  3783. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3784. if (!pet) {
  3785. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3786. return 0;
  3787. }
  3788. // Check to make sure the pet is an npc
  3789. if (!pet->IsNPC()) {
  3790. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  3791. return 0;
  3792. }
  3793. // Spawn the pet at the same location as the owner
  3794. pet->SetX(spawn->GetX());
  3795. pet->SetY(spawn->GetY());
  3796. pet->SetZ(spawn->GetZ());
  3797. pet->SetLocation(spawn->GetLocation());
  3798. pet->SetHeading(spawn->GetHeading());
  3799. spawn->GetZone()->AddSpawn(pet);
  3800. /*
  3801. const char* spawn_script = world.GetSpawnScript(pet_id);
  3802. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  3803. spawn->SetSpawnScript(string(spawn_script));
  3804. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  3805. }*/
  3806. // Get a random pet name
  3807. string random_pet_name;
  3808. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3809. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3810. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3811. // If player set various values for the char sheet (pet window)
  3812. if (spawn->IsPlayer()) {
  3813. Player* player = (Player*)spawn;
  3814. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3815. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  3816. player->GetInfoStruct()->pet_movement = 2;
  3817. player->GetInfoStruct()->pet_behavior = 3;
  3818. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3819. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3820. // Make sure the values get sent to the client
  3821. player->SetCharSheetChanged(true);
  3822. }
  3823. // Set the pets name
  3824. pet->SetName(random_pet_name.c_str());
  3825. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  3826. if (max_level > 0)
  3827. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  3828. else
  3829. pet->SetLevel(spawn->GetLevel());
  3830. // Set the max level this pet can reach
  3831. ((NPC*)pet)->SetMaxPetLevel(max_level);
  3832. // Set the faction of the pet to the same faction as the owner
  3833. pet->SetFactionID(spawn->GetFactionID());
  3834. // Set the spawn as a pet
  3835. pet->SetPet(true);
  3836. // Give a pointer of the owner to the pet
  3837. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3838. // Give a pointer of the pet to the owner
  3839. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  3840. // Set the pet type
  3841. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  3842. // Set the spell id used to create this pet
  3843. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3844. // Set the spell tier used to create this pet
  3845. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3846. // Set the pets spawn type to 6
  3847. pet->SetSpawnType(6);
  3848. // Set the pets brain
  3849. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  3850. // Check to see if the pet has a subtitle
  3851. if (strlen(pet->GetSubTitle()) > 0) {
  3852. // Add the players name to the front of the sub title
  3853. string pet_subtitle;
  3854. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3855. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3856. // Set the pets subtitle to the new one
  3857. pet->SetSubTitle(pet_subtitle.c_str());
  3858. }
  3859. // Add the "Pet Options" entity command to the pet
  3860. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3861. // Set the pet as the return value for this function
  3862. lua_interface->SetSpawnValue(state, pet);
  3863. return 1;
  3864. }
  3865. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  3866. if (!lua_interface)
  3867. return 0;
  3868. Spawn* spawn = lua_interface->GetSpawn(state);
  3869. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3870. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3871. if (!spawn) {
  3872. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3873. return 0;
  3874. }
  3875. if (!spawn->IsEntity()) {
  3876. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3877. return 0;
  3878. }
  3879. if (((Entity*)spawn)->GetDeityPet()) {
  3880. if (spawn->IsPlayer()) {
  3881. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3882. if (client)
  3883. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  3884. }
  3885. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3886. return 0;
  3887. }
  3888. if (pet_id == 0) {
  3889. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3890. return 0;
  3891. }
  3892. if (!luaspell) {
  3893. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3894. return 0;
  3895. }
  3896. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3897. if (!pet) {
  3898. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3899. return 0;
  3900. }
  3901. if (!pet->IsNPC()) {
  3902. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  3903. return 0;
  3904. }
  3905. pet->SetX(spawn->GetX());
  3906. pet->SetY(spawn->GetY());
  3907. pet->SetZ(spawn->GetZ());
  3908. pet->SetLocation(spawn->GetLocation());
  3909. pet->SetHeading(spawn->GetHeading());
  3910. spawn->GetZone()->AddSpawn(pet);
  3911. string random_pet_name;
  3912. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3913. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3914. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3915. pet->SetName(random_pet_name.c_str());
  3916. pet->SetLevel(spawn->GetLevel());
  3917. pet->SetFactionID(spawn->GetFactionID());
  3918. pet->SetPet(true);
  3919. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  3920. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3921. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  3922. pet->SetSpawnType(6);
  3923. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  3924. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3925. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3926. if (strlen(pet->GetSubTitle()) > 0) {
  3927. string pet_subtitle;
  3928. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3929. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3930. pet->SetSubTitle(pet_subtitle.c_str());
  3931. }
  3932. // deity and cosmetic pets are not attackable
  3933. pet->SetAttackable(false);
  3934. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3935. lua_interface->SetSpawnValue(state, pet);
  3936. return 1;
  3937. }
  3938. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  3939. if (!lua_interface)
  3940. return 0;
  3941. Spawn* spawn = lua_interface->GetSpawn(state);
  3942. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3943. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3944. if (!spawn) {
  3945. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3946. return 0;
  3947. }
  3948. if (!spawn->IsEntity()) {
  3949. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3950. return 0;
  3951. }
  3952. if (((Entity*)spawn)->GetCosmeticPet()) {
  3953. if (spawn->IsPlayer()) {
  3954. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3955. if (client)
  3956. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  3957. }
  3958. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3959. return 0;
  3960. }
  3961. if (pet_id == 0) {
  3962. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3963. return 0;
  3964. }
  3965. if (!luaspell) {
  3966. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3967. return 0;
  3968. }
  3969. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3970. if (!pet) {
  3971. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3972. return 0;
  3973. }
  3974. if (!pet->IsNPC()) {
  3975. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  3976. return 0;
  3977. }
  3978. pet->SetX(spawn->GetX());
  3979. pet->SetY(spawn->GetY());
  3980. pet->SetZ(spawn->GetZ());
  3981. pet->SetLocation(spawn->GetLocation());
  3982. pet->SetHeading(spawn->GetHeading());
  3983. spawn->GetZone()->AddSpawn(pet);
  3984. string random_pet_name;
  3985. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3986. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3987. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3988. pet->SetName(random_pet_name.c_str());
  3989. pet->SetLevel(spawn->GetLevel());
  3990. pet->SetFactionID(spawn->GetFactionID());
  3991. pet->SetPet(true);
  3992. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  3993. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3994. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  3995. pet->SetSpawnType(6);
  3996. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  3997. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3998. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3999. if (strlen(pet->GetSubTitle()) > 0) {
  4000. string pet_subtitle;
  4001. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4002. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4003. pet->SetSubTitle(pet_subtitle.c_str());
  4004. }
  4005. pet->SetAttackable(false);
  4006. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4007. lua_interface->SetSpawnValue(state, pet);
  4008. return 1;
  4009. }
  4010. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4011. if (!lua_interface)
  4012. return 0;
  4013. Spawn* spawn = lua_interface->GetSpawn(state);
  4014. if (!spawn) {
  4015. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4016. return 0;
  4017. }
  4018. if (!spawn->IsPet()) {
  4019. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4020. return 0;
  4021. }
  4022. if (!((NPC*)spawn)->IsDismissing())
  4023. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
  4024. return 0;
  4025. }
  4026. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4027. if (!lua_interface)
  4028. return 0;
  4029. Quest* quest = lua_interface->GetQuest(state);
  4030. if (!quest) {
  4031. 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));
  4032. return 0;
  4033. }
  4034. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4035. if (feather_color > 0)
  4036. quest->SetFeatherColor(feather_color);
  4037. return 0;
  4038. }
  4039. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4040. if (!lua_interface)
  4041. return 0;
  4042. Spawn* spawn = lua_interface->GetSpawn(state);
  4043. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4044. if (!spawn) {
  4045. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4046. return 0;
  4047. }
  4048. if (!spawn2) {
  4049. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4050. return 0;
  4051. }
  4052. spawn->RemoveSpawnAccess(spawn2);
  4053. return 0;
  4054. }
  4055. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4056. if (!lua_interface)
  4057. return 0;
  4058. ZoneServer* zone = lua_interface->GetZone(state);
  4059. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4060. if (!zone) {
  4061. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4062. return 0;
  4063. }
  4064. if (location_id == 0) {
  4065. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4066. return 0;
  4067. }
  4068. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4069. if (!location) {
  4070. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4071. return 0;
  4072. }
  4073. Spawn* spawn = 0;
  4074. if (location->entities[0]) {
  4075. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4076. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4077. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4078. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4079. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4080. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4081. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4082. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4083. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4084. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4085. if (spawn) {
  4086. const char* script = 0;
  4087. for (int x = 0; x < 3; x++) {
  4088. switch (x) {
  4089. case 0:
  4090. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4091. break;
  4092. case 1:
  4093. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4094. break;
  4095. case 2:
  4096. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4097. break;
  4098. }
  4099. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4100. spawn->SetSpawnScript(string(script));
  4101. break;
  4102. }
  4103. }
  4104. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4105. lua_interface->SetSpawnValue(state, spawn);
  4106. return 1;
  4107. }
  4108. else {
  4109. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4110. safe_delete(spawn);
  4111. }
  4112. }
  4113. return 0;
  4114. }
  4115. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4116. if (!lua_interface)
  4117. return 0;
  4118. Spawn* caster = lua_interface->GetSpawn(state);
  4119. Spawn* target = lua_interface->GetSpawn(state, 2);
  4120. int32 id = lua_interface->GetInt32Value(state, 3);
  4121. string command = lua_interface->GetStringValue(state, 4);
  4122. if (!caster) {
  4123. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4124. return 0;
  4125. }
  4126. if (!target) {
  4127. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4128. return 0;
  4129. }
  4130. if (!caster->IsPlayer()) {
  4131. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4132. return 0;
  4133. }
  4134. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4135. if (!entity_command) {
  4136. 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());
  4137. return 0;
  4138. }
  4139. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4140. if (!client) {
  4141. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4142. return 0;
  4143. }
  4144. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4145. return 0;
  4146. }
  4147. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4148. if (!lua_interface)
  4149. return 0;
  4150. Spawn* spawn = lua_interface->GetSpawn(state);
  4151. if (!spawn) {
  4152. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4153. return 0;
  4154. }
  4155. if (!spawn->IsNPC()) {
  4156. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4157. return 0;
  4158. }
  4159. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4160. return 0;
  4161. }
  4162. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4163. if (!lua_interface)
  4164. return 0;
  4165. Spawn* spawn = lua_interface->GetSpawn(state);
  4166. int16 tick = lua_interface->GetInt16Value(state, 2);
  4167. if (!spawn) {
  4168. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4169. return 0;
  4170. }
  4171. if (!spawn->IsNPC()) {
  4172. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4173. return 0;
  4174. }
  4175. if (tick < 20) {
  4176. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4177. return 0;
  4178. }
  4179. ((NPC*)spawn)->Brain()->SetTick(tick);
  4180. return 0;
  4181. }
  4182. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4183. if (!lua_interface)
  4184. return 0;
  4185. Spawn* spawn = lua_interface->GetSpawn(state);
  4186. Spawn* target = lua_interface->GetSpawn(state, 2);
  4187. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4188. if (!spawn) {
  4189. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4190. return 0;
  4191. }
  4192. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4193. spawn->SetFollowTarget(target, follow_distance);
  4194. return 0;
  4195. }
  4196. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4197. if (!lua_interface)
  4198. return 0;
  4199. Spawn* spawn = lua_interface->GetSpawn(state);
  4200. if (!spawn) {
  4201. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4202. return 0;
  4203. }
  4204. Spawn* target = spawn->GetFollowTarget();
  4205. if (target) {
  4206. lua_interface->SetSpawnValue(state, target);
  4207. return 1;
  4208. }
  4209. return 0;
  4210. }
  4211. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4212. if (!lua_interface)
  4213. return 0;
  4214. Spawn* spawn = lua_interface->GetSpawn(state);
  4215. if (!spawn) {
  4216. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4217. return 0;
  4218. }
  4219. if (spawn->following)
  4220. spawn->following = false;
  4221. else
  4222. spawn->following = true;
  4223. return 0;
  4224. }
  4225. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4226. if (!lua_interface)
  4227. return 0;
  4228. Spawn* spawn = lua_interface->GetSpawn(state);
  4229. if (!spawn) {
  4230. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4231. return 0;
  4232. }
  4233. lua_interface->SetBooleanValue(state, spawn->following);
  4234. return 1;
  4235. }
  4236. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4237. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4238. // I will attempt to explain how this function works for future refrence
  4239. // Fist lets make sure lua_interface is valid, if not return out
  4240. if (!lua_interface)
  4241. return 0;
  4242. // Next we grab the first 2 params same as we usually would
  4243. Spawn* spawn = lua_interface->GetSpawn(state);
  4244. string var = lua_interface->GetStringValue(state, 2);
  4245. // 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
  4246. // 1 = Spawn
  4247. // 2 = Zone
  4248. // 3 = Item
  4249. // 4 = Quest
  4250. // 5 = String
  4251. // 6 = nil (null)
  4252. int8 dataType = 0;
  4253. // Define pointers for each potential type
  4254. Spawn* spawnVal = 0;
  4255. ZoneServer* zone = 0;
  4256. Item* item = 0;
  4257. Quest* quest = 0;
  4258. string val;
  4259. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4260. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4261. // options window are also light user data be we do not handle those.
  4262. // We check with lua_islightuserdata(lua_State*, index)
  4263. if (lua_islightuserdata(state, 3)) {
  4264. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4265. // and convert it to LUAUserData*
  4266. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4267. // Check to make sure the data we got is valid, if not give an error
  4268. if (!data || !data->IsCorrectlyInitialized()) {
  4269. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4270. }
  4271. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4272. else if (data->IsSpawn()) {
  4273. spawnVal = data->spawn;
  4274. dataType = 1;
  4275. }
  4276. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4277. else if (data->IsZone()) {
  4278. zone = data->zone;
  4279. dataType = 2;
  4280. }
  4281. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4282. else if (data->IsItem()) {
  4283. item = data->item;
  4284. dataType = 3;
  4285. }
  4286. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4287. else if (data->IsQuest()) {
  4288. quest = data->quest;
  4289. dataType = 4;
  4290. }
  4291. }
  4292. // Wasn't light user data, check if it is nil(null)
  4293. else if (lua_isnil(state, 3)) {
  4294. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4295. dataType = 6;
  4296. }
  4297. // Wasn't light user data or nil (null), must be a string
  4298. else {
  4299. // Set the string and dataType variable
  4300. val = lua_interface->GetStringValue(state, 3);
  4301. dataType = 5;
  4302. }
  4303. // We now have all the params, lets check to make sure they are valid
  4304. if (!spawn) {
  4305. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4306. return 0;
  4307. }
  4308. if (var.length() == 0) {
  4309. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4310. return 0;
  4311. }
  4312. if (dataType == 0) {
  4313. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4314. return 0;
  4315. }
  4316. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4317. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4318. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4319. switch (dataType) {
  4320. case 1:
  4321. // 1 = Spawn
  4322. spawn->AddTempVariable(var, spawnVal);
  4323. break;
  4324. case 2:
  4325. // 2 = Zone
  4326. spawn->AddTempVariable(var, zone);
  4327. break;
  4328. case 3:
  4329. // 3 = Item
  4330. spawn->AddTempVariable(var, item);
  4331. break;
  4332. case 4:
  4333. // 4 = Quest
  4334. spawn->AddTempVariable(var, quest);
  4335. break;
  4336. case 5:
  4337. // 5 = String
  4338. spawn->AddTempVariable(var, val);
  4339. break;
  4340. case 6:
  4341. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4342. spawn->DeleteTempVariable(var);
  4343. break;
  4344. }
  4345. // And we are done so return out
  4346. return 0;
  4347. }
  4348. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4349. if (!lua_interface)
  4350. return 0;
  4351. Spawn* spawn = lua_interface->GetSpawn(state);
  4352. string var = lua_interface->GetStringValue(state, 2);
  4353. if (!spawn) {
  4354. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4355. return 0;
  4356. }
  4357. if (var.length() == 0) {
  4358. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4359. return 0;
  4360. }
  4361. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4362. int8 type = spawn->GetTempVariableType(var);
  4363. Spawn* spawn2 = 0;
  4364. ZoneServer* zone = 0;
  4365. Item* item = 0;
  4366. Quest* quest = 0;
  4367. // Set the lua function return value based on the type of data the variable contains
  4368. switch (type) {
  4369. case 1:
  4370. spawn2 = spawn->GetTempVariableSpawn(var);
  4371. if (!spawn2)
  4372. return 0;
  4373. lua_interface->SetSpawnValue(state, spawn2);
  4374. break;
  4375. case 2:
  4376. zone = spawn->GetTempVariableZone(var);
  4377. if (!zone)
  4378. return 0;
  4379. lua_interface->SetZoneValue(state, zone);
  4380. break;
  4381. case 3:
  4382. item = spawn->GetTempVariableItem(var);
  4383. if (!item)
  4384. return 0;
  4385. lua_interface->SetItemValue(state, item);
  4386. break;
  4387. case 4:
  4388. quest = spawn->GetTempVariableQuest(var);
  4389. if (!quest)
  4390. return 0;
  4391. lua_interface->SetQuestValue(state, quest);
  4392. break;
  4393. case 5:
  4394. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4395. break;
  4396. default:
  4397. // Not a valid type then the variable was not set so return out
  4398. return 0;
  4399. }
  4400. // Return value was set so return out
  4401. return 1;
  4402. }
  4403. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4404. {
  4405. if (!lua_interface)
  4406. return 0;
  4407. Quest* quest = lua_interface->GetQuest(state);
  4408. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4409. string description = lua_interface->GetStringValue(state, 3);
  4410. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4411. if (!quest) {
  4412. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4413. lua_interface->SetBooleanValue(state, false);
  4414. return 1;
  4415. }
  4416. if (!spawn) {
  4417. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4418. lua_interface->SetBooleanValue(state, false);
  4419. return 1;
  4420. }
  4421. if (!spawn->IsPlayer()) {
  4422. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4423. lua_interface->SetBooleanValue(state, false);
  4424. return 1;
  4425. }
  4426. if (item_id == 0) {
  4427. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4428. lua_interface->SetBooleanValue(state, false);
  4429. return 1;
  4430. }
  4431. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4432. if (!client) {
  4433. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4434. lua_interface->SetBooleanValue(state, false);
  4435. return 1;
  4436. }
  4437. Item* item = master_item_list.GetItem(item_id);
  4438. if (!item) {
  4439. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4440. lua_interface->SetBooleanValue(state, false);
  4441. return 1;
  4442. }
  4443. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4444. if (packet) {
  4445. packet->setDataByName("title", "Quest Reward!");
  4446. packet->setDataByName("name", quest->GetName());
  4447. packet->setDataByName("description", description.c_str());
  4448. packet->setDataByName("level", quest->GetLevel());
  4449. packet->setArrayLengthByName("num_rewards", 1);
  4450. packet->setArrayDataByName("reward_id", item->details.item_id);
  4451. if (client->GetVersion() < 860)
  4452. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4453. else if (client->GetVersion() < 1193)
  4454. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4455. else
  4456. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4457. client->QueuePacket(packet->serialize());
  4458. safe_delete(packet);
  4459. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  4460. client->Message(CHANNEL_COLOR_YELLOW, "You receive \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  4461. return 1;
  4462. }
  4463. lua_interface->SetBooleanValue(state, false);
  4464. return 1;
  4465. }
  4466. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  4467. if (!lua_interface)
  4468. return 0;
  4469. Quest* quest = lua_interface->GetQuest(state);
  4470. if (!quest) {
  4471. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  4472. return 0;
  4473. }
  4474. quest->SetRepeatable(true);
  4475. return 0;
  4476. }
  4477. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  4478. if (!lua_interface)
  4479. return 0;
  4480. Spawn* spawn = lua_interface->GetSpawn(state);
  4481. if (!spawn) {
  4482. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  4483. return 0;
  4484. }
  4485. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  4486. string ret = classes.GetClassNameCase(base_class);
  4487. if (ret.length() > 0) {
  4488. lua_interface->SetStringValue(state, ret.c_str());
  4489. return 1;
  4490. }
  4491. return 0;
  4492. }
  4493. int EQ2Emu_lua_AddWard(lua_State* state) {
  4494. if (!lua_interface)
  4495. return 0;
  4496. int32 damage = lua_interface->GetInt32Value(state);
  4497. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  4498. int8 wardType = lua_interface->GetInt8Value(state, 3);
  4499. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  4500. int8 damageAbsorptionPercent = lua_interface->GetInt8Value(state, 5);
  4501. int8 damageAbsorptionMaxHealthPercent = lua_interface->GetInt8Value(state, 6);
  4502. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4503. bool ward_was_added = false;
  4504. ZoneServer* zone = spell->caster->GetZone();
  4505. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4506. for (int32 i = 0; i < spell->targets.size(); i++) {
  4507. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  4508. if (!target)
  4509. continue;
  4510. if (target->IsEntity()) {
  4511. // If the ward is already active remove it
  4512. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  4513. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4514. // Create new ward info
  4515. WardInfo* ward = new WardInfo;
  4516. ward->Spell = spell;
  4517. ward->BaseDamage = damage;
  4518. ward->DamageLeft = damage;
  4519. ward->keepWard = keepWard;
  4520. ward->WardType = wardType;
  4521. if (damageAbsorptionPercent > 100)
  4522. damageAbsorptionPercent = 100;
  4523. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  4524. if (damageAbsorptionMaxHealthPercent > 100)
  4525. damageAbsorptionMaxHealthPercent = 100;
  4526. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  4527. if (wardType == WARD_TYPE_MAGICAL)
  4528. ward->DamageType = damageTypes;
  4529. // Add the ward to the entity
  4530. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  4531. ward_was_added = true;
  4532. }
  4533. }
  4534. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4535. if (ward_was_added && spell->caster->IsPlayer()) {
  4536. spell->had_dmg_remaining = true;
  4537. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  4538. }
  4539. return 0;
  4540. }
  4541. int EQ2Emu_lua_AddToWard(lua_State* state) {
  4542. if (!lua_interface)
  4543. return 0;
  4544. int32 amount = lua_interface->GetInt32Value(state);
  4545. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4546. WardInfo* ward = 0;
  4547. ZoneServer* zone = spell->caster->GetZone();
  4548. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4549. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4550. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  4551. ward = target->GetWard(spell->spell->GetSpellID());
  4552. if (ward) {
  4553. ward->DamageLeft += amount;
  4554. if (ward->DamageLeft > ward->BaseDamage)
  4555. ward->DamageLeft = ward->BaseDamage;
  4556. for (int32 i = 0; i < spell->targets.size(); i++) {
  4557. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  4558. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  4559. }
  4560. }
  4561. }
  4562. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4563. if (ward && spell->caster->IsPlayer())
  4564. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  4565. return 0;
  4566. }
  4567. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  4568. if (!lua_interface)
  4569. return 0;
  4570. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4571. if (!spell) {
  4572. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  4573. return 0;
  4574. }
  4575. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4576. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  4577. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  4578. if (ward) {
  4579. lua_interface->SetInt32Value(state, ward->DamageLeft);
  4580. return 1;
  4581. }
  4582. }
  4583. return 0;
  4584. }
  4585. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  4586. if (!lua_interface)
  4587. return 0;
  4588. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4589. ZoneServer* zone = spell->caster->GetZone();
  4590. Spawn* target = 0;
  4591. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4592. for (int32 i = 0; i < spell->targets.size(); i++) {
  4593. target = zone->GetSpawnByID(spell->targets.at(i));
  4594. if (target && target->IsEntity()) {
  4595. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4596. }
  4597. }
  4598. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4599. return 0;
  4600. }
  4601. int EQ2Emu_lua_Interrupt(lua_State* state)
  4602. {
  4603. if (!lua_interface)
  4604. return 0;
  4605. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  4606. Spawn* target = lua_interface->GetSpawn(state, 2);
  4607. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4608. if (!caster)
  4609. {
  4610. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  4611. return 0;
  4612. }
  4613. if (!target)
  4614. {
  4615. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  4616. return 0;
  4617. }
  4618. if (!spell) {
  4619. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  4620. return 0;
  4621. }
  4622. if (!target->IsEntity() && !spell)
  4623. {
  4624. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  4625. return 0;
  4626. }
  4627. if (!target && spell) {
  4628. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4629. for (int8 i = 0; i < spell->targets.size(); i++) {
  4630. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  4631. if (!target || !target->IsEntity())
  4632. continue;
  4633. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  4634. }
  4635. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4636. }
  4637. else
  4638. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  4639. return 0;
  4640. }
  4641. int EQ2Emu_lua_Stealth(lua_State* state) {
  4642. if (!lua_interface)
  4643. return 0;
  4644. int8 type = lua_interface->GetInt8Value(state);
  4645. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4646. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4647. if (!spell) {
  4648. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  4649. return 0;
  4650. }
  4651. ZoneServer* zone = spell->caster->GetZone();
  4652. if (spawn) {
  4653. if (spawn->IsEntity()) {
  4654. if (type == 1) {
  4655. ((Entity*)spawn)->AddStealthSpell(spell);
  4656. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  4657. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  4658. }
  4659. else if (type == 2) {
  4660. ((Entity*)spawn)->AddInvisSpell(spell);
  4661. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  4662. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  4663. }
  4664. return 0;
  4665. }
  4666. else {
  4667. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  4668. return 0;
  4669. }
  4670. }
  4671. else {
  4672. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4673. for (int32 i = 0; i < spell->targets.size(); i++) {
  4674. spawn = zone->GetSpawnByID(spell->targets.at(i));
  4675. if (!spawn || !spawn->IsEntity())
  4676. continue;
  4677. if (type == 1) {
  4678. ((Entity*)spawn)->AddStealthSpell(spell);
  4679. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  4680. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  4681. }
  4682. else if (type == 2) {
  4683. ((Entity*)spawn)->AddInvisSpell(spell);
  4684. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  4685. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  4686. }
  4687. else {
  4688. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  4689. break;
  4690. }
  4691. }
  4692. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4693. }
  4694. return 0;
  4695. }
  4696. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  4697. if (!lua_interface)
  4698. return 0;
  4699. Spawn* spawn = lua_interface->GetSpawn(state);
  4700. if (!spawn) {
  4701. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  4702. return 0;
  4703. }
  4704. if (spawn->IsEntity()) {
  4705. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  4706. return 1;
  4707. }
  4708. else
  4709. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  4710. return 0;
  4711. }
  4712. int EQ2Emu_lua_IsInvis(lua_State* state) {
  4713. if (!lua_interface)
  4714. return 0;
  4715. Spawn* spawn = lua_interface->GetSpawn(state);
  4716. if (!spawn) {
  4717. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  4718. return 0;
  4719. }
  4720. if (spawn->IsEntity()) {
  4721. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  4722. return 1;
  4723. }
  4724. else
  4725. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  4726. return 0;
  4727. }
  4728. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  4729. if (!lua_interface)
  4730. return 0;
  4731. Spawn* player = lua_interface->GetSpawn(state);
  4732. int32 item_id = lua_interface->GetInt32Value(state, 2);
  4733. if (!player->IsPlayer()) {
  4734. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  4735. return 0;
  4736. }
  4737. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  4738. return 1;
  4739. }
  4740. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  4741. if (!lua_interface)
  4742. return 0;
  4743. Spawn* player = lua_interface->GetSpawn(state);
  4744. int8 slot = lua_interface->GetInt8Value(state, 2);
  4745. if (!player) {
  4746. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  4747. return 0;
  4748. }
  4749. if (!player->IsPlayer()) {
  4750. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  4751. return 0;
  4752. }
  4753. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  4754. if (!item) {
  4755. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  4756. return 0;
  4757. }
  4758. lua_interface->SetItemValue(state, item);
  4759. return 1;
  4760. }
  4761. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  4762. if (!lua_interface)
  4763. return 0;
  4764. Spawn* player = lua_interface->GetSpawn(state);
  4765. int32 id = lua_interface->GetInt32Value(state, 2);
  4766. if (!player) {
  4767. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  4768. return 0;
  4769. }
  4770. if (!player->IsPlayer()) {
  4771. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  4772. return 0;
  4773. }
  4774. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  4775. if (!item) {
  4776. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  4777. return 0;
  4778. }
  4779. lua_interface->SetItemValue(state, item);
  4780. return 1;
  4781. }
  4782. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  4783. if (!lua_interface)
  4784. return 0;
  4785. Spawn* player = lua_interface->GetSpawn(state);
  4786. int32 id = lua_interface->GetInt32Value(state, 2);
  4787. int8 count = lua_interface->GetInt8Value(state, 3);
  4788. bool include_bank = lua_interface->GetInt8Value(state, 4);
  4789. if (!player) {
  4790. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  4791. return 0;
  4792. }
  4793. if (!player->IsPlayer()) {
  4794. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  4795. return 0;
  4796. }
  4797. if (!count)
  4798. count = 1;
  4799. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  4800. if (!item) {
  4801. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  4802. return 0;
  4803. }
  4804. lua_interface->SetItemValue(state, item);
  4805. return 1;
  4806. }
  4807. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  4808. if (!lua_interface)
  4809. return 0;
  4810. Spawn* spawn = lua_interface->GetSpawn(state);
  4811. int32 anim = lua_interface->GetInt32Value(state, 2);
  4812. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  4813. int8 type = lua_interface->GetInt8Value(state, 4);
  4814. if (!spawn) {
  4815. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  4816. return 0;
  4817. }
  4818. if (spawn2) {
  4819. if (spawn2->IsPlayer()) {
  4820. if (type != 1 && type != 2)
  4821. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  4822. else
  4823. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  4824. return 0;
  4825. }
  4826. else {
  4827. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  4828. return 0;
  4829. }
  4830. }
  4831. else
  4832. spawn->GetZone()->PlayAnimation(spawn, anim);
  4833. return 0;
  4834. }
  4835. int EQ2Emu_lua_IsPet(lua_State* state) {
  4836. if (!lua_interface)
  4837. return 0;
  4838. Spawn* spawn = lua_interface->GetSpawn(state);
  4839. if (!spawn) {
  4840. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4841. return 0;
  4842. }
  4843. lua_interface->SetBooleanValue(state, spawn->IsPet());
  4844. return 1;
  4845. }
  4846. int EQ2Emu_lua_GetOwner(lua_State* state) {
  4847. if (!lua_interface)
  4848. return 0;
  4849. Spawn* spawn = lua_interface->GetSpawn(state);
  4850. if (!spawn) {
  4851. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  4852. return 0;
  4853. }
  4854. if (!spawn->IsNPC()) {
  4855. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  4856. return 0;
  4857. }
  4858. if (((NPC*)spawn)->GetOwner()) {
  4859. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  4860. return 1;
  4861. }
  4862. return 0;
  4863. }
  4864. int EQ2Emu_lua_SetTarget(lua_State* state) {
  4865. if (!lua_interface)
  4866. return 0;
  4867. Spawn* spawn = lua_interface->GetSpawn(state);
  4868. Spawn* target = lua_interface->GetSpawn(state, 2);
  4869. if (!spawn) {
  4870. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4871. return 0;
  4872. }
  4873. if (!spawn) {
  4874. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  4875. return 0;
  4876. }
  4877. spawn->SetTarget(target);
  4878. return 0;
  4879. }
  4880. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  4881. if (!lua_interface)
  4882. return 0;
  4883. Spawn* spawn = lua_interface->GetSpawn(state);
  4884. bool val = lua_interface->GetBooleanValue(state, 2);
  4885. if (!spawn) {
  4886. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  4887. return 0;
  4888. }
  4889. if (!spawn->IsEntity()) {
  4890. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  4891. return 0;
  4892. }
  4893. ((Entity*)spawn)->InCombat(val);
  4894. if (val) {
  4895. spawn->ClearRunningLocations();
  4896. spawn->CalculateRunningLocation(true);
  4897. }
  4898. return 0;
  4899. }
  4900. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  4901. if (!lua_interface)
  4902. return 0;
  4903. Spawn* spawn1 = lua_interface->GetSpawn(state);
  4904. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4905. if (!spawn1) {
  4906. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4907. return 0;
  4908. }
  4909. if (!spawn2) {
  4910. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4911. return 0;
  4912. }
  4913. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  4914. return 1;
  4915. }
  4916. int EQ2Emu_lua_Runback(lua_State* state) {
  4917. if (!lua_interface)
  4918. return 0;
  4919. Spawn* spawn = lua_interface->GetSpawn(state);
  4920. if (!spawn) {
  4921. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  4922. return 0;
  4923. }
  4924. if (!spawn->IsNPC()) {
  4925. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  4926. return 0;
  4927. }
  4928. ((NPC*)spawn)->Runback();
  4929. return 0;
  4930. }
  4931. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  4932. if (!lua_interface)
  4933. return 0;
  4934. Spawn* spawn = lua_interface->GetSpawn(state);
  4935. if (!spawn) {
  4936. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  4937. return 0;
  4938. }
  4939. if (!spawn->IsNPC()) {
  4940. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  4941. return 0;
  4942. }
  4943. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  4944. return 1;
  4945. }
  4946. int EQ2Emu_lua_IsCasting(lua_State* state) {
  4947. if (!lua_interface)
  4948. return 0;
  4949. Spawn* spawn = lua_interface->GetSpawn(state);
  4950. if (!spawn) {
  4951. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  4952. return 0;
  4953. }
  4954. if (!spawn->IsEntity()) {
  4955. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  4956. return 0;
  4957. }
  4958. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  4959. return 1;
  4960. }
  4961. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  4962. if (!lua_interface)
  4963. return 0;
  4964. Spawn* spawn = lua_interface->GetSpawn(state);
  4965. if (!spawn) {
  4966. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  4967. return 0;
  4968. }
  4969. if (!spawn->IsEntity()) {
  4970. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  4971. return 0;
  4972. }
  4973. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  4974. return 1;
  4975. }
  4976. int EQ2Emu_lua_IsStunned(lua_State* state) {
  4977. if (!lua_interface)
  4978. return 0;
  4979. Spawn* spawn = lua_interface->GetSpawn(state);
  4980. if (!spawn) {
  4981. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  4982. return 0;
  4983. }
  4984. if (!spawn->IsEntity()) {
  4985. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  4986. return 0;
  4987. }
  4988. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  4989. return 1;
  4990. }
  4991. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  4992. if (!lua_interface)
  4993. return 0;
  4994. Spawn* spawn = lua_interface->GetSpawn(state);
  4995. if (!spawn) {
  4996. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  4997. return 0;
  4998. }
  4999. if (!spawn->IsEntity()) {
  5000. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5001. return 0;
  5002. }
  5003. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5004. return 1;
  5005. }
  5006. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5007. if (!lua_interface)
  5008. return 0;
  5009. Spawn* spawn = lua_interface->GetSpawn(state);
  5010. Spawn* target = lua_interface->GetSpawn(state, 2);
  5011. float distance = lua_interface->GetFloatValue(state, 3);
  5012. if (!spawn) {
  5013. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5014. return 0;
  5015. }
  5016. if (!target) {
  5017. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5018. return 0;
  5019. }
  5020. if (!spawn->IsNPC()) {
  5021. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5022. return 0;
  5023. }
  5024. if (!target->IsEntity()) {
  5025. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5026. return 0;
  5027. }
  5028. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5029. return 1;
  5030. }
  5031. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5032. if (!lua_interface)
  5033. return 0;
  5034. Spawn* spawn = lua_interface->GetSpawn(state);
  5035. Spawn* target = lua_interface->GetSpawn(state, 2);
  5036. float distance = lua_interface->GetFloatValue(state, 3);
  5037. if (!spawn) {
  5038. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5039. return 0;
  5040. }
  5041. if (!target) {
  5042. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5043. return 0;
  5044. }
  5045. if (!spawn->IsNPC()) {
  5046. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5047. return 0;
  5048. }
  5049. if (!target->IsEntity()) {
  5050. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5051. return 0;
  5052. }
  5053. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5054. return 0;
  5055. }
  5056. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5057. if (!lua_interface)
  5058. return 0;
  5059. Spawn* spawn = lua_interface->GetSpawn(state);
  5060. if (!spawn) {
  5061. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5062. return 0;
  5063. }
  5064. if (!spawn->IsNPC()) {
  5065. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5066. return 0;
  5067. }
  5068. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5069. return 1;
  5070. }
  5071. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5072. if (!lua_interface)
  5073. return 0;
  5074. Spawn* spawn = lua_interface->GetSpawn(state);
  5075. if (!spawn) {
  5076. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5077. return 0;
  5078. }
  5079. if (!spawn->IsNPC()) {
  5080. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5081. return 0;
  5082. }
  5083. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5084. return 1;
  5085. }
  5086. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5087. if (!lua_interface)
  5088. return 0;
  5089. Spawn* spawn = lua_interface->GetSpawn(state);
  5090. if (!spawn) {
  5091. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5092. return 0;
  5093. }
  5094. if (!spawn->IsNPC()) {
  5095. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5096. return 0;
  5097. }
  5098. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5099. if (hated) {
  5100. lua_interface->SetSpawnValue(state, hated);
  5101. return 1;
  5102. }
  5103. return 0;
  5104. }
  5105. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5106. if (!lua_interface)
  5107. return 0;
  5108. Spawn* spawn = lua_interface->GetSpawn(state);
  5109. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5110. if (!spawn) {
  5111. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5112. return 0;
  5113. }
  5114. if (!spawn->IsNPC()) {
  5115. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5116. return 0;
  5117. }
  5118. if (!hated) {
  5119. ((NPC*)spawn)->Brain()->ClearHate();
  5120. return 0;
  5121. }
  5122. else
  5123. {
  5124. if (!hated->IsEntity()) {
  5125. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5126. return 0;
  5127. }
  5128. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5129. return 0;
  5130. }
  5131. return 0;
  5132. }
  5133. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5134. if (!lua_interface)
  5135. return 0;
  5136. Spawn* spawn = lua_interface->GetSpawn(state);
  5137. if (!spawn) {
  5138. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5139. return 0;
  5140. }
  5141. if (!spawn->IsNPC()) {
  5142. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5143. return 0;
  5144. }
  5145. ((NPC*)spawn)->Brain()->ClearEncounter();
  5146. return 0;
  5147. }
  5148. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5149. if (!lua_interface)
  5150. return 0;
  5151. Spawn* spawn = lua_interface->GetSpawn(state);
  5152. if (!spawn) {
  5153. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5154. return 0;
  5155. }
  5156. if (!spawn->IsNPC()) {
  5157. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5158. return 0;
  5159. }
  5160. // Temp list to store hate list
  5161. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5162. if (encounterList->size() == 0) {
  5163. safe_delete(encounterList);
  5164. return 0;
  5165. }
  5166. lua_createtable(state, encounterList->size(), 0);
  5167. int newTable = lua_gettop(state);
  5168. for (int32 i = 0; i < encounterList->size(); i++) {
  5169. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5170. if (temp)
  5171. lua_interface->SetSpawnValue(state, temp);
  5172. lua_rawseti(state, newTable, i + 1);
  5173. }
  5174. safe_delete(encounterList);
  5175. return 1;
  5176. }
  5177. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5178. if (!lua_interface)
  5179. return 0;
  5180. Spawn* spawn = lua_interface->GetSpawn(state);
  5181. if (!spawn) {
  5182. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5183. return 0;
  5184. }
  5185. if (!spawn->IsNPC()) {
  5186. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5187. return 0;
  5188. }
  5189. // Temp list to store hate list
  5190. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5191. if (hateList->size() == 0) {
  5192. safe_delete(hateList);
  5193. return 0;
  5194. }
  5195. lua_createtable(state, hateList->size(), 0);
  5196. int newTable = lua_gettop(state);
  5197. for (int32 i = 0; i < hateList->size(); i++) {
  5198. lua_interface->SetSpawnValue(state, hateList->at(i));
  5199. lua_rawseti(state, newTable, i + 1);
  5200. }
  5201. safe_delete(hateList);
  5202. return 1;
  5203. }
  5204. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5205. if (!lua_interface)
  5206. return 0;
  5207. Spawn* spawn = lua_interface->GetSpawn(state);
  5208. if (!spawn) {
  5209. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5210. return 0;
  5211. }
  5212. if (spawn->IsPlayer()) {
  5213. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5214. lua_interface->SetBooleanValue(state, true);
  5215. else
  5216. lua_interface->SetBooleanValue(state, false);
  5217. return 1;
  5218. }
  5219. else {
  5220. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5221. return 1;
  5222. }
  5223. }
  5224. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5225. if (!lua_interface)
  5226. return 0;
  5227. Quest* quest = lua_interface->GetQuest(state);
  5228. if (!quest) {
  5229. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5230. return 0;
  5231. }
  5232. quest->SetCompletedFlag(true);
  5233. return 0;
  5234. }
  5235. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5236. if (!lua_interface)
  5237. return 0;
  5238. Spawn* spawn = lua_interface->GetSpawn(state);
  5239. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5240. int8 tier = lua_interface->GetInt8Value(state, 3);
  5241. if (!spawn) {
  5242. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5243. return 0;
  5244. }
  5245. if (!spawn->IsEntity()) {
  5246. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5247. return 0;
  5248. }
  5249. if (spellID == 0) {
  5250. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5251. return 0;
  5252. }
  5253. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5254. if (effect) {
  5255. if (tier > 0) {
  5256. // If a tier was passed chec to see if it is the same as the effect
  5257. if (tier == effect->tier)
  5258. lua_interface->SetBooleanValue(state, true);
  5259. else
  5260. lua_interface->SetBooleanValue(state, false);
  5261. return 1;
  5262. }
  5263. else {
  5264. // Have an effect but no tier was passed so return true
  5265. lua_interface->SetBooleanValue(state, true);
  5266. }
  5267. return 1;
  5268. }
  5269. // no effect so return false
  5270. lua_interface->SetBooleanValue(state, false);
  5271. return 1;
  5272. }
  5273. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5274. if (!lua_interface)
  5275. return 0;
  5276. Spawn* spawn = lua_interface->GetSpawn(state);
  5277. int32 id = lua_interface->GetInt32Value(state, 2);
  5278. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5279. Spawn* spawn2 = 0;
  5280. vector<Spawn*> list;
  5281. if (!spawn) {
  5282. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5283. return 0;
  5284. }
  5285. //If zone not provided, use spawn's zone
  5286. if (!zone)
  5287. zone = spawn->GetZone();
  5288. list = zone->GetSpawnsByID(id);
  5289. if (list.size() == 0) {
  5290. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5291. return 0;
  5292. }
  5293. vector<Spawn*>::iterator itr = list.begin();
  5294. for (int8 i = 0; i < list.size(); i++) {
  5295. spawn2 = itr[i];
  5296. if (spawn2)
  5297. spawn2->AddAllowAccessSpawn(spawn);
  5298. }
  5299. return 0;
  5300. }
  5301. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5302. if (!lua_interface)
  5303. return 0;
  5304. Spawn* spawn = lua_interface->GetSpawn(state);
  5305. int32 id = lua_interface->GetInt32Value(state, 2);
  5306. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5307. Spawn* spawn2 = 0;
  5308. if (!spawn) {
  5309. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5310. return 0;
  5311. }
  5312. //If zone not provided, use spawn's zone
  5313. if (!zone)
  5314. zone = spawn->GetZone();
  5315. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5316. vector<Spawn*>::iterator itr = list.begin();
  5317. if (list.size() == 0) {
  5318. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. for (int8 i = 0; i < list.size(); i++) {
  5322. spawn2 = itr[i];
  5323. if (spawn2)
  5324. spawn2->RemoveSpawnAccess(spawn);
  5325. }
  5326. return 0;
  5327. }
  5328. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5329. if (!lua_interface)
  5330. return 0;
  5331. Quest* quest = lua_interface->GetQuest(state);
  5332. if (!quest) {
  5333. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5334. return 0;
  5335. }
  5336. quest->SetYellowName(true);
  5337. return 0;
  5338. }
  5339. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5340. if (!lua_interface)
  5341. return 0;
  5342. Spawn* spawn = lua_interface->GetSpawn(state);
  5343. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5344. if (!spawn) {
  5345. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5346. return 0;
  5347. }
  5348. if (!spawn->IsPlayer()) {
  5349. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5350. return 0;
  5351. }
  5352. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5353. return 1;
  5354. }
  5355. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5356. if (!lua_interface)
  5357. return 0;
  5358. Spawn* spawn = lua_interface->GetSpawn(state);
  5359. if (!spawn) {
  5360. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5361. return 0;
  5362. }
  5363. if (!spawn->IsPlayer()) {
  5364. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5365. return 0;
  5366. }
  5367. ZoneServer* zone = spawn->GetZone();
  5368. if (!zone) {
  5369. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5370. return 0;
  5371. }
  5372. Instance_Type iType = zone->GetInstanceType();
  5373. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5374. iType == GROUP_LOCKOUT_INSTANCE ||
  5375. iType == RAID_LOCKOUT_INSTANCE ||
  5376. iType == SOLO_PERSIST_INSTANCE ||
  5377. iType == GROUP_PERSIST_INSTANCE ||
  5378. iType == RAID_PERSIST_INSTANCE) {
  5379. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5380. if (data) {
  5381. // Check to see if the timer has already been set, if it has return out.
  5382. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  5383. return 0;
  5384. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  5385. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  5386. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5387. if (client) {
  5388. string time_msg = "";
  5389. int32 time = data->success_lockout_time;
  5390. int16 hour;
  5391. int8 min;
  5392. int8 sec;
  5393. hour = time / 3600;
  5394. time = time % 3600;
  5395. min = time / 60;
  5396. time = time % 60;
  5397. sec = time;
  5398. if (hour > 0) {
  5399. char temp[10];
  5400. sprintf(temp, " %i", hour);
  5401. time_msg.append(temp);
  5402. time_msg.append(" hour");
  5403. time_msg.append((hour > 1) ? "s" : "");
  5404. }
  5405. if (min > 0) {
  5406. char temp[5];
  5407. sprintf(temp, " %i", min);
  5408. time_msg.append(temp);
  5409. time_msg.append(" minute");
  5410. time_msg.append((min > 1) ? "s" : "");
  5411. }
  5412. // Only add seconds if minutes and hours are 0
  5413. if (hour == 0 && min == 0 && sec > 0) {
  5414. char temp[5];
  5415. sprintf(temp, " %i", sec);
  5416. time_msg.append(temp);
  5417. time_msg.append(" second");
  5418. time_msg.append((sec > 1) ? "s" : "");
  5419. }
  5420. 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());
  5421. }
  5422. }
  5423. else
  5424. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5425. }
  5426. else
  5427. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5428. return 0;
  5429. }
  5430. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  5431. if (!lua_interface)
  5432. return 0;
  5433. Spawn* spawn = lua_interface->GetSpawn(state);
  5434. if (!spawn) {
  5435. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5436. return 0;
  5437. }
  5438. if (!spawn->IsPlayer()) {
  5439. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5440. return 0;
  5441. }
  5442. ZoneServer* zone = spawn->GetZone();
  5443. if (!zone) {
  5444. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5445. return 0;
  5446. }
  5447. Instance_Type iType = zone->GetInstanceType();
  5448. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5449. iType == GROUP_LOCKOUT_INSTANCE ||
  5450. iType == RAID_LOCKOUT_INSTANCE ||
  5451. iType == SOLO_PERSIST_INSTANCE ||
  5452. iType == GROUP_PERSIST_INSTANCE ||
  5453. iType == RAID_PERSIST_INSTANCE) {
  5454. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5455. if (data) {
  5456. // Check to see if the timer has already been set, if it has return out.
  5457. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  5458. return 0;
  5459. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  5460. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  5461. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5462. if (client) {
  5463. string time_msg = "";
  5464. int32 time = data->failure_lockout_time;
  5465. int16 hour;
  5466. int8 min;
  5467. int8 sec;
  5468. hour = time / 3600;
  5469. time = time % 3600;
  5470. min = time / 60;
  5471. time = time % 60;
  5472. sec = time;
  5473. if (hour > 0) {
  5474. char temp[10];
  5475. sprintf(temp, " %i", hour);
  5476. time_msg.append(temp);
  5477. time_msg.append(" hour");
  5478. time_msg.append((hour > 1) ? "s" : "");
  5479. }
  5480. if (min > 0) {
  5481. char temp[5];
  5482. sprintf(temp, " %i", min);
  5483. time_msg.append(temp);
  5484. time_msg.append(" minute");
  5485. time_msg.append((min > 1) ? "s" : "");
  5486. }
  5487. // Only add seconds if minutes and hours are 0
  5488. if (hour == 0 && min == 0 && sec > 0) {
  5489. char temp[5];
  5490. sprintf(temp, " %i", sec);
  5491. time_msg.append(temp);
  5492. time_msg.append(" second");
  5493. time_msg.append((sec > 1) ? "s" : "");
  5494. }
  5495. 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());
  5496. }
  5497. }
  5498. else
  5499. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5500. }
  5501. else
  5502. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5503. return 0;
  5504. }
  5505. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  5506. if (!lua_interface)
  5507. return 0;
  5508. Spawn* spawn = lua_interface->GetSpawn(state);
  5509. if (!spawn) {
  5510. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  5511. return 0;
  5512. }
  5513. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  5514. return 1;
  5515. }
  5516. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  5517. if (!lua_interface)
  5518. return 0;
  5519. Spawn* player = lua_interface->GetSpawn(state);
  5520. Spawn* ground = lua_interface->GetSpawn(state, 2);
  5521. if (!player) {
  5522. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  5523. return 0;
  5524. }
  5525. if (!player->IsPlayer()) {
  5526. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  5527. return 0;
  5528. }
  5529. if (!ground) {
  5530. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  5531. return 0;
  5532. }
  5533. if (!ground->IsGroundSpawn()) {
  5534. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  5535. return 0;
  5536. }
  5537. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  5538. if (!groundspawn_entries) {
  5539. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  5540. return 0;
  5541. }
  5542. Skill* skill = 0;
  5543. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  5544. if (collection_skill == "Collecting")
  5545. skill = ((Player*)player)->GetSkillByName("Gathering");
  5546. else
  5547. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  5548. if (!skill) {
  5549. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  5550. return 0;
  5551. }
  5552. vector<GroundSpawnEntry*>::iterator itr;
  5553. GroundSpawnEntry* entry = 0;
  5554. bool can_harvest = false;
  5555. sint32 min_skill = -1;
  5556. // first, iterate through groundspawn_entries, discard tables player cannot use
  5557. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  5558. {
  5559. entry = *itr;
  5560. if (min_skill == -1 || entry->min_skill_level < min_skill)
  5561. min_skill = entry->min_skill_level;
  5562. // if player lacks skill, skip table
  5563. if (entry->min_skill_level > skill->current_val)
  5564. continue;
  5565. // if bonus, but player lacks level, skip table
  5566. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  5567. continue;
  5568. can_harvest = true;
  5569. break;
  5570. }
  5571. lua_interface->SetBooleanValue(state, can_harvest);
  5572. // If false, send the message to the client
  5573. if (!can_harvest) {
  5574. Client* client = player->GetZone()->GetClientBySpawn(player);
  5575. if (client) {
  5576. string msg = "You do not have enough skill to ";
  5577. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  5578. msg.append("gather");
  5579. else if (collection_skill == "Mining")
  5580. msg.append("mine");
  5581. else if (collection_skill == "Trapping")
  5582. msg.append("trap");
  5583. else if (collection_skill == "Foresting")
  5584. msg.append("forest");
  5585. else if (collection_skill == "Fishing")
  5586. msg.append("catch");
  5587. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  5588. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  5589. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  5590. }
  5591. }
  5592. return 1;
  5593. }
  5594. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  5595. if (!lua_interface)
  5596. return 0;
  5597. Spawn* player = lua_interface->GetSpawn(state);
  5598. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  5599. if (!player) {
  5600. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  5601. return 0;
  5602. }
  5603. if (!player->IsPlayer()) {
  5604. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  5605. return 0;
  5606. }
  5607. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  5608. lua_interface->SetBooleanValue(state, ret);
  5609. return 1;
  5610. }
  5611. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  5612. // Check to see if we have a valid lua_interface
  5613. if (!lua_interface)
  5614. return 0;
  5615. // Get the spawn that is getting the pet
  5616. Spawn* spawn = lua_interface->GetSpawn(state);
  5617. Spawn* target = lua_interface->GetSpawn(state, 2);
  5618. // Get the DB ID of the pet
  5619. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  5620. float x = lua_interface->GetFloatValue(state, 4);
  5621. float y = lua_interface->GetFloatValue(state, 5);
  5622. float z = lua_interface->GetFloatValue(state, 6);
  5623. // Get the spell that this command was called from
  5624. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5625. // Check to make sure the spawn pointer is valid
  5626. if (!spawn) {
  5627. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5628. return 0;
  5629. }
  5630. // Check to make sure the spawn is an entity
  5631. if (!spawn->IsEntity()) {
  5632. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5633. return 0;
  5634. }
  5635. if (!target) {
  5636. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  5637. return 0;
  5638. }
  5639. if (!target->IsEntity()) {
  5640. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  5641. return 0;
  5642. }
  5643. // Check to see if the DB ID for the pet is set
  5644. if (pet_id == 0) {
  5645. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5646. return 0;
  5647. }
  5648. // Check to see if the pointer to the spell is valid
  5649. if (!luaspell) {
  5650. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5651. return 0;
  5652. }
  5653. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5654. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5655. if (!pet) {
  5656. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  5657. return 0;
  5658. }
  5659. // Check to make sure the pet is an npc
  5660. if (!pet->IsNPC()) {
  5661. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  5662. return 0;
  5663. }
  5664. if (x == 0)
  5665. x = spawn->GetX();
  5666. if (y == 0)
  5667. y = spawn->GetY();
  5668. if (z == 0)
  5669. z = spawn->GetZ();
  5670. // Spawn the pet at the same location as the owner
  5671. pet->SetX(x);
  5672. pet->SetY(y);
  5673. pet->SetZ(z);
  5674. pet->SetLocation(spawn->GetLocation());
  5675. pet->SetHeading(spawn->GetHeading());
  5676. spawn->GetZone()->AddSpawn(pet);
  5677. /*
  5678. const char* spawn_script = world.GetSpawnScript(pet_id);
  5679. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5680. spawn->SetSpawnScript(string(spawn_script));
  5681. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5682. }*/
  5683. // Get a random pet name
  5684. string random_pet_name;
  5685. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5686. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5687. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5688. // Set the pets name
  5689. pet->SetName(random_pet_name.c_str());
  5690. // Set the level of the pet to the owners level
  5691. pet->SetLevel(spawn->GetLevel());
  5692. // Set the faction of the pet to the same faction as the owner
  5693. pet->SetFactionID(spawn->GetFactionID());
  5694. // Set the spawn as a pet
  5695. pet->SetPet(true);
  5696. // Give a pointer of the owner to the pet
  5697. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5698. // Set the pet type
  5699. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  5700. // Set the spell id used to create this pet
  5701. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5702. // Set the spell tier used to create this pet
  5703. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5704. // Set the pets spawn type to 6
  5705. pet->SetSpawnType(6);
  5706. // Set the pets brain
  5707. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  5708. // Check to see if the pet has a subtitle
  5709. if (strlen(pet->GetSubTitle()) > 0) {
  5710. // Add the players name to the front of the sub title
  5711. string pet_subtitle;
  5712. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5713. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5714. // Set the pets subtitle to the new one
  5715. pet->SetSubTitle(pet_subtitle.c_str());
  5716. }
  5717. // Set the pet as the return value for this function
  5718. lua_interface->SetSpawnValue(state, pet);
  5719. return 1;
  5720. }
  5721. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  5722. if (!lua_interface)
  5723. return 0;
  5724. Spawn* spawn = lua_interface->GetSpawn(state);
  5725. Spawn* player = lua_interface->GetSpawn(state, 2);
  5726. float max_distance = lua_interface->GetFloatValue(state, 3);
  5727. string type = lua_interface->GetStringValue(state, 4);
  5728. if (!spawn || (spawn && spawn->IsPlayer())) {
  5729. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  5730. return 0;
  5731. }
  5732. if (!player || (player && !player->IsPlayer())) {
  5733. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  5734. return 0;
  5735. }
  5736. Client* client = 0;
  5737. if (player->GetZone())
  5738. client = player->GetZone()->GetClientBySpawn(player);
  5739. if (!client) {
  5740. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  5741. return 0;
  5742. }
  5743. //Set max_distance to default if not set or not proper value
  5744. if (max_distance <= 0)
  5745. max_distance = 500;
  5746. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  5747. if (packet) {
  5748. float unknown2_3 = 0;
  5749. int8 placement_mode = 0;
  5750. if (type == "wall") {
  5751. placement_mode = 2;
  5752. unknown2_3 = 150;
  5753. }
  5754. else if (type == "ceiling")
  5755. placement_mode = 1;
  5756. packet->setDataByName("placement_mode", placement_mode);
  5757. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  5758. packet->setDataByName("model_type", spawn->GetModelType());
  5759. packet->setDataByName("unknown", 1); //size
  5760. packet->setDataByName("unknown2", 1); //size 2
  5761. packet->setDataByName("unknown2", .5, 1); //size 3
  5762. packet->setDataByName("unknown2", 3, 2);
  5763. packet->setDataByName("unknown2", unknown2_3, 3);
  5764. packet->setDataByName("max_distance", max_distance);
  5765. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  5766. client->QueuePacket(packet->serialize());
  5767. safe_delete(packet);
  5768. }
  5769. return 0;
  5770. }
  5771. int EQ2Emu_lua_GetItemType(lua_State* state) {
  5772. if (!lua_interface)
  5773. return 0;
  5774. Item* item = lua_interface->GetItem(state);
  5775. if (!item) {
  5776. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  5777. return 0;
  5778. }
  5779. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  5780. return 1;
  5781. }
  5782. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  5783. if (!lua_interface)
  5784. return 0;
  5785. Spawn* spawn = lua_interface->GetSpawn(state);
  5786. if (!spawn) {
  5787. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  5788. return 0;
  5789. }
  5790. if (spawn->GetZone())
  5791. spawn->GetZone()->AddTransportSpawn(spawn);
  5792. return 0;
  5793. }
  5794. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  5795. if (!lua_interface)
  5796. return 0;
  5797. Skill* skill = lua_interface->GetSkill(state);
  5798. if (!skill) {
  5799. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5800. return 0;
  5801. }
  5802. lua_interface->SetInt32Value(state, skill->current_val);
  5803. return 1;
  5804. }
  5805. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  5806. if (!lua_interface)
  5807. return 0;
  5808. Skill* skill = lua_interface->GetSkill(state);
  5809. if (!skill) {
  5810. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5811. return 0;
  5812. }
  5813. lua_interface->SetInt32Value(state, skill->max_val);
  5814. return 1;
  5815. }
  5816. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  5817. if (!lua_interface)
  5818. return 0;
  5819. Skill* skill = lua_interface->GetSkill(state);
  5820. if (!skill) {
  5821. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  5822. return 0;
  5823. }
  5824. lua_interface->SetStringValue(state, skill->name.data.c_str());
  5825. return 1;
  5826. }
  5827. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  5828. if (!lua_interface)
  5829. return 0;
  5830. Skill* skill = lua_interface->GetSkill(state);
  5831. int16 value = lua_interface->GetInt16Value(state, 2);
  5832. if (!skill) {
  5833. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5834. return 0;
  5835. }
  5836. skill->max_val = value;
  5837. if (skill->max_val < skill->current_val)
  5838. skill->current_val = skill->max_val;
  5839. return 0;
  5840. }
  5841. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  5842. if (!lua_interface)
  5843. return 0;
  5844. Skill* skill = lua_interface->GetSkill(state);
  5845. int16 value = lua_interface->GetInt16Value(state, 2);
  5846. if (!skill) {
  5847. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5848. return 0;
  5849. }
  5850. if (value > skill->max_val)
  5851. skill->current_val = skill->max_val;
  5852. else
  5853. skill->current_val = value;
  5854. return 0;
  5855. }
  5856. int EQ2Emu_lua_GetSkill(lua_State* state) {
  5857. if (!lua_interface)
  5858. return 0;
  5859. Spawn* spawn = lua_interface->GetSpawn(state);
  5860. string name = lua_interface->GetStringValue(state, 2);
  5861. if (!spawn) {
  5862. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. if (!spawn->IsEntity()) {
  5866. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5867. return 0;
  5868. }
  5869. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  5870. if (skill) {
  5871. lua_interface->SetSkillValue(state, skill);
  5872. return 1;
  5873. }
  5874. return 0;
  5875. }
  5876. int EQ2Emu_lua_AddProc(lua_State* state) {
  5877. if (!lua_interface)
  5878. return 0;
  5879. Spawn* spawn = lua_interface->GetSpawn(state);
  5880. int8 type = lua_interface->GetInt8Value(state, 2);
  5881. float chance = lua_interface->GetFloatValue(state, 3);
  5882. Item* item = lua_interface->GetItem(state, 4);
  5883. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  5884. LuaSpell* spell = 0;
  5885. if (!spawn && (!spell || !use_all_spelltargets)) {
  5886. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  5887. return 0;
  5888. }
  5889. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  5890. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5891. return 0;
  5892. }
  5893. if (!item)
  5894. spell = lua_interface->GetCurrentSpell(state);
  5895. if (!item && !spell) {
  5896. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  5897. return 0;
  5898. }
  5899. if (spell && use_all_spelltargets) {
  5900. Spawn* target;
  5901. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5902. for (int8 i = 0; i < spell->targets.size(); i++) {
  5903. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5904. if (!target || !target->IsEntity())
  5905. continue;
  5906. ((Entity*)target)->AddProc(type, chance, item, spell);
  5907. }
  5908. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5909. }
  5910. else
  5911. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  5912. return 0;
  5913. }
  5914. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  5915. if (!lua_interface)
  5916. return 0;
  5917. Spawn* spawn = lua_interface->GetSpawn(state);
  5918. Item* item = lua_interface->GetItem(state, 2);
  5919. LuaSpell* spell = 0;
  5920. if (!spawn) {
  5921. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  5922. return 0;
  5923. }
  5924. if (!spawn->IsEntity()) {
  5925. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5926. return 0;
  5927. }
  5928. if (!item)
  5929. spell = lua_interface->GetCurrentSpell(state);
  5930. if (!item && !spell) {
  5931. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  5932. return 0;
  5933. }
  5934. if (spell) {
  5935. Spawn* target;
  5936. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5937. for (int8 i = 0; i < spell->targets.size(); i++) {
  5938. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5939. if (!target || !target->IsEntity())
  5940. continue;
  5941. ((Entity*)target)->RemoveProc(item, spell);
  5942. }
  5943. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5944. spell->caster->RemoveProc(item, spell);
  5945. }
  5946. else
  5947. ((Entity*)spawn)->RemoveProc(item, spell);
  5948. return 0;
  5949. }
  5950. int EQ2Emu_lua_Knockback(lua_State* state) {
  5951. if (!lua_interface)
  5952. return 0;
  5953. Spawn* target_spawn = lua_interface->GetSpawn(state);
  5954. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5955. int32 duration = lua_interface->GetInt32Value(state, 3);
  5956. float vertical = lua_interface->GetFloatValue(state, 4);
  5957. float horizontal = lua_interface->GetFloatValue(state, 5);
  5958. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  5959. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5960. if (!target_spawn) {
  5961. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  5962. return 0;
  5963. }
  5964. if (!spawn) {
  5965. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5966. return 0;
  5967. }
  5968. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  5969. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5970. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  5971. if (packet) {
  5972. packet->setDataByName("target_x", target_spawn->GetX());
  5973. packet->setDataByName("target_y", target_spawn->GetY());
  5974. packet->setDataByName("target_z", target_spawn->GetZ());
  5975. packet->setDataByName("vertical_movement", vertical);
  5976. packet->setDataByName("horizontal_movement", horizontal);
  5977. if (use_heading)
  5978. packet->setDataByName("use_player_heading", 1);
  5979. client->QueuePacket(packet->serialize());
  5980. }
  5981. safe_delete(packet);
  5982. }
  5983. return 0;
  5984. }
  5985. int EQ2Emu_lua_IsEpic(lua_State* state) {
  5986. if (!lua_interface)
  5987. return 0;
  5988. Spawn* spawn = lua_interface->GetSpawn(state);
  5989. if (!spawn) {
  5990. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  5991. return 0;
  5992. }
  5993. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  5994. return 1;
  5995. }
  5996. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  5997. if (!lua_interface)
  5998. return 0;
  5999. Spawn* caster = lua_interface->GetSpawn(state);
  6000. Spawn* target = lua_interface->GetSpawn(state, 2);
  6001. string name = lua_interface->GetStringValue(state, 3);
  6002. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6003. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6004. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6005. string success_msg = lua_interface->GetStringValue(state, 7);
  6006. string effect_msg = lua_interface->GetStringValue(state, 8);
  6007. if (!caster) {
  6008. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6009. return 0;
  6010. }
  6011. if (!caster->IsEntity()) {
  6012. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6013. return 0;
  6014. }
  6015. if (!target) {
  6016. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6017. return 0;
  6018. }
  6019. if (!target->IsEntity()) {
  6020. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6021. return 0;
  6022. }
  6023. if (name.length() == 0) {
  6024. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6025. return 0;
  6026. }
  6027. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6028. return 0;
  6029. }
  6030. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6031. if (!lua_interface)
  6032. return 0;
  6033. string name = lua_interface->GetStringValue(state);
  6034. if (name.length() == 0) {
  6035. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6036. return 0;
  6037. }
  6038. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6039. if (!skill) {
  6040. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6041. return 0;
  6042. }
  6043. lua_interface->SetInt32Value(state, skill->skill_id);
  6044. return 1;
  6045. }
  6046. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6047. if (!lua_interface)
  6048. return 0;
  6049. Spawn* spawn = lua_interface->GetSpawn(state);
  6050. if (!spawn) {
  6051. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6052. return 0;
  6053. }
  6054. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6055. return 1;
  6056. }
  6057. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6058. if (!lua_interface)
  6059. return 0;
  6060. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6061. if (!luaspell) {
  6062. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6063. return 0;
  6064. }
  6065. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6066. return 1;
  6067. }
  6068. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6069. if (!lua_interface)
  6070. return 0;
  6071. Spawn* spawn = lua_interface->GetSpawn(state);
  6072. Spawn* target = lua_interface->GetSpawn(state, 2);
  6073. if (!spawn) {
  6074. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6075. return 0;
  6076. }
  6077. if (!spawn->IsEntity()) {
  6078. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6079. return 0;
  6080. }
  6081. if (!target) {
  6082. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6083. return 0;
  6084. }
  6085. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6086. return 1;
  6087. }
  6088. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6089. if (!lua_interface)
  6090. return 0;
  6091. Spawn* spawn = lua_interface->GetSpawn(state);
  6092. Spawn* target = lua_interface->GetSpawn(state, 2);
  6093. if (!spawn) {
  6094. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6095. return 0;
  6096. }
  6097. if (!spawn->IsEntity()) {
  6098. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6099. return 0;
  6100. }
  6101. if (!target) {
  6102. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6103. return 0;
  6104. }
  6105. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6106. return 1;
  6107. }
  6108. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6109. if (!lua_interface)
  6110. return 0;
  6111. Item* item = lua_interface->GetItem(state);
  6112. if (!item) {
  6113. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6114. return 0;
  6115. }
  6116. lua_interface->SetInt32Value(state, item->details.count);
  6117. return 1;
  6118. }
  6119. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6120. if (!lua_interface)
  6121. return 0;
  6122. Item* item = lua_interface->GetItem(state);
  6123. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6124. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6125. if (!item) {
  6126. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6127. return 0;
  6128. }
  6129. if (!owner) {
  6130. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6131. return 0;
  6132. }
  6133. if (!owner->IsPlayer()) {
  6134. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6135. return 0;
  6136. }
  6137. if (item->stack_count < new_count) {
  6138. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6139. return 0;
  6140. }
  6141. if (new_count > 0) {
  6142. item->details.count = new_count;
  6143. item->save_needed = true;
  6144. }
  6145. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6146. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6147. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6148. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6149. else
  6150. {
  6151. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6152. return 0;
  6153. }
  6154. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6155. if (!client)
  6156. return 0;
  6157. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6158. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6159. if (app)
  6160. client->QueuePacket(app);
  6161. return 0;
  6162. }
  6163. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6164. if (!lua_interface)
  6165. return 0;
  6166. int32 time = lua_interface->GetInt32Value(state);
  6167. string function = lua_interface->GetStringValue(state, 2);
  6168. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6169. Spawn* target = lua_interface->GetSpawn(state, 4);
  6170. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6171. if (time == 0) {
  6172. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6173. return 0;
  6174. }
  6175. if (function.length() == 0) {
  6176. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6177. return 0;
  6178. }
  6179. if (!spell) {
  6180. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6181. return 0;
  6182. }
  6183. SpellScriptTimer* timer = new SpellScriptTimer;
  6184. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6185. #ifdef WIN32
  6186. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6187. #else
  6188. bzero(timer, sizeof(SpellScriptTimer));
  6189. #endif*/
  6190. timer->caster = 0;
  6191. timer->deleteWhenDone = false;
  6192. timer->target = 0;
  6193. timer->time = Timer::GetCurrentTime2() + time;
  6194. timer->customFunction = function;
  6195. timer->spell = spell;
  6196. if (caster)
  6197. timer->caster = caster->GetID();
  6198. if (target)
  6199. timer->target = target->GetID();
  6200. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6201. return 0;
  6202. }
  6203. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6204. if (!lua_interface)
  6205. return 0;
  6206. float hp_perc = lua_interface->GetFloatValue(state);
  6207. float power_perc = lua_interface->GetFloatValue(state, 2);
  6208. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6209. Spawn* target = lua_interface->GetSpawn(state, 4);
  6210. string heal_name = lua_interface->GetStringValue(state, 5);
  6211. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6212. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6213. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6214. if (!spell) {
  6215. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6216. return 0;
  6217. }
  6218. Entity* caster = spell->caster;
  6219. if (!caster) {
  6220. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6221. return 0;
  6222. }
  6223. Client* client = 0;
  6224. PendingResurrection* rez = 0;
  6225. ZoneServer* zone = spell->caster->GetZone();
  6226. if (!target) {
  6227. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6228. if (spell->targets.size() > 0) {
  6229. vector<int32> spell_targets = spell->targets;
  6230. for (int8 i = 0; i < spell_targets.size(); i++) {
  6231. target = zone->GetSpawnByID(spell_targets.at(i));
  6232. if (!target)
  6233. continue;
  6234. if (!target->IsPlayer())
  6235. continue;
  6236. client = target->GetZone()->GetClientBySpawn(target);
  6237. if (!client)
  6238. continue;
  6239. rez = client->GetCurrentRez();
  6240. if (rez->active)
  6241. continue;
  6242. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6243. rez->active = true;
  6244. rez->caster = caster;
  6245. rez->expire_timer = new Timer;
  6246. int32 duration = spell->spell->GetSpellDuration();
  6247. rez->expire_timer->Start(duration * 100);
  6248. rez->hp_perc = hp_perc;
  6249. rez->mp_perc = power_perc;
  6250. rez->range = spell->spell->GetSpellData()->range;
  6251. rez->spell_name = spell->spell->GetName();
  6252. if (heal_name.length() > 0)
  6253. rez->heal_name = heal_name;
  6254. else
  6255. rez->heal_name = rez->spell_name;
  6256. rez->no_calcs = no_calcs;
  6257. rez->crit_mod = crit_mod;
  6258. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6259. if (send_window)
  6260. client->SendResurrectionWindow();
  6261. else {
  6262. target->GetZone()->ResurrectSpawn(target, client);
  6263. rez->should_delete = true;
  6264. }
  6265. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6266. }
  6267. }
  6268. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6269. }
  6270. else {
  6271. client = target->GetZone()->GetClientBySpawn(target);
  6272. if (!client)
  6273. return 0;
  6274. rez = client->GetCurrentRez();
  6275. if (rez->active)
  6276. return 0;
  6277. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6278. rez->active = true;
  6279. rez->caster = caster;
  6280. rez->expire_timer = new Timer;
  6281. int32 duration = spell->spell->GetSpellDuration();
  6282. rez->expire_timer->Start(duration * 100);
  6283. rez->hp_perc = hp_perc;
  6284. rez->mp_perc = power_perc;
  6285. rez->range = spell->spell->GetSpellData()->range;
  6286. rez->spell_name = spell->spell->GetName();
  6287. if (heal_name.length() > 0)
  6288. rez->heal_name = heal_name;
  6289. else
  6290. rez->heal_name = rez->spell_name;
  6291. rez->no_calcs = no_calcs;
  6292. rez->crit_mod = crit_mod;
  6293. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6294. if (send_window)
  6295. client->SendResurrectionWindow();
  6296. else {
  6297. target->GetZone()->ResurrectSpawn(target, client);
  6298. rez->should_delete = true;
  6299. }
  6300. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6301. }
  6302. return 0;
  6303. }
  6304. int EQ2Emu_lua_SetVision(lua_State* state) {
  6305. if (!lua_interface)
  6306. return 0;
  6307. Spawn* spawn = lua_interface->GetSpawn(state);
  6308. int8 vision = lua_interface->GetInt8Value(state, 2);
  6309. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6310. if (!spawn) {
  6311. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6312. return 0;
  6313. }
  6314. if (!spawn->IsEntity()) {
  6315. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6316. return 0;
  6317. }
  6318. if (spell && spell->targets.size() > 0) {
  6319. ZoneServer* zone = spell->caster->GetZone();
  6320. for (int8 i = 0; i < spell->targets.size(); i++) {
  6321. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6322. if (target->IsEntity()) {
  6323. ((Entity*)target)->GetInfoStruct()->vision = vision;
  6324. if (target->IsPlayer())
  6325. ((Player*)target)->SetCharSheetChanged(true);
  6326. }
  6327. }
  6328. }
  6329. else {
  6330. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  6331. if (spawn->IsPlayer())
  6332. ((Player*)spawn)->SetCharSheetChanged(true);
  6333. }
  6334. return 0;
  6335. }
  6336. int EQ2Emu_lua_BlurVision(lua_State* state) {
  6337. if (!lua_interface)
  6338. return 0;
  6339. Spawn* spawn = lua_interface->GetSpawn(state);
  6340. float intensity = lua_interface->GetFloatValue(state, 2);
  6341. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6342. if (!spawn) {
  6343. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6344. return 0;
  6345. }
  6346. if (!spawn->IsEntity()) {
  6347. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6348. return 0;
  6349. }
  6350. if (spell && spell->targets.size() > 0) {
  6351. ZoneServer* zone = spell->caster->GetZone();
  6352. for (int8 i = 0; i < spell->targets.size(); i++) {
  6353. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6354. if (target && target->IsEntity()) {
  6355. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  6356. if (target->IsPlayer())
  6357. ((Player*)target)->SetCharSheetChanged(true);
  6358. }
  6359. }
  6360. }
  6361. else {
  6362. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  6363. if (spawn->IsPlayer())
  6364. ((Player*)spawn)->SetCharSheetChanged(true);
  6365. }
  6366. return 0;
  6367. }
  6368. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  6369. if (!lua_interface)
  6370. return 0;
  6371. Spawn* spawn = lua_interface->GetSpawn(state);
  6372. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  6373. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6374. if (!spawn) {
  6375. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  6376. return 0;
  6377. }
  6378. if (!spawn->IsEntity()) {
  6379. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  6380. return 0;
  6381. }
  6382. if (spell && spell->targets.size() > 0) {
  6383. ZoneServer* zone = spell->caster->GetZone();
  6384. for (int8 i = 0; i < spell->targets.size(); i++) {
  6385. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6386. if (target->IsEntity()) {
  6387. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6388. if (target->IsPlayer())
  6389. ((Player*)target)->SetCharSheetChanged(true);
  6390. }
  6391. }
  6392. }
  6393. else {
  6394. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6395. if (spawn->IsPlayer())
  6396. ((Player*)spawn)->SetCharSheetChanged(true);
  6397. }
  6398. return 0;
  6399. }
  6400. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  6401. if (!lua_interface)
  6402. return 0;
  6403. Item* item = lua_interface->GetItem(state);
  6404. int8 type = lua_interface->GetInt32Value(state, 2);
  6405. if (!item) {
  6406. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  6407. return 0;
  6408. }
  6409. if (type == 1)
  6410. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  6411. else if (type == 2)
  6412. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  6413. return 1;
  6414. }
  6415. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  6416. if (!lua_interface)
  6417. return 0;
  6418. Spawn* target = lua_interface->GetSpawn(state);
  6419. float val = lua_interface->GetFloatValue(state, 2);
  6420. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6421. // Added from Gangrenous post
  6422. if (spell && spell->resisted)
  6423. return 0;
  6424. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  6425. if (val > 1.0f)
  6426. val = 1.0f - (val / 100.0f);
  6427. if (spell && spell->spell && spell->targets.size() > 0) {
  6428. ZoneServer* zone = spell->caster->GetZone();
  6429. for (int32 i = 0; i != spell->targets.size(); i++) {
  6430. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  6431. if (spawn && spawn->IsEntity()) {
  6432. ((Entity*)spawn)->SetSpeedMultiplier(val);
  6433. if (spawn->IsPlayer())
  6434. ((Player*)spawn)->SetCharSheetChanged(true);
  6435. }
  6436. }
  6437. }
  6438. else {
  6439. if (target && target->IsEntity()) {
  6440. ((Entity*)target)->SetSpeedMultiplier(val);
  6441. if (target->IsPlayer())
  6442. ((Player*)target)->SetCharSheetChanged(true);
  6443. }
  6444. }
  6445. return 0;
  6446. }
  6447. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  6448. if (!lua_interface)
  6449. return 0;
  6450. Spawn* spawn = lua_interface->GetSpawn(state);
  6451. int16 model = lua_interface->GetInt16Value(state, 2);
  6452. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6453. if (spell && spell->spell && spell->targets.size() > 0) {
  6454. ZoneServer* zone = spell->caster->GetZone();
  6455. for (int32 i = 0; i < spell->targets.size(); i++) {
  6456. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6457. if (target)
  6458. target->SetIllusionModel(model);
  6459. }
  6460. }
  6461. else {
  6462. if (!spawn) {
  6463. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6464. return 0;
  6465. }
  6466. spawn->SetIllusionModel(model);
  6467. }
  6468. return 0;
  6469. }
  6470. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  6471. if (!lua_interface)
  6472. return 0;
  6473. Spawn* spawn = lua_interface->GetSpawn(state);
  6474. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6475. if (spell && spell->spell && spell->targets.size() > 0) {
  6476. ZoneServer* zone = spell->caster->GetZone();
  6477. for (int32 i = 0; i < spell->targets.size(); i++) {
  6478. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6479. if (target)
  6480. target->SetIllusionModel(0);
  6481. }
  6482. }
  6483. else {
  6484. if (!spawn) {
  6485. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6486. return 0;
  6487. }
  6488. spawn->SetIllusionModel(0);
  6489. }
  6490. return 0;
  6491. }
  6492. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  6493. if (!lua_interface)
  6494. return 0;
  6495. Spawn* caster = lua_interface->GetSpawn(state);
  6496. Spawn* target = lua_interface->GetSpawn(state, 2);
  6497. float chance = lua_interface->GetFloatValue(state, 3);
  6498. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6499. if (!caster) {
  6500. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6501. return 0;
  6502. }
  6503. if (!caster->IsEntity()) {
  6504. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  6505. return 0;
  6506. }
  6507. if (!target) {
  6508. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6509. return 0;
  6510. }
  6511. if (!target->IsEntity()) {
  6512. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  6513. return 0;
  6514. }
  6515. if (chance <= 0) {
  6516. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  6517. return 0;
  6518. }
  6519. if (!spell) {
  6520. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6521. return 0;
  6522. }
  6523. if (((Entity*)caster)->GetThreatTransfer()) {
  6524. return 0;
  6525. }
  6526. ThreatTransfer* transfer = new ThreatTransfer;
  6527. transfer->Target = target->GetID();
  6528. transfer->Amount = chance;
  6529. transfer->Spell = spell;
  6530. ((Entity*)caster)->SetThreatTransfer(transfer);
  6531. return 0;
  6532. }
  6533. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  6534. if (!lua_interface)
  6535. return 0;
  6536. Spawn* spawn = lua_interface->GetSpawn(state);
  6537. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6538. if (!spawn) {
  6539. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6540. return 0;
  6541. }
  6542. if (!spell) {
  6543. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6544. return 0;
  6545. }
  6546. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  6547. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  6548. safe_delete(transfer);
  6549. ((Entity*)spawn)->SetThreatTransfer(0);
  6550. }
  6551. return 0;
  6552. }
  6553. int EQ2Emu_lua_CureByType(lua_State* state) {
  6554. if (!lua_interface)
  6555. return 0;
  6556. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6557. if (!spell) {
  6558. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6559. return 0;
  6560. }
  6561. int8 cure_count = lua_interface->GetInt8Value(state);
  6562. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  6563. string cure_name = lua_interface->GetStringValue(state, 3);
  6564. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  6565. Spawn* target = lua_interface->GetSpawn(state, 5);
  6566. if (target) {
  6567. if (!target->IsEntity()) {
  6568. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  6569. return 0;
  6570. }
  6571. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  6572. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6573. }
  6574. else {
  6575. ZoneServer* zone = spell->caster->GetZone();
  6576. vector<int32> targets = spell->targets;
  6577. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6578. for (int8 i = 0; i < targets.size(); i++) {
  6579. target = zone->GetSpawnByID(targets.at(i));
  6580. if (!target || !target->IsEntity())
  6581. continue;
  6582. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  6583. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6584. }
  6585. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6586. }
  6587. return 0;
  6588. }
  6589. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  6590. if (!lua_interface)
  6591. return 0;
  6592. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6593. if (!spell) {
  6594. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6595. return 0;
  6596. }
  6597. int8 cure_count = lua_interface->GetInt8Value(state);
  6598. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  6599. string cure_name = lua_interface->GetStringValue(state, 3);
  6600. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  6601. Spawn* target = lua_interface->GetSpawn(state, 5);
  6602. if (target) {
  6603. if (!target->IsEntity()) {
  6604. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  6605. return 0;
  6606. }
  6607. if (((Entity*)target)->GetDetCount() > 0)
  6608. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6609. }
  6610. else {
  6611. ZoneServer* zone = spell->caster->GetZone();
  6612. vector<int32> targets = spell->targets;
  6613. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6614. for (int8 i = 0; i < targets.size(); i++) {
  6615. target = zone->GetSpawnByID(targets.at(i));
  6616. if (!target || !target->IsEntity())
  6617. continue;
  6618. if (((Entity*)target)->GetDetCount() > 0)
  6619. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6620. }
  6621. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6622. }
  6623. return 0;
  6624. }
  6625. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  6626. if (!lua_interface)
  6627. return 0;
  6628. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6629. if (!spell) {
  6630. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  6631. return 0;
  6632. }
  6633. if (!spell->caster) {
  6634. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  6635. return 0;
  6636. }
  6637. if (!spell->caster->GetZone()) {
  6638. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  6639. return 0;
  6640. }
  6641. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  6642. return 0;
  6643. }
  6644. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  6645. if (!lua_interface)
  6646. return 0;
  6647. Spawn* spawn = lua_interface->GetSpawn(state);
  6648. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6649. if (!spell) {
  6650. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6651. return 0;
  6652. }
  6653. if (spawn && spawn->IsEntity())
  6654. ((Entity*)spawn)->RemoveStealthSpell(spell);
  6655. else {
  6656. ZoneServer* zone = spell->caster->GetZone();
  6657. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6658. for (int32 i = 0; i < spell->targets.size(); i++) {
  6659. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6660. if (!spawn || !spawn->IsEntity())
  6661. continue;
  6662. ((Entity*)spawn)->RemoveStealthSpell(spell);
  6663. }
  6664. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6665. }
  6666. return 0;
  6667. }
  6668. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  6669. if (!lua_interface)
  6670. return 0;
  6671. Spawn* spawn = lua_interface->GetSpawn(state);
  6672. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6673. if (!spell) {
  6674. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  6675. return 0;
  6676. }
  6677. if (spawn && spawn->IsEntity())
  6678. ((Entity*)spawn)->RemoveInvisSpell(spell);
  6679. else {
  6680. ZoneServer* zone = spell->caster->GetZone();
  6681. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6682. for (int32 i = 0; i < spell->targets.size(); i++) {
  6683. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6684. if (!spawn || !spawn->IsEntity())
  6685. continue;
  6686. ((Entity*)spawn)->RemoveInvisSpell(spell);
  6687. }
  6688. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6689. }
  6690. return 0;
  6691. }
  6692. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  6693. if (!lua_interface)
  6694. return 0;
  6695. Spawn* caster = lua_interface->GetSpawn(state);
  6696. int8 class_id = lua_interface->GetInt8Value(state, 2);
  6697. if (!caster) {
  6698. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  6699. return 0;
  6700. }
  6701. if (!caster->IsPlayer()) {
  6702. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  6703. return 0;
  6704. }
  6705. Spawn* target = caster->GetTarget();
  6706. if (!target) {
  6707. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  6708. return 0;
  6709. }
  6710. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  6711. if (!client) {
  6712. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  6713. return 0;
  6714. }
  6715. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  6716. if (ho) {
  6717. ho->SetTarget(target->GetID());
  6718. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  6719. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  6720. if (((Entity*)caster)->GetGroupMemberInfo()) {
  6721. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  6722. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  6723. deque<GroupMemberInfo*>::iterator itr;
  6724. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  6725. for (itr = members->begin(); itr != members->end(); itr++) {
  6726. if ((*itr)->client)
  6727. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  6728. }
  6729. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  6730. }
  6731. else
  6732. safe_delete(ho);
  6733. }
  6734. else {
  6735. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  6736. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  6737. }
  6738. else
  6739. safe_delete(ho);
  6740. }
  6741. }
  6742. return 0;
  6743. }
  6744. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  6745. if (!lua_interface)
  6746. return 0;
  6747. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6748. if (!spell) {
  6749. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6750. return 0;
  6751. }
  6752. int16 triggerCount = lua_interface->GetInt16Value(state);
  6753. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  6754. if (!triggerCount) {
  6755. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  6756. return 0;
  6757. }
  6758. spell->num_triggers = triggerCount;
  6759. spell->had_triggers = true;
  6760. spell->cancel_after_all_triggers = cancel_after_triggers;
  6761. return 0;
  6762. }
  6763. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  6764. if (!lua_interface)
  6765. return 0;
  6766. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6767. if (!spell) {
  6768. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6769. return 0;
  6770. }
  6771. lua_interface->SetInt32Value(state, spell->num_triggers);
  6772. return 1;
  6773. }
  6774. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  6775. if (!lua_interface)
  6776. return 0;
  6777. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6778. if (!spell) {
  6779. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6780. return 0;
  6781. }
  6782. int16 remove_count = lua_interface->GetInt16Value(state);
  6783. if (!remove_count)
  6784. remove_count = 1;
  6785. if (remove_count >= spell->num_triggers) {
  6786. spell->num_triggers = 0;
  6787. if (spell->cancel_after_all_triggers)
  6788. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  6789. }
  6790. else {
  6791. spell->num_triggers -= remove_count;
  6792. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  6793. }
  6794. return 0;
  6795. }
  6796. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  6797. if (!lua_interface)
  6798. return 0;
  6799. Spawn* spawn = lua_interface->GetSpawn(state);
  6800. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  6801. if (!spawn) {
  6802. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  6803. return 0;
  6804. }
  6805. if (!copy_spawn) {
  6806. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  6807. return 0;
  6808. }
  6809. spawn->CopySpawnAppearance(copy_spawn);
  6810. return 0;
  6811. }
  6812. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  6813. if (!lua_interface)
  6814. return 0;
  6815. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6816. int8 type = lua_interface->GetInt8Value(state);
  6817. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6818. if (!spell) {
  6819. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  6820. return 0;
  6821. }
  6822. if (spawn) {
  6823. if (!spawn->IsEntity()) {
  6824. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  6825. return 0;
  6826. }
  6827. Entity* entity = ((Entity*)spawn);
  6828. switch (type) {
  6829. case IMMUNITY_TYPE_AOE:
  6830. entity->AddAOEImmunity(spell);
  6831. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  6832. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  6833. break;
  6834. case IMMUNITY_TYPE_STUN:
  6835. entity->AddStunImmunity(spell);
  6836. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  6837. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  6838. break;
  6839. case IMMUNITY_TYPE_ROOT:
  6840. entity->AddRootImmunity(spell);
  6841. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  6842. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  6843. break;
  6844. case IMMUNITY_TYPE_DAZE:
  6845. entity->AddDazeImmunity(spell);
  6846. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  6847. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  6848. break;
  6849. case IMMUNITY_TYPE_FEAR:
  6850. entity->AddFearImmunity(spell);
  6851. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  6852. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  6853. break;
  6854. case IMMUNITY_TYPE_MEZ:
  6855. entity->AddMezImmunity(spell);
  6856. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  6857. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  6858. break;
  6859. case IMMUNITY_TYPE_STIFLE:
  6860. entity->AddStifleImmunity(spell);
  6861. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  6862. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  6863. break;
  6864. default:
  6865. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6866. }
  6867. }
  6868. else {
  6869. bool should_break = false;
  6870. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6871. for (int8 i = 0; i < spell->targets.size(); i++) {
  6872. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6873. if (!spawn || !spawn->IsEntity())
  6874. continue;
  6875. Entity* entity = ((Entity*)spawn);
  6876. switch (type) {
  6877. case IMMUNITY_TYPE_AOE:
  6878. entity->AddAOEImmunity(spell);
  6879. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  6880. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  6881. break;
  6882. case IMMUNITY_TYPE_STUN:
  6883. entity->AddStunImmunity(spell);
  6884. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  6885. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  6886. break;
  6887. case IMMUNITY_TYPE_ROOT:
  6888. entity->AddRootImmunity(spell);
  6889. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  6890. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  6891. break;
  6892. case IMMUNITY_TYPE_DAZE:
  6893. entity->AddDazeImmunity(spell);
  6894. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  6895. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  6896. break;
  6897. case IMMUNITY_TYPE_FEAR:
  6898. entity->AddFearImmunity(spell);
  6899. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  6900. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  6901. break;
  6902. case IMMUNITY_TYPE_MEZ:
  6903. entity->AddMezImmunity(spell);
  6904. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  6905. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  6906. break;
  6907. case IMMUNITY_TYPE_STIFLE:
  6908. entity->AddStifleImmunity(spell);
  6909. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  6910. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  6911. break;
  6912. default:
  6913. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6914. should_break = true;
  6915. }
  6916. if (should_break)
  6917. break;
  6918. }
  6919. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6920. }
  6921. return 0;
  6922. }
  6923. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  6924. if (!lua_interface)
  6925. return 0;
  6926. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6927. int8 type = lua_interface->GetInt8Value(state);
  6928. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6929. if (!spell) {
  6930. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  6931. return 0;
  6932. }
  6933. if (spawn) {
  6934. if (!spawn->IsEntity()) {
  6935. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  6936. return 0;
  6937. }
  6938. Entity* entity = ((Entity*)spawn);
  6939. switch (type) {
  6940. case IMMUNITY_TYPE_AOE:
  6941. entity->RemoveAOEImmunity(spell);
  6942. break;
  6943. case IMMUNITY_TYPE_STUN:
  6944. entity->RemoveStunImmunity(spell);
  6945. break;
  6946. case IMMUNITY_TYPE_ROOT:
  6947. entity->RemoveRootImmunity(spell);
  6948. break;
  6949. case IMMUNITY_TYPE_DAZE:
  6950. entity->RemoveDazeImmunity(spell);
  6951. break;
  6952. case IMMUNITY_TYPE_FEAR:
  6953. entity->RemoveFearImmunity(spell);
  6954. break;
  6955. case IMMUNITY_TYPE_MEZ:
  6956. entity->RemoveMezImmunity(spell);
  6957. break;
  6958. case IMMUNITY_TYPE_STIFLE:
  6959. entity->RemoveStifleImmunity(spell);
  6960. break;
  6961. default:
  6962. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6963. }
  6964. }
  6965. else {
  6966. bool should_break = false;
  6967. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6968. for (int8 i = 0; i < spell->targets.size(); i++) {
  6969. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6970. if (!spawn || !spawn->IsEntity())
  6971. continue;
  6972. Entity* entity = ((Entity*)spawn);
  6973. switch (type) {
  6974. case IMMUNITY_TYPE_AOE:
  6975. entity->RemoveAOEImmunity(spell);
  6976. break;
  6977. case IMMUNITY_TYPE_STUN:
  6978. entity->RemoveStunImmunity(spell);
  6979. break;
  6980. case IMMUNITY_TYPE_ROOT:
  6981. entity->RemoveRootImmunity(spell);
  6982. break;
  6983. case IMMUNITY_TYPE_DAZE:
  6984. entity->RemoveDazeImmunity(spell);
  6985. break;
  6986. case IMMUNITY_TYPE_FEAR:
  6987. entity->RemoveFearImmunity(spell);
  6988. break;
  6989. case IMMUNITY_TYPE_MEZ:
  6990. entity->RemoveMezImmunity(spell);
  6991. break;
  6992. case IMMUNITY_TYPE_STIFLE:
  6993. entity->RemoveStifleImmunity(spell);
  6994. break;
  6995. default:
  6996. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6997. should_break = true;
  6998. }
  6999. if (should_break)
  7000. break;
  7001. }
  7002. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7003. }
  7004. return 0;
  7005. }
  7006. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7007. if (!lua_interface)
  7008. return 0;
  7009. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7010. if (!spell) {
  7011. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7012. return 0;
  7013. }
  7014. float snare = lua_interface->GetFloatValue(state);
  7015. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7016. // convert the val to the speed multipler value (100 - val)
  7017. float val = 100.0 - snare;
  7018. val /= 100.0;
  7019. if (spawn) {
  7020. if (!spawn->IsEntity()) {
  7021. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7022. return 0;
  7023. }
  7024. ((Entity*)spawn)->SetSnareValue(spell, val);
  7025. }
  7026. else {
  7027. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7028. for (int8 i = 0; i < spell->targets.size(); i++) {
  7029. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7030. if (!spawn || !spawn->IsEntity())
  7031. continue;
  7032. ((Entity*)spawn)->SetSnareValue(spell, val);
  7033. }
  7034. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7035. }
  7036. return 0;
  7037. }
  7038. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7039. if (!lua_interface)
  7040. return 0;
  7041. Spawn* spawn = lua_interface->GetSpawn(state);
  7042. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7043. if (!spawn) {
  7044. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7045. return 0;
  7046. }
  7047. if (race_id == 0) {
  7048. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7049. return 0;
  7050. }
  7051. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7052. return 1;
  7053. }
  7054. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7055. if (!lua_interface)
  7056. return 0;
  7057. Spawn* spawn = lua_interface->GetSpawn(state);
  7058. if (!spawn) {
  7059. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7060. return 0;
  7061. }
  7062. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7063. return 1;
  7064. }
  7065. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7066. if (!lua_interface)
  7067. return 0;
  7068. Spawn* spawn = lua_interface->GetSpawn(state);
  7069. if (!spawn) {
  7070. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7071. return 0;
  7072. }
  7073. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7074. return 1;
  7075. }
  7076. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7077. if (!lua_interface)
  7078. return 0;
  7079. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7080. if (!spell) {
  7081. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7082. return 0;
  7083. }
  7084. lua_interface->SetStringValue(state, spell->spell->GetName());
  7085. return 1;
  7086. }
  7087. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7088. if (!lua_interface)
  7089. return 0;
  7090. Quest* quest = lua_interface->GetQuest(state);
  7091. if (!quest) {
  7092. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7093. return 0;
  7094. }
  7095. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7096. return 1;
  7097. }
  7098. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7099. if (!lua_interface)
  7100. return 0;
  7101. Quest* quest = lua_interface->GetQuest(state);
  7102. int32 flags = lua_interface->GetInt32Value(state, 2);
  7103. if (!quest) {
  7104. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7105. return 0;
  7106. }
  7107. quest->SetQuestFlags(flags);
  7108. return 0;
  7109. }
  7110. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7111. if (!lua_interface)
  7112. return 0;
  7113. Quest* quest = lua_interface->GetQuest(state);
  7114. Spawn* player = lua_interface->GetSpawn(state, 2);
  7115. int32 step = lua_interface->GetInt32Value(state, 3);
  7116. int32 duration = lua_interface->GetInt32Value(state, 4);
  7117. string action = lua_interface->GetStringValue(state, 5);
  7118. if (!quest) {
  7119. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7120. return 0;
  7121. }
  7122. if (!player) {
  7123. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7124. return 0;
  7125. }
  7126. if (!player->IsPlayer()) {
  7127. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7128. return 0;
  7129. }
  7130. if (step == 0) {
  7131. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7132. return 0;
  7133. }
  7134. if (duration == 0) {
  7135. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7136. return 0;
  7137. }
  7138. if (action.length() == 0) {
  7139. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7140. return 0;
  7141. }
  7142. Client* client = player->GetZone()->GetClientBySpawn(player);
  7143. if (!client) {
  7144. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7145. return 0;
  7146. }
  7147. quest->SetTimerStep(step);
  7148. quest->AddFailedAction(step, action);
  7149. quest->SetStepTimer(duration);
  7150. client->AddQuestTimer(quest->GetQuestID());
  7151. return 0;
  7152. }
  7153. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7154. if (!lua_interface)
  7155. return 0;
  7156. Quest* quest = lua_interface->GetQuest(state);
  7157. Spawn* player = lua_interface->GetSpawn(state, 2);
  7158. if (!quest) {
  7159. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7160. return 0;
  7161. }
  7162. if (!player) {
  7163. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7164. return 0;
  7165. }
  7166. if (!player->IsPlayer()) {
  7167. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7168. return 0;
  7169. }
  7170. Client* client = player->GetZone()->GetClientBySpawn(player);
  7171. if (!client) {
  7172. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7173. return 0;
  7174. }
  7175. quest->SetTimerStep(0);
  7176. quest->SetStepTimer(0);
  7177. client->RemoveQuestTimer(quest->GetQuestID());
  7178. return 0;
  7179. }
  7180. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7181. if (!lua_interface)
  7182. return 0;
  7183. Spawn* player = lua_interface->GetSpawn(state);
  7184. Quest* quest = lua_interface->GetQuest(state, 2);
  7185. int32 step = lua_interface->GetInt32Value(state, 3);
  7186. if (!player) {
  7187. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7188. return 0;
  7189. }
  7190. if (!player->IsPlayer()) {
  7191. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7192. return 0;
  7193. }
  7194. if (!quest) {
  7195. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7196. return 0;
  7197. }
  7198. if (step == 0) {
  7199. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7200. return 0;
  7201. }
  7202. Client* client = player->GetZone()->GetClientBySpawn(player);
  7203. if (!client) {
  7204. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7205. return 0;
  7206. }
  7207. if (quest->RemoveQuestStep(step, client)) {
  7208. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7209. client->GetCurrentZone()->SendQuestUpdates(client);
  7210. }
  7211. else
  7212. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7213. return 0;
  7214. }
  7215. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7216. if (!lua_interface)
  7217. return 0;
  7218. Quest* quest = lua_interface->GetQuest(state, 1);
  7219. int32 step = lua_interface->GetInt32Value(state, 2);
  7220. string desc = lua_interface->GetStringValue(state, 3);
  7221. string task_group = lua_interface->GetStringValue(state, 4);
  7222. if (!quest) {
  7223. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7224. return 0;
  7225. }
  7226. if (step == 0) {
  7227. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7228. return 0;
  7229. }
  7230. QuestStep* quest_step = quest->GetQuestStep(step);
  7231. if (!quest_step) {
  7232. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7233. return 0;
  7234. }
  7235. quest_step->SetStepProgress(0);
  7236. quest_step->SetTaskGroup(task_group);
  7237. quest_step->SetDescription(desc);
  7238. return 0;
  7239. }
  7240. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7241. if (!lua_interface)
  7242. return 0;
  7243. Quest* quest = lua_interface->GetQuest(state);
  7244. int32 step = lua_interface->GetInt32Value(state, 2);
  7245. string action = lua_interface->GetStringValue(state, 3);
  7246. if (!quest) {
  7247. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7248. return 0;
  7249. }
  7250. if (step == 0) {
  7251. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  7252. return 0;
  7253. }
  7254. if (action.length() == 0) {
  7255. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  7256. return 0;
  7257. }
  7258. quest->AddFailedAction(step, action);
  7259. return 0;
  7260. }
  7261. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  7262. if (!lua_interface)
  7263. return 0;
  7264. Spawn* player = lua_interface->GetSpawn(state);
  7265. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7266. int32 step = lua_interface->GetInt32Value(state, 3);
  7267. if (!player) {
  7268. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7269. return 0;
  7270. }
  7271. if (!player->IsPlayer()) {
  7272. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7273. return 0;
  7274. }
  7275. if (quest_id == 0) {
  7276. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  7277. return 0;
  7278. }
  7279. if (step == 0) {
  7280. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  7281. return 0;
  7282. }
  7283. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  7284. if (!quest) {
  7285. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  7286. return 0;
  7287. }
  7288. quest->StepFailed(step);
  7289. return 0;
  7290. }
  7291. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  7292. if (!lua_interface)
  7293. return 0;
  7294. Spawn* player = lua_interface->GetSpawn(state);
  7295. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7296. if (!player) {
  7297. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  7298. return 0;
  7299. }
  7300. if (!player->IsPlayer()) {
  7301. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  7302. return 0;
  7303. }
  7304. if (quest_id == 0) {
  7305. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  7306. return 0;
  7307. }
  7308. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  7309. if (!quest) {
  7310. lua_interface->SetInt32Value(state, 0);
  7311. return 1;
  7312. }
  7313. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  7314. return 1;
  7315. }
  7316. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  7317. if (!lua_interface)
  7318. return 0;
  7319. string name = lua_interface->GetStringValue(state);
  7320. string value = lua_interface->GetStringValue(state, 2);
  7321. string comment = lua_interface->GetStringValue(state, 3);
  7322. if (name.length() == 0) {
  7323. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7324. return 0;
  7325. }
  7326. if (value.length() == 0) {
  7327. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  7328. return 0;
  7329. }
  7330. string varname = string("lua_").append(name);
  7331. Variable* var = variables.FindVariable(varname);
  7332. if (var)
  7333. var->SetValue(value.c_str());
  7334. else {
  7335. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  7336. variables.AddVariable(var);
  7337. }
  7338. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  7339. return 0;
  7340. }
  7341. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  7342. if (!lua_interface)
  7343. return 0;
  7344. string name = lua_interface->GetStringValue(state);
  7345. if (name.length() == 0) {
  7346. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7347. return 0;
  7348. }
  7349. string varname = string("lua_").append(name);
  7350. Variable* var = variables.FindVariable(varname);
  7351. if (var)
  7352. lua_interface->SetStringValue(state, var->GetValue());
  7353. else
  7354. lua_interface->SetStringValue(state, "NULL");
  7355. return 1;
  7356. }
  7357. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  7358. if (!lua_interface)
  7359. return 0;
  7360. Spawn* player = lua_interface->GetSpawn(state);
  7361. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7362. if (!player) {
  7363. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7364. return 0;
  7365. }
  7366. if (!player->IsPlayer()) {
  7367. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7368. return 0;
  7369. }
  7370. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  7371. return 1;
  7372. }
  7373. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  7374. if (!lua_interface)
  7375. return 0;
  7376. Spawn* player = lua_interface->GetSpawn(state);
  7377. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7378. if (!player) {
  7379. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7380. return 0;
  7381. }
  7382. if (!player->IsPlayer()) {
  7383. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7384. return 0;
  7385. }
  7386. Language* language = master_languages_list.GetLanguage(language_id);
  7387. if (language)
  7388. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  7389. return 0;
  7390. }
  7391. int EQ2Emu_lua_IsNight(lua_State* state) {
  7392. if (!lua_interface)
  7393. return 0;
  7394. ZoneServer* zone = lua_interface->GetZone(state);
  7395. if (!zone) {
  7396. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  7397. return 0;
  7398. }
  7399. lua_interface->SetBooleanValue(state, zone->IsDusk());
  7400. return 1;
  7401. }
  7402. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  7403. if (!lua_interface)
  7404. return 0;
  7405. Spawn* spawn = lua_interface->GetSpawn(state);
  7406. if (!spawn) {
  7407. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  7408. return 0;
  7409. }
  7410. if (!spawn->IsWidget()) {
  7411. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  7412. return 0;
  7413. }
  7414. ((Widget*)spawn)->SetMultiFloorLift(true);
  7415. if (spawn->GetZone())
  7416. spawn->GetZone()->AddTransportSpawn(spawn);
  7417. return 0;
  7418. }
  7419. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  7420. if (!lua_interface)
  7421. return 0;
  7422. Spawn* player = lua_interface->GetSpawn(state);
  7423. int32 path = lua_interface->GetInt32Value(state, 2);
  7424. if (!player) {
  7425. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7426. return 0;
  7427. }
  7428. if (!player->IsPlayer()) {
  7429. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7430. return 0;
  7431. }
  7432. if (path == 0) {
  7433. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  7434. return 0;
  7435. }
  7436. Client* client = player->GetZone()->GetClientBySpawn(player);
  7437. if (!client) {
  7438. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7439. return 0;
  7440. }
  7441. client->SetPendingFlightPath(path);
  7442. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  7443. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  7444. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  7445. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", client->GetVersion());
  7446. if (packet) {
  7447. client->QueuePacket(packet->serialize());
  7448. safe_delete(packet);
  7449. }
  7450. return 0;
  7451. }
  7452. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  7453. if (!lua_interface)
  7454. return 0;
  7455. Spawn* player = lua_interface->GetSpawn(state);
  7456. if (!player) {
  7457. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7458. return 0;
  7459. }
  7460. if (!player->IsPlayer()) {
  7461. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7462. return 0;
  7463. }
  7464. Client* client = player->GetZone()->GetClientBySpawn(player);
  7465. if (!client) {
  7466. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7467. return 0;
  7468. }
  7469. client->EndAutoMount();
  7470. return 0;
  7471. }
  7472. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  7473. if (!lua_interface)
  7474. return 0;
  7475. Spawn* player = lua_interface->GetSpawn(state);
  7476. if (!player) {
  7477. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  7478. return 0;
  7479. }
  7480. if (!player->IsPlayer()) {
  7481. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7482. return 0;
  7483. }
  7484. Client* client = player->GetZone()->GetClientBySpawn(player);
  7485. if (!client) {
  7486. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7487. return 0;
  7488. }
  7489. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  7490. return 1;
  7491. }
  7492. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  7493. if (!lua_interface)
  7494. return 0;
  7495. Spawn* player = lua_interface->GetSpawn(state);
  7496. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7497. int32 value = lua_interface->GetInt32Value(state, 3);
  7498. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7499. if (!player) {
  7500. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7501. return 0;
  7502. }
  7503. if (!player->IsPlayer()) {
  7504. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  7505. return 0;
  7506. }
  7507. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  7508. return 0;
  7509. }
  7510. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  7511. if (!lua_interface)
  7512. return 0;
  7513. Spawn* player = lua_interface->GetSpawn(state);
  7514. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7515. if (!player) {
  7516. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7517. return 0;
  7518. }
  7519. if (!player->IsPlayer()) {
  7520. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  7521. return 0;
  7522. }
  7523. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  7524. if (!hd)
  7525. return 0;
  7526. lua_interface->SetInt32Value(state, hd->Value);
  7527. lua_interface->SetInt32Value(state, hd->Value2);
  7528. return 2;
  7529. }
  7530. int EQ2Emu_lua_SetGridID(lua_State* state) {
  7531. if (!lua_interface)
  7532. return 0;
  7533. Spawn* spawn = lua_interface->GetSpawn(state);
  7534. int32 grid = lua_interface->GetInt32Value(state, 2);
  7535. if (!spawn) {
  7536. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  7537. return 0;
  7538. }
  7539. if (grid == 0) {
  7540. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  7541. return 0;
  7542. }
  7543. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  7544. return 0;
  7545. }
  7546. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  7547. if (!lua_interface)
  7548. return 0;
  7549. Spawn* spawn = lua_interface->GetSpawn(state);
  7550. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7551. int32 value1 = lua_interface->GetInt32Value(state, 3);
  7552. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7553. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  7554. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  7555. if (!spawn) {
  7556. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7557. return 0;
  7558. }
  7559. //Add this quest to the list of required quests for this spawn
  7560. spawn->SetRequiredHistory(event_id, value1, value2);
  7561. //If private spawn value set
  7562. if (private_spawn) {
  7563. //Set the spawn to be private when not granted access via history
  7564. spawn->AddAllowAccessSpawn(spawn);
  7565. spawn->SetPrivateQuestSpawn(true);
  7566. }
  7567. //This value will override vis_flags in the vis packet
  7568. if (flag_override > 0)
  7569. spawn->SetQuestsRequiredOverride(flag_override);
  7570. return 0;
  7571. }
  7572. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  7573. if (!lua_interface)
  7574. return 0;
  7575. Spawn* player = lua_interface->GetSpawn(state);
  7576. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7577. int32 step_id = lua_interface->GetInt32Value(state, 3);
  7578. if (!player) {
  7579. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  7580. return 0;
  7581. }
  7582. if (!player->IsPlayer()) {
  7583. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  7584. return 0;
  7585. }
  7586. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  7587. return 1;
  7588. }
  7589. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  7590. if (!lua_interface)
  7591. return 0;
  7592. Spawn* player = lua_interface->GetSpawn(state);
  7593. int8 level = lua_interface->GetInt8Value(state, 2);
  7594. if (!player) {
  7595. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  7596. return 0;
  7597. }
  7598. if (!player->IsPlayer()) {
  7599. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  7600. return 0;
  7601. }
  7602. if (level == 0) {
  7603. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  7604. return 0;
  7605. }
  7606. Client* client = player->GetZone()->GetClientBySpawn(player);
  7607. if (!client) {
  7608. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  7609. return 0;
  7610. }
  7611. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  7612. client->GetPlayer()->SetXP(1);
  7613. client->GetPlayer()->SetNeededXP();
  7614. return 0;
  7615. }
  7616. int EQ2Emu_lua_AddCoin(lua_State* state) {
  7617. if (!lua_interface)
  7618. return 0;
  7619. Spawn* player = lua_interface->GetSpawn(state);
  7620. int32 amount = lua_interface->GetInt32Value(state, 2);
  7621. if (!player) {
  7622. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  7623. return 0;
  7624. }
  7625. if (!player->IsPlayer()) {
  7626. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  7627. return 0;
  7628. }
  7629. if (amount == 0) {
  7630. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  7631. return 0;
  7632. }
  7633. ((Player*)player)->AddCoins(amount);
  7634. return 0;
  7635. }
  7636. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  7637. if (!lua_interface)
  7638. return 0;
  7639. Spawn* player = lua_interface->GetSpawn(state);
  7640. int32 amount = lua_interface->GetInt32Value(state, 2);
  7641. if (!player) {
  7642. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  7643. return 0;
  7644. }
  7645. if (!player->IsPlayer()) {
  7646. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  7647. return 0;
  7648. }
  7649. if (amount == 0) {
  7650. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  7651. return 0;
  7652. }
  7653. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  7654. return 1;
  7655. }
  7656. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  7657. if (!lua_interface)
  7658. return 0;
  7659. ZoneServer* zone = lua_interface->GetZone(state);
  7660. if (!zone) {
  7661. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  7662. return 0;
  7663. }
  7664. vector<Entity*> players = zone->GetPlayers();
  7665. if (players.size() == 0)
  7666. return 0;
  7667. lua_createtable(state, players.size(), 0);
  7668. int newTable = lua_gettop(state);
  7669. for (int32 i = 0; i < players.size(); i++) {
  7670. lua_interface->SetSpawnValue(state, players.at(i));
  7671. lua_rawseti(state, newTable, i + 1);
  7672. }
  7673. return 1;
  7674. }
  7675. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  7676. if (!lua_interface)
  7677. return 0;
  7678. ZoneServer* zone = lua_interface->GetZone(state, 1);
  7679. if (!zone) {
  7680. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  7681. return 0;
  7682. }
  7683. int32 group_id = lua_interface->GetInt32Value(state, 2);
  7684. //Map of <placement_id, location_id>
  7685. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  7686. map<int32, int32>::iterator itr;
  7687. vector<Spawn*> group;
  7688. for (itr = locs->begin(); itr != locs->end(); itr++) {
  7689. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  7690. if (!location) {
  7691. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  7692. return 0;
  7693. }
  7694. Spawn* spawn = 0;
  7695. if (location->entities[0]) {
  7696. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  7697. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  7698. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  7699. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  7700. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  7701. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  7702. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  7703. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  7704. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  7705. spawn = zone->AddSignSpawn(location, location->entities[0]);
  7706. if (spawn) {
  7707. const char* script = 0;
  7708. for (int x = 0; x < 3; x++) {
  7709. switch (x) {
  7710. case 0:
  7711. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  7712. break;
  7713. case 1:
  7714. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  7715. break;
  7716. case 2:
  7717. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  7718. break;
  7719. }
  7720. if (script && lua_interface->GetSpawnScript(script) != 0) {
  7721. spawn->SetSpawnScript(string(script));
  7722. break;
  7723. }
  7724. }
  7725. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7726. lua_interface->SetSpawnValue(state, spawn);
  7727. group.push_back(spawn);
  7728. }
  7729. else {
  7730. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  7731. safe_delete(spawn);
  7732. }
  7733. }
  7734. }
  7735. if (!group.empty()) {
  7736. lua_createtable(state, group.size(), 0);
  7737. int newTable = lua_gettop(state);
  7738. for (int32 i = 0; i < group.size(); i++) {
  7739. lua_interface->SetSpawnValue(state, group[i]);
  7740. lua_rawseti(state, newTable, i + 1);
  7741. }
  7742. }
  7743. else
  7744. lua_pushnil(state);
  7745. return 1;
  7746. }
  7747. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  7748. if (!lua_interface)
  7749. return 0;
  7750. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  7751. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  7752. int16 leeway = lua_interface->GetInt16Value(state, 3);
  7753. if (!spawn) {
  7754. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  7755. return 0;
  7756. }
  7757. if (anim_id == 0) {
  7758. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  7759. return 0;
  7760. }
  7761. if (leeway == 0)
  7762. leeway = 5000;
  7763. spawn->SetSpawnAnim(anim_id);
  7764. spawn->SetSpawnAnimLeeway(leeway);
  7765. return 0;
  7766. }
  7767. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  7768. if (!lua_interface)
  7769. return 0;
  7770. Spawn* player = lua_interface->GetSpawn(state);
  7771. if (!player) {
  7772. return 0;
  7773. }
  7774. Client* client = player->GetZone()->GetClientBySpawn(player);
  7775. if (!client) {
  7776. return 0;
  7777. }
  7778. lua_interface->SetInt32Value(state, client->GetVersion());
  7779. return 1;
  7780. }
  7781. int EQ2Emu_lua_GetItemID(lua_State* state) {
  7782. if (!lua_interface)
  7783. return 0;
  7784. Item* item = lua_interface->GetItem(state);
  7785. if (!item) {
  7786. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  7787. return 0;
  7788. }
  7789. lua_interface->SetInt32Value(state, item->details.item_id);
  7790. return 1;
  7791. }
  7792. int EQ2Emu_lua_IsEntity(lua_State* state) {
  7793. if (!lua_interface)
  7794. return 0;
  7795. Spawn* spawn = lua_interface->GetSpawn(state);
  7796. if (!spawn) {
  7797. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  7798. return 0;
  7799. }
  7800. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  7801. return 1;
  7802. }
  7803. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  7804. if (!lua_interface)
  7805. return 0;
  7806. Spawn* spawn = lua_interface->GetSpawn(state);
  7807. if (!spawn) {
  7808. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  7809. return 0;
  7810. }
  7811. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  7812. return 1;
  7813. }
  7814. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  7815. if (!lua_interface)
  7816. return 0;
  7817. Spawn* spawn = lua_interface->GetSpawn(state);
  7818. if (!spawn) {
  7819. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  7820. return 0;
  7821. }
  7822. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  7823. return 1;
  7824. }
  7825. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  7826. if (!lua_interface)
  7827. return 0;
  7828. Spawn* spawn = lua_interface->GetSpawn(state);
  7829. if (!spawn) {
  7830. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  7831. return 0;
  7832. }
  7833. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  7834. return 1;
  7835. }
  7836. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  7837. if (!lua_interface)
  7838. return 0;
  7839. Spawn* spawn = lua_interface->GetSpawn(state);
  7840. float pct = lua_interface->GetFloatValue(state, 2);
  7841. if (!spawn) {
  7842. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. if (pct == 0) {
  7846. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  7847. return 0;
  7848. }
  7849. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  7850. lua_interface->SetInt32Value(state, amount);
  7851. return 1;
  7852. }
  7853. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  7854. if (!lua_interface)
  7855. return 0;
  7856. Spawn* spawn = lua_interface->GetSpawn(state);
  7857. float pct = lua_interface->GetFloatValue(state, 2);
  7858. if (!spawn) {
  7859. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  7860. return 0;
  7861. }
  7862. if (pct == 0) {
  7863. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  7864. return 0;
  7865. }
  7866. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  7867. lua_interface->SetInt32Value(state, amount);
  7868. return 1;
  7869. }
  7870. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  7871. if (!lua_interface)
  7872. return 0;
  7873. Spawn* spawn = lua_interface->GetSpawn(state);
  7874. if (!spawn) {
  7875. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  7876. return 0;
  7877. }
  7878. if (!spawn->IsPlayer()) {
  7879. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  7880. return 0;
  7881. }
  7882. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  7883. return 1;
  7884. }
  7885. int EQ2Emu_lua_Evac(lua_State* state) {
  7886. if (!lua_interface)
  7887. return 0;
  7888. Spawn* target = lua_interface->GetSpawn(state);
  7889. if (target) {
  7890. float x = target->GetZone()->GetSafeX();
  7891. float y = target->GetZone()->GetSafeY();
  7892. float z = target->GetZone()->GetSafeZ();
  7893. float h = target->GetZone()->GetSafeHeading();
  7894. target->SetX(x);
  7895. target->SetY(y);
  7896. target->SetZ(z);
  7897. target->SetHeading(h);
  7898. target->SetSpawnOrigX(target->GetX());
  7899. target->SetSpawnOrigY(target->GetY());
  7900. target->SetSpawnOrigZ(target->GetZ());
  7901. target->SetSpawnOrigHeading(target->GetHeading());
  7902. if (target->IsPlayer()) {
  7903. Client* client = target->GetZone()->GetClientBySpawn(target);
  7904. if (client) {
  7905. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  7906. if (packet)
  7907. {
  7908. packet->setDataByName("x", x);
  7909. packet->setDataByName("y", y);
  7910. packet->setDataByName("z", z);
  7911. client->QueuePacket(packet->serialize());
  7912. safe_delete(packet);
  7913. }
  7914. }
  7915. }
  7916. }
  7917. else {
  7918. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7919. ZoneServer* zone = spell->caster->GetZone();
  7920. float x = spell->caster->GetZone()->GetSafeX();
  7921. float y = spell->caster->GetZone()->GetSafeY();
  7922. float z = spell->caster->GetZone()->GetSafeZ();
  7923. float h = spell->caster->GetZone()->GetSafeHeading();
  7924. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7925. for (int32 i = 0; i < spell->targets.size(); i++) {
  7926. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  7927. if (!target2)
  7928. continue;
  7929. target2->SetX(x);
  7930. target2->SetY(y);
  7931. target2->SetZ(z);
  7932. target2->SetHeading(h);
  7933. target2->SetSpawnOrigX(target2->GetX());
  7934. target2->SetSpawnOrigY(target2->GetY());
  7935. target2->SetSpawnOrigZ(target2->GetZ());
  7936. target2->SetSpawnOrigHeading(target2->GetHeading());
  7937. if (target2->IsPlayer()) {
  7938. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  7939. if (client) {
  7940. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  7941. if (packet)
  7942. {
  7943. packet->setDataByName("x", x);
  7944. packet->setDataByName("y", y);
  7945. packet->setDataByName("z", z);
  7946. client->QueuePacket(packet->serialize());
  7947. safe_delete(packet);
  7948. }
  7949. }
  7950. }
  7951. }
  7952. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7953. }
  7954. return 0;
  7955. }
  7956. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  7957. if (!lua_interface)
  7958. return 0;
  7959. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7960. if (!luaspell) {
  7961. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  7962. return 0;
  7963. }
  7964. int8 tier = luaspell->spell->GetSpellTier();
  7965. lua_interface->SetInt32Value(state, tier);
  7966. return 1;
  7967. }
  7968. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  7969. if (!lua_interface)
  7970. return 0;
  7971. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7972. if (!luaspell) {
  7973. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  7974. return 0;
  7975. }
  7976. int32 spell_id = luaspell->spell->GetSpellID();
  7977. lua_interface->SetInt32Value(state, spell_id);
  7978. return 1;
  7979. }
  7980. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  7981. if (!lua_interface)
  7982. return 0;
  7983. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  7984. if (!spawn) {
  7985. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  7986. return 0;
  7987. }
  7988. if (!spawn->IsPlayer()) {
  7989. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  7990. return 0;
  7991. }
  7992. ZoneServer* zone = spawn->GetZone();
  7993. if (!zone) {
  7994. return 0;
  7995. }
  7996. Client* client = zone->GetClientBySpawn(spawn);
  7997. if (!client) {
  7998. return 0;
  7999. }
  8000. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8001. return 0;
  8002. }
  8003. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8004. if (!lua_interface)
  8005. return 0;
  8006. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8007. if (!spawn) {
  8008. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8009. return 0;
  8010. }
  8011. if (!spawn->IsPlayer()) {
  8012. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8013. return 0;
  8014. }
  8015. ZoneServer* zone = spawn->GetZone();
  8016. if (!zone) {
  8017. return 0;
  8018. }
  8019. Client* client = zone->GetClientBySpawn(spawn);
  8020. if (!client) {
  8021. return 0;
  8022. }
  8023. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8024. return 0;
  8025. }
  8026. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8027. if (!lua_interface)
  8028. return 0;
  8029. Spawn* caster = lua_interface->GetSpawn(state);
  8030. Spawn* target = lua_interface->GetSpawn(state, 2);
  8031. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8032. string spell_name = lua_interface->GetStringValue(state, 4);
  8033. if (!caster) {
  8034. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8035. return 0;
  8036. }
  8037. if (!caster->IsEntity()) {
  8038. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8039. return 0;
  8040. }
  8041. if (!target) {
  8042. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8043. return 0;
  8044. }
  8045. if (!target->IsEntity()) {
  8046. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8047. return 0;
  8048. }
  8049. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8050. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8051. return 0;
  8052. }
  8053. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  8054. if (!lua_interface)
  8055. return 0;
  8056. Spawn* spawn = lua_interface->GetSpawn(state);
  8057. Spawn* target = lua_interface->GetSpawn(state, 2);
  8058. if (spawn && target)
  8059. return spawn->CheckLoS(target);
  8060. return 0;
  8061. }
  8062. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  8063. if (!lua_interface)
  8064. return 0;
  8065. Spawn* spawn = lua_interface->GetSpawn(state);
  8066. float x = lua_interface->GetFloatValue(state, 2);
  8067. float y = lua_interface->GetFloatValue(state, 3);
  8068. float z = lua_interface->GetFloatValue(state, 4);
  8069. if (spawn)
  8070. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  8071. return 0;
  8072. }
  8073. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  8074. if (!lua_interface)
  8075. return 0;
  8076. ZoneServer* zone = lua_interface->GetZone(state);
  8077. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  8078. if (zone)
  8079. zone->SetExpansionFlag(xpackFlag);
  8080. return 0;
  8081. }
  8082. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  8083. if (!lua_interface)
  8084. return 0;
  8085. ZoneServer* zone = lua_interface->GetZone(state);
  8086. if (zone) {
  8087. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  8088. return 1;
  8089. }
  8090. return 0;
  8091. }
  8092. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  8093. if (!lua_interface)
  8094. return 0;
  8095. Spawn* spawn = lua_interface->GetSpawn(state);
  8096. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  8097. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  8098. float distance = lua_interface->GetFloatValue(state, 4);
  8099. string in_range_function = lua_interface->GetStringValue(state, 5);
  8100. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  8101. if (spawn && distance > 0 && in_range_function.length() > 0)
  8102. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  8103. return 0;
  8104. }