LuaFunctions.cpp 289 KB

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