LuaFunctions.cpp 452 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 561 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. if(spawn->GetSpawnGroupID() == new_group_id) {
  685. lua_interface->SetBooleanValue(state, false);
  686. return 1;
  687. }
  688. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  689. lua_interface->SetBooleanValue(state, true);
  690. return 1;
  691. }
  692. lua_interface->SetBooleanValue(state, false);
  693. return 1;
  694. }
  695. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  696. Spawn* spawn = lua_interface->GetSpawn(state);
  697. lua_interface->ResetFunctionStack(state);
  698. if (spawn) {
  699. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  700. return 1;
  701. }
  702. return 0;
  703. }
  704. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  705. Spawn* spawn = lua_interface->GetSpawn(state);
  706. lua_interface->ResetFunctionStack(state);
  707. if (spawn) {
  708. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  709. return 1;
  710. }
  711. return 0;
  712. }
  713. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  714. Player* player = (Player*)lua_interface->GetSpawn(state);
  715. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  716. lua_interface->ResetFunctionStack(state);
  717. if (player && player->IsPlayer() && faction_id > 0) {
  718. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  719. return 1;
  720. }
  721. return 0;
  722. }
  723. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  724. if (!lua_interface)
  725. return 0;
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. int32 value = lua_interface->GetInt32Value(state, 2);
  728. lua_interface->ResetFunctionStack(state);
  729. if (spawn) {
  730. spawn->SetFactionID(value);
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  735. Spawn* spawn = lua_interface->GetSpawn(state);
  736. lua_interface->ResetFunctionStack(state);
  737. if (spawn) {
  738. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  739. return 1;
  740. }
  741. return 0;
  742. }
  743. int EQ2Emu_lua_GetGender(lua_State* state) {
  744. Spawn* spawn = lua_interface->GetSpawn(state);
  745. lua_interface->ResetFunctionStack(state);
  746. if (spawn) {
  747. lua_interface->SetInt32Value(state, spawn->GetGender());
  748. return 1;
  749. }
  750. return 0;
  751. }
  752. int EQ2Emu_lua_GetTarget(lua_State* state) {
  753. Spawn* spawn = lua_interface->GetSpawn(state);
  754. lua_interface->ResetFunctionStack(state);
  755. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  756. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  757. return 1;
  758. }
  759. return 0;
  760. }
  761. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  762. if (!lua_interface)
  763. return 0;
  764. Spawn* spawn = lua_interface->GetSpawn(state);
  765. string mp3_string = lua_interface->GetStringValue(state, 2);
  766. int32 key1 = lua_interface->GetInt32Value(state, 3);
  767. int32 key2 = lua_interface->GetInt32Value(state, 4);
  768. Spawn* player = lua_interface->GetSpawn(state, 5);
  769. lua_interface->ResetFunctionStack(state);
  770. if (spawn && mp3_string.length() > 0) {
  771. Client* client = 0;
  772. if (player && player->IsPlayer())
  773. client = ((Player*)player)->GetClient();
  774. if (client) {
  775. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  776. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  777. }
  778. else
  779. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  780. }
  781. return 0;
  782. }
  783. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  784. if (!lua_interface)
  785. return 0;
  786. Spawn* spawn = lua_interface->GetSpawn(state);
  787. lua_interface->ResetFunctionStack(state);
  788. if (spawn) {
  789. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  790. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  791. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  792. return 3;
  793. }
  794. return 0;
  795. }
  796. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. lua_interface->ResetFunctionStack(state);
  803. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  804. return 1;
  805. }
  806. lua_interface->ResetFunctionStack(state);
  807. return 0;
  808. }
  809. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  810. if (!lua_interface)
  811. return 0;
  812. Spawn* spawn = lua_interface->GetSpawn(state);
  813. if (spawn && spawn->IsEntity()) {
  814. int32 item_id = lua_interface->GetInt32Value(state, 2);
  815. int16 charges = lua_interface->GetInt16Value(state, 3);
  816. if (charges == 0)
  817. charges = 1;
  818. ((Entity*)spawn)->AddLootItem(item_id, charges);
  819. }
  820. lua_interface->ResetFunctionStack(state);
  821. return 0;
  822. }
  823. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  824. if (!lua_interface)
  825. return 0;
  826. Spawn* spawn = lua_interface->GetSpawn(state);
  827. if (spawn && spawn->IsEntity()) {
  828. int32 item_id = lua_interface->GetInt32Value(state, 2);
  829. Item* item = spawn->LootItem(item_id);
  830. lua_interface->SetLuaUserDataStale(item);
  831. safe_delete(item);
  832. }
  833. lua_interface->ResetFunctionStack(state);
  834. return 0;
  835. }
  836. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  837. if (!lua_interface)
  838. return 0;
  839. Spawn* spawn = lua_interface->GetSpawn(state);
  840. if (spawn) {
  841. int32 val = lua_interface->GetInt32Value(state, 2);
  842. spawn->AddLootCoins(val);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. if (entity && player && player->IsPlayer()) {
  853. int32 coins = lua_interface->GetInt32Value(state, 3);
  854. vector<Item*>* items = 0;
  855. int i = 0;
  856. int32 item_id = 0;
  857. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  858. if (items == 0)
  859. items = new vector<Item*>;
  860. if (master_item_list.GetItem(item_id))
  861. items->push_back(master_item_list.GetItem(item_id));
  862. i++;
  863. }
  864. Client* client = 0;
  865. client = ((Player*)player)->GetClient();
  866. if (client)
  867. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  868. if(coins > 0)
  869. entity->AddLootCoins(coins);
  870. safe_delete(items);
  871. }
  872. lua_interface->ResetFunctionStack(state);
  873. return 0;
  874. }
  875. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  876. if (!lua_interface)
  877. return 0;
  878. Spawn* entity = lua_interface->GetSpawn(state);
  879. Spawn* player = lua_interface->GetSpawn(state, 2);
  880. int32 item_id = lua_interface->GetInt32Value(state, 3);
  881. lua_interface->ResetFunctionStack(state);
  882. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  883. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  884. return 1;
  885. }
  886. return 0;
  887. }
  888. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  889. if (!lua_interface)
  890. return 0;
  891. Spawn* entity = lua_interface->GetSpawn(state);
  892. Spawn* player = lua_interface->GetSpawn(state, 2);
  893. lua_interface->ResetFunctionStack(state);
  894. if (entity && player && player->IsPlayer()) {
  895. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  896. return 1;
  897. }
  898. return 0;
  899. }
  900. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  901. if (!lua_interface)
  902. return 0;
  903. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  904. lua_interface->SetLuaUserDataStale(conversation);
  905. safe_delete(conversation);
  906. lua_interface->ResetFunctionStack(state);
  907. conversation = new vector<ConversationOption>();
  908. lua_interface->SetConversationValue(state, conversation);
  909. return 1;
  910. }
  911. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  915. if (conversation) {
  916. ConversationOption conv_option;
  917. conv_option.option = lua_interface->GetStringValue(state, 2);
  918. conv_option.function = lua_interface->GetStringValue(state, 3);
  919. if (conv_option.option.length() > 0)
  920. conversation->push_back(conv_option);
  921. }
  922. lua_interface->ResetFunctionStack(state);
  923. return 0;
  924. }
  925. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  926. if (!lua_interface)
  927. return 0;
  928. Spawn* npc = lua_interface->GetSpawn(state);
  929. Spawn* player = lua_interface->GetSpawn(state, 2);
  930. lua_interface->ResetFunctionStack(state);
  931. if (npc && player && player->IsPlayer() && player->GetZone()) {
  932. Client* client = ((Player*)player)->GetClient();
  933. if (client) {
  934. int32 conversation_id = client->GetConversationID(npc, 0);
  935. client->CloseDialog(conversation_id);
  936. }
  937. }
  938. return 0;
  939. }
  940. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  941. if (!lua_interface)
  942. return 0;
  943. Item* item = lua_interface->GetItem(state);
  944. Spawn* player = lua_interface->GetSpawn(state, 2);
  945. lua_interface->ResetFunctionStack(state);
  946. if (item && player && player->IsPlayer() && player->GetZone()) {
  947. Client* client = ((Player*)player)->GetClient();
  948. if (client) {
  949. int32 conversation_id = client->GetConversationID(0, item);
  950. client->CloseDialog(conversation_id);
  951. }
  952. }
  953. return 0;
  954. }
  955. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  956. if (!lua_interface)
  957. return 0;
  958. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  959. Spawn* spawn = 0;
  960. Item* item = 0;
  961. int8 type = lua_interface->GetInt8Value(state, 2);
  962. if (type == 1 || type == 3)
  963. spawn = lua_interface->GetSpawn(state, 3);
  964. else if (type == 2 || type == 4)
  965. item = lua_interface->GetItem(state, 3);
  966. Spawn* player = lua_interface->GetSpawn(state, 4);
  967. string text = lua_interface->GetStringValue(state, 5);
  968. string mp3 = lua_interface->GetStringValue(state, 6);
  969. int32 key1 = lua_interface->GetInt32Value(state, 7);
  970. int32 key2 = lua_interface->GetInt32Value(state, 8);
  971. int8 language = lua_interface->GetInt8Value(state, 9);
  972. int numargs = lua_interface->GetNumberOfArgs(state);
  973. int8 can_close = 1;
  974. if(numargs > 9)
  975. can_close = lua_interface->GetInt32Value(state, 10);
  976. lua_interface->ResetFunctionStack(state);
  977. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  978. Client* client = ((Player*)player)->GetClient();
  979. if (client) {
  980. if (spawn) {
  981. // Need to do this so the function works the same as it did before
  982. if (type == 1)
  983. type++;
  984. if (mp3.length() > 0)
  985. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  986. else
  987. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  988. }
  989. else {
  990. if (mp3.length() > 0)
  991. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  992. else
  993. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  994. }
  995. }
  996. }
  997. lua_interface->SetLuaUserDataStale(conversation);
  998. safe_delete(conversation);
  999. return 0;
  1000. }
  1001. int EQ2Emu_lua_StartConversation(lua_State* state) {
  1002. if (!lua_interface)
  1003. return 0;
  1004. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1005. Spawn* source = lua_interface->GetSpawn(state, 2);
  1006. Spawn* player = lua_interface->GetSpawn(state, 3);
  1007. string text = lua_interface->GetStringValue(state, 4);
  1008. string mp3 = lua_interface->GetStringValue(state, 5);
  1009. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1010. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1011. int8 language = lua_interface->GetInt32Value(state, 8);
  1012. int numargs = lua_interface->GetNumberOfArgs(state);
  1013. int8 can_close = 1;
  1014. if(numargs > 8)
  1015. can_close = lua_interface->GetInt32Value(state, 9);
  1016. lua_interface->ResetFunctionStack(state);
  1017. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1018. Client* client = ((Player*)player)->GetClient();
  1019. if (mp3.length() > 0)
  1020. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1021. else
  1022. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1023. lua_interface->SetLuaUserDataStale(conversation);
  1024. safe_delete(conversation);
  1025. }
  1026. else
  1027. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1028. return 0;
  1029. }
  1030. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1031. if (!lua_interface)
  1032. return 0;
  1033. Spawn* spawn = lua_interface->GetSpawn(state);
  1034. float distance = lua_interface->GetFloatValue(state, 2);
  1035. string in_range_function = lua_interface->GetStringValue(state, 3);
  1036. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1037. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1038. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1039. return 0;
  1040. }
  1041. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1042. ZoneServer* zone = lua_interface->GetZone(state);
  1043. float x = lua_interface->GetFloatValue(state, 2);
  1044. float y = lua_interface->GetFloatValue(state, 3);
  1045. float z = lua_interface->GetFloatValue(state, 4);
  1046. float max_variation = lua_interface->GetFloatValue(state, 5);
  1047. string in_range_function = lua_interface->GetStringValue(state, 6);
  1048. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1049. lua_interface->ResetFunctionStack(state);
  1050. if (zone && in_range_function.length() > 0)
  1051. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1052. return 0;
  1053. }
  1054. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1055. if (!lua_interface)
  1056. return 0;
  1057. Spawn* spawn = lua_interface->GetSpawn(state);
  1058. if (spawn && spawn->IsEntity()) {
  1059. int32 val = lua_interface->GetInt32Value(state, 2);
  1060. ((Entity*)spawn)->SetLootCoins(val);
  1061. }
  1062. lua_interface->ResetFunctionStack(state);
  1063. return 0;
  1064. }
  1065. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1066. if (!lua_interface)
  1067. return 0;
  1068. Spawn* spawn = lua_interface->GetSpawn(state);
  1069. lua_interface->ResetFunctionStack(state);
  1070. if (spawn && spawn->IsEntity()) {
  1071. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1072. return 1;
  1073. }
  1074. return 0;
  1075. }
  1076. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1077. if (!lua_interface)
  1078. return 0;
  1079. Spawn* spawn = lua_interface->GetSpawn(state);
  1080. float x = lua_interface->GetFloatValue(state, 2);
  1081. float y = lua_interface->GetFloatValue(state, 3);
  1082. float z = lua_interface->GetFloatValue(state, 4);
  1083. float speed = lua_interface->GetFloatValue(state, 5);
  1084. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1085. string function = lua_interface->GetStringValue(state, 7);
  1086. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1087. float heading = lua_interface->GetFloatValue(state, 8);
  1088. if (spawn) {
  1089. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1090. spawn->GetZone()->AddMovementNPC(spawn);
  1091. }
  1092. lua_interface->ResetFunctionStack(state);
  1093. return 0;
  1094. }
  1095. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1096. if (!lua_interface)
  1097. return 0;
  1098. Spawn* spawn = lua_interface->GetSpawn(state);
  1099. lua_interface->ResetFunctionStack(state);
  1100. if (spawn) {
  1101. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1102. return 1;
  1103. }
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. Spawn* spawn = lua_interface->GetSpawn(state);
  1110. lua_interface->ResetFunctionStack(state);
  1111. if (spawn && spawn->IsPlayer()) {
  1112. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1113. return 1;
  1114. }
  1115. lua_interface->SetInt32Value(state, 0);
  1116. return 1;
  1117. }
  1118. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. Spawn* target = lua_interface->GetSpawn(state, 2);
  1123. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1124. bool reset_action_state = true;
  1125. if(num_args > 2)
  1126. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1127. if (spawn && target) {
  1128. if (spawn->IsEntity())
  1129. // ((Entity*)spawn)->FaceTarget(target);
  1130. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1131. }
  1132. lua_interface->ResetFunctionStack(state);
  1133. return 0;
  1134. }
  1135. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1136. if (!lua_interface)
  1137. return 0;
  1138. Spawn* spawn = lua_interface->GetSpawn(state);
  1139. float x = lua_interface->GetFloatValue(state, 2);
  1140. float y = lua_interface->GetFloatValue(state, 3);
  1141. float z = lua_interface->GetFloatValue(state, 4);
  1142. float speed = lua_interface->GetFloatValue(state, 5);
  1143. string lua_function = lua_interface->GetStringValue(state, 6);
  1144. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1145. if (spawn) {
  1146. if (speed == 0)
  1147. speed = spawn->GetSpeed();
  1148. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1149. }
  1150. lua_interface->ResetFunctionStack(state);
  1151. return 0;
  1152. }
  1153. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1154. if (!lua_interface)
  1155. return 0;
  1156. Spawn* spawn = lua_interface->GetSpawn(state);
  1157. lua_interface->ResetFunctionStack(state);
  1158. if (spawn) {
  1159. spawn->ClearRunningLocations();
  1160. }
  1161. return 0;
  1162. }
  1163. int EQ2Emu_lua_Say(lua_State* state) {
  1164. if (!lua_interface)
  1165. return 0;
  1166. Spawn* spawn = lua_interface->GetSpawn(state);
  1167. string message = lua_interface->GetStringValue(state, 2);
  1168. Spawn* player = lua_interface->GetSpawn(state, 3);
  1169. float dist = lua_interface->GetFloatValue(state, 4);
  1170. int32 language = lua_interface->GetInt32Value(state, 5);
  1171. if (spawn && message.length() > 0) {
  1172. Client* client = 0;
  1173. if (player && player->IsPlayer())
  1174. client = ((Player*)player)->GetClient();
  1175. if (client)
  1176. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1177. else
  1178. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1179. }
  1180. lua_interface->ResetFunctionStack(state);
  1181. return 0;
  1182. }
  1183. int EQ2Emu_lua_Shout(lua_State* state) {
  1184. if (!lua_interface)
  1185. return 0;
  1186. Spawn* spawn = lua_interface->GetSpawn(state);
  1187. string message = lua_interface->GetStringValue(state, 2);
  1188. Spawn* player = lua_interface->GetSpawn(state, 3);
  1189. float dist = lua_interface->GetFloatValue(state, 4);
  1190. int32 language = lua_interface->GetInt32Value(state, 5);
  1191. if (spawn && message.length() > 0) {
  1192. Client* client = 0;
  1193. if (player && player->IsPlayer())
  1194. client = ((Player*)player)->GetClient();
  1195. if (client)
  1196. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1197. else
  1198. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1199. }
  1200. lua_interface->ResetFunctionStack(state);
  1201. return 0;
  1202. }
  1203. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1204. if (!lua_interface)
  1205. return 0;
  1206. Spawn* spawn = lua_interface->GetSpawn(state);
  1207. string message = lua_interface->GetStringValue(state, 2);
  1208. Spawn* player = lua_interface->GetSpawn(state, 3);
  1209. float dist = lua_interface->GetFloatValue(state, 4);
  1210. int32 language = lua_interface->GetInt32Value(state, 5);
  1211. if (spawn && message.length() > 0) {
  1212. Client* client = 0;
  1213. if (player && player->IsPlayer())
  1214. client = ((Player*)player)->GetClient();
  1215. if (client)
  1216. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1217. else
  1218. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1219. }
  1220. lua_interface->ResetFunctionStack(state);
  1221. return 0;
  1222. }
  1223. int EQ2Emu_lua_Emote(lua_State* state) {
  1224. if (!lua_interface)
  1225. return 0;
  1226. Spawn* spawn = lua_interface->GetSpawn(state);
  1227. string message = lua_interface->GetStringValue(state, 2);
  1228. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1229. Spawn* player = lua_interface->GetSpawn(state, 4);
  1230. char* to = 0;
  1231. if (spawn2)
  1232. to = spawn2->GetName();
  1233. if (spawn && message.length() > 0) {
  1234. Client* client = 0;
  1235. if (player && player->IsPlayer())
  1236. client = ((Player*)player)->GetClient();
  1237. if (client)
  1238. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1239. else
  1240. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1241. }
  1242. lua_interface->ResetFunctionStack(state);
  1243. return 0;
  1244. }
  1245. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1246. if (!lua_interface)
  1247. return 0;
  1248. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1249. if(!luaspell || luaspell->resisted) {
  1250. lua_interface->ResetFunctionStack(state);
  1251. return 0;
  1252. }
  1253. Spawn* caster = luaspell->caster;
  1254. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1255. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1256. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1257. Spawn* target = lua_interface->GetSpawn(state, 4);
  1258. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1259. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1260. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1261. lua_interface->ResetFunctionStack(state);
  1262. boost::to_lower(heal_type);
  1263. if (caster && caster->IsEntity()) {
  1264. bool success = false;
  1265. luaspell->resisted = false;
  1266. if (target) {
  1267. float distance = caster->GetDistance(target, true);
  1268. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1269. success = true;
  1270. }
  1271. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1272. Spawn* target = 0;
  1273. ZoneServer* zone = luaspell->caster->GetZone();
  1274. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1275. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1276. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1277. float distance = caster->GetDistance(target, true);
  1278. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1279. }
  1280. }
  1281. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1282. success = true;
  1283. }
  1284. if (success) {
  1285. if (caster->GetZone())
  1286. caster->GetZone()->TriggerCharSheetTimer();
  1287. }
  1288. }
  1289. return 0;
  1290. }
  1291. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1292. if (!lua_interface)
  1293. return 0;
  1294. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1295. if(!luaspell || luaspell->resisted) {
  1296. lua_interface->ResetFunctionStack(state);
  1297. return 0;
  1298. }
  1299. Spawn* caster = luaspell->caster;
  1300. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1301. float percentage = lua_interface->GetFloatValue(state, 2);
  1302. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1303. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1304. Spawn* target = lua_interface->GetSpawn(state, 5);
  1305. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1306. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1307. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1308. lua_interface->ResetFunctionStack(state);
  1309. boost::to_lower(heal_type);
  1310. int32 min_heal = 0, max_heal = 0;
  1311. if (caster && caster->IsEntity() && target) {
  1312. if(percentage <= 0.0f)
  1313. {
  1314. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1315. return 0;
  1316. }
  1317. if(heal_type == "power")
  1318. {
  1319. if(current_value)
  1320. {
  1321. if(caster_value)
  1322. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1323. else
  1324. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1325. }
  1326. else
  1327. {
  1328. if(caster_value)
  1329. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1330. else
  1331. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1332. }
  1333. }
  1334. else
  1335. {
  1336. if(current_value)
  1337. {
  1338. if(caster_value)
  1339. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1340. else
  1341. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1342. }
  1343. else
  1344. {
  1345. if(caster_value)
  1346. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1347. else
  1348. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1349. }
  1350. }
  1351. bool success = false;
  1352. luaspell->resisted = false;
  1353. if (target) {
  1354. float distance = caster->GetDistance(target, true);
  1355. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1356. success = true;
  1357. }
  1358. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1359. Spawn* target = 0;
  1360. ZoneServer* zone = luaspell->caster->GetZone();
  1361. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1362. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1363. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1364. float distance = caster->GetDistance(target, true);
  1365. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1366. }
  1367. }
  1368. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1369. success = true;
  1370. }
  1371. if (success) {
  1372. if (caster->GetZone())
  1373. caster->GetZone()->TriggerCharSheetTimer();
  1374. }
  1375. }
  1376. return 0;
  1377. }
  1378. int EQ2Emu_lua_AddItem(lua_State* state) {
  1379. if (!lua_interface)
  1380. return 0;
  1381. Spawn* spawn = lua_interface->GetSpawn(state);
  1382. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1383. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1384. lua_interface->ResetFunctionStack(state);
  1385. // default of 1 quantity to add
  1386. if (quantity == 0)
  1387. quantity = 1;
  1388. if (spawn && spawn->IsPlayer()) {
  1389. Client* client = ((Player*)spawn)->GetClient();
  1390. if (client && item_id > 0) {
  1391. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1392. return 1;
  1393. }
  1394. }
  1395. lua_interface->SetBooleanValue(state, false);
  1396. return 1;
  1397. }
  1398. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1399. if (!lua_interface)
  1400. return 0;
  1401. Spawn* spawn = lua_interface->GetSpawn(state);
  1402. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1403. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1404. string location = lua_interface->GetStringValue(state, 4);
  1405. int16 item_count = lua_interface->GetInt16Value(state,5);
  1406. //devn00b: if we dont have a count, assume 1 item.
  1407. if(!item_count) {
  1408. item_count = 1;
  1409. }
  1410. lua_interface->ResetFunctionStack(state);
  1411. if (spawn && spawn->IsPlayer()) {
  1412. Client* client = ((Player*)spawn)->GetClient();
  1413. if (client && item_id > 0) {
  1414. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1415. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1416. else
  1417. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1418. if (send_messages) {
  1419. Item* item = master_item_list.GetItem(item_id);
  1420. if (item) {
  1421. if(item_count > 1) {
  1422. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1423. string popup_text1 = "You receive "+ item_count;
  1424. string popup_text2 = " " + item->name;
  1425. string popup_text = popup_text1 + popup_text2;
  1426. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1427. // return 1;
  1428. } else {
  1429. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1430. string popup_text = "You receive " + item->name;
  1431. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1432. }
  1433. }
  1434. }
  1435. return 1;
  1436. }
  1437. }
  1438. lua_interface->SetBooleanValue(state, false);
  1439. return 1;
  1440. }
  1441. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1442. Spawn* spawn = lua_interface->GetSpawn(state);
  1443. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1444. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1445. lua_interface->ResetFunctionStack(state);
  1446. // default of 1 to remove
  1447. if (quantity == 0)
  1448. quantity = 1;
  1449. Client* client;
  1450. Item* item;
  1451. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1452. if ((client = ((Player*)spawn)->GetClient())) {
  1453. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1454. if (client->RemoveItem(item, quantity)) {
  1455. lua_interface->SetBooleanValue(state, true);
  1456. return 1;
  1457. }
  1458. }
  1459. }
  1460. }
  1461. lua_interface->SetBooleanValue(state, false);
  1462. return 1;
  1463. }
  1464. int EQ2Emu_lua_HasItem(lua_State* state) {
  1465. Spawn* player = lua_interface->GetSpawn(state);
  1466. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1467. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1468. lua_interface->ResetFunctionStack(state);
  1469. if (player && player->IsPlayer()) {
  1470. bool hasItem = false;
  1471. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1472. if (!hasItem)
  1473. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1474. lua_interface->SetBooleanValue(state, hasItem);
  1475. return 1;
  1476. }
  1477. lua_interface->SetBooleanValue(state, false);
  1478. return 1;
  1479. }
  1480. int EQ2Emu_lua_Spawn(lua_State* state) {
  1481. if (!lua_interface)
  1482. return 0;
  1483. ZoneServer* zone = lua_interface->GetZone(state);
  1484. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1485. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1486. float x = lua_interface->GetFloatValue(state, 4);
  1487. float y = lua_interface->GetFloatValue(state, 5);
  1488. float z = lua_interface->GetFloatValue(state, 6);
  1489. float heading = lua_interface->GetFloatValue(state, 7);
  1490. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1491. Spawn* spawn = zone->GetSpawn(spawn_id);
  1492. if (!spawn)
  1493. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1494. else {
  1495. spawn->SetX(x);
  1496. spawn->SetZ(z);
  1497. spawn->SetY(y,true,true);
  1498. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1499. spawn->SetHeading(heading);
  1500. if (restricted_npc)
  1501. spawn->AddAllowAccessSpawn(spawn);
  1502. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1503. bool scriptActive = false;
  1504. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1505. scriptActive = true;
  1506. spawn->SetSpawnScript(string(spawn_script));
  1507. }
  1508. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1509. zone->AddSpawn(spawn);
  1510. if (scriptActive) {
  1511. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1512. }
  1513. lua_interface->ResetFunctionStack(state);
  1514. lua_interface->SetSpawnValue(state, spawn);
  1515. return 1;
  1516. }
  1517. }
  1518. else {
  1519. string output = "Invalid paramaters to LUA Spawn command: \n";
  1520. if (!zone)
  1521. output = output.append("\t").append("Missing zone reference. \n");
  1522. if (spawn_id == 0)
  1523. output = output.append("\t").append("Missing spawn_id.");
  1524. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1525. }
  1526. lua_interface->ResetFunctionStack(state);
  1527. return 0;
  1528. }
  1529. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1530. if (!lua_interface)
  1531. return 0;
  1532. ZoneServer* zone = lua_interface->GetZone(state);
  1533. lua_interface->ResetFunctionStack(state);
  1534. if (zone) {
  1535. lua_interface->SetStringValue(state, zone->GetZoneName());
  1536. return 1;
  1537. }
  1538. return 0;
  1539. }
  1540. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1541. if (!lua_interface)
  1542. return 0;
  1543. ZoneServer* zone = lua_interface->GetZone(state);
  1544. lua_interface->ResetFunctionStack(state);
  1545. if (zone) {
  1546. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1547. return 1;
  1548. }
  1549. return 0;
  1550. }
  1551. int EQ2Emu_lua_GetZone(lua_State* state) {
  1552. if (!lua_interface)
  1553. return 0;
  1554. int32 zone_id = lua_interface->GetInt32Value(state);
  1555. ZoneServer* zone = 0;
  1556. if (zone_id > 0)
  1557. zone = zone_list.Get(zone_id, true, false, false);
  1558. else {
  1559. string zone_name = lua_interface->GetStringValue(state);
  1560. if (zone_name.length() > 0) {
  1561. zone = zone_list.Get(zone_name.c_str(), true, false, false);
  1562. }
  1563. else {
  1564. Spawn* spawn = lua_interface->GetSpawn(state);
  1565. if (spawn)
  1566. zone = spawn->GetZone();
  1567. }
  1568. }
  1569. lua_interface->ResetFunctionStack(state);
  1570. if (zone) {
  1571. lua_interface->SetZoneValue(state, zone);
  1572. return 1;
  1573. }
  1574. return 0;
  1575. }
  1576. int EQ2Emu_lua_AddHate(lua_State* state) {
  1577. Spawn* entity = lua_interface->GetSpawn(state);
  1578. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1579. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1580. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1581. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1582. lua_interface->ResetFunctionStack(state);
  1583. if(luaspell && luaspell->resisted) {
  1584. return 0;
  1585. }
  1586. if (entity && entity->IsEntity() && amount != 0) {
  1587. if (luaspell && luaspell->caster) {
  1588. ZoneServer* zone = luaspell->caster->GetZone();
  1589. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1590. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1591. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1592. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1593. entity->CheckEncounterState((Entity*)spawn);
  1594. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1595. if (send_packet)
  1596. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1597. }
  1598. }
  1599. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1600. }
  1601. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1602. entity->CheckEncounterState((Entity*)npc);
  1603. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1604. }
  1605. }
  1606. lua_interface->ResetFunctionStack(state);
  1607. return 0;
  1608. }
  1609. int EQ2Emu_lua_Zone(lua_State* state) {
  1610. if (!lua_interface)
  1611. return 0;
  1612. ZoneServer* zone = lua_interface->GetZone(state);
  1613. Spawn* player = lua_interface->GetSpawn(state, 2);
  1614. Client* client = 0;
  1615. if (player && player->IsPlayer())
  1616. client = ((Player*)player)->GetClient();
  1617. float x = lua_interface->GetFloatValue(state, 3);
  1618. float y = lua_interface->GetFloatValue(state, 4);
  1619. float z = lua_interface->GetFloatValue(state, 5);
  1620. float heading = lua_interface->GetFloatValue(state, 6);
  1621. lua_interface->ResetFunctionStack(state);
  1622. if (zone && client) {
  1623. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1624. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1625. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1626. {
  1627. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1628. return 0;
  1629. }
  1630. if (x != 0 || y != 0 || z != 0) {
  1631. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1632. player->SetX(x);
  1633. player->SetY(y);
  1634. player->SetZ(z);
  1635. player->SetHeading(heading);
  1636. client->Zone(zone->GetZoneName(), false);
  1637. }
  1638. else
  1639. client->Zone(zone->GetZoneName());
  1640. }
  1641. else
  1642. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1643. return 0;
  1644. }
  1645. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1646. if (!lua_interface)
  1647. return 0;
  1648. Spawn* spawn = lua_interface->GetSpawn(state);
  1649. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1650. lua_interface->ResetFunctionStack(state);
  1651. if (spawn && spawn2)
  1652. spawn->AddAllowAccessSpawn(spawn2);
  1653. lua_interface->ResetFunctionStack(state);
  1654. return 0;
  1655. }
  1656. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1657. if (!lua_interface)
  1658. return 0;
  1659. Spawn* target = lua_interface->GetSpawn(state);
  1660. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1661. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1662. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1663. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1664. lua_interface->ResetFunctionStack(state);
  1665. if (!target) {
  1666. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1667. return 0;
  1668. }
  1669. if (!target->IsEntity()) {
  1670. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1671. return 0;
  1672. }
  1673. if (spell_id <= 0) {
  1674. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1675. return 0;
  1676. }
  1677. if (caster && !caster->IsEntity()) {
  1678. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1679. return 0;
  1680. }
  1681. if (spell_tier == 0)
  1682. spell_tier = 1;
  1683. if (!caster)
  1684. caster = target;
  1685. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1686. return 0;
  1687. }
  1688. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1689. if (!lua_interface)
  1690. return 0;
  1691. Spawn* target = lua_interface->GetSpawn(state);
  1692. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1693. if(!luaspell || luaspell->resisted) {
  1694. lua_interface->ResetFunctionStack(state);
  1695. lua_interface->SetBooleanValue(state, false);
  1696. return 1;
  1697. }
  1698. Spawn* caster = luaspell->caster;
  1699. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1700. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1701. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1702. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1703. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1704. //lua_interface->ResetFunctionStack(state);
  1705. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1706. vector<int16> faction_req;
  1707. vector<int16> race_req;
  1708. int32 class_req = 0;
  1709. int32 i = 0;
  1710. int8 f = 0;
  1711. int8 r = 0;
  1712. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1713. if (class_id < 100) {
  1714. class_req += pow(2.0, double(class_id - 1));
  1715. }
  1716. else if (class_id > 100 && class_id < 1000) {
  1717. race_req.push_back(class_id);
  1718. r++;
  1719. }
  1720. else {
  1721. faction_req.push_back(class_id);
  1722. f++;
  1723. }
  1724. i++;
  1725. }
  1726. lua_interface->ResetFunctionStack(state);
  1727. if (caster && caster->IsEntity()) {
  1728. bool race_match = false;
  1729. bool success = false;
  1730. luaspell->resisted = false;
  1731. if (luaspell->targets.size() > 0) {
  1732. ZoneServer* zone = luaspell->caster->GetZone();
  1733. Spawn* target = 0;
  1734. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1735. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1736. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1737. if (race_req.size() > 0) {
  1738. for (int8 i = 0; i < race_req.size(); i++) {
  1739. if(race_req[i] == target->GetRace() ||
  1740. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1741. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1742. race_match = true;
  1743. }
  1744. }
  1745. }
  1746. else
  1747. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1748. if (race_match == true) {
  1749. float distance = caster->GetDistance(target, true);
  1750. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1751. }
  1752. }
  1753. }
  1754. success = true;
  1755. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1756. }
  1757. else if (target) {
  1758. //check class and race/faction here
  1759. if (race_req.size() > 0) {
  1760. for (int8 i = 0; i < race_req.size(); i++) {
  1761. if(race_req[i] == target->GetRace() ||
  1762. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1763. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1764. race_match = true;
  1765. }
  1766. }
  1767. }
  1768. else
  1769. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1770. if (race_match == true) {
  1771. float distance = caster->GetDistance(target, true);
  1772. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1773. success = true;
  1774. }
  1775. }
  1776. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1777. if (success) {
  1778. Spell* spell = luaspell->spell;
  1779. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1780. ((Player*)caster)->InCombat(true);
  1781. if (caster->GetZone())
  1782. caster->GetZone()->TriggerCharSheetTimer();
  1783. }
  1784. }
  1785. }
  1786. else {
  1787. lua_interface->SetBooleanValue(state, false);
  1788. }
  1789. return 1;
  1790. }
  1791. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1792. if (!lua_interface)
  1793. return 0;
  1794. Spawn* target = lua_interface->GetSpawn(state);
  1795. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1796. if(!luaspell || luaspell->resisted) {
  1797. lua_interface->ResetFunctionStack(state);
  1798. lua_interface->SetBooleanValue(state, false);
  1799. return 1;
  1800. }
  1801. Spawn* caster = luaspell->caster;
  1802. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1803. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1804. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1805. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1806. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1807. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1808. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1809. //lua_interface->ResetFunctionStack(state);
  1810. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1811. vector<int16> faction_req;
  1812. vector<int16> race_req;
  1813. int32 class_req = 0;
  1814. int32 i = 0;
  1815. int8 f = 0;
  1816. int8 r = 0;
  1817. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1818. if (class_id < 100) {
  1819. class_req += pow(2.0, double(class_id - 1));
  1820. }
  1821. else if (class_id > 100 && class_id < 1000) {
  1822. race_req.push_back(class_id);
  1823. r++;
  1824. }
  1825. else {
  1826. faction_req.push_back(class_id);
  1827. f++;
  1828. }
  1829. i++;
  1830. }
  1831. lua_interface->ResetFunctionStack(state);
  1832. if (caster && caster->IsEntity()) {
  1833. bool race_match = false;
  1834. bool success = false;
  1835. luaspell->resisted = false;
  1836. if (luaspell->targets.size() > 0) {
  1837. ZoneServer* zone = luaspell->caster->GetZone();
  1838. Spawn* target = 0;
  1839. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1840. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1841. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1842. if (race_req.size() > 0) {
  1843. for (int8 i = 0; i < race_req.size(); i++) {
  1844. if(race_req[i] == target->GetRace() ||
  1845. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1846. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1847. race_match = true;
  1848. }
  1849. }
  1850. }
  1851. else
  1852. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1853. if (race_match == true) {
  1854. float distance = caster->GetDistance(target, true);
  1855. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1856. }
  1857. }
  1858. }
  1859. success = true;
  1860. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1861. }
  1862. else if (target) {
  1863. //check class and race/faction here
  1864. if (race_req.size() > 0) {
  1865. for (int8 i = 0; i < race_req.size(); i++) {
  1866. if(race_req[i] == target->GetRace() ||
  1867. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1868. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1869. race_match = true;
  1870. }
  1871. }
  1872. }
  1873. else
  1874. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1875. if (race_match == true) {
  1876. float distance = caster->GetDistance(target, true);
  1877. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1878. success = true;
  1879. }
  1880. }
  1881. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1882. if (success) {
  1883. Spell* spell = luaspell->spell;
  1884. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1885. ((Player*)caster)->InCombat(true);
  1886. if (caster->GetZone())
  1887. caster->GetZone()->TriggerCharSheetTimer();
  1888. }
  1889. }
  1890. }
  1891. else {
  1892. lua_interface->SetBooleanValue(state, false);
  1893. }
  1894. return 1;
  1895. }
  1896. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1897. if (!lua_interface)
  1898. return 0;
  1899. Spawn* spawn = lua_interface->GetSpawn(state);
  1900. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1901. lua_interface->ResetFunctionStack(state);
  1902. if (spawn && value != 0) {
  1903. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1904. spawn->SetPower(spawn->GetTotalPower());
  1905. else
  1906. spawn->SetPower(spawn->GetPower() + value);
  1907. }
  1908. return 0;
  1909. }
  1910. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1911. if (!lua_interface)
  1912. return 0;
  1913. Spawn* spawn = lua_interface->GetSpawn(state);
  1914. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1915. lua_interface->ResetFunctionStack(state);
  1916. if (spawn && value != 0) {
  1917. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1918. spawn->SetHP(spawn->GetTotalHP());
  1919. else
  1920. spawn->SetHP(spawn->GetHP() + value);
  1921. }
  1922. return 0;
  1923. }
  1924. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1925. if (!lua_interface)
  1926. return 0;
  1927. Spawn* spawn = lua_interface->GetSpawn(state);
  1928. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1929. lua_interface->ResetFunctionStack(state);
  1930. if (spawn && value != 0) {
  1931. spawn->SetTotalPower(value);
  1932. spawn->SetTotalPowerBaseInstance(value);
  1933. }
  1934. return 0;
  1935. }
  1936. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1937. if (!lua_interface)
  1938. return 0;
  1939. Spawn* spawn = lua_interface->GetSpawn(state);
  1940. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1941. lua_interface->ResetFunctionStack(state);
  1942. if (spawn && value != 0) {
  1943. spawn->SetTotalHP(value);
  1944. spawn->SetTotalHPBaseInstance(value);
  1945. }
  1946. return 0;
  1947. }
  1948. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1949. if (!lua_interface)
  1950. return 0;
  1951. Spawn* spawn = lua_interface->GetSpawn(state);
  1952. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1953. lua_interface->ResetFunctionStack(state);
  1954. if (spawn) {
  1955. spawn->SetHP(value);
  1956. if (value > spawn->GetTotalHPBase())
  1957. spawn->SetTotalHP(value);
  1958. }
  1959. return 0;
  1960. }
  1961. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1962. if (!lua_interface)
  1963. return 0;
  1964. Spawn* spawn = lua_interface->GetSpawn(state);
  1965. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1966. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1967. lua_interface->ResetFunctionStack(state);
  1968. if (spawn && spawn->IsEntity() && value > 0)
  1969. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1970. if (spawn && spawn->IsPlayer())
  1971. ((Player*)spawn)->SetCharSheetChanged(true);
  1972. return 0;
  1973. }
  1974. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1975. if (!lua_interface)
  1976. return 0;
  1977. Spawn* spawn = lua_interface->GetSpawn(state);
  1978. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1979. lua_interface->ResetFunctionStack(state);
  1980. if (spawn && spawn->IsEntity() && value > 0)
  1981. ((Entity*)spawn)->SetTotalHPBase(value);
  1982. return 0;
  1983. }
  1984. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1985. if (!lua_interface)
  1986. return 0;
  1987. Spawn* spawn = lua_interface->GetSpawn(state);
  1988. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1989. lua_interface->ResetFunctionStack(state);
  1990. if (spawn && value > 0) {
  1991. spawn->SetPower(value);
  1992. if (value > spawn->GetTotalPowerBase())
  1993. spawn->SetTotalPower(value);
  1994. }
  1995. return 0;
  1996. }
  1997. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1998. if (!lua_interface)
  1999. return 0;
  2000. Spawn* spawn = lua_interface->GetSpawn(state);
  2001. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2002. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2003. lua_interface->ResetFunctionStack(state);
  2004. if (spawn && spawn->IsEntity() && value > 0)
  2005. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2006. return 0;
  2007. }
  2008. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2009. if (!lua_interface)
  2010. return 0;
  2011. Spawn* spawn = lua_interface->GetSpawn(state);
  2012. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2013. lua_interface->ResetFunctionStack(state);
  2014. if (spawn && spawn->IsEntity() && value > 0)
  2015. ((Entity*)spawn)->SetTotalPowerBase(value);
  2016. return 0;
  2017. }
  2018. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2019. if (!lua_interface)
  2020. return 0;
  2021. Spawn* spawn = lua_interface->GetSpawn(state);
  2022. float x = lua_interface->GetFloatValue(state, 2);
  2023. float y = lua_interface->GetFloatValue(state, 3);
  2024. float z = lua_interface->GetFloatValue(state, 4);
  2025. float heading = lua_interface->GetFloatValue(state, 5);
  2026. lua_interface->ResetFunctionStack(state);
  2027. if (spawn) {
  2028. spawn->SetX(x);
  2029. spawn->SetY(y);
  2030. spawn->SetZ(z);
  2031. if (heading != 0)
  2032. spawn->SetHeading(heading);
  2033. spawn->SetSpawnOrigX(spawn->GetX());
  2034. spawn->SetSpawnOrigY(spawn->GetY());
  2035. spawn->SetSpawnOrigZ(spawn->GetZ());
  2036. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2037. if (spawn->IsPlayer()) {
  2038. Client* client = ((Player*)spawn)->GetClient();
  2039. if (client) {
  2040. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2041. client->QueuePacket(packet);
  2042. }
  2043. }
  2044. }
  2045. return 0;
  2046. }
  2047. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2048. if (!lua_interface)
  2049. return 0;
  2050. Spawn* spawn = lua_interface->GetSpawn(state);
  2051. float value = lua_interface->GetFloatValue(state, 2);
  2052. lua_interface->ResetFunctionStack(state);
  2053. if (spawn) {
  2054. spawn->SetHeading(value);
  2055. if (spawn->IsPlayer()) {
  2056. Client* client = ((Player*)spawn)->GetClient();
  2057. if (client) {
  2058. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2059. client->QueuePacket(packet);
  2060. }
  2061. }
  2062. }
  2063. return 0;
  2064. }
  2065. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2066. if (!lua_interface)
  2067. return 0;
  2068. Spawn* spawn = lua_interface->GetSpawn(state);
  2069. int16 value = lua_interface->GetInt16Value(state, 2);
  2070. lua_interface->ResetFunctionStack(state);
  2071. if (spawn)
  2072. spawn->SetModelType(value);
  2073. return 0;
  2074. }
  2075. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2076. if (!lua_interface)
  2077. return 0;
  2078. Spawn* spawn = lua_interface->GetSpawn(state);
  2079. int8 value = lua_interface->GetInt8Value(state, 2);
  2080. lua_interface->ResetFunctionStack(state);
  2081. if (spawn) {
  2082. if (spawn->IsPlayer())
  2083. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2084. else
  2085. spawn->SetAdventureClass(value);
  2086. }
  2087. return 0;
  2088. }
  2089. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2090. if (!lua_interface)
  2091. return 0;
  2092. Spawn* spawn = lua_interface->GetSpawn(state);
  2093. int8 value = lua_interface->GetInt8Value(state, 2);
  2094. lua_interface->ResetFunctionStack(state);
  2095. if (spawn) {
  2096. spawn->SetTradeskillClass(value);
  2097. if (spawn->IsEntity()) {
  2098. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2099. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2100. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2101. }
  2102. if (spawn->IsPlayer())
  2103. ((Player*)spawn)->SetCharSheetChanged(true);
  2104. }
  2105. return 0;
  2106. }
  2107. int EQ2Emu_lua_SetMount(lua_State* state) {
  2108. if (!lua_interface)
  2109. return 0;
  2110. Spawn* spawn = lua_interface->GetSpawn(state);
  2111. int16 value = lua_interface->GetInt16Value(state, 2);
  2112. lua_interface->ResetFunctionStack(state);
  2113. if (spawn && spawn->IsEntity()) {
  2114. ((Entity*)spawn)->SetMount(value);
  2115. EQ2_Color color;
  2116. color.red = 255;
  2117. color.green = 255;
  2118. color.blue = 255;
  2119. ((Entity*)spawn)->SetMountColor(&color);
  2120. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2121. }
  2122. return 0;
  2123. }
  2124. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2125. if (!lua_interface)
  2126. return 0;
  2127. Spawn* spawn = lua_interface->GetSpawn(state);
  2128. EQ2_Color mount_color;
  2129. EQ2_Color saddle_color;
  2130. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2131. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2132. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2133. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2134. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2135. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2136. lua_interface->ResetFunctionStack(state);
  2137. if (spawn && spawn->IsEntity()) {
  2138. ((Entity*)spawn)->SetMountColor(&mount_color);
  2139. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2140. }
  2141. return 0;
  2142. }
  2143. int EQ2Emu_lua_GetMount(lua_State* state) {
  2144. if (!lua_interface)
  2145. return 0;
  2146. Spawn* spawn = lua_interface->GetSpawn(state);
  2147. lua_interface->ResetFunctionStack(state);
  2148. if (spawn && spawn->IsEntity()) {
  2149. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2150. return 1;
  2151. }
  2152. return 0;
  2153. }
  2154. int EQ2Emu_lua_GetRace(lua_State* state) {
  2155. if (!lua_interface)
  2156. return 0;
  2157. Spawn* spawn = lua_interface->GetSpawn(state);
  2158. lua_interface->ResetFunctionStack(state);
  2159. if (spawn)
  2160. {
  2161. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2162. lua_interface->SetInt32Value(state, spawn->GetRace());
  2163. return 1;
  2164. }
  2165. return 0;
  2166. }
  2167. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2168. if (!lua_interface)
  2169. return 0;
  2170. Spawn* spawn = lua_interface->GetSpawn(state);
  2171. lua_interface->ResetFunctionStack(state);
  2172. if (spawn) {
  2173. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2174. return 1;
  2175. }
  2176. return 0;
  2177. }
  2178. int EQ2Emu_lua_GetClass(lua_State* state) {
  2179. Spawn* spawn = lua_interface->GetSpawn(state);
  2180. lua_interface->ResetFunctionStack(state);
  2181. if (spawn) {
  2182. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2183. return 1;
  2184. }
  2185. return 0;
  2186. }
  2187. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2188. Spawn* spawn = lua_interface->GetSpawn(state);
  2189. lua_interface->ResetFunctionStack(state);
  2190. if (spawn) {
  2191. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2192. return 1;
  2193. }
  2194. return 0;
  2195. }
  2196. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2197. if (!lua_interface)
  2198. return 0;
  2199. Spawn* spawn = lua_interface->GetSpawn(state);
  2200. float value = lua_interface->GetFloatValue(state, 2);
  2201. lua_interface->ResetFunctionStack(state);
  2202. if (spawn) {
  2203. spawn->SetSpeed(value);
  2204. if(spawn->IsEntity())
  2205. ((Entity*)spawn)->SetSpeed(value);
  2206. if (spawn->IsPlayer()) {
  2207. Client* client = ((Player*)spawn)->GetClient();
  2208. if (client) {
  2209. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2210. if (packet) {
  2211. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2212. packet->setDataByName("speed", value);
  2213. packet->setDataByName("size", 0.51);
  2214. EQ2Packet* app = packet->serialize();
  2215. client->QueuePacket(app);
  2216. safe_delete(packet);
  2217. }
  2218. }
  2219. }
  2220. }
  2221. return 0;
  2222. }
  2223. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2224. if (!lua_interface)
  2225. return 0;
  2226. Spawn* spawn = lua_interface->GetSpawn(state);
  2227. const int16 type = lua_interface->GetInt16Value(state, 2);
  2228. const float value = lua_interface->GetFloatValue(state, 3);
  2229. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2230. lua_interface->ResetFunctionStack(state);
  2231. if(!luaspell || luaspell->resisted) {
  2232. return 0;
  2233. }
  2234. int64 class_req = 0;
  2235. int32 class_id = 0;
  2236. vector<int16> faction_req;
  2237. vector<int16> race_req;
  2238. int32 i = 0;
  2239. int8 f = 0;
  2240. int8 r = 0;
  2241. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2242. if (class_id < 100) {
  2243. class_req += pow(2.0, double(class_id - 1));
  2244. }
  2245. else if (class_id > 100 && class_id < 1000) {
  2246. race_req.push_back(class_id);
  2247. r++;
  2248. }
  2249. else {
  2250. faction_req.push_back(class_id);
  2251. f++;
  2252. }
  2253. i++;
  2254. }
  2255. if (value != 0 && type >= 0) {
  2256. if (luaspell && luaspell->spell && luaspell->caster) {
  2257. ZoneServer* zone = luaspell->caster->GetZone();
  2258. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2259. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2260. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2261. if (target) {
  2262. if (target->IsPlayer()) {
  2263. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2264. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2265. if (((Player*)target)->GetGroupMemberInfo())
  2266. ((Player*)target)->UpdateGroupMemberInfo();
  2267. ((Player*)target)->SetCharSheetChanged(true);
  2268. }
  2269. else if (target->IsNPC())
  2270. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2271. else
  2272. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2273. }
  2274. }
  2275. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2276. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2277. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2278. }
  2279. else if (spawn && spawn->IsEntity()) {
  2280. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2281. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2282. if (spawn->IsPlayer())
  2283. ((Player*)spawn)->SetCharSheetChanged(true);
  2284. }
  2285. else
  2286. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2287. }
  2288. else
  2289. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2290. return 0;
  2291. }
  2292. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2293. if (!lua_interface)
  2294. return 0;
  2295. Spawn* spawn = lua_interface->GetSpawn(state);
  2296. int16 type = lua_interface->GetInt16Value(state, 2);
  2297. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2298. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2299. lua_interface->ResetFunctionStack(state);
  2300. if (!spawn) {
  2301. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2302. return 0;
  2303. }
  2304. if (!spawn->IsEntity()) {
  2305. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2306. return 0;
  2307. }
  2308. if (value == 0) {
  2309. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2310. return 0;
  2311. }
  2312. if (!luaspell || !luaspell->spell) {
  2313. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2314. return 0;
  2315. }
  2316. if(luaspell->resisted) {
  2317. return 0;
  2318. }
  2319. int32 class_req = 0;
  2320. vector<int16> faction_req;
  2321. vector<int16> race_req;
  2322. int32 class_id = 0;
  2323. int32 i = 0;
  2324. int8 f = 0;
  2325. int8 r = 0;
  2326. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2327. if (class_id < 100) {
  2328. class_req += pow(2.0, double(class_id - 1));
  2329. }
  2330. else if (class_id > 100 && class_id < 1000) {
  2331. race_req.push_back(class_id);
  2332. r++;
  2333. }
  2334. else {
  2335. faction_req.push_back(class_id);
  2336. f++;
  2337. }
  2338. i++;
  2339. }
  2340. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2341. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2342. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2343. if (spawn->IsPlayer())
  2344. ((Player*)spawn)->SetCharSheetChanged(true);
  2345. return 0;
  2346. }
  2347. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2348. if (!lua_interface)
  2349. return 0;
  2350. Spawn* spawn = lua_interface->GetSpawn(state);
  2351. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2352. if (!spawn) {
  2353. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2354. return 0;
  2355. }
  2356. if (!spawn->IsEntity()) {
  2357. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2358. return 0;
  2359. }
  2360. if (!luaspell || !luaspell->spell) {
  2361. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2362. return 0;
  2363. }
  2364. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2365. if (spawn->IsPlayer())
  2366. ((Player*)spawn)->SetCharSheetChanged(true);
  2367. return 0;
  2368. }
  2369. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2370. if (!lua_interface)
  2371. return 0;
  2372. Spawn* spawn = lua_interface->GetSpawn(state);
  2373. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2374. lua_interface->ResetFunctionStack(state);
  2375. if (luaspell && luaspell->spell) {
  2376. ZoneServer* zone = nullptr;
  2377. if (luaspell->caster != nullptr)
  2378. zone = luaspell->caster->GetZone();
  2379. if(!zone && spawn) {
  2380. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2381. }
  2382. Spawn* target = 0;
  2383. if(zone) {
  2384. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2385. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2386. target = zone->GetSpawnByID(luaspell->targets[i]);
  2387. if (target && target->IsEntity()) {
  2388. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2389. if (target->IsPlayer())
  2390. ((Player*)target)->SetCharSheetChanged(true);
  2391. }
  2392. }
  2393. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2394. }
  2395. else {
  2396. LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn->GetName());
  2397. }
  2398. }
  2399. else if (spawn && spawn->IsEntity()) {
  2400. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2401. if (spawn->IsPlayer())
  2402. ((Player*)spawn)->SetCharSheetChanged(true);
  2403. }
  2404. return 0;
  2405. }
  2406. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2407. if (!lua_interface)
  2408. return 0;
  2409. Spawn* spawn = lua_interface->GetSpawn(state);
  2410. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2411. float value = lua_interface->GetFloatValue(state, 3);
  2412. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2413. if (value != 0) {
  2414. int32 spell_id = 0;
  2415. if (luaspell && luaspell->spell && luaspell->caster) {
  2416. if(luaspell->resisted) {
  2417. lua_interface->ResetFunctionStack(state);
  2418. return 0;
  2419. }
  2420. spell_id = luaspell->spell->GetSpellID();
  2421. ZoneServer* zone = luaspell->caster->GetZone();
  2422. Spawn* target = 0;
  2423. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2424. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2425. target = zone->GetSpawnByID(luaspell->targets[i]);
  2426. if (target && target->Alive()) {
  2427. if (target->IsPlayer()) {
  2428. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2429. Client* client = ((Player*)target)->GetClient();
  2430. if (client) {
  2431. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2432. if (packet)
  2433. client->QueuePacket(packet);
  2434. }
  2435. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2436. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2437. }
  2438. else if (target->IsNPC()) {
  2439. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2440. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2441. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2442. }
  2443. else
  2444. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2445. }
  2446. }
  2447. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2448. }
  2449. else if (spawn) {
  2450. if (spawn->IsPlayer()) {
  2451. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2452. Client* client = ((Player*)spawn)->GetClient();
  2453. if (client) {
  2454. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2455. if (packet)
  2456. client->QueuePacket(packet);
  2457. }
  2458. }
  2459. else if (spawn->IsNPC())
  2460. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2461. else
  2462. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2463. }
  2464. }
  2465. else
  2466. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2467. return 0;
  2468. }
  2469. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2470. if (!lua_interface)
  2471. return 0;
  2472. Spawn* spawn = lua_interface->GetSpawn(state);
  2473. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2474. lua_interface->ResetFunctionStack(state);
  2475. int32 spell_id = 0;
  2476. if (luaspell && luaspell->spell && luaspell->caster) {
  2477. if(luaspell->resisted) {
  2478. return 0;
  2479. }
  2480. spell_id = luaspell->spell->GetSpellID();
  2481. ZoneServer* zone = luaspell->caster->GetZone();
  2482. Spawn* target = 0;
  2483. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2484. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2485. target = zone->GetSpawnByID(luaspell->targets[i]);
  2486. if (target) {
  2487. if (target->IsPlayer()) {
  2488. ((Player*)target)->RemoveSkillBonus(spell_id);
  2489. Client* client = ((Player*)target)->GetClient();
  2490. if (client) {
  2491. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2492. if (packet)
  2493. client->QueuePacket(packet);
  2494. }
  2495. }
  2496. else if (target->IsNPC())
  2497. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2498. else
  2499. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2500. }
  2501. }
  2502. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2503. }
  2504. else if (spawn) {
  2505. if (spawn->IsPlayer()) {
  2506. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2507. Client* client = ((Player*)spawn)->GetClient();
  2508. if (client) {
  2509. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2510. if (packet)
  2511. client->QueuePacket(packet);
  2512. }
  2513. }
  2514. else if (spawn->IsNPC())
  2515. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2516. else
  2517. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2518. }
  2519. return 0;
  2520. }
  2521. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2522. if (!lua_interface)
  2523. return 0;
  2524. Spawn* spawn = lua_interface->GetSpawn(state);
  2525. int8 type = lua_interface->GetInt32Value(state, 2);
  2526. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2527. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2528. lua_interface->ResetFunctionStack(state);
  2529. if(!luaspell || luaspell->resisted) {
  2530. return 0;
  2531. }
  2532. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2533. ZoneServer* zone = luaspell->caster->GetZone();
  2534. Spawn* target = 0;
  2535. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2536. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2537. target = zone->GetSpawnByID(luaspell->targets[i]);
  2538. if (target && target->IsEntity()) {
  2539. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2540. ((Entity*)target)->AddMezSpell(luaspell);
  2541. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2542. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2543. if (target->IsNPC())
  2544. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2545. }
  2546. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2547. ((Entity*)target)->AddStifleSpell(luaspell);
  2548. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2549. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2550. if (target->IsNPC())
  2551. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2552. }
  2553. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2554. ((Entity*)target)->AddDazeSpell(luaspell);
  2555. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2556. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2557. if (target->IsNPC())
  2558. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2559. }
  2560. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2561. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2562. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2563. ((Entity*)target)->AddStunSpell(luaspell);
  2564. if (target->IsNPC())
  2565. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2566. }
  2567. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2568. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2569. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2570. ((Entity*)target)->AddRootSpell(luaspell);
  2571. if (target->IsNPC())
  2572. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2573. }
  2574. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2575. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2576. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2577. ((Entity*)target)->AddFearSpell(luaspell);
  2578. if (target->IsNPC())
  2579. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2580. }
  2581. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2582. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2583. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2584. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2585. }
  2586. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2587. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2588. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2589. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2590. }
  2591. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2592. ((Entity*)target)->AddSnareSpell(luaspell);
  2593. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2594. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2595. if (target->IsNPC())
  2596. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2597. }
  2598. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2599. ((Entity*)target)->AddFlightSpell(luaspell);
  2600. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2601. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2602. }
  2603. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2604. ((Entity*)target)->AddGlideSpell(luaspell);
  2605. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2606. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2607. }
  2608. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2609. ((Entity*)target)->AddSafefallSpell(luaspell);
  2610. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2611. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2612. }
  2613. else
  2614. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2615. }
  2616. else
  2617. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2618. }
  2619. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2620. }
  2621. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2622. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2623. ((Entity*)spawn)->AddMezSpell(luaspell);
  2624. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2625. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2626. }
  2627. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2628. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2629. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2630. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2631. }
  2632. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2633. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2634. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2635. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2636. }
  2637. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2638. ((Entity*)spawn)->AddStunSpell(luaspell);
  2639. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2640. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2641. }
  2642. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2643. ((Entity*)spawn)->AddRootSpell(luaspell);
  2644. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2645. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2646. }
  2647. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2648. ((Entity*)spawn)->AddFearSpell(luaspell);
  2649. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2650. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2651. }
  2652. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2653. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2654. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2655. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2656. }
  2657. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2658. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2659. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2660. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2661. }
  2662. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2663. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2664. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2665. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2666. }
  2667. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2668. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2669. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2670. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2671. }
  2672. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2673. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2674. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2675. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2676. }
  2677. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2678. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2679. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2680. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2681. }
  2682. else
  2683. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2684. }
  2685. else
  2686. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2687. return 0;
  2688. }
  2689. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2690. if (!lua_interface)
  2691. return 0;
  2692. Spawn* spawn = lua_interface->GetSpawn(state);
  2693. int8 type = lua_interface->GetInt8Value(state, 2);
  2694. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2695. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2696. lua_interface->ResetFunctionStack(state);
  2697. if (spawn && spawn->IsEntity()) {
  2698. if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
  2699. ZoneServer* zone = luaspell->caster->GetZone();
  2700. Spawn* target = 0;
  2701. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2702. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2703. target = zone->GetSpawnByID(luaspell->targets[i]);
  2704. if (target) {
  2705. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2706. ((Entity*)target)->RemoveMezSpell(luaspell);
  2707. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2708. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2709. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2710. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2711. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2712. ((Entity*)target)->RemoveStunSpell(luaspell);
  2713. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2714. ((Entity*)target)->RemoveRootSpell(luaspell);
  2715. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2716. ((Entity*)target)->RemoveFearSpell(luaspell);
  2717. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2718. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2719. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2720. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2721. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2722. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2723. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2724. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2725. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2726. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2727. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2728. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2729. else
  2730. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2731. }
  2732. }
  2733. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2734. }
  2735. else if (only_remove_spawn) {
  2736. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2737. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2738. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2739. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2740. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2741. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2742. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2743. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2744. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2745. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2746. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2747. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2748. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2749. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2750. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2751. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2752. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2753. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2754. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2755. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2756. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2757. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2758. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2759. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2760. else
  2761. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2762. }
  2763. }
  2764. return 0;
  2765. }
  2766. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2767. if (!lua_interface)
  2768. return 0;
  2769. Spawn* spawn = lua_interface->GetSpawn(state);
  2770. int8 type = lua_interface->GetInt8Value(state, 2);
  2771. lua_interface->ResetFunctionStack(state);
  2772. bool hasEffect = false;
  2773. if (!spawn)
  2774. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2775. else if (!spawn->IsEntity())
  2776. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2777. else if (type < CONTROL_MAX_EFFECTS)
  2778. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2779. else
  2780. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2781. lua_interface->SetBooleanValue(state, hasEffect);
  2782. return 1;
  2783. }
  2784. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2785. if (!lua_interface)
  2786. return 0;
  2787. Spawn* spawn = lua_interface->GetSpawn(state);
  2788. float distance = 0.0f;
  2789. lua_interface->ResetFunctionStack(state);
  2790. if (!spawn)
  2791. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2792. else if (!spawn->IsNPC())
  2793. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2794. else
  2795. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2796. lua_interface->SetFloatValue(state, distance);
  2797. return 1;
  2798. }
  2799. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2800. if (!lua_interface)
  2801. return 0;
  2802. Spawn* spawn = lua_interface->GetSpawn(state);
  2803. float distance = 0.0f;
  2804. lua_interface->ResetFunctionStack(state);
  2805. if (!spawn)
  2806. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2807. else if (!spawn->IsNPC())
  2808. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2809. else
  2810. distance = ((NPC*)spawn)->GetAggroRadius();
  2811. lua_interface->SetFloatValue(state, distance);
  2812. return 1;
  2813. }
  2814. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2815. if (!lua_interface)
  2816. return 0;
  2817. Spawn* spawn = lua_interface->GetSpawn(state);
  2818. float distance = lua_interface->GetFloatValue(state, 2);
  2819. bool override_ = lua_interface->GetBooleanValue(state, 3);
  2820. bool result = false;
  2821. lua_interface->ResetFunctionStack(state);
  2822. if (!spawn)
  2823. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2824. else if (!spawn->IsNPC())
  2825. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2826. else
  2827. {
  2828. ((NPC*)spawn)->SetAggroRadius(distance, override_);
  2829. result = true;
  2830. }
  2831. lua_interface->SetBooleanValue(state, result);
  2832. return 1;
  2833. }
  2834. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2835. if (!lua_interface)
  2836. return 0;
  2837. Spawn* spawn = lua_interface->GetSpawn(state);
  2838. int16 value = lua_interface->GetInt16Value(state, 2);
  2839. lua_interface->ResetFunctionStack(state);
  2840. if (spawn && spawn->IsEntity()) {
  2841. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2842. if (spawn->IsPlayer())
  2843. ((Player*)spawn)->SetCharSheetChanged(true);
  2844. }
  2845. return 0;
  2846. }
  2847. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2848. if (!lua_interface)
  2849. return 0;
  2850. Spawn* spawn = lua_interface->GetSpawn(state);
  2851. int16 value = lua_interface->GetInt16Value(state, 2);
  2852. lua_interface->ResetFunctionStack(state);
  2853. if (spawn && spawn->IsEntity()) {
  2854. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2855. if (spawn->IsPlayer())
  2856. ((Player*)spawn)->SetCharSheetChanged(true);
  2857. }
  2858. return 0;
  2859. }
  2860. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2861. if (!lua_interface)
  2862. return 0;
  2863. Spawn* spawn = lua_interface->GetSpawn(state);
  2864. int16 value = lua_interface->GetInt16Value(state, 2);
  2865. lua_interface->ResetFunctionStack(state);
  2866. if (spawn && spawn->IsEntity()) {
  2867. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2868. if (spawn->IsPlayer())
  2869. ((Player*)spawn)->SetCharSheetChanged(true);
  2870. }
  2871. return 0;
  2872. }
  2873. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2874. if (!lua_interface)
  2875. return 0;
  2876. Spawn* spawn = lua_interface->GetSpawn(state);
  2877. int16 value = lua_interface->GetInt16Value(state, 2);
  2878. lua_interface->ResetFunctionStack(state);
  2879. if (spawn && spawn->IsEntity()) {
  2880. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2881. if (spawn->IsPlayer())
  2882. ((Player*)spawn)->SetCharSheetChanged(true);
  2883. }
  2884. return 0;
  2885. }
  2886. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2887. if (!lua_interface)
  2888. return 0;
  2889. Spawn* spawn = lua_interface->GetSpawn(state);
  2890. int16 value = lua_interface->GetInt16Value(state, 2);
  2891. lua_interface->ResetFunctionStack(state);
  2892. if (spawn && spawn->IsEntity()) {
  2893. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2894. if (spawn->IsPlayer())
  2895. ((Player*)spawn)->SetCharSheetChanged(true);
  2896. }
  2897. return 0;
  2898. }
  2899. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2900. if (!lua_interface)
  2901. return 0;
  2902. Spawn* spawn = lua_interface->GetSpawn(state);
  2903. int8 value = lua_interface->GetInt8Value(state, 2);
  2904. lua_interface->ResetFunctionStack(state);
  2905. if (spawn && spawn->IsEntity()) {
  2906. ((Entity*)spawn)->SetDeity(value);
  2907. if (spawn->IsPlayer())
  2908. ((Player*)spawn)->SetCharSheetChanged(true);
  2909. }
  2910. lua_interface->ResetFunctionStack(state);
  2911. return 0;
  2912. }
  2913. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2914. if (!lua_interface)
  2915. return 0;
  2916. Spawn* spawn = lua_interface->GetSpawn(state);
  2917. lua_interface->ResetFunctionStack(state);
  2918. if (spawn && spawn->IsEntity()) {
  2919. int8 deity = ((Entity*)spawn)->GetDeity();
  2920. lua_interface->SetInt32Value(state, deity);
  2921. return 1;
  2922. }
  2923. return 0;
  2924. }
  2925. int EQ2Emu_lua_SetInt(lua_State* state) {
  2926. if (!lua_interface)
  2927. return 0;
  2928. Spawn* spawn = lua_interface->GetSpawn(state);
  2929. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2930. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2931. lua_interface->ResetFunctionStack(state);
  2932. if (spawn && spawn->IsEntity()) {
  2933. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2934. if (spawn->IsPlayer())
  2935. ((Player*)spawn)->SetCharSheetChanged(true);
  2936. }
  2937. return 0;
  2938. }
  2939. int EQ2Emu_lua_SetWis(lua_State* state) {
  2940. if (!lua_interface)
  2941. return 0;
  2942. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2943. Spawn* spawn = lua_interface->GetSpawn(state);
  2944. float value = lua_interface->GetFloatValue(state, 2);
  2945. lua_interface->ResetFunctionStack(state);
  2946. if (spawn && spawn->IsEntity()) {
  2947. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2948. if (spawn->IsPlayer())
  2949. ((Player*)spawn)->SetCharSheetChanged(true);
  2950. }
  2951. return 0;
  2952. }
  2953. int EQ2Emu_lua_SetSta(lua_State* state) {
  2954. if (!lua_interface)
  2955. return 0;
  2956. Spawn* spawn = lua_interface->GetSpawn(state);
  2957. float value = lua_interface->GetFloatValue(state, 2);
  2958. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2959. lua_interface->ResetFunctionStack(state);
  2960. if (spawn && spawn->IsEntity()) {
  2961. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2962. if (spawn->IsPlayer())
  2963. ((Player*)spawn)->SetCharSheetChanged(true);
  2964. }
  2965. return 0;
  2966. }
  2967. int EQ2Emu_lua_SetStr(lua_State* state) {
  2968. if (!lua_interface)
  2969. return 0;
  2970. Spawn* spawn = lua_interface->GetSpawn(state);
  2971. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2972. float value = lua_interface->GetFloatValue(state, 2);
  2973. lua_interface->ResetFunctionStack(state);
  2974. if (spawn && spawn->IsEntity()) {
  2975. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2976. if (spawn->IsPlayer())
  2977. ((Player*)spawn)->SetCharSheetChanged(true);
  2978. }
  2979. return 0;
  2980. }
  2981. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2982. if (!lua_interface)
  2983. return 0;
  2984. Spawn* spawn = lua_interface->GetSpawn(state);
  2985. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2986. float value = lua_interface->GetFloatValue(state, 2);
  2987. lua_interface->ResetFunctionStack(state);
  2988. if (spawn && spawn->IsEntity()) {
  2989. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2990. if (spawn->IsPlayer())
  2991. ((Player*)spawn)->SetCharSheetChanged(true);
  2992. }
  2993. return 0;
  2994. }
  2995. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2996. if (!lua_interface)
  2997. return 0;
  2998. Spawn* spawn = lua_interface->GetSpawn(state);
  2999. lua_interface->ResetFunctionStack(state);
  3000. if (spawn) {
  3001. lua_interface->SetInt32Value(state, spawn->GetHP());
  3002. return 1;
  3003. }
  3004. return 0;
  3005. }
  3006. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  3007. if (!lua_interface)
  3008. return 0;
  3009. Spawn* spawn = lua_interface->GetSpawn(state);
  3010. lua_interface->ResetFunctionStack(state);
  3011. if (spawn) {
  3012. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  3013. return 1;
  3014. }
  3015. return 0;
  3016. }
  3017. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  3018. if (!lua_interface)
  3019. return 0;
  3020. Spawn* spawn = lua_interface->GetSpawn(state);
  3021. lua_interface->ResetFunctionStack(state);
  3022. if (spawn) {
  3023. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  3024. return 1;
  3025. }
  3026. return 0;
  3027. }
  3028. int EQ2Emu_lua_GetName(lua_State* state) {
  3029. if (!lua_interface)
  3030. return 0;
  3031. Spawn* spawn = lua_interface->GetSpawn(state);
  3032. lua_interface->ResetFunctionStack(state);
  3033. if (spawn) {
  3034. lua_interface->SetStringValue(state, spawn->GetName());
  3035. return 1;
  3036. }
  3037. return 0;
  3038. }
  3039. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3040. Spawn* spawn = lua_interface->GetSpawn(state);
  3041. lua_interface->ResetFunctionStack(state);
  3042. if (spawn) {
  3043. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3044. return 1;
  3045. }
  3046. return 0;
  3047. }
  3048. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3049. Spawn* spawn = lua_interface->GetSpawn(state);
  3050. lua_interface->ResetFunctionStack(state);
  3051. if (spawn) {
  3052. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3053. return 1;
  3054. }
  3055. return 0;
  3056. }
  3057. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3058. if (!lua_interface)
  3059. return 0;
  3060. Spawn* spawn = lua_interface->GetSpawn(state);
  3061. lua_interface->ResetFunctionStack(state);
  3062. if (spawn) {
  3063. lua_interface->SetInt32Value(state, spawn->GetPower());
  3064. return 1;
  3065. }
  3066. return 0;
  3067. }
  3068. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3069. if (!lua_interface)
  3070. return 0;
  3071. Spawn* spawn = lua_interface->GetSpawn(state);
  3072. lua_interface->ResetFunctionStack(state);
  3073. if (spawn) {
  3074. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3075. return 1;
  3076. }
  3077. return 0;
  3078. }
  3079. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3080. if (!lua_interface)
  3081. return 0;
  3082. Spawn* spawn = lua_interface->GetSpawn(state);
  3083. lua_interface->ResetFunctionStack(state);
  3084. if (spawn) {
  3085. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3086. return 1;
  3087. }
  3088. return 0;
  3089. }
  3090. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3091. if (!lua_interface)
  3092. return 0;
  3093. Spawn* spawn = lua_interface->GetSpawn(state);
  3094. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3095. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3096. lua_interface->ResetFunctionStack(state);
  3097. if (spawn && spawn2) {
  3098. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3099. lua_interface->SetFloatValue(state, distance);
  3100. return 1;
  3101. }
  3102. return 0;
  3103. }
  3104. int EQ2Emu_lua_GetX(lua_State* state) {
  3105. if (!lua_interface)
  3106. return 0;
  3107. Spawn* spawn = lua_interface->GetSpawn(state);
  3108. lua_interface->ResetFunctionStack(state);
  3109. if (spawn) {
  3110. lua_interface->SetFloatValue(state, spawn->GetX());
  3111. return 1;
  3112. }
  3113. return 0;
  3114. }
  3115. int EQ2Emu_lua_GetY(lua_State* state) {
  3116. if (!lua_interface)
  3117. return 0;
  3118. Spawn* spawn = lua_interface->GetSpawn(state);
  3119. lua_interface->ResetFunctionStack(state);
  3120. if (spawn) {
  3121. lua_interface->SetFloatValue(state, spawn->GetY());
  3122. return 1;
  3123. }
  3124. return 0;
  3125. }
  3126. int EQ2Emu_lua_GetZ(lua_State* state) {
  3127. if (!lua_interface)
  3128. return 0;
  3129. Spawn* spawn = lua_interface->GetSpawn(state);
  3130. lua_interface->ResetFunctionStack(state);
  3131. if (spawn) {
  3132. lua_interface->SetFloatValue(state, spawn->GetZ());
  3133. return 1;
  3134. }
  3135. return 0;
  3136. }
  3137. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3138. if (!lua_interface)
  3139. return 0;
  3140. Spawn* spawn = lua_interface->GetSpawn(state);
  3141. lua_interface->ResetFunctionStack(state);
  3142. if (spawn) {
  3143. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3144. return 1;
  3145. }
  3146. return 0;
  3147. }
  3148. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3149. if (!lua_interface)
  3150. return 0;
  3151. Spawn* spawn = lua_interface->GetSpawn(state);
  3152. lua_interface->ResetFunctionStack(state);
  3153. if (spawn) {
  3154. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3155. return 1;
  3156. }
  3157. return 0;
  3158. }
  3159. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3160. if (!lua_interface)
  3161. return 0;
  3162. Spawn* spawn = lua_interface->GetSpawn(state);
  3163. lua_interface->ResetFunctionStack(state);
  3164. if (spawn) {
  3165. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3166. return 1;
  3167. }
  3168. return 0;
  3169. }
  3170. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3171. if (!lua_interface)
  3172. return 0;
  3173. Spawn* spawn = lua_interface->GetSpawn(state);
  3174. lua_interface->ResetFunctionStack(state);
  3175. if (spawn && spawn->IsEntity()) {
  3176. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3177. return 1;
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_GetInt(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Spawn* spawn = lua_interface->GetSpawn(state);
  3185. lua_interface->ResetFunctionStack(state);
  3186. if (spawn && spawn->IsEntity()) {
  3187. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3188. return 1;
  3189. }
  3190. return 0;
  3191. }
  3192. int EQ2Emu_lua_GetWis(lua_State* state) {
  3193. if (!lua_interface)
  3194. return 0;
  3195. Spawn* spawn = lua_interface->GetSpawn(state);
  3196. lua_interface->ResetFunctionStack(state);
  3197. if (spawn && spawn->IsEntity()) {
  3198. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3199. return 1;
  3200. }
  3201. return 0;
  3202. }
  3203. int EQ2Emu_lua_GetSta(lua_State* state) {
  3204. if (!lua_interface)
  3205. return 0;
  3206. Spawn* spawn = lua_interface->GetSpawn(state);
  3207. lua_interface->ResetFunctionStack(state);
  3208. if (spawn && spawn->IsEntity()) {
  3209. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3210. return 1;
  3211. }
  3212. return 0;
  3213. }
  3214. int EQ2Emu_lua_GetStr(lua_State* state) {
  3215. if (!lua_interface)
  3216. return 0;
  3217. Spawn* spawn = lua_interface->GetSpawn(state);
  3218. lua_interface->ResetFunctionStack(state);
  3219. if (spawn && spawn->IsEntity()) {
  3220. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3221. return 1;
  3222. }
  3223. return 0;
  3224. }
  3225. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3226. if (!lua_interface)
  3227. return 0;
  3228. Spawn* spawn = lua_interface->GetSpawn(state);
  3229. lua_interface->ResetFunctionStack(state);
  3230. if (spawn && spawn->IsEntity()) {
  3231. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3232. return 1;
  3233. }
  3234. return 0;
  3235. }
  3236. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3237. if (!lua_interface)
  3238. return 0;
  3239. Spawn* spawn = lua_interface->GetSpawn(state);
  3240. lua_interface->ResetFunctionStack(state);
  3241. if (spawn && spawn->IsEntity()) {
  3242. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3243. return 1;
  3244. }
  3245. return 0;
  3246. }
  3247. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3248. if (!lua_interface)
  3249. return 0;
  3250. Spawn* spawn = lua_interface->GetSpawn(state);
  3251. lua_interface->ResetFunctionStack(state);
  3252. if (spawn && spawn->IsEntity()) {
  3253. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3254. return 1;
  3255. }
  3256. return 0;
  3257. }
  3258. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3259. if (!lua_interface)
  3260. return 0;
  3261. Spawn* spawn = lua_interface->GetSpawn(state);
  3262. lua_interface->ResetFunctionStack(state);
  3263. if (spawn && spawn->IsEntity()) {
  3264. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3265. return 1;
  3266. }
  3267. return 0;
  3268. }
  3269. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3270. if (!lua_interface)
  3271. return 0;
  3272. Spawn* spawn = lua_interface->GetSpawn(state);
  3273. lua_interface->ResetFunctionStack(state);
  3274. if (spawn && spawn->IsEntity()) {
  3275. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3276. return 1;
  3277. }
  3278. return 0;
  3279. }
  3280. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3281. if (!lua_interface)
  3282. return 0;
  3283. Spawn* spawn = lua_interface->GetSpawn(state);
  3284. lua_interface->ResetFunctionStack(state);
  3285. if (spawn && spawn->IsEntity()) {
  3286. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3287. return 1;
  3288. }
  3289. return 0;
  3290. }
  3291. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3292. if (!lua_interface)
  3293. return 0;
  3294. Spawn* player = lua_interface->GetSpawn(state);
  3295. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3296. int32 step = lua_interface->GetInt32Value(state, 3);
  3297. lua_interface->ResetFunctionStack(state);
  3298. if (!player || !player->IsPlayer()) {
  3299. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3300. return 0;
  3301. }
  3302. if (quest_id <= 0) {
  3303. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3304. return 0;
  3305. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3306. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3307. return 0;
  3308. }
  3309. if (step > 0) {
  3310. Client* client = ((Player*)player)->GetClient();
  3311. if (client)
  3312. client->AddPendingQuestUpdate(quest_id, step);
  3313. } else {
  3314. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3315. }
  3316. return 0;
  3317. }
  3318. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3319. Spawn* player = lua_interface->GetSpawn(state);
  3320. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3321. int32 step = lua_interface->GetInt32Value(state, 3);
  3322. int32 progress = lua_interface->GetInt32Value(state, 4);
  3323. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3324. Client* client = ((Player*)player)->GetClient();
  3325. if (client)
  3326. client->AddPendingQuestUpdate(quest_id, step, progress);
  3327. }
  3328. return 0;
  3329. }
  3330. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3331. if (!lua_interface)
  3332. return 0;
  3333. Spawn* player = lua_interface->GetSpawn(state);
  3334. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3335. if (player && player->IsPlayer() && quest_id > 0) {
  3336. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3337. return 1;
  3338. }
  3339. return 0;
  3340. }
  3341. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3342. if (!lua_interface)
  3343. return 0;
  3344. Spawn* player = lua_interface->GetSpawn(state);
  3345. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3346. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3347. lua_interface->ResetFunctionStack(state);
  3348. if (player && player->IsPlayer() && quest_id > 0) {
  3349. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3350. return 1;
  3351. }
  3352. return 0;
  3353. }
  3354. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3355. if (!lua_interface)
  3356. return 0;
  3357. Spawn* player = lua_interface->GetSpawn(state);
  3358. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3359. lua_interface->ResetFunctionStack(state);
  3360. if (player && player->IsPlayer() && quest_id > 0) {
  3361. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3362. return 1;
  3363. }
  3364. return 0;
  3365. }
  3366. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3367. if (!lua_interface)
  3368. return 0;
  3369. Quest* quest = lua_interface->GetQuest(state);
  3370. string name = lua_interface->GetStringValue(state, 2);
  3371. string type = lua_interface->GetStringValue(state, 3);
  3372. string zone = lua_interface->GetStringValue(state, 4);
  3373. int16 level = lua_interface->GetInt16Value(state, 5);
  3374. string description = lua_interface->GetStringValue(state, 6);
  3375. lua_interface->ResetFunctionStack(state);
  3376. bool load = true;
  3377. if (!quest) {
  3378. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3379. load = false;
  3380. }
  3381. if (load && name.length() == 0) {
  3382. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3383. load = false;
  3384. }
  3385. if (load && type.length() == 0) {
  3386. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3387. load = false;
  3388. }
  3389. if (load && zone.length() == 0) {
  3390. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3391. load = false;
  3392. }
  3393. if (load && description.length() == 0) {
  3394. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3395. load = false;
  3396. }
  3397. if (load && level == 0) {
  3398. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3399. load = false;
  3400. }
  3401. if (load)
  3402. quest->RegisterQuest(name, type, zone, level, description);
  3403. return 0;
  3404. }
  3405. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3406. if (!lua_interface)
  3407. return 0;
  3408. Quest* quest = lua_interface->GetQuest(state);
  3409. int8 level = lua_interface->GetInt16Value(state, 2);
  3410. lua_interface->ResetFunctionStack(state);
  3411. if (quest) {
  3412. quest->SetPrereqLevel(level);
  3413. }
  3414. return 0;
  3415. }
  3416. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3417. if (!lua_interface)
  3418. return 0;
  3419. Quest* quest = lua_interface->GetQuest(state);
  3420. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3421. lua_interface->ResetFunctionStack(state);
  3422. if (quest) {
  3423. quest->AddPrereqQuest(quest_id);
  3424. }
  3425. return 0;
  3426. }
  3427. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3428. if (!lua_interface)
  3429. return 0;
  3430. Quest* quest = lua_interface->GetQuest(state);
  3431. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3432. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3433. lua_interface->ResetFunctionStack(state);
  3434. if (quest) {
  3435. if (quantity == 0)
  3436. quantity = 1;
  3437. Item* master_item = master_item_list.GetItem(item_id);
  3438. if (master_item) {
  3439. Item* item = new Item(master_item);
  3440. item->details.count = quantity;
  3441. quest->AddPrereqItem(item);
  3442. }
  3443. }
  3444. return 0;
  3445. }
  3446. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3447. if (!lua_interface)
  3448. return 0;
  3449. Spawn* player = lua_interface->GetSpawn(state);
  3450. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3451. lua_interface->ResetFunctionStack(state);
  3452. if(!player || !player->IsPlayer()) {
  3453. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3454. return 0;
  3455. }
  3456. if (quest_id > 0) {
  3457. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) == TRUE));
  3458. return 1;
  3459. } else {
  3460. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3461. }
  3462. return 0;
  3463. }
  3464. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3465. if (!lua_interface)
  3466. return 0;
  3467. Quest* quest = lua_interface->GetQuest(state);
  3468. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3469. lua_interface->ResetFunctionStack(state);
  3470. if (quest && spawn_id > 0)
  3471. quest->SetQuestReturnNPC(spawn_id);
  3472. return 0;
  3473. }
  3474. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3475. if (!lua_interface)
  3476. return 0;
  3477. Spawn* spawn = lua_interface->GetSpawn(state);
  3478. int32 time = lua_interface->GetInt32Value(state, 2);
  3479. string function = lua_interface->GetStringValue(state, 3);
  3480. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3481. Spawn* player = lua_interface->GetSpawn(state, 5);
  3482. lua_interface->ResetFunctionStack(state);
  3483. if (!spawn) {
  3484. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3485. return 0;
  3486. }
  3487. if (time <= 0) {
  3488. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3489. return 0;
  3490. }
  3491. if (function.length() == 0) {
  3492. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3493. return 0;
  3494. }
  3495. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3496. if ( time < 10)
  3497. time = 10;
  3498. timer->timer = Timer::GetCurrentTime2() + time;
  3499. timer->function = function;
  3500. timer->spawn = spawn->GetID();
  3501. timer->player = player ? player->GetID() : 0;
  3502. if (max_count == 0)
  3503. max_count = 1;
  3504. timer->max_count = max_count;
  3505. timer->current_count = 0;
  3506. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3507. return 0;
  3508. }
  3509. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3510. if (!lua_interface)
  3511. return 0;
  3512. Spawn* spawn = lua_interface->GetSpawn(state);
  3513. string function = lua_interface->GetStringValue(state, 2);
  3514. lua_interface->ResetFunctionStack(state);
  3515. if (!spawn) {
  3516. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3517. return 0;
  3518. }
  3519. if(!spawn->GetZone()) {
  3520. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3521. return 0;
  3522. }
  3523. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3524. return 0;
  3525. }
  3526. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3527. if (!lua_interface)
  3528. return 0;
  3529. Spawn* player = lua_interface->GetSpawn(state);
  3530. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3531. lua_interface->ResetFunctionStack(state);
  3532. if (player && player->IsPlayer() && quest_id > 0) {
  3533. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3534. return 1;
  3535. }
  3536. return 0;
  3537. }
  3538. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3539. if (!lua_interface)
  3540. return 0;
  3541. Spawn* player = lua_interface->GetSpawn(state);
  3542. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3543. lua_interface->ResetFunctionStack(state);
  3544. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3545. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3546. if (quest)
  3547. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3548. return 1;
  3549. }
  3550. return 0;
  3551. }
  3552. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3553. if (!lua_interface)
  3554. return 0;
  3555. Spawn* player = lua_interface->GetSpawn(state);
  3556. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3557. lua_interface->ResetFunctionStack(state);
  3558. if (player && player->IsPlayer() && quest_id > 0) {
  3559. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3560. return 1;
  3561. }
  3562. return 0;
  3563. }
  3564. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3565. if (!lua_interface)
  3566. return 0;
  3567. Spawn* npc = lua_interface->GetSpawn(state);
  3568. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3569. lua_interface->ResetFunctionStack(state);
  3570. if (npc && !npc->IsPlayer() && quest_id > 0)
  3571. npc->AddProvidedQuest(quest_id);
  3572. return 0;
  3573. }
  3574. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3575. if (!lua_interface)
  3576. return 0;
  3577. Spawn* npc = lua_interface->GetSpawn(state);
  3578. Spawn* player = lua_interface->GetSpawn(state, 2);
  3579. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3580. bool forced = lua_interface->GetBooleanValue(state, 4);
  3581. lua_interface->ResetFunctionStack(state);
  3582. /* NPC is allowed to be null */
  3583. if (player && player->IsPlayer() && quest_id > 0) {
  3584. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3585. if (master_quest) {
  3586. Client* client = ((Player*)player)->GetClient();
  3587. if (!client) {
  3588. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3589. }
  3590. Quest* quest = new Quest(master_quest);
  3591. if (!quest) {
  3592. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3593. }
  3594. if (client && quest) {
  3595. if (npc)
  3596. quest->SetQuestGiver(npc->GetDatabaseID());
  3597. else
  3598. quest->SetQuestGiver(0);
  3599. client->AddPendingQuest(quest, forced);
  3600. }
  3601. }
  3602. else {
  3603. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3604. }
  3605. }
  3606. else {
  3607. lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
  3608. }
  3609. return 0;
  3610. }
  3611. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3612. if (!lua_interface)
  3613. return 0;
  3614. Quest* quest = lua_interface->GetQuest(state);
  3615. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3616. lua_interface->ResetFunctionStack(state);
  3617. if (quest) {
  3618. quest->AddPrereqClass(class_id);
  3619. }
  3620. return 0;
  3621. }
  3622. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3623. if (!lua_interface)
  3624. return 0;
  3625. Quest* quest = lua_interface->GetQuest(state);
  3626. int8 race = lua_interface->GetInt8Value(state, 2);
  3627. lua_interface->ResetFunctionStack(state);
  3628. if (quest) {
  3629. quest->AddPrereqRace(race);
  3630. }
  3631. return 0;
  3632. }
  3633. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3634. if (!lua_interface)
  3635. return 0;
  3636. Quest* quest = lua_interface->GetQuest(state);
  3637. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3638. lua_interface->ResetFunctionStack(state);
  3639. if (quest) {
  3640. quest->AddPrereqModelType(model_type);
  3641. }
  3642. return 0;
  3643. }
  3644. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3645. if (!lua_interface)
  3646. return 0;
  3647. Quest* quest = lua_interface->GetQuest(state);
  3648. int8 level = lua_interface->GetInt8Value(state, 2);
  3649. lua_interface->ResetFunctionStack(state);
  3650. if (!quest) {
  3651. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3652. return 0;
  3653. }
  3654. quest->SetPrereqTSLevel(level);
  3655. return 0;
  3656. }
  3657. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3658. if (!lua_interface)
  3659. return 0;
  3660. Quest* quest = lua_interface->GetQuest(state);
  3661. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3662. lua_interface->ResetFunctionStack(state);
  3663. if (!quest) {
  3664. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3665. return 0;
  3666. }
  3667. quest->AddPrereqTradeskillClass(class_id);
  3668. return 0;
  3669. }
  3670. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3671. if (!lua_interface)
  3672. return 0;
  3673. Quest* quest = lua_interface->GetQuest(state);
  3674. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3675. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3676. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3677. lua_interface->ResetFunctionStack(state);
  3678. if (quest) {
  3679. quest->AddPrereqFaction(faction_id, min, max);
  3680. }
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Quest* quest = lua_interface->GetQuest(state);
  3687. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3688. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3689. lua_interface->ResetFunctionStack(state);
  3690. if (quest) {
  3691. if (quantity == 0)
  3692. quantity = 1;
  3693. Item* master_item = master_item_list.GetItem(item_id);
  3694. if (master_item) {
  3695. Item* item = new Item(master_item);
  3696. item->details.count = quantity;
  3697. quest->AddSelectableRewardItem(item);
  3698. }
  3699. }
  3700. return 0;
  3701. }
  3702. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3703. if (!lua_interface)
  3704. return 0;
  3705. Quest* quest = lua_interface->GetQuest(state);
  3706. if (quest) {
  3707. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3708. vector<Item*>* items = quest->GetRewardItems();
  3709. if (items) {
  3710. vector<Item*>::iterator itr;
  3711. for (itr = items->begin(); itr != items->end(); itr++) {
  3712. if (*itr && (*itr)->details.item_id == item_id) {
  3713. lua_interface->SetBooleanValue(state, true);
  3714. return 1;
  3715. }
  3716. }
  3717. }
  3718. }
  3719. lua_interface->SetBooleanValue(state, false);
  3720. return 1;
  3721. }
  3722. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3723. if (!lua_interface)
  3724. return 0;
  3725. Quest* quest = lua_interface->GetQuest(state);
  3726. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3727. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3728. lua_interface->ResetFunctionStack(state);
  3729. if (quest) {
  3730. if (quantity == 0)
  3731. quantity = 1;
  3732. Item* master_item = master_item_list.GetItem(item_id);
  3733. if (master_item) {
  3734. Item* item = new Item(master_item);
  3735. item->details.count = quantity;
  3736. quest->AddRewardItem(item);
  3737. }
  3738. }
  3739. return 0;
  3740. }
  3741. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3742. if (!lua_interface)
  3743. return 0;
  3744. Quest* quest = lua_interface->GetQuest(state);
  3745. int32 copper = lua_interface->GetInt32Value(state, 2);
  3746. int32 silver = lua_interface->GetInt32Value(state, 3);
  3747. int32 gold = lua_interface->GetInt32Value(state, 4);
  3748. int32 plat = lua_interface->GetInt32Value(state, 5);
  3749. lua_interface->ResetFunctionStack(state);
  3750. if (quest) {
  3751. quest->AddRewardCoins(copper, silver, gold, plat);
  3752. }
  3753. return 0;
  3754. }
  3755. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3756. if (!lua_interface)
  3757. return 0;
  3758. Quest* quest = lua_interface->GetQuest(state);
  3759. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3760. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3761. lua_interface->ResetFunctionStack(state);
  3762. if (quest && faction_id > 0 && amount != 0)
  3763. quest->AddRewardFaction(faction_id, amount);
  3764. return 0;
  3765. }
  3766. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3767. if (!lua_interface)
  3768. return 0;
  3769. Quest* quest = lua_interface->GetQuest(state);
  3770. int32 status = lua_interface->GetInt32Value(state, 2);
  3771. lua_interface->ResetFunctionStack(state);
  3772. if (quest) {
  3773. quest->SetRewardStatus(status);
  3774. }
  3775. return 0;
  3776. }
  3777. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3778. if (!lua_interface)
  3779. return 0;
  3780. Quest* quest = lua_interface->GetQuest(state);
  3781. int32 status = lua_interface->GetInt32Value(state, 2);
  3782. lua_interface->ResetFunctionStack(state);
  3783. if (quest) {
  3784. quest->SetStatusTmpReward(status);
  3785. }
  3786. return 0;
  3787. }
  3788. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3789. if (!lua_interface)
  3790. return 0;
  3791. Quest* quest = lua_interface->GetQuest(state);
  3792. int64 coins = lua_interface->GetInt64Value(state, 2);
  3793. lua_interface->ResetFunctionStack(state);
  3794. if (quest) {
  3795. quest->SetCoinTmpReward(coins);
  3796. }
  3797. return 0;
  3798. }
  3799. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3800. if (!lua_interface)
  3801. return 0;
  3802. Quest* quest = lua_interface->GetQuest(state);
  3803. string comment = lua_interface->GetStringValue(state, 2);
  3804. lua_interface->ResetFunctionStack(state);
  3805. if (quest) {
  3806. quest->SetRewardComment(comment);
  3807. }
  3808. return 0;
  3809. }
  3810. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3811. if (!lua_interface)
  3812. return 0;
  3813. Quest* quest = lua_interface->GetQuest(state);
  3814. int32 exp = lua_interface->GetInt32Value(state, 2);
  3815. lua_interface->ResetFunctionStack(state);
  3816. if (quest) {
  3817. quest->SetRewardXP(exp);
  3818. }
  3819. return 0;
  3820. }
  3821. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3822. Quest* quest = lua_interface->GetQuest(state);
  3823. int32 step = lua_interface->GetInt32Value(state, 2);
  3824. string description = lua_interface->GetStringValue(state, 3);
  3825. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3826. float percentage = lua_interface->GetFloatValue(state, 5);
  3827. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3828. int16 icon = lua_interface->GetInt16Value(state, 7);
  3829. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3830. if (quest) {
  3831. const char* taskgroup = 0;
  3832. if (str_taskgroup.length() > 0)
  3833. taskgroup = str_taskgroup.c_str();
  3834. int32 id = 0;
  3835. vector<int32>* ids = 0;
  3836. int i = 0;
  3837. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3838. if (ids == 0)
  3839. ids = new vector<int32>;
  3840. ids->push_back(id);
  3841. i++;
  3842. }
  3843. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3844. if (quest_step && icon && quantity > 0)
  3845. quest_step->SetIcon(icon);
  3846. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3847. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3848. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3849. }
  3850. }
  3851. lua_interface->ResetFunctionStack(state);
  3852. return 0;
  3853. }
  3854. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3855. {
  3856. if (!lua_interface)
  3857. return 0;
  3858. Quest* quest = lua_interface->GetQuest(state);
  3859. int32 step = lua_interface->GetInt32Value(state, 2);
  3860. string description = lua_interface->GetStringValue(state, 3);
  3861. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3862. float percentage = lua_interface->GetFloatValue(state, 5);
  3863. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3864. int16 icon = lua_interface->GetInt16Value(state, 7);
  3865. if (quest) {
  3866. const char* taskgroup = 0;
  3867. if (str_taskgroup.length() > 0)
  3868. taskgroup = str_taskgroup.c_str();
  3869. int32 id = 0;
  3870. vector<int32>* ids = 0;
  3871. int i = 0;
  3872. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3873. if (ids == 0)
  3874. ids = new vector<int32>;
  3875. ids->push_back(id);
  3876. i++;
  3877. }
  3878. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3879. if (quest_step && icon > 0 && quantity > 0)
  3880. quest_step->SetIcon(icon);
  3881. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3882. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3883. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3884. }
  3885. safe_delete(ids);
  3886. }
  3887. lua_interface->ResetFunctionStack(state);
  3888. return 0;
  3889. }
  3890. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3891. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3892. }
  3893. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3894. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3895. }
  3896. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3897. if (!lua_interface)
  3898. return 0;
  3899. Quest* quest = lua_interface->GetQuest(state);
  3900. int32 step = lua_interface->GetInt32Value(state, 2);
  3901. string description = lua_interface->GetStringValue(state, 3);
  3902. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3903. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3904. int16 icon = lua_interface->GetInt16Value(state, 6);
  3905. if (quest) {
  3906. const char* taskgroup = 0;
  3907. if (str_taskgroup.length() > 0)
  3908. taskgroup = str_taskgroup.c_str();
  3909. int32 npc_id = 0;
  3910. vector<int32>* ids = 0;
  3911. int i = 0;
  3912. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3913. if (ids == 0)
  3914. ids = new vector<int32>;
  3915. ids->push_back(npc_id);
  3916. i++;
  3917. }
  3918. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3919. if (quest_step && icon > 0)
  3920. quest_step->SetIcon(icon);
  3921. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3922. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3923. if(client)
  3924. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3925. }
  3926. safe_delete(ids);
  3927. }
  3928. lua_interface->ResetFunctionStack(state);
  3929. return 0;
  3930. }
  3931. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3932. if (!lua_interface)
  3933. return 0;
  3934. Quest* quest = lua_interface->GetQuest(state);
  3935. int32 step = lua_interface->GetInt32Value(state, 2);
  3936. string description = lua_interface->GetStringValue(state, 3);
  3937. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3938. float percentage = lua_interface->GetFloatValue(state, 5);
  3939. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3940. int16 icon = lua_interface->GetInt16Value(state, 7);
  3941. if (quest) {
  3942. const char* taskgroup = 0;
  3943. if (str_taskgroup.length() > 0)
  3944. taskgroup = str_taskgroup.c_str();
  3945. int32 item_id = 0;
  3946. vector<int32>* ids = 0;
  3947. int i = 0;
  3948. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3949. if (ids == 0)
  3950. ids = new vector<int32>;
  3951. ids->push_back(item_id);
  3952. i++;
  3953. }
  3954. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3955. if (quest_step && icon > 0 && quantity > 0)
  3956. quest_step->SetIcon(icon);
  3957. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3958. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3959. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3960. }
  3961. safe_delete(ids);
  3962. }
  3963. lua_interface->ResetFunctionStack(state);
  3964. return 0;
  3965. }
  3966. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3967. if (!lua_interface)
  3968. return 0;
  3969. Quest* quest = lua_interface->GetQuest(state);
  3970. int32 step = lua_interface->GetInt32Value(state, 2);
  3971. string description = lua_interface->GetStringValue(state, 3);
  3972. float max_variation = lua_interface->GetFloatValue(state, 4);
  3973. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3974. int16 icon = lua_interface->GetInt16Value(state, 6);
  3975. if (quest) {
  3976. const char* taskgroup = 0;
  3977. if (str_taskgroup.length() > 0)
  3978. taskgroup = str_taskgroup.c_str();
  3979. vector<Location>* locations = 0;
  3980. int8 i = 7;
  3981. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3982. while (true) {
  3983. Location loc;
  3984. loc.x = lua_interface->GetFloatValue(state, i);
  3985. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3986. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3987. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3988. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3989. break;
  3990. if (locations == 0)
  3991. locations = new vector<Location>;
  3992. locations->push_back(loc);
  3993. i += 4;
  3994. }
  3995. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3996. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3997. if (quest_step && icon > 0)
  3998. quest_step->SetIcon(icon);
  3999. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4000. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4001. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4002. }
  4003. }
  4004. lua_interface->ResetFunctionStack(state);
  4005. return 0;
  4006. }
  4007. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  4008. if (!lua_interface)
  4009. return 0;
  4010. Quest* quest = lua_interface->GetQuest(state);
  4011. int32 step = lua_interface->GetInt32Value(state, 2);
  4012. string description = lua_interface->GetStringValue(state, 3);
  4013. float max_variation = lua_interface->GetFloatValue(state, 4);
  4014. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  4015. int16 icon = lua_interface->GetInt16Value(state, 6);
  4016. if (quest) {
  4017. const char* taskgroup = 0;
  4018. if (str_taskgroup.length() > 0)
  4019. taskgroup = str_taskgroup.c_str();
  4020. vector<Location>* locations = 0;
  4021. int8 i = 7;
  4022. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4023. while (true) {
  4024. Location loc;
  4025. loc.x = lua_interface->GetFloatValue(state, i);
  4026. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4027. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4028. loc.zone_id = 0;
  4029. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4030. break;
  4031. if (locations == 0)
  4032. locations = new vector<Location>;
  4033. locations->push_back(loc);
  4034. i += 3;
  4035. }
  4036. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4037. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4038. if (quest_step && icon > 0)
  4039. quest_step->SetIcon(icon);
  4040. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4041. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4042. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4043. }
  4044. }
  4045. lua_interface->ResetFunctionStack(state);
  4046. return 0;
  4047. }
  4048. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  4049. if (!lua_interface)
  4050. return 0;
  4051. Quest* quest = lua_interface->GetQuest(state);
  4052. int32 step = lua_interface->GetInt32Value(state, 2);
  4053. string description = lua_interface->GetStringValue(state, 3);
  4054. float max_variation = lua_interface->GetFloatValue(state, 4);
  4055. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  4056. int16 icon = lua_interface->GetInt16Value(state, 6);
  4057. if (quest) {
  4058. const char* taskgroup = 0;
  4059. if (str_taskgroup.length() > 0)
  4060. taskgroup = str_taskgroup.c_str();
  4061. vector<Location>* locations = 0;
  4062. int i = 7;
  4063. while (true) {
  4064. Location loc;
  4065. loc.x = lua_interface->GetFloatValue(state, i);
  4066. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4067. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4068. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4069. break;
  4070. if (locations == 0)
  4071. locations = new vector<Location>;
  4072. locations->push_back(loc);
  4073. i += 3;
  4074. }
  4075. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4076. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4077. if (quest_step && icon > 0)
  4078. quest_step->SetIcon(icon);
  4079. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4080. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4081. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4082. }
  4083. }
  4084. lua_interface->ResetFunctionStack(state);
  4085. return 0;
  4086. }
  4087. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4088. Quest* quest = lua_interface->GetQuest(state);
  4089. int32 step = lua_interface->GetInt32Value(state, 2);
  4090. string description = lua_interface->GetStringValue(state, 3);
  4091. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4092. float percentage = lua_interface->GetFloatValue(state, 5);
  4093. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4094. int16 icon = lua_interface->GetInt16Value(state, 7);
  4095. if (quest) {
  4096. const char* taskgroup = 0;
  4097. if (str_taskgroup.length() > 0)
  4098. taskgroup = str_taskgroup.c_str();
  4099. int32 spell_id = 0;
  4100. vector<int32>* ids = 0;
  4101. int i = 0;
  4102. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4103. if (ids == 0)
  4104. ids = new vector<int32>;
  4105. ids->push_back(spell_id);
  4106. i++;
  4107. }
  4108. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4109. if (quest_step && icon > 0 && quantity > 0)
  4110. quest_step->SetIcon(icon);
  4111. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4112. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4113. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4114. }
  4115. safe_delete(ids);
  4116. }
  4117. lua_interface->ResetFunctionStack(state);
  4118. return 0;
  4119. }
  4120. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4121. if (!lua_interface)
  4122. return 0;
  4123. Quest* quest = lua_interface->GetQuest(state);
  4124. int32 step = lua_interface->GetInt32Value(state, 2);
  4125. string description = lua_interface->GetStringValue(state, 3);
  4126. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4127. float percentage = lua_interface->GetFloatValue(state, 5);
  4128. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4129. int16 icon = lua_interface->GetInt16Value(state, 7);
  4130. if (quest) {
  4131. const char* taskgroup = 0;
  4132. if (str_taskgroup.length() > 0)
  4133. taskgroup = str_taskgroup.c_str();
  4134. int32 item_id = 0;
  4135. vector<int32>* ids = 0;
  4136. int i = 0;
  4137. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4138. if (ids == 0)
  4139. ids = new vector<int32>;
  4140. ids->push_back(item_id);
  4141. i++;
  4142. }
  4143. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4144. if (quest_step && icon > 0 && quantity > 0)
  4145. quest_step->SetIcon(icon);
  4146. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4147. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4148. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4149. }
  4150. safe_delete(ids);
  4151. }
  4152. lua_interface->ResetFunctionStack(state);
  4153. return 0;
  4154. }
  4155. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4156. if (!lua_interface)
  4157. return 0;
  4158. Quest* quest = lua_interface->GetQuest(state);
  4159. int32 step = lua_interface->GetInt32Value(state, 2);
  4160. string description = lua_interface->GetStringValue(state, 3);
  4161. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4162. float percentage = lua_interface->GetFloatValue(state, 5);
  4163. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4164. int16 icon = lua_interface->GetInt16Value(state, 7);
  4165. if (quest) {
  4166. const char* taskgroup = 0;
  4167. if (str_taskgroup.length() > 0)
  4168. taskgroup = str_taskgroup.c_str();
  4169. int32 item_id = 0;
  4170. vector<int32>* ids = 0;
  4171. int i = 0;
  4172. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4173. if (ids == 0)
  4174. ids = new vector<int32>;
  4175. ids->push_back(item_id);
  4176. i++;
  4177. }
  4178. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4179. if (quest_step && icon > 0 && quantity > 0)
  4180. quest_step->SetIcon(icon);
  4181. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4182. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4183. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4184. }
  4185. safe_delete(ids);
  4186. }
  4187. lua_interface->ResetFunctionStack(state);
  4188. return 0;
  4189. }
  4190. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4191. if (!lua_interface)
  4192. return 0;
  4193. Quest* quest = lua_interface->GetQuest(state);
  4194. string action = lua_interface->GetStringValue(state, 2);
  4195. lua_interface->ResetFunctionStack(state);
  4196. if (quest) {
  4197. if (action.length() > 0)
  4198. quest->SetCompleteAction(action);
  4199. }
  4200. return 0;
  4201. }
  4202. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4203. if (!lua_interface)
  4204. return 0;
  4205. Quest* quest = lua_interface->GetQuest(state);
  4206. int32 step = lua_interface->GetInt32Value(state, 2);
  4207. string action = lua_interface->GetStringValue(state, 3);
  4208. lua_interface->ResetFunctionStack(state);
  4209. if (quest) {
  4210. if (step > 0 && action.length() > 0)
  4211. quest->AddCompleteAction(step, action);
  4212. }
  4213. return 0;
  4214. }
  4215. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4216. if (!lua_interface)
  4217. return 0;
  4218. Quest* quest = lua_interface->GetQuest(state);
  4219. int32 step = lua_interface->GetInt32Value(state, 2);
  4220. string action = lua_interface->GetStringValue(state, 3);
  4221. lua_interface->ResetFunctionStack(state);
  4222. if (quest) {
  4223. if (step > 0 && action.length() > 0)
  4224. quest->AddProgressAction(step, action);
  4225. }
  4226. return 0;
  4227. }
  4228. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4229. if (!lua_interface)
  4230. return 0;
  4231. Quest* quest = lua_interface->GetQuest(state);
  4232. string description = lua_interface->GetStringValue(state, 2);
  4233. lua_interface->ResetFunctionStack(state);
  4234. if (quest && description.length() > 0)
  4235. quest->SetDescription(description);
  4236. return 0;
  4237. }
  4238. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4239. if (!lua_interface)
  4240. return 0;
  4241. Quest* quest = lua_interface->GetQuest(state);
  4242. string description = lua_interface->GetStringValue(state, 2);
  4243. lua_interface->ResetFunctionStack(state);
  4244. if (quest && description.length() > 0)
  4245. quest->SetCompletedDescription(description);
  4246. return 0;
  4247. }
  4248. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4249. if (!lua_interface)
  4250. return 0;
  4251. Quest* quest = lua_interface->GetQuest(state);
  4252. int32 step = lua_interface->GetInt32Value(state, 2);
  4253. string description = lua_interface->GetStringValue(state, 3);
  4254. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4255. lua_interface->ResetFunctionStack(state);
  4256. if (quest && step > 0 && description.length() > 0) {
  4257. quest->SetTaskGroupDescription(step, description, display_bullets);
  4258. }
  4259. return 0;
  4260. }
  4261. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4262. if (!lua_interface)
  4263. return 0;
  4264. Quest* quest = lua_interface->GetQuest(state);
  4265. int32 step = lua_interface->GetInt32Value(state, 2);
  4266. string description = lua_interface->GetStringValue(state, 3);
  4267. lua_interface->ResetFunctionStack(state);
  4268. if (quest && step > 0 && description.length() > 0) {
  4269. quest->SetStepDescription(step, description);
  4270. }
  4271. return 0;
  4272. }
  4273. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4274. Quest* quest = lua_interface->GetQuest(state);
  4275. string zone = lua_interface->GetStringValue(state, 2);
  4276. lua_interface->ResetFunctionStack(state);
  4277. if (quest && zone.length() > 0)
  4278. quest->SetZone(zone);
  4279. return 0;
  4280. }
  4281. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4282. if (!lua_interface)
  4283. return 0;
  4284. Quest* quest = lua_interface->GetQuest(state);
  4285. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4286. lua_interface->ResetFunctionStack(state);
  4287. if (quest && spawn) {
  4288. if (spawn->IsPlayer()) {
  4289. Client* client = ((Player*)spawn)->GetClient();
  4290. if (client) {
  4291. client->AddPendingQuestReward(quest);
  4292. }
  4293. }
  4294. }
  4295. return 0;
  4296. }
  4297. int EQ2Emu_lua_Harvest(lua_State* state) {
  4298. if (!lua_interface)
  4299. return 0;
  4300. Spawn* player = lua_interface->GetSpawn(state);
  4301. Spawn* node = lua_interface->GetSpawn(state, 2);
  4302. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4303. Client* client = ((Player*)player)->GetClient();
  4304. if (client) {
  4305. ((GroundSpawn*)node)->ProcessHarvest(client);
  4306. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4307. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4308. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4309. }
  4310. }
  4311. }
  4312. else if (player && player->IsPlayer()) {
  4313. Client* client = ((Player*)player)->GetClient();
  4314. if (client)
  4315. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4316. }
  4317. lua_interface->ResetFunctionStack(state);
  4318. return 0;
  4319. }
  4320. int EQ2Emu_lua_Bind(lua_State* state) {
  4321. if (!lua_interface)
  4322. return 0;
  4323. Spawn* spawn = lua_interface->GetSpawn(state);
  4324. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4325. float x = lua_interface->GetFloatValue(state, 3);
  4326. float y = lua_interface->GetFloatValue(state, 4);
  4327. float z = lua_interface->GetFloatValue(state, 5);
  4328. float h = lua_interface->GetFloatValue(state, 6);
  4329. lua_interface->ResetFunctionStack(state);
  4330. if (!spawn) {
  4331. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4332. return 0;
  4333. }
  4334. if (!spawn->IsPlayer()) {
  4335. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4336. return 0;
  4337. }
  4338. if (zone_id == 0) {
  4339. Client* client = ((Player*)spawn)->GetClient();
  4340. if (!client) {
  4341. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4342. return 0;
  4343. }
  4344. if (!client->Bind())
  4345. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4346. }
  4347. else {
  4348. Player* player = (Player*)spawn;
  4349. player->GetPlayerInfo()->SetBindZone(zone_id);
  4350. player->GetPlayerInfo()->SetBindX(x);
  4351. player->GetPlayerInfo()->SetBindY(y);
  4352. player->GetPlayerInfo()->SetBindZ(z);
  4353. player->GetPlayerInfo()->SetBindHeading(h);
  4354. }
  4355. return 0;
  4356. }
  4357. int EQ2Emu_lua_Gate(lua_State* state) {
  4358. if (!lua_interface)
  4359. return 0;
  4360. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4361. Spawn* spawn = lua_interface->GetSpawn(state);
  4362. lua_interface->ResetFunctionStack(state);
  4363. if (spawn) {
  4364. if (spawn->IsPlayer()) {
  4365. Client* client = ((Player*)spawn)->GetClient();
  4366. if (client) {
  4367. if (!client->Gate((spell != nullptr) ? true : false))
  4368. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4369. }
  4370. }
  4371. }
  4372. return 0;
  4373. }
  4374. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4375. if (!lua_interface)
  4376. return 0;
  4377. bool ret = false;
  4378. Spawn* spawn = lua_interface->GetSpawn(state);
  4379. lua_interface->ResetFunctionStack(state);
  4380. if (spawn) {
  4381. if (spawn->IsPlayer()) {
  4382. Client* client = ((Player*)spawn)->GetClient();
  4383. if (client)
  4384. ret = client->BindAllowed();
  4385. }
  4386. }
  4387. lua_interface->SetBooleanValue(state, ret);
  4388. return 1;
  4389. }
  4390. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4391. if (!lua_interface)
  4392. return 0;
  4393. bool ret = false;
  4394. Spawn* spawn = lua_interface->GetSpawn(state);
  4395. lua_interface->ResetFunctionStack(state);
  4396. if (spawn) {
  4397. if (spawn->IsPlayer()) {
  4398. Client* client = ((Player*)spawn)->GetClient();
  4399. ZoneServer* zone = lua_interface->GetZone(state);
  4400. if (client && zone){
  4401. ret = zone->GetCanGate();
  4402. }
  4403. }
  4404. }
  4405. lua_interface->SetBooleanValue(state, ret);
  4406. return 1;
  4407. }
  4408. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4409. Spawn* spawn = lua_interface->GetSpawn(state);
  4410. lua_interface->ResetFunctionStack(state);
  4411. if (spawn) {
  4412. lua_interface->SetBooleanValue(state, spawn->Alive());
  4413. return 1;
  4414. }
  4415. return 0;
  4416. }
  4417. int EQ2Emu_lua_IsSpawnGroupAlive(lua_State* state) {
  4418. ZoneServer* zone = lua_interface->GetZone(state);
  4419. int32 group_id = lua_interface->GetInt32Value(state, 2);
  4420. lua_interface->ResetFunctionStack(state);
  4421. if (zone) {
  4422. lua_interface->SetBooleanValue(state, zone->IsSpawnGroupAlive(group_id));
  4423. return 1;
  4424. }
  4425. return 0;
  4426. }
  4427. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4428. if (!lua_interface)
  4429. return 0;
  4430. Spawn* spawn = lua_interface->GetSpawn(state);
  4431. lua_interface->ResetFunctionStack(state);
  4432. if (spawn && spawn->IsEntity()) {
  4433. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4434. return 1;
  4435. }
  4436. return 0;
  4437. }
  4438. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4439. Spawn* spawn = lua_interface->GetSpawn(state);
  4440. string message = lua_interface->GetStringValue(state, 2);
  4441. string color_str = lua_interface->GetStringValue(state, 3);
  4442. lua_interface->ResetFunctionStack(state);
  4443. int8 color = CHANNEL_NARRATIVE;
  4444. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4445. Client* client = ((Player*)spawn)->GetClient();
  4446. if (client) {
  4447. if (color_str.length() > 0) {
  4448. // leave for backwards compat, but all future should just use the number
  4449. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4450. color = CHANNEL_COLOR_RED;
  4451. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4452. color = CHANNEL_COLOR_YELLOW;
  4453. else
  4454. {
  4455. // use a number to specify the channel as per Commands/Commands.h defines
  4456. color = (int8)atoul(color_str.c_str());
  4457. }
  4458. }
  4459. client->SimpleMessage(color, message.c_str());
  4460. }
  4461. }
  4462. return 0;
  4463. }
  4464. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4465. Spawn* spawn = lua_interface->GetSpawn(state);
  4466. string message = lua_interface->GetStringValue(state, 2);
  4467. int8 red = lua_interface->GetInt8Value(state, 3);
  4468. int8 green = lua_interface->GetInt8Value(state, 4);
  4469. int8 blue = lua_interface->GetInt8Value(state, 5);
  4470. lua_interface->ResetFunctionStack(state);
  4471. if (!spawn) {
  4472. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4473. return 0;
  4474. }
  4475. if (!spawn->IsPlayer()) {
  4476. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4477. return 0;
  4478. }
  4479. int32 words = ::CountWordsInString(message.c_str());
  4480. if (words < 5)
  4481. words = 5;
  4482. Client* client = ((Player*)spawn)->GetClient();
  4483. if (client)
  4484. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4485. return 0;
  4486. }
  4487. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4488. Spawn* spawn = lua_interface->GetSpawn(state);
  4489. int8 param = lua_interface->GetInt8Value(state, 2);
  4490. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4491. int8 value = lua_interface->GetInt8Value(state, 4);
  4492. lua_interface->ResetFunctionStack(state);
  4493. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4494. Client* client = ((Player*)spawn)->GetClient();
  4495. if (client) {
  4496. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4497. switch (param) {
  4498. case 1: {
  4499. packet->setDataByName("parameter1", param_value);
  4500. break;
  4501. }
  4502. case 2: {
  4503. packet->setDataByName("parameter2", param_value);
  4504. break;
  4505. }
  4506. case 3: {
  4507. packet->setDataByName("parameter3", param_value);
  4508. break;
  4509. }
  4510. case 4: {
  4511. packet->setDataByName("parameter4", param_value);
  4512. break;
  4513. }
  4514. case 5: {
  4515. packet->setDataByName("parameter5", param_value);
  4516. break;
  4517. }
  4518. }
  4519. packet->setDataByName("value", value);
  4520. client->QueuePacket(packet->serialize());
  4521. safe_delete(packet);
  4522. }
  4523. }
  4524. return 0;
  4525. }
  4526. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4527. Spawn* spawn = lua_interface->GetSpawn(state);
  4528. lua_interface->ResetFunctionStack(state);
  4529. if (spawn && spawn->IsPlayer()) {
  4530. if (((Player*)spawn)->GetIsTracking())
  4531. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4532. else
  4533. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4534. }
  4535. return 0;
  4536. }
  4537. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4538. Spawn* player = lua_interface->GetSpawn(state);
  4539. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4540. string name = lua_interface->GetStringValue(state, 3);
  4541. float distance = lua_interface->GetFloatValue(state, 4);
  4542. string command = lua_interface->GetStringValue(state, 5);
  4543. string error_text = lua_interface->GetStringValue(state, 6);
  4544. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4545. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4546. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4547. lua_interface->ResetFunctionStack(state);
  4548. if (spawn) {
  4549. if (distance == 0)
  4550. distance = 10.0f;
  4551. if (command.length() == 0)
  4552. command = name;
  4553. if (command.length() < 1 && name.length() < 1)
  4554. {
  4555. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4556. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4557. spawn->RemovePrimaryCommands();
  4558. }
  4559. else
  4560. {
  4561. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4562. }
  4563. }
  4564. return 0;
  4565. }
  4566. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4567. if (!lua_interface)
  4568. return 0;
  4569. Spawn* player = lua_interface->GetSpawn(state);
  4570. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4571. int16 tier = lua_interface->GetInt16Value(state, 3);
  4572. lua_interface->ResetFunctionStack(state);
  4573. if (player && player->IsPlayer()) {
  4574. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4575. return 1;
  4576. }
  4577. return 0;
  4578. }
  4579. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4580. if (!lua_interface)
  4581. return 0;
  4582. Spawn* player = lua_interface->GetSpawn(state);
  4583. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4584. int16 tier = lua_interface->GetInt16Value(state, 3);
  4585. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4586. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4587. bool add_to_hotbar = true;
  4588. if (num_args > 4) {
  4589. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4590. }
  4591. lua_interface->ResetFunctionStack(state);
  4592. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4593. if (player && spell && player->IsPlayer()) {
  4594. Client* client = player->GetClient();
  4595. if (client) {
  4596. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4597. {
  4598. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4599. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4600. client->GetPlayer()->UnlockSpell(spell);
  4601. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4602. }
  4603. else
  4604. {
  4605. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4606. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4607. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4608. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4609. client->GetPlayer()->UnlockSpell(spell);
  4610. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4611. }
  4612. //if (client ) {
  4613. // ((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);
  4614. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4615. if (outapp)
  4616. client->QueuePacket(outapp);
  4617. }
  4618. }
  4619. return 0;
  4620. }
  4621. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4622. if (!lua_interface)
  4623. return 0;
  4624. Spawn* player = lua_interface->GetSpawn(state);
  4625. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4626. lua_interface->ResetFunctionStack(state);
  4627. if (player && player->IsPlayer()) {
  4628. Client* client = player->GetClient();
  4629. if (client) {
  4630. ((Player*)player)->DeleteSpellBook(type_selection);
  4631. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4632. if (outapp)
  4633. client->QueuePacket(outapp);
  4634. }
  4635. }
  4636. return 0;
  4637. }
  4638. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4639. if (!lua_interface)
  4640. return 0;
  4641. Spawn* player = lua_interface->GetSpawn(state);
  4642. lua_interface->ResetFunctionStack(state);
  4643. if (player && player->IsPlayer()) {
  4644. Client* client = player->GetClient();
  4645. if (client) {
  4646. client->SendNewAdventureSpells();
  4647. }
  4648. }
  4649. return 0;
  4650. }
  4651. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4652. if (!lua_interface)
  4653. return 0;
  4654. Spawn* player = lua_interface->GetSpawn(state);
  4655. lua_interface->ResetFunctionStack(state);
  4656. if (player && player->IsPlayer()) {
  4657. Client* client = player->GetClient();
  4658. if (client) {
  4659. client->SendNewTradeskillSpells();
  4660. }
  4661. }
  4662. return 0;
  4663. }
  4664. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4665. if (!lua_interface)
  4666. return 0;
  4667. Spawn* player = lua_interface->GetSpawn(state);
  4668. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4669. lua_interface->ResetFunctionStack(state);
  4670. if (player && player->IsPlayer()) {
  4671. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4672. Client* client = player->GetClient();
  4673. if (sbe && client) {
  4674. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4675. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4676. if (outapp)
  4677. client->QueuePacket(outapp);
  4678. }
  4679. }
  4680. return 0;
  4681. }
  4682. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4683. if (!lua_interface)
  4684. return 0;
  4685. Spawn* player = lua_interface->GetSpawn(state);
  4686. lua_interface->ResetFunctionStack(state);
  4687. if (player && player->IsPlayer()) {
  4688. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4689. return 1;
  4690. }
  4691. return 0;
  4692. }
  4693. int EQ2Emu_lua_Attack(lua_State* state) {
  4694. if (lua_interface) {
  4695. Spawn* npc = lua_interface->GetSpawn(state);
  4696. Spawn* player = lua_interface->GetSpawn(state, 2);
  4697. lua_interface->ResetFunctionStack(state);
  4698. if (npc && player && npc->IsNPC() && player->IsEntity())
  4699. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4700. }
  4701. return 0;
  4702. }
  4703. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4704. if (lua_interface) {
  4705. Spawn* target = lua_interface->GetSpawn(state);
  4706. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4707. lua_interface->ResetFunctionStack(state);
  4708. if (target && target->GetZone())
  4709. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4710. }
  4711. return 0;
  4712. }
  4713. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4714. Spawn* player;
  4715. if (lua_interface) {
  4716. player = lua_interface->GetSpawn(state);
  4717. lua_interface->ResetFunctionStack(state);
  4718. if (player && player->IsPlayer()) {
  4719. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4720. return 1;
  4721. }
  4722. }
  4723. return 0;
  4724. }
  4725. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4726. Spawn* player;
  4727. Client* client;
  4728. if (lua_interface) {
  4729. player = lua_interface->GetSpawn(state);
  4730. lua_interface->ResetFunctionStack(state);
  4731. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4732. if ((client = ((Player*)player)->GetClient()))
  4733. client->HandInCollections();
  4734. }
  4735. return 0;
  4736. }
  4737. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4738. Spawn* widget;
  4739. if (lua_interface) {
  4740. widget = lua_interface->GetSpawn(state);
  4741. lua_interface->ResetFunctionStack(state);
  4742. if (widget && widget->IsWidget())
  4743. ((Widget*)widget)->HandleUse(nullptr, "");
  4744. }
  4745. return 0;
  4746. }
  4747. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4748. Spawn* spawn = 0;
  4749. int32 primary_list = 0;
  4750. int32 secondary_list = 0;
  4751. if (lua_interface) {
  4752. spawn = lua_interface->GetSpawn(state);
  4753. primary_list = lua_interface->GetInt32Value(state, 2);
  4754. secondary_list = lua_interface->GetInt32Value(state, 3);
  4755. lua_interface->ResetFunctionStack(state);
  4756. if (!spawn->IsNPC()) {
  4757. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4758. return 0;
  4759. }
  4760. NPC* npc = (NPC*)spawn;
  4761. npc->SetPrimarySpellList(primary_list);
  4762. npc->SetSecondarySpellList(secondary_list);
  4763. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4764. }
  4765. return 0;
  4766. }
  4767. int EQ2Emu_lua_GetPet(lua_State* state) {
  4768. if (!lua_interface)
  4769. return 0;
  4770. Spawn* spawn = lua_interface->GetSpawn(state);
  4771. lua_interface->ResetFunctionStack(state);
  4772. if (spawn) {
  4773. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4774. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4775. return 1;
  4776. }
  4777. }
  4778. return 0;
  4779. }
  4780. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4781. if (!lua_interface)
  4782. return 0;
  4783. Spawn* spawn = lua_interface->GetSpawn(state);
  4784. lua_interface->ResetFunctionStack(state);
  4785. if (spawn) {
  4786. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4787. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4788. return 1;
  4789. }
  4790. }
  4791. return 0;
  4792. }
  4793. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4794. if (!lua_interface)
  4795. return 0;
  4796. Spawn* spawn = lua_interface->GetSpawn(state);
  4797. lua_interface->ResetFunctionStack(state);
  4798. if (spawn) {
  4799. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4800. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4801. return 1;
  4802. }
  4803. }
  4804. return 0;
  4805. }
  4806. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4807. if (!lua_interface)
  4808. return 0;
  4809. Spawn* spawn = lua_interface->GetSpawn(state);
  4810. lua_interface->ResetFunctionStack(state);
  4811. if (spawn) {
  4812. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4813. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4814. return 1;
  4815. }
  4816. }
  4817. return 0;
  4818. }
  4819. int EQ2Emu_lua_Charm(lua_State* state) {
  4820. if (!lua_interface)
  4821. return 0;
  4822. Spawn* owner = lua_interface->GetSpawn(state);
  4823. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4824. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4825. lua_interface->ResetFunctionStack(state);
  4826. if (!luaspell) {
  4827. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4828. return 0;
  4829. }
  4830. if(luaspell->resisted) {
  4831. return 0;
  4832. }
  4833. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4834. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4835. pet->SetPet(true);
  4836. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4837. ((NPC*)pet)->SetOwner((Entity*)owner);
  4838. // If owner is player and player does not have a summoned pet set the players charsheet
  4839. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4840. Player* player = (Player*)owner;
  4841. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4842. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4843. player->GetInfoStruct()->set_pet_movement(2);
  4844. player->GetInfoStruct()->set_pet_behavior(3);
  4845. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4846. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4847. // Make sure the values get sent to the client
  4848. player->SetCharSheetChanged(true);
  4849. }
  4850. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4851. pet->SetSpawnScript("");
  4852. // Set faction to the same as the owner
  4853. pet->SetFactionID(owner->GetFactionID());
  4854. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4855. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4856. // Clear hate list
  4857. ((NPC*)pet)->Brain()->ClearHate();
  4858. // Set the brain to a pet brain
  4859. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4860. }
  4861. return 0;
  4862. }
  4863. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4864. if (!lua_interface)
  4865. return 0;
  4866. Spawn* spawn = lua_interface->GetSpawn(state);
  4867. lua_interface->ResetFunctionStack(state);
  4868. if (!spawn) {
  4869. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4870. return 0;
  4871. }
  4872. vector<Spawn*> groupMembers;
  4873. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4874. groupMembers = *spawn->GetSpawnGroup();
  4875. }
  4876. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4877. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4878. deque<GroupMemberInfo*>::iterator itr;
  4879. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4880. if (group)
  4881. {
  4882. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4883. deque<GroupMemberInfo*>* members = group->GetMembers();
  4884. GroupMemberInfo* info = 0;
  4885. for (itr = members->begin(); itr != members->end(); itr++) {
  4886. info = *itr;
  4887. if (info->client)
  4888. groupMembers.push_back(info->client->GetPlayer());
  4889. }
  4890. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4891. }
  4892. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4893. }
  4894. else
  4895. return 0;
  4896. lua_createtable(state, groupMembers.size(), 0);
  4897. int newTable = lua_gettop(state);
  4898. for (int32 i = 0; i < groupMembers.size(); i++) {
  4899. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4900. lua_rawseti(state, newTable, i + 1);
  4901. }
  4902. return 1;
  4903. }
  4904. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4905. if (!lua_interface)
  4906. return 0;
  4907. lua_interface->ResetFunctionStack(state);
  4908. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4909. lua_interface->SetOptionWindowValue(state, option_window);
  4910. return 1;
  4911. }
  4912. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4913. if (!lua_interface)
  4914. return 0;
  4915. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4916. if (option_window) {
  4917. OptionWindowOption option_window_option;
  4918. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4919. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4920. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4921. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4922. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4923. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4924. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4925. option_window->push_back(option_window_option);
  4926. }
  4927. lua_interface->ResetFunctionStack(state);
  4928. return 0;
  4929. }
  4930. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4931. if (!lua_interface)
  4932. return 0;
  4933. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4934. Spawn* player = lua_interface->GetSpawn(state, 2);
  4935. string window_title = lua_interface->GetStringValue(state, 3);
  4936. string cancel_command = lua_interface->GetStringValue(state, 4);
  4937. lua_interface->ResetFunctionStack(state);
  4938. if (!player->IsPlayer()) {
  4939. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4940. return 0;
  4941. }
  4942. Client* client = ((Player*)player)->GetClient();
  4943. if (option_window && window_title.length() > 0 && client) {
  4944. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4945. if (!packet)
  4946. return 0;
  4947. packet->setDataByName("title_text", window_title.c_str());
  4948. if (cancel_command.length() > 0)
  4949. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4950. packet->setArrayLengthByName("num_selections", option_window->size());
  4951. vector<OptionWindowOption>::iterator itr;
  4952. int8 i = 0;
  4953. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4954. OptionWindowOption opt = *itr;
  4955. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4956. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4957. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4958. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4959. if (opt.optionCommand.length() > 0)
  4960. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4961. if (opt.optionConfirmTitle.length() > 0)
  4962. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4963. i++;
  4964. }
  4965. client->QueuePacket(packet->serialize());
  4966. lua_interface->SetLuaUserDataStale(option_window);
  4967. safe_delete(option_window);
  4968. safe_delete(packet);
  4969. }
  4970. return 0;
  4971. }
  4972. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4973. if (!lua_interface)
  4974. return 0;
  4975. Spawn* spawn = lua_interface->GetSpawn(state);
  4976. lua_interface->ResetFunctionStack(state);
  4977. if (spawn) {
  4978. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4979. return 1;
  4980. }
  4981. else
  4982. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4983. return 0;
  4984. }
  4985. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4986. if (!lua_interface)
  4987. return 0;
  4988. Spawn* spawn = lua_interface->GetSpawn(state);
  4989. lua_interface->ResetFunctionStack(state);
  4990. if (spawn) {
  4991. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4992. return 1;
  4993. }
  4994. else
  4995. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4996. return 0;
  4997. }
  4998. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4999. if (!lua_interface)
  5000. return 0;
  5001. Spawn* spawn = lua_interface->GetSpawn(state);
  5002. lua_interface->ResetFunctionStack(state);
  5003. if (spawn) {
  5004. int8 class_id = spawn->GetTradeskillClass();
  5005. // Need to add 42 for the offset in the array
  5006. class_id += 44;
  5007. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  5008. return 1;
  5009. }
  5010. else
  5011. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  5012. return 0;
  5013. }
  5014. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  5015. if (!lua_interface)
  5016. return 0;
  5017. Spawn* spawn = lua_interface->GetSpawn(state);
  5018. int16 level = lua_interface->GetInt8Value(state, 2);
  5019. lua_interface->ResetFunctionStack(state);
  5020. if (spawn) {
  5021. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  5022. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  5023. else
  5024. spawn->SetTSLevel(level);
  5025. }
  5026. else
  5027. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  5028. return 0;
  5029. }
  5030. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  5031. if (!lua_interface)
  5032. return 0;
  5033. Spawn* spawn = lua_interface->GetSpawn(state);
  5034. int8 attackable = lua_interface->GetInt8Value(state, 2);
  5035. lua_interface->ResetFunctionStack(state);
  5036. if (spawn) {
  5037. spawn->SetAttackable(attackable);
  5038. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  5039. }
  5040. return 0;
  5041. }
  5042. int EQ2Emu_lua_SummonPet(lua_State* state) {
  5043. // Check to see if we have a valid lua_interface
  5044. if (!lua_interface)
  5045. return 0;
  5046. // Get the spawn that is getting the pet
  5047. Spawn* spawn = lua_interface->GetSpawn(state);
  5048. // Get the DB ID of the pet
  5049. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5050. // The max level the pet can gain
  5051. int8 max_level = lua_interface->GetInt8Value(state, 3);
  5052. // Get the spell that this command was called from
  5053. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5054. lua_interface->ResetFunctionStack(state);
  5055. // Check to make sure the spawn pointer is valid
  5056. if (!spawn) {
  5057. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5058. return 0;
  5059. }
  5060. // Check to make sure the spawn is an entity
  5061. if (!spawn->IsEntity()) {
  5062. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5063. return 0;
  5064. }
  5065. // Check to make sure the spawn doesn't already have a pet of this type
  5066. if (((Entity*)spawn)->GetPet()) {
  5067. if (spawn->IsPlayer()) {
  5068. Client* client = ((Player*)spawn)->GetClient();
  5069. if (client)
  5070. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  5071. }
  5072. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5073. return 0;
  5074. }
  5075. // Check to see if the DB ID for the pet is set
  5076. if (pet_id == 0) {
  5077. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5078. return 0;
  5079. }
  5080. // Check to see if the pointer to the spell is valid
  5081. if (!luaspell) {
  5082. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5083. return 0;
  5084. }
  5085. if(luaspell->resisted) {
  5086. return 0;
  5087. }
  5088. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5089. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5090. if (!pet) {
  5091. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5092. return 0;
  5093. }
  5094. // Check to make sure the pet is an npc
  5095. if (!pet->IsNPC()) {
  5096. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5097. return 0;
  5098. }
  5099. // Spawn the pet at the same location as the owner
  5100. pet->SetX(spawn->GetX());
  5101. pet->SetY(spawn->GetY());
  5102. pet->SetZ(spawn->GetZ());
  5103. pet->SetLocation(spawn->GetLocation());
  5104. pet->SetHeading(spawn->GetHeading());
  5105. std::string petName = std::string("");
  5106. if(spawn->IsEntity()) {
  5107. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5108. }
  5109. if(petName.size() < 1) {
  5110. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5111. petName = spawn->GetZone()->pet_names.at(rand_index);
  5112. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5113. }
  5114. // If player set various values for the char sheet (pet window)
  5115. if (spawn->IsPlayer()) {
  5116. Player* player = (Player*)spawn;
  5117. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5118. player->GetInfoStruct()->set_pet_name(petName);
  5119. player->GetInfoStruct()->set_pet_movement(2);
  5120. player->GetInfoStruct()->set_pet_behavior(3);
  5121. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5122. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5123. // Make sure the values get sent to the client
  5124. player->SetCharSheetChanged(true);
  5125. }
  5126. // Set the pets name
  5127. pet->SetName(petName.c_str());
  5128. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5129. if (max_level > 0)
  5130. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5131. else
  5132. pet->SetLevel(spawn->GetLevel());
  5133. // Set the max level this pet can reach
  5134. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5135. ((NPC*)pet)->UpdateWeapons();
  5136. // Set the faction of the pet to the same faction as the owner
  5137. pet->SetFactionID(spawn->GetFactionID());
  5138. // Set the spawn as a pet
  5139. pet->SetPet(true);
  5140. // Give a pointer of the owner to the pet
  5141. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5142. // Give a pointer of the pet to the owner
  5143. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5144. // Set the pet type
  5145. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5146. // Set the spell id used to create this pet
  5147. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5148. // Set the spell tier used to create this pet
  5149. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5150. // Set the pets spawn type to 6
  5151. pet->SetSpawnType(6);
  5152. // Set the pets brain
  5153. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5154. // Check to see if the pet has a subtitle
  5155. if (strlen(pet->GetSubTitle()) > 0) {
  5156. // Add the players name to the front of the sub title
  5157. string pet_subtitle;
  5158. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5159. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5160. // Set the pets subtitle to the new one
  5161. pet->SetSubTitle(pet_subtitle.c_str());
  5162. }
  5163. // Add the "Pet Options" entity command to the pet
  5164. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5165. const char* spawn_script = world.GetSpawnScript(pet_id);
  5166. bool runScript = false;
  5167. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5168. runScript = true;
  5169. pet->SetSpawnScript(string(spawn_script));
  5170. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5171. }
  5172. spawn->GetZone()->AddSpawn(pet);
  5173. if(runScript){
  5174. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5175. }
  5176. // Set the pet as the return value for this function
  5177. lua_interface->SetSpawnValue(state, pet);
  5178. return 1;
  5179. }
  5180. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5181. if (!lua_interface)
  5182. return 0;
  5183. Spawn* spawn = lua_interface->GetSpawn(state);
  5184. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5185. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5186. lua_interface->ResetFunctionStack(state);
  5187. if (!spawn) {
  5188. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5189. return 0;
  5190. }
  5191. if (!spawn->IsEntity()) {
  5192. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5193. return 0;
  5194. }
  5195. if (((Entity*)spawn)->GetDeityPet()) {
  5196. if (spawn->IsPlayer()) {
  5197. Client* client = ((Player*)spawn)->GetClient();
  5198. if (client)
  5199. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5200. }
  5201. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5202. return 0;
  5203. }
  5204. if (pet_id == 0) {
  5205. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5206. return 0;
  5207. }
  5208. if (!luaspell) {
  5209. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5210. return 0;
  5211. }
  5212. if(luaspell->resisted) {
  5213. return 0;
  5214. }
  5215. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5216. if (!pet) {
  5217. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5218. return 0;
  5219. }
  5220. if (!pet->IsNPC()) {
  5221. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5222. return 0;
  5223. }
  5224. pet->SetX(spawn->GetX());
  5225. pet->SetY(spawn->GetY());
  5226. pet->SetZ(spawn->GetZ());
  5227. pet->SetLocation(spawn->GetLocation());
  5228. pet->SetHeading(spawn->GetHeading());
  5229. spawn->GetZone()->AddSpawn(pet);
  5230. string random_pet_name;
  5231. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5232. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5233. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5234. pet->SetName(random_pet_name.c_str());
  5235. pet->SetLevel(spawn->GetLevel());
  5236. pet->SetFactionID(spawn->GetFactionID());
  5237. pet->SetPet(true);
  5238. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5239. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5240. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5241. pet->SetSpawnType(6);
  5242. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5243. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5244. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5245. if (strlen(pet->GetSubTitle()) > 0) {
  5246. string pet_subtitle;
  5247. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5248. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5249. pet->SetSubTitle(pet_subtitle.c_str());
  5250. }
  5251. // deity and cosmetic pets are not attackable
  5252. pet->SetAttackable(false);
  5253. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5254. lua_interface->SetSpawnValue(state, pet);
  5255. return 1;
  5256. }
  5257. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5258. if (!lua_interface)
  5259. return 0;
  5260. Spawn* spawn = lua_interface->GetSpawn(state);
  5261. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5262. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5263. lua_interface->ResetFunctionStack(state);
  5264. if (!spawn) {
  5265. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5266. return 0;
  5267. }
  5268. if (!spawn->IsEntity()) {
  5269. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5270. return 0;
  5271. }
  5272. if (((Entity*)spawn)->GetCosmeticPet()) {
  5273. if (spawn->IsPlayer()) {
  5274. Client* client = ((Player*)spawn)->GetClient();
  5275. if (client)
  5276. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5277. }
  5278. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5279. return 0;
  5280. }
  5281. if (pet_id == 0) {
  5282. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5283. return 0;
  5284. }
  5285. if (!luaspell) {
  5286. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5287. return 0;
  5288. }
  5289. if(luaspell->resisted) {
  5290. return 0;
  5291. }
  5292. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5293. if (!pet) {
  5294. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5295. return 0;
  5296. }
  5297. if (!pet->IsNPC()) {
  5298. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5299. return 0;
  5300. }
  5301. pet->SetX(spawn->GetX());
  5302. pet->SetY(spawn->GetY());
  5303. pet->SetZ(spawn->GetZ());
  5304. pet->SetLocation(spawn->GetLocation());
  5305. pet->SetHeading(spawn->GetHeading());
  5306. spawn->GetZone()->AddSpawn(pet);
  5307. string random_pet_name;
  5308. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5309. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5310. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5311. pet->SetName(random_pet_name.c_str());
  5312. pet->SetLevel(spawn->GetLevel());
  5313. pet->SetFactionID(spawn->GetFactionID());
  5314. pet->SetPet(true);
  5315. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5316. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5317. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5318. pet->SetSpawnType(6);
  5319. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5320. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5321. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5322. if (strlen(pet->GetSubTitle()) > 0) {
  5323. string pet_subtitle;
  5324. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5325. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5326. pet->SetSubTitle(pet_subtitle.c_str());
  5327. }
  5328. pet->SetAttackable(false);
  5329. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5330. lua_interface->SetSpawnValue(state, pet);
  5331. return 1;
  5332. }
  5333. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5334. if (!lua_interface)
  5335. return 0;
  5336. Spawn* spawn = lua_interface->GetSpawn(state);
  5337. lua_interface->ResetFunctionStack(state);
  5338. if (!spawn) {
  5339. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5340. return 0;
  5341. }
  5342. if (!spawn->IsPet()) {
  5343. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5344. return 0;
  5345. }
  5346. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5347. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5348. return 0;
  5349. }
  5350. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5351. if (!lua_interface)
  5352. return 0;
  5353. Quest* quest = lua_interface->GetQuest(state);
  5354. if (!quest) {
  5355. 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));
  5356. lua_interface->ResetFunctionStack(state);
  5357. return 0;
  5358. }
  5359. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5360. lua_interface->ResetFunctionStack(state);
  5361. if (feather_color > 0)
  5362. quest->SetFeatherColor(feather_color);
  5363. return 0;
  5364. }
  5365. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5366. if (!lua_interface)
  5367. return 0;
  5368. Spawn* spawn = lua_interface->GetSpawn(state);
  5369. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5370. lua_interface->ResetFunctionStack(state);
  5371. if (!spawn) {
  5372. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5373. return 0;
  5374. }
  5375. if (!spawn2) {
  5376. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5377. return 0;
  5378. }
  5379. spawn->RemoveSpawnAccess(spawn2);
  5380. return 0;
  5381. }
  5382. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5383. if (!lua_interface)
  5384. return 0;
  5385. ZoneServer* zone = lua_interface->GetZone(state);
  5386. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5387. lua_interface->ResetFunctionStack(state);
  5388. if (!zone) {
  5389. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5390. return 0;
  5391. }
  5392. if (location_id == 0) {
  5393. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5394. return 0;
  5395. }
  5396. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5397. if (!location) {
  5398. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5399. return 0;
  5400. }
  5401. int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
  5402. Spawn* spawn = 0;
  5403. if (location->entities[rand_number]) {
  5404. if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5405. spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
  5406. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5407. spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
  5408. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5409. spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
  5410. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5411. spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
  5412. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5413. spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
  5414. if(spawn && spawn->IsOmittedByDBFlag())
  5415. {
  5416. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5417. safe_delete(spawn);
  5418. spawn = 0;
  5419. return 0;
  5420. }
  5421. if (spawn) {
  5422. const char* script = 0;
  5423. for (int x = 0; x < 3; x++) {
  5424. switch (x) {
  5425. case 0:
  5426. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5427. break;
  5428. case 1:
  5429. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5430. break;
  5431. case 2:
  5432. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5433. break;
  5434. }
  5435. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5436. spawn->SetSpawnScript(string(script));
  5437. break;
  5438. }
  5439. }
  5440. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5441. lua_interface->SetSpawnValue(state, spawn);
  5442. return 1;
  5443. }
  5444. else {
  5445. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5446. safe_delete(spawn);
  5447. }
  5448. }
  5449. return 0;
  5450. }
  5451. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5452. if (!lua_interface)
  5453. return 0;
  5454. Spawn* caster = lua_interface->GetSpawn(state);
  5455. Spawn* target = lua_interface->GetSpawn(state, 2);
  5456. int32 id = lua_interface->GetInt32Value(state, 3);
  5457. string command = lua_interface->GetStringValue(state, 4);
  5458. lua_interface->ResetFunctionStack(state);
  5459. if (!caster) {
  5460. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5461. return 0;
  5462. }
  5463. if (!target) {
  5464. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5465. return 0;
  5466. }
  5467. if (!caster->IsPlayer()) {
  5468. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5469. return 0;
  5470. }
  5471. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5472. if (!entity_command) {
  5473. 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());
  5474. return 0;
  5475. }
  5476. Client* client = ((Player*)caster)->GetClient();
  5477. if (!client) {
  5478. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5479. return 0;
  5480. }
  5481. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5482. return 0;
  5483. }
  5484. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5485. if (!lua_interface)
  5486. return 0;
  5487. Spawn* spawn = lua_interface->GetSpawn(state);
  5488. lua_interface->ResetFunctionStack(state);
  5489. if (!spawn) {
  5490. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5491. return 0;
  5492. }
  5493. if (!spawn->IsNPC()) {
  5494. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5495. return 0;
  5496. }
  5497. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5498. return 0;
  5499. }
  5500. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5501. if (!lua_interface)
  5502. return 0;
  5503. Spawn* spawn = lua_interface->GetSpawn(state);
  5504. int16 tick = lua_interface->GetInt16Value(state, 2);
  5505. lua_interface->ResetFunctionStack(state);
  5506. if (!spawn) {
  5507. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5508. return 0;
  5509. }
  5510. if (!spawn->IsNPC()) {
  5511. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5512. return 0;
  5513. }
  5514. if (tick < 20) {
  5515. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5516. return 0;
  5517. }
  5518. ((NPC*)spawn)->Brain()->SetTick(tick);
  5519. return 0;
  5520. }
  5521. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5522. if (!lua_interface)
  5523. return 0;
  5524. Spawn* spawn = lua_interface->GetSpawn(state);
  5525. Spawn* target = lua_interface->GetSpawn(state, 2);
  5526. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5527. lua_interface->ResetFunctionStack(state);
  5528. if (!spawn) {
  5529. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5530. return 0;
  5531. }
  5532. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5533. spawn->SetFollowTarget(target, follow_distance);
  5534. return 0;
  5535. }
  5536. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5537. if (!lua_interface)
  5538. return 0;
  5539. Spawn* spawn = lua_interface->GetSpawn(state);
  5540. lua_interface->ResetFunctionStack(state);
  5541. if (!spawn) {
  5542. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5543. return 0;
  5544. }
  5545. Spawn* target = spawn->GetFollowTarget();
  5546. if (target) {
  5547. lua_interface->SetSpawnValue(state, target);
  5548. return 1;
  5549. }
  5550. return 0;
  5551. }
  5552. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5553. if (!lua_interface)
  5554. return 0;
  5555. Spawn* spawn = lua_interface->GetSpawn(state);
  5556. lua_interface->ResetFunctionStack(state);
  5557. if (!spawn) {
  5558. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5559. return 0;
  5560. }
  5561. if (spawn->following)
  5562. spawn->following = false;
  5563. else
  5564. spawn->following = true;
  5565. return 0;
  5566. }
  5567. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5568. if (!lua_interface)
  5569. return 0;
  5570. Spawn* spawn = lua_interface->GetSpawn(state);
  5571. lua_interface->ResetFunctionStack(state);
  5572. if (!spawn) {
  5573. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5574. return 0;
  5575. }
  5576. lua_interface->SetBooleanValue(state, spawn->following);
  5577. return 1;
  5578. }
  5579. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5580. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5581. // I will attempt to explain how this function works for future refrence
  5582. // Fist lets make sure lua_interface is valid, if not return out
  5583. if (!lua_interface)
  5584. return 0;
  5585. // Next we grab the first 2 params same as we usually would
  5586. Spawn* spawn = lua_interface->GetSpawn(state);
  5587. string var = lua_interface->GetStringValue(state, 2);
  5588. // 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
  5589. // 1 = Spawn
  5590. // 2 = Zone
  5591. // 3 = Item
  5592. // 4 = Quest
  5593. // 5 = String
  5594. // 6 = nil (null)
  5595. int8 dataType = 0;
  5596. // Define pointers for each potential type
  5597. Spawn* spawnVal = 0;
  5598. ZoneServer* zone = 0;
  5599. Item* item = 0;
  5600. Quest* quest = 0;
  5601. string val;
  5602. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5603. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5604. // options window are also light user data be we do not handle those.
  5605. // We check with lua_islightuserdata(lua_State*, index)
  5606. if (lua_islightuserdata(state, 3)) {
  5607. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5608. // and convert it to LUAUserData*
  5609. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5610. // Check to make sure the data we got is valid, if not give an error
  5611. if (!data || !data->IsCorrectlyInitialized()) {
  5612. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5613. }
  5614. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5615. else if (data->IsSpawn()) {
  5616. spawnVal = data->spawn;
  5617. dataType = 1;
  5618. }
  5619. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5620. else if (data->IsZone()) {
  5621. zone = data->zone;
  5622. dataType = 2;
  5623. }
  5624. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5625. else if (data->IsItem()) {
  5626. item = data->item;
  5627. dataType = 3;
  5628. }
  5629. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5630. else if (data->IsQuest()) {
  5631. quest = data->quest;
  5632. dataType = 4;
  5633. }
  5634. }
  5635. // Wasn't light user data, check if it is nil(null)
  5636. else if (lua_isnil(state, 3)) {
  5637. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5638. dataType = 6;
  5639. }
  5640. // Wasn't light user data or nil (null), must be a string
  5641. else {
  5642. // Set the string and dataType variable
  5643. val = lua_interface->GetStringValue(state, 3);
  5644. dataType = 5;
  5645. }
  5646. lua_interface->ResetFunctionStack(state);
  5647. // We now have all the params, lets check to make sure they are valid
  5648. if (!spawn) {
  5649. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5650. return 0;
  5651. }
  5652. if (var.length() == 0) {
  5653. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5654. return 0;
  5655. }
  5656. if (dataType == 0) {
  5657. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5658. return 0;
  5659. }
  5660. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5661. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5662. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5663. switch (dataType) {
  5664. case 1:
  5665. // 1 = Spawn
  5666. spawn->AddTempVariable(var, spawnVal);
  5667. break;
  5668. case 2:
  5669. // 2 = Zone
  5670. spawn->AddTempVariable(var, zone);
  5671. break;
  5672. case 3:
  5673. // 3 = Item
  5674. spawn->AddTempVariable(var, item);
  5675. break;
  5676. case 4:
  5677. // 4 = Quest
  5678. spawn->AddTempVariable(var, quest);
  5679. break;
  5680. case 5:
  5681. // 5 = String
  5682. spawn->AddTempVariable(var, val);
  5683. break;
  5684. case 6:
  5685. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5686. spawn->DeleteTempVariable(var);
  5687. break;
  5688. }
  5689. // And we are done so return out
  5690. return 0;
  5691. }
  5692. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5693. if (!lua_interface)
  5694. return 0;
  5695. Spawn* spawn = lua_interface->GetSpawn(state);
  5696. string var = lua_interface->GetStringValue(state, 2);
  5697. lua_interface->ResetFunctionStack(state);
  5698. if (!spawn) {
  5699. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5700. return 0;
  5701. }
  5702. if (var.length() == 0) {
  5703. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5704. return 0;
  5705. }
  5706. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5707. int8 type = spawn->GetTempVariableType(var);
  5708. Spawn* spawn2 = 0;
  5709. ZoneServer* zone = 0;
  5710. Item* item = 0;
  5711. Quest* quest = 0;
  5712. // Set the lua function return value based on the type of data the variable contains
  5713. switch (type) {
  5714. case 1:
  5715. spawn2 = spawn->GetTempVariableSpawn(var);
  5716. if (!spawn2)
  5717. return 0;
  5718. lua_interface->SetSpawnValue(state, spawn2);
  5719. break;
  5720. case 2:
  5721. zone = spawn->GetTempVariableZone(var);
  5722. if (!zone)
  5723. return 0;
  5724. lua_interface->SetZoneValue(state, zone);
  5725. break;
  5726. case 3:
  5727. item = spawn->GetTempVariableItem(var);
  5728. if (!item)
  5729. return 0;
  5730. lua_interface->SetItemValue(state, item);
  5731. break;
  5732. case 4:
  5733. quest = spawn->GetTempVariableQuest(var);
  5734. if (!quest)
  5735. return 0;
  5736. lua_interface->SetQuestValue(state, quest);
  5737. break;
  5738. case 5:
  5739. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5740. break;
  5741. default:
  5742. // Not a valid type then the variable was not set so return out
  5743. return 0;
  5744. }
  5745. // Return value was set so return out
  5746. return 1;
  5747. }
  5748. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5749. {
  5750. if (!lua_interface)
  5751. return 0;
  5752. Quest* quest = lua_interface->GetQuest(state);
  5753. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5754. string description = lua_interface->GetStringValue(state, 3);
  5755. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5756. if (!quest) {
  5757. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5758. lua_interface->ResetFunctionStack(state);
  5759. lua_interface->SetBooleanValue(state, false);
  5760. return 1;
  5761. }
  5762. if (!spawn) {
  5763. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5764. lua_interface->ResetFunctionStack(state);
  5765. lua_interface->SetBooleanValue(state, false);
  5766. return 1;
  5767. }
  5768. if (!spawn->IsPlayer()) {
  5769. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5770. lua_interface->ResetFunctionStack(state);
  5771. lua_interface->SetBooleanValue(state, false);
  5772. return 1;
  5773. }
  5774. if (item_id == 0) {
  5775. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5776. lua_interface->ResetFunctionStack(state);
  5777. lua_interface->SetBooleanValue(state, false);
  5778. return 1;
  5779. }
  5780. Client* client = ((Player*)spawn)->GetClient();
  5781. if (!client) {
  5782. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5783. lua_interface->ResetFunctionStack(state);
  5784. lua_interface->SetBooleanValue(state, false);
  5785. return 1;
  5786. }
  5787. Item* item = master_item_list.GetItem(item_id);
  5788. if (!item) {
  5789. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5790. lua_interface->ResetFunctionStack(state);
  5791. lua_interface->SetBooleanValue(state, false);
  5792. return 1;
  5793. }
  5794. Item* firstItem = new Item(item);
  5795. quest->AddTmpRewardItem(firstItem);
  5796. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5797. bool itemsAddedSuccessfully = true;
  5798. if(num_args > 4)
  5799. {
  5800. for(int8 n=5;n<num_args+1;n++)
  5801. {
  5802. int32 new_item = lua_interface->GetInt32Value(state, n);
  5803. Item* tmpItem = master_item_list.GetItem(new_item);
  5804. if(tmpItem)
  5805. {
  5806. Item* newTmpItem = new Item(tmpItem);
  5807. quest->AddTmpRewardItem(newTmpItem);
  5808. }
  5809. else
  5810. itemsAddedSuccessfully = false;
  5811. }
  5812. }
  5813. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5814. lua_interface->ResetFunctionStack(state);
  5815. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5816. return 1;
  5817. }
  5818. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5819. if (!lua_interface)
  5820. return 0;
  5821. Quest* quest = lua_interface->GetQuest(state);
  5822. lua_interface->ResetFunctionStack(state);
  5823. if (!quest) {
  5824. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5825. return 0;
  5826. }
  5827. quest->SetRepeatable(true);
  5828. return 0;
  5829. }
  5830. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5831. if (!lua_interface)
  5832. return 0;
  5833. Spawn* spawn = lua_interface->GetSpawn(state);
  5834. lua_interface->ResetFunctionStack(state);
  5835. if (!spawn) {
  5836. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5837. return 0;
  5838. }
  5839. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5840. string ret = classes.GetClassNameCase(base_class);
  5841. if (ret.length() > 0) {
  5842. lua_interface->SetStringValue(state, ret.c_str());
  5843. return 1;
  5844. }
  5845. return 0;
  5846. }
  5847. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5848. if (!lua_interface)
  5849. return 0;
  5850. Spawn* player = lua_interface->GetSpawn(state);
  5851. lua_interface->ResetFunctionStack(state);
  5852. if (player && player->IsPlayer()) {
  5853. Client* client = player->GetClient();
  5854. if (client)
  5855. client->SendWaypoints();
  5856. }
  5857. return 0;
  5858. }
  5859. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5860. if (!lua_interface)
  5861. return 0;
  5862. Spawn* player = lua_interface->GetSpawn(state);
  5863. string name = lua_interface->GetStringValue(state, 2);
  5864. int32 type = lua_interface->GetInt32Value(state, 3);
  5865. lua_interface->ResetFunctionStack(state);
  5866. if (type == 0)
  5867. type = 2;
  5868. if (name.length() > 0) {
  5869. if (player && player->IsPlayer()) {
  5870. Client* client = player->GetClient();
  5871. if (client)
  5872. client->AddWaypoint(name, type);
  5873. }
  5874. }
  5875. return 0;
  5876. }
  5877. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5878. if (!lua_interface)
  5879. return 0;
  5880. Spawn* player = lua_interface->GetSpawn(state);
  5881. string name = lua_interface->GetStringValue(state, 2);
  5882. lua_interface->ResetFunctionStack(state);
  5883. if (name.length() > 0) {
  5884. if (player && player->IsPlayer()) {
  5885. Client* client = player->GetClient();
  5886. if (client)
  5887. client->RemoveWaypoint(name);
  5888. }
  5889. }
  5890. return 0;
  5891. }
  5892. int EQ2Emu_lua_AddWard(lua_State* state) {
  5893. if (!lua_interface)
  5894. return 0;
  5895. int32 damage = lua_interface->GetInt32Value(state);
  5896. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5897. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5898. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5899. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5900. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5901. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5902. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5903. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5904. lua_interface->ResetFunctionStack(state);
  5905. if(!spell || spell->resisted) {
  5906. return 0;
  5907. }
  5908. bool ward_was_added = false;
  5909. ZoneServer* zone = spell->caster->GetZone();
  5910. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5911. for (int32 i = 0; i < spell->targets.size(); i++) {
  5912. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5913. if (!target)
  5914. continue;
  5915. if (target->IsEntity()) {
  5916. // If the ward is already active remove it
  5917. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5918. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5919. // Create new ward info
  5920. WardInfo* ward = new WardInfo;
  5921. ward->Spell = spell;
  5922. ward->BaseDamage = damage;
  5923. ward->DamageLeft = damage;
  5924. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5925. ward->keepWard = keepWard;
  5926. ward->WardType = wardType;
  5927. if (damageAbsorptionPercent > 100)
  5928. damageAbsorptionPercent = 100;
  5929. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5930. if (damageAbsorptionMaxHealthPercent > 100)
  5931. damageAbsorptionMaxHealthPercent = 100;
  5932. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5933. ward->RedirectDamagePercent = redirectDamagePercent;
  5934. ward->LastRedirectDamage = 0;
  5935. ward->LastAbsorbedDamage = 0;
  5936. ward->HitCount = 0;
  5937. spell->num_triggers = maxHitCount;
  5938. spell->had_triggers = true;
  5939. spell->cancel_after_all_triggers = false;
  5940. ward->MaxHitCount = maxHitCount;
  5941. ward->RoundTriggered = false;
  5942. if (wardType == WARD_TYPE_MAGICAL)
  5943. ward->DamageType = damageTypes;
  5944. // Add the ward to the entity
  5945. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5946. ward_was_added = true;
  5947. }
  5948. }
  5949. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5950. if (ward_was_added && spell->caster->IsPlayer()) {
  5951. spell->had_dmg_remaining = true;
  5952. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5953. }
  5954. return 0;
  5955. }
  5956. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5957. if (!lua_interface)
  5958. return 0;
  5959. int32 amount = lua_interface->GetInt32Value(state);
  5960. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5961. lua_interface->ResetFunctionStack(state);
  5962. WardInfo* ward = 0;
  5963. if(!spell || spell->resisted) {
  5964. return 0;
  5965. }
  5966. ZoneServer* zone = spell->caster->GetZone();
  5967. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5968. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5969. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5970. ward = target->GetWard(spell->spell->GetSpellID());
  5971. if (target && ward) {
  5972. ward->DamageLeft += amount;
  5973. if (ward->DamageLeft > ward->BaseDamage)
  5974. ward->DamageLeft = ward->BaseDamage;
  5975. for (int32 i = 0; i < spell->targets.size(); i++) {
  5976. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5977. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5978. }
  5979. }
  5980. }
  5981. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5982. if (ward && spell->caster->IsPlayer())
  5983. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5984. return 0;
  5985. }
  5986. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5987. if (!lua_interface)
  5988. return 0;
  5989. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5990. lua_interface->ResetFunctionStack(state);
  5991. if (!spell) {
  5992. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5993. return 0;
  5994. }
  5995. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5996. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5997. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5998. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5999. if (ward) {
  6000. lua_interface->SetInt32Value(state, ward->DamageLeft);
  6001. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6002. return 1;
  6003. }
  6004. }
  6005. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6006. return 0;
  6007. }
  6008. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  6009. if (!lua_interface)
  6010. return 0;
  6011. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6012. if (!spell) {
  6013. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  6014. lua_interface->ResetFunctionStack(state);
  6015. return 0;
  6016. }
  6017. string type = lua_interface->GetStringValue(state, 2);
  6018. lua_interface->ResetFunctionStack(state);
  6019. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6020. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  6021. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  6022. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  6023. if (ward) {
  6024. if (boost::iequals(type, "damageleft"))
  6025. lua_interface->SetInt32Value(state, ward->DamageLeft);
  6026. else if (boost::iequals(type, "basedamage"))
  6027. lua_interface->SetInt32Value(state, ward->BaseDamage);
  6028. else if (boost::iequals(type, "keepward"))
  6029. lua_interface->SetBooleanValue(state, ward->keepWard);
  6030. else if (boost::iequals(type, "wardtype"))
  6031. lua_interface->SetInt32Value(state, ward->WardType);
  6032. else if (boost::iequals(type, "dmgabsorptionpct"))
  6033. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  6034. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  6035. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  6036. else if (boost::iequals(type, "redirectdamagepercent"))
  6037. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  6038. else if (boost::iequals(type, "lastredirectdamage"))
  6039. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  6040. else if (boost::iequals(type, "lastabsorbeddamage"))
  6041. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  6042. else if (boost::iequals(type, "hitcount"))
  6043. lua_interface->SetInt32Value(state, ward->HitCount);
  6044. else if (boost::iequals(type, "maxhitcount"))
  6045. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  6046. else
  6047. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  6048. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6049. return 1;
  6050. }
  6051. }
  6052. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6053. return 0;
  6054. }
  6055. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  6056. if (!lua_interface)
  6057. return 0;
  6058. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6059. lua_interface->ResetFunctionStack(state);
  6060. if(!spell) {
  6061. return 0;
  6062. }
  6063. ZoneServer* zone = spell->caster->GetZone();
  6064. Spawn* target = 0;
  6065. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6066. for (int32 i = 0; i < spell->targets.size(); i++) {
  6067. target = zone->GetSpawnByID(spell->targets.at(i));
  6068. if (target && target->IsEntity()) {
  6069. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  6070. }
  6071. }
  6072. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6073. return 0;
  6074. }
  6075. int EQ2Emu_lua_Interrupt(lua_State* state)
  6076. {
  6077. if (!lua_interface)
  6078. return 0;
  6079. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6080. Spawn* target = lua_interface->GetSpawn(state, 2);
  6081. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6082. lua_interface->ResetFunctionStack(state);
  6083. if (!caster)
  6084. {
  6085. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6086. return 0;
  6087. }
  6088. if (!target)
  6089. {
  6090. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6091. return 0;
  6092. }
  6093. if (!spell) {
  6094. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6095. return 0;
  6096. }
  6097. if (!target->IsEntity() && !spell)
  6098. {
  6099. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6100. return 0;
  6101. }
  6102. if (!target && spell) {
  6103. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6104. for (int8 i = 0; i < spell->targets.size(); i++) {
  6105. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6106. if (!target || !target->IsEntity())
  6107. continue;
  6108. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6109. }
  6110. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6111. }
  6112. else
  6113. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6114. return 0;
  6115. }
  6116. int EQ2Emu_lua_Stealth(lua_State* state) {
  6117. if (!lua_interface)
  6118. return 0;
  6119. int8 type = lua_interface->GetInt8Value(state);
  6120. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6121. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6122. lua_interface->ResetFunctionStack(state);
  6123. if (!spell) {
  6124. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6125. return 0;
  6126. }
  6127. ZoneServer* zone = spell->caster->GetZone();
  6128. if (spawn) {
  6129. if (spawn->IsEntity()) {
  6130. if (type == 1) {
  6131. ((Entity*)spawn)->AddStealthSpell(spell);
  6132. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6133. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6134. }
  6135. else if (type == 2) {
  6136. ((Entity*)spawn)->AddInvisSpell(spell);
  6137. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6138. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6139. }
  6140. return 0;
  6141. }
  6142. else {
  6143. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. }
  6147. else {
  6148. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6149. for (int32 i = 0; i < spell->targets.size(); i++) {
  6150. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6151. if (!spawn || !spawn->IsEntity())
  6152. continue;
  6153. if (type == 1) {
  6154. ((Entity*)spawn)->AddStealthSpell(spell);
  6155. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6156. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6157. }
  6158. else if (type == 2) {
  6159. ((Entity*)spawn)->AddInvisSpell(spell);
  6160. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6161. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6162. }
  6163. else {
  6164. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6165. break;
  6166. }
  6167. }
  6168. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6169. }
  6170. return 0;
  6171. }
  6172. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6173. if (!lua_interface)
  6174. return 0;
  6175. Spawn* spawn = lua_interface->GetSpawn(state);
  6176. lua_interface->ResetFunctionStack(state);
  6177. if (!spawn) {
  6178. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6179. return 0;
  6180. }
  6181. if (spawn->IsEntity()) {
  6182. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6183. return 1;
  6184. }
  6185. else
  6186. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6187. return 0;
  6188. }
  6189. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6190. if (!lua_interface)
  6191. return 0;
  6192. Spawn* spawn = lua_interface->GetSpawn(state);
  6193. lua_interface->ResetFunctionStack(state);
  6194. if (!spawn) {
  6195. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6196. return 0;
  6197. }
  6198. if (spawn->IsEntity()) {
  6199. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6200. return 1;
  6201. }
  6202. else
  6203. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6204. return 0;
  6205. }
  6206. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6207. if (!lua_interface)
  6208. return 0;
  6209. Spawn* player = lua_interface->GetSpawn(state);
  6210. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6211. lua_interface->ResetFunctionStack(state);
  6212. if (!player->IsPlayer()) {
  6213. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6214. return 0;
  6215. }
  6216. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6217. return 1;
  6218. }
  6219. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6220. if (!lua_interface)
  6221. return 0;
  6222. Spawn* spawn = lua_interface->GetSpawn(state);
  6223. int8 slot = lua_interface->GetInt8Value(state, 2);
  6224. lua_interface->ResetFunctionStack(state);
  6225. if (!spawn) {
  6226. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6227. return 0;
  6228. }
  6229. if (!spawn->IsEntity()) {
  6230. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6231. return 0;
  6232. }
  6233. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6234. if (!item) {
  6235. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. lua_interface->SetItemValue(state, item);
  6239. return 1;
  6240. }
  6241. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6242. if (!lua_interface)
  6243. return 0;
  6244. Spawn* player = lua_interface->GetSpawn(state);
  6245. int32 id = lua_interface->GetInt32Value(state, 2);
  6246. lua_interface->ResetFunctionStack(state);
  6247. if (!player) {
  6248. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6249. return 0;
  6250. }
  6251. if (!player->IsPlayer()) {
  6252. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6253. return 0;
  6254. }
  6255. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6256. if (!item) {
  6257. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6258. return 0;
  6259. }
  6260. lua_interface->SetItemValue(state, item);
  6261. return 1;
  6262. }
  6263. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6264. if (!lua_interface)
  6265. return 0;
  6266. Spawn* spawn = lua_interface->GetSpawn(state);
  6267. int8 slot = lua_interface->GetInt8Value(state, 2);
  6268. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6269. lua_interface->ResetFunctionStack(state);
  6270. if (!spawn) {
  6271. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6272. return 0;
  6273. }
  6274. if (!spawn->IsEntity()) {
  6275. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6276. return 0;
  6277. }
  6278. Item* item = master_item_list.GetItem(item_id);
  6279. if (!item) {
  6280. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6281. return 0;
  6282. }
  6283. Item* copy = new Item(item);
  6284. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6285. if(result)
  6286. {
  6287. ((Entity*)spawn)->SetEquipment(copy, slot);
  6288. spawn->vis_changed = true;
  6289. if(spawn->IsPlayer())
  6290. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6291. }
  6292. else
  6293. {
  6294. safe_delete(copy);
  6295. }
  6296. lua_interface->SetBooleanValue(state, result);
  6297. return 1;
  6298. }
  6299. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6300. if (!lua_interface)
  6301. return 0;
  6302. Spawn* spawn = lua_interface->GetSpawn(state);
  6303. int8 slot = lua_interface->GetInt8Value(state, 2);
  6304. Item* item = lua_interface->GetItem(state, 3);
  6305. lua_interface->ResetFunctionStack(state);
  6306. if (!spawn) {
  6307. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6308. return 0;
  6309. }
  6310. if (!spawn->IsEntity()) {
  6311. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6312. return 0;
  6313. }
  6314. if (!item) {
  6315. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6316. return 0;
  6317. }
  6318. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6319. if(result)
  6320. {
  6321. ((Entity*)spawn)->SetEquipment(item, slot);
  6322. spawn->vis_changed = true;
  6323. if(spawn->IsPlayer())
  6324. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6325. }
  6326. lua_interface->SetBooleanValue(state, result);
  6327. return 1;
  6328. }
  6329. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6330. if (!lua_interface)
  6331. return 0;
  6332. Spawn* spawn = lua_interface->GetSpawn(state);
  6333. int8 slot = lua_interface->GetInt8Value(state, 2);
  6334. bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  6335. lua_interface->ResetFunctionStack(state);
  6336. if (!spawn) {
  6337. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6338. return 0;
  6339. }
  6340. if (!spawn->IsEntity()) {
  6341. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6342. return 0;
  6343. }
  6344. if(slot >= NUM_SLOTS) {
  6345. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6346. return 0;
  6347. }
  6348. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6349. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6350. if(item) {
  6351. item->save_needed = true;
  6352. if(no_delete_item) {
  6353. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6354. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6355. }
  6356. else{
  6357. Client* client = ((Player*)spawn)->GetClient();
  6358. client->UnequipItem(item->details.index);
  6359. }
  6360. }
  6361. }
  6362. else
  6363. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6364. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6365. spawn->vis_changed = true;
  6366. if(spawn->IsPlayer())
  6367. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6368. lua_interface->SetBooleanValue(state, true);
  6369. return 1;
  6370. }
  6371. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6372. if (!lua_interface)
  6373. return 0;
  6374. Spawn* spawn = lua_interface->GetSpawn(state);
  6375. int8 slot = lua_interface->GetInt8Value(state, 2);
  6376. int16 type = lua_interface->GetInt16Value(state, 3);
  6377. int8 r = lua_interface->GetInt8Value(state, 4);
  6378. int8 g = lua_interface->GetInt8Value(state, 5);
  6379. int8 b = lua_interface->GetInt8Value(state, 6);
  6380. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6381. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6382. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6383. lua_interface->ResetFunctionStack(state);
  6384. if (!spawn) {
  6385. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6386. return 0;
  6387. }
  6388. if (!spawn->IsEntity()) {
  6389. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6390. return 0;
  6391. }
  6392. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6393. spawn->vis_changed = true;
  6394. lua_interface->SetBooleanValue(state, true);
  6395. return 1;
  6396. }
  6397. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6398. if (!lua_interface)
  6399. return 0;
  6400. Spawn* player = lua_interface->GetSpawn(state);
  6401. int32 id = lua_interface->GetInt32Value(state, 2);
  6402. int8 count = lua_interface->GetInt8Value(state, 3);
  6403. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6404. lua_interface->ResetFunctionStack(state);
  6405. if (!player) {
  6406. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6407. return 0;
  6408. }
  6409. if (!player->IsPlayer()) {
  6410. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6411. return 0;
  6412. }
  6413. if (!count)
  6414. count = 1;
  6415. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6416. if (!item) {
  6417. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6418. return 0;
  6419. }
  6420. lua_interface->SetItemValue(state, item);
  6421. return 1;
  6422. }
  6423. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6424. if (!lua_interface)
  6425. return 0;
  6426. Spawn* spawn = lua_interface->GetSpawn(state);
  6427. int32 anim = lua_interface->GetInt32Value(state, 2);
  6428. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6429. int8 type = lua_interface->GetInt8Value(state, 4);
  6430. lua_interface->ResetFunctionStack(state);
  6431. if (!spawn) {
  6432. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6433. return 0;
  6434. }
  6435. if (spawn2) {
  6436. if (spawn2->IsPlayer()) {
  6437. if (type != 1 && type != 2)
  6438. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6439. else
  6440. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6441. return 0;
  6442. }
  6443. else {
  6444. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6445. return 0;
  6446. }
  6447. }
  6448. else
  6449. spawn->GetZone()->PlayAnimation(spawn, anim);
  6450. return 0;
  6451. }
  6452. int EQ2Emu_lua_IsPet(lua_State* state) {
  6453. if (!lua_interface)
  6454. return 0;
  6455. Spawn* spawn = lua_interface->GetSpawn(state);
  6456. lua_interface->ResetFunctionStack(state);
  6457. if (!spawn) {
  6458. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6459. return 0;
  6460. }
  6461. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6462. return 1;
  6463. }
  6464. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6465. if (!lua_interface)
  6466. return 0;
  6467. Spawn* spawn = lua_interface->GetSpawn(state);
  6468. lua_interface->ResetFunctionStack(state);
  6469. if (!spawn) {
  6470. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6471. return 0;
  6472. }
  6473. if (!spawn->IsNPC()) {
  6474. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6475. return 0;
  6476. }
  6477. if (((NPC*)spawn)->GetOwner()) {
  6478. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6479. return 1;
  6480. }
  6481. return 0;
  6482. }
  6483. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6484. if (!lua_interface)
  6485. return 0;
  6486. Spawn* spawn = lua_interface->GetSpawn(state);
  6487. Spawn* target = lua_interface->GetSpawn(state, 2);
  6488. lua_interface->ResetFunctionStack(state);
  6489. if (!spawn) {
  6490. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. if (!spawn) {
  6494. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6495. return 0;
  6496. }
  6497. spawn->SetTarget(target);
  6498. return 0;
  6499. }
  6500. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6501. if (!lua_interface)
  6502. return 0;
  6503. Spawn* spawn = lua_interface->GetSpawn(state);
  6504. bool val = lua_interface->GetBooleanValue(state, 2);
  6505. lua_interface->ResetFunctionStack(state);
  6506. if (!spawn) {
  6507. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6508. return 0;
  6509. }
  6510. if (!spawn->IsEntity()) {
  6511. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6512. return 0;
  6513. }
  6514. ((Entity*)spawn)->InCombat(val);
  6515. if (val) {
  6516. spawn->ClearRunningLocations();
  6517. spawn->CalculateRunningLocation(true);
  6518. }
  6519. return 0;
  6520. }
  6521. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6522. if (!lua_interface)
  6523. return 0;
  6524. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6525. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6526. lua_interface->ResetFunctionStack(state);
  6527. if (!spawn1) {
  6528. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6529. return 0;
  6530. }
  6531. if (!spawn2) {
  6532. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6533. return 0;
  6534. }
  6535. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6536. return 1;
  6537. }
  6538. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6539. if (!lua_interface)
  6540. return 0;
  6541. Spawn* spawn = lua_interface->GetSpawn(state);
  6542. lua_interface->ResetFunctionStack(state);
  6543. if (!spawn) {
  6544. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6545. return 0;
  6546. }
  6547. if (!spawn->IsNPC()) {
  6548. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6549. return 0;
  6550. }
  6551. ((NPC*)spawn)->ClearRunback();
  6552. return 0;
  6553. }
  6554. int EQ2Emu_lua_Runback(lua_State* state) {
  6555. if (!lua_interface)
  6556. return 0;
  6557. Spawn* spawn = lua_interface->GetSpawn(state);
  6558. lua_interface->ResetFunctionStack(state);
  6559. if (!spawn) {
  6560. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6561. return 0;
  6562. }
  6563. if (!spawn->IsNPC()) {
  6564. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6565. return 0;
  6566. }
  6567. ((NPC*)spawn)->Runback();
  6568. return 0;
  6569. }
  6570. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6571. if (!lua_interface)
  6572. return 0;
  6573. Spawn* spawn = lua_interface->GetSpawn(state);
  6574. lua_interface->ResetFunctionStack(state);
  6575. if (!spawn) {
  6576. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6577. return 0;
  6578. }
  6579. if (!spawn->IsNPC()) {
  6580. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6581. return 0;
  6582. }
  6583. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6584. return 1;
  6585. }
  6586. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6587. if (!lua_interface)
  6588. return 0;
  6589. Spawn* spawn = lua_interface->GetSpawn(state);
  6590. lua_interface->ResetFunctionStack(state);
  6591. if (!spawn) {
  6592. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6593. return 0;
  6594. }
  6595. if (!spawn->IsEntity()) {
  6596. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6597. return 0;
  6598. }
  6599. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6600. return 1;
  6601. }
  6602. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6603. if (!lua_interface)
  6604. return 0;
  6605. Spawn* spawn = lua_interface->GetSpawn(state);
  6606. lua_interface->ResetFunctionStack(state);
  6607. if (!spawn) {
  6608. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6609. return 0;
  6610. }
  6611. if (!spawn->IsEntity()) {
  6612. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6613. return 0;
  6614. }
  6615. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6616. return 1;
  6617. }
  6618. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6619. if (!lua_interface)
  6620. return 0;
  6621. Spawn* spawn = lua_interface->GetSpawn(state);
  6622. lua_interface->ResetFunctionStack(state);
  6623. if (!spawn) {
  6624. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6625. return 0;
  6626. }
  6627. if (!spawn->IsEntity()) {
  6628. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6629. return 0;
  6630. }
  6631. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6632. return 1;
  6633. }
  6634. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6635. if (!lua_interface)
  6636. return 0;
  6637. Spawn* spawn = lua_interface->GetSpawn(state);
  6638. lua_interface->ResetFunctionStack(state);
  6639. if (!spawn) {
  6640. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6641. return 0;
  6642. }
  6643. if (!spawn->IsEntity()) {
  6644. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6645. return 0;
  6646. }
  6647. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6648. return 1;
  6649. }
  6650. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6651. if (!lua_interface)
  6652. return 0;
  6653. Spawn* spawn = lua_interface->GetSpawn(state);
  6654. Spawn* target = lua_interface->GetSpawn(state, 2);
  6655. float distance = lua_interface->GetFloatValue(state, 3);
  6656. lua_interface->ResetFunctionStack(state);
  6657. if (!spawn) {
  6658. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6659. return 0;
  6660. }
  6661. if (!target) {
  6662. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6663. return 0;
  6664. }
  6665. if (!spawn->IsNPC()) {
  6666. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6667. return 0;
  6668. }
  6669. if (!target->IsEntity()) {
  6670. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6671. return 0;
  6672. }
  6673. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6674. return 1;
  6675. }
  6676. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6677. if (!lua_interface)
  6678. return 0;
  6679. Spawn* spawn = lua_interface->GetSpawn(state);
  6680. Spawn* target = lua_interface->GetSpawn(state, 2);
  6681. float distance = lua_interface->GetFloatValue(state, 3);
  6682. lua_interface->ResetFunctionStack(state);
  6683. if (!spawn) {
  6684. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6685. return 0;
  6686. }
  6687. if (!target) {
  6688. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6689. return 0;
  6690. }
  6691. if (!spawn->IsNPC()) {
  6692. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6693. return 0;
  6694. }
  6695. if (!target->IsEntity()) {
  6696. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6697. return 0;
  6698. }
  6699. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6700. return 0;
  6701. }
  6702. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6703. if (!lua_interface)
  6704. return 0;
  6705. Spawn* spawn = lua_interface->GetSpawn(state);
  6706. lua_interface->ResetFunctionStack(state);
  6707. if (!spawn) {
  6708. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6709. return 0;
  6710. }
  6711. if (!spawn->IsNPC()) {
  6712. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6713. return 0;
  6714. }
  6715. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6716. return 1;
  6717. }
  6718. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6719. if (!lua_interface)
  6720. return 0;
  6721. Spawn* spawn = lua_interface->GetSpawn(state);
  6722. lua_interface->ResetFunctionStack(state);
  6723. if (!spawn) {
  6724. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6725. return 0;
  6726. }
  6727. if (!spawn->IsNPC()) {
  6728. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6729. return 0;
  6730. }
  6731. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6732. return 1;
  6733. }
  6734. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6735. if (!lua_interface)
  6736. return 0;
  6737. Spawn* spawn = lua_interface->GetSpawn(state);
  6738. lua_interface->ResetFunctionStack(state);
  6739. if (!spawn) {
  6740. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6741. return 0;
  6742. }
  6743. if (!spawn->IsNPC()) {
  6744. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6745. return 0;
  6746. }
  6747. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6748. if (hated) {
  6749. lua_interface->SetSpawnValue(state, hated);
  6750. return 1;
  6751. }
  6752. return 0;
  6753. }
  6754. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6755. if (!lua_interface)
  6756. return 0;
  6757. Spawn* spawn = lua_interface->GetSpawn(state);
  6758. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6759. lua_interface->ResetFunctionStack(state);
  6760. if (!spawn) {
  6761. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6762. return 0;
  6763. }
  6764. if (!spawn->IsNPC()) {
  6765. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6766. return 0;
  6767. }
  6768. if (!hated) {
  6769. ((NPC*)spawn)->Brain()->ClearHate();
  6770. return 0;
  6771. }
  6772. else
  6773. {
  6774. if (!hated->IsEntity()) {
  6775. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6776. return 0;
  6777. }
  6778. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6779. return 0;
  6780. }
  6781. return 0;
  6782. }
  6783. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6784. if (!lua_interface)
  6785. return 0;
  6786. Spawn* spawn = lua_interface->GetSpawn(state);
  6787. lua_interface->ResetFunctionStack(state);
  6788. if (!spawn) {
  6789. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6790. return 0;
  6791. }
  6792. if (!spawn->IsNPC()) {
  6793. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6794. return 0;
  6795. }
  6796. ((NPC*)spawn)->Brain()->ClearEncounter();
  6797. return 0;
  6798. }
  6799. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6800. if (!lua_interface)
  6801. return 0;
  6802. Spawn* spawn = lua_interface->GetSpawn(state);
  6803. lua_interface->ResetFunctionStack(state);
  6804. if (!spawn) {
  6805. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6806. return 0;
  6807. }
  6808. if (!spawn->IsNPC()) {
  6809. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6810. return 0;
  6811. }
  6812. // Temp list to store hate list
  6813. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6814. if (encounterList->size() == 0) {
  6815. safe_delete(encounterList);
  6816. return 0;
  6817. }
  6818. lua_createtable(state, encounterList->size(), 0);
  6819. int newTable = lua_gettop(state);
  6820. for (int32 i = 0; i < encounterList->size(); i++) {
  6821. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6822. if (temp)
  6823. lua_interface->SetSpawnValue(state, temp);
  6824. lua_rawseti(state, newTable, i + 1);
  6825. }
  6826. safe_delete(encounterList);
  6827. return 1;
  6828. }
  6829. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6830. if (!lua_interface)
  6831. return 0;
  6832. Spawn* spawn = lua_interface->GetSpawn(state);
  6833. lua_interface->ResetFunctionStack(state);
  6834. if (!spawn) {
  6835. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6836. return 0;
  6837. }
  6838. if (!spawn->IsNPC()) {
  6839. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6840. return 0;
  6841. }
  6842. // Temp list to store hate list
  6843. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6844. if (hateList->size() == 0) {
  6845. safe_delete(hateList);
  6846. return 0;
  6847. }
  6848. lua_createtable(state, hateList->size(), 0);
  6849. int newTable = lua_gettop(state);
  6850. for (int32 i = 0; i < hateList->size(); i++) {
  6851. lua_interface->SetSpawnValue(state, hateList->at(i));
  6852. lua_rawseti(state, newTable, i + 1);
  6853. }
  6854. safe_delete(hateList);
  6855. return 1;
  6856. }
  6857. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6858. if (!lua_interface)
  6859. return 0;
  6860. Spawn* spawn = lua_interface->GetSpawn(state);
  6861. lua_interface->ResetFunctionStack(state);
  6862. if (!spawn) {
  6863. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6864. return 0;
  6865. }
  6866. if (spawn->IsPlayer()) {
  6867. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6868. lua_interface->SetBooleanValue(state, true);
  6869. else
  6870. lua_interface->SetBooleanValue(state, false);
  6871. return 1;
  6872. }
  6873. else {
  6874. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6875. return 1;
  6876. }
  6877. }
  6878. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6879. if (!lua_interface)
  6880. return 0;
  6881. Quest* quest = lua_interface->GetQuest(state);
  6882. lua_interface->ResetFunctionStack(state);
  6883. if (!quest) {
  6884. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6885. return 0;
  6886. }
  6887. quest->SetCompletedFlag(true);
  6888. return 0;
  6889. }
  6890. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6891. if (!lua_interface)
  6892. return 0;
  6893. Spawn* spawn = lua_interface->GetSpawn(state);
  6894. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6895. int8 tier = lua_interface->GetInt8Value(state, 3);
  6896. lua_interface->ResetFunctionStack(state);
  6897. if (!spawn) {
  6898. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6899. return 0;
  6900. }
  6901. if (!spawn->IsEntity()) {
  6902. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6903. return 0;
  6904. }
  6905. if (spellID == 0) {
  6906. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6907. return 0;
  6908. }
  6909. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6910. if (effect) {
  6911. if (tier > 0) {
  6912. // If a tier was passed chec to see if it is the same as the effect
  6913. if (tier == effect->tier)
  6914. lua_interface->SetBooleanValue(state, true);
  6915. else
  6916. lua_interface->SetBooleanValue(state, false);
  6917. return 1;
  6918. }
  6919. else {
  6920. // Have an effect but no tier was passed so return true
  6921. lua_interface->SetBooleanValue(state, true);
  6922. }
  6923. return 1;
  6924. }
  6925. // no effect so return false
  6926. lua_interface->SetBooleanValue(state, false);
  6927. return 1;
  6928. }
  6929. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6930. if (!lua_interface)
  6931. return 0;
  6932. Spawn* spawn = lua_interface->GetSpawn(state);
  6933. int32 id = lua_interface->GetInt32Value(state, 2);
  6934. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6935. lua_interface->ResetFunctionStack(state);
  6936. Spawn* spawn2 = 0;
  6937. vector<Spawn*> list;
  6938. if (!spawn) {
  6939. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6940. return 0;
  6941. }
  6942. //If zone not provided, use spawn's zone
  6943. if (!zone)
  6944. zone = spawn->GetZone();
  6945. list = zone->GetSpawnsByID(id);
  6946. if (list.size() == 0) {
  6947. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6948. return 0;
  6949. }
  6950. vector<Spawn*>::iterator itr = list.begin();
  6951. for (int8 i = 0; i < list.size(); i++) {
  6952. spawn2 = itr[i];
  6953. if (spawn2)
  6954. spawn2->AddAllowAccessSpawn(spawn);
  6955. }
  6956. return 0;
  6957. }
  6958. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6959. if (!lua_interface)
  6960. return 0;
  6961. Spawn* spawn = lua_interface->GetSpawn(state);
  6962. int32 id = lua_interface->GetInt32Value(state, 2);
  6963. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6964. lua_interface->ResetFunctionStack(state);
  6965. Spawn* spawn2 = 0;
  6966. if (!spawn) {
  6967. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6968. return 0;
  6969. }
  6970. //If zone not provided, use spawn's zone
  6971. if (!zone)
  6972. zone = spawn->GetZone();
  6973. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6974. vector<Spawn*>::iterator itr = list.begin();
  6975. if (list.size() == 0) {
  6976. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6977. return 0;
  6978. }
  6979. for (int8 i = 0; i < list.size(); i++) {
  6980. spawn2 = itr[i];
  6981. if (spawn2)
  6982. spawn2->RemoveSpawnAccess(spawn);
  6983. }
  6984. return 0;
  6985. }
  6986. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6987. if (!lua_interface)
  6988. return 0;
  6989. Quest* quest = lua_interface->GetQuest(state);
  6990. lua_interface->ResetFunctionStack(state);
  6991. if (!quest) {
  6992. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6993. return 0;
  6994. }
  6995. quest->SetYellowName(true);
  6996. return 0;
  6997. }
  6998. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6999. if (!lua_interface)
  7000. return 0;
  7001. Spawn* spawn = lua_interface->GetSpawn(state);
  7002. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7003. lua_interface->ResetFunctionStack(state);
  7004. if (!spawn) {
  7005. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  7006. return 0;
  7007. }
  7008. if (!spawn->IsPlayer()) {
  7009. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  7010. return 0;
  7011. }
  7012. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  7013. return 1;
  7014. }
  7015. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  7016. if (!lua_interface)
  7017. return 0;
  7018. Spawn* spawn = lua_interface->GetSpawn(state);
  7019. lua_interface->ResetFunctionStack(state);
  7020. if (!spawn) {
  7021. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7022. return 0;
  7023. }
  7024. if (!spawn->IsPlayer()) {
  7025. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7026. return 0;
  7027. }
  7028. ZoneServer* zone = spawn->GetZone();
  7029. if (!zone) {
  7030. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7031. return 0;
  7032. }
  7033. Instance_Type iType = zone->GetInstanceType();
  7034. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7035. iType == GROUP_LOCKOUT_INSTANCE ||
  7036. iType == RAID_LOCKOUT_INSTANCE ||
  7037. iType == SOLO_PERSIST_INSTANCE ||
  7038. iType == GROUP_PERSIST_INSTANCE ||
  7039. iType == RAID_PERSIST_INSTANCE) {
  7040. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7041. if (data) {
  7042. // Check to see if the timer has already been set, if it has return out.
  7043. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  7044. return 0;
  7045. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  7046. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  7047. if(spawn->IsPlayer()) {
  7048. Client* client = ((Player*)spawn)->GetClient();
  7049. if (client) {
  7050. string time_msg = "";
  7051. int32 time = data->success_lockout_time;
  7052. int16 hour;
  7053. int8 min;
  7054. int8 sec;
  7055. hour = time / 3600;
  7056. time = time % 3600;
  7057. min = time / 60;
  7058. time = time % 60;
  7059. sec = time;
  7060. if (hour > 0) {
  7061. char temp[10];
  7062. sprintf(temp, " %i", hour);
  7063. time_msg.append(temp);
  7064. time_msg.append(" hour");
  7065. time_msg.append((hour > 1) ? "s" : "");
  7066. }
  7067. if (min > 0) {
  7068. char temp[5];
  7069. sprintf(temp, " %i", min);
  7070. time_msg.append(temp);
  7071. time_msg.append(" minute");
  7072. time_msg.append((min > 1) ? "s" : "");
  7073. }
  7074. // Only add seconds if minutes and hours are 0
  7075. if (hour == 0 && min == 0 && sec > 0) {
  7076. char temp[5];
  7077. sprintf(temp, " %i", sec);
  7078. time_msg.append(temp);
  7079. time_msg.append(" second");
  7080. time_msg.append((sec > 1) ? "s" : "");
  7081. }
  7082. 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());
  7083. }
  7084. else {
  7085. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7086. }
  7087. }
  7088. }
  7089. else
  7090. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7091. }
  7092. else
  7093. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7094. return 0;
  7095. }
  7096. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7097. if (!lua_interface)
  7098. return 0;
  7099. Spawn* spawn = lua_interface->GetSpawn(state);
  7100. lua_interface->ResetFunctionStack(state);
  7101. if (!spawn) {
  7102. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7103. return 0;
  7104. }
  7105. if (!spawn->IsPlayer()) {
  7106. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7107. return 0;
  7108. }
  7109. ZoneServer* zone = spawn->GetZone();
  7110. if (!zone) {
  7111. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7112. return 0;
  7113. }
  7114. Instance_Type iType = zone->GetInstanceType();
  7115. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7116. iType == GROUP_LOCKOUT_INSTANCE ||
  7117. iType == RAID_LOCKOUT_INSTANCE ||
  7118. iType == SOLO_PERSIST_INSTANCE ||
  7119. iType == GROUP_PERSIST_INSTANCE ||
  7120. iType == RAID_PERSIST_INSTANCE) {
  7121. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7122. if (data) {
  7123. // Check to see if the timer has already been set, if it has return out.
  7124. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7125. return 0;
  7126. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7127. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7128. if(spawn->IsPlayer()) {
  7129. Client* client = ((Player*)spawn)->GetClient();
  7130. if (client) {
  7131. string time_msg = "";
  7132. int32 time = data->failure_lockout_time;
  7133. int16 hour;
  7134. int8 min;
  7135. int8 sec;
  7136. hour = time / 3600;
  7137. time = time % 3600;
  7138. min = time / 60;
  7139. time = time % 60;
  7140. sec = time;
  7141. if (hour > 0) {
  7142. char temp[10];
  7143. sprintf(temp, " %i", hour);
  7144. time_msg.append(temp);
  7145. time_msg.append(" hour");
  7146. time_msg.append((hour > 1) ? "s" : "");
  7147. }
  7148. if (min > 0) {
  7149. char temp[5];
  7150. sprintf(temp, " %i", min);
  7151. time_msg.append(temp);
  7152. time_msg.append(" minute");
  7153. time_msg.append((min > 1) ? "s" : "");
  7154. }
  7155. // Only add seconds if minutes and hours are 0
  7156. if (hour == 0 && min == 0 && sec > 0) {
  7157. char temp[5];
  7158. sprintf(temp, " %i", sec);
  7159. time_msg.append(temp);
  7160. time_msg.append(" second");
  7161. time_msg.append((sec > 1) ? "s" : "");
  7162. }
  7163. 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());
  7164. }
  7165. }
  7166. else {
  7167. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7168. }
  7169. }
  7170. else
  7171. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7172. }
  7173. else
  7174. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7175. return 0;
  7176. }
  7177. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7178. if (!lua_interface)
  7179. return 0;
  7180. Spawn* spawn = lua_interface->GetSpawn(state);
  7181. lua_interface->ResetFunctionStack(state);
  7182. if (!spawn) {
  7183. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7184. return 0;
  7185. }
  7186. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7187. return 1;
  7188. }
  7189. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7190. if (!lua_interface)
  7191. return 0;
  7192. Spawn* player = lua_interface->GetSpawn(state);
  7193. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7194. if (!player) {
  7195. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7196. lua_interface->ResetFunctionStack(state);
  7197. return 0;
  7198. }
  7199. if (!player->IsPlayer()) {
  7200. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7201. lua_interface->ResetFunctionStack(state);
  7202. return 0;
  7203. }
  7204. if (!ground) {
  7205. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7206. lua_interface->ResetFunctionStack(state);
  7207. return 0;
  7208. }
  7209. if (!ground->IsGroundSpawn()) {
  7210. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7211. lua_interface->ResetFunctionStack(state);
  7212. return 0;
  7213. }
  7214. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7215. if (!groundspawn_entries) {
  7216. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7217. lua_interface->ResetFunctionStack(state);
  7218. return 0;
  7219. }
  7220. Skill* skill = 0;
  7221. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7222. if (collection_skill == "Collecting")
  7223. skill = ((Player*)player)->GetSkillByName("Gathering");
  7224. else
  7225. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7226. if (!skill) {
  7227. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7228. lua_interface->ResetFunctionStack(state);
  7229. return 0;
  7230. }
  7231. vector<GroundSpawnEntry*>::iterator itr;
  7232. GroundSpawnEntry* entry = 0;
  7233. bool can_harvest = false;
  7234. sint32 min_skill = -1;
  7235. int16 totalSkill = skill->current_val;
  7236. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7237. if(skillID != 0xFFFFFFFF)
  7238. {
  7239. ((Entity*)player)->MStats.lock();
  7240. totalSkill += ((Entity*)player)->stats[skillID];
  7241. ((Entity*)player)->MStats.unlock();
  7242. }
  7243. // first, iterate through groundspawn_entries, discard tables player cannot use
  7244. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7245. {
  7246. entry = *itr;
  7247. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7248. min_skill = entry->min_skill_level;
  7249. // if player lacks skill, skip table
  7250. if (entry->min_skill_level > totalSkill)
  7251. continue;
  7252. // if bonus, but player lacks level, skip table
  7253. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7254. continue;
  7255. can_harvest = true;
  7256. break;
  7257. }
  7258. lua_interface->SetBooleanValue(state, can_harvest);
  7259. // If false, send the message to the client
  7260. if (!can_harvest) {
  7261. Client* client = ((Player*)player)->GetClient();
  7262. if (client) {
  7263. string msg = "You do not have enough skill to ";
  7264. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7265. msg.append("gather");
  7266. else if (collection_skill == "Mining")
  7267. msg.append("mine");
  7268. else if (collection_skill == "Trapping")
  7269. msg.append("trap");
  7270. else if (collection_skill == "Foresting")
  7271. msg.append("forest");
  7272. else if (collection_skill == "Fishing")
  7273. msg.append("catch");
  7274. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7275. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7276. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7277. }
  7278. }
  7279. lua_interface->ResetFunctionStack(state);
  7280. return 1;
  7281. }
  7282. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7283. if (!lua_interface)
  7284. return 0;
  7285. Spawn* player = lua_interface->GetSpawn(state);
  7286. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7287. lua_interface->ResetFunctionStack(state);
  7288. if (!player) {
  7289. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7290. return 0;
  7291. }
  7292. if (!player->IsPlayer()) {
  7293. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7294. return 0;
  7295. }
  7296. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7297. lua_interface->SetBooleanValue(state, ret);
  7298. return 1;
  7299. }
  7300. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7301. // Check to see if we have a valid lua_interface
  7302. if (!lua_interface)
  7303. return 0;
  7304. // Get the spawn that is getting the pet
  7305. Spawn* spawn = lua_interface->GetSpawn(state);
  7306. Spawn* target = lua_interface->GetSpawn(state, 2);
  7307. // Get the DB ID of the pet
  7308. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7309. float x = lua_interface->GetFloatValue(state, 4);
  7310. float y = lua_interface->GetFloatValue(state, 5);
  7311. float z = lua_interface->GetFloatValue(state, 6);
  7312. // Get the spell that this command was called from
  7313. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7314. lua_interface->ResetFunctionStack(state);
  7315. // Check to make sure the spawn pointer is valid
  7316. if (!spawn) {
  7317. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7318. return 0;
  7319. }
  7320. // Check to make sure the spawn is an entity
  7321. if (!spawn->IsEntity()) {
  7322. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7323. return 0;
  7324. }
  7325. if (!target) {
  7326. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7327. return 0;
  7328. }
  7329. if (!target->IsEntity()) {
  7330. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7331. return 0;
  7332. }
  7333. // Check to see if the DB ID for the pet is set
  7334. if (pet_id == 0) {
  7335. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7336. return 0;
  7337. }
  7338. // Check to see if the pointer to the spell is valid
  7339. if (!luaspell) {
  7340. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7341. return 0;
  7342. }
  7343. if(luaspell->resisted) {
  7344. return 0;
  7345. }
  7346. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7347. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7348. if (!pet) {
  7349. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7350. return 0;
  7351. }
  7352. // Check to make sure the pet is an npc
  7353. if (!pet->IsNPC()) {
  7354. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7355. return 0;
  7356. }
  7357. if (x == 0)
  7358. x = spawn->GetX();
  7359. if (y == 0)
  7360. y = spawn->GetY();
  7361. if (z == 0)
  7362. z = spawn->GetZ();
  7363. // Spawn the pet at the same location as the owner
  7364. pet->SetX(x);
  7365. pet->SetY(y);
  7366. pet->SetZ(z);
  7367. pet->SetLocation(spawn->GetLocation());
  7368. pet->SetHeading(spawn->GetHeading());
  7369. spawn->GetZone()->AddSpawn(pet);
  7370. const char* spawn_script = world.GetSpawnScript(pet_id);
  7371. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7372. spawn->SetSpawnScript(string(spawn_script));
  7373. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7374. }
  7375. std::string petName = std::string("");
  7376. if(spawn->IsEntity()) {
  7377. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7378. }
  7379. if(petName.size() < 1) {
  7380. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7381. petName = spawn->GetZone()->pet_names.at(rand_index);
  7382. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7383. }
  7384. // Set the pets name
  7385. pet->SetName(petName.c_str());
  7386. // Set the level of the pet to the owners level
  7387. pet->SetLevel(spawn->GetLevel());
  7388. // Set the faction of the pet to the same faction as the owner
  7389. pet->SetFactionID(spawn->GetFactionID());
  7390. // Set the spawn as a pet
  7391. pet->SetPet(true);
  7392. // Give a pointer of the owner to the pet
  7393. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7394. // Set the pet type
  7395. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7396. // Set the spell id used to create this pet
  7397. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7398. // Set the spell tier used to create this pet
  7399. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7400. // Set the pets spawn type to 6
  7401. pet->SetSpawnType(6);
  7402. // Set the pets brain
  7403. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7404. // Check to see if the pet has a subtitle
  7405. if (strlen(pet->GetSubTitle()) > 0) {
  7406. // Add the players name to the front of the sub title
  7407. string pet_subtitle;
  7408. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7409. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7410. // Set the pets subtitle to the new one
  7411. pet->SetSubTitle(pet_subtitle.c_str());
  7412. }
  7413. // Set the pet as the return value for this function
  7414. lua_interface->SetSpawnValue(state, pet);
  7415. return 1;
  7416. }
  7417. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7418. if (!lua_interface)
  7419. return 0;
  7420. Spawn* spawn = lua_interface->GetSpawn(state);
  7421. Spawn* player = lua_interface->GetSpawn(state, 2);
  7422. float max_distance = lua_interface->GetFloatValue(state, 3);
  7423. string type = lua_interface->GetStringValue(state, 4);
  7424. lua_interface->ResetFunctionStack(state);
  7425. if (!spawn || (spawn && spawn->IsPlayer())) {
  7426. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7427. return 0;
  7428. }
  7429. if (!player || !player->IsPlayer()) {
  7430. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7431. return 0;
  7432. }
  7433. Client* client = ((Player*)player)->GetClient();
  7434. if (!client) {
  7435. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7436. return 0;
  7437. }
  7438. //Set max_distance to default if not set or not proper value
  7439. if (max_distance <= 0)
  7440. max_distance = 500;
  7441. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7442. if (packet) {
  7443. float unknown2_3 = 0;
  7444. int8 placement_mode = 0;
  7445. if (type == "wall") {
  7446. placement_mode = 2;
  7447. unknown2_3 = 150;
  7448. }
  7449. else if (type == "ceiling")
  7450. placement_mode = 1;
  7451. packet->setDataByName("placement_mode", placement_mode);
  7452. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7453. packet->setDataByName("model_type", spawn->GetModelType());
  7454. packet->setDataByName("unknown", 1); //size
  7455. packet->setDataByName("unknown2", 1); //size 2
  7456. packet->setDataByName("unknown2", .5, 1); //size 3
  7457. packet->setDataByName("unknown2", 3, 2);
  7458. packet->setDataByName("unknown2", unknown2_3, 3);
  7459. packet->setDataByName("max_distance", max_distance);
  7460. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7461. client->QueuePacket(packet->serialize());
  7462. safe_delete(packet);
  7463. }
  7464. return 0;
  7465. }
  7466. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7467. if (!lua_interface)
  7468. return 0;
  7469. Item* item = lua_interface->GetItem(state);
  7470. lua_interface->ResetFunctionStack(state);
  7471. if (!item) {
  7472. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7473. return 0;
  7474. }
  7475. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7476. return 1;
  7477. }
  7478. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7479. if (!lua_interface)
  7480. return 0;
  7481. Item* item = lua_interface->GetItem(state);
  7482. lua_interface->ResetFunctionStack(state);
  7483. if (!item) {
  7484. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7485. return 0;
  7486. }
  7487. lua_interface->SetInt32Value(state, item->effect_type);
  7488. return 1;
  7489. }
  7490. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7491. if (!lua_interface)
  7492. return 0;
  7493. Spawn* spawn = lua_interface->GetSpawn(state);
  7494. lua_interface->ResetFunctionStack(state);
  7495. if (!spawn) {
  7496. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7497. return 0;
  7498. }
  7499. if (spawn->GetZone())
  7500. spawn->GetZone()->AddTransportSpawn(spawn);
  7501. return 0;
  7502. }
  7503. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7504. if (!lua_interface)
  7505. return 0;
  7506. Spawn* spawn = lua_interface->GetSpawn(state);
  7507. lua_interface->ResetFunctionStack(state);
  7508. if (!spawn) {
  7509. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7510. return 0;
  7511. }
  7512. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7513. return 1;
  7514. }
  7515. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7516. if (!lua_interface)
  7517. return 0;
  7518. Skill* skill = lua_interface->GetSkill(state);
  7519. lua_interface->ResetFunctionStack(state);
  7520. if (!skill) {
  7521. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7522. return 0;
  7523. }
  7524. lua_interface->SetInt32Value(state, skill->current_val);
  7525. return 1;
  7526. }
  7527. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7528. if (!lua_interface)
  7529. return 0;
  7530. Skill* skill = lua_interface->GetSkill(state);
  7531. lua_interface->ResetFunctionStack(state);
  7532. if (!skill) {
  7533. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7534. return 0;
  7535. }
  7536. lua_interface->SetInt32Value(state, skill->max_val);
  7537. return 1;
  7538. }
  7539. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7540. if (!lua_interface)
  7541. return 0;
  7542. Skill* skill = lua_interface->GetSkill(state);
  7543. lua_interface->ResetFunctionStack(state);
  7544. if (!skill) {
  7545. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7546. return 0;
  7547. }
  7548. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7549. return 1;
  7550. }
  7551. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7552. if (!lua_interface)
  7553. return 0;
  7554. Skill* skill = lua_interface->GetSkill(state);
  7555. int16 value = lua_interface->GetInt16Value(state, 2);
  7556. lua_interface->ResetFunctionStack(state);
  7557. if (!skill) {
  7558. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7559. return 0;
  7560. }
  7561. skill->max_val = value;
  7562. if (skill->max_val < skill->current_val)
  7563. skill->current_val = skill->max_val;
  7564. return 0;
  7565. }
  7566. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7567. if (!lua_interface)
  7568. return 0;
  7569. Skill* skill = lua_interface->GetSkill(state);
  7570. int16 value = lua_interface->GetInt16Value(state, 2);
  7571. lua_interface->ResetFunctionStack(state);
  7572. if (!skill) {
  7573. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7574. return 0;
  7575. }
  7576. if (value > skill->max_val)
  7577. skill->current_val = skill->max_val;
  7578. else
  7579. skill->current_val = value;
  7580. return 0;
  7581. }
  7582. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7583. if (!lua_interface)
  7584. return 0;
  7585. Spawn* player = lua_interface->GetSpawn(state);
  7586. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7587. lua_interface->ResetFunctionStack(state);
  7588. if (skill_id > 0 && player && player->IsPlayer()) {
  7589. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7590. return 1;
  7591. }
  7592. return 0;
  7593. }
  7594. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7595. if (!lua_interface)
  7596. return 0;
  7597. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7598. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7599. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7600. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7601. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7602. lua_interface->ResetFunctionStack(state);
  7603. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7604. if (player_spawn && player_spawn->IsPlayer()) {
  7605. Player* player = (Player*)player_spawn;
  7606. bool added = false;
  7607. if (!player->skill_list.HasSkill(skill_id)) {
  7608. player->AddSkill(skill_id, current_val, max_val, true);
  7609. added = true;
  7610. }
  7611. if (!more_to_add) { //need to send update regardless, even if THIS skill wasn't added, otherwise if you have a list and the last item wasn't added but the previous ones were, it wouldn't send the update
  7612. Client* client = player->GetClient();
  7613. if (client) {
  7614. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7615. if (packet)
  7616. client->QueuePacket(packet);
  7617. }
  7618. }
  7619. if (added) {
  7620. lua_interface->SetBooleanValue(state, true);
  7621. return 1;
  7622. }
  7623. }
  7624. else {
  7625. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7626. }
  7627. }
  7628. else {
  7629. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7630. }
  7631. lua_interface->SetBooleanValue(state, false);
  7632. return 1;
  7633. }
  7634. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7635. if (!lua_interface)
  7636. return 0;
  7637. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7638. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7639. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7640. lua_interface->ResetFunctionStack(state);
  7641. if (skill_id > 0) {
  7642. if (player_spawn && player_spawn->IsPlayer()) {
  7643. Player* player = (Player*)player_spawn;
  7644. if (player->skill_list.HasSkill(skill_id)) {
  7645. player->RemovePlayerSkill(skill_id, true);
  7646. if (!more_to_remove) {
  7647. Client* client = player->GetClient();
  7648. if (client) {
  7649. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7650. if (packet)
  7651. client->QueuePacket(packet);
  7652. }
  7653. }
  7654. }
  7655. }
  7656. else {
  7657. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7658. }
  7659. }
  7660. else {
  7661. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7662. }
  7663. return 0;
  7664. }
  7665. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7666. if (!lua_interface)
  7667. return 0;
  7668. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7669. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7670. int16 amount = lua_interface->GetInt8Value(state, 3);
  7671. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7672. lua_interface->ResetFunctionStack(state);
  7673. if (amount > 0 && skill_type < 100) {
  7674. if (player_spawn && player_spawn->IsPlayer()) {
  7675. Player* player = (Player*)player_spawn;
  7676. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7677. if (!more_to_increase) {
  7678. Client* client = player->GetClient();
  7679. if (client) {
  7680. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7681. if (packet)
  7682. client->QueuePacket(packet);
  7683. }
  7684. }
  7685. }
  7686. else {
  7687. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7688. }
  7689. }
  7690. else {
  7691. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7692. }
  7693. return 0;
  7694. }
  7695. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7696. if (!lua_interface)
  7697. return 0;
  7698. Spawn* spawn = lua_interface->GetSpawn(state);
  7699. string name = lua_interface->GetStringValue(state, 2);
  7700. lua_interface->ResetFunctionStack(state);
  7701. if (!spawn) {
  7702. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7703. return 0;
  7704. }
  7705. if (!spawn->IsEntity()) {
  7706. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7707. return 0;
  7708. }
  7709. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7710. if (skill) {
  7711. lua_interface->SetSkillValue(state, skill);
  7712. return 1;
  7713. }
  7714. return 0;
  7715. }
  7716. int EQ2Emu_lua_AddProc(lua_State* state) {
  7717. if (!lua_interface)
  7718. return 0;
  7719. Spawn* spawn = lua_interface->GetSpawn(state);
  7720. int8 type = lua_interface->GetInt8Value(state, 2);
  7721. float chance = lua_interface->GetFloatValue(state, 3);
  7722. Item* item = lua_interface->GetItem(state, 4);
  7723. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7724. LuaSpell* spell = 0;
  7725. if (!item)
  7726. spell = lua_interface->GetCurrentSpell(state);
  7727. if (!spawn && (!spell || !use_all_spelltargets)) {
  7728. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7729. return 0;
  7730. }
  7731. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7732. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7733. return 0;
  7734. }
  7735. if (!item && !spell) {
  7736. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7737. return 0;
  7738. }
  7739. if(spell && spell->resisted) {
  7740. return 0;
  7741. }
  7742. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7743. Spawn* target;
  7744. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7745. for (int8 i = 0; i < spell->targets.size(); i++) {
  7746. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7747. if (!target || !target->IsEntity())
  7748. continue;
  7749. ((Entity*)target)->AddProc(type, chance, item, spell);
  7750. }
  7751. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7752. }
  7753. else
  7754. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7755. return 0;
  7756. }
  7757. int EQ2Emu_lua_AddProcExt(lua_State* state) {
  7758. if (!lua_interface)
  7759. return 0;
  7760. Spawn* spawn = lua_interface->GetSpawn(state);
  7761. int8 type = lua_interface->GetInt8Value(state, 2);
  7762. int8 damage_type = lua_interface->GetInt8Value(state, 3);
  7763. float chance = lua_interface->GetFloatValue(state, 4);
  7764. int8 hp_ratio = lua_interface->GetInt8Value(state, 5);
  7765. bool below_health = lua_interface->GetBooleanValue(state, 6);
  7766. bool target_health = lua_interface->GetBooleanValue(state, 7);
  7767. Item* item = lua_interface->GetItem(state, 8);
  7768. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 9) == 1);
  7769. bool extended_version = true;
  7770. LuaSpell* spell = 0;
  7771. if (!item)
  7772. spell = lua_interface->GetCurrentSpell(state);
  7773. if (!spawn && (!spell || !use_all_spelltargets)) {
  7774. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7775. return 0;
  7776. }
  7777. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7778. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7779. return 0;
  7780. }
  7781. if (!item && !spell) {
  7782. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7783. return 0;
  7784. }
  7785. if(spell && spell->resisted) {
  7786. return 0;
  7787. }
  7788. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7789. Spawn* target;
  7790. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7791. for (int8 i = 0; i < spell->targets.size(); i++) {
  7792. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7793. if (!target || !target->IsEntity())
  7794. continue;
  7795. ((Entity*)target)->AddProc(type, chance, item, spell, damage_type, hp_ratio, below_health, target_health, extended_version);
  7796. }
  7797. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7798. }
  7799. else
  7800. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7801. return 0;
  7802. }
  7803. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7804. if (!lua_interface)
  7805. return 0;
  7806. Spawn* spawn = lua_interface->GetSpawn(state);
  7807. Item* item = lua_interface->GetItem(state, 2);
  7808. LuaSpell* spell = 0;
  7809. if (!item)
  7810. spell = lua_interface->GetCurrentSpell(state);
  7811. lua_interface->ResetFunctionStack(state);
  7812. if (!item && !spell) {
  7813. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7814. return 0;
  7815. }
  7816. if (spell && spell->caster && spell->caster->GetZone()) {
  7817. Spawn* target;
  7818. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7819. for (int8 i = 0; i < spell->targets.size(); i++) {
  7820. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7821. if (!target || !target->IsEntity())
  7822. continue;
  7823. ((Entity*)target)->RemoveProc(item, spell);
  7824. }
  7825. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7826. spell->caster->RemoveProc(item, spell);
  7827. }
  7828. else if (!spawn) {
  7829. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7830. return 0;
  7831. }
  7832. else if (!spawn->IsEntity()) {
  7833. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7834. return 0;
  7835. }
  7836. else {
  7837. ((Entity*)spawn)->RemoveProc(item, spell);
  7838. }
  7839. return 0;
  7840. }
  7841. int EQ2Emu_lua_Knockback(lua_State* state) {
  7842. if (!lua_interface)
  7843. return 0;
  7844. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7845. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7846. int32 duration = lua_interface->GetInt32Value(state, 3);
  7847. float vertical = lua_interface->GetFloatValue(state, 4);
  7848. float horizontal = lua_interface->GetFloatValue(state, 5);
  7849. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7850. lua_interface->ResetFunctionStack(state);
  7851. if (!target_spawn) {
  7852. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7853. return 0;
  7854. }
  7855. if (!spawn) {
  7856. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7857. return 0;
  7858. }
  7859. if ((vertical != 0 || horizontal != 0)) {
  7860. if(spawn->IsPlayer()) {
  7861. Client* client = ((Player*)spawn)->GetClient();
  7862. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7863. if (packet) {
  7864. packet->setDataByName("target_x", target_spawn->GetX());
  7865. packet->setDataByName("target_y", target_spawn->GetY());
  7866. packet->setDataByName("target_z", target_spawn->GetZ());
  7867. packet->setDataByName("vertical_movement", vertical);
  7868. packet->setDataByName("horizontal_movement", horizontal);
  7869. if (use_heading)
  7870. packet->setDataByName("use_player_heading", 1);
  7871. client->QueuePacket(packet->serialize());
  7872. }
  7873. safe_delete(packet);
  7874. }
  7875. else {
  7876. spawn->SetKnockback(target_spawn, duration, vertical, horizontal);
  7877. }
  7878. }
  7879. return 0;
  7880. }
  7881. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7882. if (!lua_interface)
  7883. return 0;
  7884. Spawn* spawn = lua_interface->GetSpawn(state);
  7885. lua_interface->ResetFunctionStack(state);
  7886. if (!spawn) {
  7887. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7888. return 0;
  7889. }
  7890. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7891. return 1;
  7892. }
  7893. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7894. if (!lua_interface)
  7895. return 0;
  7896. Spawn* caster = lua_interface->GetSpawn(state);
  7897. Spawn* target = lua_interface->GetSpawn(state, 2);
  7898. string name = lua_interface->GetStringValue(state, 3);
  7899. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7900. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7901. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7902. string success_msg = lua_interface->GetStringValue(state, 7);
  7903. string effect_msg = lua_interface->GetStringValue(state, 8);
  7904. lua_interface->ResetFunctionStack(state);
  7905. if (!caster) {
  7906. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7907. return 0;
  7908. }
  7909. if (!caster->IsEntity()) {
  7910. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7911. return 0;
  7912. }
  7913. if (!target) {
  7914. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7915. return 0;
  7916. }
  7917. if (!target->IsEntity()) {
  7918. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7919. return 0;
  7920. }
  7921. if (name.length() == 0) {
  7922. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7923. return 0;
  7924. }
  7925. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7926. return 0;
  7927. }
  7928. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7929. if (!lua_interface)
  7930. return 0;
  7931. string name = lua_interface->GetStringValue(state);
  7932. lua_interface->ResetFunctionStack(state);
  7933. if (name.length() == 0) {
  7934. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7935. return 0;
  7936. }
  7937. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7938. if (!skill) {
  7939. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7940. return 0;
  7941. }
  7942. lua_interface->SetInt32Value(state, skill->skill_id);
  7943. return 1;
  7944. }
  7945. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7946. if (!lua_interface)
  7947. return 0;
  7948. Spawn* spawn = lua_interface->GetSpawn(state);
  7949. lua_interface->ResetFunctionStack(state);
  7950. if (!spawn) {
  7951. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7952. return 0;
  7953. }
  7954. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7955. return 1;
  7956. }
  7957. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7958. if (!lua_interface)
  7959. return 0;
  7960. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7961. lua_interface->ResetFunctionStack(state);
  7962. if (!luaspell) {
  7963. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7964. return 0;
  7965. }
  7966. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7967. return 1;
  7968. }
  7969. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7970. if (!lua_interface)
  7971. return 0;
  7972. Spawn* spawn = lua_interface->GetSpawn(state);
  7973. Spawn* target = lua_interface->GetSpawn(state, 2);
  7974. lua_interface->ResetFunctionStack(state);
  7975. if (!spawn) {
  7976. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7977. return 0;
  7978. }
  7979. if (!spawn->IsEntity()) {
  7980. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7981. return 0;
  7982. }
  7983. if (!target) {
  7984. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7985. return 0;
  7986. }
  7987. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7988. return 1;
  7989. }
  7990. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7991. if (!lua_interface)
  7992. return 0;
  7993. Spawn* spawn = lua_interface->GetSpawn(state);
  7994. Spawn* target = lua_interface->GetSpawn(state, 2);
  7995. lua_interface->ResetFunctionStack(state);
  7996. if (!spawn) {
  7997. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7998. return 0;
  7999. }
  8000. if (!spawn->IsEntity()) {
  8001. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8002. return 0;
  8003. }
  8004. if (!target) {
  8005. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  8006. return 0;
  8007. }
  8008. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  8009. return 1;
  8010. }
  8011. int EQ2Emu_lua_InFront(lua_State* state) {
  8012. if (!lua_interface)
  8013. return 0;
  8014. Spawn* spawn = lua_interface->GetSpawn(state);
  8015. Spawn* target = lua_interface->GetSpawn(state, 2);
  8016. lua_interface->ResetFunctionStack(state);
  8017. if (!spawn) {
  8018. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  8019. return 0;
  8020. }
  8021. if (!target) {
  8022. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  8023. return 0;
  8024. }
  8025. lua_interface->SetBooleanValue(state, spawn->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  8026. return 1;
  8027. }
  8028. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  8029. if (!lua_interface)
  8030. return 0;
  8031. Item* item = lua_interface->GetItem(state);
  8032. lua_interface->ResetFunctionStack(state);
  8033. if (!item) {
  8034. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  8035. return 0;
  8036. }
  8037. lua_interface->SetInt32Value(state, item->details.count);
  8038. return 1;
  8039. }
  8040. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  8041. if (!lua_interface)
  8042. return 0;
  8043. Item* item = lua_interface->GetItem(state);
  8044. Spawn* owner = lua_interface->GetSpawn(state, 2);
  8045. int16 new_count = lua_interface->GetInt32Value(state, 3);
  8046. lua_interface->ResetFunctionStack(state);
  8047. if (!item) {
  8048. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  8049. return 0;
  8050. }
  8051. if (!owner) {
  8052. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  8053. return 0;
  8054. }
  8055. if (!owner->IsPlayer()) {
  8056. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8057. return 0;
  8058. }
  8059. if (item->stack_count < new_count) {
  8060. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  8061. return 0;
  8062. }
  8063. if (new_count > 0) {
  8064. item->details.count = new_count;
  8065. item->save_needed = true;
  8066. }
  8067. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  8068. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  8069. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  8070. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  8071. else
  8072. {
  8073. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  8074. return 0;
  8075. }
  8076. Client* client = ((Player*)owner)->GetClient();
  8077. if (!client)
  8078. return 0;
  8079. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  8080. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  8081. if (app)
  8082. client->QueuePacket(app);
  8083. return 0;
  8084. }
  8085. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  8086. if (!lua_interface)
  8087. return 0;
  8088. int32 time = lua_interface->GetInt32Value(state);
  8089. string function = lua_interface->GetStringValue(state, 2);
  8090. Spawn* caster = lua_interface->GetSpawn(state, 3);
  8091. Spawn* target = lua_interface->GetSpawn(state, 4);
  8092. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8093. lua_interface->ResetFunctionStack(state);
  8094. if (time == 0) {
  8095. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  8096. return 0;
  8097. }
  8098. if (function.length() == 0) {
  8099. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  8100. return 0;
  8101. }
  8102. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  8103. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  8104. return 0;
  8105. }
  8106. SpellScriptTimer* timer = new SpellScriptTimer;
  8107. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  8108. #ifdef WIN32
  8109. ZeroMemory(timer, sizeof(SpellScriptTimer));
  8110. #else
  8111. bzero(timer, sizeof(SpellScriptTimer));
  8112. #endif*/
  8113. timer->caster = 0;
  8114. timer->deleteWhenDone = false;
  8115. timer->target = 0;
  8116. timer->time = Timer::GetCurrentTime2() + time;
  8117. timer->customFunction = function;
  8118. timer->spell = spell;
  8119. if (caster)
  8120. timer->caster = caster->GetID();
  8121. if (target)
  8122. timer->target = target->GetID();
  8123. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8124. return 0;
  8125. }
  8126. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8127. if (!lua_interface)
  8128. return 0;
  8129. float hp_perc = lua_interface->GetFloatValue(state);
  8130. float power_perc = lua_interface->GetFloatValue(state, 2);
  8131. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8132. Spawn* target = lua_interface->GetSpawn(state, 4);
  8133. string heal_name = lua_interface->GetStringValue(state, 5);
  8134. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8135. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8136. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8137. lua_interface->ResetFunctionStack(state);
  8138. if (!spell) {
  8139. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8140. return 0;
  8141. }
  8142. Entity* caster = spell->caster;
  8143. if (!caster) {
  8144. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8145. return 0;
  8146. }
  8147. Client* client = 0;
  8148. PendingResurrection* rez = 0;
  8149. ZoneServer* zone = spell->caster->GetZone();
  8150. if (!target) {
  8151. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8152. if (spell->targets.size() > 0) {
  8153. vector<int32> spell_targets = spell->targets;
  8154. for (int8 i = 0; i < spell_targets.size(); i++) {
  8155. target = zone->GetSpawnByID(spell_targets.at(i));
  8156. if (!target)
  8157. continue;
  8158. if (!target->IsPlayer())
  8159. continue;
  8160. client = ((Player*)target)->GetClient();
  8161. if (!client)
  8162. continue;
  8163. rez = client->GetCurrentRez();
  8164. if (rez->active)
  8165. continue;
  8166. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8167. rez->active = true;
  8168. rez->caster = caster;
  8169. rez->expire_timer = new Timer;
  8170. int32 duration = spell->spell->GetSpellDuration();
  8171. rez->expire_timer->Start(duration * 100);
  8172. rez->hp_perc = hp_perc;
  8173. rez->mp_perc = power_perc;
  8174. rez->range = spell->spell->GetSpellData()->range;
  8175. rez->spell_name = spell->spell->GetName();
  8176. if (heal_name.length() > 0)
  8177. rez->heal_name = heal_name;
  8178. else
  8179. rez->heal_name = rez->spell_name;
  8180. rez->no_calcs = no_calcs;
  8181. rez->crit_mod = crit_mod;
  8182. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8183. if (send_window)
  8184. client->SendResurrectionWindow();
  8185. else {
  8186. target->GetZone()->ResurrectSpawn(target, client);
  8187. rez->should_delete = true;
  8188. }
  8189. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8190. }
  8191. }
  8192. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8193. }
  8194. else {
  8195. if(!target->IsPlayer())
  8196. return 0;
  8197. client = ((Player*)target)->GetClient();
  8198. if (!client)
  8199. return 0;
  8200. rez = client->GetCurrentRez();
  8201. if (rez->active)
  8202. return 0;
  8203. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8204. rez->active = true;
  8205. rez->caster = caster;
  8206. rez->expire_timer = new Timer;
  8207. int32 duration = spell->spell->GetSpellDuration();
  8208. rez->expire_timer->Start(duration * 100);
  8209. rez->hp_perc = hp_perc;
  8210. rez->mp_perc = power_perc;
  8211. rez->range = spell->spell->GetSpellData()->range;
  8212. rez->spell_name = spell->spell->GetName();
  8213. if (heal_name.length() > 0)
  8214. rez->heal_name = heal_name;
  8215. else
  8216. rez->heal_name = rez->spell_name;
  8217. rez->no_calcs = no_calcs;
  8218. rez->crit_mod = crit_mod;
  8219. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8220. if (send_window)
  8221. client->SendResurrectionWindow();
  8222. else {
  8223. target->GetZone()->ResurrectSpawn(target, client);
  8224. rez->should_delete = true;
  8225. }
  8226. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8227. }
  8228. return 0;
  8229. }
  8230. int EQ2Emu_lua_SetVision(lua_State* state) {
  8231. if (!lua_interface)
  8232. return 0;
  8233. Spawn* spawn = lua_interface->GetSpawn(state);
  8234. int32 vision = lua_interface->GetInt32Value(state, 2);
  8235. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8236. lua_interface->ResetFunctionStack(state);
  8237. if (!spawn) {
  8238. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8239. return 0;
  8240. }
  8241. if (!spawn->IsEntity()) {
  8242. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8243. return 0;
  8244. }
  8245. if (spell && spell->targets.size() > 0) {
  8246. ZoneServer* zone = spell->caster->GetZone();
  8247. for (int8 i = 0; i < spell->targets.size(); i++) {
  8248. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8249. if (target && target->IsEntity()) {
  8250. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8251. if (target->IsPlayer())
  8252. ((Player*)target)->SetCharSheetChanged(true);
  8253. }
  8254. }
  8255. }
  8256. else {
  8257. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8258. if (spawn->IsPlayer())
  8259. ((Player*)spawn)->SetCharSheetChanged(true);
  8260. }
  8261. return 0;
  8262. }
  8263. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8264. if (!lua_interface)
  8265. return 0;
  8266. Spawn* spawn = lua_interface->GetSpawn(state);
  8267. float intensity = lua_interface->GetFloatValue(state, 2);
  8268. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8269. lua_interface->ResetFunctionStack(state);
  8270. if (!spawn) {
  8271. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8272. return 0;
  8273. }
  8274. if (!spawn->IsEntity()) {
  8275. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8276. return 0;
  8277. }
  8278. if (spell && spell->targets.size() > 0) {
  8279. ZoneServer* zone = spell->caster->GetZone();
  8280. for (int8 i = 0; i < spell->targets.size(); i++) {
  8281. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8282. if (target && target->IsEntity()) {
  8283. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8284. if (target->IsPlayer())
  8285. ((Player*)target)->SetCharSheetChanged(true);
  8286. }
  8287. }
  8288. }
  8289. else {
  8290. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8291. if (spawn->IsPlayer())
  8292. ((Player*)spawn)->SetCharSheetChanged(true);
  8293. }
  8294. return 0;
  8295. }
  8296. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8297. if (!lua_interface)
  8298. return 0;
  8299. Spawn* spawn = lua_interface->GetSpawn(state);
  8300. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8301. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8302. lua_interface->ResetFunctionStack(state);
  8303. if (!spawn) {
  8304. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8305. return 0;
  8306. }
  8307. if (!spawn->IsEntity()) {
  8308. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8309. return 0;
  8310. }
  8311. if (spell && spell->targets.size() > 0) {
  8312. ZoneServer* zone = spell->caster->GetZone();
  8313. for (int8 i = 0; i < spell->targets.size(); i++) {
  8314. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8315. if (target && target->IsEntity()) {
  8316. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8317. if (target->IsPlayer())
  8318. ((Player*)target)->SetCharSheetChanged(true);
  8319. }
  8320. }
  8321. }
  8322. else {
  8323. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8324. if (spawn->IsPlayer())
  8325. ((Player*)spawn)->SetCharSheetChanged(true);
  8326. }
  8327. return 0;
  8328. }
  8329. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8330. if (!lua_interface)
  8331. return 0;
  8332. Item* item = lua_interface->GetItem(state);
  8333. int8 type = lua_interface->GetInt32Value(state, 2);
  8334. lua_interface->ResetFunctionStack(state);
  8335. if (!item) {
  8336. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8337. return 0;
  8338. }
  8339. if (type == 1)
  8340. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8341. else if (type == 2)
  8342. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8343. return 1;
  8344. }
  8345. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8346. if (!lua_interface)
  8347. return 0;
  8348. Spawn* target = lua_interface->GetSpawn(state);
  8349. float val = lua_interface->GetFloatValue(state, 2);
  8350. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8351. lua_interface->ResetFunctionStack(state);
  8352. // Added from Gangrenous post
  8353. if (spell && spell->resisted)
  8354. return 0;
  8355. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8356. if (val > 1.0f)
  8357. val = 1.0f - (val / 100.0f);
  8358. if (spell && spell->spell && spell->targets.size() > 0) {
  8359. ZoneServer* zone = spell->caster->GetZone();
  8360. for (int32 i = 0; i != spell->targets.size(); i++) {
  8361. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8362. if (spawn && spawn->IsEntity()) {
  8363. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8364. if (spawn->IsPlayer())
  8365. ((Player*)spawn)->SetCharSheetChanged(true);
  8366. }
  8367. }
  8368. }
  8369. else {
  8370. if (target && target->IsEntity()) {
  8371. ((Entity*)target)->SetSpeedMultiplier(val);
  8372. if (target->IsPlayer())
  8373. ((Player*)target)->SetCharSheetChanged(true);
  8374. }
  8375. }
  8376. return 0;
  8377. }
  8378. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8379. if (!lua_interface)
  8380. return 0;
  8381. Spawn* spawn = lua_interface->GetSpawn(state);
  8382. int16 model = lua_interface->GetInt16Value(state, 2);
  8383. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8384. lua_interface->ResetFunctionStack(state);
  8385. if (spell && spell->spell && spell->targets.size() > 0) {
  8386. ZoneServer* zone = spell->caster->GetZone();
  8387. for (int32 i = 0; i < spell->targets.size(); i++) {
  8388. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8389. if (target)
  8390. target->SetIllusionModel(model);
  8391. }
  8392. }
  8393. else {
  8394. if (!spawn) {
  8395. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8396. return 0;
  8397. }
  8398. spawn->SetIllusionModel(model);
  8399. }
  8400. return 0;
  8401. }
  8402. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8403. if (!lua_interface)
  8404. return 0;
  8405. Spawn* spawn = lua_interface->GetSpawn(state);
  8406. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8407. lua_interface->ResetFunctionStack(state);
  8408. if (spell && spell->spell && spell->targets.size() > 0) {
  8409. ZoneServer* zone = spell->caster->GetZone();
  8410. for (int32 i = 0; i < spell->targets.size(); i++) {
  8411. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8412. if (target)
  8413. target->SetIllusionModel(0);
  8414. }
  8415. }
  8416. else {
  8417. if (!spawn) {
  8418. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8419. return 0;
  8420. }
  8421. spawn->SetIllusionModel(0);
  8422. }
  8423. return 0;
  8424. }
  8425. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8426. if (!lua_interface)
  8427. return 0;
  8428. Spawn* caster = lua_interface->GetSpawn(state);
  8429. Spawn* target = lua_interface->GetSpawn(state, 2);
  8430. float chance = lua_interface->GetFloatValue(state, 3);
  8431. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8432. lua_interface->ResetFunctionStack(state);
  8433. if (!caster) {
  8434. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8435. return 0;
  8436. }
  8437. if (!caster->IsEntity()) {
  8438. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8439. return 0;
  8440. }
  8441. if (!target) {
  8442. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8443. return 0;
  8444. }
  8445. if (!target->IsEntity()) {
  8446. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8447. return 0;
  8448. }
  8449. if (chance <= 0) {
  8450. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8451. return 0;
  8452. }
  8453. if (!spell) {
  8454. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8455. return 0;
  8456. }
  8457. if(spell->resisted) {
  8458. return 0;
  8459. }
  8460. if (((Entity*)caster)->GetThreatTransfer()) {
  8461. return 0;
  8462. }
  8463. ThreatTransfer* transfer = new ThreatTransfer;
  8464. transfer->Target = target->GetID();
  8465. transfer->Amount = chance;
  8466. transfer->Spell = spell;
  8467. ((Entity*)caster)->SetThreatTransfer(transfer);
  8468. return 0;
  8469. }
  8470. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8471. if (!lua_interface)
  8472. return 0;
  8473. Spawn* spawn = lua_interface->GetSpawn(state);
  8474. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8475. lua_interface->ResetFunctionStack(state);
  8476. if (!spawn || !spawn->IsEntity()) {
  8477. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8478. return 0;
  8479. }
  8480. if (!spawn->IsEntity()) {
  8481. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8482. return 0;
  8483. }
  8484. if (!spell) {
  8485. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8486. return 0;
  8487. }
  8488. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8489. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8490. if(transfer && transfer->Spell != spell) {
  8491. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8492. return 0;
  8493. }
  8494. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8495. }
  8496. return 0;
  8497. }
  8498. int EQ2Emu_lua_CureByType(lua_State* state) {
  8499. if (!lua_interface)
  8500. return 0;
  8501. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8502. int8 cure_count = lua_interface->GetInt8Value(state);
  8503. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8504. string cure_name = lua_interface->GetStringValue(state, 3);
  8505. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8506. Spawn* target = lua_interface->GetSpawn(state, 5);
  8507. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8508. lua_interface->ResetFunctionStack(state);
  8509. if(spell && spell->resisted) {
  8510. return 0;
  8511. }
  8512. if (target) {
  8513. if (!target->IsEntity()) {
  8514. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8515. return 0;
  8516. }
  8517. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8518. std::string alternate_name = "item";
  8519. if(spell)
  8520. alternate_name = std::string(spell->spell->GetName());
  8521. if(!caster && spell)
  8522. caster = (Spawn*)spell->caster;
  8523. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8524. }
  8525. }
  8526. else {
  8527. ZoneServer* zone = spell->caster->GetZone();
  8528. vector<int32> targets = spell->targets;
  8529. vector<Entity*> targets_to_cure;
  8530. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8531. for (int8 i = 0; i < targets.size(); i++) {
  8532. target = zone->GetSpawnByID(targets.at(i));
  8533. if (!target || !target->IsEntity())
  8534. continue;
  8535. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8536. targets_to_cure.push_back((Entity*)target);
  8537. }
  8538. }
  8539. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8540. vector<Entity*>::iterator itr;
  8541. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8542. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8543. }
  8544. }
  8545. return 0;
  8546. }
  8547. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8548. if (!lua_interface)
  8549. return 0;
  8550. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8551. if(spell->resisted) {
  8552. lua_interface->ResetFunctionStack(state);
  8553. return 0;
  8554. }
  8555. int8 cure_count = lua_interface->GetInt8Value(state);
  8556. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8557. string cure_name = lua_interface->GetStringValue(state, 3);
  8558. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8559. Spawn* target = lua_interface->GetSpawn(state, 5);
  8560. lua_interface->ResetFunctionStack(state);
  8561. if (target) {
  8562. if (!target->IsEntity()) {
  8563. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8564. return 0;
  8565. }
  8566. if (((Entity*)target)->GetDetCount() > 0)
  8567. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8568. }
  8569. else {
  8570. ZoneServer* zone = spell->caster->GetZone();
  8571. vector<int32> targets = spell->targets;
  8572. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8573. for (int8 i = 0; i < targets.size(); i++) {
  8574. target = zone->GetSpawnByID(targets.at(i));
  8575. if (!target || !target->IsEntity())
  8576. continue;
  8577. if (((Entity*)target)->GetDetCount() > 0)
  8578. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8579. }
  8580. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8581. }
  8582. return 0;
  8583. }
  8584. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8585. if (!lua_interface)
  8586. return 0;
  8587. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8588. lua_interface->ResetFunctionStack(state);
  8589. if (!spell) {
  8590. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8591. return 0;
  8592. }
  8593. if (!spell->caster) {
  8594. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8595. return 0;
  8596. }
  8597. if (!spell->caster->GetZone()) {
  8598. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8599. return 0;
  8600. }
  8601. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8602. return 0;
  8603. }
  8604. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8605. if (!lua_interface)
  8606. return 0;
  8607. Spawn* spawn = lua_interface->GetSpawn(state);
  8608. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8609. lua_interface->ResetFunctionStack(state);
  8610. if (!spell) {
  8611. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8612. return 0;
  8613. }
  8614. if (spawn && spawn->IsEntity())
  8615. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8616. else {
  8617. ZoneServer* zone = spell->caster->GetZone();
  8618. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8619. for (int32 i = 0; i < spell->targets.size(); i++) {
  8620. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8621. if (!spawn || !spawn->IsEntity())
  8622. continue;
  8623. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8624. }
  8625. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8626. }
  8627. return 0;
  8628. }
  8629. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8630. if (!lua_interface)
  8631. return 0;
  8632. Spawn* spawn = lua_interface->GetSpawn(state);
  8633. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8634. lua_interface->ResetFunctionStack(state);
  8635. if (!spell) {
  8636. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8637. return 0;
  8638. }
  8639. if (spawn && spawn->IsEntity())
  8640. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8641. else {
  8642. ZoneServer* zone = spell->caster->GetZone();
  8643. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8644. for (int32 i = 0; i < spell->targets.size(); i++) {
  8645. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8646. if (!spawn || !spawn->IsEntity())
  8647. continue;
  8648. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8649. }
  8650. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8651. }
  8652. return 0;
  8653. }
  8654. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8655. if (!lua_interface)
  8656. return 0;
  8657. Spawn* caster = lua_interface->GetSpawn(state);
  8658. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8659. lua_interface->ResetFunctionStack(state);
  8660. if (!caster) {
  8661. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8662. return 0;
  8663. }
  8664. if (!caster->IsPlayer()) {
  8665. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8666. return 0;
  8667. }
  8668. Spawn* target = caster->GetTarget();
  8669. if (!target) {
  8670. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8671. return 0;
  8672. }
  8673. Client* client = ((Player*)caster)->GetClient();
  8674. if (!client) {
  8675. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8676. return 0;
  8677. }
  8678. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8679. if (ho) {
  8680. ho->SetTarget(target->GetID());
  8681. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8682. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8683. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8684. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8685. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8686. deque<GroupMemberInfo*>::iterator itr;
  8687. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8688. if (group)
  8689. {
  8690. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8691. deque<GroupMemberInfo*>* members = group->GetMembers();
  8692. for (itr = members->begin(); itr != members->end(); itr++) {
  8693. if ((*itr)->client)
  8694. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8695. }
  8696. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8697. }
  8698. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8699. }
  8700. else
  8701. safe_delete(ho);
  8702. }
  8703. else {
  8704. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8705. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8706. }
  8707. else
  8708. safe_delete(ho);
  8709. }
  8710. }
  8711. return 0;
  8712. }
  8713. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8714. if (!lua_interface)
  8715. return 0;
  8716. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8717. if (!spell) {
  8718. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8719. return 0;
  8720. }
  8721. int16 triggerCount = lua_interface->GetInt16Value(state);
  8722. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8723. if (!triggerCount) {
  8724. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8725. return 0;
  8726. }
  8727. spell->num_triggers = triggerCount;
  8728. spell->had_triggers = true;
  8729. spell->cancel_after_all_triggers = cancel_after_triggers;
  8730. return 0;
  8731. }
  8732. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8733. if (!lua_interface)
  8734. return 0;
  8735. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8736. lua_interface->ResetFunctionStack(state);
  8737. if (!spell) {
  8738. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8739. return 0;
  8740. }
  8741. lua_interface->SetInt32Value(state, spell->num_triggers);
  8742. return 1;
  8743. }
  8744. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8745. if (!lua_interface)
  8746. return 0;
  8747. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8748. if (!spell) {
  8749. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8750. lua_interface->ResetFunctionStack(state);
  8751. return 0;
  8752. }
  8753. if (!spell->caster || !spell->caster->GetZone()) {
  8754. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8755. lua_interface->ResetFunctionStack(state);
  8756. return 0;
  8757. }
  8758. int16 remove_count = lua_interface->GetInt16Value(state);
  8759. lua_interface->ResetFunctionStack(state);
  8760. if (!remove_count)
  8761. remove_count = 1;
  8762. if (remove_count >= spell->num_triggers) {
  8763. spell->num_triggers = 0;
  8764. if (spell->cancel_after_all_triggers)
  8765. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8766. }
  8767. else {
  8768. spell->num_triggers -= remove_count;
  8769. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8770. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8771. }
  8772. return 0;
  8773. }
  8774. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8775. if (!lua_interface)
  8776. return 0;
  8777. Spawn* spawn = lua_interface->GetSpawn(state);
  8778. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8779. lua_interface->ResetFunctionStack(state);
  8780. if (!spawn) {
  8781. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8782. return 0;
  8783. }
  8784. if (!copy_spawn) {
  8785. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8786. return 0;
  8787. }
  8788. spawn->CopySpawnAppearance(copy_spawn);
  8789. return 0;
  8790. }
  8791. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8792. Spawn* spawn = lua_interface->GetSpawn(state);
  8793. int8 type = lua_interface->GetInt8Value(state, 2);
  8794. lua_interface->ResetFunctionStack(state);
  8795. if (!spawn) {
  8796. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8797. return 0;
  8798. }
  8799. else if (!spawn->IsEntity()) {
  8800. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8801. return 0;
  8802. }
  8803. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8804. return 1;
  8805. }
  8806. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8807. if (!lua_interface)
  8808. return 0;
  8809. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8810. int8 type = lua_interface->GetInt8Value(state);
  8811. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8812. lua_interface->ResetFunctionStack(state);
  8813. if (!spell) {
  8814. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8815. return 0;
  8816. }
  8817. if(spell->resisted) {
  8818. return 0;
  8819. }
  8820. if (spawn) {
  8821. if (!spawn->IsEntity()) {
  8822. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8823. return 0;
  8824. }
  8825. Entity* entity = ((Entity*)spawn);
  8826. entity->AddImmunity(spell, type);
  8827. }
  8828. else if(spell->caster && spell->caster->GetZone()) {
  8829. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8830. for (int8 i = 0; i < spell->targets.size(); i++) {
  8831. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8832. if (!spawn || !spawn->IsEntity())
  8833. continue;
  8834. Entity* entity = ((Entity*)spawn);
  8835. entity->AddImmunity(spell, type);
  8836. }
  8837. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8838. }
  8839. return 0;
  8840. }
  8841. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8842. if (!lua_interface)
  8843. return 0;
  8844. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8845. int8 type = lua_interface->GetInt8Value(state);
  8846. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8847. lua_interface->ResetFunctionStack(state);
  8848. if (!spell) {
  8849. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8850. return 0;
  8851. }
  8852. if (spawn) {
  8853. if (!spawn->IsEntity()) {
  8854. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8855. return 0;
  8856. }
  8857. Entity* entity = ((Entity*)spawn);
  8858. entity->RemoveImmunity(spell, type);
  8859. }
  8860. else if(spell->caster && spell->caster->GetZone()) {
  8861. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8862. for (int8 i = 0; i < spell->targets.size(); i++) {
  8863. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8864. if (!spawn || !spawn->IsEntity())
  8865. continue;
  8866. Entity* entity = ((Entity*)spawn);
  8867. entity->RemoveImmunity(spell, type);
  8868. }
  8869. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8870. }
  8871. return 0;
  8872. }
  8873. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8874. if (!lua_interface)
  8875. return 0;
  8876. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8877. if(spell && spell->resisted) {
  8878. lua_interface->ResetFunctionStack(state);
  8879. return 0;
  8880. }
  8881. float snare = lua_interface->GetFloatValue(state);
  8882. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8883. lua_interface->ResetFunctionStack(state);
  8884. // convert the val to the speed multipler value (100 - val)
  8885. float val = 100.0 - snare;
  8886. val /= 100.0;
  8887. if (spawn) {
  8888. if (!spawn->IsEntity()) {
  8889. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8890. return 0;
  8891. }
  8892. ((Entity*)spawn)->SetSnareValue(spell, val);
  8893. }
  8894. else if(spell && spell->caster && spell->caster->GetZone()) {
  8895. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8896. for (int8 i = 0; i < spell->targets.size(); i++) {
  8897. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8898. if (!spawn || !spawn->IsEntity())
  8899. continue;
  8900. ((Entity*)spawn)->SetSnareValue(spell, val);
  8901. }
  8902. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8903. }
  8904. return 0;
  8905. }
  8906. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8907. if (!lua_interface)
  8908. return 0;
  8909. Spawn* spawn = lua_interface->GetSpawn(state);
  8910. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8911. lua_interface->ResetFunctionStack(state);
  8912. if (!spawn) {
  8913. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8914. return 0;
  8915. }
  8916. if (race_id == 0) {
  8917. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8918. return 0;
  8919. }
  8920. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8921. return 1;
  8922. }
  8923. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8924. if (!lua_interface)
  8925. return 0;
  8926. Spawn* spawn = lua_interface->GetSpawn(state);
  8927. lua_interface->ResetFunctionStack(state);
  8928. if (!spawn) {
  8929. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8930. return 0;
  8931. }
  8932. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8933. return 1;
  8934. }
  8935. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8936. if (!lua_interface)
  8937. return 0;
  8938. Spawn* spawn = lua_interface->GetSpawn(state);
  8939. lua_interface->ResetFunctionStack(state);
  8940. if (!spawn) {
  8941. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8942. return 0;
  8943. }
  8944. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8945. return 1;
  8946. }
  8947. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8948. if (!lua_interface)
  8949. return 0;
  8950. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8951. lua_interface->ResetFunctionStack(state);
  8952. if (!spell) {
  8953. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8954. return 0;
  8955. }
  8956. lua_interface->SetStringValue(state, spell->spell->GetName());
  8957. return 1;
  8958. }
  8959. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8960. if (!lua_interface)
  8961. return 0;
  8962. Quest* quest = lua_interface->GetQuest(state);
  8963. lua_interface->ResetFunctionStack(state);
  8964. if (!quest) {
  8965. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8966. return 0;
  8967. }
  8968. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8969. return 1;
  8970. }
  8971. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8972. if (!lua_interface)
  8973. return 0;
  8974. Quest* quest = lua_interface->GetQuest(state);
  8975. int32 flags = lua_interface->GetInt32Value(state, 2);
  8976. lua_interface->ResetFunctionStack(state);
  8977. if (!quest) {
  8978. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8979. return 0;
  8980. }
  8981. quest->SetQuestFlags(flags);
  8982. return 0;
  8983. }
  8984. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8985. if (!lua_interface)
  8986. return 0;
  8987. Quest* quest = lua_interface->GetQuest(state);
  8988. Spawn* player = lua_interface->GetSpawn(state, 2);
  8989. int32 step = lua_interface->GetInt32Value(state, 3);
  8990. int32 duration = lua_interface->GetInt32Value(state, 4);
  8991. string action = lua_interface->GetStringValue(state, 5);
  8992. lua_interface->ResetFunctionStack(state);
  8993. if (!quest) {
  8994. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8995. return 0;
  8996. }
  8997. if (!player) {
  8998. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8999. return 0;
  9000. }
  9001. if (!player->IsPlayer()) {
  9002. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9003. return 0;
  9004. }
  9005. if (step == 0) {
  9006. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  9007. return 0;
  9008. }
  9009. if (duration == 0) {
  9010. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  9011. return 0;
  9012. }
  9013. if (action.length() == 0) {
  9014. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  9015. return 0;
  9016. }
  9017. Client* client = ((Player*)player)->GetClient();
  9018. if (!client) {
  9019. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  9020. return 0;
  9021. }
  9022. quest->SetTimerStep(step);
  9023. quest->AddFailedAction(step, action);
  9024. quest->SetStepTimer(duration);
  9025. client->AddQuestTimer(quest->GetQuestID());
  9026. return 0;
  9027. }
  9028. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  9029. if (!lua_interface)
  9030. return 0;
  9031. Quest* quest = lua_interface->GetQuest(state);
  9032. Spawn* player = lua_interface->GetSpawn(state, 2);
  9033. lua_interface->ResetFunctionStack(state);
  9034. if (!quest) {
  9035. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  9036. return 0;
  9037. }
  9038. if (!player) {
  9039. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9040. return 0;
  9041. }
  9042. if (!player->IsPlayer()) {
  9043. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9044. return 0;
  9045. }
  9046. Client* client = ((Player*)player)->GetClient();
  9047. if (!client) {
  9048. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  9049. return 0;
  9050. }
  9051. quest->SetTimerStep(0);
  9052. quest->SetStepTimer(0);
  9053. client->RemoveQuestTimer(quest->GetQuestID());
  9054. return 0;
  9055. }
  9056. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  9057. if (!lua_interface)
  9058. return 0;
  9059. Spawn* player = lua_interface->GetSpawn(state);
  9060. Quest* quest = lua_interface->GetQuest(state, 2);
  9061. int32 step = lua_interface->GetInt32Value(state, 3);
  9062. lua_interface->ResetFunctionStack(state);
  9063. if (!player) {
  9064. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9065. return 0;
  9066. }
  9067. if (!player->IsPlayer()) {
  9068. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9069. return 0;
  9070. }
  9071. if (!quest) {
  9072. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9073. return 0;
  9074. }
  9075. if (step == 0) {
  9076. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9077. return 0;
  9078. }
  9079. Client* client = ((Player*)player)->GetClient();
  9080. if (!client) {
  9081. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  9082. return 0;
  9083. }
  9084. if (quest->RemoveQuestStep(step, client)) {
  9085. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  9086. client->GetCurrentZone()->SendQuestUpdates(client);
  9087. }
  9088. else
  9089. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  9090. return 0;
  9091. }
  9092. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  9093. if (!lua_interface)
  9094. return 0;
  9095. Quest* quest = lua_interface->GetQuest(state, 1);
  9096. int32 step = lua_interface->GetInt32Value(state, 2);
  9097. string desc = lua_interface->GetStringValue(state, 3);
  9098. string task_group = lua_interface->GetStringValue(state, 4);
  9099. lua_interface->ResetFunctionStack(state);
  9100. if (!quest) {
  9101. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9102. return 0;
  9103. }
  9104. if (step == 0) {
  9105. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9106. return 0;
  9107. }
  9108. QuestStep* quest_step = quest->GetQuestStep(step);
  9109. if (!quest_step) {
  9110. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  9111. return 0;
  9112. }
  9113. quest_step->SetStepProgress(0);
  9114. quest_step->SetTaskGroup(task_group);
  9115. quest_step->SetDescription(desc);
  9116. return 0;
  9117. }
  9118. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9119. if (!lua_interface)
  9120. return 0;
  9121. Quest* quest = lua_interface->GetQuest(state);
  9122. int32 step = lua_interface->GetInt32Value(state, 2);
  9123. string action = lua_interface->GetStringValue(state, 3);
  9124. lua_interface->ResetFunctionStack(state);
  9125. if (!quest) {
  9126. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9127. return 0;
  9128. }
  9129. if (step == 0) {
  9130. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9131. return 0;
  9132. }
  9133. if (action.length() == 0) {
  9134. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9135. return 0;
  9136. }
  9137. quest->AddFailedAction(step, action);
  9138. return 0;
  9139. }
  9140. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9141. if (!lua_interface)
  9142. return 0;
  9143. Spawn* player = lua_interface->GetSpawn(state);
  9144. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9145. int32 step = lua_interface->GetInt32Value(state, 3);
  9146. lua_interface->ResetFunctionStack(state);
  9147. if (!player) {
  9148. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9149. return 0;
  9150. }
  9151. if (!player->IsPlayer()) {
  9152. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9153. return 0;
  9154. }
  9155. if (quest_id == 0) {
  9156. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9157. return 0;
  9158. }
  9159. if (step == 0) {
  9160. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9161. return 0;
  9162. }
  9163. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9164. if (!quest) {
  9165. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9166. return 0;
  9167. }
  9168. quest->StepFailed(step);
  9169. return 0;
  9170. }
  9171. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9172. if (!lua_interface)
  9173. return 0;
  9174. Spawn* player = lua_interface->GetSpawn(state);
  9175. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9176. lua_interface->ResetFunctionStack(state);
  9177. if (!player) {
  9178. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9179. return 0;
  9180. }
  9181. if (!player->IsPlayer()) {
  9182. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9183. return 0;
  9184. }
  9185. if (quest_id == 0) {
  9186. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9187. return 0;
  9188. }
  9189. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9190. return 1;
  9191. }
  9192. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9193. if (!lua_interface)
  9194. return 0;
  9195. string name = lua_interface->GetStringValue(state);
  9196. string value = lua_interface->GetStringValue(state, 2);
  9197. string comment = lua_interface->GetStringValue(state, 3);
  9198. lua_interface->ResetFunctionStack(state);
  9199. if (name.length() == 0) {
  9200. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9201. return 0;
  9202. }
  9203. if (value.length() == 0) {
  9204. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9205. return 0;
  9206. }
  9207. string varname = string("lua_").append(name);
  9208. Variable* var = variables.FindVariable(varname);
  9209. if (var)
  9210. var->SetValue(value.c_str());
  9211. else {
  9212. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9213. variables.AddVariable(var);
  9214. }
  9215. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9216. return 0;
  9217. }
  9218. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9219. if (!lua_interface)
  9220. return 0;
  9221. string name = lua_interface->GetStringValue(state);
  9222. lua_interface->ResetFunctionStack(state);
  9223. if (name.length() == 0) {
  9224. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9225. return 0;
  9226. }
  9227. string varname = string("lua_").append(name);
  9228. Variable* var = variables.FindVariable(varname);
  9229. if (var)
  9230. lua_interface->SetStringValue(state, var->GetValue());
  9231. else
  9232. lua_interface->SetStringValue(state, "NULL");
  9233. return 1;
  9234. }
  9235. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9236. if (!lua_interface)
  9237. return 0;
  9238. Spawn* player = lua_interface->GetSpawn(state);
  9239. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9240. lua_interface->ResetFunctionStack(state);
  9241. if (!player) {
  9242. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9243. return 0;
  9244. }
  9245. if (!player->IsPlayer()) {
  9246. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9247. return 0;
  9248. }
  9249. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9250. return 1;
  9251. }
  9252. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9253. if (!lua_interface)
  9254. return 0;
  9255. Spawn* player = lua_interface->GetSpawn(state);
  9256. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9257. lua_interface->ResetFunctionStack(state);
  9258. if (!player) {
  9259. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9260. return 0;
  9261. }
  9262. if (!player->IsPlayer()) {
  9263. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9264. return 0;
  9265. }
  9266. Language* language = master_languages_list.GetLanguage(language_id);
  9267. if (language)
  9268. {
  9269. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9270. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9271. }
  9272. return 0;
  9273. }
  9274. int EQ2Emu_lua_IsNight(lua_State* state) {
  9275. if (!lua_interface)
  9276. return 0;
  9277. ZoneServer* zone = lua_interface->GetZone(state);
  9278. lua_interface->ResetFunctionStack(state);
  9279. if (!zone) {
  9280. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9281. return 0;
  9282. }
  9283. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9284. return 1;
  9285. }
  9286. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9287. if (!lua_interface)
  9288. return 0;
  9289. Spawn* spawn = lua_interface->GetSpawn(state);
  9290. lua_interface->ResetFunctionStack(state);
  9291. if (!spawn) {
  9292. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9293. return 0;
  9294. }
  9295. if (!spawn->IsWidget()) {
  9296. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9297. return 0;
  9298. }
  9299. ((Widget*)spawn)->SetMultiFloorLift(true);
  9300. if (spawn->GetZone())
  9301. spawn->GetZone()->AddTransportSpawn(spawn);
  9302. return 0;
  9303. }
  9304. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9305. if (!lua_interface)
  9306. return 0;
  9307. Spawn* player = lua_interface->GetSpawn(state);
  9308. int32 path = lua_interface->GetInt32Value(state, 2);
  9309. lua_interface->ResetFunctionStack(state);
  9310. if (!player) {
  9311. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9312. return 0;
  9313. }
  9314. if (!player->IsPlayer()) {
  9315. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9316. return 0;
  9317. }
  9318. if (path == 0) {
  9319. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9320. return 0;
  9321. }
  9322. Client* client = ((Player*)player)->GetClient();
  9323. if (!client) {
  9324. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9325. return 0;
  9326. }
  9327. client->SendFlightAutoMount(path);
  9328. return 0;
  9329. }
  9330. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9331. if (!lua_interface)
  9332. return 0;
  9333. Spawn* player = lua_interface->GetSpawn(state);
  9334. if (!player) {
  9335. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9336. return 0;
  9337. }
  9338. if (!player->IsPlayer()) {
  9339. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9340. return 0;
  9341. }
  9342. Client* client = ((Player*)player)->GetClient();
  9343. if (!client) {
  9344. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9345. return 0;
  9346. }
  9347. client->EndAutoMount();
  9348. return 0;
  9349. }
  9350. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9351. if (!lua_interface)
  9352. return 0;
  9353. Spawn* player = lua_interface->GetSpawn(state);
  9354. lua_interface->ResetFunctionStack(state);
  9355. if (!player) {
  9356. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9357. return 0;
  9358. }
  9359. if (!player->IsPlayer()) {
  9360. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9361. return 0;
  9362. }
  9363. Client* client = ((Player*)player)->GetClient();
  9364. if (!client) {
  9365. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9366. return 0;
  9367. }
  9368. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9369. return 1;
  9370. }
  9371. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9372. if (!lua_interface)
  9373. return 0;
  9374. Spawn* player = lua_interface->GetSpawn(state);
  9375. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9376. int32 value = lua_interface->GetInt32Value(state, 3);
  9377. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9378. lua_interface->ResetFunctionStack(state);
  9379. if (!player) {
  9380. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9381. return 0;
  9382. }
  9383. if (!player->IsPlayer()) {
  9384. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9385. return 0;
  9386. }
  9387. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9388. return 0;
  9389. }
  9390. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9391. if (!lua_interface)
  9392. return 0;
  9393. Spawn* player = lua_interface->GetSpawn(state);
  9394. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9395. lua_interface->ResetFunctionStack(state);
  9396. if (!player) {
  9397. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9398. return 0;
  9399. }
  9400. if (!player->IsPlayer()) {
  9401. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9402. return 0;
  9403. }
  9404. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9405. if (!hd)
  9406. return 0;
  9407. lua_interface->SetInt32Value(state, hd->Value);
  9408. lua_interface->SetInt32Value(state, hd->Value2);
  9409. return 2;
  9410. }
  9411. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9412. if (!lua_interface)
  9413. return 0;
  9414. Spawn* spawn = lua_interface->GetSpawn(state);
  9415. int32 grid = lua_interface->GetInt32Value(state, 2);
  9416. lua_interface->ResetFunctionStack(state);
  9417. if (!spawn) {
  9418. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9419. return 0;
  9420. }
  9421. if (grid == 0) {
  9422. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9423. return 0;
  9424. }
  9425. spawn->SetLocation(grid);
  9426. return 0;
  9427. }
  9428. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9429. if (!lua_interface)
  9430. return 0;
  9431. Spawn* spawn = lua_interface->GetSpawn(state);
  9432. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9433. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9434. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9435. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9436. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9437. lua_interface->ResetFunctionStack(state);
  9438. if (!spawn) {
  9439. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9440. return 0;
  9441. }
  9442. //Add this quest to the list of required quests for this spawn
  9443. spawn->SetRequiredHistory(event_id, value1, value2);
  9444. //If private spawn value set
  9445. if (private_spawn) {
  9446. //Set the spawn to be private when not granted access via history
  9447. spawn->AddAllowAccessSpawn(spawn);
  9448. spawn->SetPrivateQuestSpawn(true);
  9449. }
  9450. //This value will override vis_flags in the vis packet
  9451. if (flag_override > 0)
  9452. spawn->SetQuestsRequiredOverride(flag_override);
  9453. return 0;
  9454. }
  9455. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9456. if (!lua_interface)
  9457. return 0;
  9458. Spawn* player = lua_interface->GetSpawn(state);
  9459. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9460. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9461. lua_interface->ResetFunctionStack(state);
  9462. if (!player) {
  9463. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9464. return 0;
  9465. }
  9466. if (!player->IsPlayer()) {
  9467. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9468. return 0;
  9469. }
  9470. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9471. return 1;
  9472. }
  9473. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9474. if (!lua_interface)
  9475. return 0;
  9476. Spawn* player = lua_interface->GetSpawn(state);
  9477. int8 level = lua_interface->GetInt8Value(state, 2);
  9478. lua_interface->ResetFunctionStack(state);
  9479. if (!player) {
  9480. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9481. return 0;
  9482. }
  9483. if (!player->IsPlayer()) {
  9484. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9485. return 0;
  9486. }
  9487. if (level == 0) {
  9488. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9489. return 0;
  9490. }
  9491. Client* client = ((Player*)player)->GetClient();
  9492. if (!client) {
  9493. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9494. return 0;
  9495. }
  9496. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9497. return 0;
  9498. }
  9499. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9500. if (!lua_interface)
  9501. return 0;
  9502. Spawn* player = lua_interface->GetSpawn(state);
  9503. int32 amount = lua_interface->GetInt32Value(state, 2);
  9504. lua_interface->ResetFunctionStack(state);
  9505. if (!player) {
  9506. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9507. return 0;
  9508. }
  9509. if (!player->IsPlayer()) {
  9510. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9511. return 0;
  9512. }
  9513. if (amount == 0) {
  9514. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9515. return 0;
  9516. }
  9517. ((Player*)player)->AddCoins(amount);
  9518. return 0;
  9519. }
  9520. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9521. if (!lua_interface)
  9522. return 0;
  9523. Spawn* player = lua_interface->GetSpawn(state);
  9524. int32 amount = lua_interface->GetInt32Value(state, 2);
  9525. lua_interface->ResetFunctionStack(state);
  9526. if (!player) {
  9527. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9528. return 0;
  9529. }
  9530. if (!player->IsPlayer()) {
  9531. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9532. return 0;
  9533. }
  9534. if (amount == 0) {
  9535. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9536. return 0;
  9537. }
  9538. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9539. return 1;
  9540. }
  9541. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9542. if (!lua_interface)
  9543. return 0;
  9544. ZoneServer* zone = lua_interface->GetZone(state);
  9545. lua_interface->ResetFunctionStack(state);
  9546. if (!zone) {
  9547. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9548. return 0;
  9549. }
  9550. vector<Entity*> players = zone->GetPlayers();
  9551. if (players.size() == 0)
  9552. return 0;
  9553. lua_createtable(state, players.size(), 0);
  9554. int newTable = lua_gettop(state);
  9555. for (int32 i = 0; i < players.size(); i++) {
  9556. lua_interface->SetSpawnValue(state, players.at(i));
  9557. lua_rawseti(state, newTable, i + 1);
  9558. }
  9559. return 1;
  9560. }
  9561. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9562. if (!lua_interface)
  9563. return 0;
  9564. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9565. if (!zone) {
  9566. lua_interface->LogError("%s: LUA SpawnGroupByID command error: zone is not valid", lua_interface->GetScriptName(state));
  9567. return 0;
  9568. }
  9569. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9570. int16 custom_level = lua_interface->GetInt32Value(state, 3);
  9571. lua_interface->ResetFunctionStack(state);
  9572. //Map of <placement_id, location_id>
  9573. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9574. map<int32, int32>::iterator itr;
  9575. vector<Spawn*> group;
  9576. Spawn* leader = 0;
  9577. if(locs == nullptr)
  9578. return 0;
  9579. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9580. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9581. if (!location) {
  9582. lua_interface->LogError("%s: LUA SpawnGroupByID command error: no location found for group id %u and the given ID (%u)", lua_interface->GetScriptName(state), group_id, itr->second);
  9583. return 0;
  9584. }
  9585. int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
  9586. Spawn* spawn = 0;
  9587. if (location->entities[rand_number]) {
  9588. if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9589. spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
  9590. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9591. spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
  9592. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9593. spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
  9594. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9595. spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
  9596. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9597. spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
  9598. if(spawn && spawn->IsOmittedByDBFlag())
  9599. {
  9600. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[rand_number]->spawn_id);
  9601. safe_delete(spawn);
  9602. continue;
  9603. }
  9604. if (spawn) {
  9605. if(!leader)
  9606. leader = spawn;
  9607. if(leader)
  9608. leader->AddSpawnToGroup(spawn);
  9609. spawn->SetSpawnGroupID(group_id);
  9610. if(custom_level > 0 && custom_level != 0xFFFF) {
  9611. spawn->SetLevel(custom_level);
  9612. }
  9613. const char* script = 0;
  9614. for (int x = 0; x < 3; x++) {
  9615. switch (x) {
  9616. case 0:
  9617. script = world.GetSpawnEntryScript(location->entities[rand_number]->spawn_entry_id);
  9618. break;
  9619. case 1:
  9620. script = world.GetSpawnLocationScript(location->entities[rand_number]->spawn_location_id);
  9621. break;
  9622. case 2:
  9623. script = world.GetSpawnScript(location->entities[rand_number]->spawn_id);
  9624. break;
  9625. }
  9626. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9627. spawn->SetSpawnScript(string(script));
  9628. break;
  9629. }
  9630. }
  9631. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9632. lua_interface->SetSpawnValue(state, spawn);
  9633. group.push_back(spawn);
  9634. }
  9635. else {
  9636. LogWrite(ZONE__ERROR, 0, "Zone", "%s: Error adding spawn by group id to zone %s with location id %u.", lua_interface->GetScriptName(state), zone->GetZoneName(), group_id);
  9637. safe_delete(spawn);
  9638. }
  9639. }
  9640. }
  9641. if (!group.empty()) {
  9642. lua_createtable(state, group.size(), 0);
  9643. int newTable = lua_gettop(state);
  9644. for (int32 i = 0; i < group.size(); i++) {
  9645. lua_interface->SetSpawnValue(state, group[i]);
  9646. lua_rawseti(state, newTable, i + 1);
  9647. }
  9648. }
  9649. else
  9650. lua_pushnil(state);
  9651. return 1;
  9652. }
  9653. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9654. if (!lua_interface)
  9655. return 0;
  9656. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9657. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9658. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9659. lua_interface->ResetFunctionStack(state);
  9660. if (!spawn) {
  9661. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9662. return 0;
  9663. }
  9664. if (anim_id == 0) {
  9665. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9666. return 0;
  9667. }
  9668. if (leeway == 0)
  9669. leeway = 5000;
  9670. spawn->SetSpawnAnim(anim_id);
  9671. spawn->SetSpawnAnimLeeway(leeway);
  9672. return 0;
  9673. }
  9674. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9675. if (!lua_interface)
  9676. return 0;
  9677. Spawn* player = lua_interface->GetSpawn(state);
  9678. lua_interface->ResetFunctionStack(state);
  9679. if (!player || !player->IsPlayer()) {
  9680. return 0;
  9681. }
  9682. Client* client = ((Player*)player)->GetClient();
  9683. if (!client) {
  9684. return 0;
  9685. }
  9686. lua_interface->SetInt32Value(state, client->GetVersion());
  9687. return 1;
  9688. }
  9689. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9690. if (!lua_interface)
  9691. return 0;
  9692. Item* item = lua_interface->GetItem(state);
  9693. lua_interface->ResetFunctionStack(state);
  9694. if (!item) {
  9695. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9696. return 0;
  9697. }
  9698. lua_interface->SetInt32Value(state, item->details.item_id);
  9699. return 1;
  9700. }
  9701. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9702. if (!lua_interface)
  9703. return 0;
  9704. Spawn* spawn = lua_interface->GetSpawn(state);
  9705. lua_interface->ResetFunctionStack(state);
  9706. if (!spawn) {
  9707. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9708. return 0;
  9709. }
  9710. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9711. return 1;
  9712. }
  9713. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9714. if (!lua_interface)
  9715. return 0;
  9716. Spawn* spawn = lua_interface->GetSpawn(state);
  9717. lua_interface->ResetFunctionStack(state);
  9718. if (!spawn) {
  9719. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9720. return 0;
  9721. }
  9722. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9723. return 1;
  9724. }
  9725. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9726. if (!lua_interface)
  9727. return 0;
  9728. Spawn* spawn = lua_interface->GetSpawn(state);
  9729. lua_interface->ResetFunctionStack(state);
  9730. if (!spawn) {
  9731. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9732. return 0;
  9733. }
  9734. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9735. return 1;
  9736. }
  9737. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9738. if (!lua_interface)
  9739. return 0;
  9740. Spawn* spawn = lua_interface->GetSpawn(state);
  9741. lua_interface->ResetFunctionStack(state);
  9742. if (!spawn) {
  9743. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9744. return 0;
  9745. }
  9746. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9747. return 1;
  9748. }
  9749. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9750. if (!lua_interface)
  9751. return 0;
  9752. Spawn* spawn = lua_interface->GetSpawn(state);
  9753. float pct = lua_interface->GetFloatValue(state, 2);
  9754. lua_interface->ResetFunctionStack(state);
  9755. if (!spawn) {
  9756. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9757. return 0;
  9758. }
  9759. if (pct == 0) {
  9760. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9761. return 0;
  9762. }
  9763. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9764. lua_interface->SetInt32Value(state, amount);
  9765. return 1;
  9766. }
  9767. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9768. if (!lua_interface)
  9769. return 0;
  9770. Spawn* spawn = lua_interface->GetSpawn(state);
  9771. float pct = lua_interface->GetFloatValue(state, 2);
  9772. lua_interface->ResetFunctionStack(state);
  9773. if (!spawn) {
  9774. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9775. return 0;
  9776. }
  9777. if (pct == 0) {
  9778. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9779. return 0;
  9780. }
  9781. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9782. lua_interface->SetInt32Value(state, amount);
  9783. return 1;
  9784. }
  9785. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9786. if (!lua_interface)
  9787. return 0;
  9788. Spawn* spawn = lua_interface->GetSpawn(state);
  9789. lua_interface->ResetFunctionStack(state);
  9790. if (!spawn) {
  9791. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9792. return 0;
  9793. }
  9794. if (!spawn->IsPlayer()) {
  9795. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9796. return 0;
  9797. }
  9798. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9799. return 1;
  9800. }
  9801. int EQ2Emu_lua_Evac(lua_State* state) {
  9802. if (!lua_interface)
  9803. return 0;
  9804. Spawn* target = lua_interface->GetSpawn(state);
  9805. if (target) {
  9806. float x = target->GetZone()->GetSafeX();
  9807. float y = target->GetZone()->GetSafeY();
  9808. float z = target->GetZone()->GetSafeZ();
  9809. float h = target->GetZone()->GetSafeHeading();
  9810. target->SetX(x);
  9811. target->SetY(y);
  9812. target->SetZ(z);
  9813. target->SetHeading(h);
  9814. target->SetSpawnOrigX(x);
  9815. target->SetSpawnOrigY(y);
  9816. target->SetSpawnOrigZ(z);
  9817. target->SetSpawnOrigHeading(h);
  9818. if (target->IsPlayer()) {
  9819. Client* client = ((Player*)target)->GetClient();
  9820. if (client) {
  9821. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9822. int numargs = lua_interface->GetNumberOfArgs(state);
  9823. if(numargs == 4) {
  9824. x = lua_interface->GetFloatValue(state,1);
  9825. y = lua_interface->GetFloatValue(state,2);
  9826. z = lua_interface->GetFloatValue(state,3);
  9827. h = lua_interface->GetFloatValue(state,4);
  9828. }
  9829. client->SetReloadingZone(true);
  9830. target->SetX(x);
  9831. target->SetY(y);
  9832. target->SetZ(z);
  9833. target->SetHeading(h);
  9834. target->SetSpawnOrigX(x);
  9835. target->SetSpawnOrigY(y);
  9836. target->SetSpawnOrigZ(z);
  9837. target->SetSpawnOrigHeading(h);
  9838. target->SetAppearancePosition(x,y,z);
  9839. client->SetZoningCoords(x,y,z,h);
  9840. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9841. if (packet)
  9842. {
  9843. packet->setDataByName("x", x);
  9844. packet->setDataByName("y", y);
  9845. packet->setDataByName("z", z);
  9846. client->QueuePacket(packet->serialize());
  9847. safe_delete(packet);
  9848. }
  9849. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9850. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9851. }
  9852. }
  9853. lua_interface->ResetFunctionStack(state);
  9854. }
  9855. else {
  9856. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9857. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9858. lua_interface->ResetFunctionStack(state);
  9859. return 0;
  9860. }
  9861. ZoneServer* zone = spell->caster->GetZone();
  9862. float x = spell->caster->GetZone()->GetSafeX();
  9863. float y = spell->caster->GetZone()->GetSafeY();
  9864. float z = spell->caster->GetZone()->GetSafeZ();
  9865. float h = spell->caster->GetZone()->GetSafeHeading();
  9866. int numargs = lua_interface->GetNumberOfArgs(state);
  9867. if(numargs == 4) {
  9868. x = lua_interface->GetFloatValue(state,1);
  9869. y = lua_interface->GetFloatValue(state,2);
  9870. z = lua_interface->GetFloatValue(state,3);
  9871. h = lua_interface->GetFloatValue(state,4);
  9872. }
  9873. lua_interface->ResetFunctionStack(state);
  9874. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9875. for (int32 i = 0; i < spell->targets.size(); i++) {
  9876. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9877. if (!target2)
  9878. continue;
  9879. if (target2->IsPlayer()) {
  9880. Client* client = ((Player*)target2)->GetClient();
  9881. if (client) {
  9882. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9883. client->SetReloadingZone(true);
  9884. target2->SetX(x);
  9885. target2->SetY(y);
  9886. target2->SetZ(z);
  9887. target2->SetHeading(h);
  9888. target2->SetSpawnOrigX(x);
  9889. target2->SetSpawnOrigY(y);
  9890. target2->SetSpawnOrigZ(z);
  9891. target2->SetSpawnOrigHeading(h);
  9892. target2->SetAppearancePosition(x,y,z);
  9893. client->SetZoningCoords(x,y,z,h);
  9894. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9895. if (packet)
  9896. {
  9897. packet->setDataByName("x", x);
  9898. packet->setDataByName("y", y);
  9899. packet->setDataByName("z", z);
  9900. client->QueuePacket(packet->serialize());
  9901. safe_delete(packet);
  9902. }
  9903. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9904. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9905. }
  9906. }
  9907. }
  9908. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9909. }
  9910. return 0;
  9911. }
  9912. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9913. if (!lua_interface)
  9914. return 0;
  9915. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9916. lua_interface->ResetFunctionStack(state);
  9917. if (!luaspell || !luaspell->spell) {
  9918. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9919. return 0;
  9920. }
  9921. int8 tier = luaspell->spell->GetSpellTier();
  9922. lua_interface->SetInt32Value(state, tier);
  9923. return 1;
  9924. }
  9925. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9926. if (!lua_interface)
  9927. return 0;
  9928. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9929. lua_interface->ResetFunctionStack(state);
  9930. if (!luaspell || !luaspell->spell) {
  9931. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9932. return 0;
  9933. }
  9934. int32 spell_id = luaspell->spell->GetSpellID();
  9935. lua_interface->SetInt32Value(state, spell_id);
  9936. return 1;
  9937. }
  9938. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9939. if (!lua_interface)
  9940. return 0;
  9941. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9942. lua_interface->ResetFunctionStack(state);
  9943. if (!spawn) {
  9944. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9945. return 0;
  9946. }
  9947. if (!spawn->IsPlayer()) {
  9948. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9949. return 0;
  9950. }
  9951. ZoneServer* zone = spawn->GetZone();
  9952. if (!zone) {
  9953. return 0;
  9954. }
  9955. Client* client = ((Player*)spawn)->GetClient();
  9956. if (!client) {
  9957. return 0;
  9958. }
  9959. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9960. return 0;
  9961. }
  9962. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9963. if (!lua_interface)
  9964. return 0;
  9965. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9966. lua_interface->ResetFunctionStack(state);
  9967. if (!spawn) {
  9968. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9969. return 0;
  9970. }
  9971. if (!spawn->IsPlayer()) {
  9972. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9973. return 0;
  9974. }
  9975. ZoneServer* zone = spawn->GetZone();
  9976. if (!zone) {
  9977. return 0;
  9978. }
  9979. Client* client = ((Player*)spawn)->GetClient();
  9980. if (!client) {
  9981. return 0;
  9982. }
  9983. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9984. return 0;
  9985. }
  9986. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9987. if (!lua_interface)
  9988. return 0;
  9989. Spawn* caster = lua_interface->GetSpawn(state);
  9990. Spawn* target = lua_interface->GetSpawn(state, 2);
  9991. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9992. string spell_name = lua_interface->GetStringValue(state, 4);
  9993. lua_interface->ResetFunctionStack(state);
  9994. if (!caster) {
  9995. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9996. return 0;
  9997. }
  9998. if (!caster->IsEntity()) {
  9999. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  10000. return 0;
  10001. }
  10002. if (!target) {
  10003. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10004. return 0;
  10005. }
  10006. if (!target->IsEntity()) {
  10007. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  10008. return 0;
  10009. }
  10010. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  10011. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  10012. return 0;
  10013. }
  10014. int EQ2Emu_lua_GiveExp(lua_State* state) {
  10015. if (!lua_interface)
  10016. return 0;
  10017. Spawn* player = lua_interface->GetSpawn(state);
  10018. int32 amount = lua_interface->GetInt32Value(state, 2);
  10019. lua_interface->ResetFunctionStack(state);
  10020. if (player && player->IsPlayer() && amount > 0) {
  10021. ((Player*)player)->AddXP(amount);
  10022. }
  10023. return 0;
  10024. }
  10025. int EQ2Emu_lua_DisplayText(lua_State* state) {
  10026. if (!lua_interface)
  10027. return 0;
  10028. Spawn* player = lua_interface->GetSpawn(state);
  10029. int8 type = lua_interface->GetInt8Value(state, 2);
  10030. string text = lua_interface->GetStringValue(state, 3);
  10031. lua_interface->ResetFunctionStack(state);
  10032. Client* client = 0;
  10033. if (player && player->IsPlayer())
  10034. client = ((Player*)player)->GetClient();
  10035. if (!client || text.length() == 0) {
  10036. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  10037. return 0;
  10038. }
  10039. client->SimpleMessage(type, text.c_str());
  10040. return 0;
  10041. }
  10042. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  10043. if (!lua_interface)
  10044. return 0;
  10045. Spawn* player = lua_interface->GetSpawn(state);
  10046. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10047. lua_interface->ResetFunctionStack(state);
  10048. Client* client = 0;
  10049. if (player && player->IsPlayer())
  10050. client = ((Player*)player)->GetClient();
  10051. if (!client || !spawn) {
  10052. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  10053. return 0;
  10054. }
  10055. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  10056. if (!items) {
  10057. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  10058. return 0;
  10059. }
  10060. client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
  10061. return 0;
  10062. }
  10063. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  10064. if (!lua_interface)
  10065. return 0;
  10066. Spawn* spawnref = lua_interface->GetSpawn(state);
  10067. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10068. lua_interface->ResetFunctionStack(state);
  10069. if (spawn_id > 0 && spawnref) {
  10070. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  10071. if (spawns.size() == 0) {
  10072. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10073. return 0;
  10074. }
  10075. Spawn* spawn = 0;
  10076. int16 index = MakeRandomInt(0, spawns.size());
  10077. if (index >= spawns.size() || index < 0)
  10078. index = 0;
  10079. spawn = spawns[index];
  10080. lua_interface->SetSpawnValue(state, spawn);
  10081. return 1;
  10082. }
  10083. else {
  10084. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  10085. }
  10086. return 0;
  10087. }
  10088. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  10089. Spawn* player = lua_interface->GetSpawn(state);
  10090. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10091. string name = lua_interface->GetStringValue(state, 3);
  10092. float distance = lua_interface->GetFloatValue(state, 4);
  10093. string command = lua_interface->GetStringValue(state, 5);
  10094. string error_text = lua_interface->GetStringValue(state, 6);
  10095. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  10096. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  10097. lua_interface->ResetFunctionStack(state);
  10098. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  10099. if (distance == 0)
  10100. distance = 10.0f;
  10101. if (command.length() == 0)
  10102. command = name;
  10103. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  10104. if (spawns.size() == 0) {
  10105. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10106. return 0;
  10107. }
  10108. Spawn* spawn = 0;
  10109. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  10110. spawn = *itr;
  10111. if (spawn) {
  10112. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  10113. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  10114. }
  10115. }
  10116. }
  10117. return 0;
  10118. }
  10119. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  10120. if (!lua_interface)
  10121. return 0;
  10122. Client* client = 0;
  10123. Spawn* player = lua_interface->GetSpawn(state);
  10124. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10125. lua_interface->ResetFunctionStack(state);
  10126. if (player && player->IsPlayer() && player->GetZone())
  10127. client = ((Player*)player)->GetClient();
  10128. else{
  10129. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10130. return 0;
  10131. }
  10132. if (client) {
  10133. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10134. if (packet) {
  10135. packet->setDataByName("goal_num", goal_num);
  10136. client->QueuePacket(packet->serialize());
  10137. safe_delete(packet);
  10138. }
  10139. }
  10140. return 0;
  10141. }
  10142. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10143. if (!lua_interface)
  10144. return 0;
  10145. Client* client = 0;
  10146. Spawn* player = lua_interface->GetSpawn(state);
  10147. lua_interface->ResetFunctionStack(state);
  10148. if (player && player->IsPlayer() && player->GetZone())
  10149. client = ((Player*)player)->GetClient();
  10150. else {
  10151. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10152. return 0;
  10153. }
  10154. if (client && client->GetVersion() >= 374) {
  10155. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10156. }
  10157. return 0;
  10158. }
  10159. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10160. if (!lua_interface)
  10161. return 0;
  10162. Client* client = 0;
  10163. Spawn* player = lua_interface->GetSpawn(state);
  10164. float duration = lua_interface->GetFloatValue(state, 2);
  10165. string text = lua_interface->GetStringValue(state, 3);
  10166. string voice = lua_interface->GetStringValue(state, 4);
  10167. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10168. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10169. string signal = lua_interface->GetStringValue(state, 7);
  10170. string goal1 = lua_interface->GetStringValue(state, 8);
  10171. string task1 = lua_interface->GetStringValue(state, 9);
  10172. string goal2 = lua_interface->GetStringValue(state, 10);
  10173. string task2 = lua_interface->GetStringValue(state, 11);
  10174. string goal3 = lua_interface->GetStringValue(state, 12);
  10175. string task3 = lua_interface->GetStringValue(state, 13);
  10176. string goal4 = lua_interface->GetStringValue(state, 14);
  10177. string task4 = lua_interface->GetStringValue(state, 15);
  10178. lua_interface->ResetFunctionStack(state);
  10179. if (!player) {
  10180. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10181. return 0;
  10182. }
  10183. if (!player->IsPlayer()) {
  10184. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10185. return 0;
  10186. }
  10187. else
  10188. client = ((Player*)player)->GetClient();
  10189. if (!client) {
  10190. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10191. return 0;
  10192. }
  10193. if (text.length() == 0) {
  10194. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10195. return 0;
  10196. }
  10197. if (duration >= 0 && duration < 2)
  10198. duration = 2;
  10199. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10200. if (packet) {
  10201. packet->setDataByName("open_seconds_max", duration);
  10202. packet->setDataByName("text", text.c_str());
  10203. packet->setDataByName("voice", voice.c_str());
  10204. int8 num_goals = 1;
  10205. if (task2.length() > 0)
  10206. num_goals++;
  10207. if (task3.length() > 0)
  10208. num_goals++;
  10209. if (task4.length() > 0)
  10210. num_goals++;
  10211. packet->setArrayLengthByName("num_goals", num_goals);
  10212. for (int8 i = 0; i < num_goals; i++) {
  10213. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10214. }
  10215. if (goal1.length() > 0)
  10216. packet->setArrayDataByName("goal_text", goal1.c_str());
  10217. if (goal2.length() > 0)
  10218. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10219. if (goal3.length() > 0)
  10220. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10221. if (goal4.length() > 0)
  10222. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10223. packet->setSubArrayDataByName("task_text", task1.c_str());
  10224. if (task2.length() > 0)
  10225. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10226. if (task3.length() > 0)
  10227. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10228. if (task4.length() > 0)
  10229. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10230. packet->setDataByName("complete_sound", "click");
  10231. packet->setDataByName("signal", signal.c_str());
  10232. packet->setDataByName("voice_key1", voice_key1);
  10233. packet->setDataByName("voice_key2", voice_key2);
  10234. client->QueuePacket(packet->serialize());
  10235. safe_delete(packet);
  10236. }
  10237. return 0;
  10238. }
  10239. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10240. if (!lua_interface)
  10241. return 0;
  10242. Client* client = 0;
  10243. Spawn* player = lua_interface->GetSpawn(state);
  10244. string window = lua_interface->GetStringValue(state, 2);
  10245. int8 show = lua_interface->GetInt8Value(state, 3);
  10246. lua_interface->ResetFunctionStack(state);
  10247. if (!player) {
  10248. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10249. return 0;
  10250. }
  10251. if (!player->IsPlayer()) {
  10252. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10253. return 0;
  10254. }
  10255. else
  10256. client = ((Player*)player)->GetClient();
  10257. if (!client) {
  10258. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10259. return 0;
  10260. }
  10261. if (window.length() == 0) {
  10262. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10263. return 0;
  10264. }
  10265. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10266. if (packet) {
  10267. packet->setDataByName("window", window.c_str());
  10268. packet->setDataByName("show", show);
  10269. client->QueuePacket(packet->serialize());
  10270. safe_delete(packet);
  10271. }
  10272. return 0;
  10273. }
  10274. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10275. //See GameEvents.txt for options that can be used for this function
  10276. if (!lua_interface)
  10277. return 0;
  10278. Client* client = 0;
  10279. Spawn* player = lua_interface->GetSpawn(state);
  10280. string event_name = lua_interface->GetStringValue(state, 2);
  10281. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10282. lua_interface->ResetFunctionStack(state);
  10283. if (!player || !player->IsPlayer()) {
  10284. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10285. return 0;
  10286. }
  10287. client = ((Player*)player)->GetClient();
  10288. if (!client) {
  10289. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10290. return 0;
  10291. }
  10292. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10293. if (packet) {
  10294. packet->setDataByName("event_name", event_name.c_str());
  10295. packet->setDataByName("enabled", enabled);
  10296. client->QueuePacket(packet->serialize());
  10297. safe_delete(packet);
  10298. }
  10299. return 0;
  10300. }
  10301. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10302. if (!lua_interface)
  10303. return 0;
  10304. Spawn* player = lua_interface->GetSpawn(state);
  10305. lua_interface->ResetFunctionStack(state);
  10306. if (player && player->IsPlayer()) {
  10307. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10308. return 1;
  10309. }
  10310. return 0;
  10311. }
  10312. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10313. if (!lua_interface)
  10314. return 0;
  10315. Spawn* player = lua_interface->GetSpawn(state);
  10316. int8 step = lua_interface->GetInt8Value(state, 2);
  10317. lua_interface->ResetFunctionStack(state);
  10318. if (player && player->IsPlayer() && step > 0) {
  10319. ((Player*)player)->SetTutorialStep(step);
  10320. }
  10321. return 0;
  10322. }
  10323. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10324. if (!lua_interface)
  10325. return 0;
  10326. Client* client = 0;
  10327. Spawn* player = lua_interface->GetSpawn(state);
  10328. string window = lua_interface->GetStringValue(state, 2);
  10329. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10330. lua_interface->ResetFunctionStack(state);
  10331. if (!player) {
  10332. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10333. return 0;
  10334. }
  10335. if (!player->IsPlayer()) {
  10336. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10337. return 0;
  10338. }
  10339. else
  10340. client = ((Player*)player)->GetClient();
  10341. if (!client) {
  10342. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10343. return 0;
  10344. }
  10345. if (window.length() == 0) {
  10346. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10347. return 0;
  10348. }
  10349. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10350. if (packet) {
  10351. packet->setDataByName("window", window.c_str());
  10352. packet->setDataByName("flash_seconds", flash_seconds);
  10353. client->QueuePacket(packet->serialize());
  10354. safe_delete(packet);
  10355. }
  10356. return 0;
  10357. }
  10358. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10359. if (!lua_interface)
  10360. return 0;
  10361. Spawn* spawn = lua_interface->GetSpawn(state);
  10362. Spawn* target = lua_interface->GetSpawn(state, 2);
  10363. lua_interface->ResetFunctionStack(state);
  10364. if (spawn && target)
  10365. return spawn->CheckLoS(target);
  10366. return 0;
  10367. }
  10368. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10369. if (!lua_interface)
  10370. return 0;
  10371. Spawn* spawn = lua_interface->GetSpawn(state);
  10372. float x = lua_interface->GetFloatValue(state, 2);
  10373. float y = lua_interface->GetFloatValue(state, 3);
  10374. float z = lua_interface->GetFloatValue(state, 4);
  10375. lua_interface->ResetFunctionStack(state);
  10376. if (spawn)
  10377. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10378. return 0;
  10379. }
  10380. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10381. if (!lua_interface)
  10382. return 0;
  10383. ZoneServer* zone = lua_interface->GetZone(state);
  10384. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10385. lua_interface->ResetFunctionStack(state);
  10386. if (zone)
  10387. zone->SetExpansionFlag(xpackFlag);
  10388. return 0;
  10389. }
  10390. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10391. if (!lua_interface)
  10392. return 0;
  10393. ZoneServer* zone = lua_interface->GetZone(state);
  10394. lua_interface->ResetFunctionStack(state);
  10395. if (zone) {
  10396. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10397. return 1;
  10398. }
  10399. return 0;
  10400. }
  10401. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10402. if (!lua_interface)
  10403. return 0;
  10404. ZoneServer* zone = lua_interface->GetZone(state);
  10405. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10406. lua_interface->ResetFunctionStack(state);
  10407. if (zone)
  10408. zone->SetHolidayFlag(holidayFlag);
  10409. return 0;
  10410. }
  10411. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10412. if (!lua_interface)
  10413. return 0;
  10414. ZoneServer* zone = lua_interface->GetZone(state);
  10415. lua_interface->ResetFunctionStack(state);
  10416. if (zone) {
  10417. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10418. return 1;
  10419. }
  10420. return 0;
  10421. }
  10422. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10423. if (!lua_interface)
  10424. return 0;
  10425. Spawn* spawn = lua_interface->GetSpawn(state);
  10426. bool canbind = lua_interface->GetInt32Value(state, 2);
  10427. lua_interface->ResetFunctionStack(state);
  10428. if(!spawn) {
  10429. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10430. return 0;
  10431. }
  10432. ZoneServer* zone = spawn->GetZone();
  10433. if (zone)
  10434. zone->SetCanBind(canbind);
  10435. return 0;
  10436. }
  10437. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10438. if (!lua_interface)
  10439. return 0;
  10440. Spawn* spawn = lua_interface->GetSpawn(state);
  10441. lua_interface->ResetFunctionStack(state);
  10442. if(!spawn) {
  10443. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10444. return 0;
  10445. }
  10446. ZoneServer* zone = spawn->GetZone();
  10447. if (zone) {
  10448. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10449. return 1;
  10450. }
  10451. return 0;
  10452. }
  10453. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10454. if (!lua_interface)
  10455. return 0;
  10456. Spawn* spawn = lua_interface->GetSpawn(state);
  10457. bool cangate = lua_interface->GetInt32Value(state, 2);
  10458. lua_interface->ResetFunctionStack(state);
  10459. if(!spawn) {
  10460. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10461. return 0;
  10462. }
  10463. ZoneServer* zone = spawn->GetZone();
  10464. if (zone)
  10465. zone->SetCanGate(cangate);
  10466. return 0;
  10467. }
  10468. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10469. if (!lua_interface)
  10470. return 0;
  10471. Spawn* spawn = lua_interface->GetSpawn(state);
  10472. lua_interface->ResetFunctionStack(state);
  10473. if(!spawn) {
  10474. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10475. return 0;
  10476. }
  10477. ZoneServer* zone = spawn->GetZone();
  10478. if (zone) {
  10479. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10480. return 1;
  10481. }
  10482. return 0;
  10483. }
  10484. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10485. if (!lua_interface)
  10486. return 0;
  10487. Spawn* spawn = lua_interface->GetSpawn(state);
  10488. bool canevac = lua_interface->GetInt32Value(state, 2);
  10489. lua_interface->ResetFunctionStack(state);
  10490. if(!spawn) {
  10491. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10492. return 0;
  10493. }
  10494. ZoneServer* zone = spawn->GetZone();
  10495. if (zone)
  10496. zone->SetCanEvac(canevac);
  10497. return 0;
  10498. }
  10499. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10500. if (!lua_interface)
  10501. return 0;
  10502. Spawn* spawn = lua_interface->GetSpawn(state);
  10503. lua_interface->ResetFunctionStack(state);
  10504. if(!spawn) {
  10505. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10506. return 0;
  10507. }
  10508. ZoneServer* zone = spawn->GetZone();
  10509. if (zone) {
  10510. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10511. return 1;
  10512. }
  10513. return 0;
  10514. }
  10515. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10516. if (!lua_interface)
  10517. return 0;
  10518. Spawn* spawn = lua_interface->GetSpawn(state);
  10519. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10520. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10521. float distance = lua_interface->GetFloatValue(state, 4);
  10522. string in_range_function = lua_interface->GetStringValue(state, 5);
  10523. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10524. lua_interface->ResetFunctionStack(state);
  10525. if (spawn && distance > 0 && in_range_function.length() > 0)
  10526. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10527. return 0;
  10528. }
  10529. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10530. if (!lua_interface)
  10531. return 0;
  10532. Spawn* spawn = lua_interface->GetSpawn(state);
  10533. Spawn* target = lua_interface->GetSpawn(state, 2);
  10534. lua_interface->ResetFunctionStack(state);
  10535. if (spawn && target)
  10536. {
  10537. if (spawn->IsPlayer() && target->IsEntity())
  10538. {
  10539. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10540. return 1;
  10541. }
  10542. else if (spawn->IsEntity() && target->IsEntity())
  10543. {
  10544. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10545. return 1;
  10546. }
  10547. }
  10548. return 0;
  10549. }
  10550. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10551. if (!lua_interface)
  10552. return 0;
  10553. Spawn* spawn = lua_interface->GetSpawn(state);
  10554. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10555. lua_interface->ResetFunctionStack(state);
  10556. if (spawn && spawn->IsEntity())
  10557. {
  10558. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10559. if (spawn->IsPlayer())
  10560. {
  10561. Client* client = ((Player*)spawn)->GetClient();
  10562. if (client)
  10563. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10564. }
  10565. }
  10566. return 0;
  10567. }
  10568. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10569. if (!lua_interface)
  10570. return 0;
  10571. Spawn* spawn = lua_interface->GetSpawn(state);
  10572. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10573. lua_interface->ResetFunctionStack(state);
  10574. if (spawn && spawn->IsEntity())
  10575. {
  10576. ((Entity*)spawn)->SetSeeHideSpell(val);
  10577. if (spawn->IsPlayer())
  10578. {
  10579. Client* client = ((Player*)spawn)->GetClient();
  10580. if (client)
  10581. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10582. }
  10583. }
  10584. return 0;
  10585. }
  10586. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10587. {
  10588. if (!lua_interface)
  10589. return 0;
  10590. Spawn* player = lua_interface->GetSpawn(state);
  10591. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10592. string command = lua_interface->GetStringValue(state, 3);
  10593. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10594. lua_interface->ResetFunctionStack(state);
  10595. if (spawn && player && player->IsPlayer())
  10596. {
  10597. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10598. bool res = false;
  10599. if (cmd)
  10600. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10601. lua_interface->SetBooleanValue(state, res);
  10602. return 1;
  10603. }
  10604. return 0;
  10605. }
  10606. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10607. {
  10608. if (!lua_interface)
  10609. return 0;
  10610. Spawn* spawn = lua_interface->GetSpawn(state);
  10611. int32 charID = lua_interface->GetInt32Value(state, 2);
  10612. string command = lua_interface->GetStringValue(state, 3);
  10613. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10614. lua_interface->ResetFunctionStack(state);
  10615. if (spawn && charID)
  10616. {
  10617. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10618. bool res = false;
  10619. if (cmd)
  10620. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10621. lua_interface->SetBooleanValue(state, res);
  10622. return 1;
  10623. }
  10624. return 0;
  10625. }
  10626. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10627. {
  10628. if (!lua_interface)
  10629. return 0;
  10630. Spawn* spawn = lua_interface->GetSpawn(state);
  10631. string command = lua_interface->GetStringValue(state, 2);
  10632. lua_interface->ResetFunctionStack(state);
  10633. if (spawn && command.length() > 0)
  10634. spawn->RemovePrimaryEntityCommand(command.c_str());
  10635. return 0;
  10636. }
  10637. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10638. if (!lua_interface)
  10639. return 0;
  10640. Spawn* spawn = lua_interface->GetSpawn(state);
  10641. float distance = lua_interface->GetFloatValue(state, 2);
  10642. string command = lua_interface->GetStringValue(state, 3);
  10643. Spawn* player = lua_interface->GetSpawn(state, 4);
  10644. lua_interface->ResetFunctionStack(state);
  10645. if (spawn) {
  10646. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10647. }
  10648. return 0;
  10649. }
  10650. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10651. if (!lua_interface)
  10652. return 0;
  10653. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10654. Spawn* spawn = lua_interface->GetSpawn(state);
  10655. Spawn* player = lua_interface->GetSpawn(state, 2);
  10656. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10657. lua_interface->ResetFunctionStack(state);
  10658. if (spawn && player && transport_id && player->IsPlayer()) {
  10659. Client* client = 0;
  10660. if (player && player->IsPlayer())
  10661. client = ((Player*)player)->GetClient();
  10662. if (!client)
  10663. return 0;
  10664. vector<TransportDestination*> destinations;
  10665. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10666. if (destinations.size())
  10667. {
  10668. client->SetTemporaryTransportID(transport_id);
  10669. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10670. }
  10671. else
  10672. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10673. }
  10674. return 0;
  10675. }
  10676. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10677. if (!lua_interface)
  10678. return 0;
  10679. Spawn* player = lua_interface->GetSpawn(state);
  10680. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10681. lua_interface->ResetFunctionStack(state);
  10682. if (player && player->IsPlayer()) {
  10683. Client* client = 0;
  10684. if (player && player->IsPlayer())
  10685. client = ((Player*)player)->GetClient();
  10686. if (!client)
  10687. return 0;
  10688. client->SetTemporaryTransportID(transport_id);
  10689. }
  10690. return 0;
  10691. }
  10692. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10693. if (!lua_interface)
  10694. return 0;
  10695. Spawn* player = lua_interface->GetSpawn(state);
  10696. lua_interface->ResetFunctionStack(state);
  10697. if (player && player->IsPlayer()) {
  10698. Client* client = 0;
  10699. if (player && player->IsPlayer())
  10700. client = ((Player*)player)->GetClient();
  10701. if (!client)
  10702. return 0;
  10703. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10704. return 1;
  10705. }
  10706. return 0;
  10707. }
  10708. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10709. if (!lua_interface)
  10710. return 0;
  10711. Spawn* spawn = lua_interface->GetSpawn(state);
  10712. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10713. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10714. if (!spawn) {
  10715. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10716. return 0;
  10717. }
  10718. if (!spawn->IsEntity()) {
  10719. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10720. return 0;
  10721. }
  10722. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10723. {
  10724. lua_interface->LogError("%s: LUA SetAlignment command error: alignment value beyond supported min: %i and max: %i", lua_interface->GetScriptName(state), SCHAR_MIN, SCHAR_MAX);
  10725. return 0;
  10726. }
  10727. lua_interface->ResetFunctionStack(state);
  10728. if (spell && spell->targets.size() > 0) {
  10729. ZoneServer* zone = spell->caster->GetZone();
  10730. for (int8 i = 0; i < spell->targets.size(); i++) {
  10731. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10732. if (target && target->IsEntity()) {
  10733. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10734. if (target->IsPlayer())
  10735. ((Player*)target)->SetCharSheetChanged(true);
  10736. }
  10737. }
  10738. }
  10739. else {
  10740. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10741. if (spawn->IsPlayer())
  10742. ((Player*)spawn)->SetCharSheetChanged(true);
  10743. }
  10744. return 0;
  10745. }
  10746. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10747. if (!lua_interface)
  10748. return 0;
  10749. Spawn* spawn = lua_interface->GetSpawn(state);
  10750. lua_interface->ResetFunctionStack(state);
  10751. if (!spawn) {
  10752. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10753. return 0;
  10754. }
  10755. if (!spawn->IsEntity()) {
  10756. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10757. return 0;
  10758. }
  10759. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10760. return 1;
  10761. }
  10762. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10763. if (!lua_interface)
  10764. return 0;
  10765. int32 spell_id = lua_interface->GetInt32Value(state);
  10766. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10767. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10768. if (spell_id > 0) {
  10769. if (spell_tier == 0)
  10770. spell_tier = 1;
  10771. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10772. if(!spell) {
  10773. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10774. lua_interface->ResetFunctionStack(state);
  10775. return 0;
  10776. }
  10777. LuaSpell* lua_spell = 0;
  10778. if(custom_lua_script.size() > 0)
  10779. {
  10780. // attempt to load the custom script since it isn't already loaded
  10781. // we will re-obtain the lua_spell further below
  10782. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10783. {
  10784. LogWrite(LUA__WARNING, 0, "LUA", "GetSpell(%u, %u, '%s'), custom lua script not loaded, attempting to load.", spell_id, spell_tier, custom_lua_script.c_str());
  10785. }
  10786. }
  10787. else
  10788. custom_lua_script = spell->GetSpellData()->lua_script;
  10789. if (!lua_spell && lua_interface)
  10790. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10791. lua_interface->ResetFunctionStack(state);
  10792. if (!lua_spell)
  10793. {
  10794. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10795. return 0;
  10796. }
  10797. lua_spell->spell = new Spell(spell);
  10798. lua_interface->AddCustomSpell(lua_spell);
  10799. lua_interface->SetSpellValue(state, lua_spell);
  10800. return 1;
  10801. }
  10802. return 0;
  10803. }
  10804. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10805. if (!lua_interface)
  10806. return 0;
  10807. LuaSpell* spell = lua_interface->GetSpell(state);
  10808. string field = lua_interface->GetStringValue(state, 2);
  10809. lua_interface->ResetFunctionStack(state);
  10810. if (!spell) {
  10811. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10812. return 0;
  10813. }
  10814. if (!spell->spell || !spell->spell->GetSpellData()) {
  10815. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10816. return 0;
  10817. }
  10818. boost::to_lower(field);
  10819. return spell->spell->GetSpellData(state, field);
  10820. }
  10821. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10822. if (!lua_interface)
  10823. return 0;
  10824. LuaSpell* spell = lua_interface->GetSpell(state);
  10825. string field = lua_interface->GetStringValue(state, 2);
  10826. int8 fieldArg = 3; // field value after the initial set
  10827. if (!spell) {
  10828. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10829. lua_interface->ResetFunctionStack(state);
  10830. return 0;
  10831. }
  10832. if (!spell->spell || !spell->spell->GetSpellData()) {
  10833. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10834. lua_interface->ResetFunctionStack(state);
  10835. return 0;
  10836. }
  10837. boost::to_lower(field);
  10838. bool valSet = false;
  10839. spell->spell->SetSpellData(state, field, fieldArg);
  10840. lua_interface->ResetFunctionStack(state);
  10841. return valSet;
  10842. }
  10843. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10844. if (!lua_interface)
  10845. return 0;
  10846. LuaSpell* spell = lua_interface->GetSpell(state);
  10847. int8 idx = lua_interface->GetInt32Value(state, 2);
  10848. if (!spell) {
  10849. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10850. lua_interface->ResetFunctionStack(state);
  10851. return 0;
  10852. }
  10853. if (!spell->spell || !spell->spell->GetSpellData()) {
  10854. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10855. lua_interface->ResetFunctionStack(state);
  10856. return 0;
  10857. }
  10858. if (spell->spell->lua_data.size() <= idx)
  10859. {
  10860. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10861. lua_interface->ResetFunctionStack(state);
  10862. return 0;
  10863. }
  10864. bool setVal = true;
  10865. LUAData* data = spell->spell->lua_data[idx];
  10866. switch (data->type)
  10867. {
  10868. case 0:
  10869. {
  10870. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10871. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10872. data->int_value = value;
  10873. data->int_value2 = value2;
  10874. break;
  10875. }
  10876. case 1:
  10877. {
  10878. float value = lua_interface->GetFloatValue(state, 3);
  10879. float value2 = lua_interface->GetFloatValue(state, 4);
  10880. data->float_value = value;
  10881. data->float_value2 = value2;
  10882. break;
  10883. }
  10884. case 2:
  10885. {
  10886. bool value = lua_interface->GetBooleanValue(state, 3);
  10887. data->bool_value = value;
  10888. break;
  10889. }
  10890. case 3:
  10891. {
  10892. string value = lua_interface->GetStringValue(state, 3);
  10893. string value2 = lua_interface->GetStringValue(state, 4);
  10894. data->string_value = value;
  10895. data->string_value2 = value2;
  10896. break;
  10897. }
  10898. default:
  10899. setVal = false;
  10900. }
  10901. lua_interface->ResetFunctionStack(state);
  10902. return setVal;
  10903. }
  10904. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10905. if (!lua_interface)
  10906. return 0;
  10907. LuaSpell* spell = lua_interface->GetSpell(state);
  10908. int8 idx = lua_interface->GetInt32Value(state, 2);
  10909. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10910. lua_interface->ResetFunctionStack(state);
  10911. if (!spell) {
  10912. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10913. return 0;
  10914. }
  10915. if (!spell->spell || !spell->spell->GetSpellData()) {
  10916. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10917. return 0;
  10918. }
  10919. if (spell->spell->lua_data.size() <= idx)
  10920. {
  10921. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10922. return 0;
  10923. }
  10924. bool setVal = true;
  10925. LUAData* data = spell->spell->lua_data[idx];
  10926. switch (data->type)
  10927. {
  10928. case 0:
  10929. {
  10930. if(!secondfield)
  10931. lua_interface->SetSInt32Value(state, data->int_value);
  10932. else
  10933. lua_interface->SetSInt32Value(state, data->int_value2);
  10934. break;
  10935. }
  10936. case 1:
  10937. {
  10938. if (!secondfield)
  10939. lua_interface->SetFloatValue(state, data->float_value);
  10940. else
  10941. lua_interface->SetFloatValue(state, data->float_value2);
  10942. break;
  10943. }
  10944. case 2:
  10945. {
  10946. lua_interface->SetBooleanValue(state, data->bool_value);
  10947. break;
  10948. }
  10949. case 3:
  10950. {
  10951. if (!secondfield)
  10952. lua_interface->SetStringValue(state, data->string_value.c_str());
  10953. else
  10954. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10955. break;
  10956. }
  10957. default:
  10958. setVal = false;
  10959. }
  10960. return setVal;
  10961. }
  10962. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10963. if (!lua_interface)
  10964. return 0;
  10965. LuaSpell* spell = lua_interface->GetSpell(state);
  10966. int8 idx = lua_interface->GetInt32Value(state, 2);
  10967. string field = lua_interface->GetStringValue(state, 3);
  10968. boost::to_lower(field);
  10969. if (!spell) {
  10970. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10971. lua_interface->ResetFunctionStack(state);
  10972. return 0;
  10973. }
  10974. if (!spell->spell || !spell->spell->GetSpellData()) {
  10975. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10976. lua_interface->ResetFunctionStack(state);
  10977. return 0;
  10978. }
  10979. if (spell->spell->effects.size() <= idx)
  10980. {
  10981. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10982. lua_interface->ResetFunctionStack(state);
  10983. return 0;
  10984. }
  10985. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10986. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10987. if (field == "description")
  10988. effect->description = string(lua_interface->GetStringValue(state, 4));
  10989. else if (field == "bullet")
  10990. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10991. else if (field == "percentage")
  10992. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10993. else { // no match
  10994. lua_interface->ResetFunctionStack(state);
  10995. return 0;
  10996. }
  10997. lua_interface->ResetFunctionStack(state);
  10998. return 1;
  10999. }
  11000. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  11001. if (!lua_interface)
  11002. return 0;
  11003. LuaSpell* spell = lua_interface->GetSpell(state);
  11004. int8 idx = lua_interface->GetInt32Value(state, 2);
  11005. string field = lua_interface->GetStringValue(state, 3);
  11006. lua_interface->ResetFunctionStack(state);
  11007. boost::to_lower(field);
  11008. if (!spell) {
  11009. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  11010. return 0;
  11011. }
  11012. if (!spell->spell || !spell->spell->GetSpellData()) {
  11013. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  11014. return 0;
  11015. }
  11016. if (spell->spell->effects.size() <= idx)
  11017. {
  11018. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  11019. return 0;
  11020. }
  11021. // do we need to lock? eh probably not this should only be used before use of the custom spell
  11022. SpellDisplayEffect* effect = spell->spell->effects[idx];
  11023. if (field == "description")
  11024. lua_interface->SetStringValue(state, effect->description.c_str());
  11025. else if (field == "bullet")
  11026. lua_interface->SetInt32Value(state, effect->subbullet);
  11027. else if (field == "percentage")
  11028. lua_interface->SetInt32Value(state, effect->percentage);
  11029. else // no match
  11030. return 0;
  11031. return 1;
  11032. }
  11033. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  11034. if (!lua_interface)
  11035. return 0;
  11036. LuaSpell* spell = lua_interface->GetSpell(state);
  11037. Spawn* caster = lua_interface->GetSpawn(state, 2);
  11038. Spawn* target = lua_interface->GetSpawn(state, 3);
  11039. lua_interface->ResetFunctionStack(state);
  11040. if (!target) {
  11041. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  11042. return 0;
  11043. }
  11044. if (!target->IsEntity()) {
  11045. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  11046. return 0;
  11047. }
  11048. if (!spell) {
  11049. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  11050. return 0;
  11051. }
  11052. if (caster && !caster->IsEntity()) {
  11053. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  11054. return 0;
  11055. }
  11056. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  11057. return 0;
  11058. }
  11059. int EQ2Emu_lua_InWater(lua_State* state) {
  11060. if (!lua_interface)
  11061. return 0;
  11062. Spawn* spawn = lua_interface->GetSpawn(state);
  11063. lua_interface->ResetFunctionStack(state);
  11064. if (spawn) {
  11065. lua_interface->SetBooleanValue(state, spawn->InWater());
  11066. return 1;
  11067. }
  11068. return 0;
  11069. }
  11070. int EQ2Emu_lua_InLava(lua_State* state) {
  11071. if (!lua_interface)
  11072. return 0;
  11073. Spawn* spawn = lua_interface->GetSpawn(state);
  11074. lua_interface->ResetFunctionStack(state);
  11075. if (spawn) {
  11076. lua_interface->SetBooleanValue(state, spawn->InLava());
  11077. return 1;
  11078. }
  11079. return 0;
  11080. }
  11081. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  11082. if (!lua_interface)
  11083. return 0;
  11084. Spawn* attacker = lua_interface->GetSpawn(state);
  11085. Spawn* victim = lua_interface->GetSpawn(state, 2);
  11086. int8 type = lua_interface->GetInt8Value(state, 3);
  11087. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  11088. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  11089. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  11090. string spell_name = lua_interface->GetStringValue(state, 7);
  11091. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  11092. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  11093. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  11094. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  11095. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  11096. lua_interface->ResetFunctionStack(state);
  11097. if (!attacker) {
  11098. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  11099. lua_interface->SetBooleanValue(state, false);
  11100. return 1;
  11101. }
  11102. if (!attacker->IsEntity()) {
  11103. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  11104. lua_interface->SetBooleanValue(state, false);
  11105. return 1;
  11106. }
  11107. if (!victim) {
  11108. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  11109. lua_interface->SetBooleanValue(state, false);
  11110. return 1;
  11111. }
  11112. if (!victim->IsEntity()) {
  11113. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  11114. lua_interface->SetBooleanValue(state, false);
  11115. return 1;
  11116. }
  11117. bool has_damaged = ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker, take_power);
  11118. lua_interface->SetBooleanValue(state, has_damaged);
  11119. return 1;
  11120. }
  11121. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  11122. if (!lua_interface)
  11123. return 0;
  11124. Spawn* spawn = lua_interface->GetSpawn(state);
  11125. lua_interface->ResetFunctionStack(state);
  11126. if (spawn) {
  11127. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11128. return 1;
  11129. }
  11130. return 0;
  11131. }
  11132. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11133. if (!lua_interface)
  11134. return 0;
  11135. Spawn* spawn = lua_interface->GetSpawn(state);
  11136. bool invul = lua_interface->GetBooleanValue(state, 2);
  11137. lua_interface->ResetFunctionStack(state);
  11138. if (spawn) {
  11139. spawn->SetInvulnerable(invul);
  11140. }
  11141. return 0;
  11142. }
  11143. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11144. if (!lua_interface)
  11145. return 0;
  11146. string category = lua_interface->GetStringValue(state);
  11147. string name = lua_interface->GetStringValue(state, 2);
  11148. lua_interface->ResetFunctionStack(state);
  11149. Rule *ret = 0;
  11150. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11151. lua_interface->SetBooleanValue(state, ret->GetBool());
  11152. return 1;
  11153. }
  11154. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11155. return 0;
  11156. }
  11157. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11158. if (!lua_interface)
  11159. return 0;
  11160. string category = lua_interface->GetStringValue(state);
  11161. string name = lua_interface->GetStringValue(state, 2);
  11162. lua_interface->ResetFunctionStack(state);
  11163. Rule *ret = 0;
  11164. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11165. lua_interface->SetInt32Value(state, ret->GetInt32());
  11166. return 1;
  11167. }
  11168. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11169. return 0;
  11170. }
  11171. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11172. if (!lua_interface)
  11173. return 0;
  11174. string category = lua_interface->GetStringValue(state);
  11175. string name = lua_interface->GetStringValue(state, 2);
  11176. lua_interface->ResetFunctionStack(state);
  11177. Rule *ret = 0;
  11178. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11179. lua_interface->SetFloatValue(state, ret->GetFloat());
  11180. return 1;
  11181. }
  11182. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11183. return 0;
  11184. }
  11185. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11186. if (!lua_interface)
  11187. return 0;
  11188. Spawn* spawn = lua_interface->GetSpawn(state);
  11189. string type = lua_interface->GetStringValue(state, 2);
  11190. lua_interface->ResetFunctionStack(state);
  11191. if (spawn) {
  11192. int res = 1;
  11193. boost::to_lower(type);
  11194. if(type == "assigned_aa")
  11195. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11196. else if ( type == "unassigned_aa")
  11197. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11198. else if ( type == "assigned_tradeskill_aa")
  11199. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11200. else if ( type == "unassigned_tradeskill_aa")
  11201. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11202. else if ( type == "assigned_prestige_aa")
  11203. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11204. else if ( type == "unassigned_prestige_aa")
  11205. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11206. else if ( type == "assigned_tradeskill_prestige_aa")
  11207. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11208. else if ( type == "unassigned_tradeskill_prestige_aa")
  11209. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11210. else
  11211. res = 0;
  11212. return res;
  11213. }
  11214. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11215. return 0;
  11216. }
  11217. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11218. if (!lua_interface)
  11219. return 0;
  11220. Spawn* spawn = lua_interface->GetSpawn(state);
  11221. string type = lua_interface->GetStringValue(state, 2);
  11222. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11223. lua_interface->ResetFunctionStack(state);
  11224. if (spawn) {
  11225. boost::to_lower(type);
  11226. if(type == "assigned_aa")
  11227. spawn->SetAssignedAA((sint16)value);
  11228. else if ( type == "unassigned_aa")
  11229. spawn->SetUnassignedAA((sint16)value);
  11230. else if ( type == "assigned_tradeskill_aa")
  11231. spawn->SetTradeskillAA((sint16)value);
  11232. else if ( type == "unassigned_tradeskill_aa")
  11233. spawn->SetUnassignedTradeskillAA((sint16)value);
  11234. else if ( type == "assigned_prestige_aa")
  11235. spawn->SetPrestigeAA((sint16)value);
  11236. else if ( type == "unassigned_prestige_aa")
  11237. spawn->SetUnassignedPrestigeAA((sint16)value);
  11238. else if ( type == "assigned_tradeskill_prestige_aa")
  11239. spawn->SetTradeskillPrestigeAA((sint16)value);
  11240. else if ( type == "unassigned_tradeskill_prestige_aa")
  11241. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11242. if(spawn->IsPlayer())
  11243. ((Player*)spawn)->SetCharSheetChanged(true);
  11244. }
  11245. return 0;
  11246. }
  11247. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11248. if (!lua_interface)
  11249. return 0;
  11250. string titleName = lua_interface->GetStringValue(state);
  11251. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11252. lua_interface->ResetFunctionStack(state);
  11253. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11254. lua_interface->SetSInt32Value(state, index);
  11255. return 1;
  11256. }
  11257. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11258. if (!lua_interface)
  11259. return 0;
  11260. Spawn* spawn = lua_interface->GetSpawn(state);
  11261. string titleName = lua_interface->GetStringValue(state, 2);
  11262. lua_interface->ResetFunctionStack(state);
  11263. if(!spawn->IsPlayer())
  11264. {
  11265. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11266. lua_interface->SetSInt32Value(state, -1);
  11267. return 1;
  11268. }
  11269. Player* player = (Player*)spawn;
  11270. // check if player already has the title, don't need to add twice
  11271. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11272. if ( playerHasTitle)
  11273. {
  11274. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11275. return 1;
  11276. }
  11277. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11278. if(!title)
  11279. {
  11280. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11281. lua_interface->SetSInt32Value(state, -1);
  11282. return 1;
  11283. }
  11284. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11285. if(returnIdx < 0)
  11286. {
  11287. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11288. }
  11289. lua_interface->SetSInt32Value(state, returnIdx);
  11290. player->GetClient()->SendTitleUpdate();
  11291. return 1;
  11292. }
  11293. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11294. if (!lua_interface)
  11295. return 0;
  11296. Spawn* spawn = lua_interface->GetSpawn(state);
  11297. string titleName = lua_interface->GetStringValue(state, 2);
  11298. lua_interface->ResetFunctionStack(state);
  11299. if(!spawn->IsPlayer())
  11300. {
  11301. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11302. return 0;
  11303. }
  11304. Player* player = (Player*)spawn;
  11305. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11306. if(!title)
  11307. {
  11308. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11309. return 0;
  11310. }
  11311. if(title->GetPrefix())
  11312. {
  11313. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title with name '%s' is not valid as a suffix, only prefix", lua_interface->GetScriptName(state), titleName.c_str());
  11314. return 0;
  11315. }
  11316. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11317. player->GetClient()->SendTitleUpdate();
  11318. return 1;
  11319. }
  11320. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11321. if (!lua_interface)
  11322. return 0;
  11323. Spawn* spawn = lua_interface->GetSpawn(state);
  11324. string titleName = lua_interface->GetStringValue(state, 2);
  11325. lua_interface->ResetFunctionStack(state);
  11326. if(!spawn->IsPlayer())
  11327. {
  11328. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11329. return 0;
  11330. }
  11331. Player* player = (Player*)spawn;
  11332. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11333. if(!title)
  11334. {
  11335. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11336. return 0;
  11337. }
  11338. if(!title->GetPrefix())
  11339. {
  11340. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title with name '%s' is not valid as a prefix, only suffix", lua_interface->GetScriptName(state), titleName.c_str());
  11341. return 0;
  11342. }
  11343. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11344. player->GetClient()->SendTitleUpdate();
  11345. return 1;
  11346. }
  11347. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11348. if (!lua_interface)
  11349. return 0;
  11350. Spawn* spawn = lua_interface->GetSpawn(state);
  11351. lua_interface->ResetFunctionStack(state);
  11352. if(!spawn)
  11353. {
  11354. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: spawn is null", lua_interface->GetScriptName(state));
  11355. return 0;
  11356. }
  11357. if(!spawn->IsPlayer())
  11358. {
  11359. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11360. return 0;
  11361. }
  11362. Player* player = (Player*)spawn;
  11363. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11364. player->GetClient()->SendTitleUpdate();
  11365. return 1;
  11366. }
  11367. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11368. if (!lua_interface)
  11369. return 0;
  11370. Spawn* spawn = lua_interface->GetSpawn(state);
  11371. lua_interface->ResetFunctionStack(state);
  11372. if(!spawn)
  11373. {
  11374. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: spawn is null", lua_interface->GetScriptName(state));
  11375. return 0;
  11376. }
  11377. if(!spawn->IsPlayer())
  11378. {
  11379. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11380. return 0;
  11381. }
  11382. Player* player = (Player*)spawn;
  11383. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11384. player->GetClient()->SendTitleUpdate();
  11385. return 1;
  11386. }
  11387. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11388. if (!lua_interface)
  11389. return 0;
  11390. Spawn* spawn = lua_interface->GetSpawn(state);
  11391. string field = lua_interface->GetStringValue(state, 2);
  11392. lua_interface->ResetFunctionStack(state);
  11393. if(!spawn || !spawn->IsEntity())
  11394. {
  11395. lua_interface->LogError("%s: LUA GetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11396. return 0;
  11397. }
  11398. Entity* ent = (Entity*)spawn;
  11399. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11400. return 1;
  11401. }
  11402. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11403. if (!lua_interface)
  11404. return 0;
  11405. Spawn* spawn = lua_interface->GetSpawn(state);
  11406. string field = lua_interface->GetStringValue(state, 2);
  11407. lua_interface->ResetFunctionStack(state);
  11408. if(!spawn || !spawn->IsEntity())
  11409. {
  11410. lua_interface->LogError("%s: LUA GetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11411. return 0;
  11412. }
  11413. Entity* ent = (Entity*)spawn;
  11414. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11415. return 1;
  11416. }
  11417. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11418. if (!lua_interface)
  11419. return 0;
  11420. Spawn* spawn = lua_interface->GetSpawn(state);
  11421. string field = lua_interface->GetStringValue(state, 2);
  11422. lua_interface->ResetFunctionStack(state);
  11423. if(!spawn || !spawn->IsEntity())
  11424. {
  11425. lua_interface->LogError("%s: LUA GetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11426. return 0;
  11427. }
  11428. Entity* ent = (Entity*)spawn;
  11429. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11430. return 1;
  11431. }
  11432. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11433. if (!lua_interface)
  11434. return 0;
  11435. Spawn* spawn = lua_interface->GetSpawn(state);
  11436. string field = lua_interface->GetStringValue(state, 2);
  11437. lua_interface->ResetFunctionStack(state);
  11438. if(!spawn || !spawn->IsEntity())
  11439. {
  11440. lua_interface->LogError("%s: LUA GetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11441. return 0;
  11442. }
  11443. Entity* ent = (Entity*)spawn;
  11444. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11445. return 1;
  11446. }
  11447. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11448. if (!lua_interface)
  11449. return 0;
  11450. Spawn* spawn = lua_interface->GetSpawn(state);
  11451. string field = lua_interface->GetStringValue(state, 2);
  11452. string value = lua_interface->GetStringValue(state, 3);
  11453. lua_interface->ResetFunctionStack(state);
  11454. if(!spawn || !spawn->IsEntity())
  11455. {
  11456. lua_interface->LogError("%s: LUA SetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11457. return 0;
  11458. }
  11459. Entity* ent = (Entity*)spawn;
  11460. bool set_ = ent->SetInfoStructString(field, value);
  11461. lua_interface->SetBooleanValue(state, set_);
  11462. return 1;
  11463. }
  11464. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11465. if (!lua_interface)
  11466. return 0;
  11467. Spawn* spawn = lua_interface->GetSpawn(state);
  11468. string field = lua_interface->GetStringValue(state, 2);
  11469. int64 value = lua_interface->GetInt64Value(state, 3);
  11470. lua_interface->ResetFunctionStack(state);
  11471. if(!spawn || !spawn->IsEntity())
  11472. {
  11473. lua_interface->LogError("%s: LUA SetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11474. return 0;
  11475. }
  11476. Entity* ent = (Entity*)spawn;
  11477. bool set_ = ent->SetInfoStructUInt(field, value);
  11478. lua_interface->SetBooleanValue(state, set_);
  11479. return 1;
  11480. }
  11481. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11482. if (!lua_interface)
  11483. return 0;
  11484. Spawn* spawn = lua_interface->GetSpawn(state);
  11485. string field = lua_interface->GetStringValue(state, 2);
  11486. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11487. lua_interface->ResetFunctionStack(state);
  11488. if(!spawn || !spawn->IsEntity())
  11489. {
  11490. lua_interface->LogError("%s: LUA SetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11491. return 0;
  11492. }
  11493. Entity* ent = (Entity*)spawn;
  11494. bool set_ = ent->SetInfoStructSInt(field, value);
  11495. lua_interface->SetBooleanValue(state, set_);
  11496. return 1;
  11497. }
  11498. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11499. if (!lua_interface)
  11500. return 0;
  11501. Spawn* spawn = lua_interface->GetSpawn(state);
  11502. string field = lua_interface->GetStringValue(state, 2);
  11503. float value = lua_interface->GetFloatValue(state, 3);
  11504. lua_interface->ResetFunctionStack(state);
  11505. if(!spawn || !spawn->IsEntity())
  11506. {
  11507. lua_interface->LogError("%s: LUA SetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11508. return 0;
  11509. }
  11510. Entity* ent = (Entity*)spawn;
  11511. bool set_ = ent->SetInfoStructFloat(field, value);
  11512. lua_interface->SetBooleanValue(state, set_);
  11513. return 1;
  11514. }
  11515. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11516. if (!lua_interface)
  11517. return 0;
  11518. Spawn* spawn = lua_interface->GetSpawn(state);
  11519. bool value = lua_interface->GetBooleanValue(state, 2);
  11520. lua_interface->ResetFunctionStack(state);
  11521. if(!spawn || !spawn->IsPlayer())
  11522. {
  11523. lua_interface->LogError("%s: LUA SetCharSheetChanged command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  11524. return 0;
  11525. }
  11526. ((Player*)spawn)->SetCharSheetChanged(value);
  11527. return 0;
  11528. }
  11529. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11530. if (!lua_interface)
  11531. return 0;
  11532. Spawn* spawn = lua_interface->GetSpawn(state);
  11533. std::string fromName = lua_interface->GetStringValue(state, 2);
  11534. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11535. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11536. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11537. int32 copper = lua_interface->GetInt32Value(state, 6);
  11538. int32 silver = lua_interface->GetInt32Value(state, 7);
  11539. int32 gold = lua_interface->GetInt32Value(state, 8);
  11540. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11541. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11542. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11543. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11544. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11545. lua_interface->ResetFunctionStack(state);
  11546. if(!spawn || !spawn->IsPlayer())
  11547. {
  11548. lua_interface->LogError("%s: LUA AddPlayerMail command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  11549. lua_interface->SetBooleanValue(state, false);
  11550. return 1;
  11551. }
  11552. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11553. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11554. lua_interface->SetBooleanValue(state, true);
  11555. return 1;
  11556. }
  11557. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11558. if (!lua_interface)
  11559. return 0;
  11560. int32 char_id = lua_interface->GetInt32Value(state);
  11561. std::string fromName = lua_interface->GetStringValue(state, 2);
  11562. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11563. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11564. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11565. int32 copper = lua_interface->GetInt32Value(state, 6);
  11566. int32 silver = lua_interface->GetInt32Value(state, 7);
  11567. int32 gold = lua_interface->GetInt32Value(state, 8);
  11568. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11569. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11570. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11571. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11572. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11573. lua_interface->ResetFunctionStack(state);
  11574. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11575. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11576. lua_interface->SetBooleanValue(state, true);
  11577. return 1;
  11578. }
  11579. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11580. Spawn* widget;
  11581. if (lua_interface) {
  11582. widget = lua_interface->GetSpawn(state);
  11583. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11584. lua_interface->ResetFunctionStack(state);
  11585. if (widget && widget->IsWidget())
  11586. {
  11587. ((Widget*)widget)->OpenDoor();
  11588. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11589. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11590. }
  11591. else
  11592. lua_interface->LogError("%s: LUA OpenDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  11593. }
  11594. return 0;
  11595. }
  11596. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11597. Spawn* widget;
  11598. if (lua_interface) {
  11599. widget = lua_interface->GetSpawn(state);
  11600. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11601. lua_interface->ResetFunctionStack(state);
  11602. if (widget && widget->IsWidget())
  11603. {
  11604. ((Widget*)widget)->CloseDoor();
  11605. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11606. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11607. }
  11608. else
  11609. lua_interface->LogError("%s: LUA CloseDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  11610. }
  11611. return 0;
  11612. }
  11613. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11614. if (!lua_interface)
  11615. return 0;
  11616. Spawn* widget = lua_interface->GetSpawn(state);
  11617. lua_interface->ResetFunctionStack(state);
  11618. if (widget && widget->IsWidget())
  11619. {
  11620. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11621. return 1;
  11622. }
  11623. return 0;
  11624. }
  11625. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11626. if (!lua_interface)
  11627. return 0;
  11628. sint32 min = lua_interface->GetSInt32Value(state);
  11629. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11630. lua_interface->ResetFunctionStack(state);
  11631. sint32 result = MakeRandomInt(min, max);
  11632. lua_interface->SetSInt32Value(state, result);
  11633. return 1;
  11634. }
  11635. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11636. if (!lua_interface)
  11637. return 0;
  11638. float min = lua_interface->GetFloatValue(state);
  11639. float max = lua_interface->GetFloatValue(state, 2);
  11640. lua_interface->ResetFunctionStack(state);
  11641. float result = MakeRandomFloat(min, max);
  11642. lua_interface->SetFloatValue(state, result);
  11643. return 1;
  11644. }
  11645. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11646. if (!lua_interface)
  11647. return 0;
  11648. Spawn* spawn = lua_interface->GetSpawn(state);
  11649. int32 value = lua_interface->GetInt32Value(state, 2);
  11650. lua_interface->ResetFunctionStack(state);
  11651. if(!spawn)
  11652. {
  11653. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11654. lua_interface->SetBooleanValue(state, false);
  11655. return 1;
  11656. }
  11657. spawn->AddIconValue(value);
  11658. lua_interface->SetBooleanValue(state, true);
  11659. return 1;
  11660. }
  11661. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11662. if (!lua_interface)
  11663. return 0;
  11664. Spawn* spawn = lua_interface->GetSpawn(state);
  11665. int32 value = lua_interface->GetInt32Value(state, 2);
  11666. lua_interface->ResetFunctionStack(state);
  11667. if(!spawn)
  11668. {
  11669. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11670. lua_interface->SetBooleanValue(state, false);
  11671. return 1;
  11672. }
  11673. spawn->RemoveIconValue(value);
  11674. lua_interface->SetBooleanValue(state, true);
  11675. return 1;
  11676. }
  11677. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11678. Spawn* npc = lua_interface->GetSpawn(state);
  11679. lua_interface->ResetFunctionStack(state);
  11680. if (npc && npc->IsNPC()) {
  11681. NPC* shard = (NPC*)npc;
  11682. int32 shardid = shard->GetShardID();
  11683. lua_interface->SetInt32Value(state, shardid);
  11684. return 1;
  11685. }
  11686. lua_interface->SetInt32Value(state, 0);
  11687. return 1;
  11688. }
  11689. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11690. Spawn* npc = lua_interface->GetSpawn(state);
  11691. lua_interface->ResetFunctionStack(state);
  11692. if (npc && npc->IsNPC()) {
  11693. NPC* shard = (NPC*)npc;
  11694. int32 charid = shard->GetShardCharID();
  11695. lua_interface->SetInt32Value(state, charid);
  11696. return 1;
  11697. }
  11698. lua_interface->SetInt32Value(state, 0);
  11699. return 1;
  11700. }
  11701. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11702. Spawn* npc = lua_interface->GetSpawn(state);
  11703. lua_interface->ResetFunctionStack(state);
  11704. if (npc && npc->IsNPC()) {
  11705. NPC* shard = (NPC*)npc;
  11706. int64 timestamp = shard->GetShardCreatedTimestamp();
  11707. lua_interface->SetSInt64Value(state, timestamp);
  11708. return 1;
  11709. }
  11710. lua_interface->SetSInt64Value(state, 0);
  11711. return 1;
  11712. }
  11713. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11714. if (!lua_interface)
  11715. return 0;
  11716. int32 shardid = lua_interface->GetInt32Value(state);
  11717. lua_interface->ResetFunctionStack(state);
  11718. if(shardid < 1)
  11719. lua_interface->SetBooleanValue(state, false);
  11720. else
  11721. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11722. return 1;
  11723. }
  11724. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11725. if (!lua_interface)
  11726. return 0;
  11727. Spawn* spawn = lua_interface->GetSpawn(state);
  11728. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11729. if (spawn) {
  11730. spawn->PauseMovement(delay_in_ms);
  11731. }
  11732. lua_interface->ResetFunctionStack(state);
  11733. return 0;
  11734. }
  11735. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11736. if (!lua_interface)
  11737. return 0;
  11738. Spawn* spawn = lua_interface->GetSpawn(state);
  11739. if (spawn) {
  11740. spawn->ResetMovement();
  11741. }
  11742. lua_interface->ResetFunctionStack(state);
  11743. return 0;
  11744. }
  11745. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11746. Player* player = (Player*)lua_interface->GetSpawn(state);
  11747. int8 level = lua_interface->GetInt8Value(state, 2);
  11748. lua_interface->ResetFunctionStack(state);
  11749. if (player && player->IsPlayer() && level > 0) {
  11750. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11751. return 1;
  11752. }
  11753. return 0;
  11754. }
  11755. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11756. Player* player = (Player*)lua_interface->GetSpawn(state);
  11757. int8 level = lua_interface->GetInt8Value(state, 2);
  11758. lua_interface->ResetFunctionStack(state);
  11759. if (player && player->IsPlayer() && level > 0) {
  11760. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11761. return 1;
  11762. }
  11763. return 0;
  11764. }
  11765. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11766. ZoneServer* zone = lua_interface->GetZone(state);
  11767. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11768. lua_interface->ResetFunctionStack(state);
  11769. if (zone) {
  11770. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11771. if (spawn) {
  11772. lua_interface->SetSpawnValue(state, spawn);
  11773. return 1;
  11774. }
  11775. }
  11776. return 0;
  11777. }
  11778. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11779. if (!lua_interface)
  11780. return 0;
  11781. Spawn* spawn = lua_interface->GetSpawn(state);
  11782. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11783. lua_interface->ResetFunctionStack(state);
  11784. bool res = false;
  11785. if(spawn && spawn->IsTransportSpawn())
  11786. {
  11787. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11788. spawn->SetRailID(rail_id);
  11789. res = true;
  11790. }
  11791. else if (!spawn) {
  11792. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11793. }
  11794. else if(!spawn->IsTransportSpawn()) {
  11795. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  11796. }
  11797. lua_interface->SetBooleanValue(state, res);
  11798. return 1;
  11799. }
  11800. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11801. if (!lua_interface)
  11802. return 0;
  11803. ZoneServer* zone = lua_interface->GetZone(state);
  11804. lua_interface->ResetFunctionStack(state);
  11805. if (zone) {
  11806. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11807. return 1;
  11808. }
  11809. return 0;
  11810. }
  11811. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11812. if (!lua_interface)
  11813. return 0;
  11814. Spawn* spawn = lua_interface->GetSpawn(state);
  11815. lua_interface->ResetFunctionStack(state);
  11816. if (spawn) {
  11817. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11818. return 1;
  11819. }
  11820. return 0;
  11821. }
  11822. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11823. if (!lua_interface)
  11824. return 0;
  11825. Spawn* player = lua_interface->GetSpawn(state);
  11826. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11827. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11828. lua_interface->ResetFunctionStack(state);
  11829. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11830. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11831. }
  11832. else if(!zoneID) {
  11833. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11834. }
  11835. else
  11836. {
  11837. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11838. return 1;
  11839. }
  11840. return 0;
  11841. }
  11842. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11843. if (!lua_interface)
  11844. return 0;
  11845. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11846. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11847. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11848. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11849. lua_interface->ResetFunctionStack(state);
  11850. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11851. world.GetWorldTimeStruct()->year = newYear;
  11852. world.GetWorldTimeStruct()->month = newMonth;
  11853. world.GetWorldTimeStruct()->hour = newHour;
  11854. world.GetWorldTimeStruct()->minute = newMinute;
  11855. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11856. return 0;
  11857. }
  11858. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11859. if (!lua_interface)
  11860. return 0;
  11861. lua_interface->ResetFunctionStack(state);
  11862. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11863. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11864. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11865. return 1;
  11866. }
  11867. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11868. if (!lua_interface)
  11869. return 0;
  11870. lua_interface->ResetFunctionStack(state);
  11871. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11872. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11873. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11874. return 1;
  11875. }
  11876. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11877. if (!lua_interface)
  11878. return 0;
  11879. lua_interface->ResetFunctionStack(state);
  11880. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11881. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11882. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11883. return 1;
  11884. }
  11885. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11886. if (!lua_interface)
  11887. return 0;
  11888. lua_interface->ResetFunctionStack(state);
  11889. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11890. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11891. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11892. return 1;
  11893. }
  11894. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11895. if (!lua_interface)
  11896. return 0;
  11897. lua_interface->ResetFunctionStack(state);
  11898. world.SendTimeUpdate();
  11899. return 0;
  11900. }
  11901. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11902. bool update_result = false;
  11903. Faction* faction = 0;
  11904. Spawn* spawn = lua_interface->GetSpawn(state);
  11905. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11906. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11907. lua_interface->ResetFunctionStack(state);
  11908. if(!spawn || !spawn->IsPlayer()) {
  11909. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11910. return 0;
  11911. }
  11912. Player* player = (Player*)spawn;
  11913. Client* client = player->GetClient();
  11914. if (faction_id > 0) {
  11915. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11916. if(hasfaction == 0) {
  11917. //they do not have the faction. Lets get the default value and feed it in.
  11918. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11919. //add the default faction for the player.
  11920. player->SetFactionValue(faction_id, defaultfaction);
  11921. }
  11922. if(increase >= 0) {
  11923. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11924. faction = master_faction_list.GetFaction(faction_id);
  11925. if(faction && update_result)
  11926. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11927. else if(faction)
  11928. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11929. lua_interface->SetBooleanValue(state, true);
  11930. return 1;
  11931. }
  11932. if(increase < 0){
  11933. //change the negative to a positive, since thats how decreasefaction() likes it.
  11934. increase *= -1;
  11935. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11936. faction = master_faction_list.GetFaction(faction_id);
  11937. if(faction && update_result)
  11938. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11939. else if(faction)
  11940. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11941. lua_interface->SetBooleanValue(state, true);
  11942. return 1;
  11943. }
  11944. }
  11945. lua_interface->SetBooleanValue(state, false);
  11946. return 1;
  11947. }
  11948. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11949. bool hascoin = 0;
  11950. Spawn* player = lua_interface->GetSpawn(state);
  11951. int32 coins = lua_interface->GetInt32Value(state, 2);
  11952. lua_interface->ResetFunctionStack(state);
  11953. if (player && player->IsPlayer()) {
  11954. hascoin = ((Player*)player)->HasCoins(coins);
  11955. if(hascoin == 0) {
  11956. lua_interface->SetBooleanValue(state, false);
  11957. return 1;
  11958. }
  11959. if(hascoin == 1) {
  11960. lua_interface->SetBooleanValue(state, true);
  11961. return 1;
  11962. }
  11963. }
  11964. return 0;
  11965. }
  11966. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11967. int32 loot_tier = 0;
  11968. Spawn* spawn = lua_interface->GetSpawn(state);
  11969. lua_interface->ResetFunctionStack(state);
  11970. if (spawn) {
  11971. loot_tier = spawn->GetLootTier();
  11972. lua_interface->SetInt32Value(state, loot_tier);
  11973. return 1;
  11974. }
  11975. return 0;
  11976. }
  11977. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11978. if (!lua_interface)
  11979. return 0;
  11980. Spawn* spawn = lua_interface->GetSpawn(state);
  11981. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11982. lua_interface->ResetFunctionStack(state);
  11983. if (spawn) {
  11984. spawn->SetLootTier(loot_tier);
  11985. lua_interface->SetBooleanValue(state, true);
  11986. return 1;
  11987. }
  11988. lua_interface->SetBooleanValue(state, false);
  11989. return 1;
  11990. }
  11991. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11992. int32 loot_drop_type = 0;
  11993. Spawn* spawn = lua_interface->GetSpawn(state);
  11994. lua_interface->ResetFunctionStack(state);
  11995. if (spawn) {
  11996. loot_drop_type = spawn->GetLootDropType();
  11997. lua_interface->SetInt32Value(state, loot_drop_type);
  11998. return 1;
  11999. }
  12000. return 0;
  12001. }
  12002. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  12003. if (!lua_interface)
  12004. return 0;
  12005. Spawn* spawn = lua_interface->GetSpawn(state);
  12006. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  12007. lua_interface->ResetFunctionStack(state);
  12008. if (spawn) {
  12009. spawn->SetLootDropType(loot_drop_type);
  12010. lua_interface->SetBooleanValue(state, true);
  12011. return 1;
  12012. }
  12013. lua_interface->SetBooleanValue(state, false);
  12014. return 1;
  12015. }
  12016. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  12017. if (!lua_interface)
  12018. return 0;
  12019. Spawn* spawn = lua_interface->GetSpawn(state);
  12020. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  12021. if(damage_amount > 100) {
  12022. damage_amount = 100;
  12023. }
  12024. if (!spawn) {
  12025. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  12026. lua_interface->ResetFunctionStack(state);
  12027. return 0;
  12028. }
  12029. lua_interface->ResetFunctionStack(state);
  12030. if (spawn->IsPlayer()) {
  12031. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  12032. lua_interface->SetBooleanValue(state, true);
  12033. else
  12034. lua_interface->SetBooleanValue(state, false);
  12035. }
  12036. else {
  12037. lua_interface->SetBooleanValue(state, false);
  12038. }
  12039. return 1;
  12040. }
  12041. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  12042. ZoneServer* zone = lua_interface->GetZone(state);
  12043. int32 version = lua_interface->GetInt32Value(state, 2);
  12044. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  12045. if(region_map == nullptr) {
  12046. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  12047. lua_interface->ResetFunctionStack(state);
  12048. return 0;
  12049. }
  12050. string region_name = lua_interface->GetStringValue(state, 3);
  12051. string env_name = lua_interface->GetStringValue(state, 4);
  12052. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  12053. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  12054. float dist = lua_interface->GetFloatValue(state, 7);
  12055. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  12056. lua_interface->ResetFunctionStack(state);
  12057. lua_interface->SetBooleanValue(state, true);
  12058. return 1;
  12059. }
  12060. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  12061. ZoneServer* zone = lua_interface->GetZone(state);
  12062. int32 version = lua_interface->GetInt32Value(state, 2);
  12063. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  12064. if(region_map == nullptr) {
  12065. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  12066. lua_interface->ResetFunctionStack(state);
  12067. return 0;
  12068. }
  12069. string region_name = lua_interface->GetStringValue(state, 3);
  12070. region_map->RemoveRegionNode(region_name);
  12071. lua_interface->ResetFunctionStack(state);
  12072. lua_interface->SetBooleanValue(state, true);
  12073. return 1;
  12074. }
  12075. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  12076. Client* client = nullptr;
  12077. Spawn* player = lua_interface->GetSpawn(state);
  12078. if (!player) {
  12079. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  12080. lua_interface->SetBooleanValue(state, false);
  12081. lua_interface->ResetFunctionStack(state);
  12082. return 1;
  12083. }
  12084. if (!player->IsPlayer()) {
  12085. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  12086. lua_interface->SetBooleanValue(state, false);
  12087. lua_interface->ResetFunctionStack(state);
  12088. return 1;
  12089. }
  12090. client = player->GetClient();
  12091. if (!client) {
  12092. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  12093. lua_interface->SetBooleanValue(state, false);
  12094. lua_interface->ResetFunctionStack(state);
  12095. return 1;
  12096. }
  12097. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  12098. bool success_sight = client->SetPlayerPOVGhost(spawn);
  12099. lua_interface->ResetFunctionStack(state);
  12100. lua_interface->SetBooleanValue(state, success_sight);
  12101. return 1;
  12102. }
  12103. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  12104. if (!lua_interface)
  12105. return 0;
  12106. bool result = false;
  12107. Spawn* spawn = lua_interface->GetSpawn(state);
  12108. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  12109. lua_interface->ResetFunctionStack(state);
  12110. if (!spawn)
  12111. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12112. else if (!spawn->IsNPC())
  12113. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12114. else
  12115. {
  12116. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  12117. result = true;
  12118. }
  12119. lua_interface->SetBooleanValue(state, result);
  12120. return 1;
  12121. }
  12122. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  12123. if (!lua_interface)
  12124. return 0;
  12125. bool result = false;
  12126. Spawn* spawn = lua_interface->GetSpawn(state);
  12127. lua_interface->ResetFunctionStack(state);
  12128. if (!spawn)
  12129. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12130. else if (!spawn->IsNPC())
  12131. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12132. else
  12133. {
  12134. if(((NPC*)spawn)->cast_on_aggro_completed)
  12135. result = true;
  12136. }
  12137. lua_interface->SetBooleanValue(state, result);
  12138. return 1;
  12139. }
  12140. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12141. Client* client = nullptr;
  12142. Spawn* player = lua_interface->GetSpawn(state);
  12143. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12144. lua_interface->ResetFunctionStack(state);
  12145. if (!player) {
  12146. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  12147. lua_interface->SetBooleanValue(state, false);
  12148. return 1;
  12149. }
  12150. if (!player->IsPlayer()) {
  12151. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  12152. lua_interface->SetBooleanValue(state, false);
  12153. return 1;
  12154. }
  12155. client = player->GetClient();
  12156. if (!client) {
  12157. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12158. lua_interface->SetBooleanValue(state, false);
  12159. return 1;
  12160. }
  12161. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12162. lua_interface->SetBooleanValue(state, result);
  12163. return 1;
  12164. }
  12165. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12166. Client* client = nullptr;
  12167. Spawn* player = lua_interface->GetSpawn(state);
  12168. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12169. lua_interface->ResetFunctionStack(state);
  12170. if (!player) {
  12171. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12172. lua_interface->SetBooleanValue(state, false);
  12173. return 1;
  12174. }
  12175. if (!player->IsPlayer()) {
  12176. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12177. lua_interface->SetBooleanValue(state, false);
  12178. return 1;
  12179. }
  12180. client = player->GetClient();
  12181. if (!client) {
  12182. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12183. lua_interface->SetBooleanValue(state, false);
  12184. return 1;
  12185. }
  12186. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12187. lua_interface->SetBooleanValue(state, result);
  12188. return 1;
  12189. }
  12190. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12191. Client* client = nullptr;
  12192. Spawn* player = lua_interface->GetSpawn(state);
  12193. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12194. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12195. // rest are all optional fields
  12196. float x = lua_interface->GetFloatValue(state, 4);
  12197. float y = lua_interface->GetFloatValue(state, 5);
  12198. float z = lua_interface->GetFloatValue(state, 6);
  12199. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12200. lua_interface->ResetFunctionStack(state);
  12201. if (!player) {
  12202. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12203. lua_interface->SetBooleanValue(state, false);
  12204. return 1;
  12205. }
  12206. if (!player->IsPlayer()) {
  12207. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12208. lua_interface->SetBooleanValue(state, false);
  12209. return 1;
  12210. }
  12211. if(!player->GetZone()) {
  12212. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12213. lua_interface->SetBooleanValue(state, false);
  12214. return 1;
  12215. }
  12216. client = player->GetClient();
  12217. if (!client) {
  12218. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12219. lua_interface->SetBooleanValue(state, false);
  12220. return 1;
  12221. }
  12222. if(!client->IsReadyForUpdates()) {
  12223. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12224. lua_interface->SetBooleanValue(state, false);
  12225. return 1;
  12226. }
  12227. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12228. lua_interface->SetBooleanValue(state, true);
  12229. return 1;
  12230. }
  12231. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12232. Client* client = nullptr;
  12233. Spawn* spawn = lua_interface->GetSpawn(state);
  12234. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12235. lua_interface->ResetFunctionStack(state);
  12236. if (!spawn) {
  12237. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12238. lua_interface->SetBooleanValue(state, false);
  12239. return 1;
  12240. }
  12241. if(!spawn->GetZone()) {
  12242. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12243. lua_interface->SetBooleanValue(state, false);
  12244. return 1;
  12245. }
  12246. spawn->AddIgnoredWidget(widget_id);
  12247. lua_interface->SetBooleanValue(state, true);
  12248. return 1;
  12249. }
  12250. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12251. ZoneServer* zone = lua_interface->GetZone(state);
  12252. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12253. lua_interface->ResetFunctionStack(state);
  12254. if(!zone) {
  12255. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12256. lua_interface->SetBooleanValue(state, false);
  12257. return 1;
  12258. }
  12259. if(!zone->IsLoading()) {
  12260. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12261. lua_interface->SetBooleanValue(state, false);
  12262. return 1;
  12263. }
  12264. zone->AddIgnoredWidget(widget_id);
  12265. lua_interface->SetBooleanValue(state, true);
  12266. return 1;
  12267. }
  12268. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12269. if (!lua_interface)
  12270. return 0;
  12271. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12272. Spawn* spawn = lua_interface->GetSpawn(state);
  12273. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12274. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12275. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12276. Spawn* target = lua_interface->GetSpawn(state, 5);
  12277. lua_interface->ResetFunctionStack(state);
  12278. if(spell && spawn && spawn->IsEntity()) {
  12279. ZoneServer* zone = spawn->GetZone();
  12280. if(zone) {
  12281. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12282. }
  12283. }
  12284. else if (spawn) {
  12285. if (spawn->IsPlayer()) {
  12286. Client* client = ((Player*)spawn)->GetClient();
  12287. if (client) {
  12288. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12289. }
  12290. }
  12291. }
  12292. return 0;
  12293. }
  12294. int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
  12295. if (!lua_interface)
  12296. return 0;
  12297. Spawn* player = lua_interface->GetSpawn(state);
  12298. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12299. lua_interface->ResetFunctionStack(state);
  12300. if (!player) {
  12301. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12302. return 0;
  12303. }
  12304. if (!player->IsPlayer()) {
  12305. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12306. return 0;
  12307. }
  12308. bool ret = ((Player*)player)->get_character_flag(flag_id);
  12309. lua_interface->SetBooleanValue(state, ret);
  12310. return 1;
  12311. }
  12312. int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
  12313. if (!lua_interface)
  12314. return 0;
  12315. Spawn* player = lua_interface->GetSpawn(state);
  12316. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12317. lua_interface->ResetFunctionStack(state);
  12318. if (!player) {
  12319. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12320. return 0;
  12321. }
  12322. if (!player->IsPlayer()) {
  12323. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12324. return 0;
  12325. }
  12326. ((Player*)player)->toggle_character_flag(flag_id);
  12327. return 0;
  12328. }
  12329. int EQ2Emu_lua_GetSpellInitialTarget(lua_State* state) {
  12330. LuaSpell* spell = lua_interface->GetSpell(state);
  12331. if(!spell) {
  12332. spell = lua_interface->GetCurrentSpell(state);
  12333. }
  12334. lua_interface->ResetFunctionStack(state);
  12335. if (spell) {
  12336. if(!spell->caster) {
  12337. lua_interface->LogError("%s: LUA GetSpellTarget command error, caster does not exist.", lua_interface->GetScriptName(state));
  12338. return 0;
  12339. }
  12340. if(!spell->caster->GetZone()) {
  12341. lua_interface->LogError("%s: LUA GetSpellTarget command error, zone does not exist.", lua_interface->GetScriptName(state));
  12342. return 0;
  12343. }
  12344. Spawn* spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  12345. if (spawn) {
  12346. lua_interface->SetSpawnValue(state, spawn);
  12347. return 1;
  12348. }
  12349. else {
  12350. lua_interface->LogError("%s: LUA GetSpellTarget command error, could not find initial target %u to map to spawn.", lua_interface->GetScriptName(state), spell->initial_target);
  12351. }
  12352. }
  12353. return 0;
  12354. }
  12355. int EQ2Emu_lua_DespawnByLocationID(lua_State* state) {
  12356. ZoneServer* zone = lua_interface->GetZone(state);
  12357. int32 location_id = lua_interface->GetInt32Value(state, 2);
  12358. int32 delay = lua_interface->GetInt32Value(state, 3);
  12359. lua_interface->ResetFunctionStack(state);
  12360. if (zone) {
  12361. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  12362. if (spawn) {
  12363. vector<Spawn*> groupMembers;
  12364. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  12365. groupMembers = *spawn->GetSpawnGroup();
  12366. for (int32 i = 0; i < groupMembers.size(); i++) {
  12367. Spawn* member = groupMembers.at(i);
  12368. if(member && !member->IsPlayer() && member != spawn) {
  12369. member->GetZone()->Despawn(member, delay);
  12370. }
  12371. }
  12372. }
  12373. zone->Despawn(spawn, delay);
  12374. lua_interface->SetBooleanValue(state, true);
  12375. return 1;
  12376. }
  12377. }
  12378. lua_interface->SetBooleanValue(state, false);
  12379. return 1;
  12380. }