LuaFunctions.cpp 372 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196
  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. if (spawn) {
  156. const char* mp3 = 0;
  157. const char* text = 0;
  158. const char* emote = 0;
  159. if (mp3_string.length() > 0)
  160. mp3 = mp3_string.c_str();
  161. if (text_string.length() > 0)
  162. text = text_string.c_str();
  163. if (emote_string.length() > 0)
  164. emote = emote_string.c_str();
  165. Client* client = 0;
  166. if (player && player->IsPlayer())
  167. client = spawn->GetZone()->GetClientBySpawn(player);
  168. if (client) {
  169. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  170. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  171. }
  172. else
  173. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  174. }
  175. return 0;
  176. }
  177. int EQ2Emu_lua_PlaySound(lua_State* state) {
  178. if (!lua_interface)
  179. return 0;
  180. Spawn* spawn = lua_interface->GetSpawn(state);
  181. string sound_string = lua_interface->GetStringValue(state, 2);
  182. float x = lua_interface->GetFloatValue(state, 3);
  183. float y = lua_interface->GetFloatValue(state, 4);
  184. float z = lua_interface->GetFloatValue(state, 5);
  185. Spawn* player = lua_interface->GetSpawn(state, 6);
  186. if (spawn && sound_string.length() > 0) {
  187. Client* client = 0;
  188. if (player && player->IsPlayer())
  189. client = spawn->GetZone()->GetClientBySpawn(player);
  190. if (client)
  191. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  192. else
  193. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  194. }
  195. return 0;
  196. }
  197. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  202. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  203. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  204. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  205. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  206. if (!spawn) {
  207. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  208. return 0;
  209. }
  210. if (quest_id > 0) {
  211. //Add this quest to the list of required quests for this spawn
  212. spawn->SetQuestsRequired(quest_id, quest_step);
  213. //If private spawn value set
  214. if (private_spawn) {
  215. //Set the spawn to be private when not granted access through this quest
  216. spawn->AddAllowAccessSpawn(spawn);
  217. spawn->SetPrivateQuestSpawn(true);
  218. }
  219. //This value allows access after a quest step, or the whole quest has been completed
  220. if (continued_access)
  221. spawn->SetQuestsRequiredContinuedAccess(true);
  222. //This value will override vis_flags in the vis packet
  223. if (flag_override > 0)
  224. spawn->SetQuestsRequiredOverride(flag_override);
  225. }
  226. return 0;
  227. }
  228. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  229. if (!lua_interface)
  230. return 0;
  231. Spawn* spawn = lua_interface->GetSpawn(state);
  232. float max_distance = lua_interface->GetFloatValue(state, 2);
  233. string variable = lua_interface->GetStringValue(state, 3);
  234. string value = lua_interface->GetStringValue(state, 4);
  235. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  236. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  237. return 0;
  238. }
  239. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  240. if (!lua_interface)
  241. return 0;
  242. Client* client = 0;
  243. Spawn* player = lua_interface->GetSpawn(state);
  244. if (!player) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  246. return 0;
  247. }
  248. if (!player->IsPlayer()) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  250. return 0;
  251. }
  252. if (player->GetZone())
  253. client = player->GetZone()->GetClientBySpawn(player);
  254. if (!client) {
  255. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  256. return 0;
  257. }
  258. float intensity = lua_interface->GetFloatValue(state, 2);
  259. int8 direction = lua_interface->GetInt8Value(state, 3);
  260. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  261. if (packet) {
  262. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  263. v1 = *(float *)(a1 + 4);
  264. if ( v1 > 0.0 )
  265. v2 = fminf(v1, 1.0);
  266. else
  267. v2 = 0.1;
  268. */
  269. packet->setDataByName("intensity", intensity);
  270. if ( client->GetVersion() > 546 )
  271. packet->setDataByName("direction", direction);
  272. client->QueuePacket(packet->serialize());
  273. safe_delete(packet);
  274. }
  275. return 0;
  276. }
  277. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  278. if (!lua_interface)
  279. return 0;
  280. Spawn* dead = lua_interface->GetSpawn(state);
  281. Spawn* killer = lua_interface->GetSpawn(state, 2);
  282. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  283. if (dead && dead->Alive() && dead->GetZone())
  284. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  285. return 0;
  286. }
  287. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  288. if (!lua_interface)
  289. return 0;
  290. Spawn* spawn = lua_interface->GetSpawn(state);
  291. float max_distance = lua_interface->GetFloatValue(state, 2);
  292. bool include_players = lua_interface->GetInt8Value(state, 3);
  293. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  294. if (max_distance > 0 && spawn && spawn->GetZone())
  295. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  296. return 0;
  297. }
  298. int EQ2Emu_lua_Despawn(lua_State* state) {
  299. if (!lua_interface)
  300. return 0;
  301. Spawn* spawn = lua_interface->GetSpawn(state);
  302. int32 delay = lua_interface->GetInt32Value(state, 2);
  303. if (spawn && spawn->GetZone())
  304. spawn->GetZone()->Despawn(spawn, delay);
  305. return 0;
  306. }
  307. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* spawn = lua_interface->GetSpawn(state);
  311. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  312. if (spawn) {
  313. spawn->info_changed = true;
  314. spawn->SetShowHandIcon(displayHandIcon);
  315. }
  316. return 0;
  317. }
  318. //this function is used to force an update packet to be sent.
  319. //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
  320. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  321. if (!lua_interface)
  322. return 0;
  323. Spawn* spawn = lua_interface->GetSpawn(state);
  324. if (spawn) {
  325. spawn->vis_changed = true;
  326. spawn->GetZone()->AddChangedSpawn(spawn);
  327. }
  328. return 0;
  329. }
  330. //this function is used to force an update packet to be sent.
  331. //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
  332. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  333. if (!lua_interface)
  334. return 0;
  335. Spawn* spawn = lua_interface->GetSpawn(state);
  336. if (spawn) {
  337. spawn->info_changed = true;
  338. spawn->GetZone()->AddChangedSpawn(spawn);
  339. }
  340. return 0;
  341. }
  342. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. int32 new_state = lua_interface->GetInt32Value(state, 2);
  347. Spawn* player = lua_interface->GetSpawn(state, 3);
  348. lua_interface->ResetFunctionStack(state);
  349. if (spawn) {
  350. if(player)
  351. {
  352. if(player->IsPlayer())
  353. {
  354. Client* client = ((Player*)player)->GetClient();
  355. if(client)
  356. {
  357. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  358. lua_interface->SetBooleanValue(state, true);
  359. return 1;
  360. }
  361. else
  362. 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());
  363. }
  364. else
  365. 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());
  366. }
  367. else
  368. {
  369. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  370. lua_interface->SetBooleanValue(state, true);
  371. return 1;
  372. }
  373. }
  374. lua_interface->SetBooleanValue(state, false);
  375. return 1;
  376. }
  377. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. Spawn* spawn = lua_interface->GetSpawn(state);
  381. string variable = lua_interface->GetStringValue(state, 2);
  382. string value = lua_interface->GetStringValue(state, 3);
  383. 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.
  384. bool temporary_flag = true;
  385. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  386. if(num_args >= 5)
  387. 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
  388. int32 type = commands.GetSpawnSetType(variable);
  389. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  390. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  391. return 0;
  392. }
  393. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  394. if (!lua_interface)
  395. return 0;
  396. Spawn* spawn = lua_interface->GetSpawn(state);
  397. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  398. if (spawn && spawn_id > 0) {
  399. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  400. if (closest_spawn) {
  401. lua_interface->SetSpawnValue(state, closest_spawn);
  402. return 1;
  403. }
  404. }
  405. return 0;
  406. }
  407. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  408. if (!lua_interface)
  409. return 0;
  410. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  411. int32 position = lua_interface->GetInt32Value(state, 2);
  412. if (spawnList) {
  413. if (spawnList->size() > position) {
  414. lua_interface->SetSpawnValue(state, spawnList->at(position));
  415. return 1;
  416. }
  417. else {
  418. return 0;
  419. }
  420. return spawnList->size();
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. if (spawnList) {
  429. return spawnList->size();
  430. }
  431. return 0;
  432. }
  433. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  434. if (!lua_interface)
  435. return 0;
  436. vector<Spawn*>* spawnList = new vector<Spawn*>();
  437. lua_interface->SetSpawnListValue(state, spawnList);
  438. return 1;
  439. }
  440. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  441. if (!lua_interface)
  442. return 0;
  443. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  444. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  445. if (spawnList) {
  446. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  447. if (it == spawnList->end())
  448. spawnList->push_back(spawn);
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  456. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  457. if (spawnList) {
  458. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  459. if(it != spawnList->end())
  460. spawnList->erase(it);
  461. }
  462. return 0;
  463. }
  464. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  465. if (!lua_interface)
  466. return 0;
  467. Spawn* spawn = lua_interface->GetSpawn(state);
  468. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  469. if (spawn) {
  470. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  471. if (spawns.size() > 0) {
  472. vector<Spawn*>* spawnList = new vector<Spawn*>();
  473. vector<Spawn*>::iterator itr;
  474. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  475. spawnList->push_back(*itr);
  476. }
  477. lua_interface->SetSpawnListValue(state, spawnList);
  478. return 1;
  479. }
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. Spawn* spawn = lua_interface->GetSpawn(state);
  487. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  488. if (spawn) {
  489. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  490. if (spawns.size() > 0) {
  491. vector<Spawn*>* spawnList = new vector<Spawn*>();
  492. vector<Spawn*>::iterator itr;
  493. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  494. spawnList->push_back(*itr);
  495. }
  496. lua_interface->SetSpawnListValue(state, spawnList);
  497. return 1;
  498. }
  499. }
  500. return 0;
  501. }
  502. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  503. if (!lua_interface)
  504. return 0;
  505. string variable_name = lua_interface->GetStringValue(state);
  506. Variable* var = variables.FindVariable(variable_name);
  507. if (var) {
  508. lua_interface->SetStringValue(state, var->GetValue());
  509. return 1;
  510. }
  511. return 0;
  512. }
  513. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  514. if (!lua_interface)
  515. return 0;
  516. int32 total_coins = lua_interface->GetInt32Value(state);
  517. if (total_coins == 0) {
  518. lua_interface->SetStringValue(state, "0 copper");
  519. return 1;
  520. }
  521. char tmp[64] = { 0 };
  522. string message = "";
  523. int32 val = 0;
  524. if (total_coins >= 1000000) {
  525. val = total_coins / 1000000;
  526. total_coins -= 1000000 * val;
  527. sprintf(tmp, " %u Platinum", val);
  528. message.append(tmp);
  529. memset(tmp, 0, 64);
  530. }
  531. if (total_coins >= 10000) {
  532. val = total_coins / 10000;
  533. total_coins -= 10000 * val;
  534. sprintf(tmp, " %u Gold", val);
  535. message.append(tmp);
  536. memset(tmp, 0, 64);
  537. }
  538. if (total_coins >= 100) {
  539. val = total_coins / 100;
  540. total_coins -= 100 * val;
  541. sprintf(tmp, " %u Silver", val);
  542. message.append(tmp);
  543. memset(tmp, 0, 64);
  544. }
  545. if (total_coins > 0) {
  546. sprintf(tmp, " %u Copper", (int32)total_coins);
  547. message.append(tmp);
  548. }
  549. lua_interface->SetStringValue(state, message.c_str());
  550. return 1;
  551. }
  552. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  553. ZoneServer* zone = lua_interface->GetZone(state);
  554. int32 group_id = lua_interface->GetInt32Value(state, 2);
  555. if (zone) {
  556. Spawn* spawn = zone->GetSpawnGroup(group_id);
  557. if (spawn) {
  558. lua_interface->SetSpawnValue(state, spawn);
  559. return 1;
  560. }
  561. }
  562. return 0;
  563. }
  564. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  565. ZoneServer* zone = lua_interface->GetZone(state);
  566. int32 location_id = lua_interface->GetInt32Value(state, 2);
  567. if (zone) {
  568. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  569. if (spawn) {
  570. lua_interface->SetSpawnValue(state, spawn);
  571. return 1;
  572. }
  573. }
  574. return 0;
  575. }
  576. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  577. Spawn* spawn = lua_interface->GetSpawn(state);
  578. if (spawn) {
  579. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  580. return 1;
  581. }
  582. return 0;
  583. }
  584. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  585. Spawn* spawn = lua_interface->GetSpawn(state);
  586. if (spawn) {
  587. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  588. return 1;
  589. }
  590. return 0;
  591. }
  592. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  593. if (!lua_interface)
  594. return 0;
  595. Spawn* spawn = lua_interface->GetSpawn(state);
  596. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  597. lua_interface->ResetFunctionStack(state);
  598. if (spawn) {
  599. spawn->SetSpawnGroupID(new_group_id);
  600. lua_interface->SetBooleanValue(state, true);
  601. return 1;
  602. }
  603. lua_interface->SetBooleanValue(state, false);
  604. return 1;
  605. }
  606. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  607. if (!lua_interface)
  608. return 0;
  609. Spawn* spawn = lua_interface->GetSpawn(state);
  610. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  611. lua_interface->ResetFunctionStack(state);
  612. if (spawn) {
  613. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  614. lua_interface->SetBooleanValue(state, true);
  615. return 1;
  616. }
  617. lua_interface->SetBooleanValue(state, false);
  618. return 1;
  619. }
  620. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  621. Spawn* spawn = lua_interface->GetSpawn(state);
  622. if (spawn) {
  623. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  624. return 1;
  625. }
  626. return 0;
  627. }
  628. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  629. Spawn* spawn = lua_interface->GetSpawn(state);
  630. if (spawn) {
  631. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  632. return 1;
  633. }
  634. return 0;
  635. }
  636. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  637. Player* player = (Player*)lua_interface->GetSpawn(state);
  638. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  639. if (player && player->IsPlayer() && faction_id > 0) {
  640. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  641. return 1;
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  646. if (!lua_interface)
  647. return 0;
  648. Spawn* spawn = lua_interface->GetSpawn(state);
  649. int32 value = lua_interface->GetInt32Value(state, 2);
  650. if (spawn) {
  651. spawn->SetFactionID(value);
  652. }
  653. return 0;
  654. }
  655. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  656. Spawn* spawn = lua_interface->GetSpawn(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_GetGender(lua_State* state) {
  664. Spawn* spawn = lua_interface->GetSpawn(state);
  665. if (spawn) {
  666. lua_interface->SetInt32Value(state, spawn->GetGender());
  667. return 1;
  668. }
  669. return 0;
  670. }
  671. int EQ2Emu_lua_GetTarget(lua_State* state) {
  672. Spawn* spawn = lua_interface->GetSpawn(state);
  673. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  674. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  675. return 1;
  676. }
  677. return 0;
  678. }
  679. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  680. if (!lua_interface)
  681. return 0;
  682. Spawn* spawn = lua_interface->GetSpawn(state);
  683. string mp3_string = lua_interface->GetStringValue(state, 2);
  684. int32 key1 = lua_interface->GetInt32Value(state, 3);
  685. int32 key2 = lua_interface->GetInt32Value(state, 4);
  686. Spawn* player = lua_interface->GetSpawn(state, 5);
  687. if (spawn && mp3_string.length() > 0) {
  688. Client* client = 0;
  689. if (player && player->IsPlayer())
  690. client = spawn->GetZone()->GetClientBySpawn(player);
  691. if (client) {
  692. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  693. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  694. }
  695. else
  696. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  701. if (!lua_interface)
  702. return 0;
  703. Spawn* spawn = lua_interface->GetSpawn(state);
  704. if (spawn) {
  705. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  706. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  707. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  708. return 3;
  709. }
  710. return 0;
  711. }
  712. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  713. if (!lua_interface)
  714. return 0;
  715. Spawn* spawn = lua_interface->GetSpawn(state);
  716. if (spawn) {
  717. int32 item_id = lua_interface->GetInt32Value(state, 2);
  718. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  719. return 1;
  720. }
  721. return 0;
  722. }
  723. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  724. if (!lua_interface)
  725. return 0;
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. if (spawn && spawn->IsEntity()) {
  728. int32 item_id = lua_interface->GetInt32Value(state, 2);
  729. int16 charges = lua_interface->GetInt16Value(state, 3);
  730. if (charges == 0)
  731. charges = 1;
  732. ((Entity*)spawn)->AddLootItem(item_id, charges);
  733. }
  734. return 0;
  735. }
  736. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  737. if (!lua_interface)
  738. return 0;
  739. Spawn* spawn = lua_interface->GetSpawn(state);
  740. if (spawn && spawn->IsEntity()) {
  741. int32 item_id = lua_interface->GetInt32Value(state, 2);
  742. Item* item = spawn->LootItem(item_id);
  743. safe_delete(item);
  744. }
  745. return 0;
  746. }
  747. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  748. if (!lua_interface)
  749. return 0;
  750. Spawn* spawn = lua_interface->GetSpawn(state);
  751. if (spawn) {
  752. int32 val = lua_interface->GetInt32Value(state, 2);
  753. spawn->AddLootCoins(val);
  754. }
  755. return 0;
  756. }
  757. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  758. if (!lua_interface)
  759. return 0;
  760. Spawn* entity = lua_interface->GetSpawn(state);
  761. Spawn* player = lua_interface->GetSpawn(state, 2);
  762. if (entity && player && player->IsPlayer()) {
  763. int32 coins = lua_interface->GetInt32Value(state, 3);
  764. vector<Item*>* items = 0;
  765. int i = 0;
  766. int32 item_id = 0;
  767. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  768. if (items == 0)
  769. items = new vector<Item*>;
  770. if (master_item_list.GetItem(item_id))
  771. items->push_back(master_item_list.GetItem(item_id));
  772. i++;
  773. }
  774. Client* client = 0;
  775. client = player->GetZone()->GetClientBySpawn(player);
  776. if (client)
  777. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  778. if(coins > 0)
  779. entity->AddLootCoins(coins);
  780. safe_delete(items);
  781. }
  782. return 0;
  783. }
  784. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  785. if (!lua_interface)
  786. return 0;
  787. Spawn* entity = lua_interface->GetSpawn(state);
  788. Spawn* player = lua_interface->GetSpawn(state, 2);
  789. int32 item_id = lua_interface->GetInt32Value(state, 3);
  790. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  791. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  792. return 1;
  793. }
  794. return 0;
  795. }
  796. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* entity = lua_interface->GetSpawn(state);
  800. Spawn* player = lua_interface->GetSpawn(state, 2);
  801. if (entity && player && player->IsPlayer()) {
  802. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  803. return 1;
  804. }
  805. return 0;
  806. }
  807. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  808. if (!lua_interface)
  809. return 0;
  810. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  811. safe_delete(conversation);
  812. conversation = new vector<ConversationOption>();
  813. lua_interface->SetConversationValue(state, conversation);
  814. return 1;
  815. }
  816. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  817. if (!lua_interface)
  818. return 0;
  819. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  820. if (conversation) {
  821. ConversationOption conv_option;
  822. conv_option.option = lua_interface->GetStringValue(state, 2);
  823. conv_option.function = lua_interface->GetStringValue(state, 3);
  824. if (conv_option.option.length() > 0)
  825. conversation->push_back(conv_option);
  826. }
  827. return 0;
  828. }
  829. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  830. if (!lua_interface)
  831. return 0;
  832. Spawn* npc = lua_interface->GetSpawn(state);
  833. Spawn* player = lua_interface->GetSpawn(state, 2);
  834. if (npc && player && player->IsPlayer() && player->GetZone()) {
  835. Client* client = player->GetZone()->GetClientBySpawn(player);
  836. if (client) {
  837. int32 conversation_id = client->GetConversationID(npc, 0);
  838. client->CloseDialog(conversation_id);
  839. }
  840. }
  841. return 0;
  842. }
  843. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  844. if (!lua_interface)
  845. return 0;
  846. Item* item = lua_interface->GetItem(state);
  847. Spawn* player = lua_interface->GetSpawn(state, 2);
  848. if (item && player && player->IsPlayer() && player->GetZone()) {
  849. Client* client = player->GetZone()->GetClientBySpawn(player);
  850. if (client) {
  851. int32 conversation_id = client->GetConversationID(0, item);
  852. client->CloseDialog(conversation_id);
  853. }
  854. }
  855. return 0;
  856. }
  857. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  858. if (!lua_interface)
  859. return 0;
  860. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  861. Spawn* spawn = 0;
  862. Item* item = 0;
  863. int8 type = lua_interface->GetInt8Value(state, 2);
  864. if (type == 1 || type == 3)
  865. spawn = lua_interface->GetSpawn(state, 3);
  866. else if (type == 2 || type == 4)
  867. item = lua_interface->GetItem(state, 3);
  868. Spawn* player = lua_interface->GetSpawn(state, 4);
  869. string text = lua_interface->GetStringValue(state, 5);
  870. string mp3 = lua_interface->GetStringValue(state, 6);
  871. int32 key1 = lua_interface->GetInt32Value(state, 7);
  872. int32 key2 = lua_interface->GetInt32Value(state, 8);
  873. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  874. Client* client = player->GetZone()->GetClientBySpawn(player);
  875. if (client) {
  876. if (spawn) {
  877. // Need to do this so the function works the same as it did before
  878. if (type == 1)
  879. type++;
  880. if (mp3.length() > 0)
  881. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  882. else
  883. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  884. }
  885. else {
  886. if (mp3.length() > 0)
  887. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  888. else
  889. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  890. }
  891. }
  892. }
  893. safe_delete(conversation);
  894. lua_interface->SetConversationValue(state, NULL);
  895. return 0;
  896. }
  897. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  898. if(!lua_interface)
  899. return 0;
  900. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  901. Item* item = lua_interface->GetItem(state, 2);
  902. Spawn* player = lua_interface->GetSpawn(state, 3);
  903. string text = lua_interface->GetStringValue(state, 4);
  904. string mp3 = lua_interface->GetStringValue(state, 5);
  905. int32 key1 = lua_interface->GetInt32Value(state, 6);
  906. int32 key2 = lua_interface->GetInt32Value(state, 7);
  907. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  908. Client* client = player->GetZone()->GetClientBySpawn(player);
  909. if(client){
  910. if(mp3.length() > 0)
  911. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  912. else
  913. client->DisplayConversation(item, conversation, (char*)text.c_str());
  914. }
  915. safe_delete(conversation);
  916. }
  917. return 0;
  918. }*/
  919. int EQ2Emu_lua_StartConversation(lua_State* state) {
  920. if (!lua_interface)
  921. return 0;
  922. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  923. Spawn* source = lua_interface->GetSpawn(state, 2);
  924. Spawn* player = lua_interface->GetSpawn(state, 3);
  925. string text = lua_interface->GetStringValue(state, 4);
  926. string mp3 = lua_interface->GetStringValue(state, 5);
  927. int32 key1 = lua_interface->GetInt32Value(state, 6);
  928. int32 key2 = lua_interface->GetInt32Value(state, 7);
  929. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  930. Client* client = source->GetZone()->GetClientBySpawn(player);
  931. if (mp3.length() > 0)
  932. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  933. else
  934. client->DisplayConversation(source, 1, conversation, text.c_str());
  935. safe_delete(conversation);
  936. lua_interface->SetConversationValue(state, NULL);
  937. }
  938. else
  939. 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);
  940. return 0;
  941. }
  942. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  943. if (!lua_interface)
  944. return 0;
  945. Spawn* spawn = lua_interface->GetSpawn(state);
  946. float distance = lua_interface->GetFloatValue(state, 2);
  947. string in_range_function = lua_interface->GetStringValue(state, 3);
  948. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  949. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  950. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  951. return 0;
  952. }
  953. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  954. ZoneServer* zone = lua_interface->GetZone(state);
  955. float x = lua_interface->GetFloatValue(state, 2);
  956. float y = lua_interface->GetFloatValue(state, 3);
  957. float z = lua_interface->GetFloatValue(state, 4);
  958. float max_variation = lua_interface->GetFloatValue(state, 5);
  959. string in_range_function = lua_interface->GetStringValue(state, 6);
  960. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  961. if (zone && in_range_function.length() > 0)
  962. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  963. return 0;
  964. }
  965. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  966. if (!lua_interface)
  967. return 0;
  968. Spawn* spawn = lua_interface->GetSpawn(state);
  969. if (spawn && spawn->IsEntity()) {
  970. int32 val = lua_interface->GetInt32Value(state, 2);
  971. ((Entity*)spawn)->SetLootCoins(val);
  972. }
  973. return 0;
  974. }
  975. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  976. if (!lua_interface)
  977. return 0;
  978. Spawn* spawn = lua_interface->GetSpawn(state);
  979. if (spawn && spawn->IsEntity()) {
  980. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  981. return 1;
  982. }
  983. return 0;
  984. }
  985. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  986. if (!lua_interface)
  987. return 0;
  988. Spawn* spawn = lua_interface->GetSpawn(state);
  989. float x = lua_interface->GetFloatValue(state, 2);
  990. float y = lua_interface->GetFloatValue(state, 3);
  991. float z = lua_interface->GetFloatValue(state, 4);
  992. float speed = lua_interface->GetFloatValue(state, 5);
  993. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  994. string function = lua_interface->GetStringValue(state, 7);
  995. if (spawn) {
  996. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  997. spawn->GetZone()->AddMovementNPC(spawn);
  998. }
  999. lua_interface->ResetFunctionStack(state);
  1000. return 0;
  1001. }
  1002. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1003. if (!lua_interface)
  1004. return 0;
  1005. Spawn* spawn = lua_interface->GetSpawn(state);
  1006. if (spawn) {
  1007. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1008. return 1;
  1009. }
  1010. return 0;
  1011. }
  1012. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1013. if (!lua_interface)
  1014. return 0;
  1015. Spawn* spawn = lua_interface->GetSpawn(state);
  1016. if (spawn && spawn->IsPlayer()) {
  1017. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1018. return 1;
  1019. }
  1020. lua_interface->SetInt32Value(state, 0);
  1021. return 1;
  1022. }
  1023. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1024. if (!lua_interface)
  1025. return 0;
  1026. Spawn* spawn = lua_interface->GetSpawn(state);
  1027. Spawn* target = lua_interface->GetSpawn(state, 2);
  1028. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1029. bool reset_action_state = true;
  1030. if(num_args > 2)
  1031. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1032. if (spawn && target) {
  1033. if (spawn->IsEntity())
  1034. // ((Entity*)spawn)->FaceTarget(target);
  1035. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1036. }
  1037. lua_interface->ResetFunctionStack(state);
  1038. return 0;
  1039. }
  1040. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1041. if (!lua_interface)
  1042. return 0;
  1043. Spawn* spawn = lua_interface->GetSpawn(state);
  1044. float x = lua_interface->GetFloatValue(state, 2);
  1045. float y = lua_interface->GetFloatValue(state, 3);
  1046. float z = lua_interface->GetFloatValue(state, 4);
  1047. float speed = lua_interface->GetFloatValue(state, 5);
  1048. string lua_function = lua_interface->GetStringValue(state, 6);
  1049. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1050. if (spawn) {
  1051. if (speed == 0)
  1052. speed = spawn->GetSpeed();
  1053. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1054. }
  1055. lua_interface->ResetFunctionStack(state);
  1056. return 0;
  1057. }
  1058. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1059. if (!lua_interface)
  1060. return 0;
  1061. Spawn* spawn = lua_interface->GetSpawn(state);
  1062. if (spawn) {
  1063. spawn->ClearRunningLocations();
  1064. }
  1065. return 0;
  1066. }
  1067. int EQ2Emu_lua_Say(lua_State* state) {
  1068. if (!lua_interface)
  1069. return 0;
  1070. Spawn* spawn = lua_interface->GetSpawn(state);
  1071. string message = lua_interface->GetStringValue(state, 2);
  1072. Spawn* player = lua_interface->GetSpawn(state, 3);
  1073. int32 language = lua_interface->GetInt32Value(state, 4);
  1074. if (spawn && message.length() > 0) {
  1075. Client* client = 0;
  1076. if (player && player->IsPlayer())
  1077. client = spawn->GetZone()->GetClientBySpawn(player);
  1078. if (client)
  1079. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1080. else
  1081. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1082. }
  1083. lua_interface->ResetFunctionStack(state);
  1084. return 0;
  1085. }
  1086. int EQ2Emu_lua_Shout(lua_State* state) {
  1087. if (!lua_interface)
  1088. return 0;
  1089. Spawn* spawn = lua_interface->GetSpawn(state);
  1090. string message = lua_interface->GetStringValue(state, 2);
  1091. Spawn* player = lua_interface->GetSpawn(state, 3);
  1092. float dist = lua_interface->GetFloatValue(state, 4);
  1093. if (spawn && message.length() > 0) {
  1094. Client* client = 0;
  1095. if (player && player->IsPlayer())
  1096. client = spawn->GetZone()->GetClientBySpawn(player);
  1097. if (client)
  1098. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1099. else
  1100. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1101. }
  1102. lua_interface->ResetFunctionStack(state);
  1103. return 0;
  1104. }
  1105. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1106. if (!lua_interface)
  1107. return 0;
  1108. Spawn* spawn = lua_interface->GetSpawn(state);
  1109. string message = lua_interface->GetStringValue(state, 2);
  1110. Spawn* player = lua_interface->GetSpawn(state, 3);
  1111. if (spawn && message.length() > 0) {
  1112. Client* client = 0;
  1113. if (player && player->IsPlayer())
  1114. client = spawn->GetZone()->GetClientBySpawn(player);
  1115. if (client)
  1116. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1117. else
  1118. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1119. }
  1120. lua_interface->ResetFunctionStack(state);
  1121. return 0;
  1122. }
  1123. int EQ2Emu_lua_Emote(lua_State* state) {
  1124. if (!lua_interface)
  1125. return 0;
  1126. Spawn* spawn = lua_interface->GetSpawn(state);
  1127. string message = lua_interface->GetStringValue(state, 2);
  1128. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1129. Spawn* player = lua_interface->GetSpawn(state, 4);
  1130. char* to = 0;
  1131. if (spawn2)
  1132. to = spawn2->GetName();
  1133. if (spawn && message.length() > 0) {
  1134. Client* client = 0;
  1135. if (player && player->IsPlayer())
  1136. client = spawn->GetZone()->GetClientBySpawn(player);
  1137. if (client)
  1138. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1139. else
  1140. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1141. }
  1142. lua_interface->ResetFunctionStack(state);
  1143. return 0;
  1144. }
  1145. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1146. if (!lua_interface)
  1147. return 0;
  1148. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1149. if (!luaspell)
  1150. return 0;
  1151. Spawn* caster = luaspell->caster;
  1152. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1153. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1154. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1155. Spawn* target = lua_interface->GetSpawn(state, 4);
  1156. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1157. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1158. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1159. lua_interface->ResetFunctionStack(state);
  1160. boost::to_lower(heal_type);
  1161. if (caster && caster->IsEntity()) {
  1162. bool success = false;
  1163. luaspell->resisted = false;
  1164. if (target) {
  1165. float distance = caster->GetDistance(target, true);
  1166. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1167. success = true;
  1168. }
  1169. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1170. Spawn* target = 0;
  1171. ZoneServer* zone = luaspell->caster->GetZone();
  1172. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1173. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1174. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1175. float distance = caster->GetDistance(target, true);
  1176. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1177. }
  1178. }
  1179. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1180. success = true;
  1181. }
  1182. if (success) {
  1183. if (caster->GetZone())
  1184. caster->GetZone()->TriggerCharSheetTimer();
  1185. }
  1186. }
  1187. return 0;
  1188. }
  1189. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1190. if (!lua_interface)
  1191. return 0;
  1192. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1193. if (!luaspell)
  1194. return 0;
  1195. Spawn* caster = luaspell->caster;
  1196. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1197. float percentage = lua_interface->GetFloatValue(state, 2);
  1198. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1199. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1200. Spawn* target = lua_interface->GetSpawn(state, 5);
  1201. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1202. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1203. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1204. lua_interface->ResetFunctionStack(state);
  1205. boost::to_lower(heal_type);
  1206. int32 min_heal = 0, max_heal = 0;
  1207. if (caster && caster->IsEntity() && target) {
  1208. if(percentage <= 0.0f)
  1209. {
  1210. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1211. return 0;
  1212. }
  1213. if(heal_type == "power")
  1214. {
  1215. if(current_value)
  1216. {
  1217. if(caster_value)
  1218. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1219. else
  1220. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1221. }
  1222. else
  1223. {
  1224. if(caster_value)
  1225. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1226. else
  1227. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1228. }
  1229. }
  1230. else
  1231. {
  1232. if(current_value)
  1233. {
  1234. if(caster_value)
  1235. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1236. else
  1237. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1238. }
  1239. else
  1240. {
  1241. if(caster_value)
  1242. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1243. else
  1244. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1245. }
  1246. }
  1247. bool success = false;
  1248. luaspell->resisted = false;
  1249. if (target) {
  1250. float distance = caster->GetDistance(target, true);
  1251. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1252. success = true;
  1253. }
  1254. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1255. Spawn* target = 0;
  1256. ZoneServer* zone = luaspell->caster->GetZone();
  1257. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1258. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1259. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1260. float distance = caster->GetDistance(target, true);
  1261. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1262. }
  1263. }
  1264. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1265. success = true;
  1266. }
  1267. if (success) {
  1268. if (caster->GetZone())
  1269. caster->GetZone()->TriggerCharSheetTimer();
  1270. }
  1271. }
  1272. return 0;
  1273. }
  1274. int EQ2Emu_lua_AddItem(lua_State* state) {
  1275. if (!lua_interface)
  1276. return 0;
  1277. Spawn* spawn = lua_interface->GetSpawn(state);
  1278. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1279. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1280. // default of 1 quantity to add
  1281. if (quantity == 0)
  1282. quantity = 1;
  1283. if (spawn && spawn->IsPlayer()) {
  1284. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1285. if (client && item_id > 0) {
  1286. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1287. return 1;
  1288. }
  1289. }
  1290. lua_interface->SetBooleanValue(state, false);
  1291. return 1;
  1292. }
  1293. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1294. if (!lua_interface)
  1295. return 0;
  1296. Spawn* spawn = lua_interface->GetSpawn(state);
  1297. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1298. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1299. string location = lua_interface->GetStringValue(state, 4);
  1300. if (spawn && spawn->IsPlayer()) {
  1301. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1302. if (client && item_id > 0) {
  1303. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1304. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1305. else
  1306. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1307. if (send_messages) {
  1308. Item* item = master_item_list.GetItem(item_id);
  1309. if (item) {
  1310. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1311. string popup_text = "You receive " + item->name;
  1312. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1313. }
  1314. }
  1315. return 1;
  1316. }
  1317. }
  1318. lua_interface->SetBooleanValue(state, false);
  1319. return 1;
  1320. }
  1321. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1322. Spawn* spawn = lua_interface->GetSpawn(state);
  1323. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1324. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1325. // default of 1 to remove
  1326. if (quantity == 0)
  1327. quantity = 1;
  1328. Client* client;
  1329. Item* item;
  1330. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1331. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1332. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1333. if (client->RemoveItem(item, quantity)) {
  1334. lua_interface->SetBooleanValue(state, true);
  1335. return 1;
  1336. }
  1337. }
  1338. }
  1339. }
  1340. lua_interface->SetBooleanValue(state, false);
  1341. return 1;
  1342. }
  1343. int EQ2Emu_lua_HasItem(lua_State* state) {
  1344. Spawn* player = lua_interface->GetSpawn(state);
  1345. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1346. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1347. if (player && player->IsPlayer()) {
  1348. bool hasItem = false;
  1349. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1350. if (!hasItem)
  1351. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1352. lua_interface->SetBooleanValue(state, hasItem);
  1353. return 1;
  1354. }
  1355. lua_interface->SetBooleanValue(state, false);
  1356. return 1;
  1357. }
  1358. int EQ2Emu_lua_Spawn(lua_State* state) {
  1359. if (!lua_interface)
  1360. return 0;
  1361. ZoneServer* zone = lua_interface->GetZone(state);
  1362. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1363. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1364. float x = lua_interface->GetFloatValue(state, 4);
  1365. float y = lua_interface->GetFloatValue(state, 5);
  1366. float z = lua_interface->GetFloatValue(state, 6);
  1367. float heading = lua_interface->GetFloatValue(state, 7);
  1368. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1369. Spawn* spawn = zone->GetSpawn(spawn_id);
  1370. if (!spawn)
  1371. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1372. else {
  1373. spawn->SetX(x);
  1374. spawn->SetZ(z);
  1375. spawn->SetY(y,true,true);
  1376. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1377. spawn->SetHeading(heading);
  1378. if (restricted_npc)
  1379. spawn->AddAllowAccessSpawn(spawn);
  1380. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1381. bool scriptActive = false;
  1382. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1383. scriptActive = true;
  1384. spawn->SetSpawnScript(string(spawn_script));
  1385. }
  1386. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1387. zone->AddSpawn(spawn);
  1388. if (scriptActive) {
  1389. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1390. }
  1391. lua_interface->SetSpawnValue(state, spawn);
  1392. return 1;
  1393. }
  1394. }
  1395. else {
  1396. string output = "Invalid paramaters to LUA Spawn command: \n";
  1397. if (!zone)
  1398. output = output.append("\t").append("Missing zone reference. \n");
  1399. if (spawn_id == 0)
  1400. output = output.append("\t").append("Missing spawn_id.");
  1401. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1402. }
  1403. return 0;
  1404. }
  1405. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1406. if (!lua_interface)
  1407. return 0;
  1408. ZoneServer* zone = lua_interface->GetZone(state);
  1409. if (zone) {
  1410. lua_interface->SetStringValue(state, zone->GetZoneName());
  1411. return 1;
  1412. }
  1413. return 0;
  1414. }
  1415. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1416. if (!lua_interface)
  1417. return 0;
  1418. ZoneServer* zone = lua_interface->GetZone(state);
  1419. if (zone) {
  1420. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1421. return 1;
  1422. }
  1423. return 0;
  1424. }
  1425. int EQ2Emu_lua_GetZone(lua_State* state) {
  1426. if (!lua_interface)
  1427. return 0;
  1428. int32 zone_id = lua_interface->GetInt32Value(state);
  1429. ZoneServer* zone = 0;
  1430. if (zone_id > 0)
  1431. zone = zone_list.Get(zone_id);
  1432. else {
  1433. string zone_name = lua_interface->GetStringValue(state);
  1434. if (zone_name.length() > 0) {
  1435. zone = zone_list.Get(zone_name.c_str());
  1436. }
  1437. else {
  1438. Spawn* spawn = lua_interface->GetSpawn(state);
  1439. if (spawn)
  1440. zone = spawn->GetZone();
  1441. }
  1442. }
  1443. if (zone) {
  1444. lua_interface->SetZoneValue(state, zone);
  1445. return 1;
  1446. }
  1447. return 0;
  1448. }
  1449. int EQ2Emu_lua_AddHate(lua_State* state) {
  1450. Spawn* entity = lua_interface->GetSpawn(state);
  1451. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1452. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1453. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1454. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1455. if (entity && entity->IsEntity() && amount != 0) {
  1456. if (luaspell) {
  1457. ZoneServer* zone = luaspell->caster->GetZone();
  1458. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1459. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1460. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1461. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1462. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1463. if (send_packet)
  1464. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1465. }
  1466. }
  1467. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1468. }
  1469. else if (npc && npc->IsNPC() && npc->GetZone())
  1470. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1471. }
  1472. return 0;
  1473. }
  1474. int EQ2Emu_lua_Zone(lua_State* state) {
  1475. if (!lua_interface)
  1476. return 0;
  1477. ZoneServer* zone = lua_interface->GetZone(state);
  1478. Spawn* player = lua_interface->GetSpawn(state, 2);
  1479. Client* client = 0;
  1480. if (player && player->IsPlayer())
  1481. client = player->GetZone()->GetClientBySpawn(player);
  1482. float x = lua_interface->GetFloatValue(state, 3);
  1483. float y = lua_interface->GetFloatValue(state, 4);
  1484. float z = lua_interface->GetFloatValue(state, 5);
  1485. float heading = lua_interface->GetFloatValue(state, 6);
  1486. if (zone && client) {
  1487. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1488. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1489. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1490. {
  1491. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1492. return 0;
  1493. }
  1494. if (x != 0 || y != 0 || z != 0) {
  1495. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1496. player->SetX(x);
  1497. player->SetY(y);
  1498. player->SetZ(z);
  1499. player->SetHeading(heading);
  1500. client->Zone(zone->GetZoneName(), false);
  1501. }
  1502. else
  1503. client->Zone(zone->GetZoneName());
  1504. }
  1505. else
  1506. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1507. return 0;
  1508. }
  1509. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1510. if (!lua_interface)
  1511. return 0;
  1512. Spawn* spawn = lua_interface->GetSpawn(state);
  1513. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1514. if (spawn && spawn2)
  1515. spawn->AddAllowAccessSpawn(spawn2);
  1516. return 0;
  1517. }
  1518. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1519. if (!lua_interface)
  1520. return 0;
  1521. Spawn* target = lua_interface->GetSpawn(state);
  1522. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1523. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1524. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1525. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1526. if (!target) {
  1527. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1528. return 0;
  1529. }
  1530. if (!target->IsEntity()) {
  1531. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1532. return 0;
  1533. }
  1534. if (spell_id <= 0) {
  1535. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1536. return 0;
  1537. }
  1538. if (caster && !caster->IsEntity()) {
  1539. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1540. return 0;
  1541. }
  1542. if (spell_tier == 0)
  1543. spell_tier = 1;
  1544. if (!caster)
  1545. caster = target;
  1546. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1547. return 0;
  1548. }
  1549. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1550. if (!lua_interface)
  1551. return 0;
  1552. Spawn* target = lua_interface->GetSpawn(state);
  1553. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1554. if (!luaspell)
  1555. return 0;
  1556. Spawn* caster = luaspell->caster;
  1557. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1558. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1559. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1560. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1561. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1562. //lua_interface->ResetFunctionStack(state);
  1563. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1564. vector<int16> faction_req;
  1565. vector<int16> race_req;
  1566. int32 class_req = 0;
  1567. int32 i = 0;
  1568. int8 f = 0;
  1569. int8 r = 0;
  1570. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1571. if (class_id < 100) {
  1572. class_req += pow(2.0, double(class_id - 1));
  1573. }
  1574. else if (class_id > 100 && class_id < 1000) {
  1575. race_req.push_back(class_id);
  1576. r++;
  1577. }
  1578. else {
  1579. faction_req.push_back(class_id);
  1580. f++;
  1581. }
  1582. i++;
  1583. }
  1584. if (caster && caster->IsEntity()) {
  1585. bool race_match = false;
  1586. bool success = false;
  1587. luaspell->resisted = false;
  1588. if (luaspell->targets.size() > 0) {
  1589. ZoneServer* zone = luaspell->caster->GetZone();
  1590. Spawn* target = 0;
  1591. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1592. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1593. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1594. if (race_req.size() > 0) {
  1595. for (int8 i = 0; i < race_req.size(); i++) {
  1596. if (target->GetLuaRaceId() == race_req[i]) {
  1597. race_match = true;
  1598. }
  1599. }
  1600. }
  1601. else
  1602. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1603. if (race_match == true) {
  1604. float distance = caster->GetDistance(target, true);
  1605. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1606. }
  1607. }
  1608. }
  1609. success = true;
  1610. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1611. }
  1612. else if (target) {
  1613. //check class and race/faction here
  1614. if (race_req.size() > 0) {
  1615. for (int8 i = 0; i < race_req.size(); i++) {
  1616. if (target->GetLuaRaceId() == race_req[i]) {
  1617. race_match = true;
  1618. }
  1619. }
  1620. }
  1621. else
  1622. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1623. if (race_match == true) {
  1624. float distance = caster->GetDistance(target, true);
  1625. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1626. success = true;
  1627. }
  1628. }
  1629. if (success) {
  1630. Spell* spell = luaspell->spell;
  1631. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1632. ((Player*)caster)->InCombat(true);
  1633. if (caster->GetZone())
  1634. caster->GetZone()->TriggerCharSheetTimer();
  1635. }
  1636. }
  1637. }
  1638. return 0;
  1639. }
  1640. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1641. if (!lua_interface)
  1642. return 0;
  1643. Spawn* spawn = lua_interface->GetSpawn(state);
  1644. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1645. lua_interface->ResetFunctionStack(state);
  1646. if (spawn && value != 0) {
  1647. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1648. spawn->SetPower(spawn->GetTotalPower());
  1649. else
  1650. spawn->SetPower(spawn->GetPower() + value);
  1651. }
  1652. return 0;
  1653. }
  1654. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1655. if (!lua_interface)
  1656. return 0;
  1657. Spawn* spawn = lua_interface->GetSpawn(state);
  1658. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1659. lua_interface->ResetFunctionStack(state);
  1660. if (spawn && value != 0) {
  1661. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1662. spawn->SetHP(spawn->GetTotalHP());
  1663. else
  1664. spawn->SetHP(spawn->GetHP() + value);
  1665. }
  1666. return 0;
  1667. }
  1668. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1669. if (!lua_interface)
  1670. return 0;
  1671. Spawn* spawn = lua_interface->GetSpawn(state);
  1672. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1673. lua_interface->ResetFunctionStack(state);
  1674. if (spawn && value != 0) {
  1675. spawn->SetPower(spawn->GetPower() + value);
  1676. if (value > spawn->GetTotalHPBase())
  1677. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1678. }
  1679. return 0;
  1680. }
  1681. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1682. if (!lua_interface)
  1683. return 0;
  1684. Spawn* spawn = lua_interface->GetSpawn(state);
  1685. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1686. lua_interface->ResetFunctionStack(state);
  1687. if (spawn && value != 0) {
  1688. spawn->SetHP(spawn->GetHP() + value);
  1689. if (value > spawn->GetTotalHPBase())
  1690. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1691. }
  1692. return 0;
  1693. }
  1694. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1695. if (!lua_interface)
  1696. return 0;
  1697. Spawn* spawn = lua_interface->GetSpawn(state);
  1698. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1699. lua_interface->ResetFunctionStack(state);
  1700. if (spawn) {
  1701. spawn->SetHP(value);
  1702. if (value > spawn->GetTotalHPBase())
  1703. spawn->SetTotalHP(value);
  1704. }
  1705. return 0;
  1706. }
  1707. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1708. if (!lua_interface)
  1709. return 0;
  1710. Spawn* spawn = lua_interface->GetSpawn(state);
  1711. float value = lua_interface->GetFloatValue(state, 2);
  1712. lua_interface->ResetFunctionStack(state);
  1713. if (spawn && spawn->IsEntity() && value > 0)
  1714. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1715. if (spawn->IsPlayer())
  1716. ((Player*)spawn)->SetCharSheetChanged(true);
  1717. return 0;
  1718. }
  1719. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1720. if (!lua_interface)
  1721. return 0;
  1722. Spawn* spawn = lua_interface->GetSpawn(state);
  1723. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1724. lua_interface->ResetFunctionStack(state);
  1725. if (spawn && spawn->IsEntity() && value > 0)
  1726. ((Entity*)spawn)->SetTotalHPBase(value);
  1727. return 0;
  1728. }
  1729. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1730. if (!lua_interface)
  1731. return 0;
  1732. Spawn* spawn = lua_interface->GetSpawn(state);
  1733. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1734. lua_interface->ResetFunctionStack(state);
  1735. if (spawn && value > 0) {
  1736. spawn->SetPower(value);
  1737. if (value > spawn->GetTotalPowerBase())
  1738. spawn->SetTotalPower(value);
  1739. }
  1740. return 0;
  1741. }
  1742. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1743. if (!lua_interface)
  1744. return 0;
  1745. Spawn* spawn = lua_interface->GetSpawn(state);
  1746. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1747. lua_interface->ResetFunctionStack(state);
  1748. if (spawn && spawn->IsEntity() && value > 0)
  1749. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1750. return 0;
  1751. }
  1752. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1753. if (!lua_interface)
  1754. return 0;
  1755. Spawn* spawn = lua_interface->GetSpawn(state);
  1756. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1757. lua_interface->ResetFunctionStack(state);
  1758. if (spawn && spawn->IsEntity() && value > 0)
  1759. ((Entity*)spawn)->SetTotalPowerBase(value);
  1760. return 0;
  1761. }
  1762. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1763. if (!lua_interface)
  1764. return 0;
  1765. Spawn* spawn = lua_interface->GetSpawn(state);
  1766. float x = lua_interface->GetFloatValue(state, 2);
  1767. float y = lua_interface->GetFloatValue(state, 3);
  1768. float z = lua_interface->GetFloatValue(state, 4);
  1769. float heading = lua_interface->GetFloatValue(state, 5);
  1770. lua_interface->ResetFunctionStack(state);
  1771. if (spawn) {
  1772. spawn->SetX(x);
  1773. spawn->SetY(y);
  1774. spawn->SetZ(z);
  1775. if (heading != 0)
  1776. spawn->SetHeading(heading);
  1777. spawn->SetSpawnOrigX(spawn->GetX());
  1778. spawn->SetSpawnOrigY(spawn->GetY());
  1779. spawn->SetSpawnOrigZ(spawn->GetZ());
  1780. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1781. if (spawn->IsPlayer()) {
  1782. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1783. if (client) {
  1784. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1785. client->QueuePacket(packet);
  1786. }
  1787. }
  1788. }
  1789. return 0;
  1790. }
  1791. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1792. if (!lua_interface)
  1793. return 0;
  1794. Spawn* spawn = lua_interface->GetSpawn(state);
  1795. float value = lua_interface->GetFloatValue(state, 2);
  1796. lua_interface->ResetFunctionStack(state);
  1797. if (spawn) {
  1798. spawn->SetHeading(value);
  1799. if (spawn->IsPlayer()) {
  1800. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1801. if (client) {
  1802. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1803. client->QueuePacket(packet);
  1804. }
  1805. }
  1806. }
  1807. return 0;
  1808. }
  1809. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1810. if (!lua_interface)
  1811. return 0;
  1812. Spawn* spawn = lua_interface->GetSpawn(state);
  1813. int16 value = lua_interface->GetInt16Value(state, 2);
  1814. lua_interface->ResetFunctionStack(state);
  1815. if (spawn)
  1816. spawn->SetModelType(value);
  1817. return 0;
  1818. }
  1819. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1820. if (!lua_interface)
  1821. return 0;
  1822. Spawn* spawn = lua_interface->GetSpawn(state);
  1823. int8 value = lua_interface->GetInt8Value(state, 2);
  1824. lua_interface->ResetFunctionStack(state);
  1825. if (spawn) {
  1826. if (spawn->IsPlayer())
  1827. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1828. else
  1829. spawn->SetAdventureClass(value);
  1830. }
  1831. return 0;
  1832. }
  1833. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1834. if (!lua_interface)
  1835. return 0;
  1836. Spawn* spawn = lua_interface->GetSpawn(state);
  1837. int8 value = lua_interface->GetInt8Value(state, 2);
  1838. lua_interface->ResetFunctionStack(state);
  1839. if (spawn) {
  1840. spawn->SetTradeskillClass(value);
  1841. if (spawn->IsEntity()) {
  1842. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1843. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1844. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1845. }
  1846. if (spawn->IsPlayer())
  1847. ((Player*)spawn)->SetCharSheetChanged(true);
  1848. }
  1849. return 0;
  1850. }
  1851. int EQ2Emu_lua_SetMount(lua_State* state) {
  1852. if (!lua_interface)
  1853. return 0;
  1854. Spawn* spawn = lua_interface->GetSpawn(state);
  1855. int16 value = lua_interface->GetInt16Value(state, 2);
  1856. if (spawn && spawn->IsEntity()) {
  1857. ((Entity*)spawn)->SetMount(value);
  1858. EQ2_Color color;
  1859. color.red = 255;
  1860. color.green = 255;
  1861. color.blue = 255;
  1862. ((Entity*)spawn)->SetMountColor(&color);
  1863. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1864. }
  1865. return 0;
  1866. }
  1867. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1868. if (!lua_interface)
  1869. return 0;
  1870. Spawn* spawn = lua_interface->GetSpawn(state);
  1871. EQ2_Color mount_color;
  1872. EQ2_Color saddle_color;
  1873. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1874. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1875. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1876. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1877. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1878. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1879. if (spawn && spawn->IsEntity()) {
  1880. ((Entity*)spawn)->SetMountColor(&mount_color);
  1881. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1882. }
  1883. return 0;
  1884. }
  1885. int EQ2Emu_lua_GetMount(lua_State* state) {
  1886. if (!lua_interface)
  1887. return 0;
  1888. Spawn* spawn = lua_interface->GetSpawn(state);
  1889. if (spawn && spawn->IsEntity()) {
  1890. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1891. return 1;
  1892. }
  1893. return 0;
  1894. }
  1895. int EQ2Emu_lua_GetRace(lua_State* state) {
  1896. if (!lua_interface)
  1897. return 0;
  1898. Spawn* spawn = lua_interface->GetSpawn(state);
  1899. if (spawn)
  1900. {
  1901. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1902. lua_interface->SetInt32Value(state, spawn->GetRace());
  1903. return 1;
  1904. }
  1905. return 0;
  1906. }
  1907. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1908. if (!lua_interface)
  1909. return 0;
  1910. Spawn* spawn = lua_interface->GetSpawn(state);
  1911. if (spawn) {
  1912. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1913. return 1;
  1914. }
  1915. return 0;
  1916. }
  1917. int EQ2Emu_lua_GetClass(lua_State* state) {
  1918. Spawn* spawn = lua_interface->GetSpawn(state);
  1919. if (spawn) {
  1920. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1921. return 1;
  1922. }
  1923. return 0;
  1924. }
  1925. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1926. Spawn* spawn = lua_interface->GetSpawn(state);
  1927. if (spawn) {
  1928. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1929. return 1;
  1930. }
  1931. return 0;
  1932. }
  1933. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1934. if (!lua_interface)
  1935. return 0;
  1936. Spawn* spawn = lua_interface->GetSpawn(state);
  1937. float value = lua_interface->GetFloatValue(state, 2);
  1938. lua_interface->ResetFunctionStack(state);
  1939. if (spawn) {
  1940. spawn->SetSpeed(value);
  1941. ((Entity*)spawn)->SetSpeed(value);
  1942. if (spawn->IsPlayer()) {
  1943. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1944. if (client) {
  1945. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1946. if (packet) {
  1947. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1948. packet->setDataByName("speed", value);
  1949. packet->setDataByName("size", 0.51);
  1950. EQ2Packet* app = packet->serialize();
  1951. client->QueuePacket(app);
  1952. safe_delete(packet);
  1953. }
  1954. }
  1955. }
  1956. }
  1957. return 0;
  1958. }
  1959. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1960. if (!lua_interface)
  1961. return 0;
  1962. Spawn* spawn = lua_interface->GetSpawn(state);
  1963. const int16 type = lua_interface->GetInt16Value(state, 2);
  1964. const float value = lua_interface->GetFloatValue(state, 3);
  1965. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1966. int64 class_req = 0;
  1967. int32 class_id = 0;
  1968. vector<int16> faction_req;
  1969. vector<int16> race_req;
  1970. int32 i = 0;
  1971. int8 f = 0;
  1972. int8 r = 0;
  1973. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1974. if (class_id < 100) {
  1975. class_req += pow(2.0, double(class_id - 1));
  1976. }
  1977. else if (class_id > 100 && class_id < 1000) {
  1978. race_req.push_back(class_id);
  1979. r++;
  1980. }
  1981. else {
  1982. faction_req.push_back(class_id);
  1983. f++;
  1984. }
  1985. i++;
  1986. }
  1987. if (value != 0 && type >= 0) {
  1988. if (luaspell && luaspell->spell && luaspell->caster) {
  1989. ZoneServer* zone = luaspell->caster->GetZone();
  1990. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1991. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1992. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1993. if (target) {
  1994. if (target->IsPlayer()) {
  1995. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1996. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1997. if (((Player*)target)->GetGroupMemberInfo())
  1998. ((Player*)target)->UpdateGroupMemberInfo();
  1999. ((Player*)target)->SetCharSheetChanged(true);
  2000. }
  2001. else if (target->IsNPC())
  2002. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2003. else
  2004. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2005. }
  2006. }
  2007. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2008. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2009. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2010. }
  2011. else if (spawn && spawn->IsEntity()) {
  2012. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2013. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2014. if (spawn->IsPlayer())
  2015. ((Player*)spawn)->SetCharSheetChanged(true);
  2016. }
  2017. else
  2018. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2019. }
  2020. else
  2021. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2022. return 0;
  2023. }
  2024. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2025. if (!lua_interface)
  2026. return 0;
  2027. Spawn* spawn = lua_interface->GetSpawn(state);
  2028. int16 type = lua_interface->GetInt16Value(state, 2);
  2029. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2030. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2031. if (!spawn) {
  2032. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2033. return 0;
  2034. }
  2035. if (!spawn->IsEntity()) {
  2036. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2037. return 0;
  2038. }
  2039. if (value == 0) {
  2040. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2041. return 0;
  2042. }
  2043. if (!luaspell || !luaspell->spell) {
  2044. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2045. return 0;
  2046. }
  2047. int32 class_req = 0;
  2048. vector<int16> faction_req;
  2049. vector<int16> race_req;
  2050. int32 class_id = 0;
  2051. int32 i = 0;
  2052. int8 f = 0;
  2053. int8 r = 0;
  2054. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2055. if (class_id < 100) {
  2056. class_req += pow(2.0, double(class_id - 1));
  2057. }
  2058. else if (class_id > 100 && class_id < 1000) {
  2059. race_req.push_back(class_id);
  2060. r++;
  2061. }
  2062. else {
  2063. faction_req.push_back(class_id);
  2064. f++;
  2065. }
  2066. i++;
  2067. }
  2068. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2069. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2070. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2071. if (spawn->IsPlayer())
  2072. ((Player*)spawn)->SetCharSheetChanged(true);
  2073. return 0;
  2074. }
  2075. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2076. if (!lua_interface)
  2077. return 0;
  2078. Spawn* spawn = lua_interface->GetSpawn(state);
  2079. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2080. if (!spawn) {
  2081. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2082. return 0;
  2083. }
  2084. if (!spawn->IsEntity()) {
  2085. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2086. return 0;
  2087. }
  2088. if (!luaspell || !luaspell->spell) {
  2089. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2090. return 0;
  2091. }
  2092. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2093. if (spawn->IsPlayer())
  2094. ((Player*)spawn)->SetCharSheetChanged(true);
  2095. return 0;
  2096. }
  2097. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2098. if (!lua_interface)
  2099. return 0;
  2100. Spawn* spawn = lua_interface->GetSpawn(state);
  2101. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2102. if (luaspell && luaspell->spell) {
  2103. ZoneServer* zone = luaspell->caster->GetZone();
  2104. Spawn* target = 0;
  2105. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2106. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2107. target = zone->GetSpawnByID(luaspell->targets[i]);
  2108. if (target && target->IsEntity()) {
  2109. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2110. if (target->IsPlayer())
  2111. ((Player*)target)->SetCharSheetChanged(true);
  2112. }
  2113. }
  2114. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2115. }
  2116. else if (spawn && spawn->IsEntity()) {
  2117. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2118. if (spawn->IsPlayer())
  2119. ((Player*)spawn)->SetCharSheetChanged(true);
  2120. }
  2121. return 0;
  2122. }
  2123. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2124. if (!lua_interface)
  2125. return 0;
  2126. Spawn* spawn = lua_interface->GetSpawn(state);
  2127. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2128. float value = lua_interface->GetFloatValue(state, 3);
  2129. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2130. if (value != 0) {
  2131. int32 spell_id = 0;
  2132. if (luaspell && luaspell->spell && luaspell->caster) {
  2133. spell_id = luaspell->spell->GetSpellID();
  2134. ZoneServer* zone = luaspell->caster->GetZone();
  2135. Spawn* target = 0;
  2136. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2137. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2138. target = zone->GetSpawnByID(luaspell->targets[i]);
  2139. if (target && target->Alive()) {
  2140. if (target->IsPlayer()) {
  2141. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2142. Client* client = target->GetZone()->GetClientBySpawn(target);
  2143. if (client) {
  2144. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2145. if (packet)
  2146. client->QueuePacket(packet);
  2147. }
  2148. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2149. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2150. }
  2151. else if (target->IsNPC()) {
  2152. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2153. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2154. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2155. }
  2156. else
  2157. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2158. }
  2159. }
  2160. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2161. }
  2162. else if (spawn) {
  2163. if (spawn->IsPlayer()) {
  2164. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2165. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2166. if (client) {
  2167. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2168. if (packet)
  2169. client->QueuePacket(packet);
  2170. }
  2171. }
  2172. else if (spawn->IsNPC())
  2173. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2174. else
  2175. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2176. }
  2177. }
  2178. else
  2179. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2180. return 0;
  2181. }
  2182. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2183. if (!lua_interface)
  2184. return 0;
  2185. Spawn* spawn = lua_interface->GetSpawn(state);
  2186. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2187. if (spawn && spawn->IsPlayer()) {
  2188. int32 spell_id = 0;
  2189. if (luaspell && luaspell->spell) {
  2190. spell_id = luaspell->spell->GetSpellID();
  2191. ZoneServer* zone = luaspell->caster->GetZone();
  2192. Spawn* target = 0;
  2193. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2194. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2195. target = zone->GetSpawnByID(luaspell->targets[i]);
  2196. if (target) {
  2197. if (target->IsPlayer()) {
  2198. ((Player*)target)->RemoveSkillBonus(spell_id);
  2199. Client* client = target->GetZone()->GetClientBySpawn(target);
  2200. if (client) {
  2201. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2202. if (packet)
  2203. client->QueuePacket(packet);
  2204. }
  2205. }
  2206. else if (target->IsNPC())
  2207. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2208. else
  2209. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2210. }
  2211. }
  2212. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2213. }
  2214. else if (spawn) {
  2215. if (spawn->IsPlayer()) {
  2216. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2217. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2218. if (client) {
  2219. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2220. if (packet)
  2221. client->QueuePacket(packet);
  2222. }
  2223. }
  2224. else if (spawn->IsNPC())
  2225. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2226. else
  2227. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2228. }
  2229. }
  2230. return 0;
  2231. }
  2232. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2233. if (!lua_interface)
  2234. return 0;
  2235. Spawn* spawn = lua_interface->GetSpawn(state);
  2236. int8 type = lua_interface->GetInt32Value(state, 2);
  2237. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2238. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2239. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2240. ZoneServer* zone = luaspell->caster->GetZone();
  2241. Spawn* target = 0;
  2242. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2243. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2244. target = zone->GetSpawnByID(luaspell->targets[i]);
  2245. if (target && target->IsEntity()) {
  2246. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2247. ((Entity*)target)->AddMezSpell(luaspell);
  2248. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2249. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2250. if (target->IsNPC())
  2251. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2252. }
  2253. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2254. ((Entity*)target)->AddStifleSpell(luaspell);
  2255. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2256. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2257. if (target->IsNPC())
  2258. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2259. }
  2260. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2261. ((Entity*)target)->AddDazeSpell(luaspell);
  2262. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2263. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2264. if (target->IsNPC())
  2265. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2266. }
  2267. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2268. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2269. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2270. ((Entity*)target)->AddStunSpell(luaspell);
  2271. if (target->IsNPC())
  2272. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2273. }
  2274. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2275. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2276. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2277. ((Entity*)target)->AddRootSpell(luaspell);
  2278. if (target->IsNPC())
  2279. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2280. }
  2281. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2282. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2283. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2284. ((Entity*)target)->AddFearSpell(luaspell);
  2285. if (target->IsNPC())
  2286. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2287. }
  2288. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2289. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2290. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2291. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2292. }
  2293. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2294. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2295. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2296. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2297. }
  2298. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2299. ((Entity*)target)->AddSnareSpell(luaspell);
  2300. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2301. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2302. if (target->IsNPC())
  2303. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2304. }
  2305. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2306. ((Entity*)target)->AddFlightSpell(luaspell);
  2307. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2308. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2309. }
  2310. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2311. ((Entity*)target)->AddGlideSpell(luaspell);
  2312. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2313. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2314. }
  2315. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2316. ((Entity*)target)->AddSafefallSpell(luaspell);
  2317. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2318. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2319. }
  2320. else
  2321. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2322. }
  2323. else
  2324. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2325. }
  2326. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2327. }
  2328. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2329. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2330. ((Entity*)spawn)->AddMezSpell(luaspell);
  2331. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2332. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2333. }
  2334. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2335. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2336. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2337. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2338. }
  2339. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2340. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2341. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2342. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2343. }
  2344. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2345. ((Entity*)spawn)->AddStunSpell(luaspell);
  2346. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2347. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2348. }
  2349. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2350. ((Entity*)spawn)->AddRootSpell(luaspell);
  2351. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2352. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2353. }
  2354. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2355. ((Entity*)spawn)->AddFearSpell(luaspell);
  2356. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2357. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2358. }
  2359. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2360. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2361. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2362. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2363. }
  2364. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2365. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2366. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2367. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2368. }
  2369. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2370. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2371. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2372. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2373. }
  2374. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2375. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2376. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2377. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2378. }
  2379. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2380. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2381. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2382. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2383. }
  2384. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2385. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2386. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2387. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2388. }
  2389. else
  2390. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2391. }
  2392. else
  2393. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2394. return 0;
  2395. }
  2396. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2397. if (!lua_interface)
  2398. return 0;
  2399. Spawn* spawn = lua_interface->GetSpawn(state);
  2400. int8 type = lua_interface->GetInt8Value(state, 2);
  2401. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2402. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2403. if (spawn && spawn->IsEntity()) {
  2404. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2405. ZoneServer* zone = luaspell->caster->GetZone();
  2406. Spawn* target = 0;
  2407. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2408. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2409. target = zone->GetSpawnByID(luaspell->targets[i]);
  2410. if (target) {
  2411. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2412. ((Entity*)target)->RemoveMezSpell(luaspell);
  2413. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2414. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2415. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2416. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2417. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2418. ((Entity*)target)->RemoveStunSpell(luaspell);
  2419. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2420. ((Entity*)target)->RemoveRootSpell(luaspell);
  2421. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2422. ((Entity*)target)->RemoveFearSpell(luaspell);
  2423. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2424. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2425. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2426. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2427. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2428. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2429. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2430. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2431. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2432. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2433. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2434. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2435. else
  2436. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2437. }
  2438. }
  2439. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2440. }
  2441. else if (only_remove_spawn) {
  2442. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2443. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2444. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2445. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2446. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2447. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2448. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2449. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2450. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2451. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2452. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2453. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2454. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2455. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2456. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2457. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2458. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2459. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2460. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2461. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2462. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2463. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2464. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2465. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2466. else
  2467. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2468. }
  2469. }
  2470. return 0;
  2471. }
  2472. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2473. if (!lua_interface)
  2474. return 0;
  2475. Spawn* spawn = lua_interface->GetSpawn(state);
  2476. int8 type = lua_interface->GetInt8Value(state, 2);
  2477. bool hasEffect = false;
  2478. if (!spawn)
  2479. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2480. else if (!spawn->IsEntity())
  2481. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2482. else if (type < CONTROL_MAX_EFFECTS)
  2483. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2484. else
  2485. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2486. lua_interface->SetBooleanValue(state, hasEffect);
  2487. return 1;
  2488. }
  2489. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2490. if (!lua_interface)
  2491. return 0;
  2492. Spawn* spawn = lua_interface->GetSpawn(state);
  2493. float distance = 0.0f;
  2494. if (!spawn)
  2495. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2496. else if (!spawn->IsNPC())
  2497. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2498. else
  2499. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2500. lua_interface->SetFloatValue(state, distance);
  2501. return 1;
  2502. }
  2503. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2504. if (!lua_interface)
  2505. return 0;
  2506. Spawn* spawn = lua_interface->GetSpawn(state);
  2507. float distance = 0.0f;
  2508. if (!spawn)
  2509. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2510. else if (!spawn->IsNPC())
  2511. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2512. else
  2513. distance = ((NPC*)spawn)->GetAggroRadius();
  2514. lua_interface->SetFloatValue(state, distance);
  2515. return 1;
  2516. }
  2517. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2518. if (!lua_interface)
  2519. return 0;
  2520. Spawn* spawn = lua_interface->GetSpawn(state);
  2521. float distance = lua_interface->GetFloatValue(state, 2);
  2522. bool override = lua_interface->GetBooleanValue(state, 3);
  2523. bool result = false;
  2524. lua_interface->ResetFunctionStack(state);
  2525. if (!spawn)
  2526. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2527. else if (!spawn->IsNPC())
  2528. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2529. else
  2530. {
  2531. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2532. result = true;
  2533. }
  2534. lua_interface->SetBooleanValue(state, result);
  2535. return 1;
  2536. }
  2537. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2538. if (!lua_interface)
  2539. return 0;
  2540. Spawn* spawn = lua_interface->GetSpawn(state);
  2541. int16 value = lua_interface->GetInt16Value(state, 2);
  2542. if (spawn && spawn->IsEntity()) {
  2543. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2544. if (spawn->IsPlayer())
  2545. ((Player*)spawn)->SetCharSheetChanged(true);
  2546. }
  2547. return 0;
  2548. }
  2549. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2550. if (!lua_interface)
  2551. return 0;
  2552. Spawn* spawn = lua_interface->GetSpawn(state);
  2553. int16 value = lua_interface->GetInt16Value(state, 2);
  2554. if (spawn && spawn->IsEntity()) {
  2555. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2556. if (spawn->IsPlayer())
  2557. ((Player*)spawn)->SetCharSheetChanged(true);
  2558. }
  2559. return 0;
  2560. }
  2561. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2562. if (!lua_interface)
  2563. return 0;
  2564. Spawn* spawn = lua_interface->GetSpawn(state);
  2565. int16 value = lua_interface->GetInt16Value(state, 2);
  2566. if (spawn && spawn->IsEntity()) {
  2567. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2568. if (spawn->IsPlayer())
  2569. ((Player*)spawn)->SetCharSheetChanged(true);
  2570. }
  2571. return 0;
  2572. }
  2573. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2574. if (!lua_interface)
  2575. return 0;
  2576. Spawn* spawn = lua_interface->GetSpawn(state);
  2577. int16 value = lua_interface->GetInt16Value(state, 2);
  2578. if (spawn && spawn->IsEntity()) {
  2579. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2580. if (spawn->IsPlayer())
  2581. ((Player*)spawn)->SetCharSheetChanged(true);
  2582. }
  2583. return 0;
  2584. }
  2585. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2586. if (!lua_interface)
  2587. return 0;
  2588. Spawn* spawn = lua_interface->GetSpawn(state);
  2589. int16 value = lua_interface->GetInt16Value(state, 2);
  2590. if (spawn && spawn->IsEntity()) {
  2591. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2592. if (spawn->IsPlayer())
  2593. ((Player*)spawn)->SetCharSheetChanged(true);
  2594. }
  2595. return 0;
  2596. }
  2597. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2598. if (!lua_interface)
  2599. return 0;
  2600. Spawn* spawn = lua_interface->GetSpawn(state);
  2601. int8 value = lua_interface->GetInt8Value(state, 2);
  2602. if (spawn && spawn->IsEntity()) {
  2603. ((Entity*)spawn)->SetDeity(value);
  2604. if (spawn->IsPlayer())
  2605. ((Player*)spawn)->SetCharSheetChanged(true);
  2606. }
  2607. lua_interface->ResetFunctionStack(state);
  2608. return 0;
  2609. }
  2610. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2611. if (!lua_interface)
  2612. return 0;
  2613. Spawn* spawn = lua_interface->GetSpawn(state);
  2614. if (spawn && spawn->IsEntity()) {
  2615. int8 deity = ((Entity*)spawn)->GetDeity();
  2616. lua_interface->SetInt32Value(state, deity);
  2617. return 1;
  2618. }
  2619. return 0;
  2620. }
  2621. int EQ2Emu_lua_SetInt(lua_State* state) {
  2622. if (!lua_interface)
  2623. return 0;
  2624. Spawn* spawn = lua_interface->GetSpawn(state);
  2625. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2626. if (spawn && spawn->IsEntity()) {
  2627. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2628. if (spawn->IsPlayer())
  2629. ((Player*)spawn)->SetCharSheetChanged(true);
  2630. }
  2631. return 0;
  2632. }
  2633. int EQ2Emu_lua_SetWis(lua_State* state) {
  2634. if (!lua_interface)
  2635. return 0;
  2636. Spawn* spawn = lua_interface->GetSpawn(state);
  2637. float value = lua_interface->GetFloatValue(state, 2);
  2638. if (spawn && spawn->IsEntity()) {
  2639. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2640. if (spawn->IsPlayer())
  2641. ((Player*)spawn)->SetCharSheetChanged(true);
  2642. }
  2643. return 0;
  2644. }
  2645. int EQ2Emu_lua_SetSta(lua_State* state) {
  2646. if (!lua_interface)
  2647. return 0;
  2648. Spawn* spawn = lua_interface->GetSpawn(state);
  2649. float value = lua_interface->GetFloatValue(state, 2);
  2650. if (spawn && spawn->IsEntity()) {
  2651. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2652. if (spawn->IsPlayer())
  2653. ((Player*)spawn)->SetCharSheetChanged(true);
  2654. }
  2655. return 0;
  2656. }
  2657. int EQ2Emu_lua_SetStr(lua_State* state) {
  2658. if (!lua_interface)
  2659. return 0;
  2660. Spawn* spawn = lua_interface->GetSpawn(state);
  2661. float value = lua_interface->GetFloatValue(state, 2);
  2662. if (spawn && spawn->IsEntity()) {
  2663. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2664. if (spawn->IsPlayer())
  2665. ((Player*)spawn)->SetCharSheetChanged(true);
  2666. }
  2667. return 0;
  2668. }
  2669. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2670. if (!lua_interface)
  2671. return 0;
  2672. Spawn* spawn = lua_interface->GetSpawn(state);
  2673. float value = lua_interface->GetFloatValue(state, 2);
  2674. if (spawn && spawn->IsEntity()) {
  2675. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2676. if (spawn->IsPlayer())
  2677. ((Player*)spawn)->SetCharSheetChanged(true);
  2678. }
  2679. return 0;
  2680. }
  2681. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2682. if (!lua_interface)
  2683. return 0;
  2684. Spawn* spawn = lua_interface->GetSpawn(state);
  2685. if (spawn) {
  2686. lua_interface->SetInt32Value(state, spawn->GetHP());
  2687. return 1;
  2688. }
  2689. return 0;
  2690. }
  2691. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2692. if (!lua_interface)
  2693. return 0;
  2694. Spawn* spawn = lua_interface->GetSpawn(state);
  2695. if (spawn) {
  2696. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2697. return 1;
  2698. }
  2699. return 0;
  2700. }
  2701. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2702. if (!lua_interface)
  2703. return 0;
  2704. Spawn* spawn = lua_interface->GetSpawn(state);
  2705. if (spawn) {
  2706. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2707. return 1;
  2708. }
  2709. return 0;
  2710. }
  2711. int EQ2Emu_lua_GetName(lua_State* state) {
  2712. if (!lua_interface)
  2713. return 0;
  2714. Spawn* spawn = lua_interface->GetSpawn(state);
  2715. if (spawn) {
  2716. lua_interface->SetStringValue(state, spawn->GetName());
  2717. return 1;
  2718. }
  2719. return 0;
  2720. }
  2721. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2722. Spawn* spawn = lua_interface->GetSpawn(state);
  2723. if (spawn) {
  2724. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2725. return 1;
  2726. }
  2727. return 0;
  2728. }
  2729. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2730. if (!lua_interface)
  2731. return 0;
  2732. Spawn* spawn = lua_interface->GetSpawn(state);
  2733. if (spawn) {
  2734. lua_interface->SetInt32Value(state, spawn->GetPower());
  2735. return 1;
  2736. }
  2737. return 0;
  2738. }
  2739. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2740. if (!lua_interface)
  2741. return 0;
  2742. Spawn* spawn = lua_interface->GetSpawn(state);
  2743. if (spawn) {
  2744. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2745. return 1;
  2746. }
  2747. return 0;
  2748. }
  2749. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2750. if (!lua_interface)
  2751. return 0;
  2752. Spawn* spawn = lua_interface->GetSpawn(state);
  2753. if (spawn) {
  2754. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2755. return 1;
  2756. }
  2757. return 0;
  2758. }
  2759. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2760. if (!lua_interface)
  2761. return 0;
  2762. Spawn* spawn = lua_interface->GetSpawn(state);
  2763. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2764. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2765. if (spawn && spawn2) {
  2766. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2767. lua_interface->SetFloatValue(state, distance);
  2768. return 1;
  2769. }
  2770. return 0;
  2771. }
  2772. int EQ2Emu_lua_GetX(lua_State* state) {
  2773. if (!lua_interface)
  2774. return 0;
  2775. Spawn* spawn = lua_interface->GetSpawn(state);
  2776. if (spawn) {
  2777. lua_interface->SetFloatValue(state, spawn->GetX());
  2778. return 1;
  2779. }
  2780. return 0;
  2781. }
  2782. int EQ2Emu_lua_GetY(lua_State* state) {
  2783. if (!lua_interface)
  2784. return 0;
  2785. Spawn* spawn = lua_interface->GetSpawn(state);
  2786. if (spawn) {
  2787. lua_interface->SetFloatValue(state, spawn->GetY());
  2788. return 1;
  2789. }
  2790. return 0;
  2791. }
  2792. int EQ2Emu_lua_GetZ(lua_State* state) {
  2793. if (!lua_interface)
  2794. return 0;
  2795. Spawn* spawn = lua_interface->GetSpawn(state);
  2796. if (spawn) {
  2797. lua_interface->SetFloatValue(state, spawn->GetZ());
  2798. return 1;
  2799. }
  2800. return 0;
  2801. }
  2802. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2803. if (!lua_interface)
  2804. return 0;
  2805. Spawn* spawn = lua_interface->GetSpawn(state);
  2806. if (spawn) {
  2807. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2808. return 1;
  2809. }
  2810. return 0;
  2811. }
  2812. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2813. if (!lua_interface)
  2814. return 0;
  2815. Spawn* spawn = lua_interface->GetSpawn(state);
  2816. if (spawn) {
  2817. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2818. return 1;
  2819. }
  2820. return 0;
  2821. }
  2822. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2823. if (!lua_interface)
  2824. return 0;
  2825. Spawn* spawn = lua_interface->GetSpawn(state);
  2826. if (spawn) {
  2827. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2828. return 1;
  2829. }
  2830. return 0;
  2831. }
  2832. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2833. if (!lua_interface)
  2834. return 0;
  2835. Spawn* spawn = lua_interface->GetSpawn(state);
  2836. if (spawn && spawn->IsEntity()) {
  2837. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2838. return 1;
  2839. }
  2840. return 0;
  2841. }
  2842. int EQ2Emu_lua_GetInt(lua_State* state) {
  2843. if (!lua_interface)
  2844. return 0;
  2845. Spawn* spawn = lua_interface->GetSpawn(state);
  2846. if (spawn && spawn->IsEntity()) {
  2847. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2848. return 1;
  2849. }
  2850. return 0;
  2851. }
  2852. int EQ2Emu_lua_GetWis(lua_State* state) {
  2853. if (!lua_interface)
  2854. return 0;
  2855. Spawn* spawn = lua_interface->GetSpawn(state);
  2856. if (spawn && spawn->IsEntity()) {
  2857. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2858. return 1;
  2859. }
  2860. return 0;
  2861. }
  2862. int EQ2Emu_lua_GetSta(lua_State* state) {
  2863. if (!lua_interface)
  2864. return 0;
  2865. Spawn* spawn = lua_interface->GetSpawn(state);
  2866. if (spawn && spawn->IsEntity()) {
  2867. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2868. return 1;
  2869. }
  2870. return 0;
  2871. }
  2872. int EQ2Emu_lua_GetStr(lua_State* state) {
  2873. if (!lua_interface)
  2874. return 0;
  2875. Spawn* spawn = lua_interface->GetSpawn(state);
  2876. if (spawn && spawn->IsEntity()) {
  2877. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2878. return 1;
  2879. }
  2880. return 0;
  2881. }
  2882. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2883. if (!lua_interface)
  2884. return 0;
  2885. Spawn* spawn = lua_interface->GetSpawn(state);
  2886. if (spawn && spawn->IsEntity()) {
  2887. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2888. return 1;
  2889. }
  2890. return 0;
  2891. }
  2892. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2893. if (!lua_interface)
  2894. return 0;
  2895. Spawn* spawn = lua_interface->GetSpawn(state);
  2896. if (spawn && spawn->IsEntity()) {
  2897. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2898. return 1;
  2899. }
  2900. return 0;
  2901. }
  2902. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2903. if (!lua_interface)
  2904. return 0;
  2905. Spawn* spawn = lua_interface->GetSpawn(state);
  2906. if (spawn && spawn->IsEntity()) {
  2907. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2908. return 1;
  2909. }
  2910. return 0;
  2911. }
  2912. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2913. if (!lua_interface)
  2914. return 0;
  2915. Spawn* spawn = lua_interface->GetSpawn(state);
  2916. if (spawn && spawn->IsEntity()) {
  2917. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2918. return 1;
  2919. }
  2920. return 0;
  2921. }
  2922. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2923. if (!lua_interface)
  2924. return 0;
  2925. Spawn* spawn = lua_interface->GetSpawn(state);
  2926. if (spawn && spawn->IsEntity()) {
  2927. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2928. return 1;
  2929. }
  2930. return 0;
  2931. }
  2932. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2933. if (!lua_interface)
  2934. return 0;
  2935. Spawn* spawn = lua_interface->GetSpawn(state);
  2936. if (spawn && spawn->IsEntity()) {
  2937. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2938. return 1;
  2939. }
  2940. return 0;
  2941. }
  2942. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2943. if (!lua_interface)
  2944. return 0;
  2945. Spawn* player = lua_interface->GetSpawn(state);
  2946. if (!player || !player->IsPlayer()) {
  2947. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2948. return 0;
  2949. }
  2950. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2951. if (quest_id <= 0) {
  2952. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2953. return 0;
  2954. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2955. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2956. return 0;
  2957. }
  2958. int32 step = lua_interface->GetInt32Value(state, 3);
  2959. if (step > 0) {
  2960. Client* client = player->GetZone()->GetClientBySpawn(player);
  2961. if (client)
  2962. client->AddPendingQuestUpdate(quest_id, step);
  2963. } else {
  2964. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2965. }
  2966. return 0;
  2967. }
  2968. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2969. Spawn* player = lua_interface->GetSpawn(state);
  2970. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2971. int32 step = lua_interface->GetInt32Value(state, 3);
  2972. int32 progress = lua_interface->GetInt32Value(state, 4);
  2973. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2974. Client* client = player->GetZone()->GetClientBySpawn(player);
  2975. if (client)
  2976. client->AddPendingQuestUpdate(quest_id, step, progress);
  2977. }
  2978. return 0;
  2979. }
  2980. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2981. if (!lua_interface)
  2982. return 0;
  2983. Spawn* player = lua_interface->GetSpawn(state);
  2984. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2985. if (player && player->IsPlayer() && quest_id > 0) {
  2986. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2987. return 1;
  2988. }
  2989. return 0;
  2990. }
  2991. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2992. if (!lua_interface)
  2993. return 0;
  2994. Spawn* player = lua_interface->GetSpawn(state);
  2995. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2996. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2997. if (player && player->IsPlayer() && quest_id > 0) {
  2998. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2999. return 1;
  3000. }
  3001. return 0;
  3002. }
  3003. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3004. if (!lua_interface)
  3005. return 0;
  3006. Spawn* player = lua_interface->GetSpawn(state);
  3007. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3008. if (player && player->IsPlayer() && quest_id > 0) {
  3009. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3010. return 1;
  3011. }
  3012. return 0;
  3013. }
  3014. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3015. if (!lua_interface)
  3016. return 0;
  3017. Quest* quest = lua_interface->GetQuest(state);
  3018. string name = lua_interface->GetStringValue(state, 2);
  3019. string type = lua_interface->GetStringValue(state, 3);
  3020. string zone = lua_interface->GetStringValue(state, 4);
  3021. int16 level = lua_interface->GetInt16Value(state, 5);
  3022. string description = lua_interface->GetStringValue(state, 6);
  3023. bool load = true;
  3024. if (!quest) {
  3025. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3026. load = false;
  3027. }
  3028. if (load && name.length() == 0) {
  3029. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3030. load = false;
  3031. }
  3032. if (load && type.length() == 0) {
  3033. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3034. load = false;
  3035. }
  3036. if (load && zone.length() == 0) {
  3037. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3038. load = false;
  3039. }
  3040. if (load && description.length() == 0) {
  3041. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3042. load = false;
  3043. }
  3044. if (load && level == 0) {
  3045. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3046. load = false;
  3047. }
  3048. if (load)
  3049. quest->RegisterQuest(name, type, zone, level, description);
  3050. return 0;
  3051. }
  3052. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3053. if (!lua_interface)
  3054. return 0;
  3055. Quest* quest = lua_interface->GetQuest(state);
  3056. if (quest) {
  3057. int8 level = lua_interface->GetInt16Value(state, 2);
  3058. quest->SetPrereqLevel(level);
  3059. }
  3060. return 0;
  3061. }
  3062. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3063. if (!lua_interface)
  3064. return 0;
  3065. Quest* quest = lua_interface->GetQuest(state);
  3066. if (quest) {
  3067. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3068. quest->AddPrereqQuest(quest_id);
  3069. }
  3070. return 0;
  3071. }
  3072. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3073. if (!lua_interface)
  3074. return 0;
  3075. Quest* quest = lua_interface->GetQuest(state);
  3076. if (quest) {
  3077. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3078. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3079. if (quantity == 0)
  3080. quantity = 1;
  3081. Item* master_item = master_item_list.GetItem(item_id);
  3082. if (master_item) {
  3083. Item* item = new Item(master_item);
  3084. item->details.count = quantity;
  3085. quest->AddPrereqItem(item);
  3086. }
  3087. }
  3088. return 0;
  3089. }
  3090. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3091. if (!lua_interface)
  3092. return 0;
  3093. Spawn* player = lua_interface->GetSpawn(state);
  3094. if(!player || !player->IsPlayer()) {
  3095. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3096. return 0;
  3097. }
  3098. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3099. if (quest_id > 0) {
  3100. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3101. return 1;
  3102. } else {
  3103. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3104. }
  3105. return 0;
  3106. }
  3107. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3108. if (!lua_interface)
  3109. return 0;
  3110. Quest* quest = lua_interface->GetQuest(state);
  3111. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3112. if (quest && spawn_id > 0)
  3113. quest->SetQuestReturnNPC(spawn_id);
  3114. return 0;
  3115. }
  3116. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3117. if (!lua_interface)
  3118. return 0;
  3119. Spawn* spawn = lua_interface->GetSpawn(state);
  3120. if (!spawn) {
  3121. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3122. return 0;
  3123. }
  3124. int32 time = lua_interface->GetInt32Value(state, 2);
  3125. if (time <= 0) {
  3126. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3127. return 0;
  3128. }
  3129. string function = lua_interface->GetStringValue(state, 3);
  3130. if (function.length() == 0) {
  3131. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3132. return 0;
  3133. }
  3134. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3135. Spawn* player = lua_interface->GetSpawn(state, 5);
  3136. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3137. timer->timer = Timer::GetCurrentTime2() + time;
  3138. timer->function = function;
  3139. timer->spawn = spawn->GetID();
  3140. timer->player = player ? player->GetID() : 0;
  3141. if (max_count == 0)
  3142. max_count = 1;
  3143. timer->max_count = max_count;
  3144. timer->current_count = 0;
  3145. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3146. return 0;
  3147. }
  3148. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3149. if (!lua_interface)
  3150. return 0;
  3151. Spawn* player = lua_interface->GetSpawn(state);
  3152. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3153. if (player && player->IsPlayer() && quest_id > 0) {
  3154. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3155. return 1;
  3156. }
  3157. return 0;
  3158. }
  3159. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3160. if (!lua_interface)
  3161. return 0;
  3162. Spawn* player = lua_interface->GetSpawn(state);
  3163. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3164. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3165. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3166. if (quest)
  3167. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3168. return 1;
  3169. }
  3170. return 0;
  3171. }
  3172. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3173. if (!lua_interface)
  3174. return 0;
  3175. Spawn* player = lua_interface->GetSpawn(state);
  3176. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3177. if (player && player->IsPlayer() && quest_id > 0) {
  3178. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3179. return 1;
  3180. }
  3181. return 0;
  3182. }
  3183. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3184. if (!lua_interface)
  3185. return 0;
  3186. Spawn* npc = lua_interface->GetSpawn(state);
  3187. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3188. if (npc && !npc->IsPlayer() && quest_id > 0)
  3189. npc->AddProvidedQuest(quest_id);
  3190. return 0;
  3191. }
  3192. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3193. if (!lua_interface)
  3194. return 0;
  3195. Spawn* npc = lua_interface->GetSpawn(state);
  3196. Spawn* player = lua_interface->GetSpawn(state, 2);
  3197. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3198. bool forced = lua_interface->GetBooleanValue(state, 4);
  3199. /* NPC is allowed to be null */
  3200. if (player && player->IsPlayer() && quest_id > 0) {
  3201. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3202. if (master_quest) {
  3203. Client* client = player->GetZone()->GetClientBySpawn(player);
  3204. if (!client) {
  3205. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3206. }
  3207. Quest* quest = new Quest(master_quest);
  3208. if (!quest) {
  3209. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3210. }
  3211. if (client && quest) {
  3212. if (npc)
  3213. quest->SetQuestGiver(npc->GetDatabaseID());
  3214. else
  3215. quest->SetQuestGiver(0);
  3216. client->AddPendingQuest(quest, forced);
  3217. }
  3218. }
  3219. else {
  3220. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3221. }
  3222. }
  3223. else {
  3224. 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);
  3225. }
  3226. return 0;
  3227. }
  3228. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3229. if (!lua_interface)
  3230. return 0;
  3231. Quest* quest = lua_interface->GetQuest(state);
  3232. if (quest) {
  3233. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3234. quest->AddPrereqClass(class_id);
  3235. }
  3236. return 0;
  3237. }
  3238. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3239. if (!lua_interface)
  3240. return 0;
  3241. Quest* quest = lua_interface->GetQuest(state);
  3242. if (quest) {
  3243. int8 race = lua_interface->GetInt8Value(state, 2);
  3244. quest->AddPrereqRace(race);
  3245. }
  3246. return 0;
  3247. }
  3248. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3249. if (!lua_interface)
  3250. return 0;
  3251. Quest* quest = lua_interface->GetQuest(state);
  3252. if (quest) {
  3253. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3254. quest->AddPrereqModelType(model_type);
  3255. }
  3256. return 0;
  3257. }
  3258. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3259. if (!lua_interface)
  3260. return 0;
  3261. Quest* quest = lua_interface->GetQuest(state);
  3262. if (!quest) {
  3263. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3264. return 0;
  3265. }
  3266. int8 level = lua_interface->GetInt8Value(state, 2);
  3267. quest->SetPrereqTSLevel(level);
  3268. return 0;
  3269. }
  3270. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3271. if (!lua_interface)
  3272. return 0;
  3273. Quest* quest = lua_interface->GetQuest(state);
  3274. if (!quest) {
  3275. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3276. return 0;
  3277. }
  3278. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3279. quest->AddPrereqTradeskillClass(class_id);
  3280. return 0;
  3281. }
  3282. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3283. if (!lua_interface)
  3284. return 0;
  3285. Quest* quest = lua_interface->GetQuest(state);
  3286. if (quest) {
  3287. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3288. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3289. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3290. quest->AddPrereqFaction(faction_id, min, max);
  3291. }
  3292. return 0;
  3293. }
  3294. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3295. if (!lua_interface)
  3296. return 0;
  3297. Quest* quest = lua_interface->GetQuest(state);
  3298. if (quest) {
  3299. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3300. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3301. if (quantity == 0)
  3302. quantity = 1;
  3303. Item* master_item = master_item_list.GetItem(item_id);
  3304. if (master_item) {
  3305. Item* item = new Item(master_item);
  3306. item->details.count = quantity;
  3307. quest->AddSelectableRewardItem(item);
  3308. }
  3309. }
  3310. return 0;
  3311. }
  3312. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3313. if (!lua_interface)
  3314. return 0;
  3315. Quest* quest = lua_interface->GetQuest(state);
  3316. if (quest) {
  3317. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3318. vector<Item*>* items = quest->GetRewardItems();
  3319. if (items) {
  3320. vector<Item*>::iterator itr;
  3321. for (itr = items->begin(); itr != items->end(); itr++) {
  3322. if (*itr && (*itr)->details.item_id == item_id) {
  3323. lua_interface->SetBooleanValue(state, true);
  3324. return 1;
  3325. }
  3326. }
  3327. }
  3328. }
  3329. lua_interface->SetBooleanValue(state, false);
  3330. return 1;
  3331. }
  3332. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3333. if (!lua_interface)
  3334. return 0;
  3335. Quest* quest = lua_interface->GetQuest(state);
  3336. if (quest) {
  3337. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3338. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3339. if (quantity == 0)
  3340. quantity = 1;
  3341. Item* master_item = master_item_list.GetItem(item_id);
  3342. if (master_item) {
  3343. Item* item = new Item(master_item);
  3344. item->details.count = quantity;
  3345. quest->AddRewardItem(item);
  3346. }
  3347. }
  3348. return 0;
  3349. }
  3350. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3351. if (!lua_interface)
  3352. return 0;
  3353. Quest* quest = lua_interface->GetQuest(state);
  3354. if (quest) {
  3355. int32 copper = lua_interface->GetInt32Value(state, 2);
  3356. int32 silver = lua_interface->GetInt32Value(state, 3);
  3357. int32 gold = lua_interface->GetInt32Value(state, 4);
  3358. int32 plat = lua_interface->GetInt32Value(state, 5);
  3359. quest->AddRewardCoins(copper, silver, gold, plat);
  3360. }
  3361. return 0;
  3362. }
  3363. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3364. if (!lua_interface)
  3365. return 0;
  3366. Quest* quest = lua_interface->GetQuest(state);
  3367. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3368. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3369. if (quest && faction_id > 0 && amount != 0)
  3370. quest->AddRewardFaction(faction_id, amount);
  3371. return 0;
  3372. }
  3373. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3374. if (!lua_interface)
  3375. return 0;
  3376. Quest* quest = lua_interface->GetQuest(state);
  3377. if (quest) {
  3378. int32 status = lua_interface->GetInt32Value(state, 2);
  3379. quest->SetRewardStatus(status);
  3380. }
  3381. return 0;
  3382. }
  3383. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3384. if (!lua_interface)
  3385. return 0;
  3386. Quest* quest = lua_interface->GetQuest(state);
  3387. if (quest) {
  3388. int32 status = lua_interface->GetInt32Value(state, 2);
  3389. quest->SetStatusTmpReward(status);
  3390. }
  3391. return 0;
  3392. }
  3393. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3394. if (!lua_interface)
  3395. return 0;
  3396. Quest* quest = lua_interface->GetQuest(state);
  3397. if (quest) {
  3398. int64 coins = lua_interface->GetInt64Value(state, 2);
  3399. quest->SetCoinTmpReward(coins);
  3400. }
  3401. return 0;
  3402. }
  3403. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3404. if (!lua_interface)
  3405. return 0;
  3406. Quest* quest = lua_interface->GetQuest(state);
  3407. if (quest) {
  3408. string comment = lua_interface->GetStringValue(state, 2);
  3409. quest->SetRewardComment(comment);
  3410. }
  3411. return 0;
  3412. }
  3413. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3414. if (!lua_interface)
  3415. return 0;
  3416. Quest* quest = lua_interface->GetQuest(state);
  3417. if (quest) {
  3418. int32 exp = lua_interface->GetInt32Value(state, 2);
  3419. quest->SetRewardXP(exp);
  3420. }
  3421. return 0;
  3422. }
  3423. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3424. Quest* quest = lua_interface->GetQuest(state);
  3425. if (quest) {
  3426. int32 step = lua_interface->GetInt32Value(state, 2);
  3427. string description = lua_interface->GetStringValue(state, 3);
  3428. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3429. float percentage = lua_interface->GetFloatValue(state, 5);
  3430. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3431. int16 icon = lua_interface->GetInt16Value(state, 7);
  3432. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3433. const char* taskgroup = 0;
  3434. if (str_taskgroup.length() > 0)
  3435. taskgroup = str_taskgroup.c_str();
  3436. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3437. if (quest_step && icon && quantity > 0)
  3438. quest_step->SetIcon(icon);
  3439. }
  3440. return 0;
  3441. }
  3442. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3443. if (!lua_interface)
  3444. return 0;
  3445. Quest* quest = lua_interface->GetQuest(state);
  3446. if (quest) {
  3447. int32 step = lua_interface->GetInt32Value(state, 2);
  3448. string description = lua_interface->GetStringValue(state, 3);
  3449. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3450. float percentage = lua_interface->GetFloatValue(state, 5);
  3451. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3452. int16 icon = lua_interface->GetInt16Value(state, 7);
  3453. const char* taskgroup = 0;
  3454. if (str_taskgroup.length() > 0)
  3455. taskgroup = str_taskgroup.c_str();
  3456. int32 npc_id = 0;
  3457. vector<int32>* ids = 0;
  3458. int i = 0;
  3459. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3460. if (ids == 0)
  3461. ids = new vector<int32>;
  3462. ids->push_back(npc_id);
  3463. i++;
  3464. }
  3465. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3466. if (quest_step && icon > 0 && quantity > 0)
  3467. quest_step->SetIcon(icon);
  3468. if (quest->GetPlayer()) {
  3469. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3470. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3471. }
  3472. safe_delete(ids);
  3473. }
  3474. return 0;
  3475. }
  3476. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3477. if (!lua_interface)
  3478. return 0;
  3479. Quest* quest = lua_interface->GetQuest(state);
  3480. if (quest) {
  3481. int32 step = lua_interface->GetInt32Value(state, 2);
  3482. string description = lua_interface->GetStringValue(state, 3);
  3483. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3484. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3485. int16 icon = lua_interface->GetInt16Value(state, 6);
  3486. const char* taskgroup = 0;
  3487. if (str_taskgroup.length() > 0)
  3488. taskgroup = str_taskgroup.c_str();
  3489. int32 npc_id = 0;
  3490. vector<int32>* ids = 0;
  3491. int i = 0;
  3492. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3493. if (ids == 0)
  3494. ids = new vector<int32>;
  3495. ids->push_back(npc_id);
  3496. i++;
  3497. }
  3498. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3499. if (quest_step && icon > 0)
  3500. quest_step->SetIcon(icon);
  3501. if (quest->GetPlayer()) {
  3502. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3503. if(client)
  3504. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3505. }
  3506. safe_delete(ids);
  3507. }
  3508. return 0;
  3509. }
  3510. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3511. if (!lua_interface)
  3512. return 0;
  3513. Quest* quest = lua_interface->GetQuest(state);
  3514. if (quest) {
  3515. int32 step = lua_interface->GetInt32Value(state, 2);
  3516. string description = lua_interface->GetStringValue(state, 3);
  3517. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3518. float percentage = lua_interface->GetFloatValue(state, 5);
  3519. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3520. int16 icon = lua_interface->GetInt16Value(state, 7);
  3521. const char* taskgroup = 0;
  3522. if (str_taskgroup.length() > 0)
  3523. taskgroup = str_taskgroup.c_str();
  3524. int32 item_id = 0;
  3525. vector<int32>* ids = 0;
  3526. int i = 0;
  3527. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3528. if (ids == 0)
  3529. ids = new vector<int32>;
  3530. ids->push_back(item_id);
  3531. i++;
  3532. }
  3533. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3534. if (quest_step && icon > 0 && quantity > 0)
  3535. quest_step->SetIcon(icon);
  3536. if (quest->GetPlayer()) {
  3537. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3538. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3539. }
  3540. safe_delete(ids);
  3541. }
  3542. return 0;
  3543. }
  3544. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3545. if (!lua_interface)
  3546. return 0;
  3547. Quest* quest = lua_interface->GetQuest(state);
  3548. if (quest) {
  3549. int32 step = lua_interface->GetInt32Value(state, 2);
  3550. string description = lua_interface->GetStringValue(state, 3);
  3551. float max_variation = lua_interface->GetFloatValue(state, 4);
  3552. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3553. int16 icon = lua_interface->GetInt16Value(state, 6);
  3554. const char* taskgroup = 0;
  3555. if (str_taskgroup.length() > 0)
  3556. taskgroup = str_taskgroup.c_str();
  3557. vector<Location>* locations = 0;
  3558. int i = 7;
  3559. while (true) {
  3560. Location loc;
  3561. loc.x = lua_interface->GetFloatValue(state, i);
  3562. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3563. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3564. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3565. break;
  3566. if (locations == 0)
  3567. locations = new vector<Location>;
  3568. locations->push_back(loc);
  3569. i += 3;
  3570. }
  3571. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3572. if (quest_step && icon > 0)
  3573. quest_step->SetIcon(icon);
  3574. if (quest->GetPlayer()) {
  3575. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3576. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3577. }
  3578. }
  3579. return 0;
  3580. }
  3581. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3582. if (!lua_interface)
  3583. return 0;
  3584. Quest* quest = lua_interface->GetQuest(state);
  3585. if (quest) {
  3586. int32 step = lua_interface->GetInt32Value(state, 2);
  3587. string description = lua_interface->GetStringValue(state, 3);
  3588. float max_variation = lua_interface->GetFloatValue(state, 4);
  3589. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3590. int16 icon = lua_interface->GetInt16Value(state, 6);
  3591. const char* taskgroup = 0;
  3592. if (str_taskgroup.length() > 0)
  3593. taskgroup = str_taskgroup.c_str();
  3594. vector<Location>* locations = 0;
  3595. int i = 7;
  3596. while (true) {
  3597. Location loc;
  3598. loc.x = lua_interface->GetFloatValue(state, i);
  3599. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3600. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3601. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3602. break;
  3603. if (locations == 0)
  3604. locations = new vector<Location>;
  3605. locations->push_back(loc);
  3606. i += 3;
  3607. }
  3608. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3609. if (quest_step && icon > 0)
  3610. quest_step->SetIcon(icon);
  3611. if (quest->GetPlayer()) {
  3612. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3613. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3614. }
  3615. }
  3616. return 0;
  3617. }
  3618. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3619. Quest* quest = lua_interface->GetQuest(state);
  3620. if (quest) {
  3621. int32 step = lua_interface->GetInt32Value(state, 2);
  3622. string description = lua_interface->GetStringValue(state, 3);
  3623. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3624. float percentage = lua_interface->GetFloatValue(state, 5);
  3625. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3626. int16 icon = lua_interface->GetInt16Value(state, 7);
  3627. const char* taskgroup = 0;
  3628. if (str_taskgroup.length() > 0)
  3629. taskgroup = str_taskgroup.c_str();
  3630. int32 spell_id = 0;
  3631. vector<int32>* ids = 0;
  3632. int i = 0;
  3633. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3634. if (ids == 0)
  3635. ids = new vector<int32>;
  3636. ids->push_back(spell_id);
  3637. i++;
  3638. }
  3639. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3640. if (quest_step && icon > 0 && quantity > 0)
  3641. quest_step->SetIcon(icon);
  3642. if (quest->GetPlayer()) {
  3643. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3644. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3645. }
  3646. safe_delete(ids);
  3647. }
  3648. return 0;
  3649. }
  3650. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3651. if (!lua_interface)
  3652. return 0;
  3653. Quest* quest = lua_interface->GetQuest(state);
  3654. if (quest) {
  3655. int32 step = lua_interface->GetInt32Value(state, 2);
  3656. string description = lua_interface->GetStringValue(state, 3);
  3657. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3658. float percentage = lua_interface->GetFloatValue(state, 5);
  3659. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3660. int16 icon = lua_interface->GetInt16Value(state, 7);
  3661. const char* taskgroup = 0;
  3662. if (str_taskgroup.length() > 0)
  3663. taskgroup = str_taskgroup.c_str();
  3664. int32 item_id = 0;
  3665. vector<int32>* ids = 0;
  3666. int i = 0;
  3667. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3668. if (ids == 0)
  3669. ids = new vector<int32>;
  3670. ids->push_back(item_id);
  3671. i++;
  3672. }
  3673. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3674. if (quest_step && icon > 0 && quantity > 0)
  3675. quest_step->SetIcon(icon);
  3676. if (quest->GetPlayer()) {
  3677. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3678. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3679. }
  3680. safe_delete(ids);
  3681. }
  3682. return 0;
  3683. }
  3684. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3685. if (!lua_interface)
  3686. return 0;
  3687. Quest* quest = lua_interface->GetQuest(state);
  3688. if (quest) {
  3689. int32 step = lua_interface->GetInt32Value(state, 2);
  3690. string description = lua_interface->GetStringValue(state, 3);
  3691. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3692. float percentage = lua_interface->GetFloatValue(state, 5);
  3693. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3694. int16 icon = lua_interface->GetInt16Value(state, 7);
  3695. const char* taskgroup = 0;
  3696. if (str_taskgroup.length() > 0)
  3697. taskgroup = str_taskgroup.c_str();
  3698. int32 item_id = 0;
  3699. vector<int32>* ids = 0;
  3700. int i = 0;
  3701. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3702. if (ids == 0)
  3703. ids = new vector<int32>;
  3704. ids->push_back(item_id);
  3705. i++;
  3706. }
  3707. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3708. if (quest_step && icon > 0 && quantity > 0)
  3709. quest_step->SetIcon(icon);
  3710. if (quest->GetPlayer()) {
  3711. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3712. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3713. }
  3714. safe_delete(ids);
  3715. }
  3716. return 0;
  3717. }
  3718. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3719. if (!lua_interface)
  3720. return 0;
  3721. Quest* quest = lua_interface->GetQuest(state);
  3722. if (quest) {
  3723. string action = lua_interface->GetStringValue(state, 2);
  3724. if (action.length() > 0)
  3725. quest->SetCompleteAction(action);
  3726. }
  3727. return 0;
  3728. }
  3729. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3730. if (!lua_interface)
  3731. return 0;
  3732. Quest* quest = lua_interface->GetQuest(state);
  3733. if (quest) {
  3734. int32 step = lua_interface->GetInt32Value(state, 2);
  3735. string action = lua_interface->GetStringValue(state, 3);
  3736. if (step > 0 && action.length() > 0)
  3737. quest->AddCompleteAction(step, action);
  3738. }
  3739. return 0;
  3740. }
  3741. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3742. if (!lua_interface)
  3743. return 0;
  3744. Quest* quest = lua_interface->GetQuest(state);
  3745. if (quest) {
  3746. int32 step = lua_interface->GetInt32Value(state, 2);
  3747. string action = lua_interface->GetStringValue(state, 3);
  3748. if (step > 0 && action.length() > 0)
  3749. quest->AddProgressAction(step, action);
  3750. }
  3751. return 0;
  3752. }
  3753. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3754. if (!lua_interface)
  3755. return 0;
  3756. Quest* quest = lua_interface->GetQuest(state);
  3757. string description = lua_interface->GetStringValue(state, 2);
  3758. if (quest && description.length() > 0)
  3759. quest->SetDescription(description);
  3760. return 0;
  3761. }
  3762. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3763. if (!lua_interface)
  3764. return 0;
  3765. Quest* quest = lua_interface->GetQuest(state);
  3766. string description = lua_interface->GetStringValue(state, 2);
  3767. if (quest && description.length() > 0)
  3768. quest->SetCompletedDescription(description);
  3769. return 0;
  3770. }
  3771. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3772. if (!lua_interface)
  3773. return 0;
  3774. Quest* quest = lua_interface->GetQuest(state);
  3775. int32 step = lua_interface->GetInt32Value(state, 2);
  3776. string description = lua_interface->GetStringValue(state, 3);
  3777. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3778. if (quest && step > 0 && description.length() > 0) {
  3779. quest->SetTaskGroupDescription(step, description, display_bullets);
  3780. /* if (quest->GetPlayer()) {
  3781. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3782. if (client)
  3783. client->SendQuestUpdateStep(quest, step, false);
  3784. }*/
  3785. }
  3786. return 0;
  3787. }
  3788. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3789. if (!lua_interface)
  3790. return 0;
  3791. Quest* quest = lua_interface->GetQuest(state);
  3792. int32 step = lua_interface->GetInt32Value(state, 2);
  3793. string description = lua_interface->GetStringValue(state, 3);
  3794. if (quest && step > 0 && description.length() > 0) {
  3795. quest->SetStepDescription(step, description);
  3796. /*if (quest->GetPlayer()) {
  3797. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3798. if (client)
  3799. client->SendQuestUpdateStepImmediately(quest, step);
  3800. }*/
  3801. }
  3802. return 0;
  3803. }
  3804. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3805. Quest* quest = lua_interface->GetQuest(state);
  3806. string zone = lua_interface->GetStringValue(state, 2);
  3807. if (quest && zone.length() > 0)
  3808. quest->SetZone(zone);
  3809. return 0;
  3810. }
  3811. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3812. if (!lua_interface)
  3813. return 0;
  3814. Quest* quest = lua_interface->GetQuest(state);
  3815. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3816. lua_interface->ResetFunctionStack(state);
  3817. if (quest && spawn) {
  3818. if (spawn->IsPlayer()) {
  3819. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3820. if (client)
  3821. {
  3822. client->AddPendingQuestAcceptReward(quest);
  3823. client->AddPendingQuestReward(quest);
  3824. }
  3825. }
  3826. }
  3827. return 0;
  3828. }
  3829. int EQ2Emu_lua_Harvest(lua_State* state) {
  3830. if (!lua_interface)
  3831. return 0;
  3832. Spawn* player = lua_interface->GetSpawn(state);
  3833. Spawn* node = lua_interface->GetSpawn(state, 2);
  3834. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3835. Client* client = player->GetZone()->GetClientBySpawn(player);
  3836. if (client) {
  3837. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3838. ((GroundSpawn*)node)->ProcessHarvest(client);
  3839. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3840. player->GetZone()->RemoveSpawn(node, true);
  3841. }
  3842. }
  3843. else if (player && player->IsPlayer()) {
  3844. Client* client = player->GetZone()->GetClientBySpawn(player);
  3845. if (client)
  3846. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3847. }
  3848. return 0;
  3849. }
  3850. int EQ2Emu_lua_Bind(lua_State* state) {
  3851. if (!lua_interface)
  3852. return 0;
  3853. Spawn* spawn = lua_interface->GetSpawn(state);
  3854. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3855. float x = lua_interface->GetFloatValue(state, 3);
  3856. float y = lua_interface->GetFloatValue(state, 4);
  3857. float z = lua_interface->GetFloatValue(state, 5);
  3858. float h = lua_interface->GetFloatValue(state, 6);
  3859. if (!spawn) {
  3860. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3861. return 0;
  3862. }
  3863. if (!spawn->IsPlayer()) {
  3864. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3865. return 0;
  3866. }
  3867. if (zone_id == 0) {
  3868. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3869. if (!client) {
  3870. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3871. return 0;
  3872. }
  3873. if (!client->Bind())
  3874. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3875. }
  3876. else {
  3877. Player* player = (Player*)spawn;
  3878. player->GetPlayerInfo()->SetBindZone(zone_id);
  3879. player->GetPlayerInfo()->SetBindX(x);
  3880. player->GetPlayerInfo()->SetBindY(y);
  3881. player->GetPlayerInfo()->SetBindZ(z);
  3882. player->GetPlayerInfo()->SetBindHeading(h);
  3883. }
  3884. return 0;
  3885. }
  3886. int EQ2Emu_lua_Gate(lua_State* state) {
  3887. if (!lua_interface)
  3888. return 0;
  3889. Spawn* spawn = lua_interface->GetSpawn(state);
  3890. if (spawn) {
  3891. if (spawn->IsPlayer()) {
  3892. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3893. if (client) {
  3894. if (!client->Gate())
  3895. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3896. }
  3897. }
  3898. }
  3899. return 0;
  3900. }
  3901. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3902. if (!lua_interface)
  3903. return 0;
  3904. bool ret = false;
  3905. Spawn* spawn = lua_interface->GetSpawn(state);
  3906. if (spawn) {
  3907. if (spawn->IsPlayer()) {
  3908. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3909. if (client)
  3910. ret = client->BindAllowed();
  3911. }
  3912. }
  3913. lua_interface->SetBooleanValue(state, ret);
  3914. return 1;
  3915. }
  3916. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3917. if (!lua_interface)
  3918. return 0;
  3919. bool ret = false;
  3920. Spawn* spawn = lua_interface->GetSpawn(state);
  3921. if (spawn) {
  3922. if (spawn->IsPlayer()) {
  3923. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3924. if (client)
  3925. ret = client->GateAllowed();
  3926. }
  3927. }
  3928. lua_interface->SetBooleanValue(state, ret);
  3929. return 1;
  3930. }
  3931. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3932. Spawn* spawn = lua_interface->GetSpawn(state);
  3933. if (spawn) {
  3934. lua_interface->SetBooleanValue(state, spawn->Alive());
  3935. return 1;
  3936. }
  3937. return 0;
  3938. }
  3939. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3940. if (!lua_interface)
  3941. return 0;
  3942. Spawn* spawn = lua_interface->GetSpawn(state);
  3943. if (spawn && spawn->IsEntity()) {
  3944. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3945. return 1;
  3946. }
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3950. Spawn* spawn = lua_interface->GetSpawn(state);
  3951. string message = lua_interface->GetStringValue(state, 2);
  3952. string color_str = lua_interface->GetStringValue(state, 3);
  3953. int8 color = CHANNEL_NARRATIVE;
  3954. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3955. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3956. if (client) {
  3957. if (color_str.length() > 0) {
  3958. // leave for backwards compat, but all future should just use the number
  3959. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3960. color = CHANNEL_COLOR_RED;
  3961. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3962. color = CHANNEL_COLOR_YELLOW;
  3963. else
  3964. {
  3965. // use a number to specify the channel as per Commands/Commands.h defines
  3966. color = (int8)atoul(color_str.c_str());
  3967. }
  3968. }
  3969. client->SimpleMessage(color, message.c_str());
  3970. }
  3971. }
  3972. return 0;
  3973. }
  3974. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3975. Spawn* spawn = lua_interface->GetSpawn(state);
  3976. string message = lua_interface->GetStringValue(state, 2);
  3977. int8 red = lua_interface->GetInt8Value(state, 3);
  3978. int8 green = lua_interface->GetInt8Value(state, 4);
  3979. int8 blue = lua_interface->GetInt8Value(state, 5);
  3980. if (!spawn) {
  3981. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3982. return 0;
  3983. }
  3984. int32 words = ::CountWordsInString(message.c_str());
  3985. if (words < 5)
  3986. words = 5;
  3987. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3988. if (client)
  3989. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3990. return 0;
  3991. }
  3992. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3993. Spawn* spawn = lua_interface->GetSpawn(state);
  3994. int8 param = lua_interface->GetInt8Value(state, 2);
  3995. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3996. int8 value = lua_interface->GetInt8Value(state, 4);
  3997. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3998. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3999. if (client) {
  4000. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4001. switch (param) {
  4002. case 1: {
  4003. packet->setDataByName("parameter1", param_value);
  4004. break;
  4005. }
  4006. case 2: {
  4007. packet->setDataByName("parameter2", param_value);
  4008. break;
  4009. }
  4010. case 3: {
  4011. packet->setDataByName("parameter3", param_value);
  4012. break;
  4013. }
  4014. case 4: {
  4015. packet->setDataByName("parameter4", param_value);
  4016. break;
  4017. }
  4018. case 5: {
  4019. packet->setDataByName("parameter5", param_value);
  4020. break;
  4021. }
  4022. }
  4023. packet->setDataByName("value", value);
  4024. client->QueuePacket(packet->serialize());
  4025. safe_delete(packet);
  4026. }
  4027. }
  4028. return 0;
  4029. }
  4030. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4031. Spawn* spawn = lua_interface->GetSpawn(state);
  4032. if (spawn && spawn->IsPlayer()) {
  4033. if (((Player*)spawn)->GetIsTracking())
  4034. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4035. else
  4036. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4037. }
  4038. return 0;
  4039. }
  4040. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4041. Spawn* player = lua_interface->GetSpawn(state);
  4042. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4043. string name = lua_interface->GetStringValue(state, 3);
  4044. float distance = lua_interface->GetFloatValue(state, 4);
  4045. string command = lua_interface->GetStringValue(state, 5);
  4046. string error_text = lua_interface->GetStringValue(state, 6);
  4047. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4048. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4049. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4050. if (spawn) {
  4051. if (distance == 0)
  4052. distance = 10.0f;
  4053. if (command.length() == 0)
  4054. command = name;
  4055. if (command.length() < 1 && name.length() < 1)
  4056. {
  4057. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4058. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4059. spawn->RemovePrimaryCommands();
  4060. }
  4061. else
  4062. {
  4063. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4064. }
  4065. }
  4066. return 0;
  4067. }
  4068. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4069. if (!lua_interface)
  4070. return 0;
  4071. Spawn* player = lua_interface->GetSpawn(state);
  4072. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4073. int16 tier = lua_interface->GetInt16Value(state, 3);
  4074. if (player && player->IsPlayer()) {
  4075. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4076. return 1;
  4077. }
  4078. return 0;
  4079. }
  4080. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4081. if (!lua_interface)
  4082. return 0;
  4083. Spawn* player = lua_interface->GetSpawn(state);
  4084. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4085. int16 tier = lua_interface->GetInt16Value(state, 3);
  4086. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4087. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4088. bool add_to_hotbar = true;
  4089. if (num_args > 4) {
  4090. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4091. }
  4092. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4093. if (player && spell && player->IsPlayer()) {
  4094. Client* client = player->GetClient();
  4095. if (client) {
  4096. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4097. {
  4098. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4099. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4100. client->GetPlayer()->UnlockSpell(spell);
  4101. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4102. }
  4103. else
  4104. {
  4105. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4106. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4107. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4108. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4109. client->GetPlayer()->UnlockSpell(spell);
  4110. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4111. }
  4112. //if (client ) {
  4113. // ((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);
  4114. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4115. if (outapp)
  4116. client->QueuePacket(outapp);
  4117. }
  4118. }
  4119. return 0;
  4120. }
  4121. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4122. if (!lua_interface)
  4123. return 0;
  4124. Spawn* player = lua_interface->GetSpawn(state);
  4125. if (player && player->IsPlayer()) {
  4126. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4127. return 1;
  4128. }
  4129. return 0;
  4130. }
  4131. int EQ2Emu_lua_Attack(lua_State* state) {
  4132. if (lua_interface) {
  4133. Spawn* npc = lua_interface->GetSpawn(state);
  4134. Spawn* player = lua_interface->GetSpawn(state, 2);
  4135. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4136. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4137. }
  4138. return 0;
  4139. }
  4140. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4141. if (lua_interface) {
  4142. Spawn* target = lua_interface->GetSpawn(state);
  4143. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4144. if (target && target->GetZone())
  4145. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4146. }
  4147. return 0;
  4148. }
  4149. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4150. Spawn* player;
  4151. if (lua_interface) {
  4152. player = lua_interface->GetSpawn(state);
  4153. if (player && player->IsPlayer()) {
  4154. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4155. return 1;
  4156. }
  4157. }
  4158. return 0;
  4159. }
  4160. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4161. Spawn* player;
  4162. Client* client;
  4163. if (lua_interface) {
  4164. player = lua_interface->GetSpawn(state);
  4165. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4166. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4167. client->HandInCollections();
  4168. }
  4169. return 0;
  4170. }
  4171. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4172. Spawn* widget;
  4173. if (lua_interface) {
  4174. widget = lua_interface->GetSpawn(state);
  4175. if (widget && widget->IsWidget())
  4176. ((Widget*)widget)->HandleUse(nullptr, "");
  4177. }
  4178. return 0;
  4179. }
  4180. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4181. Spawn* spawn = 0;
  4182. int32 primary_list = 0;
  4183. int32 secondary_list = 0;
  4184. if (lua_interface) {
  4185. spawn = lua_interface->GetSpawn(state);
  4186. primary_list = lua_interface->GetInt32Value(state, 2);
  4187. secondary_list = lua_interface->GetInt32Value(state, 3);
  4188. if (!spawn->IsNPC()) {
  4189. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4190. return 0;
  4191. }
  4192. NPC* npc = (NPC*)spawn;
  4193. npc->SetPrimarySpellList(primary_list);
  4194. npc->SetSecondarySpellList(secondary_list);
  4195. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4196. }
  4197. return 0;
  4198. }
  4199. int EQ2Emu_lua_GetPet(lua_State* state) {
  4200. if (!lua_interface)
  4201. return 0;
  4202. Spawn* spawn = lua_interface->GetSpawn(state);
  4203. if (spawn) {
  4204. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4205. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4206. return 1;
  4207. }
  4208. }
  4209. return 0;
  4210. }
  4211. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4212. if (!lua_interface)
  4213. return 0;
  4214. Spawn* spawn = lua_interface->GetSpawn(state);
  4215. if (spawn) {
  4216. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4217. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4218. return 1;
  4219. }
  4220. }
  4221. return 0;
  4222. }
  4223. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4224. if (!lua_interface)
  4225. return 0;
  4226. Spawn* spawn = lua_interface->GetSpawn(state);
  4227. if (spawn) {
  4228. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4229. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4230. return 1;
  4231. }
  4232. }
  4233. return 0;
  4234. }
  4235. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4236. if (!lua_interface)
  4237. return 0;
  4238. Spawn* spawn = lua_interface->GetSpawn(state);
  4239. if (spawn) {
  4240. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4241. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4242. return 1;
  4243. }
  4244. }
  4245. return 0;
  4246. }
  4247. int EQ2Emu_lua_Charm(lua_State* state) {
  4248. if (!lua_interface)
  4249. return 0;
  4250. Spawn* owner = lua_interface->GetSpawn(state);
  4251. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4252. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4253. if (!luaspell) {
  4254. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4255. return 0;
  4256. }
  4257. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4258. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4259. pet->SetPet(true);
  4260. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4261. ((NPC*)pet)->SetOwner((Entity*)owner);
  4262. // If owner is player and player does not have a summoned pet set the players charsheet
  4263. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4264. Player* player = (Player*)owner;
  4265. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4266. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4267. player->GetInfoStruct()->set_pet_movement(2);
  4268. player->GetInfoStruct()->set_pet_behavior(3);
  4269. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4270. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4271. // Make sure the values get sent to the client
  4272. player->SetCharSheetChanged(true);
  4273. }
  4274. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4275. pet->SetSpawnScript("");
  4276. // Set faction to the same as the owner
  4277. pet->SetFactionID(owner->GetFactionID());
  4278. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4279. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4280. // Clear hate list
  4281. ((NPC*)pet)->Brain()->ClearHate();
  4282. // Set the brain to a pet brain
  4283. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4284. }
  4285. return 0;
  4286. }
  4287. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4288. if (!lua_interface)
  4289. return 0;
  4290. Spawn* spawn = lua_interface->GetSpawn(state);
  4291. if (!spawn) {
  4292. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4293. return 0;
  4294. }
  4295. vector<Spawn*> groupMembers;
  4296. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4297. groupMembers = *spawn->GetSpawnGroup();
  4298. }
  4299. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4300. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4301. deque<GroupMemberInfo*>::iterator itr;
  4302. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4303. if (group)
  4304. {
  4305. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4306. deque<GroupMemberInfo*>* members = group->GetMembers();
  4307. GroupMemberInfo* info = 0;
  4308. for (itr = members->begin(); itr != members->end(); itr++) {
  4309. info = *itr;
  4310. if (info->client)
  4311. groupMembers.push_back(info->client->GetPlayer());
  4312. }
  4313. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4314. }
  4315. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4316. }
  4317. else
  4318. return 0;
  4319. lua_createtable(state, groupMembers.size(), 0);
  4320. int newTable = lua_gettop(state);
  4321. for (int32 i = 0; i < groupMembers.size(); i++) {
  4322. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4323. lua_rawseti(state, newTable, i + 1);
  4324. }
  4325. return 1;
  4326. }
  4327. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4328. if (!lua_interface)
  4329. return 0;
  4330. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4331. lua_interface->SetOptionWindowValue(state, option_window);
  4332. return 1;
  4333. }
  4334. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4335. if (!lua_interface)
  4336. return 0;
  4337. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4338. if (option_window) {
  4339. OptionWindowOption option_window_option;
  4340. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4341. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4342. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4343. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4344. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4345. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4346. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4347. option_window->push_back(option_window_option);
  4348. }
  4349. return 0;
  4350. }
  4351. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4352. if (!lua_interface)
  4353. return 0;
  4354. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4355. Spawn* player = lua_interface->GetSpawn(state, 2);
  4356. string window_title = lua_interface->GetStringValue(state, 3);
  4357. string cancel_command = lua_interface->GetStringValue(state, 4);
  4358. Client* client = player->GetZone()->GetClientBySpawn(player);
  4359. if (option_window && window_title.length() > 0 && client) {
  4360. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4361. if (!packet)
  4362. return 0;
  4363. packet->setDataByName("title_text", window_title.c_str());
  4364. if (cancel_command.length() > 0)
  4365. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4366. packet->setArrayLengthByName("num_selections", option_window->size());
  4367. vector<OptionWindowOption>::iterator itr;
  4368. int8 i = 0;
  4369. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4370. OptionWindowOption opt = *itr;
  4371. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4372. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4373. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4374. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4375. if (opt.optionCommand.length() > 0)
  4376. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4377. if (opt.optionConfirmTitle.length() > 0)
  4378. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4379. i++;
  4380. }
  4381. client->QueuePacket(packet->serialize());
  4382. safe_delete(option_window);
  4383. safe_delete(packet);
  4384. }
  4385. return 0;
  4386. }
  4387. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4388. if (!lua_interface)
  4389. return 0;
  4390. Spawn* spawn = lua_interface->GetSpawn(state);
  4391. if (spawn) {
  4392. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4393. return 1;
  4394. }
  4395. else
  4396. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4397. return 0;
  4398. }
  4399. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4400. if (!lua_interface)
  4401. return 0;
  4402. Spawn* spawn = lua_interface->GetSpawn(state);
  4403. if (spawn) {
  4404. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4405. return 1;
  4406. }
  4407. else
  4408. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4409. return 0;
  4410. }
  4411. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4412. if (!lua_interface)
  4413. return 0;
  4414. Spawn* spawn = lua_interface->GetSpawn(state);
  4415. if (spawn) {
  4416. int8 class_id = spawn->GetTradeskillClass();
  4417. // Need to add 42 for the offset in the array
  4418. class_id += 44;
  4419. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4420. return 1;
  4421. }
  4422. else
  4423. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4424. return 0;
  4425. }
  4426. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4427. if (!lua_interface)
  4428. return 0;
  4429. Spawn* spawn = lua_interface->GetSpawn(state);
  4430. int16 level = lua_interface->GetInt8Value(state, 2);
  4431. if (spawn) {
  4432. if (spawn->IsPlayer())
  4433. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4434. else
  4435. spawn->SetTSLevel(level);
  4436. }
  4437. else
  4438. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4439. return 0;
  4440. }
  4441. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4442. if (!lua_interface)
  4443. return 0;
  4444. Spawn* spawn = lua_interface->GetSpawn(state);
  4445. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4446. if (spawn) {
  4447. spawn->SetAttackable(attackable);
  4448. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4449. }
  4450. return 0;
  4451. }
  4452. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4453. // Check to see if we have a valid lua_interface
  4454. if (!lua_interface)
  4455. return 0;
  4456. // Get the spawn that is getting the pet
  4457. Spawn* spawn = lua_interface->GetSpawn(state);
  4458. // Get the DB ID of the pet
  4459. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4460. // The max level the pet can gain
  4461. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4462. // Get the spell that this command was called from
  4463. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4464. // Check to make sure the spawn pointer is valid
  4465. if (!spawn) {
  4466. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4467. return 0;
  4468. }
  4469. // Check to make sure the spawn is an entity
  4470. if (!spawn->IsEntity()) {
  4471. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4472. return 0;
  4473. }
  4474. // Check to make sure the spawn doesn't already have a pet of this type
  4475. if (((Entity*)spawn)->GetPet()) {
  4476. if (spawn->IsPlayer()) {
  4477. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4478. if (client)
  4479. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4480. }
  4481. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4482. return 0;
  4483. }
  4484. // Check to see if the DB ID for the pet is set
  4485. if (pet_id == 0) {
  4486. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4487. return 0;
  4488. }
  4489. // Check to see if the pointer to the spell is valid
  4490. if (!luaspell) {
  4491. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4492. return 0;
  4493. }
  4494. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4495. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4496. if (!pet) {
  4497. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4498. return 0;
  4499. }
  4500. // Check to make sure the pet is an npc
  4501. if (!pet->IsNPC()) {
  4502. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4503. return 0;
  4504. }
  4505. // Spawn the pet at the same location as the owner
  4506. pet->SetX(spawn->GetX());
  4507. pet->SetY(spawn->GetY());
  4508. pet->SetZ(spawn->GetZ());
  4509. pet->SetLocation(spawn->GetLocation());
  4510. pet->SetHeading(spawn->GetHeading());
  4511. spawn->GetZone()->AddSpawn(pet);
  4512. /*
  4513. const char* spawn_script = world.GetSpawnScript(pet_id);
  4514. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4515. spawn->SetSpawnScript(string(spawn_script));
  4516. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4517. }*/
  4518. // Get a random pet name
  4519. string random_pet_name;
  4520. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4521. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4522. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4523. // If player set various values for the char sheet (pet window)
  4524. if (spawn->IsPlayer()) {
  4525. Player* player = (Player*)spawn;
  4526. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4527. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4528. player->GetInfoStruct()->set_pet_movement(2);
  4529. player->GetInfoStruct()->set_pet_behavior(3);
  4530. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4531. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4532. // Make sure the values get sent to the client
  4533. player->SetCharSheetChanged(true);
  4534. }
  4535. // Set the pets name
  4536. pet->SetName(random_pet_name.c_str());
  4537. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4538. if (max_level > 0)
  4539. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4540. else
  4541. pet->SetLevel(spawn->GetLevel());
  4542. // Set the max level this pet can reach
  4543. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4544. // Set the faction of the pet to the same faction as the owner
  4545. pet->SetFactionID(spawn->GetFactionID());
  4546. // Set the spawn as a pet
  4547. pet->SetPet(true);
  4548. // Give a pointer of the owner to the pet
  4549. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4550. // Give a pointer of the pet to the owner
  4551. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4552. // Set the pet type
  4553. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4554. // Set the spell id used to create this pet
  4555. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4556. // Set the spell tier used to create this pet
  4557. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4558. // Set the pets spawn type to 6
  4559. pet->SetSpawnType(6);
  4560. // Set the pets brain
  4561. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4562. // Check to see if the pet has a subtitle
  4563. if (strlen(pet->GetSubTitle()) > 0) {
  4564. // Add the players name to the front of the sub title
  4565. string pet_subtitle;
  4566. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4567. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4568. // Set the pets subtitle to the new one
  4569. pet->SetSubTitle(pet_subtitle.c_str());
  4570. }
  4571. // Add the "Pet Options" entity command to the pet
  4572. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4573. // Set the pet as the return value for this function
  4574. lua_interface->SetSpawnValue(state, pet);
  4575. return 1;
  4576. }
  4577. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4578. if (!lua_interface)
  4579. return 0;
  4580. Spawn* spawn = lua_interface->GetSpawn(state);
  4581. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4582. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4583. if (!spawn) {
  4584. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4585. return 0;
  4586. }
  4587. if (!spawn->IsEntity()) {
  4588. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4589. return 0;
  4590. }
  4591. if (((Entity*)spawn)->GetDeityPet()) {
  4592. if (spawn->IsPlayer()) {
  4593. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4594. if (client)
  4595. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4596. }
  4597. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4598. return 0;
  4599. }
  4600. if (pet_id == 0) {
  4601. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4602. return 0;
  4603. }
  4604. if (!luaspell) {
  4605. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4606. return 0;
  4607. }
  4608. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4609. if (!pet) {
  4610. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4611. return 0;
  4612. }
  4613. if (!pet->IsNPC()) {
  4614. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4615. return 0;
  4616. }
  4617. pet->SetX(spawn->GetX());
  4618. pet->SetY(spawn->GetY());
  4619. pet->SetZ(spawn->GetZ());
  4620. pet->SetLocation(spawn->GetLocation());
  4621. pet->SetHeading(spawn->GetHeading());
  4622. spawn->GetZone()->AddSpawn(pet);
  4623. string random_pet_name;
  4624. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4625. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4626. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4627. pet->SetName(random_pet_name.c_str());
  4628. pet->SetLevel(spawn->GetLevel());
  4629. pet->SetFactionID(spawn->GetFactionID());
  4630. pet->SetPet(true);
  4631. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4632. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4633. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4634. pet->SetSpawnType(6);
  4635. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4636. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4637. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4638. if (strlen(pet->GetSubTitle()) > 0) {
  4639. string pet_subtitle;
  4640. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4641. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4642. pet->SetSubTitle(pet_subtitle.c_str());
  4643. }
  4644. // deity and cosmetic pets are not attackable
  4645. pet->SetAttackable(false);
  4646. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4647. lua_interface->SetSpawnValue(state, pet);
  4648. return 1;
  4649. }
  4650. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4651. if (!lua_interface)
  4652. return 0;
  4653. Spawn* spawn = lua_interface->GetSpawn(state);
  4654. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4655. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4656. if (!spawn) {
  4657. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4658. return 0;
  4659. }
  4660. if (!spawn->IsEntity()) {
  4661. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4662. return 0;
  4663. }
  4664. if (((Entity*)spawn)->GetCosmeticPet()) {
  4665. if (spawn->IsPlayer()) {
  4666. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4667. if (client)
  4668. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4669. }
  4670. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4671. return 0;
  4672. }
  4673. if (pet_id == 0) {
  4674. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4675. return 0;
  4676. }
  4677. if (!luaspell) {
  4678. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4679. return 0;
  4680. }
  4681. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4682. if (!pet) {
  4683. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4684. return 0;
  4685. }
  4686. if (!pet->IsNPC()) {
  4687. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4688. return 0;
  4689. }
  4690. pet->SetX(spawn->GetX());
  4691. pet->SetY(spawn->GetY());
  4692. pet->SetZ(spawn->GetZ());
  4693. pet->SetLocation(spawn->GetLocation());
  4694. pet->SetHeading(spawn->GetHeading());
  4695. spawn->GetZone()->AddSpawn(pet);
  4696. string random_pet_name;
  4697. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4698. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4699. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4700. pet->SetName(random_pet_name.c_str());
  4701. pet->SetLevel(spawn->GetLevel());
  4702. pet->SetFactionID(spawn->GetFactionID());
  4703. pet->SetPet(true);
  4704. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4705. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4706. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4707. pet->SetSpawnType(6);
  4708. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4709. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4710. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4711. if (strlen(pet->GetSubTitle()) > 0) {
  4712. string pet_subtitle;
  4713. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4714. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4715. pet->SetSubTitle(pet_subtitle.c_str());
  4716. }
  4717. pet->SetAttackable(false);
  4718. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4719. lua_interface->SetSpawnValue(state, pet);
  4720. return 1;
  4721. }
  4722. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4723. if (!lua_interface)
  4724. return 0;
  4725. Spawn* spawn = lua_interface->GetSpawn(state);
  4726. if (!spawn) {
  4727. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4728. return 0;
  4729. }
  4730. if (!spawn->IsPet()) {
  4731. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4732. return 0;
  4733. }
  4734. if (!((NPC*)spawn)->IsDismissing())
  4735. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4736. return 0;
  4737. }
  4738. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4739. if (!lua_interface)
  4740. return 0;
  4741. Quest* quest = lua_interface->GetQuest(state);
  4742. if (!quest) {
  4743. 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));
  4744. return 0;
  4745. }
  4746. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4747. if (feather_color > 0)
  4748. quest->SetFeatherColor(feather_color);
  4749. return 0;
  4750. }
  4751. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4752. if (!lua_interface)
  4753. return 0;
  4754. Spawn* spawn = lua_interface->GetSpawn(state);
  4755. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4756. if (!spawn) {
  4757. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4758. return 0;
  4759. }
  4760. if (!spawn2) {
  4761. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4762. return 0;
  4763. }
  4764. spawn->RemoveSpawnAccess(spawn2);
  4765. return 0;
  4766. }
  4767. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4768. if (!lua_interface)
  4769. return 0;
  4770. ZoneServer* zone = lua_interface->GetZone(state);
  4771. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4772. if (!zone) {
  4773. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4774. return 0;
  4775. }
  4776. if (location_id == 0) {
  4777. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4778. return 0;
  4779. }
  4780. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4781. if (!location) {
  4782. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4783. return 0;
  4784. }
  4785. Spawn* spawn = 0;
  4786. if (location->entities[0]) {
  4787. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4788. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4789. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4790. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4791. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4792. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4793. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4794. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4795. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4796. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4797. if (spawn) {
  4798. const char* script = 0;
  4799. for (int x = 0; x < 3; x++) {
  4800. switch (x) {
  4801. case 0:
  4802. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4803. break;
  4804. case 1:
  4805. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4806. break;
  4807. case 2:
  4808. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4809. break;
  4810. }
  4811. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4812. spawn->SetSpawnScript(string(script));
  4813. break;
  4814. }
  4815. }
  4816. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4817. lua_interface->SetSpawnValue(state, spawn);
  4818. return 1;
  4819. }
  4820. else {
  4821. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4822. safe_delete(spawn);
  4823. }
  4824. }
  4825. return 0;
  4826. }
  4827. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4828. if (!lua_interface)
  4829. return 0;
  4830. Spawn* caster = lua_interface->GetSpawn(state);
  4831. Spawn* target = lua_interface->GetSpawn(state, 2);
  4832. int32 id = lua_interface->GetInt32Value(state, 3);
  4833. string command = lua_interface->GetStringValue(state, 4);
  4834. if (!caster) {
  4835. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4836. return 0;
  4837. }
  4838. if (!target) {
  4839. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4840. return 0;
  4841. }
  4842. if (!caster->IsPlayer()) {
  4843. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4844. return 0;
  4845. }
  4846. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4847. if (!entity_command) {
  4848. 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());
  4849. return 0;
  4850. }
  4851. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4852. if (!client) {
  4853. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4854. return 0;
  4855. }
  4856. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4857. return 0;
  4858. }
  4859. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4860. if (!lua_interface)
  4861. return 0;
  4862. Spawn* spawn = lua_interface->GetSpawn(state);
  4863. if (!spawn) {
  4864. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4865. return 0;
  4866. }
  4867. if (!spawn->IsNPC()) {
  4868. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4869. return 0;
  4870. }
  4871. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4872. return 0;
  4873. }
  4874. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4875. if (!lua_interface)
  4876. return 0;
  4877. Spawn* spawn = lua_interface->GetSpawn(state);
  4878. int16 tick = lua_interface->GetInt16Value(state, 2);
  4879. if (!spawn) {
  4880. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4881. return 0;
  4882. }
  4883. if (!spawn->IsNPC()) {
  4884. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4885. return 0;
  4886. }
  4887. if (tick < 20) {
  4888. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4889. return 0;
  4890. }
  4891. ((NPC*)spawn)->Brain()->SetTick(tick);
  4892. return 0;
  4893. }
  4894. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4895. if (!lua_interface)
  4896. return 0;
  4897. Spawn* spawn = lua_interface->GetSpawn(state);
  4898. Spawn* target = lua_interface->GetSpawn(state, 2);
  4899. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4900. if (!spawn) {
  4901. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4902. return 0;
  4903. }
  4904. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4905. spawn->SetFollowTarget(target, follow_distance);
  4906. return 0;
  4907. }
  4908. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4909. if (!lua_interface)
  4910. return 0;
  4911. Spawn* spawn = lua_interface->GetSpawn(state);
  4912. if (!spawn) {
  4913. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4914. return 0;
  4915. }
  4916. Spawn* target = spawn->GetFollowTarget();
  4917. if (target) {
  4918. lua_interface->SetSpawnValue(state, target);
  4919. return 1;
  4920. }
  4921. return 0;
  4922. }
  4923. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4924. if (!lua_interface)
  4925. return 0;
  4926. Spawn* spawn = lua_interface->GetSpawn(state);
  4927. if (!spawn) {
  4928. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4929. return 0;
  4930. }
  4931. if (spawn->following)
  4932. spawn->following = false;
  4933. else
  4934. spawn->following = true;
  4935. return 0;
  4936. }
  4937. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4938. if (!lua_interface)
  4939. return 0;
  4940. Spawn* spawn = lua_interface->GetSpawn(state);
  4941. if (!spawn) {
  4942. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4943. return 0;
  4944. }
  4945. lua_interface->SetBooleanValue(state, spawn->following);
  4946. return 1;
  4947. }
  4948. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4949. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4950. // I will attempt to explain how this function works for future refrence
  4951. // Fist lets make sure lua_interface is valid, if not return out
  4952. if (!lua_interface)
  4953. return 0;
  4954. // Next we grab the first 2 params same as we usually would
  4955. Spawn* spawn = lua_interface->GetSpawn(state);
  4956. string var = lua_interface->GetStringValue(state, 2);
  4957. // 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
  4958. // 1 = Spawn
  4959. // 2 = Zone
  4960. // 3 = Item
  4961. // 4 = Quest
  4962. // 5 = String
  4963. // 6 = nil (null)
  4964. int8 dataType = 0;
  4965. // Define pointers for each potential type
  4966. Spawn* spawnVal = 0;
  4967. ZoneServer* zone = 0;
  4968. Item* item = 0;
  4969. Quest* quest = 0;
  4970. string val;
  4971. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4972. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4973. // options window are also light user data be we do not handle those.
  4974. // We check with lua_islightuserdata(lua_State*, index)
  4975. if (lua_islightuserdata(state, 3)) {
  4976. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4977. // and convert it to LUAUserData*
  4978. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4979. // Check to make sure the data we got is valid, if not give an error
  4980. if (!data || !data->IsCorrectlyInitialized()) {
  4981. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4982. }
  4983. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4984. else if (data->IsSpawn()) {
  4985. spawnVal = data->spawn;
  4986. dataType = 1;
  4987. }
  4988. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4989. else if (data->IsZone()) {
  4990. zone = data->zone;
  4991. dataType = 2;
  4992. }
  4993. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4994. else if (data->IsItem()) {
  4995. item = data->item;
  4996. dataType = 3;
  4997. }
  4998. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4999. else if (data->IsQuest()) {
  5000. quest = data->quest;
  5001. dataType = 4;
  5002. }
  5003. }
  5004. // Wasn't light user data, check if it is nil(null)
  5005. else if (lua_isnil(state, 3)) {
  5006. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5007. dataType = 6;
  5008. }
  5009. // Wasn't light user data or nil (null), must be a string
  5010. else {
  5011. // Set the string and dataType variable
  5012. val = lua_interface->GetStringValue(state, 3);
  5013. dataType = 5;
  5014. }
  5015. // We now have all the params, lets check to make sure they are valid
  5016. if (!spawn) {
  5017. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5018. return 0;
  5019. }
  5020. if (var.length() == 0) {
  5021. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5022. return 0;
  5023. }
  5024. if (dataType == 0) {
  5025. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5026. return 0;
  5027. }
  5028. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5029. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5030. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5031. switch (dataType) {
  5032. case 1:
  5033. // 1 = Spawn
  5034. spawn->AddTempVariable(var, spawnVal);
  5035. break;
  5036. case 2:
  5037. // 2 = Zone
  5038. spawn->AddTempVariable(var, zone);
  5039. break;
  5040. case 3:
  5041. // 3 = Item
  5042. spawn->AddTempVariable(var, item);
  5043. break;
  5044. case 4:
  5045. // 4 = Quest
  5046. spawn->AddTempVariable(var, quest);
  5047. break;
  5048. case 5:
  5049. // 5 = String
  5050. spawn->AddTempVariable(var, val);
  5051. break;
  5052. case 6:
  5053. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5054. spawn->DeleteTempVariable(var);
  5055. break;
  5056. }
  5057. // And we are done so return out
  5058. return 0;
  5059. }
  5060. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5061. if (!lua_interface)
  5062. return 0;
  5063. Spawn* spawn = lua_interface->GetSpawn(state);
  5064. string var = lua_interface->GetStringValue(state, 2);
  5065. if (!spawn) {
  5066. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5067. return 0;
  5068. }
  5069. if (var.length() == 0) {
  5070. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5071. return 0;
  5072. }
  5073. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5074. int8 type = spawn->GetTempVariableType(var);
  5075. Spawn* spawn2 = 0;
  5076. ZoneServer* zone = 0;
  5077. Item* item = 0;
  5078. Quest* quest = 0;
  5079. // Set the lua function return value based on the type of data the variable contains
  5080. switch (type) {
  5081. case 1:
  5082. spawn2 = spawn->GetTempVariableSpawn(var);
  5083. if (!spawn2)
  5084. return 0;
  5085. lua_interface->SetSpawnValue(state, spawn2);
  5086. break;
  5087. case 2:
  5088. zone = spawn->GetTempVariableZone(var);
  5089. if (!zone)
  5090. return 0;
  5091. lua_interface->SetZoneValue(state, zone);
  5092. break;
  5093. case 3:
  5094. item = spawn->GetTempVariableItem(var);
  5095. if (!item)
  5096. return 0;
  5097. lua_interface->SetItemValue(state, item);
  5098. break;
  5099. case 4:
  5100. quest = spawn->GetTempVariableQuest(var);
  5101. if (!quest)
  5102. return 0;
  5103. lua_interface->SetQuestValue(state, quest);
  5104. break;
  5105. case 5:
  5106. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5107. break;
  5108. default:
  5109. // Not a valid type then the variable was not set so return out
  5110. return 0;
  5111. }
  5112. // Return value was set so return out
  5113. return 1;
  5114. }
  5115. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5116. {
  5117. if (!lua_interface)
  5118. return 0;
  5119. Quest* quest = lua_interface->GetQuest(state);
  5120. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5121. string description = lua_interface->GetStringValue(state, 3);
  5122. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5123. if (!quest) {
  5124. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5125. lua_interface->SetBooleanValue(state, false);
  5126. return 1;
  5127. }
  5128. if (!spawn) {
  5129. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5130. lua_interface->SetBooleanValue(state, false);
  5131. return 1;
  5132. }
  5133. if (!spawn->IsPlayer()) {
  5134. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5135. lua_interface->SetBooleanValue(state, false);
  5136. return 1;
  5137. }
  5138. if (item_id == 0) {
  5139. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5140. lua_interface->SetBooleanValue(state, false);
  5141. return 1;
  5142. }
  5143. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5144. if (!client) {
  5145. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5146. lua_interface->SetBooleanValue(state, false);
  5147. return 1;
  5148. }
  5149. Item* item = master_item_list.GetItem(item_id);
  5150. if (!item) {
  5151. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5152. lua_interface->SetBooleanValue(state, false);
  5153. return 1;
  5154. }
  5155. Item* firstItem = new Item(item);
  5156. quest->AddTmpRewardItem(firstItem);
  5157. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5158. bool itemsAddedSuccessfully = true;
  5159. if(num_args > 4)
  5160. {
  5161. for(int8 n=5;n<num_args+1;n++)
  5162. {
  5163. int32 new_item = lua_interface->GetInt32Value(state, n);
  5164. Item* tmpItem = master_item_list.GetItem(new_item);
  5165. if(tmpItem)
  5166. {
  5167. Item* newTmpItem = new Item(tmpItem);
  5168. quest->AddTmpRewardItem(newTmpItem);
  5169. }
  5170. else
  5171. itemsAddedSuccessfully = false;
  5172. }
  5173. }
  5174. client->AddPendingQuestAcceptReward(quest);
  5175. client->DisplayQuestComplete(quest, true, description);
  5176. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5177. return 1;
  5178. }
  5179. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5180. if (!lua_interface)
  5181. return 0;
  5182. Quest* quest = lua_interface->GetQuest(state);
  5183. if (!quest) {
  5184. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5185. return 0;
  5186. }
  5187. quest->SetRepeatable(true);
  5188. return 0;
  5189. }
  5190. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5191. if (!lua_interface)
  5192. return 0;
  5193. Spawn* spawn = lua_interface->GetSpawn(state);
  5194. if (!spawn) {
  5195. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5196. return 0;
  5197. }
  5198. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5199. string ret = classes.GetClassNameCase(base_class);
  5200. if (ret.length() > 0) {
  5201. lua_interface->SetStringValue(state, ret.c_str());
  5202. return 1;
  5203. }
  5204. return 0;
  5205. }
  5206. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5207. if (!lua_interface)
  5208. return 0;
  5209. Spawn* player = lua_interface->GetSpawn(state);
  5210. if (player && player->IsPlayer()) {
  5211. Client* client = player->GetClient();
  5212. if (client)
  5213. client->SendWaypoints();
  5214. }
  5215. return 0;
  5216. }
  5217. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5218. if (!lua_interface)
  5219. return 0;
  5220. Spawn* player = lua_interface->GetSpawn(state);
  5221. string name = lua_interface->GetStringValue(state, 2);
  5222. int32 type = lua_interface->GetInt32Value(state, 3);
  5223. if (type == 0)
  5224. type = 2;
  5225. if (name.length() > 0) {
  5226. if (player && player->IsPlayer()) {
  5227. Client* client = player->GetClient();
  5228. if (client)
  5229. client->AddWaypoint(name, type);
  5230. }
  5231. }
  5232. return 0;
  5233. }
  5234. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5235. if (!lua_interface)
  5236. return 0;
  5237. Spawn* player = lua_interface->GetSpawn(state);
  5238. string name = lua_interface->GetStringValue(state, 2);
  5239. if (name.length() > 0) {
  5240. if (player && player->IsPlayer()) {
  5241. Client* client = player->GetClient();
  5242. if (client)
  5243. client->RemoveWaypoint(name);
  5244. }
  5245. }
  5246. return 0;
  5247. }
  5248. int EQ2Emu_lua_AddWard(lua_State* state) {
  5249. if (!lua_interface)
  5250. return 0;
  5251. int32 damage = lua_interface->GetInt32Value(state);
  5252. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5253. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5254. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5255. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5256. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5257. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5258. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5259. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5260. bool ward_was_added = false;
  5261. ZoneServer* zone = spell->caster->GetZone();
  5262. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5263. for (int32 i = 0; i < spell->targets.size(); i++) {
  5264. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5265. if (!target)
  5266. continue;
  5267. if (target->IsEntity()) {
  5268. // If the ward is already active remove it
  5269. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5270. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5271. // Create new ward info
  5272. WardInfo* ward = new WardInfo;
  5273. ward->Spell = spell;
  5274. ward->BaseDamage = damage;
  5275. ward->DamageLeft = damage;
  5276. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5277. ward->keepWard = keepWard;
  5278. ward->WardType = wardType;
  5279. if (damageAbsorptionPercent > 100)
  5280. damageAbsorptionPercent = 100;
  5281. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5282. if (damageAbsorptionMaxHealthPercent > 100)
  5283. damageAbsorptionMaxHealthPercent = 100;
  5284. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5285. ward->RedirectDamagePercent = redirectDamagePercent;
  5286. ward->LastRedirectDamage = 0;
  5287. ward->LastAbsorbedDamage = 0;
  5288. ward->HitCount = 0;
  5289. spell->num_triggers = maxHitCount;
  5290. spell->had_triggers = true;
  5291. spell->cancel_after_all_triggers = false;
  5292. ward->MaxHitCount = maxHitCount;
  5293. if (wardType == WARD_TYPE_MAGICAL)
  5294. ward->DamageType = damageTypes;
  5295. // Add the ward to the entity
  5296. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5297. ward_was_added = true;
  5298. }
  5299. }
  5300. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5301. if (ward_was_added && spell->caster->IsPlayer()) {
  5302. spell->had_dmg_remaining = true;
  5303. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5304. }
  5305. return 0;
  5306. }
  5307. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5308. if (!lua_interface)
  5309. return 0;
  5310. int32 amount = lua_interface->GetInt32Value(state);
  5311. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5312. WardInfo* ward = 0;
  5313. ZoneServer* zone = spell->caster->GetZone();
  5314. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5315. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5316. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5317. ward = target->GetWard(spell->spell->GetSpellID());
  5318. if (target && ward) {
  5319. ward->DamageLeft += amount;
  5320. if (ward->DamageLeft > ward->BaseDamage)
  5321. ward->DamageLeft = ward->BaseDamage;
  5322. for (int32 i = 0; i < spell->targets.size(); i++) {
  5323. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5324. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5325. }
  5326. }
  5327. }
  5328. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5329. if (ward && spell->caster->IsPlayer())
  5330. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5331. return 0;
  5332. }
  5333. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5334. if (!lua_interface)
  5335. return 0;
  5336. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5337. if (!spell) {
  5338. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5339. return 0;
  5340. }
  5341. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5342. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5343. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5344. if (ward) {
  5345. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5346. return 1;
  5347. }
  5348. }
  5349. return 0;
  5350. }
  5351. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5352. if (!lua_interface)
  5353. return 0;
  5354. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5355. if (!spell) {
  5356. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5357. return 0;
  5358. }
  5359. string type = lua_interface->GetStringValue(state, 2);
  5360. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5361. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5362. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5363. if (ward) {
  5364. if (boost::iequals(type, "damageleft"))
  5365. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5366. else if (boost::iequals(type, "basedamage"))
  5367. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5368. else if (boost::iequals(type, "keepward"))
  5369. lua_interface->SetBooleanValue(state, ward->keepWard);
  5370. else if (boost::iequals(type, "wardtype"))
  5371. lua_interface->SetInt32Value(state, ward->WardType);
  5372. else if (boost::iequals(type, "dmgabsorptionpct"))
  5373. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5374. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5375. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5376. else if (boost::iequals(type, "redirectdamagepercent"))
  5377. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5378. else if (boost::iequals(type, "lastredirectdamage"))
  5379. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5380. else if (boost::iequals(type, "lastabsorbeddamage"))
  5381. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5382. else if (boost::iequals(type, "hitcount"))
  5383. lua_interface->SetInt32Value(state, ward->HitCount);
  5384. else if (boost::iequals(type, "maxhitcount"))
  5385. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5386. else
  5387. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5388. return 1;
  5389. }
  5390. }
  5391. return 0;
  5392. }
  5393. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5394. if (!lua_interface)
  5395. return 0;
  5396. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5397. ZoneServer* zone = spell->caster->GetZone();
  5398. Spawn* target = 0;
  5399. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5400. for (int32 i = 0; i < spell->targets.size(); i++) {
  5401. target = zone->GetSpawnByID(spell->targets.at(i));
  5402. if (target && target->IsEntity()) {
  5403. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5404. }
  5405. }
  5406. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5407. return 0;
  5408. }
  5409. int EQ2Emu_lua_Interrupt(lua_State* state)
  5410. {
  5411. if (!lua_interface)
  5412. return 0;
  5413. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5414. Spawn* target = lua_interface->GetSpawn(state, 2);
  5415. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5416. if (!caster)
  5417. {
  5418. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5419. return 0;
  5420. }
  5421. if (!target)
  5422. {
  5423. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5424. return 0;
  5425. }
  5426. if (!spell) {
  5427. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5428. return 0;
  5429. }
  5430. if (!target->IsEntity() && !spell)
  5431. {
  5432. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5433. return 0;
  5434. }
  5435. if (!target && spell) {
  5436. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5437. for (int8 i = 0; i < spell->targets.size(); i++) {
  5438. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5439. if (!target || !target->IsEntity())
  5440. continue;
  5441. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5442. }
  5443. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5444. }
  5445. else
  5446. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5447. return 0;
  5448. }
  5449. int EQ2Emu_lua_Stealth(lua_State* state) {
  5450. if (!lua_interface)
  5451. return 0;
  5452. int8 type = lua_interface->GetInt8Value(state);
  5453. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5454. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5455. if (!spell) {
  5456. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5457. return 0;
  5458. }
  5459. ZoneServer* zone = spell->caster->GetZone();
  5460. if (spawn) {
  5461. if (spawn->IsEntity()) {
  5462. if (type == 1) {
  5463. ((Entity*)spawn)->AddStealthSpell(spell);
  5464. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5465. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5466. }
  5467. else if (type == 2) {
  5468. ((Entity*)spawn)->AddInvisSpell(spell);
  5469. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5470. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5471. }
  5472. return 0;
  5473. }
  5474. else {
  5475. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5476. return 0;
  5477. }
  5478. }
  5479. else {
  5480. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5481. for (int32 i = 0; i < spell->targets.size(); i++) {
  5482. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5483. if (!spawn || !spawn->IsEntity())
  5484. continue;
  5485. if (type == 1) {
  5486. ((Entity*)spawn)->AddStealthSpell(spell);
  5487. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5488. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5489. }
  5490. else if (type == 2) {
  5491. ((Entity*)spawn)->AddInvisSpell(spell);
  5492. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5493. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5494. }
  5495. else {
  5496. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5497. break;
  5498. }
  5499. }
  5500. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5501. }
  5502. return 0;
  5503. }
  5504. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5505. if (!lua_interface)
  5506. return 0;
  5507. Spawn* spawn = lua_interface->GetSpawn(state);
  5508. if (!spawn) {
  5509. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5510. return 0;
  5511. }
  5512. if (spawn->IsEntity()) {
  5513. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5514. return 1;
  5515. }
  5516. else
  5517. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5518. return 0;
  5519. }
  5520. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5521. if (!lua_interface)
  5522. return 0;
  5523. Spawn* spawn = lua_interface->GetSpawn(state);
  5524. if (!spawn) {
  5525. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5526. return 0;
  5527. }
  5528. if (spawn->IsEntity()) {
  5529. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5530. return 1;
  5531. }
  5532. else
  5533. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5534. return 0;
  5535. }
  5536. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5537. if (!lua_interface)
  5538. return 0;
  5539. Spawn* player = lua_interface->GetSpawn(state);
  5540. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5541. lua_interface->ResetFunctionStack(state);
  5542. if (!player->IsPlayer()) {
  5543. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5544. return 0;
  5545. }
  5546. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5547. return 1;
  5548. }
  5549. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5550. if (!lua_interface)
  5551. return 0;
  5552. Spawn* player = lua_interface->GetSpawn(state);
  5553. int8 slot = lua_interface->GetInt8Value(state, 2);
  5554. lua_interface->ResetFunctionStack(state);
  5555. if (!player) {
  5556. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5557. return 0;
  5558. }
  5559. if (!player->IsPlayer()) {
  5560. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5561. return 0;
  5562. }
  5563. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5564. if (!item) {
  5565. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5566. return 0;
  5567. }
  5568. lua_interface->SetItemValue(state, item);
  5569. return 1;
  5570. }
  5571. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5572. if (!lua_interface)
  5573. return 0;
  5574. Spawn* player = lua_interface->GetSpawn(state);
  5575. int32 id = lua_interface->GetInt32Value(state, 2);
  5576. lua_interface->ResetFunctionStack(state);
  5577. if (!player) {
  5578. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5579. return 0;
  5580. }
  5581. if (!player->IsPlayer()) {
  5582. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5583. return 0;
  5584. }
  5585. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5586. if (!item) {
  5587. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5588. return 0;
  5589. }
  5590. lua_interface->SetItemValue(state, item);
  5591. return 1;
  5592. }
  5593. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5594. if (!lua_interface)
  5595. return 0;
  5596. Spawn* spawn = lua_interface->GetSpawn(state);
  5597. int8 slot = lua_interface->GetInt8Value(state, 2);
  5598. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5599. lua_interface->ResetFunctionStack(state);
  5600. if (!spawn) {
  5601. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5602. return 0;
  5603. }
  5604. if (!spawn->IsEntity()) {
  5605. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5606. return 0;
  5607. }
  5608. Item* item = master_item_list.GetItem(item_id);
  5609. if (!item) {
  5610. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5611. return 0;
  5612. }
  5613. Item* copy = new Item(item);
  5614. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5615. if(result)
  5616. {
  5617. ((Entity*)spawn)->SetEquipment(copy, slot);
  5618. spawn->vis_changed = true;
  5619. if(spawn->IsPlayer())
  5620. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5621. }
  5622. else
  5623. {
  5624. safe_delete(copy);
  5625. }
  5626. lua_interface->SetBooleanValue(state, result);
  5627. return 1;
  5628. }
  5629. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5630. if (!lua_interface)
  5631. return 0;
  5632. Spawn* spawn = lua_interface->GetSpawn(state);
  5633. int8 slot = lua_interface->GetInt8Value(state, 2);
  5634. Item* item = lua_interface->GetItem(state, 3);
  5635. lua_interface->ResetFunctionStack(state);
  5636. if (!spawn) {
  5637. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5638. return 0;
  5639. }
  5640. if (!spawn->IsEntity()) {
  5641. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5642. return 0;
  5643. }
  5644. if (!item) {
  5645. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5646. return 0;
  5647. }
  5648. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5649. if(result)
  5650. {
  5651. ((Entity*)spawn)->SetEquipment(item, slot);
  5652. spawn->vis_changed = true;
  5653. if(spawn->IsPlayer())
  5654. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5655. }
  5656. lua_interface->SetBooleanValue(state, result);
  5657. return 1;
  5658. }
  5659. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5660. if (!lua_interface)
  5661. return 0;
  5662. Spawn* spawn = lua_interface->GetSpawn(state);
  5663. int8 slot = lua_interface->GetInt8Value(state, 2);
  5664. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5665. lua_interface->ResetFunctionStack(state);
  5666. if (!spawn) {
  5667. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5668. return 0;
  5669. }
  5670. if (!spawn->IsEntity()) {
  5671. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5672. return 0;
  5673. }
  5674. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5675. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5676. spawn->vis_changed = true;
  5677. if(spawn->IsPlayer())
  5678. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5679. lua_interface->SetBooleanValue(state, true);
  5680. return 1;
  5681. }
  5682. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5683. if (!lua_interface)
  5684. return 0;
  5685. Spawn* spawn = lua_interface->GetSpawn(state);
  5686. int8 slot = lua_interface->GetInt8Value(state, 2);
  5687. int16 type = lua_interface->GetInt16Value(state, 3);
  5688. int8 r = lua_interface->GetInt8Value(state, 4);
  5689. int8 g = lua_interface->GetInt8Value(state, 5);
  5690. int8 b = lua_interface->GetInt8Value(state, 6);
  5691. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5692. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5693. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5694. lua_interface->ResetFunctionStack(state);
  5695. if (!spawn) {
  5696. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5697. return 0;
  5698. }
  5699. if (!spawn->IsEntity()) {
  5700. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5701. return 0;
  5702. }
  5703. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5704. spawn->vis_changed = true;
  5705. lua_interface->SetBooleanValue(state, true);
  5706. return 1;
  5707. }
  5708. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5709. if (!lua_interface)
  5710. return 0;
  5711. Spawn* player = lua_interface->GetSpawn(state);
  5712. int32 id = lua_interface->GetInt32Value(state, 2);
  5713. int8 count = lua_interface->GetInt8Value(state, 3);
  5714. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5715. lua_interface->ResetFunctionStack(state);
  5716. if (!player) {
  5717. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5718. return 0;
  5719. }
  5720. if (!player->IsPlayer()) {
  5721. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5722. return 0;
  5723. }
  5724. if (!count)
  5725. count = 1;
  5726. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5727. if (!item) {
  5728. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5729. return 0;
  5730. }
  5731. lua_interface->SetItemValue(state, item);
  5732. return 1;
  5733. }
  5734. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5735. if (!lua_interface)
  5736. return 0;
  5737. Spawn* spawn = lua_interface->GetSpawn(state);
  5738. int32 anim = lua_interface->GetInt32Value(state, 2);
  5739. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5740. int8 type = lua_interface->GetInt8Value(state, 4);
  5741. if (!spawn) {
  5742. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5743. return 0;
  5744. }
  5745. if (spawn2) {
  5746. if (spawn2->IsPlayer()) {
  5747. if (type != 1 && type != 2)
  5748. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5749. else
  5750. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5751. return 0;
  5752. }
  5753. else {
  5754. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5755. return 0;
  5756. }
  5757. }
  5758. else
  5759. spawn->GetZone()->PlayAnimation(spawn, anim);
  5760. return 0;
  5761. }
  5762. int EQ2Emu_lua_IsPet(lua_State* state) {
  5763. if (!lua_interface)
  5764. return 0;
  5765. Spawn* spawn = lua_interface->GetSpawn(state);
  5766. if (!spawn) {
  5767. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5768. return 0;
  5769. }
  5770. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5771. return 1;
  5772. }
  5773. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5774. if (!lua_interface)
  5775. return 0;
  5776. Spawn* spawn = lua_interface->GetSpawn(state);
  5777. if (!spawn) {
  5778. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5779. return 0;
  5780. }
  5781. if (!spawn->IsNPC()) {
  5782. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5783. return 0;
  5784. }
  5785. if (((NPC*)spawn)->GetOwner()) {
  5786. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5787. return 1;
  5788. }
  5789. return 0;
  5790. }
  5791. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5792. if (!lua_interface)
  5793. return 0;
  5794. Spawn* spawn = lua_interface->GetSpawn(state);
  5795. Spawn* target = lua_interface->GetSpawn(state, 2);
  5796. if (!spawn) {
  5797. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5798. return 0;
  5799. }
  5800. if (!spawn) {
  5801. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5802. return 0;
  5803. }
  5804. spawn->SetTarget(target);
  5805. return 0;
  5806. }
  5807. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5808. if (!lua_interface)
  5809. return 0;
  5810. Spawn* spawn = lua_interface->GetSpawn(state);
  5811. bool val = lua_interface->GetBooleanValue(state, 2);
  5812. if (!spawn) {
  5813. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5814. return 0;
  5815. }
  5816. if (!spawn->IsEntity()) {
  5817. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5818. return 0;
  5819. }
  5820. ((Entity*)spawn)->InCombat(val);
  5821. if (val) {
  5822. spawn->ClearRunningLocations();
  5823. spawn->CalculateRunningLocation(true);
  5824. }
  5825. return 0;
  5826. }
  5827. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5828. if (!lua_interface)
  5829. return 0;
  5830. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5831. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5832. if (!spawn1) {
  5833. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5834. return 0;
  5835. }
  5836. if (!spawn2) {
  5837. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5838. return 0;
  5839. }
  5840. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5841. return 1;
  5842. }
  5843. int EQ2Emu_lua_Runback(lua_State* state) {
  5844. if (!lua_interface)
  5845. return 0;
  5846. Spawn* spawn = lua_interface->GetSpawn(state);
  5847. if (!spawn) {
  5848. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5849. return 0;
  5850. }
  5851. if (!spawn->IsNPC()) {
  5852. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5853. return 0;
  5854. }
  5855. ((NPC*)spawn)->Runback();
  5856. return 0;
  5857. }
  5858. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5859. if (!lua_interface)
  5860. return 0;
  5861. Spawn* spawn = lua_interface->GetSpawn(state);
  5862. if (!spawn) {
  5863. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5864. return 0;
  5865. }
  5866. if (!spawn->IsNPC()) {
  5867. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5868. return 0;
  5869. }
  5870. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5871. return 1;
  5872. }
  5873. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5874. if (!lua_interface)
  5875. return 0;
  5876. Spawn* spawn = lua_interface->GetSpawn(state);
  5877. if (!spawn) {
  5878. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5879. return 0;
  5880. }
  5881. if (!spawn->IsEntity()) {
  5882. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5883. return 0;
  5884. }
  5885. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5886. return 1;
  5887. }
  5888. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5889. if (!lua_interface)
  5890. return 0;
  5891. Spawn* spawn = lua_interface->GetSpawn(state);
  5892. if (!spawn) {
  5893. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5894. return 0;
  5895. }
  5896. if (!spawn->IsEntity()) {
  5897. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5898. return 0;
  5899. }
  5900. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5901. return 1;
  5902. }
  5903. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5904. if (!lua_interface)
  5905. return 0;
  5906. Spawn* spawn = lua_interface->GetSpawn(state);
  5907. if (!spawn) {
  5908. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5909. return 0;
  5910. }
  5911. if (!spawn->IsEntity()) {
  5912. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5913. return 0;
  5914. }
  5915. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5916. return 1;
  5917. }
  5918. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5919. if (!lua_interface)
  5920. return 0;
  5921. Spawn* spawn = lua_interface->GetSpawn(state);
  5922. if (!spawn) {
  5923. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5924. return 0;
  5925. }
  5926. if (!spawn->IsEntity()) {
  5927. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5928. return 0;
  5929. }
  5930. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5931. return 1;
  5932. }
  5933. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5934. if (!lua_interface)
  5935. return 0;
  5936. Spawn* spawn = lua_interface->GetSpawn(state);
  5937. Spawn* target = lua_interface->GetSpawn(state, 2);
  5938. float distance = lua_interface->GetFloatValue(state, 3);
  5939. if (!spawn) {
  5940. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5941. return 0;
  5942. }
  5943. if (!target) {
  5944. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5945. return 0;
  5946. }
  5947. if (!spawn->IsNPC()) {
  5948. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5949. return 0;
  5950. }
  5951. if (!target->IsEntity()) {
  5952. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5953. return 0;
  5954. }
  5955. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5956. return 1;
  5957. }
  5958. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5959. if (!lua_interface)
  5960. return 0;
  5961. Spawn* spawn = lua_interface->GetSpawn(state);
  5962. Spawn* target = lua_interface->GetSpawn(state, 2);
  5963. float distance = lua_interface->GetFloatValue(state, 3);
  5964. if (!spawn) {
  5965. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5966. return 0;
  5967. }
  5968. if (!target) {
  5969. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5970. return 0;
  5971. }
  5972. if (!spawn->IsNPC()) {
  5973. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5974. return 0;
  5975. }
  5976. if (!target->IsEntity()) {
  5977. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5978. return 0;
  5979. }
  5980. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5981. return 0;
  5982. }
  5983. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5984. if (!lua_interface)
  5985. return 0;
  5986. Spawn* spawn = lua_interface->GetSpawn(state);
  5987. if (!spawn) {
  5988. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5989. return 0;
  5990. }
  5991. if (!spawn->IsNPC()) {
  5992. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5993. return 0;
  5994. }
  5995. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5996. return 1;
  5997. }
  5998. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5999. if (!lua_interface)
  6000. return 0;
  6001. Spawn* spawn = lua_interface->GetSpawn(state);
  6002. if (!spawn) {
  6003. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6004. return 0;
  6005. }
  6006. if (!spawn->IsNPC()) {
  6007. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6008. return 0;
  6009. }
  6010. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6011. return 1;
  6012. }
  6013. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6014. if (!lua_interface)
  6015. return 0;
  6016. Spawn* spawn = lua_interface->GetSpawn(state);
  6017. if (!spawn) {
  6018. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6019. return 0;
  6020. }
  6021. if (!spawn->IsNPC()) {
  6022. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6023. return 0;
  6024. }
  6025. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6026. if (hated) {
  6027. lua_interface->SetSpawnValue(state, hated);
  6028. return 1;
  6029. }
  6030. return 0;
  6031. }
  6032. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6033. if (!lua_interface)
  6034. return 0;
  6035. Spawn* spawn = lua_interface->GetSpawn(state);
  6036. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6037. if (!spawn) {
  6038. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6039. return 0;
  6040. }
  6041. if (!spawn->IsNPC()) {
  6042. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6043. return 0;
  6044. }
  6045. if (!hated) {
  6046. ((NPC*)spawn)->Brain()->ClearHate();
  6047. return 0;
  6048. }
  6049. else
  6050. {
  6051. if (!hated->IsEntity()) {
  6052. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6053. return 0;
  6054. }
  6055. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6056. return 0;
  6057. }
  6058. return 0;
  6059. }
  6060. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6061. if (!lua_interface)
  6062. return 0;
  6063. Spawn* spawn = lua_interface->GetSpawn(state);
  6064. if (!spawn) {
  6065. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6066. return 0;
  6067. }
  6068. if (!spawn->IsNPC()) {
  6069. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6070. return 0;
  6071. }
  6072. ((NPC*)spawn)->Brain()->ClearEncounter();
  6073. return 0;
  6074. }
  6075. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6076. if (!lua_interface)
  6077. return 0;
  6078. Spawn* spawn = lua_interface->GetSpawn(state);
  6079. if (!spawn) {
  6080. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6081. return 0;
  6082. }
  6083. if (!spawn->IsNPC()) {
  6084. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6085. return 0;
  6086. }
  6087. // Temp list to store hate list
  6088. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6089. if (encounterList->size() == 0) {
  6090. safe_delete(encounterList);
  6091. return 0;
  6092. }
  6093. lua_createtable(state, encounterList->size(), 0);
  6094. int newTable = lua_gettop(state);
  6095. for (int32 i = 0; i < encounterList->size(); i++) {
  6096. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6097. if (temp)
  6098. lua_interface->SetSpawnValue(state, temp);
  6099. lua_rawseti(state, newTable, i + 1);
  6100. }
  6101. safe_delete(encounterList);
  6102. return 1;
  6103. }
  6104. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6105. if (!lua_interface)
  6106. return 0;
  6107. Spawn* spawn = lua_interface->GetSpawn(state);
  6108. if (!spawn) {
  6109. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6110. return 0;
  6111. }
  6112. if (!spawn->IsNPC()) {
  6113. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6114. return 0;
  6115. }
  6116. // Temp list to store hate list
  6117. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6118. if (hateList->size() == 0) {
  6119. safe_delete(hateList);
  6120. return 0;
  6121. }
  6122. lua_createtable(state, hateList->size(), 0);
  6123. int newTable = lua_gettop(state);
  6124. for (int32 i = 0; i < hateList->size(); i++) {
  6125. lua_interface->SetSpawnValue(state, hateList->at(i));
  6126. lua_rawseti(state, newTable, i + 1);
  6127. }
  6128. safe_delete(hateList);
  6129. return 1;
  6130. }
  6131. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6132. if (!lua_interface)
  6133. return 0;
  6134. Spawn* spawn = lua_interface->GetSpawn(state);
  6135. if (!spawn) {
  6136. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6137. return 0;
  6138. }
  6139. if (spawn->IsPlayer()) {
  6140. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6141. lua_interface->SetBooleanValue(state, true);
  6142. else
  6143. lua_interface->SetBooleanValue(state, false);
  6144. return 1;
  6145. }
  6146. else {
  6147. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6148. return 1;
  6149. }
  6150. }
  6151. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6152. if (!lua_interface)
  6153. return 0;
  6154. Quest* quest = lua_interface->GetQuest(state);
  6155. if (!quest) {
  6156. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6157. return 0;
  6158. }
  6159. quest->SetCompletedFlag(true);
  6160. return 0;
  6161. }
  6162. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6163. if (!lua_interface)
  6164. return 0;
  6165. Spawn* spawn = lua_interface->GetSpawn(state);
  6166. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6167. int8 tier = lua_interface->GetInt8Value(state, 3);
  6168. if (!spawn) {
  6169. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6170. return 0;
  6171. }
  6172. if (!spawn->IsEntity()) {
  6173. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6174. return 0;
  6175. }
  6176. if (spellID == 0) {
  6177. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6178. return 0;
  6179. }
  6180. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6181. if (effect) {
  6182. if (tier > 0) {
  6183. // If a tier was passed chec to see if it is the same as the effect
  6184. if (tier == effect->tier)
  6185. lua_interface->SetBooleanValue(state, true);
  6186. else
  6187. lua_interface->SetBooleanValue(state, false);
  6188. return 1;
  6189. }
  6190. else {
  6191. // Have an effect but no tier was passed so return true
  6192. lua_interface->SetBooleanValue(state, true);
  6193. }
  6194. return 1;
  6195. }
  6196. // no effect so return false
  6197. lua_interface->SetBooleanValue(state, false);
  6198. return 1;
  6199. }
  6200. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6201. if (!lua_interface)
  6202. return 0;
  6203. Spawn* spawn = lua_interface->GetSpawn(state);
  6204. int32 id = lua_interface->GetInt32Value(state, 2);
  6205. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6206. Spawn* spawn2 = 0;
  6207. vector<Spawn*> list;
  6208. if (!spawn) {
  6209. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6210. return 0;
  6211. }
  6212. //If zone not provided, use spawn's zone
  6213. if (!zone)
  6214. zone = spawn->GetZone();
  6215. list = zone->GetSpawnsByID(id);
  6216. if (list.size() == 0) {
  6217. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6218. return 0;
  6219. }
  6220. vector<Spawn*>::iterator itr = list.begin();
  6221. for (int8 i = 0; i < list.size(); i++) {
  6222. spawn2 = itr[i];
  6223. if (spawn2)
  6224. spawn2->AddAllowAccessSpawn(spawn);
  6225. }
  6226. return 0;
  6227. }
  6228. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6229. if (!lua_interface)
  6230. return 0;
  6231. Spawn* spawn = lua_interface->GetSpawn(state);
  6232. int32 id = lua_interface->GetInt32Value(state, 2);
  6233. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6234. Spawn* spawn2 = 0;
  6235. if (!spawn) {
  6236. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6237. return 0;
  6238. }
  6239. //If zone not provided, use spawn's zone
  6240. if (!zone)
  6241. zone = spawn->GetZone();
  6242. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6243. vector<Spawn*>::iterator itr = list.begin();
  6244. if (list.size() == 0) {
  6245. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6246. return 0;
  6247. }
  6248. for (int8 i = 0; i < list.size(); i++) {
  6249. spawn2 = itr[i];
  6250. if (spawn2)
  6251. spawn2->RemoveSpawnAccess(spawn);
  6252. }
  6253. return 0;
  6254. }
  6255. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6256. if (!lua_interface)
  6257. return 0;
  6258. Quest* quest = lua_interface->GetQuest(state);
  6259. if (!quest) {
  6260. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6261. return 0;
  6262. }
  6263. quest->SetYellowName(true);
  6264. return 0;
  6265. }
  6266. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6267. if (!lua_interface)
  6268. return 0;
  6269. Spawn* spawn = lua_interface->GetSpawn(state);
  6270. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6271. if (!spawn) {
  6272. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6273. return 0;
  6274. }
  6275. if (!spawn->IsPlayer()) {
  6276. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6277. return 0;
  6278. }
  6279. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6280. return 1;
  6281. }
  6282. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6283. if (!lua_interface)
  6284. return 0;
  6285. Spawn* spawn = lua_interface->GetSpawn(state);
  6286. if (!spawn) {
  6287. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6288. return 0;
  6289. }
  6290. if (!spawn->IsPlayer()) {
  6291. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6292. return 0;
  6293. }
  6294. ZoneServer* zone = spawn->GetZone();
  6295. if (!zone) {
  6296. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6297. return 0;
  6298. }
  6299. Instance_Type iType = zone->GetInstanceType();
  6300. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6301. iType == GROUP_LOCKOUT_INSTANCE ||
  6302. iType == RAID_LOCKOUT_INSTANCE ||
  6303. iType == SOLO_PERSIST_INSTANCE ||
  6304. iType == GROUP_PERSIST_INSTANCE ||
  6305. iType == RAID_PERSIST_INSTANCE) {
  6306. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6307. if (data) {
  6308. // Check to see if the timer has already been set, if it has return out.
  6309. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6310. return 0;
  6311. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6312. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6313. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6314. if (client) {
  6315. string time_msg = "";
  6316. int32 time = data->success_lockout_time;
  6317. int16 hour;
  6318. int8 min;
  6319. int8 sec;
  6320. hour = time / 3600;
  6321. time = time % 3600;
  6322. min = time / 60;
  6323. time = time % 60;
  6324. sec = time;
  6325. if (hour > 0) {
  6326. char temp[10];
  6327. sprintf(temp, " %i", hour);
  6328. time_msg.append(temp);
  6329. time_msg.append(" hour");
  6330. time_msg.append((hour > 1) ? "s" : "");
  6331. }
  6332. if (min > 0) {
  6333. char temp[5];
  6334. sprintf(temp, " %i", min);
  6335. time_msg.append(temp);
  6336. time_msg.append(" minute");
  6337. time_msg.append((min > 1) ? "s" : "");
  6338. }
  6339. // Only add seconds if minutes and hours are 0
  6340. if (hour == 0 && min == 0 && sec > 0) {
  6341. char temp[5];
  6342. sprintf(temp, " %i", sec);
  6343. time_msg.append(temp);
  6344. time_msg.append(" second");
  6345. time_msg.append((sec > 1) ? "s" : "");
  6346. }
  6347. 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());
  6348. }
  6349. }
  6350. else
  6351. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6352. }
  6353. else
  6354. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6355. return 0;
  6356. }
  6357. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6358. if (!lua_interface)
  6359. return 0;
  6360. Spawn* spawn = lua_interface->GetSpawn(state);
  6361. if (!spawn) {
  6362. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6363. return 0;
  6364. }
  6365. if (!spawn->IsPlayer()) {
  6366. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6367. return 0;
  6368. }
  6369. ZoneServer* zone = spawn->GetZone();
  6370. if (!zone) {
  6371. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6372. return 0;
  6373. }
  6374. Instance_Type iType = zone->GetInstanceType();
  6375. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6376. iType == GROUP_LOCKOUT_INSTANCE ||
  6377. iType == RAID_LOCKOUT_INSTANCE ||
  6378. iType == SOLO_PERSIST_INSTANCE ||
  6379. iType == GROUP_PERSIST_INSTANCE ||
  6380. iType == RAID_PERSIST_INSTANCE) {
  6381. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6382. if (data) {
  6383. // Check to see if the timer has already been set, if it has return out.
  6384. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6385. return 0;
  6386. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6387. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6388. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6389. if (client) {
  6390. string time_msg = "";
  6391. int32 time = data->failure_lockout_time;
  6392. int16 hour;
  6393. int8 min;
  6394. int8 sec;
  6395. hour = time / 3600;
  6396. time = time % 3600;
  6397. min = time / 60;
  6398. time = time % 60;
  6399. sec = time;
  6400. if (hour > 0) {
  6401. char temp[10];
  6402. sprintf(temp, " %i", hour);
  6403. time_msg.append(temp);
  6404. time_msg.append(" hour");
  6405. time_msg.append((hour > 1) ? "s" : "");
  6406. }
  6407. if (min > 0) {
  6408. char temp[5];
  6409. sprintf(temp, " %i", min);
  6410. time_msg.append(temp);
  6411. time_msg.append(" minute");
  6412. time_msg.append((min > 1) ? "s" : "");
  6413. }
  6414. // Only add seconds if minutes and hours are 0
  6415. if (hour == 0 && min == 0 && sec > 0) {
  6416. char temp[5];
  6417. sprintf(temp, " %i", sec);
  6418. time_msg.append(temp);
  6419. time_msg.append(" second");
  6420. time_msg.append((sec > 1) ? "s" : "");
  6421. }
  6422. 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());
  6423. }
  6424. }
  6425. else
  6426. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6427. }
  6428. else
  6429. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6430. return 0;
  6431. }
  6432. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6433. if (!lua_interface)
  6434. return 0;
  6435. Spawn* spawn = lua_interface->GetSpawn(state);
  6436. if (!spawn) {
  6437. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6438. return 0;
  6439. }
  6440. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6441. return 1;
  6442. }
  6443. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6444. if (!lua_interface)
  6445. return 0;
  6446. Spawn* player = lua_interface->GetSpawn(state);
  6447. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6448. if (!player) {
  6449. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6450. return 0;
  6451. }
  6452. if (!player->IsPlayer()) {
  6453. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6454. return 0;
  6455. }
  6456. if (!ground) {
  6457. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6458. return 0;
  6459. }
  6460. if (!ground->IsGroundSpawn()) {
  6461. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6462. return 0;
  6463. }
  6464. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6465. if (!groundspawn_entries) {
  6466. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6467. return 0;
  6468. }
  6469. Skill* skill = 0;
  6470. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6471. if (collection_skill == "Collecting")
  6472. skill = ((Player*)player)->GetSkillByName("Gathering");
  6473. else
  6474. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6475. if (!skill) {
  6476. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6477. return 0;
  6478. }
  6479. vector<GroundSpawnEntry*>::iterator itr;
  6480. GroundSpawnEntry* entry = 0;
  6481. bool can_harvest = false;
  6482. sint32 min_skill = -1;
  6483. int16 totalSkill = skill->current_val;
  6484. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6485. if(skillID != 0xFFFFFFFF)
  6486. {
  6487. ((Entity*)player)->MStats.lock();
  6488. totalSkill += ((Entity*)player)->stats[skillID];
  6489. ((Entity*)player)->MStats.unlock();
  6490. }
  6491. // first, iterate through groundspawn_entries, discard tables player cannot use
  6492. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6493. {
  6494. entry = *itr;
  6495. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6496. min_skill = entry->min_skill_level;
  6497. // if player lacks skill, skip table
  6498. if (entry->min_skill_level > totalSkill)
  6499. continue;
  6500. // if bonus, but player lacks level, skip table
  6501. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6502. continue;
  6503. can_harvest = true;
  6504. break;
  6505. }
  6506. lua_interface->SetBooleanValue(state, can_harvest);
  6507. // If false, send the message to the client
  6508. if (!can_harvest) {
  6509. Client* client = player->GetZone()->GetClientBySpawn(player);
  6510. if (client) {
  6511. string msg = "You do not have enough skill to ";
  6512. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6513. msg.append("gather");
  6514. else if (collection_skill == "Mining")
  6515. msg.append("mine");
  6516. else if (collection_skill == "Trapping")
  6517. msg.append("trap");
  6518. else if (collection_skill == "Foresting")
  6519. msg.append("forest");
  6520. else if (collection_skill == "Fishing")
  6521. msg.append("catch");
  6522. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6523. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6524. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6525. }
  6526. }
  6527. return 1;
  6528. }
  6529. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6530. if (!lua_interface)
  6531. return 0;
  6532. Spawn* player = lua_interface->GetSpawn(state);
  6533. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6534. if (!player) {
  6535. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6536. return 0;
  6537. }
  6538. if (!player->IsPlayer()) {
  6539. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6540. return 0;
  6541. }
  6542. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6543. lua_interface->SetBooleanValue(state, ret);
  6544. return 1;
  6545. }
  6546. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6547. // Check to see if we have a valid lua_interface
  6548. if (!lua_interface)
  6549. return 0;
  6550. // Get the spawn that is getting the pet
  6551. Spawn* spawn = lua_interface->GetSpawn(state);
  6552. Spawn* target = lua_interface->GetSpawn(state, 2);
  6553. // Get the DB ID of the pet
  6554. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6555. float x = lua_interface->GetFloatValue(state, 4);
  6556. float y = lua_interface->GetFloatValue(state, 5);
  6557. float z = lua_interface->GetFloatValue(state, 6);
  6558. // Get the spell that this command was called from
  6559. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6560. // Check to make sure the spawn pointer is valid
  6561. if (!spawn) {
  6562. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6563. return 0;
  6564. }
  6565. // Check to make sure the spawn is an entity
  6566. if (!spawn->IsEntity()) {
  6567. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6568. return 0;
  6569. }
  6570. if (!target) {
  6571. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6572. return 0;
  6573. }
  6574. if (!target->IsEntity()) {
  6575. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6576. return 0;
  6577. }
  6578. // Check to see if the DB ID for the pet is set
  6579. if (pet_id == 0) {
  6580. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6581. return 0;
  6582. }
  6583. // Check to see if the pointer to the spell is valid
  6584. if (!luaspell) {
  6585. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6586. return 0;
  6587. }
  6588. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6589. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6590. if (!pet) {
  6591. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6592. return 0;
  6593. }
  6594. // Check to make sure the pet is an npc
  6595. if (!pet->IsNPC()) {
  6596. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6597. return 0;
  6598. }
  6599. if (x == 0)
  6600. x = spawn->GetX();
  6601. if (y == 0)
  6602. y = spawn->GetY();
  6603. if (z == 0)
  6604. z = spawn->GetZ();
  6605. // Spawn the pet at the same location as the owner
  6606. pet->SetX(x);
  6607. pet->SetY(y);
  6608. pet->SetZ(z);
  6609. pet->SetLocation(spawn->GetLocation());
  6610. pet->SetHeading(spawn->GetHeading());
  6611. spawn->GetZone()->AddSpawn(pet);
  6612. /*
  6613. const char* spawn_script = world.GetSpawnScript(pet_id);
  6614. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6615. spawn->SetSpawnScript(string(spawn_script));
  6616. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6617. }*/
  6618. // Get a random pet name
  6619. string random_pet_name;
  6620. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6621. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6622. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6623. // Set the pets name
  6624. pet->SetName(random_pet_name.c_str());
  6625. // Set the level of the pet to the owners level
  6626. pet->SetLevel(spawn->GetLevel());
  6627. // Set the faction of the pet to the same faction as the owner
  6628. pet->SetFactionID(spawn->GetFactionID());
  6629. // Set the spawn as a pet
  6630. pet->SetPet(true);
  6631. // Give a pointer of the owner to the pet
  6632. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6633. // Set the pet type
  6634. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6635. // Set the spell id used to create this pet
  6636. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6637. // Set the spell tier used to create this pet
  6638. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6639. // Set the pets spawn type to 6
  6640. pet->SetSpawnType(6);
  6641. // Set the pets brain
  6642. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6643. // Check to see if the pet has a subtitle
  6644. if (strlen(pet->GetSubTitle()) > 0) {
  6645. // Add the players name to the front of the sub title
  6646. string pet_subtitle;
  6647. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6648. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6649. // Set the pets subtitle to the new one
  6650. pet->SetSubTitle(pet_subtitle.c_str());
  6651. }
  6652. // Set the pet as the return value for this function
  6653. lua_interface->SetSpawnValue(state, pet);
  6654. return 1;
  6655. }
  6656. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6657. if (!lua_interface)
  6658. return 0;
  6659. Spawn* spawn = lua_interface->GetSpawn(state);
  6660. Spawn* player = lua_interface->GetSpawn(state, 2);
  6661. float max_distance = lua_interface->GetFloatValue(state, 3);
  6662. string type = lua_interface->GetStringValue(state, 4);
  6663. if (!spawn || (spawn && spawn->IsPlayer())) {
  6664. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6665. return 0;
  6666. }
  6667. if (!player || (player && !player->IsPlayer())) {
  6668. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6669. return 0;
  6670. }
  6671. Client* client = 0;
  6672. if (player->GetZone())
  6673. client = player->GetZone()->GetClientBySpawn(player);
  6674. if (!client) {
  6675. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6676. return 0;
  6677. }
  6678. //Set max_distance to default if not set or not proper value
  6679. if (max_distance <= 0)
  6680. max_distance = 500;
  6681. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6682. if (packet) {
  6683. float unknown2_3 = 0;
  6684. int8 placement_mode = 0;
  6685. if (type == "wall") {
  6686. placement_mode = 2;
  6687. unknown2_3 = 150;
  6688. }
  6689. else if (type == "ceiling")
  6690. placement_mode = 1;
  6691. packet->setDataByName("placement_mode", placement_mode);
  6692. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6693. packet->setDataByName("model_type", spawn->GetModelType());
  6694. packet->setDataByName("unknown", 1); //size
  6695. packet->setDataByName("unknown2", 1); //size 2
  6696. packet->setDataByName("unknown2", .5, 1); //size 3
  6697. packet->setDataByName("unknown2", 3, 2);
  6698. packet->setDataByName("unknown2", unknown2_3, 3);
  6699. packet->setDataByName("max_distance", max_distance);
  6700. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6701. client->QueuePacket(packet->serialize());
  6702. safe_delete(packet);
  6703. }
  6704. return 0;
  6705. }
  6706. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6707. if (!lua_interface)
  6708. return 0;
  6709. Item* item = lua_interface->GetItem(state);
  6710. if (!item) {
  6711. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6712. return 0;
  6713. }
  6714. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6715. return 1;
  6716. }
  6717. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6718. if (!lua_interface)
  6719. return 0;
  6720. Spawn* spawn = lua_interface->GetSpawn(state);
  6721. if (!spawn) {
  6722. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6723. return 0;
  6724. }
  6725. if (spawn->GetZone())
  6726. spawn->GetZone()->AddTransportSpawn(spawn);
  6727. return 0;
  6728. }
  6729. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  6730. if (!lua_interface)
  6731. return 0;
  6732. Spawn* spawn = lua_interface->GetSpawn(state);
  6733. if (!spawn) {
  6734. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6735. return 0;
  6736. }
  6737. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  6738. return 1;
  6739. }
  6740. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6741. if (!lua_interface)
  6742. return 0;
  6743. Skill* skill = lua_interface->GetSkill(state);
  6744. if (!skill) {
  6745. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6746. return 0;
  6747. }
  6748. lua_interface->SetInt32Value(state, skill->current_val);
  6749. return 1;
  6750. }
  6751. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6752. if (!lua_interface)
  6753. return 0;
  6754. Skill* skill = lua_interface->GetSkill(state);
  6755. if (!skill) {
  6756. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6757. return 0;
  6758. }
  6759. lua_interface->SetInt32Value(state, skill->max_val);
  6760. return 1;
  6761. }
  6762. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6763. if (!lua_interface)
  6764. return 0;
  6765. Skill* skill = lua_interface->GetSkill(state);
  6766. if (!skill) {
  6767. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6768. return 0;
  6769. }
  6770. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6771. return 1;
  6772. }
  6773. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6774. if (!lua_interface)
  6775. return 0;
  6776. Skill* skill = lua_interface->GetSkill(state);
  6777. int16 value = lua_interface->GetInt16Value(state, 2);
  6778. if (!skill) {
  6779. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6780. return 0;
  6781. }
  6782. skill->max_val = value;
  6783. if (skill->max_val < skill->current_val)
  6784. skill->current_val = skill->max_val;
  6785. return 0;
  6786. }
  6787. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6788. if (!lua_interface)
  6789. return 0;
  6790. Skill* skill = lua_interface->GetSkill(state);
  6791. int16 value = lua_interface->GetInt16Value(state, 2);
  6792. if (!skill) {
  6793. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6794. return 0;
  6795. }
  6796. if (value > skill->max_val)
  6797. skill->current_val = skill->max_val;
  6798. else
  6799. skill->current_val = value;
  6800. return 0;
  6801. }
  6802. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6803. if (!lua_interface)
  6804. return 0;
  6805. Spawn* player = lua_interface->GetSpawn(state);
  6806. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6807. if (skill_id > 0 && player && player->IsPlayer()) {
  6808. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6809. return 1;
  6810. }
  6811. return 0;
  6812. }
  6813. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6814. if (!lua_interface)
  6815. return 0;
  6816. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6817. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6818. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6819. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6820. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6821. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6822. if (player_spawn && player_spawn->IsPlayer()) {
  6823. Player* player = (Player*)player_spawn;
  6824. bool added = false;
  6825. if (!player->skill_list.HasSkill(skill_id)) {
  6826. player->AddSkill(skill_id, current_val, max_val, true);
  6827. added = true;
  6828. }
  6829. 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
  6830. Client* client = player->GetClient();
  6831. if (client) {
  6832. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6833. if (packet)
  6834. client->QueuePacket(packet);
  6835. }
  6836. }
  6837. if (added) {
  6838. lua_interface->SetBooleanValue(state, true);
  6839. return 1;
  6840. }
  6841. }
  6842. else {
  6843. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6844. }
  6845. }
  6846. else {
  6847. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6848. }
  6849. lua_interface->SetBooleanValue(state, false);
  6850. return 1;
  6851. }
  6852. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6853. if (!lua_interface)
  6854. return 0;
  6855. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6856. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6857. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6858. if (skill_id > 0) {
  6859. if (player_spawn && player_spawn->IsPlayer()) {
  6860. Player* player = (Player*)player_spawn;
  6861. if (player->skill_list.HasSkill(skill_id)) {
  6862. player->RemovePlayerSkill(skill_id);
  6863. if (!more_to_remove) {
  6864. Client* client = player->GetClient();
  6865. if (client) {
  6866. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6867. if (packet)
  6868. client->QueuePacket(packet);
  6869. }
  6870. }
  6871. }
  6872. }
  6873. else {
  6874. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6875. }
  6876. }
  6877. else {
  6878. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6879. }
  6880. return 0;
  6881. }
  6882. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6883. if (!lua_interface)
  6884. return 0;
  6885. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6886. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6887. int16 amount = lua_interface->GetInt8Value(state, 3);
  6888. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6889. if (amount > 0 && skill_type < 100) {
  6890. if (player_spawn && player_spawn->IsPlayer()) {
  6891. Player* player = (Player*)player_spawn;
  6892. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6893. if (!more_to_increase) {
  6894. Client* client = player->GetClient();
  6895. if (client) {
  6896. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6897. if (packet)
  6898. client->QueuePacket(packet);
  6899. }
  6900. }
  6901. }
  6902. else {
  6903. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6904. }
  6905. }
  6906. else {
  6907. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6908. }
  6909. return 0;
  6910. }
  6911. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6912. if (!lua_interface)
  6913. return 0;
  6914. Spawn* spawn = lua_interface->GetSpawn(state);
  6915. string name = lua_interface->GetStringValue(state, 2);
  6916. if (!spawn) {
  6917. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6918. return 0;
  6919. }
  6920. if (!spawn->IsEntity()) {
  6921. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6922. return 0;
  6923. }
  6924. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6925. if (skill) {
  6926. lua_interface->SetSkillValue(state, skill);
  6927. return 1;
  6928. }
  6929. return 0;
  6930. }
  6931. int EQ2Emu_lua_AddProc(lua_State* state) {
  6932. if (!lua_interface)
  6933. return 0;
  6934. Spawn* spawn = lua_interface->GetSpawn(state);
  6935. int8 type = lua_interface->GetInt8Value(state, 2);
  6936. float chance = lua_interface->GetFloatValue(state, 3);
  6937. Item* item = lua_interface->GetItem(state, 4);
  6938. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6939. LuaSpell* spell = 0;
  6940. if (!spawn && (!spell || !use_all_spelltargets)) {
  6941. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6942. return 0;
  6943. }
  6944. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6945. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6946. return 0;
  6947. }
  6948. if (!item)
  6949. spell = lua_interface->GetCurrentSpell(state);
  6950. if (!item && !spell) {
  6951. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6952. return 0;
  6953. }
  6954. if (spell && use_all_spelltargets) {
  6955. Spawn* target;
  6956. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6957. for (int8 i = 0; i < spell->targets.size(); i++) {
  6958. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6959. if (!target || !target->IsEntity())
  6960. continue;
  6961. ((Entity*)target)->AddProc(type, chance, item, spell);
  6962. }
  6963. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6964. }
  6965. else
  6966. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6967. return 0;
  6968. }
  6969. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6970. if (!lua_interface)
  6971. return 0;
  6972. Spawn* spawn = lua_interface->GetSpawn(state);
  6973. Item* item = lua_interface->GetItem(state, 2);
  6974. LuaSpell* spell = 0;
  6975. if (!spawn) {
  6976. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6977. return 0;
  6978. }
  6979. if (!spawn->IsEntity()) {
  6980. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6981. return 0;
  6982. }
  6983. if (!item)
  6984. spell = lua_interface->GetCurrentSpell(state);
  6985. if (!item && !spell) {
  6986. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6987. return 0;
  6988. }
  6989. if (spell) {
  6990. Spawn* target;
  6991. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6992. for (int8 i = 0; i < spell->targets.size(); i++) {
  6993. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6994. if (!target || !target->IsEntity())
  6995. continue;
  6996. ((Entity*)target)->RemoveProc(item, spell);
  6997. }
  6998. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6999. spell->caster->RemoveProc(item, spell);
  7000. }
  7001. else
  7002. ((Entity*)spawn)->RemoveProc(item, spell);
  7003. return 0;
  7004. }
  7005. int EQ2Emu_lua_Knockback(lua_State* state) {
  7006. if (!lua_interface)
  7007. return 0;
  7008. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7009. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7010. int32 duration = lua_interface->GetInt32Value(state, 3);
  7011. float vertical = lua_interface->GetFloatValue(state, 4);
  7012. float horizontal = lua_interface->GetFloatValue(state, 5);
  7013. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7014. if (!target_spawn) {
  7015. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7016. return 0;
  7017. }
  7018. if (!spawn) {
  7019. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7020. return 0;
  7021. }
  7022. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7023. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7024. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7025. if (packet) {
  7026. packet->setDataByName("target_x", target_spawn->GetX());
  7027. packet->setDataByName("target_y", target_spawn->GetY());
  7028. packet->setDataByName("target_z", target_spawn->GetZ());
  7029. packet->setDataByName("vertical_movement", vertical);
  7030. packet->setDataByName("horizontal_movement", horizontal);
  7031. if (use_heading)
  7032. packet->setDataByName("use_player_heading", 1);
  7033. client->QueuePacket(packet->serialize());
  7034. }
  7035. safe_delete(packet);
  7036. }
  7037. return 0;
  7038. }
  7039. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7040. if (!lua_interface)
  7041. return 0;
  7042. Spawn* spawn = lua_interface->GetSpawn(state);
  7043. if (!spawn) {
  7044. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7045. return 0;
  7046. }
  7047. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7048. return 1;
  7049. }
  7050. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7051. if (!lua_interface)
  7052. return 0;
  7053. Spawn* caster = lua_interface->GetSpawn(state);
  7054. Spawn* target = lua_interface->GetSpawn(state, 2);
  7055. string name = lua_interface->GetStringValue(state, 3);
  7056. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7057. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7058. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7059. string success_msg = lua_interface->GetStringValue(state, 7);
  7060. string effect_msg = lua_interface->GetStringValue(state, 8);
  7061. if (!caster) {
  7062. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7063. return 0;
  7064. }
  7065. if (!caster->IsEntity()) {
  7066. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7067. return 0;
  7068. }
  7069. if (!target) {
  7070. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7071. return 0;
  7072. }
  7073. if (!target->IsEntity()) {
  7074. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7075. return 0;
  7076. }
  7077. if (name.length() == 0) {
  7078. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7079. return 0;
  7080. }
  7081. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7082. return 0;
  7083. }
  7084. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7085. if (!lua_interface)
  7086. return 0;
  7087. string name = lua_interface->GetStringValue(state);
  7088. if (name.length() == 0) {
  7089. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7090. return 0;
  7091. }
  7092. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7093. if (!skill) {
  7094. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7095. return 0;
  7096. }
  7097. lua_interface->SetInt32Value(state, skill->skill_id);
  7098. return 1;
  7099. }
  7100. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7101. if (!lua_interface)
  7102. return 0;
  7103. Spawn* spawn = lua_interface->GetSpawn(state);
  7104. if (!spawn) {
  7105. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7106. return 0;
  7107. }
  7108. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7109. return 1;
  7110. }
  7111. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7112. if (!lua_interface)
  7113. return 0;
  7114. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7115. if (!luaspell) {
  7116. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7117. return 0;
  7118. }
  7119. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7120. return 1;
  7121. }
  7122. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7123. if (!lua_interface)
  7124. return 0;
  7125. Spawn* spawn = lua_interface->GetSpawn(state);
  7126. Spawn* target = lua_interface->GetSpawn(state, 2);
  7127. if (!spawn) {
  7128. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7129. return 0;
  7130. }
  7131. if (!spawn->IsEntity()) {
  7132. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7133. return 0;
  7134. }
  7135. if (!target) {
  7136. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7137. return 0;
  7138. }
  7139. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7140. return 1;
  7141. }
  7142. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7143. if (!lua_interface)
  7144. return 0;
  7145. Spawn* spawn = lua_interface->GetSpawn(state);
  7146. Spawn* target = lua_interface->GetSpawn(state, 2);
  7147. if (!spawn) {
  7148. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7149. return 0;
  7150. }
  7151. if (!spawn->IsEntity()) {
  7152. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7153. return 0;
  7154. }
  7155. if (!target) {
  7156. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7157. return 0;
  7158. }
  7159. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7160. return 1;
  7161. }
  7162. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7163. if (!lua_interface)
  7164. return 0;
  7165. Item* item = lua_interface->GetItem(state);
  7166. if (!item) {
  7167. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7168. return 0;
  7169. }
  7170. lua_interface->SetInt32Value(state, item->details.count);
  7171. return 1;
  7172. }
  7173. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7174. if (!lua_interface)
  7175. return 0;
  7176. Item* item = lua_interface->GetItem(state);
  7177. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7178. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7179. if (!item) {
  7180. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7181. return 0;
  7182. }
  7183. if (!owner) {
  7184. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7185. return 0;
  7186. }
  7187. if (!owner->IsPlayer()) {
  7188. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7189. return 0;
  7190. }
  7191. if (item->stack_count < new_count) {
  7192. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7193. return 0;
  7194. }
  7195. if (new_count > 0) {
  7196. item->details.count = new_count;
  7197. item->save_needed = true;
  7198. }
  7199. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7200. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7201. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7202. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7203. else
  7204. {
  7205. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7206. return 0;
  7207. }
  7208. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7209. if (!client)
  7210. return 0;
  7211. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7212. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7213. if (app)
  7214. client->QueuePacket(app);
  7215. return 0;
  7216. }
  7217. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7218. if (!lua_interface)
  7219. return 0;
  7220. int32 time = lua_interface->GetInt32Value(state);
  7221. string function = lua_interface->GetStringValue(state, 2);
  7222. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7223. Spawn* target = lua_interface->GetSpawn(state, 4);
  7224. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7225. if (time == 0) {
  7226. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7227. return 0;
  7228. }
  7229. if (function.length() == 0) {
  7230. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7231. return 0;
  7232. }
  7233. if (!spell) {
  7234. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7235. return 0;
  7236. }
  7237. SpellScriptTimer* timer = new SpellScriptTimer;
  7238. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7239. #ifdef WIN32
  7240. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7241. #else
  7242. bzero(timer, sizeof(SpellScriptTimer));
  7243. #endif*/
  7244. timer->caster = 0;
  7245. timer->deleteWhenDone = false;
  7246. timer->target = 0;
  7247. timer->time = Timer::GetCurrentTime2() + time;
  7248. timer->customFunction = function;
  7249. timer->spell = spell;
  7250. if (caster)
  7251. timer->caster = caster->GetID();
  7252. if (target)
  7253. timer->target = target->GetID();
  7254. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7255. return 0;
  7256. }
  7257. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7258. if (!lua_interface)
  7259. return 0;
  7260. float hp_perc = lua_interface->GetFloatValue(state);
  7261. float power_perc = lua_interface->GetFloatValue(state, 2);
  7262. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7263. Spawn* target = lua_interface->GetSpawn(state, 4);
  7264. string heal_name = lua_interface->GetStringValue(state, 5);
  7265. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7266. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7267. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7268. if (!spell) {
  7269. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7270. return 0;
  7271. }
  7272. Entity* caster = spell->caster;
  7273. if (!caster) {
  7274. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7275. return 0;
  7276. }
  7277. Client* client = 0;
  7278. PendingResurrection* rez = 0;
  7279. ZoneServer* zone = spell->caster->GetZone();
  7280. if (!target) {
  7281. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7282. if (spell->targets.size() > 0) {
  7283. vector<int32> spell_targets = spell->targets;
  7284. for (int8 i = 0; i < spell_targets.size(); i++) {
  7285. target = zone->GetSpawnByID(spell_targets.at(i));
  7286. if (!target)
  7287. continue;
  7288. if (!target->IsPlayer())
  7289. continue;
  7290. client = target->GetZone()->GetClientBySpawn(target);
  7291. if (!client)
  7292. continue;
  7293. rez = client->GetCurrentRez();
  7294. if (rez->active)
  7295. continue;
  7296. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7297. rez->active = true;
  7298. rez->caster = caster;
  7299. rez->expire_timer = new Timer;
  7300. int32 duration = spell->spell->GetSpellDuration();
  7301. rez->expire_timer->Start(duration * 100);
  7302. rez->hp_perc = hp_perc;
  7303. rez->mp_perc = power_perc;
  7304. rez->range = spell->spell->GetSpellData()->range;
  7305. rez->spell_name = spell->spell->GetName();
  7306. if (heal_name.length() > 0)
  7307. rez->heal_name = heal_name;
  7308. else
  7309. rez->heal_name = rez->spell_name;
  7310. rez->no_calcs = no_calcs;
  7311. rez->crit_mod = crit_mod;
  7312. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7313. if (send_window)
  7314. client->SendResurrectionWindow();
  7315. else {
  7316. target->GetZone()->ResurrectSpawn(target, client);
  7317. rez->should_delete = true;
  7318. }
  7319. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7320. }
  7321. }
  7322. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7323. }
  7324. else {
  7325. client = target->GetZone()->GetClientBySpawn(target);
  7326. if (!client)
  7327. return 0;
  7328. rez = client->GetCurrentRez();
  7329. if (rez->active)
  7330. return 0;
  7331. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7332. rez->active = true;
  7333. rez->caster = caster;
  7334. rez->expire_timer = new Timer;
  7335. int32 duration = spell->spell->GetSpellDuration();
  7336. rez->expire_timer->Start(duration * 100);
  7337. rez->hp_perc = hp_perc;
  7338. rez->mp_perc = power_perc;
  7339. rez->range = spell->spell->GetSpellData()->range;
  7340. rez->spell_name = spell->spell->GetName();
  7341. if (heal_name.length() > 0)
  7342. rez->heal_name = heal_name;
  7343. else
  7344. rez->heal_name = rez->spell_name;
  7345. rez->no_calcs = no_calcs;
  7346. rez->crit_mod = crit_mod;
  7347. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7348. if (send_window)
  7349. client->SendResurrectionWindow();
  7350. else {
  7351. target->GetZone()->ResurrectSpawn(target, client);
  7352. rez->should_delete = true;
  7353. }
  7354. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7355. }
  7356. return 0;
  7357. }
  7358. int EQ2Emu_lua_SetVision(lua_State* state) {
  7359. if (!lua_interface)
  7360. return 0;
  7361. Spawn* spawn = lua_interface->GetSpawn(state);
  7362. int8 vision = lua_interface->GetInt8Value(state, 2);
  7363. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7364. if (!spawn) {
  7365. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7366. return 0;
  7367. }
  7368. if (!spawn->IsEntity()) {
  7369. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7370. return 0;
  7371. }
  7372. if (spell && spell->targets.size() > 0) {
  7373. ZoneServer* zone = spell->caster->GetZone();
  7374. for (int8 i = 0; i < spell->targets.size(); i++) {
  7375. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7376. if (target && target->IsEntity()) {
  7377. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7378. if (target->IsPlayer())
  7379. ((Player*)target)->SetCharSheetChanged(true);
  7380. }
  7381. }
  7382. }
  7383. else {
  7384. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7385. if (spawn->IsPlayer())
  7386. ((Player*)spawn)->SetCharSheetChanged(true);
  7387. }
  7388. return 0;
  7389. }
  7390. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7391. if (!lua_interface)
  7392. return 0;
  7393. Spawn* spawn = lua_interface->GetSpawn(state);
  7394. float intensity = lua_interface->GetFloatValue(state, 2);
  7395. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7396. if (!spawn) {
  7397. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7398. return 0;
  7399. }
  7400. if (!spawn->IsEntity()) {
  7401. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7402. return 0;
  7403. }
  7404. if (spell && spell->targets.size() > 0) {
  7405. ZoneServer* zone = spell->caster->GetZone();
  7406. for (int8 i = 0; i < spell->targets.size(); i++) {
  7407. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7408. if (target && target->IsEntity()) {
  7409. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7410. if (target->IsPlayer())
  7411. ((Player*)target)->SetCharSheetChanged(true);
  7412. }
  7413. }
  7414. }
  7415. else {
  7416. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7417. if (spawn->IsPlayer())
  7418. ((Player*)spawn)->SetCharSheetChanged(true);
  7419. }
  7420. return 0;
  7421. }
  7422. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7423. if (!lua_interface)
  7424. return 0;
  7425. Spawn* spawn = lua_interface->GetSpawn(state);
  7426. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7427. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7428. if (!spawn) {
  7429. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7430. return 0;
  7431. }
  7432. if (!spawn->IsEntity()) {
  7433. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7434. return 0;
  7435. }
  7436. if (spell && spell->targets.size() > 0) {
  7437. ZoneServer* zone = spell->caster->GetZone();
  7438. for (int8 i = 0; i < spell->targets.size(); i++) {
  7439. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7440. if (target && target->IsEntity()) {
  7441. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7442. if (target->IsPlayer())
  7443. ((Player*)target)->SetCharSheetChanged(true);
  7444. }
  7445. }
  7446. }
  7447. else {
  7448. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7449. if (spawn->IsPlayer())
  7450. ((Player*)spawn)->SetCharSheetChanged(true);
  7451. }
  7452. return 0;
  7453. }
  7454. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7455. if (!lua_interface)
  7456. return 0;
  7457. Item* item = lua_interface->GetItem(state);
  7458. int8 type = lua_interface->GetInt32Value(state, 2);
  7459. if (!item) {
  7460. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7461. return 0;
  7462. }
  7463. if (type == 1)
  7464. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7465. else if (type == 2)
  7466. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7467. return 1;
  7468. }
  7469. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7470. if (!lua_interface)
  7471. return 0;
  7472. Spawn* target = lua_interface->GetSpawn(state);
  7473. float val = lua_interface->GetFloatValue(state, 2);
  7474. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7475. // Added from Gangrenous post
  7476. if (spell && spell->resisted)
  7477. return 0;
  7478. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7479. if (val > 1.0f)
  7480. val = 1.0f - (val / 100.0f);
  7481. if (spell && spell->spell && spell->targets.size() > 0) {
  7482. ZoneServer* zone = spell->caster->GetZone();
  7483. for (int32 i = 0; i != spell->targets.size(); i++) {
  7484. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7485. if (spawn && spawn->IsEntity()) {
  7486. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7487. if (spawn->IsPlayer())
  7488. ((Player*)spawn)->SetCharSheetChanged(true);
  7489. }
  7490. }
  7491. }
  7492. else {
  7493. if (target && target->IsEntity()) {
  7494. ((Entity*)target)->SetSpeedMultiplier(val);
  7495. if (target->IsPlayer())
  7496. ((Player*)target)->SetCharSheetChanged(true);
  7497. }
  7498. }
  7499. return 0;
  7500. }
  7501. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7502. if (!lua_interface)
  7503. return 0;
  7504. Spawn* spawn = lua_interface->GetSpawn(state);
  7505. int16 model = lua_interface->GetInt16Value(state, 2);
  7506. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7507. if (spell && spell->spell && spell->targets.size() > 0) {
  7508. ZoneServer* zone = spell->caster->GetZone();
  7509. for (int32 i = 0; i < spell->targets.size(); i++) {
  7510. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7511. if (target)
  7512. target->SetIllusionModel(model);
  7513. }
  7514. }
  7515. else {
  7516. if (!spawn) {
  7517. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7518. return 0;
  7519. }
  7520. spawn->SetIllusionModel(model);
  7521. }
  7522. return 0;
  7523. }
  7524. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7525. if (!lua_interface)
  7526. return 0;
  7527. Spawn* spawn = lua_interface->GetSpawn(state);
  7528. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7529. if (spell && spell->spell && spell->targets.size() > 0) {
  7530. ZoneServer* zone = spell->caster->GetZone();
  7531. for (int32 i = 0; i < spell->targets.size(); i++) {
  7532. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7533. if (target)
  7534. target->SetIllusionModel(0);
  7535. }
  7536. }
  7537. else {
  7538. if (!spawn) {
  7539. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7540. return 0;
  7541. }
  7542. spawn->SetIllusionModel(0);
  7543. }
  7544. return 0;
  7545. }
  7546. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7547. if (!lua_interface)
  7548. return 0;
  7549. Spawn* caster = lua_interface->GetSpawn(state);
  7550. Spawn* target = lua_interface->GetSpawn(state, 2);
  7551. float chance = lua_interface->GetFloatValue(state, 3);
  7552. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7553. if (!caster) {
  7554. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7555. return 0;
  7556. }
  7557. if (!caster->IsEntity()) {
  7558. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7559. return 0;
  7560. }
  7561. if (!target) {
  7562. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7563. return 0;
  7564. }
  7565. if (!target->IsEntity()) {
  7566. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7567. return 0;
  7568. }
  7569. if (chance <= 0) {
  7570. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7571. return 0;
  7572. }
  7573. if (!spell) {
  7574. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7575. return 0;
  7576. }
  7577. if (((Entity*)caster)->GetThreatTransfer()) {
  7578. return 0;
  7579. }
  7580. ThreatTransfer* transfer = new ThreatTransfer;
  7581. transfer->Target = target->GetID();
  7582. transfer->Amount = chance;
  7583. transfer->Spell = spell;
  7584. ((Entity*)caster)->SetThreatTransfer(transfer);
  7585. return 0;
  7586. }
  7587. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7588. if (!lua_interface)
  7589. return 0;
  7590. Spawn* spawn = lua_interface->GetSpawn(state);
  7591. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7592. if (!spawn) {
  7593. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7594. return 0;
  7595. }
  7596. if (!spell) {
  7597. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7598. return 0;
  7599. }
  7600. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7601. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7602. ((Entity*)spawn)->SetThreatTransfer(0);
  7603. safe_delete(transfer);
  7604. }
  7605. return 0;
  7606. }
  7607. int EQ2Emu_lua_CureByType(lua_State* state) {
  7608. if (!lua_interface)
  7609. return 0;
  7610. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7611. if (!spell) {
  7612. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7613. return 0;
  7614. }
  7615. int8 cure_count = lua_interface->GetInt8Value(state);
  7616. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7617. string cure_name = lua_interface->GetStringValue(state, 3);
  7618. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7619. Spawn* target = lua_interface->GetSpawn(state, 5);
  7620. if (target) {
  7621. if (!target->IsEntity()) {
  7622. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7623. return 0;
  7624. }
  7625. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7626. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7627. }
  7628. else {
  7629. ZoneServer* zone = spell->caster->GetZone();
  7630. vector<int32> targets = spell->targets;
  7631. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7632. for (int8 i = 0; i < targets.size(); i++) {
  7633. target = zone->GetSpawnByID(targets.at(i));
  7634. if (!target || !target->IsEntity())
  7635. continue;
  7636. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7637. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7638. }
  7639. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7640. }
  7641. return 0;
  7642. }
  7643. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7644. if (!lua_interface)
  7645. return 0;
  7646. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7647. if (!spell) {
  7648. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7649. return 0;
  7650. }
  7651. int8 cure_count = lua_interface->GetInt8Value(state);
  7652. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7653. string cure_name = lua_interface->GetStringValue(state, 3);
  7654. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7655. Spawn* target = lua_interface->GetSpawn(state, 5);
  7656. if (target) {
  7657. if (!target->IsEntity()) {
  7658. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7659. return 0;
  7660. }
  7661. if (((Entity*)target)->GetDetCount() > 0)
  7662. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7663. }
  7664. else {
  7665. ZoneServer* zone = spell->caster->GetZone();
  7666. vector<int32> targets = spell->targets;
  7667. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7668. for (int8 i = 0; i < targets.size(); i++) {
  7669. target = zone->GetSpawnByID(targets.at(i));
  7670. if (!target || !target->IsEntity())
  7671. continue;
  7672. if (((Entity*)target)->GetDetCount() > 0)
  7673. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7674. }
  7675. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7676. }
  7677. return 0;
  7678. }
  7679. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7680. if (!lua_interface)
  7681. return 0;
  7682. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7683. if (!spell) {
  7684. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7685. return 0;
  7686. }
  7687. if (!spell->caster) {
  7688. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7689. return 0;
  7690. }
  7691. if (!spell->caster->GetZone()) {
  7692. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7693. return 0;
  7694. }
  7695. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7696. return 0;
  7697. }
  7698. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7699. if (!lua_interface)
  7700. return 0;
  7701. Spawn* spawn = lua_interface->GetSpawn(state);
  7702. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7703. if (!spell) {
  7704. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7705. return 0;
  7706. }
  7707. if (spawn && spawn->IsEntity())
  7708. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7709. else {
  7710. ZoneServer* zone = spell->caster->GetZone();
  7711. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7712. for (int32 i = 0; i < spell->targets.size(); i++) {
  7713. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7714. if (!spawn || !spawn->IsEntity())
  7715. continue;
  7716. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7717. }
  7718. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7719. }
  7720. return 0;
  7721. }
  7722. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7723. if (!lua_interface)
  7724. return 0;
  7725. Spawn* spawn = lua_interface->GetSpawn(state);
  7726. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7727. if (!spell) {
  7728. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7729. return 0;
  7730. }
  7731. if (spawn && spawn->IsEntity())
  7732. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7733. else {
  7734. ZoneServer* zone = spell->caster->GetZone();
  7735. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7736. for (int32 i = 0; i < spell->targets.size(); i++) {
  7737. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7738. if (!spawn || !spawn->IsEntity())
  7739. continue;
  7740. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7741. }
  7742. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7743. }
  7744. return 0;
  7745. }
  7746. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7747. if (!lua_interface)
  7748. return 0;
  7749. Spawn* caster = lua_interface->GetSpawn(state);
  7750. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7751. if (!caster) {
  7752. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7753. return 0;
  7754. }
  7755. if (!caster->IsPlayer()) {
  7756. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7757. return 0;
  7758. }
  7759. Spawn* target = caster->GetTarget();
  7760. if (!target) {
  7761. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7762. return 0;
  7763. }
  7764. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7765. if (!client) {
  7766. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7767. return 0;
  7768. }
  7769. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7770. if (ho) {
  7771. ho->SetTarget(target->GetID());
  7772. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7773. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7774. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7775. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7776. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7777. deque<GroupMemberInfo*>::iterator itr;
  7778. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7779. if (group)
  7780. {
  7781. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7782. deque<GroupMemberInfo*>* members = group->GetMembers();
  7783. for (itr = members->begin(); itr != members->end(); itr++) {
  7784. if ((*itr)->client)
  7785. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7786. }
  7787. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7788. }
  7789. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7790. }
  7791. else
  7792. safe_delete(ho);
  7793. }
  7794. else {
  7795. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7796. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7797. }
  7798. else
  7799. safe_delete(ho);
  7800. }
  7801. }
  7802. return 0;
  7803. }
  7804. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7805. if (!lua_interface)
  7806. return 0;
  7807. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7808. if (!spell) {
  7809. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7810. return 0;
  7811. }
  7812. int16 triggerCount = lua_interface->GetInt16Value(state);
  7813. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7814. if (!triggerCount) {
  7815. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7816. return 0;
  7817. }
  7818. spell->num_triggers = triggerCount;
  7819. spell->had_triggers = true;
  7820. spell->cancel_after_all_triggers = cancel_after_triggers;
  7821. return 0;
  7822. }
  7823. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7824. if (!lua_interface)
  7825. return 0;
  7826. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7827. if (!spell) {
  7828. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7829. return 0;
  7830. }
  7831. lua_interface->SetInt32Value(state, spell->num_triggers);
  7832. return 1;
  7833. }
  7834. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7835. if (!lua_interface)
  7836. return 0;
  7837. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7838. if (!spell) {
  7839. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7840. return 0;
  7841. }
  7842. int16 remove_count = lua_interface->GetInt16Value(state);
  7843. if (!remove_count)
  7844. remove_count = 1;
  7845. if (remove_count >= spell->num_triggers) {
  7846. spell->num_triggers = 0;
  7847. if (spell->cancel_after_all_triggers)
  7848. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7849. }
  7850. else {
  7851. spell->num_triggers -= remove_count;
  7852. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7853. }
  7854. return 0;
  7855. }
  7856. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7857. if (!lua_interface)
  7858. return 0;
  7859. Spawn* spawn = lua_interface->GetSpawn(state);
  7860. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7861. if (!spawn) {
  7862. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7863. return 0;
  7864. }
  7865. if (!copy_spawn) {
  7866. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7867. return 0;
  7868. }
  7869. spawn->CopySpawnAppearance(copy_spawn);
  7870. return 0;
  7871. }
  7872. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7873. Spawn* spawn = lua_interface->GetSpawn(state);
  7874. int8 type = lua_interface->GetInt8Value(state, 2);
  7875. if (!spawn) {
  7876. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7877. return 0;
  7878. }
  7879. else if (!spawn->IsEntity()) {
  7880. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7881. return 0;
  7882. }
  7883. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7884. return 1;
  7885. }
  7886. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7887. if (!lua_interface)
  7888. return 0;
  7889. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7890. int8 type = lua_interface->GetInt8Value(state);
  7891. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7892. if (!spell) {
  7893. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7894. return 0;
  7895. }
  7896. if (spawn) {
  7897. if (!spawn->IsEntity()) {
  7898. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7899. return 0;
  7900. }
  7901. Entity* entity = ((Entity*)spawn);
  7902. entity->AddImmunity(spell, type);
  7903. }
  7904. else {
  7905. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7906. for (int8 i = 0; i < spell->targets.size(); i++) {
  7907. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7908. if (!spawn || !spawn->IsEntity())
  7909. continue;
  7910. Entity* entity = ((Entity*)spawn);
  7911. entity->AddImmunity(spell, type);
  7912. }
  7913. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7914. }
  7915. return 0;
  7916. }
  7917. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7918. if (!lua_interface)
  7919. return 0;
  7920. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7921. int8 type = lua_interface->GetInt8Value(state);
  7922. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7923. if (!spell) {
  7924. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7925. return 0;
  7926. }
  7927. if (spawn) {
  7928. if (!spawn->IsEntity()) {
  7929. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7930. return 0;
  7931. }
  7932. Entity* entity = ((Entity*)spawn);
  7933. entity->RemoveImmunity(spell, type);
  7934. }
  7935. else {
  7936. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7937. for (int8 i = 0; i < spell->targets.size(); i++) {
  7938. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7939. if (!spawn || !spawn->IsEntity())
  7940. continue;
  7941. Entity* entity = ((Entity*)spawn);
  7942. entity->RemoveImmunity(spell, type);
  7943. }
  7944. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7945. }
  7946. return 0;
  7947. }
  7948. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7949. if (!lua_interface)
  7950. return 0;
  7951. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7952. if (!spell) {
  7953. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7954. return 0;
  7955. }
  7956. float snare = lua_interface->GetFloatValue(state);
  7957. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7958. // convert the val to the speed multipler value (100 - val)
  7959. float val = 100.0 - snare;
  7960. val /= 100.0;
  7961. if (spawn) {
  7962. if (!spawn->IsEntity()) {
  7963. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7964. return 0;
  7965. }
  7966. ((Entity*)spawn)->SetSnareValue(spell, val);
  7967. }
  7968. else {
  7969. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7970. for (int8 i = 0; i < spell->targets.size(); i++) {
  7971. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7972. if (!spawn || !spawn->IsEntity())
  7973. continue;
  7974. ((Entity*)spawn)->SetSnareValue(spell, val);
  7975. }
  7976. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7977. }
  7978. return 0;
  7979. }
  7980. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7981. if (!lua_interface)
  7982. return 0;
  7983. Spawn* spawn = lua_interface->GetSpawn(state);
  7984. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7985. if (!spawn) {
  7986. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7987. return 0;
  7988. }
  7989. if (race_id == 0) {
  7990. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7991. return 0;
  7992. }
  7993. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7994. return 1;
  7995. }
  7996. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7997. if (!lua_interface)
  7998. return 0;
  7999. Spawn* spawn = lua_interface->GetSpawn(state);
  8000. if (!spawn) {
  8001. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8002. return 0;
  8003. }
  8004. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8005. return 1;
  8006. }
  8007. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8008. if (!lua_interface)
  8009. return 0;
  8010. Spawn* spawn = lua_interface->GetSpawn(state);
  8011. if (!spawn) {
  8012. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8013. return 0;
  8014. }
  8015. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8016. return 1;
  8017. }
  8018. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8019. if (!lua_interface)
  8020. return 0;
  8021. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8022. if (!spell) {
  8023. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8024. return 0;
  8025. }
  8026. lua_interface->SetStringValue(state, spell->spell->GetName());
  8027. return 1;
  8028. }
  8029. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8030. if (!lua_interface)
  8031. return 0;
  8032. Quest* quest = lua_interface->GetQuest(state);
  8033. if (!quest) {
  8034. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8035. return 0;
  8036. }
  8037. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8038. return 1;
  8039. }
  8040. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8041. if (!lua_interface)
  8042. return 0;
  8043. Quest* quest = lua_interface->GetQuest(state);
  8044. int32 flags = lua_interface->GetInt32Value(state, 2);
  8045. if (!quest) {
  8046. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8047. return 0;
  8048. }
  8049. quest->SetQuestFlags(flags);
  8050. return 0;
  8051. }
  8052. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8053. if (!lua_interface)
  8054. return 0;
  8055. Quest* quest = lua_interface->GetQuest(state);
  8056. Spawn* player = lua_interface->GetSpawn(state, 2);
  8057. int32 step = lua_interface->GetInt32Value(state, 3);
  8058. int32 duration = lua_interface->GetInt32Value(state, 4);
  8059. string action = lua_interface->GetStringValue(state, 5);
  8060. if (!quest) {
  8061. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8062. return 0;
  8063. }
  8064. if (!player) {
  8065. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8066. return 0;
  8067. }
  8068. if (!player->IsPlayer()) {
  8069. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8070. return 0;
  8071. }
  8072. if (step == 0) {
  8073. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8074. return 0;
  8075. }
  8076. if (duration == 0) {
  8077. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8078. return 0;
  8079. }
  8080. if (action.length() == 0) {
  8081. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8082. return 0;
  8083. }
  8084. Client* client = player->GetZone()->GetClientBySpawn(player);
  8085. if (!client) {
  8086. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8087. return 0;
  8088. }
  8089. quest->SetTimerStep(step);
  8090. quest->AddFailedAction(step, action);
  8091. quest->SetStepTimer(duration);
  8092. client->AddQuestTimer(quest->GetQuestID());
  8093. return 0;
  8094. }
  8095. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8096. if (!lua_interface)
  8097. return 0;
  8098. Quest* quest = lua_interface->GetQuest(state);
  8099. Spawn* player = lua_interface->GetSpawn(state, 2);
  8100. if (!quest) {
  8101. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8102. return 0;
  8103. }
  8104. if (!player) {
  8105. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8106. return 0;
  8107. }
  8108. if (!player->IsPlayer()) {
  8109. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8110. return 0;
  8111. }
  8112. Client* client = player->GetZone()->GetClientBySpawn(player);
  8113. if (!client) {
  8114. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8115. return 0;
  8116. }
  8117. quest->SetTimerStep(0);
  8118. quest->SetStepTimer(0);
  8119. client->RemoveQuestTimer(quest->GetQuestID());
  8120. return 0;
  8121. }
  8122. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8123. if (!lua_interface)
  8124. return 0;
  8125. Spawn* player = lua_interface->GetSpawn(state);
  8126. Quest* quest = lua_interface->GetQuest(state, 2);
  8127. int32 step = lua_interface->GetInt32Value(state, 3);
  8128. if (!player) {
  8129. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8130. return 0;
  8131. }
  8132. if (!player->IsPlayer()) {
  8133. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8134. return 0;
  8135. }
  8136. if (!quest) {
  8137. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8138. return 0;
  8139. }
  8140. if (step == 0) {
  8141. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8142. return 0;
  8143. }
  8144. Client* client = player->GetZone()->GetClientBySpawn(player);
  8145. if (!client) {
  8146. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8147. return 0;
  8148. }
  8149. if (quest->RemoveQuestStep(step, client)) {
  8150. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8151. client->GetCurrentZone()->SendQuestUpdates(client);
  8152. }
  8153. else
  8154. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8155. return 0;
  8156. }
  8157. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8158. if (!lua_interface)
  8159. return 0;
  8160. Quest* quest = lua_interface->GetQuest(state, 1);
  8161. int32 step = lua_interface->GetInt32Value(state, 2);
  8162. string desc = lua_interface->GetStringValue(state, 3);
  8163. string task_group = lua_interface->GetStringValue(state, 4);
  8164. if (!quest) {
  8165. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8166. return 0;
  8167. }
  8168. if (step == 0) {
  8169. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8170. return 0;
  8171. }
  8172. QuestStep* quest_step = quest->GetQuestStep(step);
  8173. if (!quest_step) {
  8174. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8175. return 0;
  8176. }
  8177. quest_step->SetStepProgress(0);
  8178. quest_step->SetTaskGroup(task_group);
  8179. quest_step->SetDescription(desc);
  8180. return 0;
  8181. }
  8182. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8183. if (!lua_interface)
  8184. return 0;
  8185. Quest* quest = lua_interface->GetQuest(state);
  8186. int32 step = lua_interface->GetInt32Value(state, 2);
  8187. string action = lua_interface->GetStringValue(state, 3);
  8188. if (!quest) {
  8189. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8190. return 0;
  8191. }
  8192. if (step == 0) {
  8193. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8194. return 0;
  8195. }
  8196. if (action.length() == 0) {
  8197. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8198. return 0;
  8199. }
  8200. quest->AddFailedAction(step, action);
  8201. return 0;
  8202. }
  8203. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8204. if (!lua_interface)
  8205. return 0;
  8206. Spawn* player = lua_interface->GetSpawn(state);
  8207. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8208. int32 step = lua_interface->GetInt32Value(state, 3);
  8209. if (!player) {
  8210. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8211. return 0;
  8212. }
  8213. if (!player->IsPlayer()) {
  8214. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8215. return 0;
  8216. }
  8217. if (quest_id == 0) {
  8218. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8219. return 0;
  8220. }
  8221. if (step == 0) {
  8222. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8223. return 0;
  8224. }
  8225. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8226. if (!quest) {
  8227. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8228. return 0;
  8229. }
  8230. quest->StepFailed(step);
  8231. return 0;
  8232. }
  8233. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8234. if (!lua_interface)
  8235. return 0;
  8236. Spawn* player = lua_interface->GetSpawn(state);
  8237. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8238. if (!player) {
  8239. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8240. return 0;
  8241. }
  8242. if (!player->IsPlayer()) {
  8243. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8244. return 0;
  8245. }
  8246. if (quest_id == 0) {
  8247. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8248. return 0;
  8249. }
  8250. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8251. if (!quest) {
  8252. lua_interface->SetInt32Value(state, 0);
  8253. return 1;
  8254. }
  8255. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8256. return 1;
  8257. }
  8258. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8259. if (!lua_interface)
  8260. return 0;
  8261. string name = lua_interface->GetStringValue(state);
  8262. string value = lua_interface->GetStringValue(state, 2);
  8263. string comment = lua_interface->GetStringValue(state, 3);
  8264. if (name.length() == 0) {
  8265. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8266. return 0;
  8267. }
  8268. if (value.length() == 0) {
  8269. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8270. return 0;
  8271. }
  8272. string varname = string("lua_").append(name);
  8273. Variable* var = variables.FindVariable(varname);
  8274. if (var)
  8275. var->SetValue(value.c_str());
  8276. else {
  8277. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8278. variables.AddVariable(var);
  8279. }
  8280. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8281. return 0;
  8282. }
  8283. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8284. if (!lua_interface)
  8285. return 0;
  8286. string name = lua_interface->GetStringValue(state);
  8287. if (name.length() == 0) {
  8288. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8289. return 0;
  8290. }
  8291. string varname = string("lua_").append(name);
  8292. Variable* var = variables.FindVariable(varname);
  8293. if (var)
  8294. lua_interface->SetStringValue(state, var->GetValue());
  8295. else
  8296. lua_interface->SetStringValue(state, "NULL");
  8297. return 1;
  8298. }
  8299. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8300. if (!lua_interface)
  8301. return 0;
  8302. Spawn* player = lua_interface->GetSpawn(state);
  8303. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8304. if (!player) {
  8305. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8306. return 0;
  8307. }
  8308. if (!player->IsPlayer()) {
  8309. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8310. return 0;
  8311. }
  8312. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8313. return 1;
  8314. }
  8315. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8316. if (!lua_interface)
  8317. return 0;
  8318. Spawn* player = lua_interface->GetSpawn(state);
  8319. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8320. if (!player) {
  8321. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. if (!player->IsPlayer()) {
  8325. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. Language* language = master_languages_list.GetLanguage(language_id);
  8329. if (language)
  8330. {
  8331. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8332. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8333. }
  8334. return 0;
  8335. }
  8336. int EQ2Emu_lua_IsNight(lua_State* state) {
  8337. if (!lua_interface)
  8338. return 0;
  8339. ZoneServer* zone = lua_interface->GetZone(state);
  8340. if (!zone) {
  8341. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8342. return 0;
  8343. }
  8344. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8345. return 1;
  8346. }
  8347. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8348. if (!lua_interface)
  8349. return 0;
  8350. Spawn* spawn = lua_interface->GetSpawn(state);
  8351. if (!spawn) {
  8352. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8353. return 0;
  8354. }
  8355. if (!spawn->IsWidget()) {
  8356. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8357. return 0;
  8358. }
  8359. ((Widget*)spawn)->SetMultiFloorLift(true);
  8360. if (spawn->GetZone())
  8361. spawn->GetZone()->AddTransportSpawn(spawn);
  8362. return 0;
  8363. }
  8364. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8365. if (!lua_interface)
  8366. return 0;
  8367. Spawn* player = lua_interface->GetSpawn(state);
  8368. int32 path = lua_interface->GetInt32Value(state, 2);
  8369. if (!player) {
  8370. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8371. return 0;
  8372. }
  8373. if (!player->IsPlayer()) {
  8374. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8375. return 0;
  8376. }
  8377. if (path == 0) {
  8378. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8379. return 0;
  8380. }
  8381. Client* client = player->GetZone()->GetClientBySpawn(player);
  8382. if (!client) {
  8383. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8384. return 0;
  8385. }
  8386. client->SendFlightAutoMount(path);
  8387. return 0;
  8388. }
  8389. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8390. if (!lua_interface)
  8391. return 0;
  8392. Spawn* player = lua_interface->GetSpawn(state);
  8393. if (!player) {
  8394. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8395. return 0;
  8396. }
  8397. if (!player->IsPlayer()) {
  8398. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8399. return 0;
  8400. }
  8401. Client* client = player->GetZone()->GetClientBySpawn(player);
  8402. if (!client) {
  8403. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8404. return 0;
  8405. }
  8406. client->EndAutoMount();
  8407. return 0;
  8408. }
  8409. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8410. if (!lua_interface)
  8411. return 0;
  8412. Spawn* player = lua_interface->GetSpawn(state);
  8413. if (!player) {
  8414. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8415. return 0;
  8416. }
  8417. if (!player->IsPlayer()) {
  8418. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8419. return 0;
  8420. }
  8421. Client* client = player->GetZone()->GetClientBySpawn(player);
  8422. if (!client) {
  8423. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8424. return 0;
  8425. }
  8426. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8427. return 1;
  8428. }
  8429. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8430. if (!lua_interface)
  8431. return 0;
  8432. Spawn* player = lua_interface->GetSpawn(state);
  8433. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8434. int32 value = lua_interface->GetInt32Value(state, 3);
  8435. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8436. if (!player) {
  8437. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8438. return 0;
  8439. }
  8440. if (!player->IsPlayer()) {
  8441. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8442. return 0;
  8443. }
  8444. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8445. return 0;
  8446. }
  8447. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8448. if (!lua_interface)
  8449. return 0;
  8450. Spawn* player = lua_interface->GetSpawn(state);
  8451. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8452. if (!player) {
  8453. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8454. return 0;
  8455. }
  8456. if (!player->IsPlayer()) {
  8457. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8458. return 0;
  8459. }
  8460. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8461. if (!hd)
  8462. return 0;
  8463. lua_interface->SetInt32Value(state, hd->Value);
  8464. lua_interface->SetInt32Value(state, hd->Value2);
  8465. return 2;
  8466. }
  8467. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8468. if (!lua_interface)
  8469. return 0;
  8470. Spawn* spawn = lua_interface->GetSpawn(state);
  8471. int32 grid = lua_interface->GetInt32Value(state, 2);
  8472. if (!spawn) {
  8473. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8474. return 0;
  8475. }
  8476. if (grid == 0) {
  8477. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8478. return 0;
  8479. }
  8480. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8481. return 0;
  8482. }
  8483. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8484. if (!lua_interface)
  8485. return 0;
  8486. Spawn* spawn = lua_interface->GetSpawn(state);
  8487. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8488. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8489. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8490. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8491. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8492. if (!spawn) {
  8493. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8494. return 0;
  8495. }
  8496. //Add this quest to the list of required quests for this spawn
  8497. spawn->SetRequiredHistory(event_id, value1, value2);
  8498. //If private spawn value set
  8499. if (private_spawn) {
  8500. //Set the spawn to be private when not granted access via history
  8501. spawn->AddAllowAccessSpawn(spawn);
  8502. spawn->SetPrivateQuestSpawn(true);
  8503. }
  8504. //This value will override vis_flags in the vis packet
  8505. if (flag_override > 0)
  8506. spawn->SetQuestsRequiredOverride(flag_override);
  8507. return 0;
  8508. }
  8509. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8510. if (!lua_interface)
  8511. return 0;
  8512. Spawn* player = lua_interface->GetSpawn(state);
  8513. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8514. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8515. if (!player) {
  8516. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8517. return 0;
  8518. }
  8519. if (!player->IsPlayer()) {
  8520. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8521. return 0;
  8522. }
  8523. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8524. return 1;
  8525. }
  8526. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8527. if (!lua_interface)
  8528. return 0;
  8529. Spawn* player = lua_interface->GetSpawn(state);
  8530. int8 level = lua_interface->GetInt8Value(state, 2);
  8531. if (!player) {
  8532. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8533. return 0;
  8534. }
  8535. if (!player->IsPlayer()) {
  8536. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8537. return 0;
  8538. }
  8539. if (level == 0) {
  8540. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8541. return 0;
  8542. }
  8543. Client* client = player->GetZone()->GetClientBySpawn(player);
  8544. if (!client) {
  8545. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8546. return 0;
  8547. }
  8548. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8549. return 0;
  8550. }
  8551. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8552. if (!lua_interface)
  8553. return 0;
  8554. Spawn* player = lua_interface->GetSpawn(state);
  8555. int32 amount = lua_interface->GetInt32Value(state, 2);
  8556. if (!player) {
  8557. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8558. return 0;
  8559. }
  8560. if (!player->IsPlayer()) {
  8561. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8562. return 0;
  8563. }
  8564. if (amount == 0) {
  8565. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8566. return 0;
  8567. }
  8568. ((Player*)player)->AddCoins(amount);
  8569. return 0;
  8570. }
  8571. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8572. if (!lua_interface)
  8573. return 0;
  8574. Spawn* player = lua_interface->GetSpawn(state);
  8575. int32 amount = lua_interface->GetInt32Value(state, 2);
  8576. if (!player) {
  8577. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8578. return 0;
  8579. }
  8580. if (!player->IsPlayer()) {
  8581. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8582. return 0;
  8583. }
  8584. if (amount == 0) {
  8585. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8586. return 0;
  8587. }
  8588. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8589. return 1;
  8590. }
  8591. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8592. if (!lua_interface)
  8593. return 0;
  8594. ZoneServer* zone = lua_interface->GetZone(state);
  8595. if (!zone) {
  8596. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8597. return 0;
  8598. }
  8599. vector<Entity*> players = zone->GetPlayers();
  8600. if (players.size() == 0)
  8601. return 0;
  8602. lua_createtable(state, players.size(), 0);
  8603. int newTable = lua_gettop(state);
  8604. for (int32 i = 0; i < players.size(); i++) {
  8605. lua_interface->SetSpawnValue(state, players.at(i));
  8606. lua_rawseti(state, newTable, i + 1);
  8607. }
  8608. return 1;
  8609. }
  8610. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8611. if (!lua_interface)
  8612. return 0;
  8613. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8614. if (!zone) {
  8615. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8616. return 0;
  8617. }
  8618. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8619. //Map of <placement_id, location_id>
  8620. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8621. map<int32, int32>::iterator itr;
  8622. vector<Spawn*> group;
  8623. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8624. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8625. if (!location) {
  8626. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8627. return 0;
  8628. }
  8629. Spawn* spawn = 0;
  8630. if (location->entities[0]) {
  8631. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8632. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8633. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8634. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8635. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8636. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8637. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8638. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8639. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8640. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8641. if (spawn) {
  8642. const char* script = 0;
  8643. for (int x = 0; x < 3; x++) {
  8644. switch (x) {
  8645. case 0:
  8646. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8647. break;
  8648. case 1:
  8649. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8650. break;
  8651. case 2:
  8652. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8653. break;
  8654. }
  8655. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8656. spawn->SetSpawnScript(string(script));
  8657. break;
  8658. }
  8659. }
  8660. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8661. lua_interface->SetSpawnValue(state, spawn);
  8662. group.push_back(spawn);
  8663. }
  8664. else {
  8665. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8666. safe_delete(spawn);
  8667. }
  8668. }
  8669. }
  8670. if (!group.empty()) {
  8671. lua_createtable(state, group.size(), 0);
  8672. int newTable = lua_gettop(state);
  8673. for (int32 i = 0; i < group.size(); i++) {
  8674. lua_interface->SetSpawnValue(state, group[i]);
  8675. lua_rawseti(state, newTable, i + 1);
  8676. }
  8677. }
  8678. else
  8679. lua_pushnil(state);
  8680. return 1;
  8681. }
  8682. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8683. if (!lua_interface)
  8684. return 0;
  8685. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8686. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8687. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8688. if (!spawn) {
  8689. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8690. return 0;
  8691. }
  8692. if (anim_id == 0) {
  8693. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8694. return 0;
  8695. }
  8696. if (leeway == 0)
  8697. leeway = 5000;
  8698. spawn->SetSpawnAnim(anim_id);
  8699. spawn->SetSpawnAnimLeeway(leeway);
  8700. return 0;
  8701. }
  8702. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8703. if (!lua_interface)
  8704. return 0;
  8705. Spawn* player = lua_interface->GetSpawn(state);
  8706. if (!player) {
  8707. return 0;
  8708. }
  8709. Client* client = player->GetZone()->GetClientBySpawn(player);
  8710. if (!client) {
  8711. return 0;
  8712. }
  8713. lua_interface->SetInt32Value(state, client->GetVersion());
  8714. return 1;
  8715. }
  8716. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8717. if (!lua_interface)
  8718. return 0;
  8719. Item* item = lua_interface->GetItem(state);
  8720. if (!item) {
  8721. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8722. return 0;
  8723. }
  8724. lua_interface->SetInt32Value(state, item->details.item_id);
  8725. return 1;
  8726. }
  8727. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8728. if (!lua_interface)
  8729. return 0;
  8730. Spawn* spawn = lua_interface->GetSpawn(state);
  8731. if (!spawn) {
  8732. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8733. return 0;
  8734. }
  8735. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8736. return 1;
  8737. }
  8738. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8739. if (!lua_interface)
  8740. return 0;
  8741. Spawn* spawn = lua_interface->GetSpawn(state);
  8742. if (!spawn) {
  8743. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8744. return 0;
  8745. }
  8746. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8747. return 1;
  8748. }
  8749. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8750. if (!lua_interface)
  8751. return 0;
  8752. Spawn* spawn = lua_interface->GetSpawn(state);
  8753. if (!spawn) {
  8754. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8755. return 0;
  8756. }
  8757. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8758. return 1;
  8759. }
  8760. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8761. if (!lua_interface)
  8762. return 0;
  8763. Spawn* spawn = lua_interface->GetSpawn(state);
  8764. if (!spawn) {
  8765. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8766. return 0;
  8767. }
  8768. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8769. return 1;
  8770. }
  8771. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8772. if (!lua_interface)
  8773. return 0;
  8774. Spawn* spawn = lua_interface->GetSpawn(state);
  8775. float pct = lua_interface->GetFloatValue(state, 2);
  8776. if (!spawn) {
  8777. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8778. return 0;
  8779. }
  8780. if (pct == 0) {
  8781. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8782. return 0;
  8783. }
  8784. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8785. lua_interface->SetInt32Value(state, amount);
  8786. return 1;
  8787. }
  8788. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8789. if (!lua_interface)
  8790. return 0;
  8791. Spawn* spawn = lua_interface->GetSpawn(state);
  8792. float pct = lua_interface->GetFloatValue(state, 2);
  8793. if (!spawn) {
  8794. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8795. return 0;
  8796. }
  8797. if (pct == 0) {
  8798. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8799. return 0;
  8800. }
  8801. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8802. lua_interface->SetInt32Value(state, amount);
  8803. return 1;
  8804. }
  8805. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8806. if (!lua_interface)
  8807. return 0;
  8808. Spawn* spawn = lua_interface->GetSpawn(state);
  8809. if (!spawn) {
  8810. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8811. return 0;
  8812. }
  8813. if (!spawn->IsPlayer()) {
  8814. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8815. return 0;
  8816. }
  8817. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8818. return 1;
  8819. }
  8820. int EQ2Emu_lua_Evac(lua_State* state) {
  8821. if (!lua_interface)
  8822. return 0;
  8823. Spawn* target = lua_interface->GetSpawn(state);
  8824. if (target) {
  8825. float x = target->GetZone()->GetSafeX();
  8826. float y = target->GetZone()->GetSafeY();
  8827. float z = target->GetZone()->GetSafeZ();
  8828. float h = target->GetZone()->GetSafeHeading();
  8829. target->SetX(x);
  8830. target->SetY(y);
  8831. target->SetZ(z);
  8832. target->SetHeading(h);
  8833. target->SetSpawnOrigX(target->GetX());
  8834. target->SetSpawnOrigY(target->GetY());
  8835. target->SetSpawnOrigZ(target->GetZ());
  8836. target->SetSpawnOrigHeading(target->GetHeading());
  8837. if (target->IsPlayer()) {
  8838. Client* client = target->GetZone()->GetClientBySpawn(target);
  8839. if (client) {
  8840. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8841. if (packet)
  8842. {
  8843. packet->setDataByName("x", x);
  8844. packet->setDataByName("y", y);
  8845. packet->setDataByName("z", z);
  8846. client->QueuePacket(packet->serialize());
  8847. safe_delete(packet);
  8848. }
  8849. }
  8850. }
  8851. }
  8852. else {
  8853. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8854. ZoneServer* zone = spell->caster->GetZone();
  8855. float x = spell->caster->GetZone()->GetSafeX();
  8856. float y = spell->caster->GetZone()->GetSafeY();
  8857. float z = spell->caster->GetZone()->GetSafeZ();
  8858. float h = spell->caster->GetZone()->GetSafeHeading();
  8859. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8860. for (int32 i = 0; i < spell->targets.size(); i++) {
  8861. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8862. if (!target2)
  8863. continue;
  8864. target2->SetX(x);
  8865. target2->SetY(y);
  8866. target2->SetZ(z);
  8867. target2->SetHeading(h);
  8868. target2->SetSpawnOrigX(target2->GetX());
  8869. target2->SetSpawnOrigY(target2->GetY());
  8870. target2->SetSpawnOrigZ(target2->GetZ());
  8871. target2->SetSpawnOrigHeading(target2->GetHeading());
  8872. if (target2->IsPlayer()) {
  8873. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8874. if (client) {
  8875. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8876. if (packet)
  8877. {
  8878. client->SetReloadingZone(true);
  8879. packet->setDataByName("x", x);
  8880. packet->setDataByName("y", y);
  8881. packet->setDataByName("z", z);
  8882. client->QueuePacket(packet->serialize());
  8883. safe_delete(packet);
  8884. }
  8885. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8886. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8887. }
  8888. }
  8889. }
  8890. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8891. }
  8892. return 0;
  8893. }
  8894. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8895. if (!lua_interface)
  8896. return 0;
  8897. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8898. if (!luaspell) {
  8899. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8900. return 0;
  8901. }
  8902. int8 tier = luaspell->spell->GetSpellTier();
  8903. lua_interface->SetInt32Value(state, tier);
  8904. return 1;
  8905. }
  8906. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8907. if (!lua_interface)
  8908. return 0;
  8909. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8910. if (!luaspell) {
  8911. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8912. return 0;
  8913. }
  8914. int32 spell_id = luaspell->spell->GetSpellID();
  8915. lua_interface->SetInt32Value(state, spell_id);
  8916. return 1;
  8917. }
  8918. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8919. if (!lua_interface)
  8920. return 0;
  8921. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8922. if (!spawn) {
  8923. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8924. return 0;
  8925. }
  8926. if (!spawn->IsPlayer()) {
  8927. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8928. return 0;
  8929. }
  8930. ZoneServer* zone = spawn->GetZone();
  8931. if (!zone) {
  8932. return 0;
  8933. }
  8934. Client* client = zone->GetClientBySpawn(spawn);
  8935. if (!client) {
  8936. return 0;
  8937. }
  8938. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8939. return 0;
  8940. }
  8941. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8942. if (!lua_interface)
  8943. return 0;
  8944. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8945. if (!spawn) {
  8946. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8947. return 0;
  8948. }
  8949. if (!spawn->IsPlayer()) {
  8950. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8951. return 0;
  8952. }
  8953. ZoneServer* zone = spawn->GetZone();
  8954. if (!zone) {
  8955. return 0;
  8956. }
  8957. Client* client = zone->GetClientBySpawn(spawn);
  8958. if (!client) {
  8959. return 0;
  8960. }
  8961. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8962. return 0;
  8963. }
  8964. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8965. if (!lua_interface)
  8966. return 0;
  8967. Spawn* caster = lua_interface->GetSpawn(state);
  8968. Spawn* target = lua_interface->GetSpawn(state, 2);
  8969. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8970. string spell_name = lua_interface->GetStringValue(state, 4);
  8971. if (!caster) {
  8972. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8973. return 0;
  8974. }
  8975. if (!caster->IsEntity()) {
  8976. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8977. return 0;
  8978. }
  8979. if (!target) {
  8980. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8981. return 0;
  8982. }
  8983. if (!target->IsEntity()) {
  8984. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8985. return 0;
  8986. }
  8987. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8988. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8989. return 0;
  8990. }
  8991. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8992. if (!lua_interface)
  8993. return 0;
  8994. Spawn* player = lua_interface->GetSpawn(state);
  8995. int32 amount = lua_interface->GetInt32Value(state, 2);
  8996. if (player && player->IsPlayer() && amount > 0) {
  8997. ((Player*)player)->AddXP(amount);
  8998. ((Player*)player)->SetCharSheetChanged(true);
  8999. Client* client = player->GetZone()->GetClientBySpawn(player);
  9000. if (client) {
  9001. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9002. }
  9003. }
  9004. return 0;
  9005. }
  9006. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9007. if (!lua_interface)
  9008. return 0;
  9009. Spawn* player = lua_interface->GetSpawn(state);
  9010. int8 type = lua_interface->GetInt8Value(state, 2);
  9011. string text = lua_interface->GetStringValue(state, 3);
  9012. Client* client = 0;
  9013. if (player && player->IsPlayer())
  9014. client = player->GetZone()->GetClientBySpawn(player);
  9015. if (!client || text.length() == 0) {
  9016. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9017. return 0;
  9018. }
  9019. client->SimpleMessage(type, text.c_str());
  9020. return 0;
  9021. }
  9022. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9023. if (!lua_interface)
  9024. return 0;
  9025. Spawn* player = lua_interface->GetSpawn(state);
  9026. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9027. Client* client = 0;
  9028. if (player && player->IsPlayer())
  9029. client = player->GetZone()->GetClientBySpawn(player);
  9030. if (!client || !spawn) {
  9031. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9032. return 0;
  9033. }
  9034. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9035. if (!items) {
  9036. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9037. return 0;
  9038. }
  9039. client->Loot(spawn->GetLootCoins(), items, spawn);
  9040. return 0;
  9041. }
  9042. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9043. if (!lua_interface)
  9044. return 0;
  9045. Spawn* spawnref = lua_interface->GetSpawn(state);
  9046. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9047. if (spawn_id > 0 && spawnref) {
  9048. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9049. if (spawns.size() == 0) {
  9050. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9051. return 0;
  9052. }
  9053. Spawn* spawn = 0;
  9054. int16 index = MakeRandomInt(0, spawns.size());
  9055. if (index >= spawns.size() || index < 0)
  9056. index = 0;
  9057. spawn = spawns[index];
  9058. lua_interface->SetSpawnValue(state, spawn);
  9059. return 1;
  9060. }
  9061. else {
  9062. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9063. }
  9064. return 0;
  9065. }
  9066. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9067. Spawn* player = lua_interface->GetSpawn(state);
  9068. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9069. string name = lua_interface->GetStringValue(state, 3);
  9070. float distance = lua_interface->GetFloatValue(state, 4);
  9071. string command = lua_interface->GetStringValue(state, 5);
  9072. string error_text = lua_interface->GetStringValue(state, 6);
  9073. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9074. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9075. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9076. if (distance == 0)
  9077. distance = 10.0f;
  9078. if (command.length() == 0)
  9079. command = name;
  9080. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9081. if (spawns.size() == 0) {
  9082. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9083. return 0;
  9084. }
  9085. Spawn* spawn = 0;
  9086. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9087. spawn = *itr;
  9088. if (spawn) {
  9089. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9090. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9091. }
  9092. }
  9093. }
  9094. return 0;
  9095. }
  9096. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9097. if (!lua_interface)
  9098. return 0;
  9099. Client* client = 0;
  9100. Spawn* player = lua_interface->GetSpawn(state);
  9101. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9102. if (player && player->IsPlayer() && player->GetZone())
  9103. client = player->GetZone()->GetClientBySpawn(player);
  9104. else{
  9105. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9106. return 0;
  9107. }
  9108. if (client) {
  9109. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9110. if (packet) {
  9111. packet->setDataByName("goal_num", goal_num);
  9112. client->QueuePacket(packet->serialize());
  9113. safe_delete(packet);
  9114. }
  9115. }
  9116. return 0;
  9117. }
  9118. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9119. if (!lua_interface)
  9120. return 0;
  9121. Client* client = 0;
  9122. Spawn* player = lua_interface->GetSpawn(state);
  9123. if (player && player->IsPlayer() && player->GetZone())
  9124. client = player->GetZone()->GetClientBySpawn(player);
  9125. else {
  9126. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9127. return 0;
  9128. }
  9129. if (client) {
  9130. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9131. }
  9132. return 0;
  9133. }
  9134. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9135. if (!lua_interface)
  9136. return 0;
  9137. Client* client = 0;
  9138. Spawn* player = lua_interface->GetSpawn(state);
  9139. float duration = lua_interface->GetFloatValue(state, 2);
  9140. string text = lua_interface->GetStringValue(state, 3);
  9141. string voice = lua_interface->GetStringValue(state, 4);
  9142. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9143. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9144. string signal = lua_interface->GetStringValue(state, 7);
  9145. string goal1 = lua_interface->GetStringValue(state, 8);
  9146. string task1 = lua_interface->GetStringValue(state, 9);
  9147. string goal2 = lua_interface->GetStringValue(state, 10);
  9148. string task2 = lua_interface->GetStringValue(state, 11);
  9149. string goal3 = lua_interface->GetStringValue(state, 12);
  9150. string task3 = lua_interface->GetStringValue(state, 13);
  9151. string goal4 = lua_interface->GetStringValue(state, 14);
  9152. string task4 = lua_interface->GetStringValue(state, 15);
  9153. if (!player) {
  9154. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9155. return 0;
  9156. }
  9157. if (!player->IsPlayer()) {
  9158. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9159. return 0;
  9160. }
  9161. else
  9162. client = ((Player*)player)->GetClient();
  9163. if (!client) {
  9164. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9165. return 0;
  9166. }
  9167. if (text.length() == 0) {
  9168. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9169. return 0;
  9170. }
  9171. if (duration >= 0 && duration < 2)
  9172. duration = 2;
  9173. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9174. if (packet) {
  9175. packet->setDataByName("open_seconds_max", duration);
  9176. packet->setDataByName("text", text.c_str());
  9177. packet->setDataByName("voice", voice.c_str());
  9178. int8 num_goals = 1;
  9179. if (task2.length() > 0)
  9180. num_goals++;
  9181. if (task3.length() > 0)
  9182. num_goals++;
  9183. if (task4.length() > 0)
  9184. num_goals++;
  9185. packet->setArrayLengthByName("num_goals", num_goals);
  9186. for (int8 i = 0; i < num_goals; i++) {
  9187. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9188. }
  9189. if (goal1.length() > 0)
  9190. packet->setArrayDataByName("goal_text", goal1.c_str());
  9191. if (goal2.length() > 0)
  9192. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9193. if (goal3.length() > 0)
  9194. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9195. if (goal4.length() > 0)
  9196. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9197. packet->setSubArrayDataByName("task_text", task1.c_str());
  9198. if (task2.length() > 0)
  9199. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9200. if (task3.length() > 0)
  9201. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9202. if (task4.length() > 0)
  9203. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9204. packet->setDataByName("complete_sound", "click");
  9205. packet->setDataByName("signal", signal.c_str());
  9206. packet->setDataByName("voice_key1", voice_key1);
  9207. packet->setDataByName("voice_key2", voice_key2);
  9208. client->QueuePacket(packet->serialize());
  9209. safe_delete(packet);
  9210. }
  9211. return 0;
  9212. }
  9213. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9214. if (!lua_interface)
  9215. return 0;
  9216. Client* client = 0;
  9217. Spawn* player = lua_interface->GetSpawn(state);
  9218. string window = lua_interface->GetStringValue(state, 2);
  9219. int8 show = lua_interface->GetInt8Value(state, 3);
  9220. if (!player) {
  9221. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9222. return 0;
  9223. }
  9224. if (!player->IsPlayer()) {
  9225. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9226. return 0;
  9227. }
  9228. else
  9229. client = ((Player*)player)->GetClient();
  9230. if (!client) {
  9231. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9232. return 0;
  9233. }
  9234. if (window.length() == 0) {
  9235. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9236. return 0;
  9237. }
  9238. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9239. if (packet) {
  9240. packet->setDataByName("window", window.c_str());
  9241. packet->setDataByName("show", show);
  9242. client->QueuePacket(packet->serialize());
  9243. safe_delete(packet);
  9244. }
  9245. return 0;
  9246. }
  9247. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9248. //See GameEvents.txt for options that can be used for this function
  9249. if (!lua_interface)
  9250. return 0;
  9251. Client* client = 0;
  9252. Spawn* player = lua_interface->GetSpawn(state);
  9253. string event_name = lua_interface->GetStringValue(state, 2);
  9254. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9255. if (!player || !player->IsPlayer()) {
  9256. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9257. return 0;
  9258. }
  9259. if (player->GetZone())
  9260. client = player->GetZone()->GetClientBySpawn(player);
  9261. if (!client) {
  9262. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9263. return 0;
  9264. }
  9265. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9266. if (packet) {
  9267. packet->setDataByName("event_name", event_name.c_str());
  9268. packet->setDataByName("enabled", enabled);
  9269. client->QueuePacket(packet->serialize());
  9270. safe_delete(packet);
  9271. }
  9272. return 0;
  9273. }
  9274. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9275. if (!lua_interface)
  9276. return 0;
  9277. Spawn* player = lua_interface->GetSpawn(state);
  9278. if (player && player->IsPlayer()) {
  9279. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9280. return 1;
  9281. }
  9282. return 0;
  9283. }
  9284. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9285. if (!lua_interface)
  9286. return 0;
  9287. Spawn* player = lua_interface->GetSpawn(state);
  9288. int8 step = lua_interface->GetInt8Value(state, 2);
  9289. if (player && player->IsPlayer() && step > 0) {
  9290. ((Player*)player)->SetTutorialStep(step);
  9291. }
  9292. return 0;
  9293. }
  9294. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9295. if (!lua_interface)
  9296. return 0;
  9297. Client* client = 0;
  9298. Spawn* player = lua_interface->GetSpawn(state);
  9299. string window = lua_interface->GetStringValue(state, 2);
  9300. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9301. if (!player) {
  9302. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9303. return 0;
  9304. }
  9305. if (!player->IsPlayer()) {
  9306. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9307. return 0;
  9308. }
  9309. else
  9310. client = ((Player*)player)->GetClient();
  9311. if (!client) {
  9312. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9313. return 0;
  9314. }
  9315. if (window.length() == 0) {
  9316. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9317. return 0;
  9318. }
  9319. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9320. if (packet) {
  9321. packet->setDataByName("window", window.c_str());
  9322. packet->setDataByName("flash_seconds", flash_seconds);
  9323. client->QueuePacket(packet->serialize());
  9324. safe_delete(packet);
  9325. }
  9326. return 0;
  9327. }
  9328. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9329. if (!lua_interface)
  9330. return 0;
  9331. Spawn* spawn = lua_interface->GetSpawn(state);
  9332. Spawn* target = lua_interface->GetSpawn(state, 2);
  9333. if (spawn && target)
  9334. return spawn->CheckLoS(target);
  9335. return 0;
  9336. }
  9337. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9338. if (!lua_interface)
  9339. return 0;
  9340. Spawn* spawn = lua_interface->GetSpawn(state);
  9341. float x = lua_interface->GetFloatValue(state, 2);
  9342. float y = lua_interface->GetFloatValue(state, 3);
  9343. float z = lua_interface->GetFloatValue(state, 4);
  9344. if (spawn)
  9345. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9346. return 0;
  9347. }
  9348. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9349. if (!lua_interface)
  9350. return 0;
  9351. ZoneServer* zone = lua_interface->GetZone(state);
  9352. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9353. if (zone)
  9354. zone->SetExpansionFlag(xpackFlag);
  9355. return 0;
  9356. }
  9357. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9358. if (!lua_interface)
  9359. return 0;
  9360. ZoneServer* zone = lua_interface->GetZone(state);
  9361. if (zone) {
  9362. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9363. return 1;
  9364. }
  9365. return 0;
  9366. }
  9367. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9368. if (!lua_interface)
  9369. return 0;
  9370. ZoneServer* zone = lua_interface->GetZone(state);
  9371. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9372. if (zone)
  9373. zone->SetHolidayFlag(holidayFlag);
  9374. return 0;
  9375. }
  9376. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9377. if (!lua_interface)
  9378. return 0;
  9379. ZoneServer* zone = lua_interface->GetZone(state);
  9380. if (zone) {
  9381. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9382. return 1;
  9383. }
  9384. return 0;
  9385. }
  9386. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9387. if (!lua_interface)
  9388. return 0;
  9389. Spawn* spawn = lua_interface->GetSpawn(state);
  9390. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9391. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9392. float distance = lua_interface->GetFloatValue(state, 4);
  9393. string in_range_function = lua_interface->GetStringValue(state, 5);
  9394. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9395. if (spawn && distance > 0 && in_range_function.length() > 0)
  9396. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9397. return 0;
  9398. }
  9399. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9400. if (!lua_interface)
  9401. return 0;
  9402. Spawn* spawn = lua_interface->GetSpawn(state);
  9403. Spawn* target = lua_interface->GetSpawn(state, 2);
  9404. if (spawn && target)
  9405. {
  9406. if (spawn->IsPlayer() && target->IsEntity())
  9407. {
  9408. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9409. return 1;
  9410. }
  9411. else if (spawn->IsEntity() && target->IsEntity())
  9412. {
  9413. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9414. return 1;
  9415. }
  9416. }
  9417. return 0;
  9418. }
  9419. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9420. if (!lua_interface)
  9421. return 0;
  9422. Spawn* spawn = lua_interface->GetSpawn(state);
  9423. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9424. if (spawn && spawn->IsEntity())
  9425. {
  9426. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9427. if (spawn->IsPlayer())
  9428. {
  9429. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9430. if (client)
  9431. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9432. }
  9433. }
  9434. return 0;
  9435. }
  9436. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9437. if (!lua_interface)
  9438. return 0;
  9439. Spawn* spawn = lua_interface->GetSpawn(state);
  9440. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9441. if (spawn && spawn->IsEntity())
  9442. {
  9443. ((Entity*)spawn)->SetSeeHideSpell(val);
  9444. if (spawn->IsPlayer())
  9445. {
  9446. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9447. if (client)
  9448. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9449. }
  9450. }
  9451. return 0;
  9452. }
  9453. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9454. {
  9455. if (!lua_interface)
  9456. return 0;
  9457. Spawn* player = lua_interface->GetSpawn(state);
  9458. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9459. string command = lua_interface->GetStringValue(state, 3);
  9460. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9461. lua_interface->ResetFunctionStack(state);
  9462. if (spawn && player && player->IsPlayer())
  9463. {
  9464. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9465. bool res = false;
  9466. if (cmd)
  9467. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9468. lua_interface->SetBooleanValue(state, res);
  9469. return 1;
  9470. }
  9471. return 0;
  9472. }
  9473. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9474. {
  9475. if (!lua_interface)
  9476. return 0;
  9477. Spawn* spawn = lua_interface->GetSpawn(state);
  9478. int32 charID = lua_interface->GetInt32Value(state, 2);
  9479. string command = lua_interface->GetStringValue(state, 3);
  9480. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9481. lua_interface->ResetFunctionStack(state);
  9482. if (spawn && charID)
  9483. {
  9484. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9485. bool res = false;
  9486. if (cmd)
  9487. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9488. lua_interface->SetBooleanValue(state, res);
  9489. return 1;
  9490. }
  9491. return 0;
  9492. }
  9493. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9494. {
  9495. if (!lua_interface)
  9496. return 0;
  9497. Spawn* spawn = lua_interface->GetSpawn(state);
  9498. string command = lua_interface->GetStringValue(state, 2);
  9499. lua_interface->ResetFunctionStack(state);
  9500. if (spawn && command.length() > 0)
  9501. spawn->RemovePrimaryEntityCommand(command.c_str());
  9502. return 0;
  9503. }
  9504. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9505. if (!lua_interface)
  9506. return 0;
  9507. Spawn* spawn = lua_interface->GetSpawn(state);
  9508. float distance = lua_interface->GetFloatValue(state, 2);
  9509. string command = lua_interface->GetStringValue(state, 3);
  9510. Spawn* player = lua_interface->GetSpawn(state, 4);
  9511. lua_interface->ResetFunctionStack(state);
  9512. if (spawn) {
  9513. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9514. }
  9515. return 0;
  9516. }
  9517. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9518. if (!lua_interface)
  9519. return 0;
  9520. Spawn* spawn = lua_interface->GetSpawn(state);
  9521. Spawn* player = lua_interface->GetSpawn(state, 2);
  9522. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9523. lua_interface->ResetFunctionStack(state);
  9524. if (spawn && player && transport_id && player->IsPlayer()) {
  9525. Client* client = 0;
  9526. if (player && player->IsPlayer())
  9527. client = player->GetZone()->GetClientBySpawn(player);
  9528. if (!client)
  9529. return 0;
  9530. vector<TransportDestination*> destinations;
  9531. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9532. if (destinations.size())
  9533. {
  9534. client->SetTemporaryTransportID(transport_id);
  9535. client->ProcessTeleport(spawn, &destinations, transport_id);
  9536. }
  9537. else
  9538. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9539. }
  9540. return 0;
  9541. }
  9542. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9543. if (!lua_interface)
  9544. return 0;
  9545. Spawn* player = lua_interface->GetSpawn(state);
  9546. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9547. lua_interface->ResetFunctionStack(state);
  9548. if (player && player->IsPlayer()) {
  9549. Client* client = 0;
  9550. if (player && player->IsPlayer())
  9551. client = player->GetZone()->GetClientBySpawn(player);
  9552. if (!client)
  9553. return 0;
  9554. client->SetTemporaryTransportID(transport_id);
  9555. }
  9556. return 0;
  9557. }
  9558. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9559. if (!lua_interface)
  9560. return 0;
  9561. Spawn* player = lua_interface->GetSpawn(state);
  9562. lua_interface->ResetFunctionStack(state);
  9563. if (player && player->IsPlayer()) {
  9564. Client* client = 0;
  9565. if (player && player->IsPlayer())
  9566. client = player->GetZone()->GetClientBySpawn(player);
  9567. if (!client)
  9568. return 0;
  9569. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9570. return 1;
  9571. }
  9572. return 0;
  9573. }
  9574. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9575. if (!lua_interface)
  9576. return 0;
  9577. Spawn* spawn = lua_interface->GetSpawn(state);
  9578. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9579. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9580. if (!spawn) {
  9581. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9582. return 0;
  9583. }
  9584. if (!spawn->IsEntity()) {
  9585. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9586. return 0;
  9587. }
  9588. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9589. {
  9590. 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);
  9591. return 0;
  9592. }
  9593. lua_interface->ResetFunctionStack(state);
  9594. if (spell && spell->targets.size() > 0) {
  9595. ZoneServer* zone = spell->caster->GetZone();
  9596. for (int8 i = 0; i < spell->targets.size(); i++) {
  9597. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9598. if (target && target->IsEntity()) {
  9599. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9600. if (target->IsPlayer())
  9601. ((Player*)target)->SetCharSheetChanged(true);
  9602. }
  9603. }
  9604. }
  9605. else {
  9606. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9607. if (spawn->IsPlayer())
  9608. ((Player*)spawn)->SetCharSheetChanged(true);
  9609. }
  9610. return 0;
  9611. }
  9612. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9613. if (!lua_interface)
  9614. return 0;
  9615. Spawn* spawn = lua_interface->GetSpawn(state);
  9616. lua_interface->ResetFunctionStack(state);
  9617. if (!spawn) {
  9618. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9619. return 0;
  9620. }
  9621. if (!spawn->IsEntity()) {
  9622. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9623. return 0;
  9624. }
  9625. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9626. return 1;
  9627. }
  9628. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9629. if (!lua_interface)
  9630. return 0;
  9631. int32 spell_id = lua_interface->GetInt32Value(state);
  9632. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9633. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9634. if (spell_id > 0) {
  9635. if (spell_tier == 0)
  9636. spell_tier = 1;
  9637. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9638. LuaSpell* lua_spell = 0;
  9639. if(custom_lua_script.size() > 0)
  9640. {
  9641. // attempt to load the custom script since it isn't already loaded
  9642. // we will re-obtain the lua_spell further below
  9643. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9644. {
  9645. 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());
  9646. lua_interface->LoadLuaSpell(custom_lua_script);
  9647. }
  9648. }
  9649. else
  9650. custom_lua_script = spell->GetSpellData()->lua_script;
  9651. if (!lua_spell && lua_interface)
  9652. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9653. if (!lua_spell)
  9654. {
  9655. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9656. return 0;
  9657. }
  9658. lua_spell->spell = new Spell(spell);
  9659. lua_interface->AddCustomSpell(lua_spell);
  9660. lua_interface->SetSpellValue(state, lua_spell);
  9661. return 1;
  9662. }
  9663. return 0;
  9664. }
  9665. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9666. if (!lua_interface)
  9667. return 0;
  9668. LuaSpell* spell = lua_interface->GetSpell(state);
  9669. string field = lua_interface->GetStringValue(state, 2);
  9670. if (!spell) {
  9671. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9672. return 0;
  9673. }
  9674. if (!spell->spell || !spell->spell->GetSpellData()) {
  9675. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9676. return 0;
  9677. }
  9678. boost::to_lower(field);
  9679. return spell->spell->GetSpellData(state, field);
  9680. }
  9681. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9682. if (!lua_interface)
  9683. return 0;
  9684. LuaSpell* spell = lua_interface->GetSpell(state);
  9685. string field = lua_interface->GetStringValue(state, 2);
  9686. int8 fieldArg = 3; // field value after the initial set
  9687. if (!spell) {
  9688. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9689. return 0;
  9690. }
  9691. if (!spell->spell || !spell->spell->GetSpellData()) {
  9692. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9693. return 0;
  9694. }
  9695. boost::to_lower(field);
  9696. bool valSet = false;
  9697. spell->spell->SetSpellData(state, field, fieldArg);
  9698. return valSet;
  9699. }
  9700. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9701. if (!lua_interface)
  9702. return 0;
  9703. LuaSpell* spell = lua_interface->GetSpell(state);
  9704. int8 idx = lua_interface->GetInt32Value(state, 2);
  9705. if (!spell) {
  9706. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9707. return 0;
  9708. }
  9709. if (!spell->spell || !spell->spell->GetSpellData()) {
  9710. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9711. return 0;
  9712. }
  9713. if (spell->spell->lua_data.size() <= idx)
  9714. {
  9715. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9716. return 0;
  9717. }
  9718. bool setVal = true;
  9719. LUAData* data = spell->spell->lua_data[idx];
  9720. switch (data->type)
  9721. {
  9722. case 0:
  9723. {
  9724. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9725. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9726. data->int_value = value;
  9727. data->int_value2 = value2;
  9728. break;
  9729. }
  9730. case 1:
  9731. {
  9732. float value = lua_interface->GetFloatValue(state, 3);
  9733. float value2 = lua_interface->GetFloatValue(state, 4);
  9734. data->float_value = value;
  9735. data->float_value2 = value2;
  9736. break;
  9737. }
  9738. case 2:
  9739. {
  9740. bool value = lua_interface->GetBooleanValue(state, 3);
  9741. data->bool_value = value;
  9742. break;
  9743. }
  9744. case 3:
  9745. {
  9746. string value = lua_interface->GetStringValue(state, 3);
  9747. string value2 = lua_interface->GetStringValue(state, 4);
  9748. data->string_value = value;
  9749. data->string_value2 = value2;
  9750. break;
  9751. }
  9752. default:
  9753. setVal = false;
  9754. }
  9755. return setVal;
  9756. }
  9757. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9758. if (!lua_interface)
  9759. return 0;
  9760. LuaSpell* spell = lua_interface->GetSpell(state);
  9761. int8 idx = lua_interface->GetInt32Value(state, 2);
  9762. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9763. if (!spell) {
  9764. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9765. return 0;
  9766. }
  9767. if (!spell->spell || !spell->spell->GetSpellData()) {
  9768. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9769. return 0;
  9770. }
  9771. if (spell->spell->lua_data.size() <= idx)
  9772. {
  9773. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9774. return 0;
  9775. }
  9776. bool setVal = true;
  9777. LUAData* data = spell->spell->lua_data[idx];
  9778. switch (data->type)
  9779. {
  9780. case 0:
  9781. {
  9782. if(!secondfield)
  9783. lua_interface->SetSInt32Value(state, data->int_value);
  9784. else
  9785. lua_interface->SetSInt32Value(state, data->int_value2);
  9786. break;
  9787. }
  9788. case 1:
  9789. {
  9790. if (!secondfield)
  9791. lua_interface->SetFloatValue(state, data->float_value);
  9792. else
  9793. lua_interface->SetFloatValue(state, data->float_value2);
  9794. break;
  9795. }
  9796. case 2:
  9797. {
  9798. lua_interface->SetBooleanValue(state, data->bool_value);
  9799. break;
  9800. }
  9801. case 3:
  9802. {
  9803. if (!secondfield)
  9804. lua_interface->SetStringValue(state, data->string_value.c_str());
  9805. else
  9806. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9807. break;
  9808. }
  9809. default:
  9810. setVal = false;
  9811. }
  9812. return setVal;
  9813. }
  9814. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9815. if (!lua_interface)
  9816. return 0;
  9817. LuaSpell* spell = lua_interface->GetSpell(state);
  9818. int8 idx = lua_interface->GetInt32Value(state, 2);
  9819. string field = lua_interface->GetStringValue(state, 3);
  9820. boost::to_lower(field);
  9821. if (!spell) {
  9822. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9823. return 0;
  9824. }
  9825. if (!spell->spell || !spell->spell->GetSpellData()) {
  9826. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9827. return 0;
  9828. }
  9829. if (spell->spell->effects.size() <= idx)
  9830. {
  9831. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9832. return 0;
  9833. }
  9834. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9835. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9836. if (field == "description")
  9837. effect->description = string(lua_interface->GetStringValue(state, 4));
  9838. else if (field == "bullet")
  9839. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9840. else if (field == "percentage")
  9841. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9842. else // no match
  9843. return 0;
  9844. return 1;
  9845. }
  9846. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9847. if (!lua_interface)
  9848. return 0;
  9849. LuaSpell* spell = lua_interface->GetSpell(state);
  9850. int8 idx = lua_interface->GetInt32Value(state, 2);
  9851. string field = lua_interface->GetStringValue(state, 3);
  9852. boost::to_lower(field);
  9853. if (!spell) {
  9854. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9855. return 0;
  9856. }
  9857. if (!spell->spell || !spell->spell->GetSpellData()) {
  9858. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9859. return 0;
  9860. }
  9861. if (spell->spell->effects.size() <= idx)
  9862. {
  9863. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9864. return 0;
  9865. }
  9866. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9867. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9868. if (field == "description")
  9869. lua_interface->SetStringValue(state, effect->description.c_str());
  9870. else if (field == "bullet")
  9871. lua_interface->SetInt32Value(state, effect->subbullet);
  9872. else if (field == "percentage")
  9873. lua_interface->SetInt32Value(state, effect->percentage);
  9874. else // no match
  9875. return 0;
  9876. return 1;
  9877. }
  9878. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9879. if (!lua_interface)
  9880. return 0;
  9881. LuaSpell* spell = lua_interface->GetSpell(state);
  9882. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9883. Spawn* target = lua_interface->GetSpawn(state, 3);
  9884. if (!target) {
  9885. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9886. return 0;
  9887. }
  9888. if (!target->IsEntity()) {
  9889. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9890. return 0;
  9891. }
  9892. if (!spell) {
  9893. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9894. return 0;
  9895. }
  9896. if (caster && !caster->IsEntity()) {
  9897. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9898. return 0;
  9899. }
  9900. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9901. return 0;
  9902. }
  9903. int EQ2Emu_lua_InWater(lua_State* state) {
  9904. if (!lua_interface)
  9905. return 0;
  9906. Spawn* spawn = lua_interface->GetSpawn(state);
  9907. lua_interface->ResetFunctionStack(state);
  9908. if (spawn) {
  9909. lua_interface->SetBooleanValue(state, spawn->InWater());
  9910. return 1;
  9911. }
  9912. return 0;
  9913. }
  9914. int EQ2Emu_lua_InLava(lua_State* state) {
  9915. if (!lua_interface)
  9916. return 0;
  9917. Spawn* spawn = lua_interface->GetSpawn(state);
  9918. lua_interface->ResetFunctionStack(state);
  9919. if (spawn) {
  9920. lua_interface->SetBooleanValue(state, spawn->InLava());
  9921. return 1;
  9922. }
  9923. return 0;
  9924. }
  9925. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9926. if (!lua_interface)
  9927. return 0;
  9928. Spawn* attacker = lua_interface->GetSpawn(state);
  9929. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9930. int8 type = lua_interface->GetInt8Value(state, 3);
  9931. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9932. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9933. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9934. string spell_name = lua_interface->GetStringValue(state, 7);
  9935. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9936. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9937. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9938. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9939. lua_interface->ResetFunctionStack(state);
  9940. if (!attacker) {
  9941. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9942. return 0;
  9943. }
  9944. if (!attacker->IsEntity()) {
  9945. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9946. return 0;
  9947. }
  9948. if (!victim) {
  9949. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9950. return 0;
  9951. }
  9952. if (!victim->IsEntity()) {
  9953. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9954. return 0;
  9955. }
  9956. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9957. return 0;
  9958. }
  9959. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9960. if (!lua_interface)
  9961. return 0;
  9962. Spawn* spawn = lua_interface->GetSpawn(state);
  9963. lua_interface->ResetFunctionStack(state);
  9964. if (spawn) {
  9965. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9966. return 1;
  9967. }
  9968. return 0;
  9969. }
  9970. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9971. if (!lua_interface)
  9972. return 0;
  9973. Spawn* spawn = lua_interface->GetSpawn(state);
  9974. bool invul = lua_interface->GetBooleanValue(state, 2);
  9975. lua_interface->ResetFunctionStack(state);
  9976. if (spawn) {
  9977. spawn->SetInvulnerable(invul);
  9978. }
  9979. return 0;
  9980. }
  9981. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  9982. if (!lua_interface)
  9983. return 0;
  9984. string category = lua_interface->GetStringValue(state);
  9985. string name = lua_interface->GetStringValue(state, 2);
  9986. lua_interface->ResetFunctionStack(state);
  9987. Rule *ret = 0;
  9988. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9989. lua_interface->SetBooleanValue(state, ret->GetBool());
  9990. return 1;
  9991. }
  9992. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9993. return 0;
  9994. }
  9995. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9996. if (!lua_interface)
  9997. return 0;
  9998. string category = lua_interface->GetStringValue(state);
  9999. string name = lua_interface->GetStringValue(state, 2);
  10000. lua_interface->ResetFunctionStack(state);
  10001. Rule *ret = 0;
  10002. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10003. lua_interface->SetInt32Value(state, ret->GetInt32());
  10004. return 1;
  10005. }
  10006. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10007. return 0;
  10008. }
  10009. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10010. if (!lua_interface)
  10011. return 0;
  10012. string category = lua_interface->GetStringValue(state);
  10013. string name = lua_interface->GetStringValue(state, 2);
  10014. lua_interface->ResetFunctionStack(state);
  10015. Rule *ret = 0;
  10016. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10017. lua_interface->SetFloatValue(state, ret->GetFloat());
  10018. return 1;
  10019. }
  10020. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10021. return 0;
  10022. }
  10023. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10024. if (!lua_interface)
  10025. return 0;
  10026. Spawn* spawn = lua_interface->GetSpawn(state);
  10027. string type = lua_interface->GetStringValue(state, 2);
  10028. lua_interface->ResetFunctionStack(state);
  10029. if (spawn) {
  10030. int res = 1;
  10031. boost::to_lower(type);
  10032. if(type == "assigned_aa")
  10033. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10034. else if ( type == "unassigned_aa")
  10035. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10036. else if ( type == "assigned_tradeskill_aa")
  10037. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10038. else if ( type == "unassigned_tradeskill_aa")
  10039. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10040. else if ( type == "assigned_prestige_aa")
  10041. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10042. else if ( type == "unassigned_prestige_aa")
  10043. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10044. else if ( type == "assigned_tradeskill_prestige_aa")
  10045. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10046. else if ( type == "unassigned_tradeskill_prestige_aa")
  10047. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10048. else
  10049. res = 0;
  10050. return res;
  10051. }
  10052. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10053. return 0;
  10054. }
  10055. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10056. if (!lua_interface)
  10057. return 0;
  10058. Spawn* spawn = lua_interface->GetSpawn(state);
  10059. string type = lua_interface->GetStringValue(state, 2);
  10060. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10061. lua_interface->ResetFunctionStack(state);
  10062. if (spawn) {
  10063. boost::to_lower(type);
  10064. if(type == "assigned_aa")
  10065. spawn->SetAssignedAA((sint16)value);
  10066. else if ( type == "unassigned_aa")
  10067. spawn->SetUnassignedAA((sint16)value);
  10068. else if ( type == "assigned_tradeskill_aa")
  10069. spawn->SetTradeskillAA((sint16)value);
  10070. else if ( type == "unassigned_tradeskill_aa")
  10071. spawn->SetUnassignedTradeskillAA((sint16)value);
  10072. else if ( type == "assigned_prestige_aa")
  10073. spawn->SetPrestigeAA((sint16)value);
  10074. else if ( type == "unassigned_prestige_aa")
  10075. spawn->SetUnassignedPrestigeAA((sint16)value);
  10076. else if ( type == "assigned_tradeskill_prestige_aa")
  10077. spawn->SetTradeskillPrestigeAA((sint16)value);
  10078. else if ( type == "unassigned_tradeskill_prestige_aa")
  10079. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10080. if(spawn->IsPlayer())
  10081. ((Player*)spawn)->SetCharSheetChanged(true);
  10082. }
  10083. return 0;
  10084. }
  10085. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10086. if (!lua_interface)
  10087. return 0;
  10088. string titleName = lua_interface->GetStringValue(state);
  10089. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10090. lua_interface->ResetFunctionStack(state);
  10091. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10092. lua_interface->SetSInt32Value(state, index);
  10093. return 1;
  10094. }
  10095. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10096. if (!lua_interface)
  10097. return 0;
  10098. Spawn* spawn = lua_interface->GetSpawn(state);
  10099. string titleName = lua_interface->GetStringValue(state, 2);
  10100. lua_interface->ResetFunctionStack(state);
  10101. if(!spawn->IsPlayer())
  10102. {
  10103. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10104. lua_interface->SetSInt32Value(state, -1);
  10105. return 1;
  10106. }
  10107. Player* player = (Player*)spawn;
  10108. // check if player already has the title, don't need to add twice
  10109. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10110. if ( playerHasTitle)
  10111. {
  10112. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10113. return 1;
  10114. }
  10115. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10116. if(!title)
  10117. {
  10118. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10119. lua_interface->SetSInt32Value(state, -1);
  10120. return 1;
  10121. }
  10122. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10123. if(returnIdx < 0)
  10124. {
  10125. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10126. }
  10127. lua_interface->SetSInt32Value(state, returnIdx);
  10128. player->GetClient()->SendTitleUpdate();
  10129. return 1;
  10130. }
  10131. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10132. if (!lua_interface)
  10133. return 0;
  10134. Spawn* spawn = lua_interface->GetSpawn(state);
  10135. string titleName = lua_interface->GetStringValue(state, 2);
  10136. lua_interface->ResetFunctionStack(state);
  10137. if(!spawn->IsPlayer())
  10138. {
  10139. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10140. return 0;
  10141. }
  10142. Player* player = (Player*)spawn;
  10143. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10144. if(!title)
  10145. {
  10146. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10147. return 0;
  10148. }
  10149. if(title->GetPrefix())
  10150. {
  10151. 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());
  10152. return 0;
  10153. }
  10154. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10155. player->GetClient()->SendTitleUpdate();
  10156. return 1;
  10157. }
  10158. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10159. if (!lua_interface)
  10160. return 0;
  10161. Spawn* spawn = lua_interface->GetSpawn(state);
  10162. string titleName = lua_interface->GetStringValue(state, 2);
  10163. lua_interface->ResetFunctionStack(state);
  10164. if(!spawn->IsPlayer())
  10165. {
  10166. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10167. return 0;
  10168. }
  10169. Player* player = (Player*)spawn;
  10170. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10171. if(!title)
  10172. {
  10173. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10174. return 0;
  10175. }
  10176. if(!title->GetPrefix())
  10177. {
  10178. 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());
  10179. return 0;
  10180. }
  10181. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10182. player->GetClient()->SendTitleUpdate();
  10183. return 1;
  10184. }
  10185. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10186. if (!lua_interface)
  10187. return 0;
  10188. Spawn* spawn = lua_interface->GetSpawn(state);
  10189. lua_interface->ResetFunctionStack(state);
  10190. if(!spawn->IsPlayer())
  10191. {
  10192. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10193. return 0;
  10194. }
  10195. Player* player = (Player*)spawn;
  10196. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10197. player->GetClient()->SendTitleUpdate();
  10198. return 1;
  10199. }
  10200. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10201. if (!lua_interface)
  10202. return 0;
  10203. Spawn* spawn = lua_interface->GetSpawn(state);
  10204. lua_interface->ResetFunctionStack(state);
  10205. if(!spawn->IsPlayer())
  10206. {
  10207. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10208. return 0;
  10209. }
  10210. Player* player = (Player*)spawn;
  10211. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10212. player->GetClient()->SendTitleUpdate();
  10213. return 1;
  10214. }
  10215. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10216. if (!lua_interface)
  10217. return 0;
  10218. Spawn* spawn = lua_interface->GetSpawn(state);
  10219. string field = lua_interface->GetStringValue(state, 2);
  10220. lua_interface->ResetFunctionStack(state);
  10221. if(!spawn || !spawn->IsEntity())
  10222. {
  10223. 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));
  10224. return 0;
  10225. }
  10226. Entity* ent = (Entity*)spawn;
  10227. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10228. return 1;
  10229. }
  10230. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10231. if (!lua_interface)
  10232. return 0;
  10233. Spawn* spawn = lua_interface->GetSpawn(state);
  10234. string field = lua_interface->GetStringValue(state, 2);
  10235. lua_interface->ResetFunctionStack(state);
  10236. if(!spawn || !spawn->IsEntity())
  10237. {
  10238. 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));
  10239. return 0;
  10240. }
  10241. Entity* ent = (Entity*)spawn;
  10242. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10243. return 1;
  10244. }
  10245. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10246. if (!lua_interface)
  10247. return 0;
  10248. Spawn* spawn = lua_interface->GetSpawn(state);
  10249. string field = lua_interface->GetStringValue(state, 2);
  10250. lua_interface->ResetFunctionStack(state);
  10251. if(!spawn || !spawn->IsEntity())
  10252. {
  10253. 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));
  10254. return 0;
  10255. }
  10256. Entity* ent = (Entity*)spawn;
  10257. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10258. return 1;
  10259. }
  10260. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10261. if (!lua_interface)
  10262. return 0;
  10263. Spawn* spawn = lua_interface->GetSpawn(state);
  10264. string field = lua_interface->GetStringValue(state, 2);
  10265. lua_interface->ResetFunctionStack(state);
  10266. if(!spawn || !spawn->IsEntity())
  10267. {
  10268. 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));
  10269. return 0;
  10270. }
  10271. Entity* ent = (Entity*)spawn;
  10272. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10273. return 1;
  10274. }
  10275. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10276. if (!lua_interface)
  10277. return 0;
  10278. Spawn* spawn = lua_interface->GetSpawn(state);
  10279. string field = lua_interface->GetStringValue(state, 2);
  10280. string value = lua_interface->GetStringValue(state, 3);
  10281. lua_interface->ResetFunctionStack(state);
  10282. if(!spawn || !spawn->IsEntity())
  10283. {
  10284. 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));
  10285. return 0;
  10286. }
  10287. Entity* ent = (Entity*)spawn;
  10288. bool set_ = ent->SetInfoStructString(field, value);
  10289. lua_interface->SetBooleanValue(state, set_);
  10290. return 1;
  10291. }
  10292. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10293. if (!lua_interface)
  10294. return 0;
  10295. Spawn* spawn = lua_interface->GetSpawn(state);
  10296. string field = lua_interface->GetStringValue(state, 2);
  10297. int64 value = lua_interface->GetInt64Value(state, 3);
  10298. lua_interface->ResetFunctionStack(state);
  10299. if(!spawn || !spawn->IsEntity())
  10300. {
  10301. 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));
  10302. return 0;
  10303. }
  10304. Entity* ent = (Entity*)spawn;
  10305. bool set_ = ent->SetInfoStructUInt(field, value);
  10306. lua_interface->SetBooleanValue(state, set_);
  10307. return 1;
  10308. }
  10309. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10310. if (!lua_interface)
  10311. return 0;
  10312. Spawn* spawn = lua_interface->GetSpawn(state);
  10313. string field = lua_interface->GetStringValue(state, 2);
  10314. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10315. lua_interface->ResetFunctionStack(state);
  10316. if(!spawn || !spawn->IsEntity())
  10317. {
  10318. 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));
  10319. return 0;
  10320. }
  10321. Entity* ent = (Entity*)spawn;
  10322. bool set_ = ent->SetInfoStructSInt(field, value);
  10323. lua_interface->SetBooleanValue(state, set_);
  10324. return 1;
  10325. }
  10326. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10327. if (!lua_interface)
  10328. return 0;
  10329. Spawn* spawn = lua_interface->GetSpawn(state);
  10330. string field = lua_interface->GetStringValue(state, 2);
  10331. float value = lua_interface->GetFloatValue(state, 3);
  10332. lua_interface->ResetFunctionStack(state);
  10333. if(!spawn || !spawn->IsEntity())
  10334. {
  10335. 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));
  10336. return 0;
  10337. }
  10338. Entity* ent = (Entity*)spawn;
  10339. bool set_ = ent->SetInfoStructFloat(field, value);
  10340. lua_interface->SetBooleanValue(state, set_);
  10341. return 1;
  10342. }
  10343. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10344. if (!lua_interface)
  10345. return 0;
  10346. Spawn* spawn = lua_interface->GetSpawn(state);
  10347. bool value = lua_interface->GetBooleanValue(state, 2);
  10348. lua_interface->ResetFunctionStack(state);
  10349. if(!spawn || !spawn->IsPlayer())
  10350. {
  10351. 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));
  10352. return 0;
  10353. }
  10354. ((Player*)spawn)->SetCharSheetChanged(value);
  10355. return 0;
  10356. }
  10357. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10358. if (!lua_interface)
  10359. return 0;
  10360. Spawn* spawn = lua_interface->GetSpawn(state);
  10361. std::string fromName = lua_interface->GetStringValue(state, 2);
  10362. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10363. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10364. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10365. int32 copper = lua_interface->GetInt32Value(state, 6);
  10366. int32 silver = lua_interface->GetInt32Value(state, 7);
  10367. int32 gold = lua_interface->GetInt32Value(state, 8);
  10368. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10369. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10370. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10371. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10372. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10373. lua_interface->ResetFunctionStack(state);
  10374. if(!spawn || !spawn->IsPlayer())
  10375. {
  10376. 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));
  10377. lua_interface->SetBooleanValue(state, false);
  10378. return 1;
  10379. }
  10380. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10381. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10382. lua_interface->SetBooleanValue(state, true);
  10383. return 1;
  10384. }
  10385. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10386. if (!lua_interface)
  10387. return 0;
  10388. int32 char_id = lua_interface->GetInt32Value(state);
  10389. std::string fromName = lua_interface->GetStringValue(state, 2);
  10390. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10391. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10392. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10393. int32 copper = lua_interface->GetInt32Value(state, 6);
  10394. int32 silver = lua_interface->GetInt32Value(state, 7);
  10395. int32 gold = lua_interface->GetInt32Value(state, 8);
  10396. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10397. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10398. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10399. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10400. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10401. lua_interface->ResetFunctionStack(state);
  10402. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10403. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10404. lua_interface->SetBooleanValue(state, true);
  10405. return 1;
  10406. }
  10407. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10408. Spawn* widget;
  10409. if (lua_interface) {
  10410. widget = lua_interface->GetSpawn(state);
  10411. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10412. lua_interface->ResetFunctionStack(state);
  10413. if (widget && widget->IsWidget())
  10414. {
  10415. ((Widget*)widget)->OpenDoor();
  10416. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10417. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10418. }
  10419. else
  10420. 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));
  10421. }
  10422. return 0;
  10423. }
  10424. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10425. Spawn* widget;
  10426. if (lua_interface) {
  10427. widget = lua_interface->GetSpawn(state);
  10428. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10429. lua_interface->ResetFunctionStack(state);
  10430. if (widget && widget->IsWidget())
  10431. {
  10432. ((Widget*)widget)->CloseDoor();
  10433. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10434. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10435. }
  10436. else
  10437. 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));
  10438. }
  10439. return 0;
  10440. }
  10441. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10442. if (!lua_interface)
  10443. return 0;
  10444. Spawn* widget = lua_interface->GetSpawn(state);
  10445. lua_interface->ResetFunctionStack(state);
  10446. if (widget && widget->IsWidget())
  10447. {
  10448. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10449. return 1;
  10450. }
  10451. return 0;
  10452. }
  10453. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10454. if (!lua_interface)
  10455. return 0;
  10456. sint32 min = lua_interface->GetSInt32Value(state);
  10457. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10458. lua_interface->ResetFunctionStack(state);
  10459. sint32 result = MakeRandomInt(min, max);
  10460. lua_interface->SetSInt32Value(state, result);
  10461. return 1;
  10462. }
  10463. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10464. if (!lua_interface)
  10465. return 0;
  10466. float min = lua_interface->GetFloatValue(state);
  10467. float max = lua_interface->GetFloatValue(state, 2);
  10468. lua_interface->ResetFunctionStack(state);
  10469. float result = MakeRandomFloat(min, max);
  10470. lua_interface->SetFloatValue(state, result);
  10471. return 1;
  10472. }
  10473. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10474. if (!lua_interface)
  10475. return 0;
  10476. Spawn* spawn = lua_interface->GetSpawn(state);
  10477. int32 value = lua_interface->GetInt32Value(state, 2);
  10478. lua_interface->ResetFunctionStack(state);
  10479. if(!spawn)
  10480. {
  10481. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10482. lua_interface->SetBooleanValue(state, false);
  10483. return 1;
  10484. }
  10485. spawn->AddIconValue(value);
  10486. lua_interface->SetBooleanValue(state, true);
  10487. return 1;
  10488. }
  10489. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10490. if (!lua_interface)
  10491. return 0;
  10492. Spawn* spawn = lua_interface->GetSpawn(state);
  10493. int32 value = lua_interface->GetInt32Value(state, 2);
  10494. lua_interface->ResetFunctionStack(state);
  10495. if(!spawn)
  10496. {
  10497. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10498. lua_interface->SetBooleanValue(state, false);
  10499. return 1;
  10500. }
  10501. spawn->RemoveIconValue(value);
  10502. lua_interface->SetBooleanValue(state, true);
  10503. return 1;
  10504. }
  10505. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10506. Spawn* npc = lua_interface->GetSpawn(state);
  10507. lua_interface->ResetFunctionStack(state);
  10508. if (npc && npc->IsNPC()) {
  10509. NPC* shard = (NPC*)npc;
  10510. int32 shardid = shard->GetShardID();
  10511. lua_interface->SetInt32Value(state, shardid);
  10512. return 1;
  10513. }
  10514. lua_interface->SetInt32Value(state, 0);
  10515. return 1;
  10516. }
  10517. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10518. Spawn* npc = lua_interface->GetSpawn(state);
  10519. lua_interface->ResetFunctionStack(state);
  10520. if (npc && npc->IsNPC()) {
  10521. NPC* shard = (NPC*)npc;
  10522. int32 charid = shard->GetShardCharID();
  10523. lua_interface->SetInt32Value(state, charid);
  10524. return 1;
  10525. }
  10526. lua_interface->SetInt32Value(state, 0);
  10527. return 1;
  10528. }
  10529. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10530. Spawn* npc = lua_interface->GetSpawn(state);
  10531. lua_interface->ResetFunctionStack(state);
  10532. if (npc && npc->IsNPC()) {
  10533. NPC* shard = (NPC*)npc;
  10534. int64 timestamp = shard->GetShardCreatedTimestamp();
  10535. lua_interface->SetSInt64Value(state, timestamp);
  10536. return 1;
  10537. }
  10538. lua_interface->SetSInt64Value(state, 0);
  10539. return 1;
  10540. }
  10541. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10542. if (!lua_interface)
  10543. return 0;
  10544. int32 shardid = lua_interface->GetInt32Value(state);
  10545. lua_interface->ResetFunctionStack(state);
  10546. if(shardid < 1)
  10547. lua_interface->SetBooleanValue(state, false);
  10548. else
  10549. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10550. return 1;
  10551. }
  10552. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10553. if (!lua_interface)
  10554. return 0;
  10555. Spawn* spawn = lua_interface->GetSpawn(state);
  10556. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10557. if (spawn) {
  10558. spawn->PauseMovement(delay_in_ms);
  10559. }
  10560. lua_interface->ResetFunctionStack(state);
  10561. return 0;
  10562. }
  10563. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10564. if (!lua_interface)
  10565. return 0;
  10566. Spawn* spawn = lua_interface->GetSpawn(state);
  10567. if (spawn) {
  10568. spawn->StopMovement();
  10569. }
  10570. lua_interface->ResetFunctionStack(state);
  10571. return 0;
  10572. }
  10573. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10574. Player* player = (Player*)lua_interface->GetSpawn(state);
  10575. int8 level = lua_interface->GetInt8Value(state, 2);
  10576. lua_interface->ResetFunctionStack(state);
  10577. if (player && player->IsPlayer() && level > 0) {
  10578. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10579. return 1;
  10580. }
  10581. return 0;
  10582. }
  10583. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10584. Player* player = (Player*)lua_interface->GetSpawn(state);
  10585. int8 level = lua_interface->GetInt8Value(state, 2);
  10586. lua_interface->ResetFunctionStack(state);
  10587. if (player && player->IsPlayer() && level > 0) {
  10588. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10589. return 1;
  10590. }
  10591. return 0;
  10592. }
  10593. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10594. ZoneServer* zone = lua_interface->GetZone(state);
  10595. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10596. if (zone) {
  10597. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10598. if (spawn) {
  10599. lua_interface->SetSpawnValue(state, spawn);
  10600. return 1;
  10601. }
  10602. }
  10603. return 0;
  10604. }