LuaFunctions.cpp 364 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884
  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. }
  327. return 0;
  328. }
  329. //this function is used to force an update packet to be sent.
  330. //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
  331. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  332. if (!lua_interface)
  333. return 0;
  334. Spawn* spawn = lua_interface->GetSpawn(state);
  335. if (spawn) {
  336. spawn->info_changed = true;
  337. }
  338. return 0;
  339. }
  340. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int32 new_state = lua_interface->GetInt32Value(state, 2);
  345. if (spawn) {
  346. spawn->GetZone()->SendStateCommand(spawn, new_state);
  347. }
  348. return 0;
  349. }
  350. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  351. if (!lua_interface)
  352. return 0;
  353. Spawn* spawn = lua_interface->GetSpawn(state);
  354. string variable = lua_interface->GetStringValue(state, 2);
  355. string value = lua_interface->GetStringValue(state, 3);
  356. 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.
  357. bool temporary_flag = lua_interface->GetBooleanValue(state, 5); // default false as originally designed, allow user to set temporary_flag true to not update DB
  358. int32 type = commands.GetSpawnSetType(variable);
  359. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  360. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  361. return 0;
  362. }
  363. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  364. if (!lua_interface)
  365. return 0;
  366. Spawn* spawn = lua_interface->GetSpawn(state);
  367. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  368. if (spawn && spawn_id > 0) {
  369. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  370. if (closest_spawn) {
  371. lua_interface->SetSpawnValue(state, closest_spawn);
  372. return 1;
  373. }
  374. }
  375. return 0;
  376. }
  377. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  381. int32 position = lua_interface->GetInt32Value(state, 2);
  382. if (spawnList) {
  383. if (spawnList->size() > position) {
  384. lua_interface->SetSpawnValue(state, spawnList->at(position));
  385. return 1;
  386. }
  387. else {
  388. return 0;
  389. }
  390. return spawnList->size();
  391. }
  392. return 0;
  393. }
  394. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  395. if (!lua_interface)
  396. return 0;
  397. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  398. if (spawnList) {
  399. return spawnList->size();
  400. }
  401. return 0;
  402. }
  403. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  404. if (!lua_interface)
  405. return 0;
  406. vector<Spawn*>* spawnList = new vector<Spawn*>();
  407. lua_interface->SetSpawnListValue(state, spawnList);
  408. return 1;
  409. }
  410. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  411. if (!lua_interface)
  412. return 0;
  413. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  414. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  415. if (spawnList) {
  416. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  417. if (it == spawnList->end())
  418. spawnList->push_back(spawn);
  419. }
  420. return 0;
  421. }
  422. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  423. if (!lua_interface)
  424. return 0;
  425. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  426. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  427. if (spawnList) {
  428. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  429. if(it != spawnList->end())
  430. spawnList->erase(it);
  431. }
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. if (spawn) {
  440. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  441. if (spawns.size() > 0) {
  442. vector<Spawn*>* spawnList = new vector<Spawn*>();
  443. vector<Spawn*>::iterator itr;
  444. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  445. spawnList->push_back(*itr);
  446. }
  447. lua_interface->SetSpawnListValue(state, spawnList);
  448. return 1;
  449. }
  450. }
  451. return 0;
  452. }
  453. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  454. if (!lua_interface)
  455. return 0;
  456. string variable_name = lua_interface->GetStringValue(state);
  457. Variable* var = variables.FindVariable(variable_name);
  458. if (var) {
  459. lua_interface->SetStringValue(state, var->GetValue());
  460. return 1;
  461. }
  462. return 0;
  463. }
  464. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  465. if (!lua_interface)
  466. return 0;
  467. int32 total_coins = lua_interface->GetInt32Value(state);
  468. if (total_coins == 0) {
  469. lua_interface->SetStringValue(state, "0 copper");
  470. return 1;
  471. }
  472. char tmp[64] = { 0 };
  473. string message = "";
  474. int32 val = 0;
  475. if (total_coins >= 1000000) {
  476. val = total_coins / 1000000;
  477. total_coins -= 1000000 * val;
  478. sprintf(tmp, " %u Platinum", val);
  479. message.append(tmp);
  480. memset(tmp, 0, 64);
  481. }
  482. if (total_coins >= 10000) {
  483. val = total_coins / 10000;
  484. total_coins -= 10000 * val;
  485. sprintf(tmp, " %u Gold", val);
  486. message.append(tmp);
  487. memset(tmp, 0, 64);
  488. }
  489. if (total_coins >= 100) {
  490. val = total_coins / 100;
  491. total_coins -= 100 * val;
  492. sprintf(tmp, " %u Silver", val);
  493. message.append(tmp);
  494. memset(tmp, 0, 64);
  495. }
  496. if (total_coins > 0) {
  497. sprintf(tmp, " %u Copper", (int32)total_coins);
  498. message.append(tmp);
  499. }
  500. lua_interface->SetStringValue(state, message.c_str());
  501. return 1;
  502. }
  503. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  504. ZoneServer* zone = lua_interface->GetZone(state);
  505. int32 group_id = lua_interface->GetInt32Value(state, 2);
  506. if (zone) {
  507. Spawn* spawn = zone->GetSpawnGroup(group_id);
  508. if (spawn) {
  509. lua_interface->SetSpawnValue(state, spawn);
  510. return 1;
  511. }
  512. }
  513. return 0;
  514. }
  515. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  516. ZoneServer* zone = lua_interface->GetZone(state);
  517. int32 location_id = lua_interface->GetInt32Value(state, 2);
  518. if (zone) {
  519. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  520. if (spawn) {
  521. lua_interface->SetSpawnValue(state, spawn);
  522. return 1;
  523. }
  524. }
  525. return 0;
  526. }
  527. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. if (spawn) {
  530. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  531. return 1;
  532. }
  533. return 0;
  534. }
  535. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  536. Spawn* spawn = lua_interface->GetSpawn(state);
  537. if (spawn) {
  538. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  539. return 1;
  540. }
  541. return 0;
  542. }
  543. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  544. Spawn* spawn = lua_interface->GetSpawn(state);
  545. if (spawn) {
  546. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  547. return 1;
  548. }
  549. return 0;
  550. }
  551. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  552. Spawn* spawn = lua_interface->GetSpawn(state);
  553. if (spawn) {
  554. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  555. return 1;
  556. }
  557. return 0;
  558. }
  559. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  560. Player* player = (Player*)lua_interface->GetSpawn(state);
  561. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  562. if (player && player->IsPlayer() && faction_id > 0) {
  563. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  564. return 1;
  565. }
  566. return 0;
  567. }
  568. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  569. if (!lua_interface)
  570. return 0;
  571. Spawn* spawn = lua_interface->GetSpawn(state);
  572. int32 value = lua_interface->GetInt32Value(state, 2);
  573. if (spawn) {
  574. spawn->SetFactionID(value);
  575. }
  576. return 0;
  577. }
  578. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  579. Spawn* spawn = lua_interface->GetSpawn(state);
  580. if (spawn) {
  581. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  582. return 1;
  583. }
  584. return 0;
  585. }
  586. int EQ2Emu_lua_GetGender(lua_State* state) {
  587. Spawn* spawn = lua_interface->GetSpawn(state);
  588. if (spawn) {
  589. lua_interface->SetInt32Value(state, spawn->GetGender());
  590. return 1;
  591. }
  592. return 0;
  593. }
  594. int EQ2Emu_lua_GetTarget(lua_State* state) {
  595. Spawn* spawn = lua_interface->GetSpawn(state);
  596. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  597. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  598. return 1;
  599. }
  600. return 0;
  601. }
  602. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  603. if (!lua_interface)
  604. return 0;
  605. Spawn* spawn = lua_interface->GetSpawn(state);
  606. string mp3_string = lua_interface->GetStringValue(state, 2);
  607. int32 key1 = lua_interface->GetInt32Value(state, 3);
  608. int32 key2 = lua_interface->GetInt32Value(state, 4);
  609. Spawn* player = lua_interface->GetSpawn(state, 5);
  610. if (spawn && mp3_string.length() > 0) {
  611. Client* client = 0;
  612. if (player && player->IsPlayer())
  613. client = spawn->GetZone()->GetClientBySpawn(player);
  614. if (client) {
  615. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  616. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  617. }
  618. else
  619. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  620. }
  621. return 0;
  622. }
  623. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  624. if (!lua_interface)
  625. return 0;
  626. Spawn* spawn = lua_interface->GetSpawn(state);
  627. if (spawn) {
  628. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  629. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  630. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  631. return 3;
  632. }
  633. return 0;
  634. }
  635. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  636. if (!lua_interface)
  637. return 0;
  638. Spawn* spawn = lua_interface->GetSpawn(state);
  639. if (spawn) {
  640. int32 item_id = lua_interface->GetInt32Value(state, 2);
  641. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  642. return 1;
  643. }
  644. return 0;
  645. }
  646. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  647. if (!lua_interface)
  648. return 0;
  649. Spawn* spawn = lua_interface->GetSpawn(state);
  650. if (spawn && spawn->IsEntity()) {
  651. int32 item_id = lua_interface->GetInt32Value(state, 2);
  652. int16 charges = lua_interface->GetInt16Value(state, 3);
  653. if (charges == 0)
  654. charges = 1;
  655. ((Entity*)spawn)->AddLootItem(item_id, charges);
  656. }
  657. return 0;
  658. }
  659. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  660. if (!lua_interface)
  661. return 0;
  662. Spawn* spawn = lua_interface->GetSpawn(state);
  663. if (spawn && spawn->IsEntity()) {
  664. int32 item_id = lua_interface->GetInt32Value(state, 2);
  665. spawn->LootItem(item_id);
  666. }
  667. return 0;
  668. }
  669. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  670. if (!lua_interface)
  671. return 0;
  672. Spawn* spawn = lua_interface->GetSpawn(state);
  673. if (spawn) {
  674. int32 val = lua_interface->GetInt32Value(state, 2);
  675. spawn->AddLootCoins(val);
  676. }
  677. return 0;
  678. }
  679. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  680. if (!lua_interface)
  681. return 0;
  682. Spawn* entity = lua_interface->GetSpawn(state);
  683. Spawn* player = lua_interface->GetSpawn(state, 2);
  684. if (entity && player && player->IsPlayer()) {
  685. int32 coins = lua_interface->GetInt32Value(state, 3);
  686. vector<Item*>* items = 0;
  687. int i = 0;
  688. int32 item_id = 0;
  689. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  690. if (items == 0)
  691. items = new vector<Item*>;
  692. if (master_item_list.GetItem(item_id))
  693. items->push_back(master_item_list.GetItem(item_id));
  694. i++;
  695. }
  696. Client* client = 0;
  697. client = player->GetZone()->GetClientBySpawn(player);
  698. if (client)
  699. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  700. if(coins > 0)
  701. entity->AddLootCoins(coins);
  702. safe_delete(items);
  703. }
  704. return 0;
  705. }
  706. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  707. if (!lua_interface)
  708. return 0;
  709. Spawn* entity = lua_interface->GetSpawn(state);
  710. Spawn* player = lua_interface->GetSpawn(state, 2);
  711. int32 item_id = lua_interface->GetInt32Value(state, 3);
  712. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  713. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  714. return 1;
  715. }
  716. return 0;
  717. }
  718. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  719. if (!lua_interface)
  720. return 0;
  721. Spawn* entity = lua_interface->GetSpawn(state);
  722. Spawn* player = lua_interface->GetSpawn(state, 2);
  723. if (entity && player && player->IsPlayer()) {
  724. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  725. return 1;
  726. }
  727. return 0;
  728. }
  729. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  730. if (!lua_interface)
  731. return 0;
  732. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  733. safe_delete(conversation);
  734. conversation = new vector<ConversationOption>();
  735. lua_interface->SetConversationValue(state, conversation);
  736. return 1;
  737. }
  738. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  739. if (!lua_interface)
  740. return 0;
  741. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  742. if (conversation) {
  743. ConversationOption conv_option;
  744. conv_option.option = lua_interface->GetStringValue(state, 2);
  745. conv_option.function = lua_interface->GetStringValue(state, 3);
  746. if (conv_option.option.length() > 0)
  747. conversation->push_back(conv_option);
  748. }
  749. return 0;
  750. }
  751. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  752. if (!lua_interface)
  753. return 0;
  754. Spawn* npc = lua_interface->GetSpawn(state);
  755. Spawn* player = lua_interface->GetSpawn(state, 2);
  756. if (npc && player && player->IsPlayer() && player->GetZone()) {
  757. Client* client = player->GetZone()->GetClientBySpawn(player);
  758. if (client) {
  759. int32 conversation_id = client->GetConversationID(npc, 0);
  760. client->CloseDialog(conversation_id);
  761. }
  762. }
  763. return 0;
  764. }
  765. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  766. if (!lua_interface)
  767. return 0;
  768. Item* item = lua_interface->GetItem(state);
  769. Spawn* player = lua_interface->GetSpawn(state, 2);
  770. if (item && player && player->IsPlayer() && player->GetZone()) {
  771. Client* client = player->GetZone()->GetClientBySpawn(player);
  772. if (client) {
  773. int32 conversation_id = client->GetConversationID(0, item);
  774. client->CloseDialog(conversation_id);
  775. }
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  783. Spawn* spawn = 0;
  784. Item* item = 0;
  785. int8 type = lua_interface->GetInt8Value(state, 2);
  786. if (type == 1 || type == 3)
  787. spawn = lua_interface->GetSpawn(state, 3);
  788. else if (type == 2 || type == 4)
  789. item = lua_interface->GetItem(state, 3);
  790. Spawn* player = lua_interface->GetSpawn(state, 4);
  791. string text = lua_interface->GetStringValue(state, 5);
  792. string mp3 = lua_interface->GetStringValue(state, 6);
  793. int32 key1 = lua_interface->GetInt32Value(state, 7);
  794. int32 key2 = lua_interface->GetInt32Value(state, 8);
  795. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  796. Client* client = player->GetZone()->GetClientBySpawn(player);
  797. if (client) {
  798. if (spawn) {
  799. // Need to do this so the function works the same as it did before
  800. if (type == 1)
  801. type++;
  802. if (mp3.length() > 0)
  803. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  804. else
  805. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  806. }
  807. else {
  808. if (mp3.length() > 0)
  809. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  810. else
  811. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  812. }
  813. }
  814. }
  815. safe_delete(conversation);
  816. lua_interface->SetConversationValue(state, NULL);
  817. return 0;
  818. }
  819. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  820. if(!lua_interface)
  821. return 0;
  822. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  823. Item* item = lua_interface->GetItem(state, 2);
  824. Spawn* player = lua_interface->GetSpawn(state, 3);
  825. string text = lua_interface->GetStringValue(state, 4);
  826. string mp3 = lua_interface->GetStringValue(state, 5);
  827. int32 key1 = lua_interface->GetInt32Value(state, 6);
  828. int32 key2 = lua_interface->GetInt32Value(state, 7);
  829. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  830. Client* client = player->GetZone()->GetClientBySpawn(player);
  831. if(client){
  832. if(mp3.length() > 0)
  833. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  834. else
  835. client->DisplayConversation(item, conversation, (char*)text.c_str());
  836. }
  837. safe_delete(conversation);
  838. }
  839. return 0;
  840. }*/
  841. int EQ2Emu_lua_StartConversation(lua_State* state) {
  842. if (!lua_interface)
  843. return 0;
  844. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  845. Spawn* source = lua_interface->GetSpawn(state, 2);
  846. Spawn* player = lua_interface->GetSpawn(state, 3);
  847. string text = lua_interface->GetStringValue(state, 4);
  848. string mp3 = lua_interface->GetStringValue(state, 5);
  849. int32 key1 = lua_interface->GetInt32Value(state, 6);
  850. int32 key2 = lua_interface->GetInt32Value(state, 7);
  851. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  852. Client* client = source->GetZone()->GetClientBySpawn(player);
  853. if (mp3.length() > 0)
  854. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  855. else
  856. client->DisplayConversation(source, 1, conversation, text.c_str());
  857. safe_delete(conversation);
  858. lua_interface->SetConversationValue(state, NULL);
  859. }
  860. else
  861. 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);
  862. return 0;
  863. }
  864. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  865. if (!lua_interface)
  866. return 0;
  867. Spawn* spawn = lua_interface->GetSpawn(state);
  868. float distance = lua_interface->GetFloatValue(state, 2);
  869. string in_range_function = lua_interface->GetStringValue(state, 3);
  870. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  871. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  872. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  873. return 0;
  874. }
  875. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  876. ZoneServer* zone = lua_interface->GetZone(state);
  877. float x = lua_interface->GetFloatValue(state, 2);
  878. float y = lua_interface->GetFloatValue(state, 3);
  879. float z = lua_interface->GetFloatValue(state, 4);
  880. float max_variation = lua_interface->GetFloatValue(state, 5);
  881. string in_range_function = lua_interface->GetStringValue(state, 6);
  882. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  883. if (zone && in_range_function.length() > 0)
  884. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  885. return 0;
  886. }
  887. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  888. if (!lua_interface)
  889. return 0;
  890. Spawn* spawn = lua_interface->GetSpawn(state);
  891. if (spawn && spawn->IsEntity()) {
  892. int32 val = lua_interface->GetInt32Value(state, 2);
  893. ((Entity*)spawn)->SetLootCoins(val);
  894. }
  895. return 0;
  896. }
  897. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  898. if (!lua_interface)
  899. return 0;
  900. Spawn* spawn = lua_interface->GetSpawn(state);
  901. if (spawn && spawn->IsEntity()) {
  902. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  903. return 1;
  904. }
  905. return 0;
  906. }
  907. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. Spawn* spawn = lua_interface->GetSpawn(state);
  911. float x = lua_interface->GetFloatValue(state, 2);
  912. float y = lua_interface->GetFloatValue(state, 3);
  913. float z = lua_interface->GetFloatValue(state, 4);
  914. float speed = lua_interface->GetFloatValue(state, 5);
  915. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  916. string function = lua_interface->GetStringValue(state, 7);
  917. if (spawn) {
  918. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  919. spawn->GetZone()->AddMovementNPC(spawn);
  920. }
  921. lua_interface->ResetFunctionStack(state);
  922. return 0;
  923. }
  924. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  925. if (!lua_interface)
  926. return 0;
  927. Spawn* spawn = lua_interface->GetSpawn(state);
  928. if (spawn) {
  929. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  930. return 1;
  931. }
  932. return 0;
  933. }
  934. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  935. if (!lua_interface)
  936. return 0;
  937. Spawn* spawn = lua_interface->GetSpawn(state);
  938. Spawn* target = lua_interface->GetSpawn(state, 2);
  939. if (spawn && target) {
  940. if (spawn->IsEntity())
  941. // ((Entity*)spawn)->FaceTarget(target);
  942. static_cast<Entity*>(spawn)->FaceTarget(target);
  943. }
  944. lua_interface->ResetFunctionStack(state);
  945. return 0;
  946. }
  947. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  948. if (!lua_interface)
  949. return 0;
  950. Spawn* spawn = lua_interface->GetSpawn(state);
  951. float x = lua_interface->GetFloatValue(state, 2);
  952. float y = lua_interface->GetFloatValue(state, 3);
  953. float z = lua_interface->GetFloatValue(state, 4);
  954. float speed = lua_interface->GetFloatValue(state, 5);
  955. string lua_function = lua_interface->GetStringValue(state, 6);
  956. bool more_points = lua_interface->GetBooleanValue(state, 7);
  957. if (spawn) {
  958. if (speed == 0)
  959. speed = spawn->GetSpeed();
  960. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  961. }
  962. lua_interface->ResetFunctionStack(state);
  963. return 0;
  964. }
  965. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  966. if (!lua_interface)
  967. return 0;
  968. Spawn* spawn = lua_interface->GetSpawn(state);
  969. if (spawn) {
  970. spawn->ClearRunningLocations();
  971. }
  972. return 0;
  973. }
  974. int EQ2Emu_lua_Say(lua_State* state) {
  975. if (!lua_interface)
  976. return 0;
  977. Spawn* spawn = lua_interface->GetSpawn(state);
  978. string message = lua_interface->GetStringValue(state, 2);
  979. Spawn* player = lua_interface->GetSpawn(state, 3);
  980. int32 language = lua_interface->GetInt32Value(state, 4);
  981. if (spawn && message.length() > 0) {
  982. Client* client = 0;
  983. if (player && player->IsPlayer())
  984. client = spawn->GetZone()->GetClientBySpawn(player);
  985. if (client)
  986. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  987. else
  988. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  989. }
  990. lua_interface->ResetFunctionStack(state);
  991. return 0;
  992. }
  993. int EQ2Emu_lua_Shout(lua_State* state) {
  994. if (!lua_interface)
  995. return 0;
  996. Spawn* spawn = lua_interface->GetSpawn(state);
  997. string message = lua_interface->GetStringValue(state, 2);
  998. Spawn* player = lua_interface->GetSpawn(state, 3);
  999. if (spawn && message.length() > 0) {
  1000. Client* client = 0;
  1001. if (player && player->IsPlayer())
  1002. client = spawn->GetZone()->GetClientBySpawn(player);
  1003. if (client)
  1004. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1005. else
  1006. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1007. }
  1008. lua_interface->ResetFunctionStack(state);
  1009. return 0;
  1010. }
  1011. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1012. if (!lua_interface)
  1013. return 0;
  1014. Spawn* spawn = lua_interface->GetSpawn(state);
  1015. string message = lua_interface->GetStringValue(state, 2);
  1016. Spawn* player = lua_interface->GetSpawn(state, 3);
  1017. if (spawn && message.length() > 0) {
  1018. Client* client = 0;
  1019. if (player && player->IsPlayer())
  1020. client = spawn->GetZone()->GetClientBySpawn(player);
  1021. if (client)
  1022. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1023. else
  1024. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1025. }
  1026. lua_interface->ResetFunctionStack(state);
  1027. return 0;
  1028. }
  1029. int EQ2Emu_lua_Emote(lua_State* state) {
  1030. if (!lua_interface)
  1031. return 0;
  1032. Spawn* spawn = lua_interface->GetSpawn(state);
  1033. string message = lua_interface->GetStringValue(state, 2);
  1034. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1035. Spawn* player = lua_interface->GetSpawn(state, 4);
  1036. char* to = 0;
  1037. if (spawn2)
  1038. to = spawn2->GetName();
  1039. if (spawn && message.length() > 0) {
  1040. Client* client = 0;
  1041. if (player && player->IsPlayer())
  1042. client = spawn->GetZone()->GetClientBySpawn(player);
  1043. if (client)
  1044. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1045. else
  1046. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1047. }
  1048. lua_interface->ResetFunctionStack(state);
  1049. return 0;
  1050. }
  1051. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1052. if (!lua_interface)
  1053. return 0;
  1054. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1055. if (!luaspell)
  1056. return 0;
  1057. Spawn* caster = luaspell->caster;
  1058. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1059. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1060. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1061. Spawn* target = lua_interface->GetSpawn(state, 4);
  1062. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1063. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1064. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1065. lua_interface->ResetFunctionStack(state);
  1066. boost::to_lower(heal_type);
  1067. if (caster && caster->IsEntity()) {
  1068. bool success = false;
  1069. luaspell->resisted = false;
  1070. if (target) {
  1071. float distance = caster->GetDistance(target, true);
  1072. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1073. success = true;
  1074. }
  1075. if (luaspell->targets.size() > 0) {
  1076. Spawn* target = 0;
  1077. ZoneServer* zone = luaspell->caster->GetZone();
  1078. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1079. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1080. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1081. float distance = caster->GetDistance(target, true);
  1082. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1083. }
  1084. }
  1085. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1086. success = true;
  1087. }
  1088. if (success) {
  1089. if (caster->GetZone())
  1090. caster->GetZone()->TriggerCharSheetTimer();
  1091. }
  1092. }
  1093. return 0;
  1094. }
  1095. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1096. if (!lua_interface)
  1097. return 0;
  1098. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1099. if (!luaspell)
  1100. return 0;
  1101. Spawn* caster = luaspell->caster;
  1102. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1103. float percentage = lua_interface->GetFloatValue(state, 2);
  1104. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1105. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1106. Spawn* target = lua_interface->GetSpawn(state, 5);
  1107. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1108. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1109. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1110. lua_interface->ResetFunctionStack(state);
  1111. boost::to_lower(heal_type);
  1112. int32 min_heal = 0, max_heal = 0;
  1113. if (caster && caster->IsEntity() && target) {
  1114. if(percentage <= 0.0f)
  1115. {
  1116. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1117. return 0;
  1118. }
  1119. if(heal_type == "power")
  1120. {
  1121. if(current_value)
  1122. {
  1123. if(caster_value)
  1124. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1125. else
  1126. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1127. }
  1128. else
  1129. {
  1130. if(caster_value)
  1131. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1132. else
  1133. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1134. }
  1135. }
  1136. else
  1137. {
  1138. if(current_value)
  1139. {
  1140. if(caster_value)
  1141. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1142. else
  1143. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1144. }
  1145. else
  1146. {
  1147. if(caster_value)
  1148. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1149. else
  1150. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1151. }
  1152. }
  1153. bool success = false;
  1154. luaspell->resisted = false;
  1155. if (target) {
  1156. float distance = caster->GetDistance(target, true);
  1157. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1158. success = true;
  1159. }
  1160. if (luaspell->targets.size() > 0) {
  1161. Spawn* target = 0;
  1162. ZoneServer* zone = luaspell->caster->GetZone();
  1163. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1164. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1165. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1166. float distance = caster->GetDistance(target, true);
  1167. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1168. }
  1169. }
  1170. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1171. success = true;
  1172. }
  1173. if (success) {
  1174. if (caster->GetZone())
  1175. caster->GetZone()->TriggerCharSheetTimer();
  1176. }
  1177. }
  1178. return 0;
  1179. }
  1180. int EQ2Emu_lua_AddItem(lua_State* state) {
  1181. if (!lua_interface)
  1182. return 0;
  1183. Spawn* spawn = lua_interface->GetSpawn(state);
  1184. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1185. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1186. // default of 1 quantity to add
  1187. if (quantity == 0)
  1188. quantity = 1;
  1189. if (spawn && spawn->IsPlayer()) {
  1190. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1191. if (client && item_id > 0) {
  1192. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1193. return 1;
  1194. }
  1195. }
  1196. lua_interface->SetBooleanValue(state, false);
  1197. return 1;
  1198. }
  1199. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1204. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1205. string location = lua_interface->GetStringValue(state, 4);
  1206. if (spawn && spawn->IsPlayer()) {
  1207. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1208. if (client && item_id > 0) {
  1209. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1210. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1211. else
  1212. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1213. if (send_messages) {
  1214. Item* item = master_item_list.GetItem(item_id);
  1215. if (item) {
  1216. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1217. string popup_text = "You receive " + item->name;
  1218. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1219. }
  1220. }
  1221. return 1;
  1222. }
  1223. }
  1224. lua_interface->SetBooleanValue(state, false);
  1225. return 1;
  1226. }
  1227. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1228. Spawn* spawn = lua_interface->GetSpawn(state);
  1229. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1230. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1231. // default of 1 to remove
  1232. if (quantity == 0)
  1233. quantity = 1;
  1234. Client* client;
  1235. Item* item;
  1236. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1237. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1238. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1239. if (client->RemoveItem(item, quantity)) {
  1240. lua_interface->SetBooleanValue(state, true);
  1241. return 1;
  1242. }
  1243. }
  1244. }
  1245. }
  1246. lua_interface->SetBooleanValue(state, false);
  1247. return 1;
  1248. }
  1249. int EQ2Emu_lua_HasItem(lua_State* state) {
  1250. Spawn* player = lua_interface->GetSpawn(state);
  1251. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1252. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1253. if (player && player->IsPlayer()) {
  1254. bool hasItem = false;
  1255. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1256. if (!hasItem)
  1257. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1258. lua_interface->SetBooleanValue(state, hasItem);
  1259. return 1;
  1260. }
  1261. lua_interface->SetBooleanValue(state, false);
  1262. return 1;
  1263. }
  1264. int EQ2Emu_lua_Spawn(lua_State* state) {
  1265. if (!lua_interface)
  1266. return 0;
  1267. ZoneServer* zone = lua_interface->GetZone(state);
  1268. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1269. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1270. float x = lua_interface->GetFloatValue(state, 4);
  1271. float y = lua_interface->GetFloatValue(state, 5);
  1272. float z = lua_interface->GetFloatValue(state, 6);
  1273. float heading = lua_interface->GetFloatValue(state, 7);
  1274. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1275. Spawn* spawn = zone->GetSpawn(spawn_id);
  1276. if (!spawn)
  1277. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1278. else {
  1279. spawn->SetX(x);
  1280. spawn->SetZ(z);
  1281. spawn->SetY(y,true,true);
  1282. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1283. spawn->SetHeading(heading);
  1284. if (restricted_npc)
  1285. spawn->AddAllowAccessSpawn(spawn);
  1286. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1287. bool scriptActive = false;
  1288. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1289. scriptActive = true;
  1290. spawn->SetSpawnScript(string(spawn_script));
  1291. }
  1292. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1293. zone->AddSpawn(spawn);
  1294. if (scriptActive) {
  1295. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1296. }
  1297. lua_interface->SetSpawnValue(state, spawn);
  1298. return 1;
  1299. }
  1300. }
  1301. else {
  1302. string output = "Invalid paramaters to LUA Spawn command: \n";
  1303. if (!zone)
  1304. output = output.append("\t").append("Missing zone reference. \n");
  1305. if (spawn_id == 0)
  1306. output = output.append("\t").append("Missing spawn_id.");
  1307. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1308. }
  1309. return 0;
  1310. }
  1311. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1312. if (!lua_interface)
  1313. return 0;
  1314. ZoneServer* zone = lua_interface->GetZone(state);
  1315. if (zone) {
  1316. lua_interface->SetStringValue(state, zone->GetZoneName());
  1317. return 1;
  1318. }
  1319. return 0;
  1320. }
  1321. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1322. if (!lua_interface)
  1323. return 0;
  1324. ZoneServer* zone = lua_interface->GetZone(state);
  1325. if (zone) {
  1326. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1327. return 1;
  1328. }
  1329. return 0;
  1330. }
  1331. int EQ2Emu_lua_GetZone(lua_State* state) {
  1332. if (!lua_interface)
  1333. return 0;
  1334. int32 zone_id = lua_interface->GetInt32Value(state);
  1335. ZoneServer* zone = 0;
  1336. if (zone_id > 0)
  1337. zone = zone_list.Get(zone_id);
  1338. else {
  1339. string zone_name = lua_interface->GetStringValue(state);
  1340. if (zone_name.length() > 0) {
  1341. zone = zone_list.Get(zone_name.c_str());
  1342. }
  1343. else {
  1344. Spawn* spawn = lua_interface->GetSpawn(state);
  1345. if (spawn)
  1346. zone = spawn->GetZone();
  1347. }
  1348. }
  1349. if (zone) {
  1350. lua_interface->SetZoneValue(state, zone);
  1351. return 1;
  1352. }
  1353. return 0;
  1354. }
  1355. int EQ2Emu_lua_AddHate(lua_State* state) {
  1356. Spawn* entity = lua_interface->GetSpawn(state);
  1357. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1358. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1359. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1360. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1361. if (entity && entity->IsEntity() && amount != 0) {
  1362. if (luaspell) {
  1363. ZoneServer* zone = luaspell->caster->GetZone();
  1364. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1365. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1366. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1367. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1368. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1369. if (send_packet)
  1370. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1371. }
  1372. }
  1373. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1374. }
  1375. else if (npc && npc->IsNPC() && npc->GetZone())
  1376. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1377. }
  1378. return 0;
  1379. }
  1380. int EQ2Emu_lua_Zone(lua_State* state) {
  1381. if (!lua_interface)
  1382. return 0;
  1383. ZoneServer* zone = lua_interface->GetZone(state);
  1384. Spawn* player = lua_interface->GetSpawn(state, 2);
  1385. Client* client = 0;
  1386. if (player && player->IsPlayer())
  1387. client = player->GetZone()->GetClientBySpawn(player);
  1388. float x = lua_interface->GetFloatValue(state, 3);
  1389. float y = lua_interface->GetFloatValue(state, 4);
  1390. float z = lua_interface->GetFloatValue(state, 5);
  1391. float heading = lua_interface->GetFloatValue(state, 6);
  1392. if (zone && client) {
  1393. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1394. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1395. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1396. {
  1397. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1398. return 0;
  1399. }
  1400. if (x != 0 || y != 0 || z != 0) {
  1401. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1402. player->SetX(x);
  1403. player->SetY(y);
  1404. player->SetZ(z);
  1405. player->SetHeading(heading);
  1406. client->Zone(zone->GetZoneName(), false);
  1407. }
  1408. else
  1409. client->Zone(zone->GetZoneName());
  1410. }
  1411. else
  1412. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1413. return 0;
  1414. }
  1415. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1416. if (!lua_interface)
  1417. return 0;
  1418. Spawn* spawn = lua_interface->GetSpawn(state);
  1419. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1420. if (spawn && spawn2)
  1421. spawn->AddAllowAccessSpawn(spawn2);
  1422. return 0;
  1423. }
  1424. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1425. if (!lua_interface)
  1426. return 0;
  1427. Spawn* target = lua_interface->GetSpawn(state);
  1428. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1429. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1430. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1431. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1432. if (!target) {
  1433. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1434. return 0;
  1435. }
  1436. if (!target->IsEntity()) {
  1437. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1438. return 0;
  1439. }
  1440. if (spell_id <= 0) {
  1441. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1442. return 0;
  1443. }
  1444. if (caster && !caster->IsEntity()) {
  1445. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1446. return 0;
  1447. }
  1448. if (spell_tier == 0)
  1449. spell_tier = 1;
  1450. if (!caster)
  1451. caster = target;
  1452. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1453. return 0;
  1454. }
  1455. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1456. if (!lua_interface)
  1457. return 0;
  1458. Spawn* target = lua_interface->GetSpawn(state);
  1459. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1460. if (!luaspell)
  1461. return 0;
  1462. Spawn* caster = luaspell->caster;
  1463. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1464. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1465. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1466. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1467. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1468. //lua_interface->ResetFunctionStack(state);
  1469. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1470. vector<int16> faction_req;
  1471. vector<int16> race_req;
  1472. int32 class_req = 0;
  1473. int32 i = 0;
  1474. int8 f = 0;
  1475. int8 r = 0;
  1476. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1477. if (class_id < 100) {
  1478. class_req += pow(2.0, double(class_id - 1));
  1479. }
  1480. else if (class_id > 100 && class_id < 1000) {
  1481. race_req.push_back(class_id);
  1482. r++;
  1483. }
  1484. else {
  1485. faction_req.push_back(class_id);
  1486. f++;
  1487. }
  1488. i++;
  1489. }
  1490. if (caster && caster->IsEntity()) {
  1491. bool race_match = false;
  1492. bool success = false;
  1493. luaspell->resisted = false;
  1494. if (luaspell->targets.size() > 0) {
  1495. ZoneServer* zone = luaspell->caster->GetZone();
  1496. Spawn* target = 0;
  1497. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1498. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1499. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1500. if (race_req.size() > 0) {
  1501. for (int8 i = 0; i < race_req.size(); i++) {
  1502. if (target->GetLuaRaceId() == race_req[i]) {
  1503. race_match = true;
  1504. }
  1505. }
  1506. }
  1507. else
  1508. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1509. if (race_match == true) {
  1510. float distance = caster->GetDistance(target, true);
  1511. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1512. }
  1513. }
  1514. }
  1515. success = true;
  1516. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1517. }
  1518. else if (target) {
  1519. //check class and race/faction here
  1520. if (race_req.size() > 0) {
  1521. for (int8 i = 0; i < race_req.size(); i++) {
  1522. if (target->GetLuaRaceId() == race_req[i]) {
  1523. race_match = true;
  1524. }
  1525. }
  1526. }
  1527. else
  1528. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1529. if (race_match == true) {
  1530. float distance = caster->GetDistance(target, true);
  1531. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1532. success = true;
  1533. }
  1534. }
  1535. if (success) {
  1536. Spell* spell = luaspell->spell;
  1537. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1538. ((Player*)caster)->InCombat(true);
  1539. if (caster->GetZone())
  1540. caster->GetZone()->TriggerCharSheetTimer();
  1541. }
  1542. }
  1543. }
  1544. return 0;
  1545. }
  1546. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1547. if (!lua_interface)
  1548. return 0;
  1549. Spawn* spawn = lua_interface->GetSpawn(state);
  1550. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1551. lua_interface->ResetFunctionStack(state);
  1552. if (spawn && value != 0) {
  1553. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1554. spawn->SetPower(spawn->GetTotalPower());
  1555. else
  1556. spawn->SetPower(spawn->GetPower() + value);
  1557. }
  1558. return 0;
  1559. }
  1560. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1561. if (!lua_interface)
  1562. return 0;
  1563. Spawn* spawn = lua_interface->GetSpawn(state);
  1564. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (spawn && value != 0) {
  1567. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1568. spawn->SetHP(spawn->GetTotalHP());
  1569. else
  1570. spawn->SetHP(spawn->GetHP() + value);
  1571. }
  1572. return 0;
  1573. }
  1574. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1575. if (!lua_interface)
  1576. return 0;
  1577. Spawn* spawn = lua_interface->GetSpawn(state);
  1578. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1579. lua_interface->ResetFunctionStack(state);
  1580. if (spawn && value != 0) {
  1581. spawn->SetPower(spawn->GetPower() + value);
  1582. if (value > spawn->GetTotalHPBase())
  1583. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1584. }
  1585. return 0;
  1586. }
  1587. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1588. if (!lua_interface)
  1589. return 0;
  1590. Spawn* spawn = lua_interface->GetSpawn(state);
  1591. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1592. lua_interface->ResetFunctionStack(state);
  1593. if (spawn && value != 0) {
  1594. spawn->SetHP(spawn->GetHP() + value);
  1595. if (value > spawn->GetTotalHPBase())
  1596. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1597. }
  1598. return 0;
  1599. }
  1600. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1601. if (!lua_interface)
  1602. return 0;
  1603. Spawn* spawn = lua_interface->GetSpawn(state);
  1604. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1605. lua_interface->ResetFunctionStack(state);
  1606. if (spawn) {
  1607. spawn->SetHP(value);
  1608. if (value > spawn->GetTotalHPBase())
  1609. spawn->SetTotalHP(value);
  1610. }
  1611. return 0;
  1612. }
  1613. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1614. if (!lua_interface)
  1615. return 0;
  1616. Spawn* spawn = lua_interface->GetSpawn(state);
  1617. float value = lua_interface->GetFloatValue(state, 2);
  1618. lua_interface->ResetFunctionStack(state);
  1619. if (spawn && spawn->IsEntity() && value > 0)
  1620. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1621. if (spawn->IsPlayer())
  1622. ((Player*)spawn)->SetCharSheetChanged(true);
  1623. return 0;
  1624. }
  1625. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1626. if (!lua_interface)
  1627. return 0;
  1628. Spawn* spawn = lua_interface->GetSpawn(state);
  1629. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1630. lua_interface->ResetFunctionStack(state);
  1631. if (spawn && spawn->IsEntity() && value > 0)
  1632. ((Entity*)spawn)->SetTotalHPBase(value);
  1633. return 0;
  1634. }
  1635. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1636. if (!lua_interface)
  1637. return 0;
  1638. Spawn* spawn = lua_interface->GetSpawn(state);
  1639. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1640. lua_interface->ResetFunctionStack(state);
  1641. if (spawn && value > 0) {
  1642. spawn->SetPower(value);
  1643. if (value > spawn->GetTotalPowerBase())
  1644. spawn->SetTotalPower(value);
  1645. }
  1646. return 0;
  1647. }
  1648. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1649. if (!lua_interface)
  1650. return 0;
  1651. Spawn* spawn = lua_interface->GetSpawn(state);
  1652. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1653. lua_interface->ResetFunctionStack(state);
  1654. if (spawn && spawn->IsEntity() && value > 0)
  1655. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1656. return 0;
  1657. }
  1658. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1659. if (!lua_interface)
  1660. return 0;
  1661. Spawn* spawn = lua_interface->GetSpawn(state);
  1662. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1663. lua_interface->ResetFunctionStack(state);
  1664. if (spawn && spawn->IsEntity() && value > 0)
  1665. ((Entity*)spawn)->SetTotalPowerBase(value);
  1666. return 0;
  1667. }
  1668. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1669. if (!lua_interface)
  1670. return 0;
  1671. Spawn* spawn = lua_interface->GetSpawn(state);
  1672. float x = lua_interface->GetFloatValue(state, 2);
  1673. float y = lua_interface->GetFloatValue(state, 3);
  1674. float z = lua_interface->GetFloatValue(state, 4);
  1675. float heading = lua_interface->GetFloatValue(state, 5);
  1676. lua_interface->ResetFunctionStack(state);
  1677. if (spawn) {
  1678. spawn->SetX(x);
  1679. spawn->SetY(y);
  1680. spawn->SetZ(z);
  1681. if (heading != 0)
  1682. spawn->SetHeading(heading);
  1683. spawn->SetSpawnOrigX(spawn->GetX());
  1684. spawn->SetSpawnOrigY(spawn->GetY());
  1685. spawn->SetSpawnOrigZ(spawn->GetZ());
  1686. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1687. if (spawn->IsPlayer()) {
  1688. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1689. if (client) {
  1690. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1691. client->QueuePacket(packet);
  1692. }
  1693. }
  1694. }
  1695. return 0;
  1696. }
  1697. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1698. if (!lua_interface)
  1699. return 0;
  1700. Spawn* spawn = lua_interface->GetSpawn(state);
  1701. float value = lua_interface->GetFloatValue(state, 2);
  1702. lua_interface->ResetFunctionStack(state);
  1703. if (spawn) {
  1704. spawn->SetHeading(value);
  1705. if (spawn->IsPlayer()) {
  1706. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1707. if (client) {
  1708. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1709. client->QueuePacket(packet);
  1710. }
  1711. }
  1712. }
  1713. return 0;
  1714. }
  1715. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1716. if (!lua_interface)
  1717. return 0;
  1718. Spawn* spawn = lua_interface->GetSpawn(state);
  1719. int16 value = lua_interface->GetInt16Value(state, 2);
  1720. lua_interface->ResetFunctionStack(state);
  1721. if (spawn)
  1722. spawn->SetModelType(value);
  1723. return 0;
  1724. }
  1725. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1726. if (!lua_interface)
  1727. return 0;
  1728. Spawn* spawn = lua_interface->GetSpawn(state);
  1729. int8 value = lua_interface->GetInt8Value(state, 2);
  1730. lua_interface->ResetFunctionStack(state);
  1731. if (spawn) {
  1732. if (spawn->IsPlayer())
  1733. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1734. else
  1735. spawn->SetAdventureClass(value);
  1736. }
  1737. return 0;
  1738. }
  1739. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1740. if (!lua_interface)
  1741. return 0;
  1742. Spawn* spawn = lua_interface->GetSpawn(state);
  1743. int8 value = lua_interface->GetInt8Value(state, 2);
  1744. lua_interface->ResetFunctionStack(state);
  1745. if (spawn) {
  1746. spawn->SetTradeskillClass(value);
  1747. if (spawn->IsEntity()) {
  1748. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1749. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1750. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1751. }
  1752. if (spawn->IsPlayer())
  1753. ((Player*)spawn)->SetCharSheetChanged(true);
  1754. }
  1755. return 0;
  1756. }
  1757. int EQ2Emu_lua_SetMount(lua_State* state) {
  1758. if (!lua_interface)
  1759. return 0;
  1760. Spawn* spawn = lua_interface->GetSpawn(state);
  1761. int16 value = lua_interface->GetInt16Value(state, 2);
  1762. if (spawn && spawn->IsEntity()) {
  1763. ((Entity*)spawn)->SetMount(value);
  1764. EQ2_Color color;
  1765. color.red = 255;
  1766. color.green = 255;
  1767. color.blue = 255;
  1768. ((Entity*)spawn)->SetMountColor(&color);
  1769. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1770. }
  1771. return 0;
  1772. }
  1773. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1774. if (!lua_interface)
  1775. return 0;
  1776. Spawn* spawn = lua_interface->GetSpawn(state);
  1777. EQ2_Color mount_color;
  1778. EQ2_Color saddle_color;
  1779. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1780. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1781. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1782. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1783. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1784. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1785. if (spawn && spawn->IsEntity()) {
  1786. ((Entity*)spawn)->SetMountColor(&mount_color);
  1787. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1788. }
  1789. return 0;
  1790. }
  1791. int EQ2Emu_lua_GetMount(lua_State* state) {
  1792. if (!lua_interface)
  1793. return 0;
  1794. Spawn* spawn = lua_interface->GetSpawn(state);
  1795. if (spawn && spawn->IsEntity()) {
  1796. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1797. return 1;
  1798. }
  1799. return 0;
  1800. }
  1801. int EQ2Emu_lua_GetRace(lua_State* state) {
  1802. if (!lua_interface)
  1803. return 0;
  1804. Spawn* spawn = lua_interface->GetSpawn(state);
  1805. if (spawn)
  1806. {
  1807. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1808. lua_interface->SetInt32Value(state, spawn->GetRace());
  1809. return 1;
  1810. }
  1811. return 0;
  1812. }
  1813. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1814. if (!lua_interface)
  1815. return 0;
  1816. Spawn* spawn = lua_interface->GetSpawn(state);
  1817. if (spawn) {
  1818. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1819. return 1;
  1820. }
  1821. return 0;
  1822. }
  1823. int EQ2Emu_lua_GetClass(lua_State* state) {
  1824. Spawn* spawn = lua_interface->GetSpawn(state);
  1825. if (spawn) {
  1826. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1827. return 1;
  1828. }
  1829. return 0;
  1830. }
  1831. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1832. Spawn* spawn = lua_interface->GetSpawn(state);
  1833. if (spawn) {
  1834. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1835. return 1;
  1836. }
  1837. return 0;
  1838. }
  1839. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1840. if (!lua_interface)
  1841. return 0;
  1842. Spawn* spawn = lua_interface->GetSpawn(state);
  1843. float value = lua_interface->GetFloatValue(state, 2);
  1844. lua_interface->ResetFunctionStack(state);
  1845. if (spawn) {
  1846. spawn->SetSpeed(value);
  1847. ((Entity*)spawn)->SetSpeed(value);
  1848. if (spawn->IsPlayer()) {
  1849. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1850. if (client) {
  1851. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1852. if (packet) {
  1853. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1854. packet->setDataByName("speed", value);
  1855. packet->setDataByName("size", 0.51);
  1856. EQ2Packet* app = packet->serialize();
  1857. client->QueuePacket(app);
  1858. safe_delete(packet);
  1859. }
  1860. }
  1861. }
  1862. }
  1863. return 0;
  1864. }
  1865. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1866. if (!lua_interface)
  1867. return 0;
  1868. Spawn* spawn = lua_interface->GetSpawn(state);
  1869. const int16 type = lua_interface->GetInt16Value(state, 2);
  1870. const float value = lua_interface->GetFloatValue(state, 3);
  1871. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1872. int64 class_req = 0;
  1873. int32 class_id = 0;
  1874. vector<int16> faction_req;
  1875. vector<int16> race_req;
  1876. int32 i = 0;
  1877. int8 f = 0;
  1878. int8 r = 0;
  1879. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1880. if (class_id < 100) {
  1881. class_req += pow(2.0, double(class_id - 1));
  1882. }
  1883. else if (class_id > 100 && class_id < 1000) {
  1884. race_req.push_back(class_id);
  1885. r++;
  1886. }
  1887. else {
  1888. faction_req.push_back(class_id);
  1889. f++;
  1890. }
  1891. i++;
  1892. }
  1893. if (value != 0 && type >= 0) {
  1894. if (luaspell && luaspell->spell && luaspell->caster) {
  1895. ZoneServer* zone = luaspell->caster->GetZone();
  1896. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1897. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1898. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1899. if (target) {
  1900. if (target->IsPlayer()) {
  1901. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1902. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1903. if (((Player*)target)->GetGroupMemberInfo())
  1904. ((Player*)target)->UpdateGroupMemberInfo();
  1905. ((Player*)target)->SetCharSheetChanged(true);
  1906. }
  1907. else if (target->IsNPC())
  1908. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1909. else
  1910. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1911. }
  1912. }
  1913. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1914. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1915. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1916. }
  1917. else if (spawn && spawn->IsEntity()) {
  1918. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1919. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1920. if (spawn->IsPlayer())
  1921. ((Player*)spawn)->SetCharSheetChanged(true);
  1922. }
  1923. else
  1924. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1925. }
  1926. else
  1927. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1928. return 0;
  1929. }
  1930. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1931. if (!lua_interface)
  1932. return 0;
  1933. Spawn* spawn = lua_interface->GetSpawn(state);
  1934. int16 type = lua_interface->GetInt16Value(state, 2);
  1935. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1936. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1937. if (!spawn) {
  1938. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1939. return 0;
  1940. }
  1941. if (!spawn->IsEntity()) {
  1942. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1943. return 0;
  1944. }
  1945. if (value == 0) {
  1946. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1947. return 0;
  1948. }
  1949. if (!luaspell || !luaspell->spell) {
  1950. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1951. return 0;
  1952. }
  1953. int32 class_req = 0;
  1954. vector<int16> faction_req;
  1955. vector<int16> race_req;
  1956. int32 class_id = 0;
  1957. int32 i = 0;
  1958. int8 f = 0;
  1959. int8 r = 0;
  1960. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1961. if (class_id < 100) {
  1962. class_req += pow(2.0, double(class_id - 1));
  1963. }
  1964. else if (class_id > 100 && class_id < 1000) {
  1965. race_req.push_back(class_id);
  1966. r++;
  1967. }
  1968. else {
  1969. faction_req.push_back(class_id);
  1970. f++;
  1971. }
  1972. i++;
  1973. }
  1974. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1975. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1976. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1977. if (spawn->IsPlayer())
  1978. ((Player*)spawn)->SetCharSheetChanged(true);
  1979. return 0;
  1980. }
  1981. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  1982. if (!lua_interface)
  1983. return 0;
  1984. Spawn* spawn = lua_interface->GetSpawn(state);
  1985. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1986. if (!spawn) {
  1987. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1988. return 0;
  1989. }
  1990. if (!spawn->IsEntity()) {
  1991. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1992. return 0;
  1993. }
  1994. if (!luaspell || !luaspell->spell) {
  1995. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1996. return 0;
  1997. }
  1998. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1999. if (spawn->IsPlayer())
  2000. ((Player*)spawn)->SetCharSheetChanged(true);
  2001. return 0;
  2002. }
  2003. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2004. if (!lua_interface)
  2005. return 0;
  2006. Spawn* spawn = lua_interface->GetSpawn(state);
  2007. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2008. if (luaspell && luaspell->spell) {
  2009. ZoneServer* zone = luaspell->caster->GetZone();
  2010. Spawn* target = 0;
  2011. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2012. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2013. target = zone->GetSpawnByID(luaspell->targets[i]);
  2014. if (target && target->IsEntity()) {
  2015. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2016. if (target->IsPlayer())
  2017. ((Player*)target)->SetCharSheetChanged(true);
  2018. }
  2019. }
  2020. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2021. }
  2022. else if (spawn && spawn->IsEntity()) {
  2023. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2024. if (spawn->IsPlayer())
  2025. ((Player*)spawn)->SetCharSheetChanged(true);
  2026. }
  2027. return 0;
  2028. }
  2029. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2030. if (!lua_interface)
  2031. return 0;
  2032. Spawn* spawn = lua_interface->GetSpawn(state);
  2033. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2034. float value = lua_interface->GetFloatValue(state, 3);
  2035. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2036. if (value != 0) {
  2037. int32 spell_id = 0;
  2038. if (luaspell && luaspell->spell && luaspell->caster) {
  2039. spell_id = luaspell->spell->GetSpellID();
  2040. ZoneServer* zone = luaspell->caster->GetZone();
  2041. Spawn* target = 0;
  2042. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2043. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2044. target = zone->GetSpawnByID(luaspell->targets[i]);
  2045. if (target && target->Alive()) {
  2046. if (target->IsPlayer()) {
  2047. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2048. Client* client = target->GetZone()->GetClientBySpawn(target);
  2049. if (client) {
  2050. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2051. if (packet)
  2052. client->QueuePacket(packet);
  2053. }
  2054. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2055. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2056. }
  2057. else if (target->IsNPC()) {
  2058. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2059. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2060. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2061. }
  2062. else
  2063. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2064. }
  2065. }
  2066. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2067. }
  2068. else if (spawn) {
  2069. if (spawn->IsPlayer()) {
  2070. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2071. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2072. if (client) {
  2073. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2074. if (packet)
  2075. client->QueuePacket(packet);
  2076. }
  2077. }
  2078. else if (spawn->IsNPC())
  2079. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2080. else
  2081. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2082. }
  2083. }
  2084. else
  2085. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2086. return 0;
  2087. }
  2088. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2089. if (!lua_interface)
  2090. return 0;
  2091. Spawn* spawn = lua_interface->GetSpawn(state);
  2092. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2093. if (spawn && spawn->IsPlayer()) {
  2094. int32 spell_id = 0;
  2095. if (luaspell && luaspell->spell) {
  2096. spell_id = luaspell->spell->GetSpellID();
  2097. ZoneServer* zone = luaspell->caster->GetZone();
  2098. Spawn* target = 0;
  2099. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2100. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2101. target = zone->GetSpawnByID(luaspell->targets[i]);
  2102. if (target) {
  2103. if (target->IsPlayer()) {
  2104. ((Player*)target)->RemoveSkillBonus(spell_id);
  2105. Client* client = target->GetZone()->GetClientBySpawn(target);
  2106. if (client) {
  2107. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2108. if (packet)
  2109. client->QueuePacket(packet);
  2110. }
  2111. }
  2112. else if (target->IsNPC())
  2113. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2114. else
  2115. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2116. }
  2117. }
  2118. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2119. }
  2120. else if (spawn) {
  2121. if (spawn->IsPlayer()) {
  2122. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2123. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2124. if (client) {
  2125. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2126. if (packet)
  2127. client->QueuePacket(packet);
  2128. }
  2129. }
  2130. else if (spawn->IsNPC())
  2131. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2132. else
  2133. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2134. }
  2135. }
  2136. return 0;
  2137. }
  2138. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2139. if (!lua_interface)
  2140. return 0;
  2141. Spawn* spawn = lua_interface->GetSpawn(state);
  2142. int8 type = lua_interface->GetInt32Value(state, 2);
  2143. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2144. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2145. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2146. ZoneServer* zone = luaspell->caster->GetZone();
  2147. Spawn* target = 0;
  2148. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2149. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2150. target = zone->GetSpawnByID(luaspell->targets[i]);
  2151. if (target && target->IsEntity()) {
  2152. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2153. ((Entity*)target)->AddMezSpell(luaspell);
  2154. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2155. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2156. if (target->IsNPC())
  2157. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2158. }
  2159. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2160. ((Entity*)target)->AddStifleSpell(luaspell);
  2161. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2162. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2163. if (target->IsNPC())
  2164. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2165. }
  2166. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2167. ((Entity*)target)->AddDazeSpell(luaspell);
  2168. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2169. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2170. if (target->IsNPC())
  2171. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2172. }
  2173. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2174. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2175. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2176. ((Entity*)target)->AddStunSpell(luaspell);
  2177. if (target->IsNPC())
  2178. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2179. }
  2180. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2181. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2182. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2183. ((Entity*)target)->AddRootSpell(luaspell);
  2184. if (target->IsNPC())
  2185. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2186. }
  2187. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2188. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2189. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2190. ((Entity*)target)->AddFearSpell(luaspell);
  2191. if (target->IsNPC())
  2192. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2193. }
  2194. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2195. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2196. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2197. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2198. }
  2199. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2200. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2201. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2202. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2203. }
  2204. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2205. ((Entity*)target)->AddSnareSpell(luaspell);
  2206. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2207. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2208. if (target->IsNPC())
  2209. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2210. }
  2211. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2212. ((Entity*)target)->AddFlightSpell(luaspell);
  2213. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2214. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2215. }
  2216. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2217. ((Entity*)target)->AddGlideSpell(luaspell);
  2218. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2219. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2220. }
  2221. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2222. ((Entity*)target)->AddSafefallSpell(luaspell);
  2223. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2224. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2225. }
  2226. else
  2227. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2228. }
  2229. else
  2230. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2231. }
  2232. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2233. }
  2234. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2235. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2236. ((Entity*)spawn)->AddMezSpell(luaspell);
  2237. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2238. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2239. }
  2240. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2241. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2242. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2243. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2244. }
  2245. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2246. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2247. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2248. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2249. }
  2250. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2251. ((Entity*)spawn)->AddStunSpell(luaspell);
  2252. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2253. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2254. }
  2255. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2256. ((Entity*)spawn)->AddRootSpell(luaspell);
  2257. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2258. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2259. }
  2260. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2261. ((Entity*)spawn)->AddFearSpell(luaspell);
  2262. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2263. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2264. }
  2265. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2266. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2267. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2268. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2269. }
  2270. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2271. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2272. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2273. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2274. }
  2275. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2276. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2277. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2278. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2279. }
  2280. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2281. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2282. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2283. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2284. }
  2285. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2286. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2287. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2288. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2289. }
  2290. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2291. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2292. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2293. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2294. }
  2295. else
  2296. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2297. }
  2298. else
  2299. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2300. return 0;
  2301. }
  2302. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2303. if (!lua_interface)
  2304. return 0;
  2305. Spawn* spawn = lua_interface->GetSpawn(state);
  2306. int8 type = lua_interface->GetInt8Value(state, 2);
  2307. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2308. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2309. if (spawn && spawn->IsEntity()) {
  2310. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2311. ZoneServer* zone = luaspell->caster->GetZone();
  2312. Spawn* target = 0;
  2313. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2314. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2315. target = zone->GetSpawnByID(luaspell->targets[i]);
  2316. if (target) {
  2317. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2318. ((Entity*)target)->RemoveMezSpell(luaspell);
  2319. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2320. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2321. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2322. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2323. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2324. ((Entity*)target)->RemoveStunSpell(luaspell);
  2325. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2326. ((Entity*)target)->RemoveRootSpell(luaspell);
  2327. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2328. ((Entity*)target)->RemoveFearSpell(luaspell);
  2329. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2330. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2331. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2332. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2333. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2334. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2335. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2336. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2337. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2338. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2339. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2340. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2341. else
  2342. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2343. }
  2344. }
  2345. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2346. }
  2347. else if (only_remove_spawn) {
  2348. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2349. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2350. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2351. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2352. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2353. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2354. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2355. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2356. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2357. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2358. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2359. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2360. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2361. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2362. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2363. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2364. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2365. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2366. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2367. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2368. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2369. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2370. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2371. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2372. else
  2373. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2374. }
  2375. }
  2376. return 0;
  2377. }
  2378. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2379. if (!lua_interface)
  2380. return 0;
  2381. Spawn* spawn = lua_interface->GetSpawn(state);
  2382. int8 type = lua_interface->GetInt8Value(state, 2);
  2383. bool hasEffect = false;
  2384. if (!spawn)
  2385. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2386. else if (!spawn->IsEntity())
  2387. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2388. else if (type < CONTROL_MAX_EFFECTS)
  2389. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2390. else
  2391. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2392. lua_interface->SetBooleanValue(state, hasEffect);
  2393. return 1;
  2394. }
  2395. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2396. if (!lua_interface)
  2397. return 0;
  2398. Spawn* spawn = lua_interface->GetSpawn(state);
  2399. float distance = 0.0f;
  2400. if (!spawn)
  2401. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2402. else if (!spawn->IsNPC())
  2403. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2404. else
  2405. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2406. lua_interface->SetFloatValue(state, distance);
  2407. return 1;
  2408. }
  2409. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2410. if (!lua_interface)
  2411. return 0;
  2412. Spawn* spawn = lua_interface->GetSpawn(state);
  2413. float distance = 0.0f;
  2414. if (!spawn)
  2415. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2416. else if (!spawn->IsNPC())
  2417. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2418. else
  2419. distance = ((NPC*)spawn)->GetAggroRadius();
  2420. lua_interface->SetFloatValue(state, distance);
  2421. return 1;
  2422. }
  2423. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2424. if (!lua_interface)
  2425. return 0;
  2426. Spawn* spawn = lua_interface->GetSpawn(state);
  2427. float distance = lua_interface->GetFloatValue(state, 2);
  2428. bool override = lua_interface->GetBooleanValue(state, 3);
  2429. bool result = false;
  2430. lua_interface->ResetFunctionStack(state);
  2431. if (!spawn)
  2432. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2433. else if (!spawn->IsNPC())
  2434. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2435. else
  2436. {
  2437. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2438. result = true;
  2439. }
  2440. lua_interface->SetBooleanValue(state, result);
  2441. return 1;
  2442. }
  2443. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2444. if (!lua_interface)
  2445. return 0;
  2446. Spawn* spawn = lua_interface->GetSpawn(state);
  2447. int16 value = lua_interface->GetInt16Value(state, 2);
  2448. if (spawn && spawn->IsEntity()) {
  2449. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2450. if (spawn->IsPlayer())
  2451. ((Player*)spawn)->SetCharSheetChanged(true);
  2452. }
  2453. return 0;
  2454. }
  2455. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2456. if (!lua_interface)
  2457. return 0;
  2458. Spawn* spawn = lua_interface->GetSpawn(state);
  2459. int16 value = lua_interface->GetInt16Value(state, 2);
  2460. if (spawn && spawn->IsEntity()) {
  2461. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2462. if (spawn->IsPlayer())
  2463. ((Player*)spawn)->SetCharSheetChanged(true);
  2464. }
  2465. return 0;
  2466. }
  2467. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2468. if (!lua_interface)
  2469. return 0;
  2470. Spawn* spawn = lua_interface->GetSpawn(state);
  2471. int16 value = lua_interface->GetInt16Value(state, 2);
  2472. if (spawn && spawn->IsEntity()) {
  2473. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2474. if (spawn->IsPlayer())
  2475. ((Player*)spawn)->SetCharSheetChanged(true);
  2476. }
  2477. return 0;
  2478. }
  2479. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2480. if (!lua_interface)
  2481. return 0;
  2482. Spawn* spawn = lua_interface->GetSpawn(state);
  2483. int16 value = lua_interface->GetInt16Value(state, 2);
  2484. if (spawn && spawn->IsEntity()) {
  2485. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2486. if (spawn->IsPlayer())
  2487. ((Player*)spawn)->SetCharSheetChanged(true);
  2488. }
  2489. return 0;
  2490. }
  2491. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2492. if (!lua_interface)
  2493. return 0;
  2494. Spawn* spawn = lua_interface->GetSpawn(state);
  2495. int16 value = lua_interface->GetInt16Value(state, 2);
  2496. if (spawn && spawn->IsEntity()) {
  2497. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2498. if (spawn->IsPlayer())
  2499. ((Player*)spawn)->SetCharSheetChanged(true);
  2500. }
  2501. return 0;
  2502. }
  2503. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2504. if (!lua_interface)
  2505. return 0;
  2506. Spawn* spawn = lua_interface->GetSpawn(state);
  2507. int8 value = lua_interface->GetInt8Value(state, 2);
  2508. if (spawn && spawn->IsEntity()) {
  2509. ((Entity*)spawn)->SetDeity(value);
  2510. if (spawn->IsPlayer())
  2511. ((Player*)spawn)->SetCharSheetChanged(true);
  2512. }
  2513. lua_interface->ResetFunctionStack(state);
  2514. return 0;
  2515. }
  2516. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2517. if (!lua_interface)
  2518. return 0;
  2519. Spawn* spawn = lua_interface->GetSpawn(state);
  2520. if (spawn && spawn->IsEntity()) {
  2521. int8 deity = ((Entity*)spawn)->GetDeity();
  2522. lua_interface->SetInt32Value(state, deity);
  2523. return 1;
  2524. }
  2525. return 0;
  2526. }
  2527. int EQ2Emu_lua_SetInt(lua_State* state) {
  2528. if (!lua_interface)
  2529. return 0;
  2530. Spawn* spawn = lua_interface->GetSpawn(state);
  2531. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2532. if (spawn && spawn->IsEntity()) {
  2533. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2534. if (spawn->IsPlayer())
  2535. ((Player*)spawn)->SetCharSheetChanged(true);
  2536. }
  2537. return 0;
  2538. }
  2539. int EQ2Emu_lua_SetWis(lua_State* state) {
  2540. if (!lua_interface)
  2541. return 0;
  2542. Spawn* spawn = lua_interface->GetSpawn(state);
  2543. float value = lua_interface->GetFloatValue(state, 2);
  2544. if (spawn && spawn->IsEntity()) {
  2545. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2546. if (spawn->IsPlayer())
  2547. ((Player*)spawn)->SetCharSheetChanged(true);
  2548. }
  2549. return 0;
  2550. }
  2551. int EQ2Emu_lua_SetSta(lua_State* state) {
  2552. if (!lua_interface)
  2553. return 0;
  2554. Spawn* spawn = lua_interface->GetSpawn(state);
  2555. float value = lua_interface->GetFloatValue(state, 2);
  2556. if (spawn && spawn->IsEntity()) {
  2557. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2558. if (spawn->IsPlayer())
  2559. ((Player*)spawn)->SetCharSheetChanged(true);
  2560. }
  2561. return 0;
  2562. }
  2563. int EQ2Emu_lua_SetStr(lua_State* state) {
  2564. if (!lua_interface)
  2565. return 0;
  2566. Spawn* spawn = lua_interface->GetSpawn(state);
  2567. float value = lua_interface->GetFloatValue(state, 2);
  2568. if (spawn && spawn->IsEntity()) {
  2569. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2570. if (spawn->IsPlayer())
  2571. ((Player*)spawn)->SetCharSheetChanged(true);
  2572. }
  2573. return 0;
  2574. }
  2575. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2576. if (!lua_interface)
  2577. return 0;
  2578. Spawn* spawn = lua_interface->GetSpawn(state);
  2579. float value = lua_interface->GetFloatValue(state, 2);
  2580. if (spawn && spawn->IsEntity()) {
  2581. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2582. if (spawn->IsPlayer())
  2583. ((Player*)spawn)->SetCharSheetChanged(true);
  2584. }
  2585. return 0;
  2586. }
  2587. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2588. if (!lua_interface)
  2589. return 0;
  2590. Spawn* spawn = lua_interface->GetSpawn(state);
  2591. if (spawn) {
  2592. lua_interface->SetInt32Value(state, spawn->GetHP());
  2593. return 1;
  2594. }
  2595. return 0;
  2596. }
  2597. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2598. if (!lua_interface)
  2599. return 0;
  2600. Spawn* spawn = lua_interface->GetSpawn(state);
  2601. if (spawn) {
  2602. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2603. return 1;
  2604. }
  2605. return 0;
  2606. }
  2607. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2608. if (!lua_interface)
  2609. return 0;
  2610. Spawn* spawn = lua_interface->GetSpawn(state);
  2611. if (spawn) {
  2612. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2613. return 1;
  2614. }
  2615. return 0;
  2616. }
  2617. int EQ2Emu_lua_GetName(lua_State* state) {
  2618. if (!lua_interface)
  2619. return 0;
  2620. Spawn* spawn = lua_interface->GetSpawn(state);
  2621. if (spawn) {
  2622. lua_interface->SetStringValue(state, spawn->GetName());
  2623. return 1;
  2624. }
  2625. return 0;
  2626. }
  2627. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2628. Spawn* spawn = lua_interface->GetSpawn(state);
  2629. if (spawn) {
  2630. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2631. return 1;
  2632. }
  2633. return 0;
  2634. }
  2635. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2636. if (!lua_interface)
  2637. return 0;
  2638. Spawn* spawn = lua_interface->GetSpawn(state);
  2639. if (spawn) {
  2640. lua_interface->SetInt32Value(state, spawn->GetPower());
  2641. return 1;
  2642. }
  2643. return 0;
  2644. }
  2645. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2646. if (!lua_interface)
  2647. return 0;
  2648. Spawn* spawn = lua_interface->GetSpawn(state);
  2649. if (spawn) {
  2650. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2651. return 1;
  2652. }
  2653. return 0;
  2654. }
  2655. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2656. if (!lua_interface)
  2657. return 0;
  2658. Spawn* spawn = lua_interface->GetSpawn(state);
  2659. if (spawn) {
  2660. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2661. return 1;
  2662. }
  2663. return 0;
  2664. }
  2665. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2666. if (!lua_interface)
  2667. return 0;
  2668. Spawn* spawn = lua_interface->GetSpawn(state);
  2669. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2670. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2671. if (spawn && spawn2) {
  2672. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2673. lua_interface->SetFloatValue(state, distance);
  2674. return 1;
  2675. }
  2676. return 0;
  2677. }
  2678. int EQ2Emu_lua_GetX(lua_State* state) {
  2679. if (!lua_interface)
  2680. return 0;
  2681. Spawn* spawn = lua_interface->GetSpawn(state);
  2682. if (spawn) {
  2683. lua_interface->SetFloatValue(state, spawn->GetX());
  2684. return 1;
  2685. }
  2686. return 0;
  2687. }
  2688. int EQ2Emu_lua_GetY(lua_State* state) {
  2689. if (!lua_interface)
  2690. return 0;
  2691. Spawn* spawn = lua_interface->GetSpawn(state);
  2692. if (spawn) {
  2693. lua_interface->SetFloatValue(state, spawn->GetY());
  2694. return 1;
  2695. }
  2696. return 0;
  2697. }
  2698. int EQ2Emu_lua_GetZ(lua_State* state) {
  2699. if (!lua_interface)
  2700. return 0;
  2701. Spawn* spawn = lua_interface->GetSpawn(state);
  2702. if (spawn) {
  2703. lua_interface->SetFloatValue(state, spawn->GetZ());
  2704. return 1;
  2705. }
  2706. return 0;
  2707. }
  2708. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2709. if (!lua_interface)
  2710. return 0;
  2711. Spawn* spawn = lua_interface->GetSpawn(state);
  2712. if (spawn) {
  2713. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2714. return 1;
  2715. }
  2716. return 0;
  2717. }
  2718. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2719. if (!lua_interface)
  2720. return 0;
  2721. Spawn* spawn = lua_interface->GetSpawn(state);
  2722. if (spawn) {
  2723. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2724. return 1;
  2725. }
  2726. return 0;
  2727. }
  2728. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2729. if (!lua_interface)
  2730. return 0;
  2731. Spawn* spawn = lua_interface->GetSpawn(state);
  2732. if (spawn) {
  2733. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2734. return 1;
  2735. }
  2736. return 0;
  2737. }
  2738. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2739. if (!lua_interface)
  2740. return 0;
  2741. Spawn* spawn = lua_interface->GetSpawn(state);
  2742. if (spawn && spawn->IsEntity()) {
  2743. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2744. return 1;
  2745. }
  2746. return 0;
  2747. }
  2748. int EQ2Emu_lua_GetInt(lua_State* state) {
  2749. if (!lua_interface)
  2750. return 0;
  2751. Spawn* spawn = lua_interface->GetSpawn(state);
  2752. if (spawn && spawn->IsEntity()) {
  2753. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2754. return 1;
  2755. }
  2756. return 0;
  2757. }
  2758. int EQ2Emu_lua_GetWis(lua_State* state) {
  2759. if (!lua_interface)
  2760. return 0;
  2761. Spawn* spawn = lua_interface->GetSpawn(state);
  2762. if (spawn && spawn->IsEntity()) {
  2763. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2764. return 1;
  2765. }
  2766. return 0;
  2767. }
  2768. int EQ2Emu_lua_GetSta(lua_State* state) {
  2769. if (!lua_interface)
  2770. return 0;
  2771. Spawn* spawn = lua_interface->GetSpawn(state);
  2772. if (spawn && spawn->IsEntity()) {
  2773. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2774. return 1;
  2775. }
  2776. return 0;
  2777. }
  2778. int EQ2Emu_lua_GetStr(lua_State* state) {
  2779. if (!lua_interface)
  2780. return 0;
  2781. Spawn* spawn = lua_interface->GetSpawn(state);
  2782. if (spawn && spawn->IsEntity()) {
  2783. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2784. return 1;
  2785. }
  2786. return 0;
  2787. }
  2788. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2789. if (!lua_interface)
  2790. return 0;
  2791. Spawn* spawn = lua_interface->GetSpawn(state);
  2792. if (spawn && spawn->IsEntity()) {
  2793. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2794. return 1;
  2795. }
  2796. return 0;
  2797. }
  2798. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2799. if (!lua_interface)
  2800. return 0;
  2801. Spawn* spawn = lua_interface->GetSpawn(state);
  2802. if (spawn && spawn->IsEntity()) {
  2803. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2804. return 1;
  2805. }
  2806. return 0;
  2807. }
  2808. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2809. if (!lua_interface)
  2810. return 0;
  2811. Spawn* spawn = lua_interface->GetSpawn(state);
  2812. if (spawn && spawn->IsEntity()) {
  2813. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2814. return 1;
  2815. }
  2816. return 0;
  2817. }
  2818. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2819. if (!lua_interface)
  2820. return 0;
  2821. Spawn* spawn = lua_interface->GetSpawn(state);
  2822. if (spawn && spawn->IsEntity()) {
  2823. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2824. return 1;
  2825. }
  2826. return 0;
  2827. }
  2828. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2829. if (!lua_interface)
  2830. return 0;
  2831. Spawn* spawn = lua_interface->GetSpawn(state);
  2832. if (spawn && spawn->IsEntity()) {
  2833. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2834. return 1;
  2835. }
  2836. return 0;
  2837. }
  2838. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2839. if (!lua_interface)
  2840. return 0;
  2841. Spawn* spawn = lua_interface->GetSpawn(state);
  2842. if (spawn && spawn->IsEntity()) {
  2843. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2844. return 1;
  2845. }
  2846. return 0;
  2847. }
  2848. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2849. if (!lua_interface)
  2850. return 0;
  2851. Spawn* player = lua_interface->GetSpawn(state);
  2852. if (!player || !player->IsPlayer()) {
  2853. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2854. return 0;
  2855. }
  2856. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2857. if (quest_id <= 0) {
  2858. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2859. return 0;
  2860. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2861. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2862. return 0;
  2863. }
  2864. int32 step = lua_interface->GetInt32Value(state, 3);
  2865. if (step > 0) {
  2866. Client* client = player->GetZone()->GetClientBySpawn(player);
  2867. if (client)
  2868. client->AddPendingQuestUpdate(quest_id, step);
  2869. } else {
  2870. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2871. }
  2872. return 0;
  2873. }
  2874. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2875. Spawn* player = lua_interface->GetSpawn(state);
  2876. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2877. int32 step = lua_interface->GetInt32Value(state, 3);
  2878. int32 progress = lua_interface->GetInt32Value(state, 4);
  2879. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2880. Client* client = player->GetZone()->GetClientBySpawn(player);
  2881. if (client)
  2882. client->AddPendingQuestUpdate(quest_id, step, progress);
  2883. }
  2884. return 0;
  2885. }
  2886. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2887. if (!lua_interface)
  2888. return 0;
  2889. Spawn* player = lua_interface->GetSpawn(state);
  2890. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2891. if (player && player->IsPlayer() && quest_id > 0) {
  2892. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2893. return 1;
  2894. }
  2895. return 0;
  2896. }
  2897. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2898. if (!lua_interface)
  2899. return 0;
  2900. Spawn* player = lua_interface->GetSpawn(state);
  2901. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2902. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2903. if (player && player->IsPlayer() && quest_id > 0) {
  2904. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2905. return 1;
  2906. }
  2907. return 0;
  2908. }
  2909. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2910. if (!lua_interface)
  2911. return 0;
  2912. Spawn* player = lua_interface->GetSpawn(state);
  2913. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2914. if (player && player->IsPlayer() && quest_id > 0) {
  2915. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2916. return 1;
  2917. }
  2918. return 0;
  2919. }
  2920. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2921. if (!lua_interface)
  2922. return 0;
  2923. Quest* quest = lua_interface->GetQuest(state);
  2924. string name = lua_interface->GetStringValue(state, 2);
  2925. string type = lua_interface->GetStringValue(state, 3);
  2926. string zone = lua_interface->GetStringValue(state, 4);
  2927. int16 level = lua_interface->GetInt16Value(state, 5);
  2928. string description = lua_interface->GetStringValue(state, 6);
  2929. bool load = true;
  2930. if (!quest) {
  2931. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2932. load = false;
  2933. }
  2934. if (load && name.length() == 0) {
  2935. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2936. load = false;
  2937. }
  2938. if (load && type.length() == 0) {
  2939. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2940. load = false;
  2941. }
  2942. if (load && zone.length() == 0) {
  2943. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2944. load = false;
  2945. }
  2946. if (load && description.length() == 0) {
  2947. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2948. load = false;
  2949. }
  2950. if (load && level == 0) {
  2951. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2952. load = false;
  2953. }
  2954. if (load)
  2955. quest->RegisterQuest(name, type, zone, level, description);
  2956. return 0;
  2957. }
  2958. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2959. if (!lua_interface)
  2960. return 0;
  2961. Quest* quest = lua_interface->GetQuest(state);
  2962. if (quest) {
  2963. int8 level = lua_interface->GetInt16Value(state, 2);
  2964. quest->SetPrereqLevel(level);
  2965. }
  2966. return 0;
  2967. }
  2968. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2969. if (!lua_interface)
  2970. return 0;
  2971. Quest* quest = lua_interface->GetQuest(state);
  2972. if (quest) {
  2973. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2974. quest->AddPrereqQuest(quest_id);
  2975. }
  2976. return 0;
  2977. }
  2978. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2979. if (!lua_interface)
  2980. return 0;
  2981. Quest* quest = lua_interface->GetQuest(state);
  2982. if (quest) {
  2983. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2984. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2985. if (quantity == 0)
  2986. quantity = 1;
  2987. Item* master_item = master_item_list.GetItem(item_id);
  2988. if (master_item) {
  2989. Item* item = new Item(master_item);
  2990. item->details.count = quantity;
  2991. quest->AddPrereqItem(item);
  2992. }
  2993. }
  2994. return 0;
  2995. }
  2996. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2997. if (!lua_interface)
  2998. return 0;
  2999. Spawn* player = lua_interface->GetSpawn(state);
  3000. if(!player || !player->IsPlayer()) {
  3001. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3002. return 0;
  3003. }
  3004. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3005. if (quest_id > 0) {
  3006. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3007. return 1;
  3008. } else {
  3009. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3010. }
  3011. return 0;
  3012. }
  3013. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3014. if (!lua_interface)
  3015. return 0;
  3016. Quest* quest = lua_interface->GetQuest(state);
  3017. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3018. if (quest && spawn_id > 0)
  3019. quest->SetQuestReturnNPC(spawn_id);
  3020. return 0;
  3021. }
  3022. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3023. if (!lua_interface)
  3024. return 0;
  3025. Spawn* spawn = lua_interface->GetSpawn(state);
  3026. if (!spawn) {
  3027. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3028. return 0;
  3029. }
  3030. int32 time = lua_interface->GetInt32Value(state, 2);
  3031. if (time <= 0) {
  3032. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3033. return 0;
  3034. }
  3035. string function = lua_interface->GetStringValue(state, 3);
  3036. if (function.length() == 0) {
  3037. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3038. return 0;
  3039. }
  3040. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3041. Spawn* player = lua_interface->GetSpawn(state, 5);
  3042. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3043. timer->timer = Timer::GetCurrentTime2() + time;
  3044. timer->function = function;
  3045. timer->spawn = spawn->GetID();
  3046. timer->player = player ? player->GetID() : 0;
  3047. if (max_count == 0)
  3048. max_count = 1;
  3049. timer->max_count = max_count;
  3050. timer->current_count = 0;
  3051. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3052. return 0;
  3053. }
  3054. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3055. if (!lua_interface)
  3056. return 0;
  3057. Spawn* player = lua_interface->GetSpawn(state);
  3058. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3059. if (player && player->IsPlayer() && quest_id > 0) {
  3060. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3061. return 1;
  3062. }
  3063. return 0;
  3064. }
  3065. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3066. if (!lua_interface)
  3067. return 0;
  3068. Spawn* player = lua_interface->GetSpawn(state);
  3069. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3070. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3071. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3072. if (quest)
  3073. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3074. return 1;
  3075. }
  3076. return 0;
  3077. }
  3078. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3079. if (!lua_interface)
  3080. return 0;
  3081. Spawn* player = lua_interface->GetSpawn(state);
  3082. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3083. if (player && player->IsPlayer() && quest_id > 0) {
  3084. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3085. return 1;
  3086. }
  3087. return 0;
  3088. }
  3089. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3090. if (!lua_interface)
  3091. return 0;
  3092. Spawn* npc = lua_interface->GetSpawn(state);
  3093. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3094. if (npc && !npc->IsPlayer() && quest_id > 0)
  3095. npc->AddProvidedQuest(quest_id);
  3096. return 0;
  3097. }
  3098. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3099. if (!lua_interface)
  3100. return 0;
  3101. Spawn* npc = lua_interface->GetSpawn(state);
  3102. Spawn* player = lua_interface->GetSpawn(state, 2);
  3103. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3104. bool forced = lua_interface->GetBooleanValue(state, 4);
  3105. /* NPC is allowed to be null */
  3106. if (player && player->IsPlayer() && quest_id > 0) {
  3107. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3108. if (master_quest) {
  3109. Client* client = player->GetZone()->GetClientBySpawn(player);
  3110. if (!client) {
  3111. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3112. }
  3113. Quest* quest = new Quest(master_quest);
  3114. if (!quest) {
  3115. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3116. }
  3117. if (client && quest) {
  3118. if (npc)
  3119. quest->SetQuestGiver(npc->GetDatabaseID());
  3120. else
  3121. quest->SetQuestGiver(0);
  3122. client->AddPendingQuest(quest, forced);
  3123. }
  3124. }
  3125. else {
  3126. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3127. }
  3128. }
  3129. else {
  3130. 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);
  3131. }
  3132. return 0;
  3133. }
  3134. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3135. if (!lua_interface)
  3136. return 0;
  3137. Quest* quest = lua_interface->GetQuest(state);
  3138. if (quest) {
  3139. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3140. quest->AddPrereqClass(class_id);
  3141. }
  3142. return 0;
  3143. }
  3144. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3145. if (!lua_interface)
  3146. return 0;
  3147. Quest* quest = lua_interface->GetQuest(state);
  3148. if (quest) {
  3149. int8 race = lua_interface->GetInt8Value(state, 2);
  3150. quest->AddPrereqRace(race);
  3151. }
  3152. return 0;
  3153. }
  3154. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3155. if (!lua_interface)
  3156. return 0;
  3157. Quest* quest = lua_interface->GetQuest(state);
  3158. if (quest) {
  3159. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3160. quest->AddPrereqModelType(model_type);
  3161. }
  3162. return 0;
  3163. }
  3164. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3165. if (!lua_interface)
  3166. return 0;
  3167. Quest* quest = lua_interface->GetQuest(state);
  3168. if (!quest) {
  3169. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3170. return 0;
  3171. }
  3172. int8 level = lua_interface->GetInt8Value(state, 2);
  3173. quest->SetPrereqTSLevel(level);
  3174. return 0;
  3175. }
  3176. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3177. if (!lua_interface)
  3178. return 0;
  3179. Quest* quest = lua_interface->GetQuest(state);
  3180. if (!quest) {
  3181. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3182. return 0;
  3183. }
  3184. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3185. quest->AddPrereqTradeskillClass(class_id);
  3186. return 0;
  3187. }
  3188. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3189. if (!lua_interface)
  3190. return 0;
  3191. Quest* quest = lua_interface->GetQuest(state);
  3192. if (quest) {
  3193. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3194. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3195. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3196. quest->AddPrereqFaction(faction_id, min, max);
  3197. }
  3198. return 0;
  3199. }
  3200. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3201. if (!lua_interface)
  3202. return 0;
  3203. Quest* quest = lua_interface->GetQuest(state);
  3204. if (quest) {
  3205. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3206. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3207. if (quantity == 0)
  3208. quantity = 1;
  3209. Item* master_item = master_item_list.GetItem(item_id);
  3210. if (master_item) {
  3211. Item* item = new Item(master_item);
  3212. item->details.count = quantity;
  3213. quest->AddSelectableRewardItem(item);
  3214. }
  3215. }
  3216. return 0;
  3217. }
  3218. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3219. if (!lua_interface)
  3220. return 0;
  3221. Quest* quest = lua_interface->GetQuest(state);
  3222. if (quest) {
  3223. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3224. vector<Item*>* items = quest->GetRewardItems();
  3225. if (items) {
  3226. vector<Item*>::iterator itr;
  3227. for (itr = items->begin(); itr != items->end(); itr++) {
  3228. if (*itr && (*itr)->details.item_id == item_id) {
  3229. lua_interface->SetBooleanValue(state, true);
  3230. return 1;
  3231. }
  3232. }
  3233. }
  3234. }
  3235. lua_interface->SetBooleanValue(state, false);
  3236. return 1;
  3237. }
  3238. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3239. if (!lua_interface)
  3240. return 0;
  3241. Quest* quest = lua_interface->GetQuest(state);
  3242. if (quest) {
  3243. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3244. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3245. if (quantity == 0)
  3246. quantity = 1;
  3247. Item* master_item = master_item_list.GetItem(item_id);
  3248. if (master_item) {
  3249. Item* item = new Item(master_item);
  3250. item->details.count = quantity;
  3251. quest->AddRewardItem(item);
  3252. }
  3253. }
  3254. return 0;
  3255. }
  3256. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3257. if (!lua_interface)
  3258. return 0;
  3259. Quest* quest = lua_interface->GetQuest(state);
  3260. if (quest) {
  3261. int32 copper = lua_interface->GetInt32Value(state, 2);
  3262. int32 silver = lua_interface->GetInt32Value(state, 3);
  3263. int32 gold = lua_interface->GetInt32Value(state, 4);
  3264. int32 plat = lua_interface->GetInt32Value(state, 5);
  3265. quest->AddRewardCoins(copper, silver, gold, plat);
  3266. }
  3267. return 0;
  3268. }
  3269. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3270. if (!lua_interface)
  3271. return 0;
  3272. Quest* quest = lua_interface->GetQuest(state);
  3273. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3274. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3275. if (quest && faction_id > 0 && amount != 0)
  3276. quest->AddRewardFaction(faction_id, amount);
  3277. return 0;
  3278. }
  3279. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3280. if (!lua_interface)
  3281. return 0;
  3282. Quest* quest = lua_interface->GetQuest(state);
  3283. if (quest) {
  3284. int32 status = lua_interface->GetInt32Value(state, 2);
  3285. quest->SetRewardStatus(status);
  3286. }
  3287. return 0;
  3288. }
  3289. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3290. if (!lua_interface)
  3291. return 0;
  3292. Quest* quest = lua_interface->GetQuest(state);
  3293. if (quest) {
  3294. string comment = lua_interface->GetStringValue(state, 2);
  3295. quest->SetRewardComment(comment);
  3296. }
  3297. return 0;
  3298. }
  3299. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3300. if (!lua_interface)
  3301. return 0;
  3302. Quest* quest = lua_interface->GetQuest(state);
  3303. if (quest) {
  3304. int32 exp = lua_interface->GetInt32Value(state, 2);
  3305. quest->SetRewardXP(exp);
  3306. }
  3307. return 0;
  3308. }
  3309. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3310. Quest* quest = lua_interface->GetQuest(state);
  3311. if (quest) {
  3312. int32 step = lua_interface->GetInt32Value(state, 2);
  3313. string description = lua_interface->GetStringValue(state, 3);
  3314. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3315. float percentage = lua_interface->GetFloatValue(state, 5);
  3316. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3317. int16 icon = lua_interface->GetInt16Value(state, 7);
  3318. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3319. const char* taskgroup = 0;
  3320. if (str_taskgroup.length() > 0)
  3321. taskgroup = str_taskgroup.c_str();
  3322. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3323. if (quest_step && icon && quantity > 0)
  3324. quest_step->SetIcon(icon);
  3325. }
  3326. return 0;
  3327. }
  3328. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3329. if (!lua_interface)
  3330. return 0;
  3331. Quest* quest = lua_interface->GetQuest(state);
  3332. if (quest) {
  3333. int32 step = lua_interface->GetInt32Value(state, 2);
  3334. string description = lua_interface->GetStringValue(state, 3);
  3335. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3336. float percentage = lua_interface->GetFloatValue(state, 5);
  3337. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3338. int16 icon = lua_interface->GetInt16Value(state, 7);
  3339. const char* taskgroup = 0;
  3340. if (str_taskgroup.length() > 0)
  3341. taskgroup = str_taskgroup.c_str();
  3342. int32 npc_id = 0;
  3343. vector<int32>* ids = 0;
  3344. int i = 0;
  3345. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3346. if (ids == 0)
  3347. ids = new vector<int32>;
  3348. ids->push_back(npc_id);
  3349. i++;
  3350. }
  3351. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3352. if (quest_step && icon > 0 && quantity > 0)
  3353. quest_step->SetIcon(icon);
  3354. if (quest->GetPlayer()) {
  3355. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3356. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3357. }
  3358. }
  3359. return 0;
  3360. }
  3361. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3362. if (!lua_interface)
  3363. return 0;
  3364. Quest* quest = lua_interface->GetQuest(state);
  3365. if (quest) {
  3366. int32 step = lua_interface->GetInt32Value(state, 2);
  3367. string description = lua_interface->GetStringValue(state, 3);
  3368. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3369. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3370. int16 icon = lua_interface->GetInt16Value(state, 6);
  3371. const char* taskgroup = 0;
  3372. if (str_taskgroup.length() > 0)
  3373. taskgroup = str_taskgroup.c_str();
  3374. int32 npc_id = 0;
  3375. vector<int32>* ids = 0;
  3376. int i = 0;
  3377. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3378. if (ids == 0)
  3379. ids = new vector<int32>;
  3380. ids->push_back(npc_id);
  3381. i++;
  3382. }
  3383. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3384. if (quest_step && icon > 0)
  3385. quest_step->SetIcon(icon);
  3386. if (quest->GetPlayer()) {
  3387. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3388. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3389. }
  3390. }
  3391. return 0;
  3392. }
  3393. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3394. if (!lua_interface)
  3395. return 0;
  3396. Quest* quest = lua_interface->GetQuest(state);
  3397. if (quest) {
  3398. int32 step = lua_interface->GetInt32Value(state, 2);
  3399. string description = lua_interface->GetStringValue(state, 3);
  3400. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3401. float percentage = lua_interface->GetFloatValue(state, 5);
  3402. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3403. int16 icon = lua_interface->GetInt16Value(state, 7);
  3404. const char* taskgroup = 0;
  3405. if (str_taskgroup.length() > 0)
  3406. taskgroup = str_taskgroup.c_str();
  3407. int32 item_id = 0;
  3408. vector<int32>* ids = 0;
  3409. int i = 0;
  3410. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3411. if (ids == 0)
  3412. ids = new vector<int32>;
  3413. ids->push_back(item_id);
  3414. i++;
  3415. }
  3416. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3417. if (quest_step && icon > 0 && quantity > 0)
  3418. quest_step->SetIcon(icon);
  3419. if (quest->GetPlayer()) {
  3420. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3421. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3422. }
  3423. }
  3424. return 0;
  3425. }
  3426. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3427. if (!lua_interface)
  3428. return 0;
  3429. Quest* quest = lua_interface->GetQuest(state);
  3430. if (quest) {
  3431. int32 step = lua_interface->GetInt32Value(state, 2);
  3432. string description = lua_interface->GetStringValue(state, 3);
  3433. float max_variation = lua_interface->GetFloatValue(state, 4);
  3434. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3435. int16 icon = lua_interface->GetInt16Value(state, 6);
  3436. const char* taskgroup = 0;
  3437. if (str_taskgroup.length() > 0)
  3438. taskgroup = str_taskgroup.c_str();
  3439. vector<Location>* locations = 0;
  3440. int i = 7;
  3441. while (true) {
  3442. Location loc;
  3443. loc.x = lua_interface->GetFloatValue(state, i);
  3444. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3445. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3446. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3447. break;
  3448. if (locations == 0)
  3449. locations = new vector<Location>;
  3450. locations->push_back(loc);
  3451. i += 3;
  3452. }
  3453. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3454. if (quest_step && icon > 0)
  3455. quest_step->SetIcon(icon);
  3456. if (quest->GetPlayer()) {
  3457. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3458. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3459. }
  3460. }
  3461. return 0;
  3462. }
  3463. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3464. if (!lua_interface)
  3465. return 0;
  3466. Quest* quest = lua_interface->GetQuest(state);
  3467. if (quest) {
  3468. int32 step = lua_interface->GetInt32Value(state, 2);
  3469. string description = lua_interface->GetStringValue(state, 3);
  3470. float max_variation = lua_interface->GetFloatValue(state, 4);
  3471. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3472. int16 icon = lua_interface->GetInt16Value(state, 6);
  3473. const char* taskgroup = 0;
  3474. if (str_taskgroup.length() > 0)
  3475. taskgroup = str_taskgroup.c_str();
  3476. vector<Location>* locations = 0;
  3477. int i = 7;
  3478. while (true) {
  3479. Location loc;
  3480. loc.x = lua_interface->GetFloatValue(state, i);
  3481. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3482. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3483. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3484. break;
  3485. if (locations == 0)
  3486. locations = new vector<Location>;
  3487. locations->push_back(loc);
  3488. i += 3;
  3489. }
  3490. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3491. if (quest_step && icon > 0)
  3492. quest_step->SetIcon(icon);
  3493. if (quest->GetPlayer()) {
  3494. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3495. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3496. }
  3497. }
  3498. return 0;
  3499. }
  3500. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3501. Quest* quest = lua_interface->GetQuest(state);
  3502. if (quest) {
  3503. int32 step = lua_interface->GetInt32Value(state, 2);
  3504. string description = lua_interface->GetStringValue(state, 3);
  3505. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3506. float percentage = lua_interface->GetFloatValue(state, 5);
  3507. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3508. int16 icon = lua_interface->GetInt16Value(state, 7);
  3509. const char* taskgroup = 0;
  3510. if (str_taskgroup.length() > 0)
  3511. taskgroup = str_taskgroup.c_str();
  3512. int32 spell_id = 0;
  3513. vector<int32>* ids = 0;
  3514. int i = 0;
  3515. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3516. if (ids == 0)
  3517. ids = new vector<int32>;
  3518. ids->push_back(spell_id);
  3519. i++;
  3520. }
  3521. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3522. if (quest_step && icon > 0 && quantity > 0)
  3523. quest_step->SetIcon(icon);
  3524. if (quest->GetPlayer()) {
  3525. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3526. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3527. }
  3528. }
  3529. return 0;
  3530. }
  3531. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3532. if (!lua_interface)
  3533. return 0;
  3534. Quest* quest = lua_interface->GetQuest(state);
  3535. if (quest) {
  3536. int32 step = lua_interface->GetInt32Value(state, 2);
  3537. string description = lua_interface->GetStringValue(state, 3);
  3538. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3539. float percentage = lua_interface->GetFloatValue(state, 5);
  3540. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3541. int16 icon = lua_interface->GetInt16Value(state, 7);
  3542. const char* taskgroup = 0;
  3543. if (str_taskgroup.length() > 0)
  3544. taskgroup = str_taskgroup.c_str();
  3545. int32 item_id = 0;
  3546. vector<int32>* ids = 0;
  3547. int i = 0;
  3548. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3549. if (ids == 0)
  3550. ids = new vector<int32>;
  3551. ids->push_back(item_id);
  3552. i++;
  3553. }
  3554. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3555. if (quest_step && icon > 0 && quantity > 0)
  3556. quest_step->SetIcon(icon);
  3557. if (quest->GetPlayer()) {
  3558. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3559. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3560. }
  3561. }
  3562. return 0;
  3563. }
  3564. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3565. if (!lua_interface)
  3566. return 0;
  3567. Quest* quest = lua_interface->GetQuest(state);
  3568. if (quest) {
  3569. int32 step = lua_interface->GetInt32Value(state, 2);
  3570. string description = lua_interface->GetStringValue(state, 3);
  3571. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3572. float percentage = lua_interface->GetFloatValue(state, 5);
  3573. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3574. int16 icon = lua_interface->GetInt16Value(state, 7);
  3575. const char* taskgroup = 0;
  3576. if (str_taskgroup.length() > 0)
  3577. taskgroup = str_taskgroup.c_str();
  3578. int32 item_id = 0;
  3579. vector<int32>* ids = 0;
  3580. int i = 0;
  3581. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3582. if (ids == 0)
  3583. ids = new vector<int32>;
  3584. ids->push_back(item_id);
  3585. i++;
  3586. }
  3587. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3588. if (quest_step && icon > 0 && quantity > 0)
  3589. quest_step->SetIcon(icon);
  3590. if (quest->GetPlayer()) {
  3591. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3592. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3593. }
  3594. }
  3595. return 0;
  3596. }
  3597. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3598. if (!lua_interface)
  3599. return 0;
  3600. Quest* quest = lua_interface->GetQuest(state);
  3601. if (quest) {
  3602. string action = lua_interface->GetStringValue(state, 2);
  3603. if (action.length() > 0)
  3604. quest->SetCompleteAction(action);
  3605. }
  3606. return 0;
  3607. }
  3608. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3609. if (!lua_interface)
  3610. return 0;
  3611. Quest* quest = lua_interface->GetQuest(state);
  3612. if (quest) {
  3613. int32 step = lua_interface->GetInt32Value(state, 2);
  3614. string action = lua_interface->GetStringValue(state, 3);
  3615. if (step > 0 && action.length() > 0)
  3616. quest->AddCompleteAction(step, action);
  3617. }
  3618. return 0;
  3619. }
  3620. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3621. if (!lua_interface)
  3622. return 0;
  3623. Quest* quest = lua_interface->GetQuest(state);
  3624. if (quest) {
  3625. int32 step = lua_interface->GetInt32Value(state, 2);
  3626. string action = lua_interface->GetStringValue(state, 3);
  3627. if (step > 0 && action.length() > 0)
  3628. quest->AddProgressAction(step, action);
  3629. }
  3630. return 0;
  3631. }
  3632. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3633. if (!lua_interface)
  3634. return 0;
  3635. Quest* quest = lua_interface->GetQuest(state);
  3636. string description = lua_interface->GetStringValue(state, 2);
  3637. if (quest && description.length() > 0)
  3638. quest->SetDescription(description);
  3639. return 0;
  3640. }
  3641. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3642. if (!lua_interface)
  3643. return 0;
  3644. Quest* quest = lua_interface->GetQuest(state);
  3645. string description = lua_interface->GetStringValue(state, 2);
  3646. if (quest && description.length() > 0)
  3647. quest->SetCompletedDescription(description);
  3648. return 0;
  3649. }
  3650. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3651. if (!lua_interface)
  3652. return 0;
  3653. Quest* quest = lua_interface->GetQuest(state);
  3654. int32 step = lua_interface->GetInt32Value(state, 2);
  3655. string description = lua_interface->GetStringValue(state, 3);
  3656. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3657. if (quest && step > 0 && description.length() > 0) {
  3658. quest->SetTaskGroupDescription(step, description, display_bullets);
  3659. if (quest->GetPlayer()) {
  3660. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3661. if (client)
  3662. client->SendQuestUpdateStep(quest, step, false);
  3663. }
  3664. }
  3665. return 0;
  3666. }
  3667. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3668. if (!lua_interface)
  3669. return 0;
  3670. Quest* quest = lua_interface->GetQuest(state);
  3671. int32 step = lua_interface->GetInt32Value(state, 2);
  3672. string description = lua_interface->GetStringValue(state, 3);
  3673. if (quest && step > 0 && description.length() > 0) {
  3674. quest->SetStepDescription(step, description);
  3675. if (quest->GetPlayer()) {
  3676. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3677. if (client)
  3678. client->SendQuestUpdateStepImmediately(quest, step);
  3679. }
  3680. }
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3684. Quest* quest = lua_interface->GetQuest(state);
  3685. string zone = lua_interface->GetStringValue(state, 2);
  3686. if (quest && zone.length() > 0)
  3687. quest->SetZone(zone);
  3688. return 0;
  3689. }
  3690. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3691. if (!lua_interface)
  3692. return 0;
  3693. Quest* quest = lua_interface->GetQuest(state);
  3694. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3695. int32 coin = lua_interface->GetInt32Value(state, 3);
  3696. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3697. string rewards_str = lua_interface->GetStringValue(state, 5);
  3698. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3699. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3700. string text = lua_interface->GetStringValue(state, 8);
  3701. if (playerSpawn && playerSpawn->IsPlayer()) {
  3702. Player* player = (Player*)playerSpawn;
  3703. Client* client = player->GetZone()->GetClientBySpawn(player);
  3704. if (client) {
  3705. vector<Item*> reward_items;
  3706. vector<Item*> selectable_reward_items;
  3707. if (rewards_str.length() > 0) {
  3708. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3709. map<unsigned int, unsigned short>::iterator itr;
  3710. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3711. if (itr->first > 0) {
  3712. Item* item = new Item(master_item_list.GetItem(itr->first));
  3713. if (item) {
  3714. if (itr->second > 0)
  3715. item->details.count = itr->second;
  3716. reward_items.push_back(item);
  3717. }
  3718. }
  3719. }
  3720. }
  3721. if (select_rewards_str.length() > 0) {
  3722. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3723. map<unsigned int, unsigned short>::iterator itr;
  3724. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3725. if (itr->first > 0) {
  3726. Item* item = new Item(master_item_list.GetItem(itr->first));
  3727. if (item) {
  3728. if (itr->second > 0)
  3729. item->stack_count = itr->second;
  3730. selectable_reward_items.push_back(item);
  3731. }
  3732. }
  3733. }
  3734. }
  3735. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3736. const char* reward_type = "Quest Reward!";
  3737. if (!quest)
  3738. reward_type = "Reward!";
  3739. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3740. }
  3741. }
  3742. return 0;
  3743. }
  3744. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3745. if (!lua_interface)
  3746. return 0;
  3747. Quest* quest = lua_interface->GetQuest(state);
  3748. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3749. if (quest && spawn) {
  3750. if (spawn->IsPlayer()) {
  3751. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3752. if (client)
  3753. client->AddPendingQuestReward(quest);
  3754. }
  3755. }
  3756. return 0;
  3757. }
  3758. int EQ2Emu_lua_Harvest(lua_State* state) {
  3759. if (!lua_interface)
  3760. return 0;
  3761. Spawn* player = lua_interface->GetSpawn(state);
  3762. Spawn* node = lua_interface->GetSpawn(state, 2);
  3763. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3764. Client* client = player->GetZone()->GetClientBySpawn(player);
  3765. if (client) {
  3766. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3767. ((GroundSpawn*)node)->ProcessHarvest(client);
  3768. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3769. player->GetZone()->RemoveSpawn(node, true);
  3770. }
  3771. }
  3772. else if (player && player->IsPlayer()) {
  3773. Client* client = player->GetZone()->GetClientBySpawn(player);
  3774. if (client)
  3775. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3776. }
  3777. return 0;
  3778. }
  3779. int EQ2Emu_lua_Bind(lua_State* state) {
  3780. if (!lua_interface)
  3781. return 0;
  3782. Spawn* spawn = lua_interface->GetSpawn(state);
  3783. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3784. float x = lua_interface->GetFloatValue(state, 3);
  3785. float y = lua_interface->GetFloatValue(state, 4);
  3786. float z = lua_interface->GetFloatValue(state, 5);
  3787. float h = lua_interface->GetFloatValue(state, 6);
  3788. if (!spawn) {
  3789. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3790. return 0;
  3791. }
  3792. if (!spawn->IsPlayer()) {
  3793. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3794. return 0;
  3795. }
  3796. if (zone_id == 0) {
  3797. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3798. if (!client) {
  3799. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3800. return 0;
  3801. }
  3802. if (!client->Bind())
  3803. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3804. }
  3805. else {
  3806. Player* player = (Player*)spawn;
  3807. player->GetPlayerInfo()->SetBindZone(zone_id);
  3808. player->GetPlayerInfo()->SetBindX(x);
  3809. player->GetPlayerInfo()->SetBindY(y);
  3810. player->GetPlayerInfo()->SetBindZ(z);
  3811. player->GetPlayerInfo()->SetBindHeading(h);
  3812. }
  3813. return 0;
  3814. }
  3815. int EQ2Emu_lua_Gate(lua_State* state) {
  3816. if (!lua_interface)
  3817. return 0;
  3818. Spawn* spawn = lua_interface->GetSpawn(state);
  3819. if (spawn) {
  3820. if (spawn->IsPlayer()) {
  3821. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3822. if (client) {
  3823. if (!client->Gate())
  3824. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3825. }
  3826. }
  3827. }
  3828. return 0;
  3829. }
  3830. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3831. if (!lua_interface)
  3832. return 0;
  3833. bool ret = false;
  3834. Spawn* spawn = lua_interface->GetSpawn(state);
  3835. if (spawn) {
  3836. if (spawn->IsPlayer()) {
  3837. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3838. if (client)
  3839. ret = client->BindAllowed();
  3840. }
  3841. }
  3842. lua_interface->SetBooleanValue(state, ret);
  3843. return 1;
  3844. }
  3845. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3846. if (!lua_interface)
  3847. return 0;
  3848. bool ret = false;
  3849. Spawn* spawn = lua_interface->GetSpawn(state);
  3850. if (spawn) {
  3851. if (spawn->IsPlayer()) {
  3852. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3853. if (client)
  3854. ret = client->GateAllowed();
  3855. }
  3856. }
  3857. lua_interface->SetBooleanValue(state, ret);
  3858. return 1;
  3859. }
  3860. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3861. Spawn* spawn = lua_interface->GetSpawn(state);
  3862. if (spawn) {
  3863. lua_interface->SetBooleanValue(state, spawn->Alive());
  3864. return 1;
  3865. }
  3866. return 0;
  3867. }
  3868. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3869. if (!lua_interface)
  3870. return 0;
  3871. Spawn* spawn = lua_interface->GetSpawn(state);
  3872. if (spawn && spawn->IsEntity()) {
  3873. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3874. return 1;
  3875. }
  3876. return 0;
  3877. }
  3878. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3879. Spawn* spawn = lua_interface->GetSpawn(state);
  3880. string message = lua_interface->GetStringValue(state, 2);
  3881. string color_str = lua_interface->GetStringValue(state, 3);
  3882. int8 color = CHANNEL_NARRATIVE;
  3883. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3884. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3885. if (client) {
  3886. if (color_str.length() > 0) {
  3887. // leave for backwards compat, but all future should just use the number
  3888. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3889. color = CHANNEL_COLOR_RED;
  3890. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3891. color = CHANNEL_COLOR_YELLOW;
  3892. else
  3893. {
  3894. // use a number to specify the channel as per Commands/Commands.h defines
  3895. color = (int8)atoul(color_str.c_str());
  3896. }
  3897. }
  3898. client->SimpleMessage(color, message.c_str());
  3899. }
  3900. }
  3901. return 0;
  3902. }
  3903. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3904. Spawn* spawn = lua_interface->GetSpawn(state);
  3905. string message = lua_interface->GetStringValue(state, 2);
  3906. int8 red = lua_interface->GetInt8Value(state, 3);
  3907. int8 green = lua_interface->GetInt8Value(state, 4);
  3908. int8 blue = lua_interface->GetInt8Value(state, 5);
  3909. if (!spawn) {
  3910. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3911. return 0;
  3912. }
  3913. int32 words = ::CountWordsInString(message.c_str());
  3914. if (words < 5)
  3915. words = 5;
  3916. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3917. if (client)
  3918. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3919. return 0;
  3920. }
  3921. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3922. Spawn* spawn = lua_interface->GetSpawn(state);
  3923. int8 param = lua_interface->GetInt8Value(state, 2);
  3924. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3925. int8 value = lua_interface->GetInt8Value(state, 4);
  3926. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3927. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3928. if (client) {
  3929. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3930. switch (param) {
  3931. case 1: {
  3932. packet->setDataByName("parameter1", param_value);
  3933. break;
  3934. }
  3935. case 2: {
  3936. packet->setDataByName("parameter2", param_value);
  3937. break;
  3938. }
  3939. case 3: {
  3940. packet->setDataByName("parameter3", param_value);
  3941. break;
  3942. }
  3943. case 4: {
  3944. packet->setDataByName("parameter4", param_value);
  3945. break;
  3946. }
  3947. case 5: {
  3948. packet->setDataByName("parameter5", param_value);
  3949. break;
  3950. }
  3951. }
  3952. packet->setDataByName("value", value);
  3953. client->QueuePacket(packet->serialize());
  3954. safe_delete(packet);
  3955. }
  3956. }
  3957. return 0;
  3958. }
  3959. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3960. Spawn* spawn = lua_interface->GetSpawn(state);
  3961. if (spawn && spawn->IsPlayer()) {
  3962. if (((Player*)spawn)->GetIsTracking())
  3963. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3964. else
  3965. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3966. }
  3967. return 0;
  3968. }
  3969. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3970. Spawn* player = lua_interface->GetSpawn(state);
  3971. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3972. string name = lua_interface->GetStringValue(state, 3);
  3973. float distance = lua_interface->GetFloatValue(state, 4);
  3974. string command = lua_interface->GetStringValue(state, 5);
  3975. string error_text = lua_interface->GetStringValue(state, 6);
  3976. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3977. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3978. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3979. if (spawn) {
  3980. if (distance == 0)
  3981. distance = 10.0f;
  3982. if (command.length() == 0)
  3983. command = name;
  3984. if (command.length() < 1 && name.length() < 1)
  3985. {
  3986. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3987. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3988. spawn->RemovePrimaryCommands();
  3989. }
  3990. else
  3991. {
  3992. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3993. }
  3994. }
  3995. return 0;
  3996. }
  3997. int EQ2Emu_lua_HasSpell(lua_State* state) {
  3998. if (!lua_interface)
  3999. return 0;
  4000. Spawn* player = lua_interface->GetSpawn(state);
  4001. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4002. int16 tier = lua_interface->GetInt16Value(state, 3);
  4003. if (player && player->IsPlayer()) {
  4004. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4005. return 1;
  4006. }
  4007. return 0;
  4008. }
  4009. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4010. if (!lua_interface)
  4011. return 0;
  4012. Spawn* player = lua_interface->GetSpawn(state);
  4013. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4014. int16 tier = lua_interface->GetInt16Value(state, 3);
  4015. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4016. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4017. bool add_to_hotbar = true;
  4018. if (num_args > 4) {
  4019. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4020. }
  4021. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4022. if (player && spell && player->IsPlayer()) {
  4023. Client* client = player->GetClient();
  4024. if (client) {
  4025. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4026. {
  4027. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4028. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4029. client->GetPlayer()->UnlockSpell(spell);
  4030. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4031. }
  4032. else
  4033. {
  4034. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4035. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4036. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4037. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4038. client->GetPlayer()->UnlockSpell(spell);
  4039. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4040. }
  4041. //if (client ) {
  4042. // ((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);
  4043. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4044. if (outapp)
  4045. client->QueuePacket(outapp);
  4046. }
  4047. }
  4048. return 0;
  4049. }
  4050. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4051. if (!lua_interface)
  4052. return 0;
  4053. Spawn* player = lua_interface->GetSpawn(state);
  4054. if (player && player->IsPlayer()) {
  4055. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4056. return 1;
  4057. }
  4058. return 0;
  4059. }
  4060. int EQ2Emu_lua_Attack(lua_State* state) {
  4061. if (lua_interface) {
  4062. Spawn* npc = lua_interface->GetSpawn(state);
  4063. Spawn* player = lua_interface->GetSpawn(state, 2);
  4064. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4065. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4066. }
  4067. return 0;
  4068. }
  4069. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4070. if (lua_interface) {
  4071. Spawn* target = lua_interface->GetSpawn(state);
  4072. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4073. if (target && target->GetZone())
  4074. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4075. }
  4076. return 0;
  4077. }
  4078. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4079. Spawn* player;
  4080. if (lua_interface) {
  4081. player = lua_interface->GetSpawn(state);
  4082. if (player && player->IsPlayer()) {
  4083. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4084. return 1;
  4085. }
  4086. }
  4087. return 0;
  4088. }
  4089. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4090. Spawn* player;
  4091. Client* client;
  4092. if (lua_interface) {
  4093. player = lua_interface->GetSpawn(state);
  4094. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4095. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4096. client->HandInCollections();
  4097. }
  4098. return 0;
  4099. }
  4100. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4101. Spawn* widget;
  4102. if (lua_interface) {
  4103. widget = lua_interface->GetSpawn(state);
  4104. if (widget && widget->IsWidget())
  4105. ((Widget*)widget)->HandleUse(nullptr, "");
  4106. }
  4107. return 0;
  4108. }
  4109. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4110. Spawn* spawn = 0;
  4111. int32 primary_list = 0;
  4112. int32 secondary_list = 0;
  4113. if (lua_interface) {
  4114. spawn = lua_interface->GetSpawn(state);
  4115. primary_list = lua_interface->GetInt32Value(state, 2);
  4116. secondary_list = lua_interface->GetInt32Value(state, 3);
  4117. if (!spawn->IsNPC()) {
  4118. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4119. return 0;
  4120. }
  4121. NPC* npc = (NPC*)spawn;
  4122. npc->SetPrimarySpellList(primary_list);
  4123. npc->SetSecondarySpellList(secondary_list);
  4124. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4125. }
  4126. return 0;
  4127. }
  4128. int EQ2Emu_lua_GetPet(lua_State* state) {
  4129. if (!lua_interface)
  4130. return 0;
  4131. Spawn* spawn = lua_interface->GetSpawn(state);
  4132. if (spawn) {
  4133. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4134. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4135. return 1;
  4136. }
  4137. }
  4138. return 0;
  4139. }
  4140. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4141. if (!lua_interface)
  4142. return 0;
  4143. Spawn* spawn = lua_interface->GetSpawn(state);
  4144. if (spawn) {
  4145. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4146. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4147. return 1;
  4148. }
  4149. }
  4150. return 0;
  4151. }
  4152. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4153. if (!lua_interface)
  4154. return 0;
  4155. Spawn* spawn = lua_interface->GetSpawn(state);
  4156. if (spawn) {
  4157. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4158. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4159. return 1;
  4160. }
  4161. }
  4162. return 0;
  4163. }
  4164. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4165. if (!lua_interface)
  4166. return 0;
  4167. Spawn* spawn = lua_interface->GetSpawn(state);
  4168. if (spawn) {
  4169. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4170. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4171. return 1;
  4172. }
  4173. }
  4174. return 0;
  4175. }
  4176. int EQ2Emu_lua_Charm(lua_State* state) {
  4177. if (!lua_interface)
  4178. return 0;
  4179. Spawn* owner = lua_interface->GetSpawn(state);
  4180. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4181. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4182. if (!luaspell) {
  4183. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4184. return 0;
  4185. }
  4186. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4187. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4188. pet->SetPet(true);
  4189. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4190. ((NPC*)pet)->SetOwner((Entity*)owner);
  4191. // If owner is player and player does not have a summoned pet set the players charsheet
  4192. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4193. Player* player = (Player*)owner;
  4194. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4195. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4196. player->GetInfoStruct()->set_pet_movement(2);
  4197. player->GetInfoStruct()->set_pet_behavior(3);
  4198. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4199. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4200. // Make sure the values get sent to the client
  4201. player->SetCharSheetChanged(true);
  4202. }
  4203. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4204. pet->SetSpawnScript("");
  4205. // Set faction to the same as the owner
  4206. pet->SetFactionID(owner->GetFactionID());
  4207. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4208. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4209. // Clear hate list
  4210. ((NPC*)pet)->Brain()->ClearHate();
  4211. // Set the brain to a pet brain
  4212. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4213. }
  4214. return 0;
  4215. }
  4216. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4217. if (!lua_interface)
  4218. return 0;
  4219. Spawn* spawn = lua_interface->GetSpawn(state);
  4220. if (!spawn) {
  4221. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4222. return 0;
  4223. }
  4224. vector<Spawn*> groupMembers;
  4225. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4226. groupMembers = *spawn->GetSpawnGroup();
  4227. }
  4228. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4229. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4230. deque<GroupMemberInfo*>::iterator itr;
  4231. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4232. if (group)
  4233. {
  4234. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4235. deque<GroupMemberInfo*>* members = group->GetMembers();
  4236. GroupMemberInfo* info = 0;
  4237. for (itr = members->begin(); itr != members->end(); itr++) {
  4238. info = *itr;
  4239. if (info->client)
  4240. groupMembers.push_back(info->client->GetPlayer());
  4241. }
  4242. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4243. }
  4244. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4245. }
  4246. else
  4247. return 0;
  4248. lua_createtable(state, groupMembers.size(), 0);
  4249. int newTable = lua_gettop(state);
  4250. for (int32 i = 0; i < groupMembers.size(); i++) {
  4251. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4252. lua_rawseti(state, newTable, i + 1);
  4253. }
  4254. return 1;
  4255. }
  4256. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4257. if (!lua_interface)
  4258. return 0;
  4259. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4260. lua_interface->SetOptionWindowValue(state, option_window);
  4261. return 1;
  4262. }
  4263. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4264. if (!lua_interface)
  4265. return 0;
  4266. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4267. if (option_window) {
  4268. OptionWindowOption option_window_option;
  4269. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4270. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4271. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4272. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4273. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4274. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4275. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4276. option_window->push_back(option_window_option);
  4277. }
  4278. return 0;
  4279. }
  4280. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4281. if (!lua_interface)
  4282. return 0;
  4283. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4284. Spawn* player = lua_interface->GetSpawn(state, 2);
  4285. string window_title = lua_interface->GetStringValue(state, 3);
  4286. string cancel_command = lua_interface->GetStringValue(state, 4);
  4287. Client* client = player->GetZone()->GetClientBySpawn(player);
  4288. if (option_window && window_title.length() > 0 && client) {
  4289. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4290. if (!packet)
  4291. return 0;
  4292. packet->setDataByName("title_text", window_title.c_str());
  4293. if (cancel_command.length() > 0)
  4294. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4295. packet->setArrayLengthByName("num_selections", option_window->size());
  4296. vector<OptionWindowOption>::iterator itr;
  4297. int8 i = 0;
  4298. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4299. OptionWindowOption opt = *itr;
  4300. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4301. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4302. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4303. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4304. if (opt.optionCommand.length() > 0)
  4305. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4306. if (opt.optionConfirmTitle.length() > 0)
  4307. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4308. i++;
  4309. }
  4310. client->QueuePacket(packet->serialize());
  4311. safe_delete(option_window);
  4312. safe_delete(packet);
  4313. }
  4314. return 0;
  4315. }
  4316. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4317. if (!lua_interface)
  4318. return 0;
  4319. Spawn* spawn = lua_interface->GetSpawn(state);
  4320. if (spawn) {
  4321. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4322. return 1;
  4323. }
  4324. else
  4325. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4326. return 0;
  4327. }
  4328. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4329. if (!lua_interface)
  4330. return 0;
  4331. Spawn* spawn = lua_interface->GetSpawn(state);
  4332. if (spawn) {
  4333. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4334. return 1;
  4335. }
  4336. else
  4337. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4338. return 0;
  4339. }
  4340. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4341. if (!lua_interface)
  4342. return 0;
  4343. Spawn* spawn = lua_interface->GetSpawn(state);
  4344. if (spawn) {
  4345. int8 class_id = spawn->GetTradeskillClass();
  4346. // Need to add 42 for the offset in the array
  4347. class_id += 44;
  4348. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4349. return 1;
  4350. }
  4351. else
  4352. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4353. return 0;
  4354. }
  4355. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4356. if (!lua_interface)
  4357. return 0;
  4358. Spawn* spawn = lua_interface->GetSpawn(state);
  4359. int16 level = lua_interface->GetInt8Value(state, 2);
  4360. if (spawn) {
  4361. if (spawn->IsPlayer())
  4362. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4363. else
  4364. spawn->SetTSLevel(level);
  4365. }
  4366. else
  4367. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4368. return 0;
  4369. }
  4370. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4371. if (!lua_interface)
  4372. return 0;
  4373. Spawn* spawn = lua_interface->GetSpawn(state);
  4374. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4375. if (spawn) {
  4376. spawn->SetAttackable(attackable);
  4377. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4378. }
  4379. return 0;
  4380. }
  4381. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4382. // Check to see if we have a valid lua_interface
  4383. if (!lua_interface)
  4384. return 0;
  4385. // Get the spawn that is getting the pet
  4386. Spawn* spawn = lua_interface->GetSpawn(state);
  4387. // Get the DB ID of the pet
  4388. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4389. // The max level the pet can gain
  4390. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4391. // Get the spell that this command was called from
  4392. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4393. // Check to make sure the spawn pointer is valid
  4394. if (!spawn) {
  4395. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4396. return 0;
  4397. }
  4398. // Check to make sure the spawn is an entity
  4399. if (!spawn->IsEntity()) {
  4400. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4401. return 0;
  4402. }
  4403. // Check to make sure the spawn doesn't already have a pet of this type
  4404. if (((Entity*)spawn)->GetPet()) {
  4405. if (spawn->IsPlayer()) {
  4406. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4407. if (client)
  4408. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4409. }
  4410. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4411. return 0;
  4412. }
  4413. // Check to see if the DB ID for the pet is set
  4414. if (pet_id == 0) {
  4415. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4416. return 0;
  4417. }
  4418. // Check to see if the pointer to the spell is valid
  4419. if (!luaspell) {
  4420. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4421. return 0;
  4422. }
  4423. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4424. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4425. if (!pet) {
  4426. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4427. return 0;
  4428. }
  4429. // Check to make sure the pet is an npc
  4430. if (!pet->IsNPC()) {
  4431. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4432. return 0;
  4433. }
  4434. // Spawn the pet at the same location as the owner
  4435. pet->SetX(spawn->GetX());
  4436. pet->SetY(spawn->GetY());
  4437. pet->SetZ(spawn->GetZ());
  4438. pet->SetLocation(spawn->GetLocation());
  4439. pet->SetHeading(spawn->GetHeading());
  4440. spawn->GetZone()->AddSpawn(pet);
  4441. /*
  4442. const char* spawn_script = world.GetSpawnScript(pet_id);
  4443. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4444. spawn->SetSpawnScript(string(spawn_script));
  4445. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4446. }*/
  4447. // Get a random pet name
  4448. string random_pet_name;
  4449. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4450. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4451. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4452. // If player set various values for the char sheet (pet window)
  4453. if (spawn->IsPlayer()) {
  4454. Player* player = (Player*)spawn;
  4455. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4456. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4457. player->GetInfoStruct()->set_pet_movement(2);
  4458. player->GetInfoStruct()->set_pet_behavior(3);
  4459. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4460. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4461. // Make sure the values get sent to the client
  4462. player->SetCharSheetChanged(true);
  4463. }
  4464. // Set the pets name
  4465. pet->SetName(random_pet_name.c_str());
  4466. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4467. if (max_level > 0)
  4468. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4469. else
  4470. pet->SetLevel(spawn->GetLevel());
  4471. // Set the max level this pet can reach
  4472. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4473. // Set the faction of the pet to the same faction as the owner
  4474. pet->SetFactionID(spawn->GetFactionID());
  4475. // Set the spawn as a pet
  4476. pet->SetPet(true);
  4477. // Give a pointer of the owner to the pet
  4478. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4479. // Give a pointer of the pet to the owner
  4480. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4481. // Set the pet type
  4482. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4483. // Set the spell id used to create this pet
  4484. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4485. // Set the spell tier used to create this pet
  4486. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4487. // Set the pets spawn type to 6
  4488. pet->SetSpawnType(6);
  4489. // Set the pets brain
  4490. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4491. // Check to see if the pet has a subtitle
  4492. if (strlen(pet->GetSubTitle()) > 0) {
  4493. // Add the players name to the front of the sub title
  4494. string pet_subtitle;
  4495. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4496. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4497. // Set the pets subtitle to the new one
  4498. pet->SetSubTitle(pet_subtitle.c_str());
  4499. }
  4500. // Add the "Pet Options" entity command to the pet
  4501. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4502. // Set the pet as the return value for this function
  4503. lua_interface->SetSpawnValue(state, pet);
  4504. return 1;
  4505. }
  4506. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4507. if (!lua_interface)
  4508. return 0;
  4509. Spawn* spawn = lua_interface->GetSpawn(state);
  4510. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4511. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4512. if (!spawn) {
  4513. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4514. return 0;
  4515. }
  4516. if (!spawn->IsEntity()) {
  4517. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4518. return 0;
  4519. }
  4520. if (((Entity*)spawn)->GetDeityPet()) {
  4521. if (spawn->IsPlayer()) {
  4522. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4523. if (client)
  4524. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4525. }
  4526. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4527. return 0;
  4528. }
  4529. if (pet_id == 0) {
  4530. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4531. return 0;
  4532. }
  4533. if (!luaspell) {
  4534. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4535. return 0;
  4536. }
  4537. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4538. if (!pet) {
  4539. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4540. return 0;
  4541. }
  4542. if (!pet->IsNPC()) {
  4543. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4544. return 0;
  4545. }
  4546. pet->SetX(spawn->GetX());
  4547. pet->SetY(spawn->GetY());
  4548. pet->SetZ(spawn->GetZ());
  4549. pet->SetLocation(spawn->GetLocation());
  4550. pet->SetHeading(spawn->GetHeading());
  4551. spawn->GetZone()->AddSpawn(pet);
  4552. string random_pet_name;
  4553. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4554. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4555. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4556. pet->SetName(random_pet_name.c_str());
  4557. pet->SetLevel(spawn->GetLevel());
  4558. pet->SetFactionID(spawn->GetFactionID());
  4559. pet->SetPet(true);
  4560. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4561. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4562. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4563. pet->SetSpawnType(6);
  4564. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4565. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4566. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4567. if (strlen(pet->GetSubTitle()) > 0) {
  4568. string pet_subtitle;
  4569. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4570. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4571. pet->SetSubTitle(pet_subtitle.c_str());
  4572. }
  4573. // deity and cosmetic pets are not attackable
  4574. pet->SetAttackable(false);
  4575. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4576. lua_interface->SetSpawnValue(state, pet);
  4577. return 1;
  4578. }
  4579. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4580. if (!lua_interface)
  4581. return 0;
  4582. Spawn* spawn = lua_interface->GetSpawn(state);
  4583. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4584. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4585. if (!spawn) {
  4586. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4587. return 0;
  4588. }
  4589. if (!spawn->IsEntity()) {
  4590. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4591. return 0;
  4592. }
  4593. if (((Entity*)spawn)->GetCosmeticPet()) {
  4594. if (spawn->IsPlayer()) {
  4595. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4596. if (client)
  4597. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4598. }
  4599. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4600. return 0;
  4601. }
  4602. if (pet_id == 0) {
  4603. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4604. return 0;
  4605. }
  4606. if (!luaspell) {
  4607. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4608. return 0;
  4609. }
  4610. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4611. if (!pet) {
  4612. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4613. return 0;
  4614. }
  4615. if (!pet->IsNPC()) {
  4616. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4617. return 0;
  4618. }
  4619. pet->SetX(spawn->GetX());
  4620. pet->SetY(spawn->GetY());
  4621. pet->SetZ(spawn->GetZ());
  4622. pet->SetLocation(spawn->GetLocation());
  4623. pet->SetHeading(spawn->GetHeading());
  4624. spawn->GetZone()->AddSpawn(pet);
  4625. string random_pet_name;
  4626. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4627. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4628. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4629. pet->SetName(random_pet_name.c_str());
  4630. pet->SetLevel(spawn->GetLevel());
  4631. pet->SetFactionID(spawn->GetFactionID());
  4632. pet->SetPet(true);
  4633. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4634. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4635. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4636. pet->SetSpawnType(6);
  4637. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4638. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4639. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4640. if (strlen(pet->GetSubTitle()) > 0) {
  4641. string pet_subtitle;
  4642. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4643. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4644. pet->SetSubTitle(pet_subtitle.c_str());
  4645. }
  4646. pet->SetAttackable(false);
  4647. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4648. lua_interface->SetSpawnValue(state, pet);
  4649. return 1;
  4650. }
  4651. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4652. if (!lua_interface)
  4653. return 0;
  4654. Spawn* spawn = lua_interface->GetSpawn(state);
  4655. if (!spawn) {
  4656. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4657. return 0;
  4658. }
  4659. if (!spawn->IsPet()) {
  4660. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4661. return 0;
  4662. }
  4663. if (!((NPC*)spawn)->IsDismissing())
  4664. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4665. return 0;
  4666. }
  4667. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4668. if (!lua_interface)
  4669. return 0;
  4670. Quest* quest = lua_interface->GetQuest(state);
  4671. if (!quest) {
  4672. 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));
  4673. return 0;
  4674. }
  4675. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4676. if (feather_color > 0)
  4677. quest->SetFeatherColor(feather_color);
  4678. return 0;
  4679. }
  4680. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4681. if (!lua_interface)
  4682. return 0;
  4683. Spawn* spawn = lua_interface->GetSpawn(state);
  4684. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4685. if (!spawn) {
  4686. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4687. return 0;
  4688. }
  4689. if (!spawn2) {
  4690. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4691. return 0;
  4692. }
  4693. spawn->RemoveSpawnAccess(spawn2);
  4694. return 0;
  4695. }
  4696. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4697. if (!lua_interface)
  4698. return 0;
  4699. ZoneServer* zone = lua_interface->GetZone(state);
  4700. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4701. if (!zone) {
  4702. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4703. return 0;
  4704. }
  4705. if (location_id == 0) {
  4706. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4707. return 0;
  4708. }
  4709. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4710. if (!location) {
  4711. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4712. return 0;
  4713. }
  4714. Spawn* spawn = 0;
  4715. if (location->entities[0]) {
  4716. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4717. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4718. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4719. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4720. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4721. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4722. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4723. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4724. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4725. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4726. if (spawn) {
  4727. const char* script = 0;
  4728. for (int x = 0; x < 3; x++) {
  4729. switch (x) {
  4730. case 0:
  4731. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4732. break;
  4733. case 1:
  4734. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4735. break;
  4736. case 2:
  4737. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4738. break;
  4739. }
  4740. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4741. spawn->SetSpawnScript(string(script));
  4742. break;
  4743. }
  4744. }
  4745. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4746. lua_interface->SetSpawnValue(state, spawn);
  4747. return 1;
  4748. }
  4749. else {
  4750. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4751. safe_delete(spawn);
  4752. }
  4753. }
  4754. return 0;
  4755. }
  4756. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4757. if (!lua_interface)
  4758. return 0;
  4759. Spawn* caster = lua_interface->GetSpawn(state);
  4760. Spawn* target = lua_interface->GetSpawn(state, 2);
  4761. int32 id = lua_interface->GetInt32Value(state, 3);
  4762. string command = lua_interface->GetStringValue(state, 4);
  4763. if (!caster) {
  4764. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4765. return 0;
  4766. }
  4767. if (!target) {
  4768. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4769. return 0;
  4770. }
  4771. if (!caster->IsPlayer()) {
  4772. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4773. return 0;
  4774. }
  4775. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4776. if (!entity_command) {
  4777. 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());
  4778. return 0;
  4779. }
  4780. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4781. if (!client) {
  4782. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4783. return 0;
  4784. }
  4785. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4786. return 0;
  4787. }
  4788. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4789. if (!lua_interface)
  4790. return 0;
  4791. Spawn* spawn = lua_interface->GetSpawn(state);
  4792. if (!spawn) {
  4793. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4794. return 0;
  4795. }
  4796. if (!spawn->IsNPC()) {
  4797. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4798. return 0;
  4799. }
  4800. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4801. return 0;
  4802. }
  4803. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4804. if (!lua_interface)
  4805. return 0;
  4806. Spawn* spawn = lua_interface->GetSpawn(state);
  4807. int16 tick = lua_interface->GetInt16Value(state, 2);
  4808. if (!spawn) {
  4809. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4810. return 0;
  4811. }
  4812. if (!spawn->IsNPC()) {
  4813. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4814. return 0;
  4815. }
  4816. if (tick < 20) {
  4817. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4818. return 0;
  4819. }
  4820. ((NPC*)spawn)->Brain()->SetTick(tick);
  4821. return 0;
  4822. }
  4823. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4824. if (!lua_interface)
  4825. return 0;
  4826. Spawn* spawn = lua_interface->GetSpawn(state);
  4827. Spawn* target = lua_interface->GetSpawn(state, 2);
  4828. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4829. if (!spawn) {
  4830. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4831. return 0;
  4832. }
  4833. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4834. spawn->SetFollowTarget(target, follow_distance);
  4835. return 0;
  4836. }
  4837. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4838. if (!lua_interface)
  4839. return 0;
  4840. Spawn* spawn = lua_interface->GetSpawn(state);
  4841. if (!spawn) {
  4842. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4843. return 0;
  4844. }
  4845. Spawn* target = spawn->GetFollowTarget();
  4846. if (target) {
  4847. lua_interface->SetSpawnValue(state, target);
  4848. return 1;
  4849. }
  4850. return 0;
  4851. }
  4852. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4853. if (!lua_interface)
  4854. return 0;
  4855. Spawn* spawn = lua_interface->GetSpawn(state);
  4856. if (!spawn) {
  4857. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4858. return 0;
  4859. }
  4860. if (spawn->following)
  4861. spawn->following = false;
  4862. else
  4863. spawn->following = true;
  4864. return 0;
  4865. }
  4866. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4867. if (!lua_interface)
  4868. return 0;
  4869. Spawn* spawn = lua_interface->GetSpawn(state);
  4870. if (!spawn) {
  4871. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4872. return 0;
  4873. }
  4874. lua_interface->SetBooleanValue(state, spawn->following);
  4875. return 1;
  4876. }
  4877. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4878. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4879. // I will attempt to explain how this function works for future refrence
  4880. // Fist lets make sure lua_interface is valid, if not return out
  4881. if (!lua_interface)
  4882. return 0;
  4883. // Next we grab the first 2 params same as we usually would
  4884. Spawn* spawn = lua_interface->GetSpawn(state);
  4885. string var = lua_interface->GetStringValue(state, 2);
  4886. // 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
  4887. // 1 = Spawn
  4888. // 2 = Zone
  4889. // 3 = Item
  4890. // 4 = Quest
  4891. // 5 = String
  4892. // 6 = nil (null)
  4893. int8 dataType = 0;
  4894. // Define pointers for each potential type
  4895. Spawn* spawnVal = 0;
  4896. ZoneServer* zone = 0;
  4897. Item* item = 0;
  4898. Quest* quest = 0;
  4899. string val;
  4900. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4901. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4902. // options window are also light user data be we do not handle those.
  4903. // We check with lua_islightuserdata(lua_State*, index)
  4904. if (lua_islightuserdata(state, 3)) {
  4905. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4906. // and convert it to LUAUserData*
  4907. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4908. // Check to make sure the data we got is valid, if not give an error
  4909. if (!data || !data->IsCorrectlyInitialized()) {
  4910. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4911. }
  4912. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4913. else if (data->IsSpawn()) {
  4914. spawnVal = data->spawn;
  4915. dataType = 1;
  4916. }
  4917. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4918. else if (data->IsZone()) {
  4919. zone = data->zone;
  4920. dataType = 2;
  4921. }
  4922. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4923. else if (data->IsItem()) {
  4924. item = data->item;
  4925. dataType = 3;
  4926. }
  4927. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4928. else if (data->IsQuest()) {
  4929. quest = data->quest;
  4930. dataType = 4;
  4931. }
  4932. }
  4933. // Wasn't light user data, check if it is nil(null)
  4934. else if (lua_isnil(state, 3)) {
  4935. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4936. dataType = 6;
  4937. }
  4938. // Wasn't light user data or nil (null), must be a string
  4939. else {
  4940. // Set the string and dataType variable
  4941. val = lua_interface->GetStringValue(state, 3);
  4942. dataType = 5;
  4943. }
  4944. // We now have all the params, lets check to make sure they are valid
  4945. if (!spawn) {
  4946. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4947. return 0;
  4948. }
  4949. if (var.length() == 0) {
  4950. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4951. return 0;
  4952. }
  4953. if (dataType == 0) {
  4954. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4955. return 0;
  4956. }
  4957. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4958. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4959. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4960. switch (dataType) {
  4961. case 1:
  4962. // 1 = Spawn
  4963. spawn->AddTempVariable(var, spawnVal);
  4964. break;
  4965. case 2:
  4966. // 2 = Zone
  4967. spawn->AddTempVariable(var, zone);
  4968. break;
  4969. case 3:
  4970. // 3 = Item
  4971. spawn->AddTempVariable(var, item);
  4972. break;
  4973. case 4:
  4974. // 4 = Quest
  4975. spawn->AddTempVariable(var, quest);
  4976. break;
  4977. case 5:
  4978. // 5 = String
  4979. spawn->AddTempVariable(var, val);
  4980. break;
  4981. case 6:
  4982. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4983. spawn->DeleteTempVariable(var);
  4984. break;
  4985. }
  4986. // And we are done so return out
  4987. return 0;
  4988. }
  4989. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4990. if (!lua_interface)
  4991. return 0;
  4992. Spawn* spawn = lua_interface->GetSpawn(state);
  4993. string var = lua_interface->GetStringValue(state, 2);
  4994. if (!spawn) {
  4995. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4996. return 0;
  4997. }
  4998. if (var.length() == 0) {
  4999. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5000. return 0;
  5001. }
  5002. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5003. int8 type = spawn->GetTempVariableType(var);
  5004. Spawn* spawn2 = 0;
  5005. ZoneServer* zone = 0;
  5006. Item* item = 0;
  5007. Quest* quest = 0;
  5008. // Set the lua function return value based on the type of data the variable contains
  5009. switch (type) {
  5010. case 1:
  5011. spawn2 = spawn->GetTempVariableSpawn(var);
  5012. if (!spawn2)
  5013. return 0;
  5014. lua_interface->SetSpawnValue(state, spawn2);
  5015. break;
  5016. case 2:
  5017. zone = spawn->GetTempVariableZone(var);
  5018. if (!zone)
  5019. return 0;
  5020. lua_interface->SetZoneValue(state, zone);
  5021. break;
  5022. case 3:
  5023. item = spawn->GetTempVariableItem(var);
  5024. if (!item)
  5025. return 0;
  5026. lua_interface->SetItemValue(state, item);
  5027. break;
  5028. case 4:
  5029. quest = spawn->GetTempVariableQuest(var);
  5030. if (!quest)
  5031. return 0;
  5032. lua_interface->SetQuestValue(state, quest);
  5033. break;
  5034. case 5:
  5035. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5036. break;
  5037. default:
  5038. // Not a valid type then the variable was not set so return out
  5039. return 0;
  5040. }
  5041. // Return value was set so return out
  5042. return 1;
  5043. }
  5044. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5045. {
  5046. if (!lua_interface)
  5047. return 0;
  5048. Quest* quest = lua_interface->GetQuest(state);
  5049. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5050. string description = lua_interface->GetStringValue(state, 3);
  5051. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5052. if (!quest) {
  5053. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5054. lua_interface->SetBooleanValue(state, false);
  5055. return 1;
  5056. }
  5057. if (!spawn) {
  5058. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5059. lua_interface->SetBooleanValue(state, false);
  5060. return 1;
  5061. }
  5062. if (!spawn->IsPlayer()) {
  5063. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5064. lua_interface->SetBooleanValue(state, false);
  5065. return 1;
  5066. }
  5067. if (item_id == 0) {
  5068. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5069. lua_interface->SetBooleanValue(state, false);
  5070. return 1;
  5071. }
  5072. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5073. if (!client) {
  5074. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5075. lua_interface->SetBooleanValue(state, false);
  5076. return 1;
  5077. }
  5078. Item* item = master_item_list.GetItem(item_id);
  5079. if (!item) {
  5080. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5081. lua_interface->SetBooleanValue(state, false);
  5082. return 1;
  5083. }
  5084. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  5085. if (packet) {
  5086. packet->setDataByName("title", "Quest Reward!");
  5087. packet->setDataByName("name", quest->GetName());
  5088. packet->setDataByName("description", description.c_str());
  5089. packet->setDataByName("level", quest->GetLevel());
  5090. packet->setArrayLengthByName("num_rewards", 1);
  5091. packet->setArrayDataByName("reward_id", item->details.item_id);
  5092. if (client->GetVersion() < 860)
  5093. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  5094. else if (client->GetVersion() < 1193)
  5095. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  5096. else
  5097. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  5098. client->QueuePacket(packet->serialize());
  5099. safe_delete(packet);
  5100. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  5101. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  5102. return 1;
  5103. }
  5104. lua_interface->SetBooleanValue(state, false);
  5105. return 1;
  5106. }
  5107. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5108. if (!lua_interface)
  5109. return 0;
  5110. Quest* quest = lua_interface->GetQuest(state);
  5111. if (!quest) {
  5112. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5113. return 0;
  5114. }
  5115. quest->SetRepeatable(true);
  5116. return 0;
  5117. }
  5118. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5119. if (!lua_interface)
  5120. return 0;
  5121. Spawn* spawn = lua_interface->GetSpawn(state);
  5122. if (!spawn) {
  5123. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5124. return 0;
  5125. }
  5126. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5127. string ret = classes.GetClassNameCase(base_class);
  5128. if (ret.length() > 0) {
  5129. lua_interface->SetStringValue(state, ret.c_str());
  5130. return 1;
  5131. }
  5132. return 0;
  5133. }
  5134. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5135. if (!lua_interface)
  5136. return 0;
  5137. Spawn* player = lua_interface->GetSpawn(state);
  5138. if (player && player->IsPlayer()) {
  5139. Client* client = player->GetClient();
  5140. if (client)
  5141. client->SendWaypoints();
  5142. }
  5143. return 0;
  5144. }
  5145. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5146. if (!lua_interface)
  5147. return 0;
  5148. Spawn* player = lua_interface->GetSpawn(state);
  5149. string name = lua_interface->GetStringValue(state, 2);
  5150. int32 type = lua_interface->GetInt32Value(state, 3);
  5151. if (type == 0)
  5152. type = 2;
  5153. if (name.length() > 0) {
  5154. if (player && player->IsPlayer()) {
  5155. Client* client = player->GetClient();
  5156. if (client)
  5157. client->AddWaypoint(name, type);
  5158. }
  5159. }
  5160. return 0;
  5161. }
  5162. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5163. if (!lua_interface)
  5164. return 0;
  5165. Spawn* player = lua_interface->GetSpawn(state);
  5166. string name = lua_interface->GetStringValue(state, 2);
  5167. if (name.length() > 0) {
  5168. if (player && player->IsPlayer()) {
  5169. Client* client = player->GetClient();
  5170. if (client)
  5171. client->RemoveWaypoint(name);
  5172. }
  5173. }
  5174. return 0;
  5175. }
  5176. int EQ2Emu_lua_AddWard(lua_State* state) {
  5177. if (!lua_interface)
  5178. return 0;
  5179. int32 damage = lua_interface->GetInt32Value(state);
  5180. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5181. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5182. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5183. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5184. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5185. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5186. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5187. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5188. bool ward_was_added = false;
  5189. ZoneServer* zone = spell->caster->GetZone();
  5190. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5191. for (int32 i = 0; i < spell->targets.size(); i++) {
  5192. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5193. if (!target)
  5194. continue;
  5195. if (target->IsEntity()) {
  5196. // If the ward is already active remove it
  5197. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5198. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5199. // Create new ward info
  5200. WardInfo* ward = new WardInfo;
  5201. ward->Spell = spell;
  5202. ward->BaseDamage = damage;
  5203. ward->DamageLeft = damage;
  5204. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5205. ward->keepWard = keepWard;
  5206. ward->WardType = wardType;
  5207. if (damageAbsorptionPercent > 100)
  5208. damageAbsorptionPercent = 100;
  5209. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5210. if (damageAbsorptionMaxHealthPercent > 100)
  5211. damageAbsorptionMaxHealthPercent = 100;
  5212. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5213. ward->RedirectDamagePercent = redirectDamagePercent;
  5214. ward->LastRedirectDamage = 0;
  5215. ward->LastAbsorbedDamage = 0;
  5216. ward->HitCount = 0;
  5217. spell->num_triggers = maxHitCount;
  5218. spell->had_triggers = true;
  5219. spell->cancel_after_all_triggers = false;
  5220. ward->MaxHitCount = maxHitCount;
  5221. if (wardType == WARD_TYPE_MAGICAL)
  5222. ward->DamageType = damageTypes;
  5223. // Add the ward to the entity
  5224. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5225. ward_was_added = true;
  5226. }
  5227. }
  5228. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5229. if (ward_was_added && spell->caster->IsPlayer()) {
  5230. spell->had_dmg_remaining = true;
  5231. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5232. }
  5233. return 0;
  5234. }
  5235. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5236. if (!lua_interface)
  5237. return 0;
  5238. int32 amount = lua_interface->GetInt32Value(state);
  5239. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5240. WardInfo* ward = 0;
  5241. ZoneServer* zone = spell->caster->GetZone();
  5242. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5243. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5244. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5245. ward = target->GetWard(spell->spell->GetSpellID());
  5246. if (ward) {
  5247. ward->DamageLeft += amount;
  5248. if (ward->DamageLeft > ward->BaseDamage)
  5249. ward->DamageLeft = ward->BaseDamage;
  5250. for (int32 i = 0; i < spell->targets.size(); i++) {
  5251. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5252. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5253. }
  5254. }
  5255. }
  5256. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5257. if (ward && spell->caster->IsPlayer())
  5258. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5259. return 0;
  5260. }
  5261. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5262. if (!lua_interface)
  5263. return 0;
  5264. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5265. if (!spell) {
  5266. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5267. return 0;
  5268. }
  5269. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5270. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5271. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5272. if (ward) {
  5273. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5274. return 1;
  5275. }
  5276. }
  5277. return 0;
  5278. }
  5279. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5280. if (!lua_interface)
  5281. return 0;
  5282. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5283. if (!spell) {
  5284. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5285. return 0;
  5286. }
  5287. string type = lua_interface->GetStringValue(state, 2);
  5288. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5289. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5290. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5291. if (ward) {
  5292. if (boost::iequals(type, "damageleft"))
  5293. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5294. else if (boost::iequals(type, "basedamage"))
  5295. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5296. else if (boost::iequals(type, "keepward"))
  5297. lua_interface->SetBooleanValue(state, ward->keepWard);
  5298. else if (boost::iequals(type, "wardtype"))
  5299. lua_interface->SetInt32Value(state, ward->WardType);
  5300. else if (boost::iequals(type, "dmgabsorptionpct"))
  5301. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5302. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5303. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5304. else if (boost::iequals(type, "redirectdamagepercent"))
  5305. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5306. else if (boost::iequals(type, "lastredirectdamage"))
  5307. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5308. else if (boost::iequals(type, "lastabsorbeddamage"))
  5309. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5310. else if (boost::iequals(type, "hitcount"))
  5311. lua_interface->SetInt32Value(state, ward->HitCount);
  5312. else if (boost::iequals(type, "maxhitcount"))
  5313. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5314. else
  5315. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5316. return 1;
  5317. }
  5318. }
  5319. return 0;
  5320. }
  5321. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5322. if (!lua_interface)
  5323. return 0;
  5324. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5325. ZoneServer* zone = spell->caster->GetZone();
  5326. Spawn* target = 0;
  5327. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5328. for (int32 i = 0; i < spell->targets.size(); i++) {
  5329. target = zone->GetSpawnByID(spell->targets.at(i));
  5330. if (target && target->IsEntity()) {
  5331. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5332. }
  5333. }
  5334. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5335. return 0;
  5336. }
  5337. int EQ2Emu_lua_Interrupt(lua_State* state)
  5338. {
  5339. if (!lua_interface)
  5340. return 0;
  5341. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5342. Spawn* target = lua_interface->GetSpawn(state, 2);
  5343. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5344. if (!caster)
  5345. {
  5346. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5347. return 0;
  5348. }
  5349. if (!target)
  5350. {
  5351. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5352. return 0;
  5353. }
  5354. if (!spell) {
  5355. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5356. return 0;
  5357. }
  5358. if (!target->IsEntity() && !spell)
  5359. {
  5360. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5361. return 0;
  5362. }
  5363. if (!target && spell) {
  5364. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5365. for (int8 i = 0; i < spell->targets.size(); i++) {
  5366. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5367. if (!target || !target->IsEntity())
  5368. continue;
  5369. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5370. }
  5371. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5372. }
  5373. else
  5374. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5375. return 0;
  5376. }
  5377. int EQ2Emu_lua_Stealth(lua_State* state) {
  5378. if (!lua_interface)
  5379. return 0;
  5380. int8 type = lua_interface->GetInt8Value(state);
  5381. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5382. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5383. if (!spell) {
  5384. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5385. return 0;
  5386. }
  5387. ZoneServer* zone = spell->caster->GetZone();
  5388. if (spawn) {
  5389. if (spawn->IsEntity()) {
  5390. if (type == 1) {
  5391. ((Entity*)spawn)->AddStealthSpell(spell);
  5392. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5393. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5394. }
  5395. else if (type == 2) {
  5396. ((Entity*)spawn)->AddInvisSpell(spell);
  5397. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5398. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5399. }
  5400. return 0;
  5401. }
  5402. else {
  5403. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5404. return 0;
  5405. }
  5406. }
  5407. else {
  5408. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5409. for (int32 i = 0; i < spell->targets.size(); i++) {
  5410. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5411. if (!spawn || !spawn->IsEntity())
  5412. continue;
  5413. if (type == 1) {
  5414. ((Entity*)spawn)->AddStealthSpell(spell);
  5415. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5416. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5417. }
  5418. else if (type == 2) {
  5419. ((Entity*)spawn)->AddInvisSpell(spell);
  5420. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5421. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5422. }
  5423. else {
  5424. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5425. break;
  5426. }
  5427. }
  5428. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5429. }
  5430. return 0;
  5431. }
  5432. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5433. if (!lua_interface)
  5434. return 0;
  5435. Spawn* spawn = lua_interface->GetSpawn(state);
  5436. if (!spawn) {
  5437. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5438. return 0;
  5439. }
  5440. if (spawn->IsEntity()) {
  5441. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5442. return 1;
  5443. }
  5444. else
  5445. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5446. return 0;
  5447. }
  5448. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5449. if (!lua_interface)
  5450. return 0;
  5451. Spawn* spawn = lua_interface->GetSpawn(state);
  5452. if (!spawn) {
  5453. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5454. return 0;
  5455. }
  5456. if (spawn->IsEntity()) {
  5457. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5458. return 1;
  5459. }
  5460. else
  5461. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5462. return 0;
  5463. }
  5464. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5465. if (!lua_interface)
  5466. return 0;
  5467. Spawn* player = lua_interface->GetSpawn(state);
  5468. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5469. lua_interface->ResetFunctionStack(state);
  5470. if (!player->IsPlayer()) {
  5471. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5472. return 0;
  5473. }
  5474. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5475. return 1;
  5476. }
  5477. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5478. if (!lua_interface)
  5479. return 0;
  5480. Spawn* player = lua_interface->GetSpawn(state);
  5481. int8 slot = lua_interface->GetInt8Value(state, 2);
  5482. lua_interface->ResetFunctionStack(state);
  5483. if (!player) {
  5484. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5485. return 0;
  5486. }
  5487. if (!player->IsPlayer()) {
  5488. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5489. return 0;
  5490. }
  5491. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5492. if (!item) {
  5493. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5494. return 0;
  5495. }
  5496. lua_interface->SetItemValue(state, item);
  5497. return 1;
  5498. }
  5499. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5500. if (!lua_interface)
  5501. return 0;
  5502. Spawn* player = lua_interface->GetSpawn(state);
  5503. int32 id = lua_interface->GetInt32Value(state, 2);
  5504. lua_interface->ResetFunctionStack(state);
  5505. if (!player) {
  5506. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5507. return 0;
  5508. }
  5509. if (!player->IsPlayer()) {
  5510. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5511. return 0;
  5512. }
  5513. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5514. if (!item) {
  5515. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5516. return 0;
  5517. }
  5518. lua_interface->SetItemValue(state, item);
  5519. return 1;
  5520. }
  5521. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5522. if (!lua_interface)
  5523. return 0;
  5524. Spawn* spawn = lua_interface->GetSpawn(state);
  5525. int8 slot = lua_interface->GetInt8Value(state, 2);
  5526. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5527. lua_interface->ResetFunctionStack(state);
  5528. if (!spawn) {
  5529. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5530. return 0;
  5531. }
  5532. if (!spawn->IsEntity()) {
  5533. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5534. return 0;
  5535. }
  5536. Item* item = master_item_list.GetItem(item_id);
  5537. if (!item) {
  5538. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5539. return 0;
  5540. }
  5541. Item* copy = new Item(item);
  5542. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5543. if(result)
  5544. {
  5545. ((Entity*)spawn)->SetEquipment(copy, slot);
  5546. spawn->vis_changed = true;
  5547. if(spawn->IsPlayer())
  5548. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5549. }
  5550. else
  5551. {
  5552. safe_delete(copy);
  5553. }
  5554. lua_interface->SetBooleanValue(state, result);
  5555. return 1;
  5556. }
  5557. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5558. if (!lua_interface)
  5559. return 0;
  5560. Spawn* spawn = lua_interface->GetSpawn(state);
  5561. int8 slot = lua_interface->GetInt8Value(state, 2);
  5562. Item* item = lua_interface->GetItem(state, 3);
  5563. lua_interface->ResetFunctionStack(state);
  5564. if (!spawn) {
  5565. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5566. return 0;
  5567. }
  5568. if (!spawn->IsEntity()) {
  5569. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5570. return 0;
  5571. }
  5572. if (!item) {
  5573. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5574. return 0;
  5575. }
  5576. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5577. if(result)
  5578. {
  5579. ((Entity*)spawn)->SetEquipment(item, slot);
  5580. spawn->vis_changed = true;
  5581. if(spawn->IsPlayer())
  5582. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5583. }
  5584. lua_interface->SetBooleanValue(state, result);
  5585. return 1;
  5586. }
  5587. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5588. if (!lua_interface)
  5589. return 0;
  5590. Spawn* spawn = lua_interface->GetSpawn(state);
  5591. int8 slot = lua_interface->GetInt8Value(state, 2);
  5592. 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
  5593. lua_interface->ResetFunctionStack(state);
  5594. if (!spawn) {
  5595. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5596. return 0;
  5597. }
  5598. if (!spawn->IsEntity()) {
  5599. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5600. return 0;
  5601. }
  5602. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5603. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5604. spawn->vis_changed = true;
  5605. if(spawn->IsPlayer())
  5606. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5607. lua_interface->SetBooleanValue(state, true);
  5608. return 1;
  5609. }
  5610. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5611. if (!lua_interface)
  5612. return 0;
  5613. Spawn* spawn = lua_interface->GetSpawn(state);
  5614. int8 slot = lua_interface->GetInt8Value(state, 2);
  5615. int16 type = lua_interface->GetInt16Value(state, 3);
  5616. int8 r = lua_interface->GetInt8Value(state, 4);
  5617. int8 g = lua_interface->GetInt8Value(state, 5);
  5618. int8 b = lua_interface->GetInt8Value(state, 6);
  5619. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5620. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5621. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5622. lua_interface->ResetFunctionStack(state);
  5623. if (!spawn) {
  5624. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5625. return 0;
  5626. }
  5627. if (!spawn->IsEntity()) {
  5628. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5629. return 0;
  5630. }
  5631. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5632. spawn->vis_changed = true;
  5633. lua_interface->SetBooleanValue(state, true);
  5634. return 1;
  5635. }
  5636. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5637. if (!lua_interface)
  5638. return 0;
  5639. Spawn* player = lua_interface->GetSpawn(state);
  5640. int32 id = lua_interface->GetInt32Value(state, 2);
  5641. int8 count = lua_interface->GetInt8Value(state, 3);
  5642. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5643. lua_interface->ResetFunctionStack(state);
  5644. if (!player) {
  5645. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5646. return 0;
  5647. }
  5648. if (!player->IsPlayer()) {
  5649. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5650. return 0;
  5651. }
  5652. if (!count)
  5653. count = 1;
  5654. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5655. if (!item) {
  5656. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5657. return 0;
  5658. }
  5659. lua_interface->SetItemValue(state, item);
  5660. return 1;
  5661. }
  5662. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5663. if (!lua_interface)
  5664. return 0;
  5665. Spawn* spawn = lua_interface->GetSpawn(state);
  5666. int32 anim = lua_interface->GetInt32Value(state, 2);
  5667. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5668. int8 type = lua_interface->GetInt8Value(state, 4);
  5669. if (!spawn) {
  5670. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5671. return 0;
  5672. }
  5673. if (spawn2) {
  5674. if (spawn2->IsPlayer()) {
  5675. if (type != 1 && type != 2)
  5676. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5677. else
  5678. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5679. return 0;
  5680. }
  5681. else {
  5682. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5683. return 0;
  5684. }
  5685. }
  5686. else
  5687. spawn->GetZone()->PlayAnimation(spawn, anim);
  5688. return 0;
  5689. }
  5690. int EQ2Emu_lua_IsPet(lua_State* state) {
  5691. if (!lua_interface)
  5692. return 0;
  5693. Spawn* spawn = lua_interface->GetSpawn(state);
  5694. if (!spawn) {
  5695. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5696. return 0;
  5697. }
  5698. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5699. return 1;
  5700. }
  5701. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5702. if (!lua_interface)
  5703. return 0;
  5704. Spawn* spawn = lua_interface->GetSpawn(state);
  5705. if (!spawn) {
  5706. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5707. return 0;
  5708. }
  5709. if (!spawn->IsNPC()) {
  5710. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5711. return 0;
  5712. }
  5713. if (((NPC*)spawn)->GetOwner()) {
  5714. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5715. return 1;
  5716. }
  5717. return 0;
  5718. }
  5719. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5720. if (!lua_interface)
  5721. return 0;
  5722. Spawn* spawn = lua_interface->GetSpawn(state);
  5723. Spawn* target = lua_interface->GetSpawn(state, 2);
  5724. if (!spawn) {
  5725. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5726. return 0;
  5727. }
  5728. if (!spawn) {
  5729. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5730. return 0;
  5731. }
  5732. spawn->SetTarget(target);
  5733. return 0;
  5734. }
  5735. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5736. if (!lua_interface)
  5737. return 0;
  5738. Spawn* spawn = lua_interface->GetSpawn(state);
  5739. bool val = lua_interface->GetBooleanValue(state, 2);
  5740. if (!spawn) {
  5741. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5742. return 0;
  5743. }
  5744. if (!spawn->IsEntity()) {
  5745. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5746. return 0;
  5747. }
  5748. ((Entity*)spawn)->InCombat(val);
  5749. if (val) {
  5750. spawn->ClearRunningLocations();
  5751. spawn->CalculateRunningLocation(true);
  5752. }
  5753. return 0;
  5754. }
  5755. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5756. if (!lua_interface)
  5757. return 0;
  5758. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5759. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5760. if (!spawn1) {
  5761. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5762. return 0;
  5763. }
  5764. if (!spawn2) {
  5765. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5766. return 0;
  5767. }
  5768. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5769. return 1;
  5770. }
  5771. int EQ2Emu_lua_Runback(lua_State* state) {
  5772. if (!lua_interface)
  5773. return 0;
  5774. Spawn* spawn = lua_interface->GetSpawn(state);
  5775. if (!spawn) {
  5776. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5777. return 0;
  5778. }
  5779. if (!spawn->IsNPC()) {
  5780. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5781. return 0;
  5782. }
  5783. ((NPC*)spawn)->Runback();
  5784. return 0;
  5785. }
  5786. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5787. if (!lua_interface)
  5788. return 0;
  5789. Spawn* spawn = lua_interface->GetSpawn(state);
  5790. if (!spawn) {
  5791. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5792. return 0;
  5793. }
  5794. if (!spawn->IsNPC()) {
  5795. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5796. return 0;
  5797. }
  5798. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5799. return 1;
  5800. }
  5801. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5802. if (!lua_interface)
  5803. return 0;
  5804. Spawn* spawn = lua_interface->GetSpawn(state);
  5805. if (!spawn) {
  5806. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5807. return 0;
  5808. }
  5809. if (!spawn->IsEntity()) {
  5810. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5811. return 0;
  5812. }
  5813. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5814. return 1;
  5815. }
  5816. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5817. if (!lua_interface)
  5818. return 0;
  5819. Spawn* spawn = lua_interface->GetSpawn(state);
  5820. if (!spawn) {
  5821. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5822. return 0;
  5823. }
  5824. if (!spawn->IsEntity()) {
  5825. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5826. return 0;
  5827. }
  5828. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5829. return 1;
  5830. }
  5831. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5832. if (!lua_interface)
  5833. return 0;
  5834. Spawn* spawn = lua_interface->GetSpawn(state);
  5835. if (!spawn) {
  5836. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5837. return 0;
  5838. }
  5839. if (!spawn->IsEntity()) {
  5840. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5841. return 0;
  5842. }
  5843. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5844. return 1;
  5845. }
  5846. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5847. if (!lua_interface)
  5848. return 0;
  5849. Spawn* spawn = lua_interface->GetSpawn(state);
  5850. if (!spawn) {
  5851. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5852. return 0;
  5853. }
  5854. if (!spawn->IsEntity()) {
  5855. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5856. return 0;
  5857. }
  5858. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5859. return 1;
  5860. }
  5861. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5862. if (!lua_interface)
  5863. return 0;
  5864. Spawn* spawn = lua_interface->GetSpawn(state);
  5865. Spawn* target = lua_interface->GetSpawn(state, 2);
  5866. float distance = lua_interface->GetFloatValue(state, 3);
  5867. if (!spawn) {
  5868. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5869. return 0;
  5870. }
  5871. if (!target) {
  5872. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5873. return 0;
  5874. }
  5875. if (!spawn->IsNPC()) {
  5876. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5877. return 0;
  5878. }
  5879. if (!target->IsEntity()) {
  5880. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5881. return 0;
  5882. }
  5883. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5884. return 1;
  5885. }
  5886. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5887. if (!lua_interface)
  5888. return 0;
  5889. Spawn* spawn = lua_interface->GetSpawn(state);
  5890. Spawn* target = lua_interface->GetSpawn(state, 2);
  5891. float distance = lua_interface->GetFloatValue(state, 3);
  5892. if (!spawn) {
  5893. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5894. return 0;
  5895. }
  5896. if (!target) {
  5897. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5898. return 0;
  5899. }
  5900. if (!spawn->IsNPC()) {
  5901. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5902. return 0;
  5903. }
  5904. if (!target->IsEntity()) {
  5905. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5906. return 0;
  5907. }
  5908. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5909. return 0;
  5910. }
  5911. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5912. if (!lua_interface)
  5913. return 0;
  5914. Spawn* spawn = lua_interface->GetSpawn(state);
  5915. if (!spawn) {
  5916. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5917. return 0;
  5918. }
  5919. if (!spawn->IsNPC()) {
  5920. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5921. return 0;
  5922. }
  5923. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5924. return 1;
  5925. }
  5926. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5927. if (!lua_interface)
  5928. return 0;
  5929. Spawn* spawn = lua_interface->GetSpawn(state);
  5930. if (!spawn) {
  5931. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5932. return 0;
  5933. }
  5934. if (!spawn->IsNPC()) {
  5935. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5936. return 0;
  5937. }
  5938. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5939. return 1;
  5940. }
  5941. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5942. if (!lua_interface)
  5943. return 0;
  5944. Spawn* spawn = lua_interface->GetSpawn(state);
  5945. if (!spawn) {
  5946. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5947. return 0;
  5948. }
  5949. if (!spawn->IsNPC()) {
  5950. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5951. return 0;
  5952. }
  5953. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5954. if (hated) {
  5955. lua_interface->SetSpawnValue(state, hated);
  5956. return 1;
  5957. }
  5958. return 0;
  5959. }
  5960. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5961. if (!lua_interface)
  5962. return 0;
  5963. Spawn* spawn = lua_interface->GetSpawn(state);
  5964. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5965. if (!spawn) {
  5966. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5967. return 0;
  5968. }
  5969. if (!spawn->IsNPC()) {
  5970. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5971. return 0;
  5972. }
  5973. if (!hated) {
  5974. ((NPC*)spawn)->Brain()->ClearHate();
  5975. return 0;
  5976. }
  5977. else
  5978. {
  5979. if (!hated->IsEntity()) {
  5980. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5981. return 0;
  5982. }
  5983. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5984. return 0;
  5985. }
  5986. return 0;
  5987. }
  5988. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5989. if (!lua_interface)
  5990. return 0;
  5991. Spawn* spawn = lua_interface->GetSpawn(state);
  5992. if (!spawn) {
  5993. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5994. return 0;
  5995. }
  5996. if (!spawn->IsNPC()) {
  5997. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5998. return 0;
  5999. }
  6000. ((NPC*)spawn)->Brain()->ClearEncounter();
  6001. return 0;
  6002. }
  6003. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6004. if (!lua_interface)
  6005. return 0;
  6006. Spawn* spawn = lua_interface->GetSpawn(state);
  6007. if (!spawn) {
  6008. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6009. return 0;
  6010. }
  6011. if (!spawn->IsNPC()) {
  6012. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6013. return 0;
  6014. }
  6015. // Temp list to store hate list
  6016. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6017. if (encounterList->size() == 0) {
  6018. safe_delete(encounterList);
  6019. return 0;
  6020. }
  6021. lua_createtable(state, encounterList->size(), 0);
  6022. int newTable = lua_gettop(state);
  6023. for (int32 i = 0; i < encounterList->size(); i++) {
  6024. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6025. if (temp)
  6026. lua_interface->SetSpawnValue(state, temp);
  6027. lua_rawseti(state, newTable, i + 1);
  6028. }
  6029. safe_delete(encounterList);
  6030. return 1;
  6031. }
  6032. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6033. if (!lua_interface)
  6034. return 0;
  6035. Spawn* spawn = lua_interface->GetSpawn(state);
  6036. if (!spawn) {
  6037. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6038. return 0;
  6039. }
  6040. if (!spawn->IsNPC()) {
  6041. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6042. return 0;
  6043. }
  6044. // Temp list to store hate list
  6045. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6046. if (hateList->size() == 0) {
  6047. safe_delete(hateList);
  6048. return 0;
  6049. }
  6050. lua_createtable(state, hateList->size(), 0);
  6051. int newTable = lua_gettop(state);
  6052. for (int32 i = 0; i < hateList->size(); i++) {
  6053. lua_interface->SetSpawnValue(state, hateList->at(i));
  6054. lua_rawseti(state, newTable, i + 1);
  6055. }
  6056. safe_delete(hateList);
  6057. return 1;
  6058. }
  6059. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6060. if (!lua_interface)
  6061. return 0;
  6062. Spawn* spawn = lua_interface->GetSpawn(state);
  6063. if (!spawn) {
  6064. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6065. return 0;
  6066. }
  6067. if (spawn->IsPlayer()) {
  6068. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6069. lua_interface->SetBooleanValue(state, true);
  6070. else
  6071. lua_interface->SetBooleanValue(state, false);
  6072. return 1;
  6073. }
  6074. else {
  6075. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6076. return 1;
  6077. }
  6078. }
  6079. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6080. if (!lua_interface)
  6081. return 0;
  6082. Quest* quest = lua_interface->GetQuest(state);
  6083. if (!quest) {
  6084. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6085. return 0;
  6086. }
  6087. quest->SetCompletedFlag(true);
  6088. return 0;
  6089. }
  6090. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6091. if (!lua_interface)
  6092. return 0;
  6093. Spawn* spawn = lua_interface->GetSpawn(state);
  6094. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6095. int8 tier = lua_interface->GetInt8Value(state, 3);
  6096. if (!spawn) {
  6097. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6098. return 0;
  6099. }
  6100. if (!spawn->IsEntity()) {
  6101. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6102. return 0;
  6103. }
  6104. if (spellID == 0) {
  6105. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6106. return 0;
  6107. }
  6108. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6109. if (effect) {
  6110. if (tier > 0) {
  6111. // If a tier was passed chec to see if it is the same as the effect
  6112. if (tier == effect->tier)
  6113. lua_interface->SetBooleanValue(state, true);
  6114. else
  6115. lua_interface->SetBooleanValue(state, false);
  6116. return 1;
  6117. }
  6118. else {
  6119. // Have an effect but no tier was passed so return true
  6120. lua_interface->SetBooleanValue(state, true);
  6121. }
  6122. return 1;
  6123. }
  6124. // no effect so return false
  6125. lua_interface->SetBooleanValue(state, false);
  6126. return 1;
  6127. }
  6128. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6129. if (!lua_interface)
  6130. return 0;
  6131. Spawn* spawn = lua_interface->GetSpawn(state);
  6132. int32 id = lua_interface->GetInt32Value(state, 2);
  6133. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6134. Spawn* spawn2 = 0;
  6135. vector<Spawn*> list;
  6136. if (!spawn) {
  6137. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6138. return 0;
  6139. }
  6140. //If zone not provided, use spawn's zone
  6141. if (!zone)
  6142. zone = spawn->GetZone();
  6143. list = zone->GetSpawnsByID(id);
  6144. if (list.size() == 0) {
  6145. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6146. return 0;
  6147. }
  6148. vector<Spawn*>::iterator itr = list.begin();
  6149. for (int8 i = 0; i < list.size(); i++) {
  6150. spawn2 = itr[i];
  6151. if (spawn2)
  6152. spawn2->AddAllowAccessSpawn(spawn);
  6153. }
  6154. return 0;
  6155. }
  6156. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6157. if (!lua_interface)
  6158. return 0;
  6159. Spawn* spawn = lua_interface->GetSpawn(state);
  6160. int32 id = lua_interface->GetInt32Value(state, 2);
  6161. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6162. Spawn* spawn2 = 0;
  6163. if (!spawn) {
  6164. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6165. return 0;
  6166. }
  6167. //If zone not provided, use spawn's zone
  6168. if (!zone)
  6169. zone = spawn->GetZone();
  6170. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6171. vector<Spawn*>::iterator itr = list.begin();
  6172. if (list.size() == 0) {
  6173. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6174. return 0;
  6175. }
  6176. for (int8 i = 0; i < list.size(); i++) {
  6177. spawn2 = itr[i];
  6178. if (spawn2)
  6179. spawn2->RemoveSpawnAccess(spawn);
  6180. }
  6181. return 0;
  6182. }
  6183. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6184. if (!lua_interface)
  6185. return 0;
  6186. Quest* quest = lua_interface->GetQuest(state);
  6187. if (!quest) {
  6188. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6189. return 0;
  6190. }
  6191. quest->SetYellowName(true);
  6192. return 0;
  6193. }
  6194. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6195. if (!lua_interface)
  6196. return 0;
  6197. Spawn* spawn = lua_interface->GetSpawn(state);
  6198. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6199. if (!spawn) {
  6200. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6201. return 0;
  6202. }
  6203. if (!spawn->IsPlayer()) {
  6204. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6205. return 0;
  6206. }
  6207. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6208. return 1;
  6209. }
  6210. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6211. if (!lua_interface)
  6212. return 0;
  6213. Spawn* spawn = lua_interface->GetSpawn(state);
  6214. if (!spawn) {
  6215. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6216. return 0;
  6217. }
  6218. if (!spawn->IsPlayer()) {
  6219. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6220. return 0;
  6221. }
  6222. ZoneServer* zone = spawn->GetZone();
  6223. if (!zone) {
  6224. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6225. return 0;
  6226. }
  6227. Instance_Type iType = zone->GetInstanceType();
  6228. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6229. iType == GROUP_LOCKOUT_INSTANCE ||
  6230. iType == RAID_LOCKOUT_INSTANCE ||
  6231. iType == SOLO_PERSIST_INSTANCE ||
  6232. iType == GROUP_PERSIST_INSTANCE ||
  6233. iType == RAID_PERSIST_INSTANCE) {
  6234. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6235. if (data) {
  6236. // Check to see if the timer has already been set, if it has return out.
  6237. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6238. return 0;
  6239. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6240. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6241. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6242. if (client) {
  6243. string time_msg = "";
  6244. int32 time = data->success_lockout_time;
  6245. int16 hour;
  6246. int8 min;
  6247. int8 sec;
  6248. hour = time / 3600;
  6249. time = time % 3600;
  6250. min = time / 60;
  6251. time = time % 60;
  6252. sec = time;
  6253. if (hour > 0) {
  6254. char temp[10];
  6255. sprintf(temp, " %i", hour);
  6256. time_msg.append(temp);
  6257. time_msg.append(" hour");
  6258. time_msg.append((hour > 1) ? "s" : "");
  6259. }
  6260. if (min > 0) {
  6261. char temp[5];
  6262. sprintf(temp, " %i", min);
  6263. time_msg.append(temp);
  6264. time_msg.append(" minute");
  6265. time_msg.append((min > 1) ? "s" : "");
  6266. }
  6267. // Only add seconds if minutes and hours are 0
  6268. if (hour == 0 && min == 0 && sec > 0) {
  6269. char temp[5];
  6270. sprintf(temp, " %i", sec);
  6271. time_msg.append(temp);
  6272. time_msg.append(" second");
  6273. time_msg.append((sec > 1) ? "s" : "");
  6274. }
  6275. 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());
  6276. }
  6277. }
  6278. else
  6279. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6280. }
  6281. else
  6282. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6283. return 0;
  6284. }
  6285. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6286. if (!lua_interface)
  6287. return 0;
  6288. Spawn* spawn = lua_interface->GetSpawn(state);
  6289. if (!spawn) {
  6290. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. if (!spawn->IsPlayer()) {
  6294. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6295. return 0;
  6296. }
  6297. ZoneServer* zone = spawn->GetZone();
  6298. if (!zone) {
  6299. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6300. return 0;
  6301. }
  6302. Instance_Type iType = zone->GetInstanceType();
  6303. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6304. iType == GROUP_LOCKOUT_INSTANCE ||
  6305. iType == RAID_LOCKOUT_INSTANCE ||
  6306. iType == SOLO_PERSIST_INSTANCE ||
  6307. iType == GROUP_PERSIST_INSTANCE ||
  6308. iType == RAID_PERSIST_INSTANCE) {
  6309. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6310. if (data) {
  6311. // Check to see if the timer has already been set, if it has return out.
  6312. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6313. return 0;
  6314. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6315. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6316. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6317. if (client) {
  6318. string time_msg = "";
  6319. int32 time = data->failure_lockout_time;
  6320. int16 hour;
  6321. int8 min;
  6322. int8 sec;
  6323. hour = time / 3600;
  6324. time = time % 3600;
  6325. min = time / 60;
  6326. time = time % 60;
  6327. sec = time;
  6328. if (hour > 0) {
  6329. char temp[10];
  6330. sprintf(temp, " %i", hour);
  6331. time_msg.append(temp);
  6332. time_msg.append(" hour");
  6333. time_msg.append((hour > 1) ? "s" : "");
  6334. }
  6335. if (min > 0) {
  6336. char temp[5];
  6337. sprintf(temp, " %i", min);
  6338. time_msg.append(temp);
  6339. time_msg.append(" minute");
  6340. time_msg.append((min > 1) ? "s" : "");
  6341. }
  6342. // Only add seconds if minutes and hours are 0
  6343. if (hour == 0 && min == 0 && sec > 0) {
  6344. char temp[5];
  6345. sprintf(temp, " %i", sec);
  6346. time_msg.append(temp);
  6347. time_msg.append(" second");
  6348. time_msg.append((sec > 1) ? "s" : "");
  6349. }
  6350. 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());
  6351. }
  6352. }
  6353. else
  6354. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6355. }
  6356. else
  6357. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6358. return 0;
  6359. }
  6360. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6361. if (!lua_interface)
  6362. return 0;
  6363. Spawn* spawn = lua_interface->GetSpawn(state);
  6364. if (!spawn) {
  6365. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6366. return 0;
  6367. }
  6368. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6369. return 1;
  6370. }
  6371. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6372. if (!lua_interface)
  6373. return 0;
  6374. Spawn* player = lua_interface->GetSpawn(state);
  6375. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6376. if (!player) {
  6377. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6378. return 0;
  6379. }
  6380. if (!player->IsPlayer()) {
  6381. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6382. return 0;
  6383. }
  6384. if (!ground) {
  6385. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6386. return 0;
  6387. }
  6388. if (!ground->IsGroundSpawn()) {
  6389. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6390. return 0;
  6391. }
  6392. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6393. if (!groundspawn_entries) {
  6394. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6395. return 0;
  6396. }
  6397. Skill* skill = 0;
  6398. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6399. if (collection_skill == "Collecting")
  6400. skill = ((Player*)player)->GetSkillByName("Gathering");
  6401. else
  6402. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6403. if (!skill) {
  6404. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6405. return 0;
  6406. }
  6407. vector<GroundSpawnEntry*>::iterator itr;
  6408. GroundSpawnEntry* entry = 0;
  6409. bool can_harvest = false;
  6410. sint32 min_skill = -1;
  6411. int16 totalSkill = skill->current_val;
  6412. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6413. if(skillID != 0xFFFFFFFF)
  6414. {
  6415. ((Entity*)player)->MStats.lock();
  6416. totalSkill += ((Entity*)player)->stats[skillID];
  6417. ((Entity*)player)->MStats.unlock();
  6418. }
  6419. // first, iterate through groundspawn_entries, discard tables player cannot use
  6420. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6421. {
  6422. entry = *itr;
  6423. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6424. min_skill = entry->min_skill_level;
  6425. // if player lacks skill, skip table
  6426. if (entry->min_skill_level > totalSkill)
  6427. continue;
  6428. // if bonus, but player lacks level, skip table
  6429. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6430. continue;
  6431. can_harvest = true;
  6432. break;
  6433. }
  6434. lua_interface->SetBooleanValue(state, can_harvest);
  6435. // If false, send the message to the client
  6436. if (!can_harvest) {
  6437. Client* client = player->GetZone()->GetClientBySpawn(player);
  6438. if (client) {
  6439. string msg = "You do not have enough skill to ";
  6440. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6441. msg.append("gather");
  6442. else if (collection_skill == "Mining")
  6443. msg.append("mine");
  6444. else if (collection_skill == "Trapping")
  6445. msg.append("trap");
  6446. else if (collection_skill == "Foresting")
  6447. msg.append("forest");
  6448. else if (collection_skill == "Fishing")
  6449. msg.append("catch");
  6450. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6451. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6452. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6453. }
  6454. }
  6455. return 1;
  6456. }
  6457. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6458. if (!lua_interface)
  6459. return 0;
  6460. Spawn* player = lua_interface->GetSpawn(state);
  6461. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6462. if (!player) {
  6463. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6464. return 0;
  6465. }
  6466. if (!player->IsPlayer()) {
  6467. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6468. return 0;
  6469. }
  6470. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6471. lua_interface->SetBooleanValue(state, ret);
  6472. return 1;
  6473. }
  6474. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6475. // Check to see if we have a valid lua_interface
  6476. if (!lua_interface)
  6477. return 0;
  6478. // Get the spawn that is getting the pet
  6479. Spawn* spawn = lua_interface->GetSpawn(state);
  6480. Spawn* target = lua_interface->GetSpawn(state, 2);
  6481. // Get the DB ID of the pet
  6482. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6483. float x = lua_interface->GetFloatValue(state, 4);
  6484. float y = lua_interface->GetFloatValue(state, 5);
  6485. float z = lua_interface->GetFloatValue(state, 6);
  6486. // Get the spell that this command was called from
  6487. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6488. // Check to make sure the spawn pointer is valid
  6489. if (!spawn) {
  6490. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. // Check to make sure the spawn is an entity
  6494. if (!spawn->IsEntity()) {
  6495. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6496. return 0;
  6497. }
  6498. if (!target) {
  6499. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6500. return 0;
  6501. }
  6502. if (!target->IsEntity()) {
  6503. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6504. return 0;
  6505. }
  6506. // Check to see if the DB ID for the pet is set
  6507. if (pet_id == 0) {
  6508. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6509. return 0;
  6510. }
  6511. // Check to see if the pointer to the spell is valid
  6512. if (!luaspell) {
  6513. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6514. return 0;
  6515. }
  6516. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6517. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6518. if (!pet) {
  6519. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6520. return 0;
  6521. }
  6522. // Check to make sure the pet is an npc
  6523. if (!pet->IsNPC()) {
  6524. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6525. return 0;
  6526. }
  6527. if (x == 0)
  6528. x = spawn->GetX();
  6529. if (y == 0)
  6530. y = spawn->GetY();
  6531. if (z == 0)
  6532. z = spawn->GetZ();
  6533. // Spawn the pet at the same location as the owner
  6534. pet->SetX(x);
  6535. pet->SetY(y);
  6536. pet->SetZ(z);
  6537. pet->SetLocation(spawn->GetLocation());
  6538. pet->SetHeading(spawn->GetHeading());
  6539. spawn->GetZone()->AddSpawn(pet);
  6540. /*
  6541. const char* spawn_script = world.GetSpawnScript(pet_id);
  6542. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6543. spawn->SetSpawnScript(string(spawn_script));
  6544. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6545. }*/
  6546. // Get a random pet name
  6547. string random_pet_name;
  6548. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6549. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6550. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6551. // Set the pets name
  6552. pet->SetName(random_pet_name.c_str());
  6553. // Set the level of the pet to the owners level
  6554. pet->SetLevel(spawn->GetLevel());
  6555. // Set the faction of the pet to the same faction as the owner
  6556. pet->SetFactionID(spawn->GetFactionID());
  6557. // Set the spawn as a pet
  6558. pet->SetPet(true);
  6559. // Give a pointer of the owner to the pet
  6560. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6561. // Set the pet type
  6562. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6563. // Set the spell id used to create this pet
  6564. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6565. // Set the spell tier used to create this pet
  6566. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6567. // Set the pets spawn type to 6
  6568. pet->SetSpawnType(6);
  6569. // Set the pets brain
  6570. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6571. // Check to see if the pet has a subtitle
  6572. if (strlen(pet->GetSubTitle()) > 0) {
  6573. // Add the players name to the front of the sub title
  6574. string pet_subtitle;
  6575. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6576. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6577. // Set the pets subtitle to the new one
  6578. pet->SetSubTitle(pet_subtitle.c_str());
  6579. }
  6580. // Set the pet as the return value for this function
  6581. lua_interface->SetSpawnValue(state, pet);
  6582. return 1;
  6583. }
  6584. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6585. if (!lua_interface)
  6586. return 0;
  6587. Spawn* spawn = lua_interface->GetSpawn(state);
  6588. Spawn* player = lua_interface->GetSpawn(state, 2);
  6589. float max_distance = lua_interface->GetFloatValue(state, 3);
  6590. string type = lua_interface->GetStringValue(state, 4);
  6591. if (!spawn || (spawn && spawn->IsPlayer())) {
  6592. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6593. return 0;
  6594. }
  6595. if (!player || (player && !player->IsPlayer())) {
  6596. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6597. return 0;
  6598. }
  6599. Client* client = 0;
  6600. if (player->GetZone())
  6601. client = player->GetZone()->GetClientBySpawn(player);
  6602. if (!client) {
  6603. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6604. return 0;
  6605. }
  6606. //Set max_distance to default if not set or not proper value
  6607. if (max_distance <= 0)
  6608. max_distance = 500;
  6609. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6610. if (packet) {
  6611. float unknown2_3 = 0;
  6612. int8 placement_mode = 0;
  6613. if (type == "wall") {
  6614. placement_mode = 2;
  6615. unknown2_3 = 150;
  6616. }
  6617. else if (type == "ceiling")
  6618. placement_mode = 1;
  6619. packet->setDataByName("placement_mode", placement_mode);
  6620. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6621. packet->setDataByName("model_type", spawn->GetModelType());
  6622. packet->setDataByName("unknown", 1); //size
  6623. packet->setDataByName("unknown2", 1); //size 2
  6624. packet->setDataByName("unknown2", .5, 1); //size 3
  6625. packet->setDataByName("unknown2", 3, 2);
  6626. packet->setDataByName("unknown2", unknown2_3, 3);
  6627. packet->setDataByName("max_distance", max_distance);
  6628. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6629. client->QueuePacket(packet->serialize());
  6630. safe_delete(packet);
  6631. }
  6632. return 0;
  6633. }
  6634. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6635. if (!lua_interface)
  6636. return 0;
  6637. Item* item = lua_interface->GetItem(state);
  6638. if (!item) {
  6639. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6640. return 0;
  6641. }
  6642. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6643. return 1;
  6644. }
  6645. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6646. if (!lua_interface)
  6647. return 0;
  6648. Spawn* spawn = lua_interface->GetSpawn(state);
  6649. if (!spawn) {
  6650. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6651. return 0;
  6652. }
  6653. if (spawn->GetZone())
  6654. spawn->GetZone()->AddTransportSpawn(spawn);
  6655. return 0;
  6656. }
  6657. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6658. if (!lua_interface)
  6659. return 0;
  6660. Skill* skill = lua_interface->GetSkill(state);
  6661. if (!skill) {
  6662. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6663. return 0;
  6664. }
  6665. lua_interface->SetInt32Value(state, skill->current_val);
  6666. return 1;
  6667. }
  6668. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6669. if (!lua_interface)
  6670. return 0;
  6671. Skill* skill = lua_interface->GetSkill(state);
  6672. if (!skill) {
  6673. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6674. return 0;
  6675. }
  6676. lua_interface->SetInt32Value(state, skill->max_val);
  6677. return 1;
  6678. }
  6679. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6680. if (!lua_interface)
  6681. return 0;
  6682. Skill* skill = lua_interface->GetSkill(state);
  6683. if (!skill) {
  6684. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6685. return 0;
  6686. }
  6687. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6688. return 1;
  6689. }
  6690. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6691. if (!lua_interface)
  6692. return 0;
  6693. Skill* skill = lua_interface->GetSkill(state);
  6694. int16 value = lua_interface->GetInt16Value(state, 2);
  6695. if (!skill) {
  6696. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6697. return 0;
  6698. }
  6699. skill->max_val = value;
  6700. if (skill->max_val < skill->current_val)
  6701. skill->current_val = skill->max_val;
  6702. return 0;
  6703. }
  6704. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6705. if (!lua_interface)
  6706. return 0;
  6707. Skill* skill = lua_interface->GetSkill(state);
  6708. int16 value = lua_interface->GetInt16Value(state, 2);
  6709. if (!skill) {
  6710. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6711. return 0;
  6712. }
  6713. if (value > skill->max_val)
  6714. skill->current_val = skill->max_val;
  6715. else
  6716. skill->current_val = value;
  6717. return 0;
  6718. }
  6719. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6720. if (!lua_interface)
  6721. return 0;
  6722. Spawn* player = lua_interface->GetSpawn(state);
  6723. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6724. if (skill_id > 0 && player && player->IsPlayer()) {
  6725. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6726. return 1;
  6727. }
  6728. return 0;
  6729. }
  6730. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6731. if (!lua_interface)
  6732. return 0;
  6733. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6734. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6735. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6736. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6737. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6738. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6739. if (player_spawn && player_spawn->IsPlayer()) {
  6740. Player* player = (Player*)player_spawn;
  6741. bool added = false;
  6742. if (!player->skill_list.HasSkill(skill_id)) {
  6743. player->AddSkill(skill_id, current_val, max_val, true);
  6744. added = true;
  6745. }
  6746. 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
  6747. Client* client = player->GetClient();
  6748. if (client) {
  6749. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6750. if (packet)
  6751. client->QueuePacket(packet);
  6752. }
  6753. }
  6754. if (added) {
  6755. lua_interface->SetBooleanValue(state, true);
  6756. return 1;
  6757. }
  6758. }
  6759. else {
  6760. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6761. }
  6762. }
  6763. else {
  6764. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6765. }
  6766. lua_interface->SetBooleanValue(state, false);
  6767. return 1;
  6768. }
  6769. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6770. if (!lua_interface)
  6771. return 0;
  6772. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6773. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6774. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6775. if (skill_id > 0) {
  6776. if (player_spawn && player_spawn->IsPlayer()) {
  6777. Player* player = (Player*)player_spawn;
  6778. if (player->skill_list.HasSkill(skill_id)) {
  6779. player->RemovePlayerSkill(skill_id);
  6780. if (!more_to_remove) {
  6781. Client* client = player->GetClient();
  6782. if (client) {
  6783. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6784. if (packet)
  6785. client->QueuePacket(packet);
  6786. }
  6787. }
  6788. }
  6789. }
  6790. else {
  6791. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6792. }
  6793. }
  6794. else {
  6795. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6796. }
  6797. return 0;
  6798. }
  6799. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6800. if (!lua_interface)
  6801. return 0;
  6802. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6803. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6804. int16 amount = lua_interface->GetInt8Value(state, 3);
  6805. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6806. if (amount > 0 && skill_type < 100) {
  6807. if (player_spawn && player_spawn->IsPlayer()) {
  6808. Player* player = (Player*)player_spawn;
  6809. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6810. if (!more_to_increase) {
  6811. Client* client = player->GetClient();
  6812. if (client) {
  6813. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6814. if (packet)
  6815. client->QueuePacket(packet);
  6816. }
  6817. }
  6818. }
  6819. else {
  6820. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6821. }
  6822. }
  6823. else {
  6824. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6825. }
  6826. return 0;
  6827. }
  6828. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6829. if (!lua_interface)
  6830. return 0;
  6831. Spawn* spawn = lua_interface->GetSpawn(state);
  6832. string name = lua_interface->GetStringValue(state, 2);
  6833. if (!spawn) {
  6834. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6835. return 0;
  6836. }
  6837. if (!spawn->IsEntity()) {
  6838. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6839. return 0;
  6840. }
  6841. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6842. if (skill) {
  6843. lua_interface->SetSkillValue(state, skill);
  6844. return 1;
  6845. }
  6846. return 0;
  6847. }
  6848. int EQ2Emu_lua_AddProc(lua_State* state) {
  6849. if (!lua_interface)
  6850. return 0;
  6851. Spawn* spawn = lua_interface->GetSpawn(state);
  6852. int8 type = lua_interface->GetInt8Value(state, 2);
  6853. float chance = lua_interface->GetFloatValue(state, 3);
  6854. Item* item = lua_interface->GetItem(state, 4);
  6855. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6856. LuaSpell* spell = 0;
  6857. if (!spawn && (!spell || !use_all_spelltargets)) {
  6858. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6859. return 0;
  6860. }
  6861. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6862. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6863. return 0;
  6864. }
  6865. if (!item)
  6866. spell = lua_interface->GetCurrentSpell(state);
  6867. if (!item && !spell) {
  6868. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6869. return 0;
  6870. }
  6871. if (spell && use_all_spelltargets) {
  6872. Spawn* target;
  6873. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6874. for (int8 i = 0; i < spell->targets.size(); i++) {
  6875. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6876. if (!target || !target->IsEntity())
  6877. continue;
  6878. ((Entity*)target)->AddProc(type, chance, item, spell);
  6879. }
  6880. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6881. }
  6882. else
  6883. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6884. return 0;
  6885. }
  6886. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6887. if (!lua_interface)
  6888. return 0;
  6889. Spawn* spawn = lua_interface->GetSpawn(state);
  6890. Item* item = lua_interface->GetItem(state, 2);
  6891. LuaSpell* spell = 0;
  6892. if (!spawn) {
  6893. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6894. return 0;
  6895. }
  6896. if (!spawn->IsEntity()) {
  6897. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6898. return 0;
  6899. }
  6900. if (!item)
  6901. spell = lua_interface->GetCurrentSpell(state);
  6902. if (!item && !spell) {
  6903. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6904. return 0;
  6905. }
  6906. if (spell) {
  6907. Spawn* target;
  6908. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6909. for (int8 i = 0; i < spell->targets.size(); i++) {
  6910. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6911. if (!target || !target->IsEntity())
  6912. continue;
  6913. ((Entity*)target)->RemoveProc(item, spell);
  6914. }
  6915. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6916. spell->caster->RemoveProc(item, spell);
  6917. }
  6918. else
  6919. ((Entity*)spawn)->RemoveProc(item, spell);
  6920. return 0;
  6921. }
  6922. int EQ2Emu_lua_Knockback(lua_State* state) {
  6923. if (!lua_interface)
  6924. return 0;
  6925. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6926. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6927. int32 duration = lua_interface->GetInt32Value(state, 3);
  6928. float vertical = lua_interface->GetFloatValue(state, 4);
  6929. float horizontal = lua_interface->GetFloatValue(state, 5);
  6930. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6931. if (!target_spawn) {
  6932. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6933. return 0;
  6934. }
  6935. if (!spawn) {
  6936. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6937. return 0;
  6938. }
  6939. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6940. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6941. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6942. if (packet) {
  6943. packet->setDataByName("target_x", target_spawn->GetX());
  6944. packet->setDataByName("target_y", target_spawn->GetY());
  6945. packet->setDataByName("target_z", target_spawn->GetZ());
  6946. packet->setDataByName("vertical_movement", vertical);
  6947. packet->setDataByName("horizontal_movement", horizontal);
  6948. if (use_heading)
  6949. packet->setDataByName("use_player_heading", 1);
  6950. client->QueuePacket(packet->serialize());
  6951. }
  6952. safe_delete(packet);
  6953. }
  6954. return 0;
  6955. }
  6956. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6957. if (!lua_interface)
  6958. return 0;
  6959. Spawn* spawn = lua_interface->GetSpawn(state);
  6960. if (!spawn) {
  6961. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6962. return 0;
  6963. }
  6964. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6965. return 1;
  6966. }
  6967. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6968. if (!lua_interface)
  6969. return 0;
  6970. Spawn* caster = lua_interface->GetSpawn(state);
  6971. Spawn* target = lua_interface->GetSpawn(state, 2);
  6972. string name = lua_interface->GetStringValue(state, 3);
  6973. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6974. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6975. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6976. string success_msg = lua_interface->GetStringValue(state, 7);
  6977. string effect_msg = lua_interface->GetStringValue(state, 8);
  6978. if (!caster) {
  6979. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6980. return 0;
  6981. }
  6982. if (!caster->IsEntity()) {
  6983. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6984. return 0;
  6985. }
  6986. if (!target) {
  6987. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6988. return 0;
  6989. }
  6990. if (!target->IsEntity()) {
  6991. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6992. return 0;
  6993. }
  6994. if (name.length() == 0) {
  6995. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6996. return 0;
  6997. }
  6998. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6999. return 0;
  7000. }
  7001. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7002. if (!lua_interface)
  7003. return 0;
  7004. string name = lua_interface->GetStringValue(state);
  7005. if (name.length() == 0) {
  7006. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7007. return 0;
  7008. }
  7009. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7010. if (!skill) {
  7011. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7012. return 0;
  7013. }
  7014. lua_interface->SetInt32Value(state, skill->skill_id);
  7015. return 1;
  7016. }
  7017. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7018. if (!lua_interface)
  7019. return 0;
  7020. Spawn* spawn = lua_interface->GetSpawn(state);
  7021. if (!spawn) {
  7022. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7023. return 0;
  7024. }
  7025. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7026. return 1;
  7027. }
  7028. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7029. if (!lua_interface)
  7030. return 0;
  7031. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7032. if (!luaspell) {
  7033. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7034. return 0;
  7035. }
  7036. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7037. return 1;
  7038. }
  7039. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7040. if (!lua_interface)
  7041. return 0;
  7042. Spawn* spawn = lua_interface->GetSpawn(state);
  7043. Spawn* target = lua_interface->GetSpawn(state, 2);
  7044. if (!spawn) {
  7045. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7046. return 0;
  7047. }
  7048. if (!spawn->IsEntity()) {
  7049. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7050. return 0;
  7051. }
  7052. if (!target) {
  7053. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7054. return 0;
  7055. }
  7056. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7057. return 1;
  7058. }
  7059. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7060. if (!lua_interface)
  7061. return 0;
  7062. Spawn* spawn = lua_interface->GetSpawn(state);
  7063. Spawn* target = lua_interface->GetSpawn(state, 2);
  7064. if (!spawn) {
  7065. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7066. return 0;
  7067. }
  7068. if (!spawn->IsEntity()) {
  7069. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7070. return 0;
  7071. }
  7072. if (!target) {
  7073. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7074. return 0;
  7075. }
  7076. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7077. return 1;
  7078. }
  7079. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7080. if (!lua_interface)
  7081. return 0;
  7082. Item* item = lua_interface->GetItem(state);
  7083. if (!item) {
  7084. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7085. return 0;
  7086. }
  7087. lua_interface->SetInt32Value(state, item->details.count);
  7088. return 1;
  7089. }
  7090. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7091. if (!lua_interface)
  7092. return 0;
  7093. Item* item = lua_interface->GetItem(state);
  7094. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7095. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7096. if (!item) {
  7097. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7098. return 0;
  7099. }
  7100. if (!owner) {
  7101. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7102. return 0;
  7103. }
  7104. if (!owner->IsPlayer()) {
  7105. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7106. return 0;
  7107. }
  7108. if (item->stack_count < new_count) {
  7109. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7110. return 0;
  7111. }
  7112. if (new_count > 0) {
  7113. item->details.count = new_count;
  7114. item->save_needed = true;
  7115. }
  7116. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7117. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7118. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7119. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7120. else
  7121. {
  7122. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7123. return 0;
  7124. }
  7125. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7126. if (!client)
  7127. return 0;
  7128. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7129. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  7130. if (app)
  7131. client->QueuePacket(app);
  7132. return 0;
  7133. }
  7134. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7135. if (!lua_interface)
  7136. return 0;
  7137. int32 time = lua_interface->GetInt32Value(state);
  7138. string function = lua_interface->GetStringValue(state, 2);
  7139. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7140. Spawn* target = lua_interface->GetSpawn(state, 4);
  7141. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7142. if (time == 0) {
  7143. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7144. return 0;
  7145. }
  7146. if (function.length() == 0) {
  7147. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7148. return 0;
  7149. }
  7150. if (!spell) {
  7151. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7152. return 0;
  7153. }
  7154. SpellScriptTimer* timer = new SpellScriptTimer;
  7155. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7156. #ifdef WIN32
  7157. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7158. #else
  7159. bzero(timer, sizeof(SpellScriptTimer));
  7160. #endif*/
  7161. timer->caster = 0;
  7162. timer->deleteWhenDone = false;
  7163. timer->target = 0;
  7164. timer->time = Timer::GetCurrentTime2() + time;
  7165. timer->customFunction = function;
  7166. timer->spell = spell;
  7167. if (caster)
  7168. timer->caster = caster->GetID();
  7169. if (target)
  7170. timer->target = target->GetID();
  7171. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7172. return 0;
  7173. }
  7174. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7175. if (!lua_interface)
  7176. return 0;
  7177. float hp_perc = lua_interface->GetFloatValue(state);
  7178. float power_perc = lua_interface->GetFloatValue(state, 2);
  7179. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7180. Spawn* target = lua_interface->GetSpawn(state, 4);
  7181. string heal_name = lua_interface->GetStringValue(state, 5);
  7182. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7183. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7184. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7185. if (!spell) {
  7186. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7187. return 0;
  7188. }
  7189. Entity* caster = spell->caster;
  7190. if (!caster) {
  7191. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7192. return 0;
  7193. }
  7194. Client* client = 0;
  7195. PendingResurrection* rez = 0;
  7196. ZoneServer* zone = spell->caster->GetZone();
  7197. if (!target) {
  7198. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7199. if (spell->targets.size() > 0) {
  7200. vector<int32> spell_targets = spell->targets;
  7201. for (int8 i = 0; i < spell_targets.size(); i++) {
  7202. target = zone->GetSpawnByID(spell_targets.at(i));
  7203. if (!target)
  7204. continue;
  7205. if (!target->IsPlayer())
  7206. continue;
  7207. client = target->GetZone()->GetClientBySpawn(target);
  7208. if (!client)
  7209. continue;
  7210. rez = client->GetCurrentRez();
  7211. if (rez->active)
  7212. continue;
  7213. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7214. rez->active = true;
  7215. rez->caster = caster;
  7216. rez->expire_timer = new Timer;
  7217. int32 duration = spell->spell->GetSpellDuration();
  7218. rez->expire_timer->Start(duration * 100);
  7219. rez->hp_perc = hp_perc;
  7220. rez->mp_perc = power_perc;
  7221. rez->range = spell->spell->GetSpellData()->range;
  7222. rez->spell_name = spell->spell->GetName();
  7223. if (heal_name.length() > 0)
  7224. rez->heal_name = heal_name;
  7225. else
  7226. rez->heal_name = rez->spell_name;
  7227. rez->no_calcs = no_calcs;
  7228. rez->crit_mod = crit_mod;
  7229. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7230. if (send_window)
  7231. client->SendResurrectionWindow();
  7232. else {
  7233. target->GetZone()->ResurrectSpawn(target, client);
  7234. rez->should_delete = true;
  7235. }
  7236. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7237. }
  7238. }
  7239. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7240. }
  7241. else {
  7242. client = target->GetZone()->GetClientBySpawn(target);
  7243. if (!client)
  7244. return 0;
  7245. rez = client->GetCurrentRez();
  7246. if (rez->active)
  7247. return 0;
  7248. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7249. rez->active = true;
  7250. rez->caster = caster;
  7251. rez->expire_timer = new Timer;
  7252. int32 duration = spell->spell->GetSpellDuration();
  7253. rez->expire_timer->Start(duration * 100);
  7254. rez->hp_perc = hp_perc;
  7255. rez->mp_perc = power_perc;
  7256. rez->range = spell->spell->GetSpellData()->range;
  7257. rez->spell_name = spell->spell->GetName();
  7258. if (heal_name.length() > 0)
  7259. rez->heal_name = heal_name;
  7260. else
  7261. rez->heal_name = rez->spell_name;
  7262. rez->no_calcs = no_calcs;
  7263. rez->crit_mod = crit_mod;
  7264. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7265. if (send_window)
  7266. client->SendResurrectionWindow();
  7267. else {
  7268. target->GetZone()->ResurrectSpawn(target, client);
  7269. rez->should_delete = true;
  7270. }
  7271. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7272. }
  7273. return 0;
  7274. }
  7275. int EQ2Emu_lua_SetVision(lua_State* state) {
  7276. if (!lua_interface)
  7277. return 0;
  7278. Spawn* spawn = lua_interface->GetSpawn(state);
  7279. int8 vision = lua_interface->GetInt8Value(state, 2);
  7280. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7281. if (!spawn) {
  7282. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7283. return 0;
  7284. }
  7285. if (!spawn->IsEntity()) {
  7286. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7287. return 0;
  7288. }
  7289. if (spell && spell->targets.size() > 0) {
  7290. ZoneServer* zone = spell->caster->GetZone();
  7291. for (int8 i = 0; i < spell->targets.size(); i++) {
  7292. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7293. if (target->IsEntity()) {
  7294. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7295. if (target->IsPlayer())
  7296. ((Player*)target)->SetCharSheetChanged(true);
  7297. }
  7298. }
  7299. }
  7300. else {
  7301. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7302. if (spawn->IsPlayer())
  7303. ((Player*)spawn)->SetCharSheetChanged(true);
  7304. }
  7305. return 0;
  7306. }
  7307. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7308. if (!lua_interface)
  7309. return 0;
  7310. Spawn* spawn = lua_interface->GetSpawn(state);
  7311. float intensity = lua_interface->GetFloatValue(state, 2);
  7312. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7313. if (!spawn) {
  7314. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. if (!spawn->IsEntity()) {
  7318. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7319. return 0;
  7320. }
  7321. if (spell && spell->targets.size() > 0) {
  7322. ZoneServer* zone = spell->caster->GetZone();
  7323. for (int8 i = 0; i < spell->targets.size(); i++) {
  7324. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7325. if (target && target->IsEntity()) {
  7326. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7327. if (target->IsPlayer())
  7328. ((Player*)target)->SetCharSheetChanged(true);
  7329. }
  7330. }
  7331. }
  7332. else {
  7333. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7334. if (spawn->IsPlayer())
  7335. ((Player*)spawn)->SetCharSheetChanged(true);
  7336. }
  7337. return 0;
  7338. }
  7339. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7340. if (!lua_interface)
  7341. return 0;
  7342. Spawn* spawn = lua_interface->GetSpawn(state);
  7343. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7344. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7345. if (!spawn) {
  7346. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7347. return 0;
  7348. }
  7349. if (!spawn->IsEntity()) {
  7350. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7351. return 0;
  7352. }
  7353. if (spell && spell->targets.size() > 0) {
  7354. ZoneServer* zone = spell->caster->GetZone();
  7355. for (int8 i = 0; i < spell->targets.size(); i++) {
  7356. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7357. if (target->IsEntity()) {
  7358. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7359. if (target->IsPlayer())
  7360. ((Player*)target)->SetCharSheetChanged(true);
  7361. }
  7362. }
  7363. }
  7364. else {
  7365. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7366. if (spawn->IsPlayer())
  7367. ((Player*)spawn)->SetCharSheetChanged(true);
  7368. }
  7369. return 0;
  7370. }
  7371. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7372. if (!lua_interface)
  7373. return 0;
  7374. Item* item = lua_interface->GetItem(state);
  7375. int8 type = lua_interface->GetInt32Value(state, 2);
  7376. if (!item) {
  7377. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7378. return 0;
  7379. }
  7380. if (type == 1)
  7381. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7382. else if (type == 2)
  7383. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7384. return 1;
  7385. }
  7386. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7387. if (!lua_interface)
  7388. return 0;
  7389. Spawn* target = lua_interface->GetSpawn(state);
  7390. float val = lua_interface->GetFloatValue(state, 2);
  7391. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7392. // Added from Gangrenous post
  7393. if (spell && spell->resisted)
  7394. return 0;
  7395. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7396. if (val > 1.0f)
  7397. val = 1.0f - (val / 100.0f);
  7398. if (spell && spell->spell && spell->targets.size() > 0) {
  7399. ZoneServer* zone = spell->caster->GetZone();
  7400. for (int32 i = 0; i != spell->targets.size(); i++) {
  7401. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7402. if (spawn && spawn->IsEntity()) {
  7403. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7404. if (spawn->IsPlayer())
  7405. ((Player*)spawn)->SetCharSheetChanged(true);
  7406. }
  7407. }
  7408. }
  7409. else {
  7410. if (target && target->IsEntity()) {
  7411. ((Entity*)target)->SetSpeedMultiplier(val);
  7412. if (target->IsPlayer())
  7413. ((Player*)target)->SetCharSheetChanged(true);
  7414. }
  7415. }
  7416. return 0;
  7417. }
  7418. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7419. if (!lua_interface)
  7420. return 0;
  7421. Spawn* spawn = lua_interface->GetSpawn(state);
  7422. int16 model = lua_interface->GetInt16Value(state, 2);
  7423. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7424. if (spell && spell->spell && spell->targets.size() > 0) {
  7425. ZoneServer* zone = spell->caster->GetZone();
  7426. for (int32 i = 0; i < spell->targets.size(); i++) {
  7427. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7428. if (target)
  7429. target->SetIllusionModel(model);
  7430. }
  7431. }
  7432. else {
  7433. if (!spawn) {
  7434. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7435. return 0;
  7436. }
  7437. spawn->SetIllusionModel(model);
  7438. }
  7439. return 0;
  7440. }
  7441. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7442. if (!lua_interface)
  7443. return 0;
  7444. Spawn* spawn = lua_interface->GetSpawn(state);
  7445. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7446. if (spell && spell->spell && spell->targets.size() > 0) {
  7447. ZoneServer* zone = spell->caster->GetZone();
  7448. for (int32 i = 0; i < spell->targets.size(); i++) {
  7449. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7450. if (target)
  7451. target->SetIllusionModel(0);
  7452. }
  7453. }
  7454. else {
  7455. if (!spawn) {
  7456. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7457. return 0;
  7458. }
  7459. spawn->SetIllusionModel(0);
  7460. }
  7461. return 0;
  7462. }
  7463. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7464. if (!lua_interface)
  7465. return 0;
  7466. Spawn* caster = lua_interface->GetSpawn(state);
  7467. Spawn* target = lua_interface->GetSpawn(state, 2);
  7468. float chance = lua_interface->GetFloatValue(state, 3);
  7469. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7470. if (!caster) {
  7471. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7472. return 0;
  7473. }
  7474. if (!caster->IsEntity()) {
  7475. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7476. return 0;
  7477. }
  7478. if (!target) {
  7479. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7480. return 0;
  7481. }
  7482. if (!target->IsEntity()) {
  7483. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7484. return 0;
  7485. }
  7486. if (chance <= 0) {
  7487. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7488. return 0;
  7489. }
  7490. if (!spell) {
  7491. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7492. return 0;
  7493. }
  7494. if (((Entity*)caster)->GetThreatTransfer()) {
  7495. return 0;
  7496. }
  7497. ThreatTransfer* transfer = new ThreatTransfer;
  7498. transfer->Target = target->GetID();
  7499. transfer->Amount = chance;
  7500. transfer->Spell = spell;
  7501. ((Entity*)caster)->SetThreatTransfer(transfer);
  7502. return 0;
  7503. }
  7504. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7505. if (!lua_interface)
  7506. return 0;
  7507. Spawn* spawn = lua_interface->GetSpawn(state);
  7508. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7509. if (!spawn) {
  7510. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7511. return 0;
  7512. }
  7513. if (!spell) {
  7514. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7515. return 0;
  7516. }
  7517. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7518. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7519. ((Entity*)spawn)->SetThreatTransfer(0);
  7520. safe_delete(transfer);
  7521. }
  7522. return 0;
  7523. }
  7524. int EQ2Emu_lua_CureByType(lua_State* state) {
  7525. if (!lua_interface)
  7526. return 0;
  7527. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7528. if (!spell) {
  7529. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7530. return 0;
  7531. }
  7532. int8 cure_count = lua_interface->GetInt8Value(state);
  7533. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7534. string cure_name = lua_interface->GetStringValue(state, 3);
  7535. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7536. Spawn* target = lua_interface->GetSpawn(state, 5);
  7537. if (target) {
  7538. if (!target->IsEntity()) {
  7539. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7540. return 0;
  7541. }
  7542. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7543. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7544. }
  7545. else {
  7546. ZoneServer* zone = spell->caster->GetZone();
  7547. vector<int32> targets = spell->targets;
  7548. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7549. for (int8 i = 0; i < targets.size(); i++) {
  7550. target = zone->GetSpawnByID(targets.at(i));
  7551. if (!target || !target->IsEntity())
  7552. continue;
  7553. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7554. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7555. }
  7556. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7557. }
  7558. return 0;
  7559. }
  7560. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7561. if (!lua_interface)
  7562. return 0;
  7563. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7564. if (!spell) {
  7565. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7566. return 0;
  7567. }
  7568. int8 cure_count = lua_interface->GetInt8Value(state);
  7569. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7570. string cure_name = lua_interface->GetStringValue(state, 3);
  7571. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7572. Spawn* target = lua_interface->GetSpawn(state, 5);
  7573. if (target) {
  7574. if (!target->IsEntity()) {
  7575. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7576. return 0;
  7577. }
  7578. if (((Entity*)target)->GetDetCount() > 0)
  7579. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7580. }
  7581. else {
  7582. ZoneServer* zone = spell->caster->GetZone();
  7583. vector<int32> targets = spell->targets;
  7584. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7585. for (int8 i = 0; i < targets.size(); i++) {
  7586. target = zone->GetSpawnByID(targets.at(i));
  7587. if (!target || !target->IsEntity())
  7588. continue;
  7589. if (((Entity*)target)->GetDetCount() > 0)
  7590. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7591. }
  7592. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7593. }
  7594. return 0;
  7595. }
  7596. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7597. if (!lua_interface)
  7598. return 0;
  7599. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7600. if (!spell) {
  7601. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7602. return 0;
  7603. }
  7604. if (!spell->caster) {
  7605. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7606. return 0;
  7607. }
  7608. if (!spell->caster->GetZone()) {
  7609. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7610. return 0;
  7611. }
  7612. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7613. return 0;
  7614. }
  7615. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7616. if (!lua_interface)
  7617. return 0;
  7618. Spawn* spawn = lua_interface->GetSpawn(state);
  7619. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7620. if (!spell) {
  7621. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7622. return 0;
  7623. }
  7624. if (spawn && spawn->IsEntity())
  7625. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7626. else {
  7627. ZoneServer* zone = spell->caster->GetZone();
  7628. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7629. for (int32 i = 0; i < spell->targets.size(); i++) {
  7630. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7631. if (!spawn || !spawn->IsEntity())
  7632. continue;
  7633. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7634. }
  7635. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7636. }
  7637. return 0;
  7638. }
  7639. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7640. if (!lua_interface)
  7641. return 0;
  7642. Spawn* spawn = lua_interface->GetSpawn(state);
  7643. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7644. if (!spell) {
  7645. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7646. return 0;
  7647. }
  7648. if (spawn && spawn->IsEntity())
  7649. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7650. else {
  7651. ZoneServer* zone = spell->caster->GetZone();
  7652. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7653. for (int32 i = 0; i < spell->targets.size(); i++) {
  7654. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7655. if (!spawn || !spawn->IsEntity())
  7656. continue;
  7657. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7658. }
  7659. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7660. }
  7661. return 0;
  7662. }
  7663. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7664. if (!lua_interface)
  7665. return 0;
  7666. Spawn* caster = lua_interface->GetSpawn(state);
  7667. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7668. if (!caster) {
  7669. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7670. return 0;
  7671. }
  7672. if (!caster->IsPlayer()) {
  7673. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7674. return 0;
  7675. }
  7676. Spawn* target = caster->GetTarget();
  7677. if (!target) {
  7678. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7679. return 0;
  7680. }
  7681. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7682. if (!client) {
  7683. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7684. return 0;
  7685. }
  7686. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7687. if (ho) {
  7688. ho->SetTarget(target->GetID());
  7689. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7690. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7691. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7692. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7693. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7694. deque<GroupMemberInfo*>::iterator itr;
  7695. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7696. if (group)
  7697. {
  7698. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7699. deque<GroupMemberInfo*>* members = group->GetMembers();
  7700. for (itr = members->begin(); itr != members->end(); itr++) {
  7701. if ((*itr)->client)
  7702. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7703. }
  7704. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7705. }
  7706. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7707. }
  7708. else
  7709. safe_delete(ho);
  7710. }
  7711. else {
  7712. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7713. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7714. }
  7715. else
  7716. safe_delete(ho);
  7717. }
  7718. }
  7719. return 0;
  7720. }
  7721. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7722. if (!lua_interface)
  7723. return 0;
  7724. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7725. if (!spell) {
  7726. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7727. return 0;
  7728. }
  7729. int16 triggerCount = lua_interface->GetInt16Value(state);
  7730. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7731. if (!triggerCount) {
  7732. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7733. return 0;
  7734. }
  7735. spell->num_triggers = triggerCount;
  7736. spell->had_triggers = true;
  7737. spell->cancel_after_all_triggers = cancel_after_triggers;
  7738. return 0;
  7739. }
  7740. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7741. if (!lua_interface)
  7742. return 0;
  7743. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7744. if (!spell) {
  7745. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7746. return 0;
  7747. }
  7748. lua_interface->SetInt32Value(state, spell->num_triggers);
  7749. return 1;
  7750. }
  7751. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7752. if (!lua_interface)
  7753. return 0;
  7754. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7755. if (!spell) {
  7756. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7757. return 0;
  7758. }
  7759. int16 remove_count = lua_interface->GetInt16Value(state);
  7760. if (!remove_count)
  7761. remove_count = 1;
  7762. if (remove_count >= spell->num_triggers) {
  7763. spell->num_triggers = 0;
  7764. if (spell->cancel_after_all_triggers)
  7765. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7766. }
  7767. else {
  7768. spell->num_triggers -= remove_count;
  7769. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7770. }
  7771. return 0;
  7772. }
  7773. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7774. if (!lua_interface)
  7775. return 0;
  7776. Spawn* spawn = lua_interface->GetSpawn(state);
  7777. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7778. if (!spawn) {
  7779. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7780. return 0;
  7781. }
  7782. if (!copy_spawn) {
  7783. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7784. return 0;
  7785. }
  7786. spawn->CopySpawnAppearance(copy_spawn);
  7787. return 0;
  7788. }
  7789. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7790. Spawn* spawn = lua_interface->GetSpawn(state);
  7791. int8 type = lua_interface->GetInt8Value(state, 2);
  7792. if (!spawn) {
  7793. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7794. return 0;
  7795. }
  7796. else if (!spawn->IsEntity()) {
  7797. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7798. return 0;
  7799. }
  7800. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7801. return 1;
  7802. }
  7803. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7804. if (!lua_interface)
  7805. return 0;
  7806. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7807. int8 type = lua_interface->GetInt8Value(state);
  7808. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7809. if (!spell) {
  7810. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7811. return 0;
  7812. }
  7813. if (spawn) {
  7814. if (!spawn->IsEntity()) {
  7815. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7816. return 0;
  7817. }
  7818. Entity* entity = ((Entity*)spawn);
  7819. entity->AddImmunity(spell, type);
  7820. }
  7821. else {
  7822. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7823. for (int8 i = 0; i < spell->targets.size(); i++) {
  7824. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7825. if (!spawn || !spawn->IsEntity())
  7826. continue;
  7827. Entity* entity = ((Entity*)spawn);
  7828. entity->AddImmunity(spell, type);
  7829. }
  7830. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7831. }
  7832. return 0;
  7833. }
  7834. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7835. if (!lua_interface)
  7836. return 0;
  7837. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7838. int8 type = lua_interface->GetInt8Value(state);
  7839. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7840. if (!spell) {
  7841. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7842. return 0;
  7843. }
  7844. if (spawn) {
  7845. if (!spawn->IsEntity()) {
  7846. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7847. return 0;
  7848. }
  7849. Entity* entity = ((Entity*)spawn);
  7850. entity->RemoveImmunity(spell, type);
  7851. }
  7852. else {
  7853. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7854. for (int8 i = 0; i < spell->targets.size(); i++) {
  7855. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7856. if (!spawn || !spawn->IsEntity())
  7857. continue;
  7858. Entity* entity = ((Entity*)spawn);
  7859. entity->RemoveImmunity(spell, type);
  7860. }
  7861. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7862. }
  7863. return 0;
  7864. }
  7865. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7866. if (!lua_interface)
  7867. return 0;
  7868. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7869. if (!spell) {
  7870. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7871. return 0;
  7872. }
  7873. float snare = lua_interface->GetFloatValue(state);
  7874. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7875. // convert the val to the speed multipler value (100 - val)
  7876. float val = 100.0 - snare;
  7877. val /= 100.0;
  7878. if (spawn) {
  7879. if (!spawn->IsEntity()) {
  7880. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7881. return 0;
  7882. }
  7883. ((Entity*)spawn)->SetSnareValue(spell, val);
  7884. }
  7885. else {
  7886. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7887. for (int8 i = 0; i < spell->targets.size(); i++) {
  7888. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7889. if (!spawn || !spawn->IsEntity())
  7890. continue;
  7891. ((Entity*)spawn)->SetSnareValue(spell, val);
  7892. }
  7893. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7894. }
  7895. return 0;
  7896. }
  7897. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7898. if (!lua_interface)
  7899. return 0;
  7900. Spawn* spawn = lua_interface->GetSpawn(state);
  7901. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7902. if (!spawn) {
  7903. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7904. return 0;
  7905. }
  7906. if (race_id == 0) {
  7907. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7908. return 0;
  7909. }
  7910. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7911. return 1;
  7912. }
  7913. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7914. if (!lua_interface)
  7915. return 0;
  7916. Spawn* spawn = lua_interface->GetSpawn(state);
  7917. if (!spawn) {
  7918. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7919. return 0;
  7920. }
  7921. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7922. return 1;
  7923. }
  7924. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7925. if (!lua_interface)
  7926. return 0;
  7927. Spawn* spawn = lua_interface->GetSpawn(state);
  7928. if (!spawn) {
  7929. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7930. return 0;
  7931. }
  7932. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7933. return 1;
  7934. }
  7935. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7936. if (!lua_interface)
  7937. return 0;
  7938. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7939. if (!spell) {
  7940. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7941. return 0;
  7942. }
  7943. lua_interface->SetStringValue(state, spell->spell->GetName());
  7944. return 1;
  7945. }
  7946. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7947. if (!lua_interface)
  7948. return 0;
  7949. Quest* quest = lua_interface->GetQuest(state);
  7950. if (!quest) {
  7951. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7952. return 0;
  7953. }
  7954. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7955. return 1;
  7956. }
  7957. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7958. if (!lua_interface)
  7959. return 0;
  7960. Quest* quest = lua_interface->GetQuest(state);
  7961. int32 flags = lua_interface->GetInt32Value(state, 2);
  7962. if (!quest) {
  7963. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7964. return 0;
  7965. }
  7966. quest->SetQuestFlags(flags);
  7967. return 0;
  7968. }
  7969. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7970. if (!lua_interface)
  7971. return 0;
  7972. Quest* quest = lua_interface->GetQuest(state);
  7973. Spawn* player = lua_interface->GetSpawn(state, 2);
  7974. int32 step = lua_interface->GetInt32Value(state, 3);
  7975. int32 duration = lua_interface->GetInt32Value(state, 4);
  7976. string action = lua_interface->GetStringValue(state, 5);
  7977. if (!quest) {
  7978. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7979. return 0;
  7980. }
  7981. if (!player) {
  7982. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7983. return 0;
  7984. }
  7985. if (!player->IsPlayer()) {
  7986. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7987. return 0;
  7988. }
  7989. if (step == 0) {
  7990. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7991. return 0;
  7992. }
  7993. if (duration == 0) {
  7994. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7995. return 0;
  7996. }
  7997. if (action.length() == 0) {
  7998. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7999. return 0;
  8000. }
  8001. Client* client = player->GetZone()->GetClientBySpawn(player);
  8002. if (!client) {
  8003. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8004. return 0;
  8005. }
  8006. quest->SetTimerStep(step);
  8007. quest->AddFailedAction(step, action);
  8008. quest->SetStepTimer(duration);
  8009. client->AddQuestTimer(quest->GetQuestID());
  8010. return 0;
  8011. }
  8012. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8013. if (!lua_interface)
  8014. return 0;
  8015. Quest* quest = lua_interface->GetQuest(state);
  8016. Spawn* player = lua_interface->GetSpawn(state, 2);
  8017. if (!quest) {
  8018. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8019. return 0;
  8020. }
  8021. if (!player) {
  8022. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8023. return 0;
  8024. }
  8025. if (!player->IsPlayer()) {
  8026. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8027. return 0;
  8028. }
  8029. Client* client = player->GetZone()->GetClientBySpawn(player);
  8030. if (!client) {
  8031. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8032. return 0;
  8033. }
  8034. quest->SetTimerStep(0);
  8035. quest->SetStepTimer(0);
  8036. client->RemoveQuestTimer(quest->GetQuestID());
  8037. return 0;
  8038. }
  8039. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8040. if (!lua_interface)
  8041. return 0;
  8042. Spawn* player = lua_interface->GetSpawn(state);
  8043. Quest* quest = lua_interface->GetQuest(state, 2);
  8044. int32 step = lua_interface->GetInt32Value(state, 3);
  8045. if (!player) {
  8046. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8047. return 0;
  8048. }
  8049. if (!player->IsPlayer()) {
  8050. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8051. return 0;
  8052. }
  8053. if (!quest) {
  8054. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8055. return 0;
  8056. }
  8057. if (step == 0) {
  8058. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8059. return 0;
  8060. }
  8061. Client* client = player->GetZone()->GetClientBySpawn(player);
  8062. if (!client) {
  8063. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8064. return 0;
  8065. }
  8066. if (quest->RemoveQuestStep(step, client)) {
  8067. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8068. client->GetCurrentZone()->SendQuestUpdates(client);
  8069. }
  8070. else
  8071. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8072. return 0;
  8073. }
  8074. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8075. if (!lua_interface)
  8076. return 0;
  8077. Quest* quest = lua_interface->GetQuest(state, 1);
  8078. int32 step = lua_interface->GetInt32Value(state, 2);
  8079. string desc = lua_interface->GetStringValue(state, 3);
  8080. string task_group = lua_interface->GetStringValue(state, 4);
  8081. if (!quest) {
  8082. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8083. return 0;
  8084. }
  8085. if (step == 0) {
  8086. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8087. return 0;
  8088. }
  8089. QuestStep* quest_step = quest->GetQuestStep(step);
  8090. if (!quest_step) {
  8091. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8092. return 0;
  8093. }
  8094. quest_step->SetStepProgress(0);
  8095. quest_step->SetTaskGroup(task_group);
  8096. quest_step->SetDescription(desc);
  8097. return 0;
  8098. }
  8099. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8100. if (!lua_interface)
  8101. return 0;
  8102. Quest* quest = lua_interface->GetQuest(state);
  8103. int32 step = lua_interface->GetInt32Value(state, 2);
  8104. string action = lua_interface->GetStringValue(state, 3);
  8105. if (!quest) {
  8106. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8107. return 0;
  8108. }
  8109. if (step == 0) {
  8110. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8111. return 0;
  8112. }
  8113. if (action.length() == 0) {
  8114. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8115. return 0;
  8116. }
  8117. quest->AddFailedAction(step, action);
  8118. return 0;
  8119. }
  8120. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8121. if (!lua_interface)
  8122. return 0;
  8123. Spawn* player = lua_interface->GetSpawn(state);
  8124. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8125. int32 step = lua_interface->GetInt32Value(state, 3);
  8126. if (!player) {
  8127. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8128. return 0;
  8129. }
  8130. if (!player->IsPlayer()) {
  8131. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8132. return 0;
  8133. }
  8134. if (quest_id == 0) {
  8135. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8136. return 0;
  8137. }
  8138. if (step == 0) {
  8139. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8140. return 0;
  8141. }
  8142. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8143. if (!quest) {
  8144. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8145. return 0;
  8146. }
  8147. quest->StepFailed(step);
  8148. return 0;
  8149. }
  8150. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8151. if (!lua_interface)
  8152. return 0;
  8153. Spawn* player = lua_interface->GetSpawn(state);
  8154. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8155. if (!player) {
  8156. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8157. return 0;
  8158. }
  8159. if (!player->IsPlayer()) {
  8160. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8161. return 0;
  8162. }
  8163. if (quest_id == 0) {
  8164. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8165. return 0;
  8166. }
  8167. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8168. if (!quest) {
  8169. lua_interface->SetInt32Value(state, 0);
  8170. return 1;
  8171. }
  8172. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8173. return 1;
  8174. }
  8175. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8176. if (!lua_interface)
  8177. return 0;
  8178. string name = lua_interface->GetStringValue(state);
  8179. string value = lua_interface->GetStringValue(state, 2);
  8180. string comment = lua_interface->GetStringValue(state, 3);
  8181. if (name.length() == 0) {
  8182. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8183. return 0;
  8184. }
  8185. if (value.length() == 0) {
  8186. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8187. return 0;
  8188. }
  8189. string varname = string("lua_").append(name);
  8190. Variable* var = variables.FindVariable(varname);
  8191. if (var)
  8192. var->SetValue(value.c_str());
  8193. else {
  8194. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8195. variables.AddVariable(var);
  8196. }
  8197. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8198. return 0;
  8199. }
  8200. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8201. if (!lua_interface)
  8202. return 0;
  8203. string name = lua_interface->GetStringValue(state);
  8204. if (name.length() == 0) {
  8205. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8206. return 0;
  8207. }
  8208. string varname = string("lua_").append(name);
  8209. Variable* var = variables.FindVariable(varname);
  8210. if (var)
  8211. lua_interface->SetStringValue(state, var->GetValue());
  8212. else
  8213. lua_interface->SetStringValue(state, "NULL");
  8214. return 1;
  8215. }
  8216. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8217. if (!lua_interface)
  8218. return 0;
  8219. Spawn* player = lua_interface->GetSpawn(state);
  8220. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8221. if (!player) {
  8222. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8223. return 0;
  8224. }
  8225. if (!player->IsPlayer()) {
  8226. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8227. return 0;
  8228. }
  8229. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8230. return 1;
  8231. }
  8232. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8233. if (!lua_interface)
  8234. return 0;
  8235. Spawn* player = lua_interface->GetSpawn(state);
  8236. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8237. if (!player) {
  8238. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8239. return 0;
  8240. }
  8241. if (!player->IsPlayer()) {
  8242. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8243. return 0;
  8244. }
  8245. Language* language = master_languages_list.GetLanguage(language_id);
  8246. if (language)
  8247. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8248. return 0;
  8249. }
  8250. int EQ2Emu_lua_IsNight(lua_State* state) {
  8251. if (!lua_interface)
  8252. return 0;
  8253. ZoneServer* zone = lua_interface->GetZone(state);
  8254. if (!zone) {
  8255. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8256. return 0;
  8257. }
  8258. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8259. return 1;
  8260. }
  8261. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8262. if (!lua_interface)
  8263. return 0;
  8264. Spawn* spawn = lua_interface->GetSpawn(state);
  8265. if (!spawn) {
  8266. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8267. return 0;
  8268. }
  8269. if (!spawn->IsWidget()) {
  8270. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8271. return 0;
  8272. }
  8273. ((Widget*)spawn)->SetMultiFloorLift(true);
  8274. if (spawn->GetZone())
  8275. spawn->GetZone()->AddTransportSpawn(spawn);
  8276. return 0;
  8277. }
  8278. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8279. if (!lua_interface)
  8280. return 0;
  8281. Spawn* player = lua_interface->GetSpawn(state);
  8282. int32 path = lua_interface->GetInt32Value(state, 2);
  8283. if (!player) {
  8284. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8285. return 0;
  8286. }
  8287. if (!player->IsPlayer()) {
  8288. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8289. return 0;
  8290. }
  8291. if (path == 0) {
  8292. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8293. return 0;
  8294. }
  8295. Client* client = player->GetZone()->GetClientBySpawn(player);
  8296. if (!client) {
  8297. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8298. return 0;
  8299. }
  8300. client->SendFlightAutoMount(path);
  8301. return 0;
  8302. }
  8303. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8304. if (!lua_interface)
  8305. return 0;
  8306. Spawn* player = lua_interface->GetSpawn(state);
  8307. if (!player) {
  8308. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8309. return 0;
  8310. }
  8311. if (!player->IsPlayer()) {
  8312. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8313. return 0;
  8314. }
  8315. Client* client = player->GetZone()->GetClientBySpawn(player);
  8316. if (!client) {
  8317. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8318. return 0;
  8319. }
  8320. client->EndAutoMount();
  8321. return 0;
  8322. }
  8323. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8324. if (!lua_interface)
  8325. return 0;
  8326. Spawn* player = lua_interface->GetSpawn(state);
  8327. if (!player) {
  8328. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8329. return 0;
  8330. }
  8331. if (!player->IsPlayer()) {
  8332. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8333. return 0;
  8334. }
  8335. Client* client = player->GetZone()->GetClientBySpawn(player);
  8336. if (!client) {
  8337. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8338. return 0;
  8339. }
  8340. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8341. return 1;
  8342. }
  8343. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8344. if (!lua_interface)
  8345. return 0;
  8346. Spawn* player = lua_interface->GetSpawn(state);
  8347. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8348. int32 value = lua_interface->GetInt32Value(state, 3);
  8349. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8350. if (!player) {
  8351. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8352. return 0;
  8353. }
  8354. if (!player->IsPlayer()) {
  8355. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8356. return 0;
  8357. }
  8358. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8359. return 0;
  8360. }
  8361. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8362. if (!lua_interface)
  8363. return 0;
  8364. Spawn* player = lua_interface->GetSpawn(state);
  8365. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8366. if (!player) {
  8367. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8368. return 0;
  8369. }
  8370. if (!player->IsPlayer()) {
  8371. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8372. return 0;
  8373. }
  8374. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8375. if (!hd)
  8376. return 0;
  8377. lua_interface->SetInt32Value(state, hd->Value);
  8378. lua_interface->SetInt32Value(state, hd->Value2);
  8379. return 2;
  8380. }
  8381. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8382. if (!lua_interface)
  8383. return 0;
  8384. Spawn* spawn = lua_interface->GetSpawn(state);
  8385. int32 grid = lua_interface->GetInt32Value(state, 2);
  8386. if (!spawn) {
  8387. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8388. return 0;
  8389. }
  8390. if (grid == 0) {
  8391. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8392. return 0;
  8393. }
  8394. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8395. return 0;
  8396. }
  8397. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8398. if (!lua_interface)
  8399. return 0;
  8400. Spawn* spawn = lua_interface->GetSpawn(state);
  8401. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8402. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8403. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8404. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8405. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8406. if (!spawn) {
  8407. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8408. return 0;
  8409. }
  8410. //Add this quest to the list of required quests for this spawn
  8411. spawn->SetRequiredHistory(event_id, value1, value2);
  8412. //If private spawn value set
  8413. if (private_spawn) {
  8414. //Set the spawn to be private when not granted access via history
  8415. spawn->AddAllowAccessSpawn(spawn);
  8416. spawn->SetPrivateQuestSpawn(true);
  8417. }
  8418. //This value will override vis_flags in the vis packet
  8419. if (flag_override > 0)
  8420. spawn->SetQuestsRequiredOverride(flag_override);
  8421. return 0;
  8422. }
  8423. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8424. if (!lua_interface)
  8425. return 0;
  8426. Spawn* player = lua_interface->GetSpawn(state);
  8427. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8428. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8429. if (!player) {
  8430. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8431. return 0;
  8432. }
  8433. if (!player->IsPlayer()) {
  8434. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8435. return 0;
  8436. }
  8437. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8438. return 1;
  8439. }
  8440. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8441. if (!lua_interface)
  8442. return 0;
  8443. Spawn* player = lua_interface->GetSpawn(state);
  8444. int8 level = lua_interface->GetInt8Value(state, 2);
  8445. if (!player) {
  8446. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8447. return 0;
  8448. }
  8449. if (!player->IsPlayer()) {
  8450. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8451. return 0;
  8452. }
  8453. if (level == 0) {
  8454. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8455. return 0;
  8456. }
  8457. Client* client = player->GetZone()->GetClientBySpawn(player);
  8458. if (!client) {
  8459. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8460. return 0;
  8461. }
  8462. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8463. return 0;
  8464. }
  8465. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8466. if (!lua_interface)
  8467. return 0;
  8468. Spawn* player = lua_interface->GetSpawn(state);
  8469. int32 amount = lua_interface->GetInt32Value(state, 2);
  8470. if (!player) {
  8471. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8472. return 0;
  8473. }
  8474. if (!player->IsPlayer()) {
  8475. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8476. return 0;
  8477. }
  8478. if (amount == 0) {
  8479. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8480. return 0;
  8481. }
  8482. ((Player*)player)->AddCoins(amount);
  8483. return 0;
  8484. }
  8485. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8486. if (!lua_interface)
  8487. return 0;
  8488. Spawn* player = lua_interface->GetSpawn(state);
  8489. int32 amount = lua_interface->GetInt32Value(state, 2);
  8490. if (!player) {
  8491. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8492. return 0;
  8493. }
  8494. if (!player->IsPlayer()) {
  8495. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8496. return 0;
  8497. }
  8498. if (amount == 0) {
  8499. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8500. return 0;
  8501. }
  8502. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8503. return 1;
  8504. }
  8505. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8506. if (!lua_interface)
  8507. return 0;
  8508. ZoneServer* zone = lua_interface->GetZone(state);
  8509. if (!zone) {
  8510. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8511. return 0;
  8512. }
  8513. vector<Entity*> players = zone->GetPlayers();
  8514. if (players.size() == 0)
  8515. return 0;
  8516. lua_createtable(state, players.size(), 0);
  8517. int newTable = lua_gettop(state);
  8518. for (int32 i = 0; i < players.size(); i++) {
  8519. lua_interface->SetSpawnValue(state, players.at(i));
  8520. lua_rawseti(state, newTable, i + 1);
  8521. }
  8522. return 1;
  8523. }
  8524. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8525. if (!lua_interface)
  8526. return 0;
  8527. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8528. if (!zone) {
  8529. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8530. return 0;
  8531. }
  8532. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8533. //Map of <placement_id, location_id>
  8534. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8535. map<int32, int32>::iterator itr;
  8536. vector<Spawn*> group;
  8537. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8538. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8539. if (!location) {
  8540. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8541. return 0;
  8542. }
  8543. Spawn* spawn = 0;
  8544. if (location->entities[0]) {
  8545. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8546. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8547. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8548. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8549. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8550. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8551. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8552. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8553. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8554. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8555. if (spawn) {
  8556. const char* script = 0;
  8557. for (int x = 0; x < 3; x++) {
  8558. switch (x) {
  8559. case 0:
  8560. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8561. break;
  8562. case 1:
  8563. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8564. break;
  8565. case 2:
  8566. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8567. break;
  8568. }
  8569. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8570. spawn->SetSpawnScript(string(script));
  8571. break;
  8572. }
  8573. }
  8574. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8575. lua_interface->SetSpawnValue(state, spawn);
  8576. group.push_back(spawn);
  8577. }
  8578. else {
  8579. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8580. safe_delete(spawn);
  8581. }
  8582. }
  8583. }
  8584. if (!group.empty()) {
  8585. lua_createtable(state, group.size(), 0);
  8586. int newTable = lua_gettop(state);
  8587. for (int32 i = 0; i < group.size(); i++) {
  8588. lua_interface->SetSpawnValue(state, group[i]);
  8589. lua_rawseti(state, newTable, i + 1);
  8590. }
  8591. }
  8592. else
  8593. lua_pushnil(state);
  8594. return 1;
  8595. }
  8596. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8597. if (!lua_interface)
  8598. return 0;
  8599. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8600. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8601. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8602. if (!spawn) {
  8603. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8604. return 0;
  8605. }
  8606. if (anim_id == 0) {
  8607. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8608. return 0;
  8609. }
  8610. if (leeway == 0)
  8611. leeway = 5000;
  8612. spawn->SetSpawnAnim(anim_id);
  8613. spawn->SetSpawnAnimLeeway(leeway);
  8614. return 0;
  8615. }
  8616. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8617. if (!lua_interface)
  8618. return 0;
  8619. Spawn* player = lua_interface->GetSpawn(state);
  8620. if (!player) {
  8621. return 0;
  8622. }
  8623. Client* client = player->GetZone()->GetClientBySpawn(player);
  8624. if (!client) {
  8625. return 0;
  8626. }
  8627. lua_interface->SetInt32Value(state, client->GetVersion());
  8628. return 1;
  8629. }
  8630. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8631. if (!lua_interface)
  8632. return 0;
  8633. Item* item = lua_interface->GetItem(state);
  8634. if (!item) {
  8635. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8636. return 0;
  8637. }
  8638. lua_interface->SetInt32Value(state, item->details.item_id);
  8639. return 1;
  8640. }
  8641. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8642. if (!lua_interface)
  8643. return 0;
  8644. Spawn* spawn = lua_interface->GetSpawn(state);
  8645. if (!spawn) {
  8646. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8647. return 0;
  8648. }
  8649. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8650. return 1;
  8651. }
  8652. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8653. if (!lua_interface)
  8654. return 0;
  8655. Spawn* spawn = lua_interface->GetSpawn(state);
  8656. if (!spawn) {
  8657. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8658. return 0;
  8659. }
  8660. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8661. return 1;
  8662. }
  8663. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8664. if (!lua_interface)
  8665. return 0;
  8666. Spawn* spawn = lua_interface->GetSpawn(state);
  8667. if (!spawn) {
  8668. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8669. return 0;
  8670. }
  8671. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8672. return 1;
  8673. }
  8674. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8675. if (!lua_interface)
  8676. return 0;
  8677. Spawn* spawn = lua_interface->GetSpawn(state);
  8678. if (!spawn) {
  8679. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8680. return 0;
  8681. }
  8682. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8683. return 1;
  8684. }
  8685. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8686. if (!lua_interface)
  8687. return 0;
  8688. Spawn* spawn = lua_interface->GetSpawn(state);
  8689. float pct = lua_interface->GetFloatValue(state, 2);
  8690. if (!spawn) {
  8691. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8692. return 0;
  8693. }
  8694. if (pct == 0) {
  8695. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8696. return 0;
  8697. }
  8698. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8699. lua_interface->SetInt32Value(state, amount);
  8700. return 1;
  8701. }
  8702. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8703. if (!lua_interface)
  8704. return 0;
  8705. Spawn* spawn = lua_interface->GetSpawn(state);
  8706. float pct = lua_interface->GetFloatValue(state, 2);
  8707. if (!spawn) {
  8708. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8709. return 0;
  8710. }
  8711. if (pct == 0) {
  8712. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8713. return 0;
  8714. }
  8715. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8716. lua_interface->SetInt32Value(state, amount);
  8717. return 1;
  8718. }
  8719. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8720. if (!lua_interface)
  8721. return 0;
  8722. Spawn* spawn = lua_interface->GetSpawn(state);
  8723. if (!spawn) {
  8724. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8725. return 0;
  8726. }
  8727. if (!spawn->IsPlayer()) {
  8728. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8729. return 0;
  8730. }
  8731. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8732. return 1;
  8733. }
  8734. int EQ2Emu_lua_Evac(lua_State* state) {
  8735. if (!lua_interface)
  8736. return 0;
  8737. Spawn* target = lua_interface->GetSpawn(state);
  8738. if (target) {
  8739. float x = target->GetZone()->GetSafeX();
  8740. float y = target->GetZone()->GetSafeY();
  8741. float z = target->GetZone()->GetSafeZ();
  8742. float h = target->GetZone()->GetSafeHeading();
  8743. target->SetX(x);
  8744. target->SetY(y);
  8745. target->SetZ(z);
  8746. target->SetHeading(h);
  8747. target->SetSpawnOrigX(target->GetX());
  8748. target->SetSpawnOrigY(target->GetY());
  8749. target->SetSpawnOrigZ(target->GetZ());
  8750. target->SetSpawnOrigHeading(target->GetHeading());
  8751. if (target->IsPlayer()) {
  8752. Client* client = target->GetZone()->GetClientBySpawn(target);
  8753. if (client) {
  8754. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8755. if (packet)
  8756. {
  8757. packet->setDataByName("x", x);
  8758. packet->setDataByName("y", y);
  8759. packet->setDataByName("z", z);
  8760. client->QueuePacket(packet->serialize());
  8761. safe_delete(packet);
  8762. }
  8763. }
  8764. }
  8765. }
  8766. else {
  8767. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8768. ZoneServer* zone = spell->caster->GetZone();
  8769. float x = spell->caster->GetZone()->GetSafeX();
  8770. float y = spell->caster->GetZone()->GetSafeY();
  8771. float z = spell->caster->GetZone()->GetSafeZ();
  8772. float h = spell->caster->GetZone()->GetSafeHeading();
  8773. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8774. for (int32 i = 0; i < spell->targets.size(); i++) {
  8775. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8776. if (!target2)
  8777. continue;
  8778. target2->SetX(x);
  8779. target2->SetY(y);
  8780. target2->SetZ(z);
  8781. target2->SetHeading(h);
  8782. target2->SetSpawnOrigX(target2->GetX());
  8783. target2->SetSpawnOrigY(target2->GetY());
  8784. target2->SetSpawnOrigZ(target2->GetZ());
  8785. target2->SetSpawnOrigHeading(target2->GetHeading());
  8786. if (target2->IsPlayer()) {
  8787. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8788. if (client) {
  8789. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8790. if (packet)
  8791. {
  8792. client->SetReloadingZone(true);
  8793. packet->setDataByName("x", x);
  8794. packet->setDataByName("y", y);
  8795. packet->setDataByName("z", z);
  8796. client->QueuePacket(packet->serialize());
  8797. safe_delete(packet);
  8798. }
  8799. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8800. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8801. }
  8802. }
  8803. }
  8804. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8805. }
  8806. return 0;
  8807. }
  8808. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8809. if (!lua_interface)
  8810. return 0;
  8811. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8812. if (!luaspell) {
  8813. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8814. return 0;
  8815. }
  8816. int8 tier = luaspell->spell->GetSpellTier();
  8817. lua_interface->SetInt32Value(state, tier);
  8818. return 1;
  8819. }
  8820. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8821. if (!lua_interface)
  8822. return 0;
  8823. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8824. if (!luaspell) {
  8825. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8826. return 0;
  8827. }
  8828. int32 spell_id = luaspell->spell->GetSpellID();
  8829. lua_interface->SetInt32Value(state, spell_id);
  8830. return 1;
  8831. }
  8832. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8833. if (!lua_interface)
  8834. return 0;
  8835. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8836. if (!spawn) {
  8837. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8838. return 0;
  8839. }
  8840. if (!spawn->IsPlayer()) {
  8841. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8842. return 0;
  8843. }
  8844. ZoneServer* zone = spawn->GetZone();
  8845. if (!zone) {
  8846. return 0;
  8847. }
  8848. Client* client = zone->GetClientBySpawn(spawn);
  8849. if (!client) {
  8850. return 0;
  8851. }
  8852. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8853. return 0;
  8854. }
  8855. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8856. if (!lua_interface)
  8857. return 0;
  8858. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8859. if (!spawn) {
  8860. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8861. return 0;
  8862. }
  8863. if (!spawn->IsPlayer()) {
  8864. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8865. return 0;
  8866. }
  8867. ZoneServer* zone = spawn->GetZone();
  8868. if (!zone) {
  8869. return 0;
  8870. }
  8871. Client* client = zone->GetClientBySpawn(spawn);
  8872. if (!client) {
  8873. return 0;
  8874. }
  8875. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8876. return 0;
  8877. }
  8878. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8879. if (!lua_interface)
  8880. return 0;
  8881. Spawn* caster = lua_interface->GetSpawn(state);
  8882. Spawn* target = lua_interface->GetSpawn(state, 2);
  8883. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8884. string spell_name = lua_interface->GetStringValue(state, 4);
  8885. if (!caster) {
  8886. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8887. return 0;
  8888. }
  8889. if (!caster->IsEntity()) {
  8890. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8891. return 0;
  8892. }
  8893. if (!target) {
  8894. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8895. return 0;
  8896. }
  8897. if (!target->IsEntity()) {
  8898. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8899. return 0;
  8900. }
  8901. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8902. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8903. return 0;
  8904. }
  8905. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8906. if (!lua_interface)
  8907. return 0;
  8908. Spawn* player = lua_interface->GetSpawn(state);
  8909. int32 amount = lua_interface->GetInt32Value(state, 2);
  8910. if (player && player->IsPlayer() && amount > 0) {
  8911. ((Player*)player)->AddXP(amount);
  8912. ((Player*)player)->SetCharSheetChanged(true);
  8913. Client* client = player->GetZone()->GetClientBySpawn(player);
  8914. if (client) {
  8915. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8916. }
  8917. }
  8918. return 0;
  8919. }
  8920. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8921. if (!lua_interface)
  8922. return 0;
  8923. Spawn* player = lua_interface->GetSpawn(state);
  8924. int8 type = lua_interface->GetInt8Value(state, 2);
  8925. string text = lua_interface->GetStringValue(state, 3);
  8926. Client* client = 0;
  8927. if (player && player->IsPlayer())
  8928. client = player->GetZone()->GetClientBySpawn(player);
  8929. if (!client || text.length() == 0) {
  8930. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8931. return 0;
  8932. }
  8933. client->SimpleMessage(type, text.c_str());
  8934. return 0;
  8935. }
  8936. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8937. if (!lua_interface)
  8938. return 0;
  8939. Spawn* player = lua_interface->GetSpawn(state);
  8940. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8941. Client* client = 0;
  8942. if (player && player->IsPlayer())
  8943. client = player->GetZone()->GetClientBySpawn(player);
  8944. if (!client || !spawn) {
  8945. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8946. return 0;
  8947. }
  8948. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8949. if (!items) {
  8950. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8951. return 0;
  8952. }
  8953. client->Loot(spawn->GetLootCoins(), items, spawn);
  8954. return 0;
  8955. }
  8956. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8957. if (!lua_interface)
  8958. return 0;
  8959. Spawn* spawnref = lua_interface->GetSpawn(state);
  8960. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8961. if (spawn_id > 0 && spawnref) {
  8962. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8963. if (spawns.size() == 0) {
  8964. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8965. return 0;
  8966. }
  8967. Spawn* spawn = 0;
  8968. int16 index = MakeRandomInt(0, spawns.size());
  8969. if (index >= spawns.size() || index < 0)
  8970. index = 0;
  8971. spawn = spawns[index];
  8972. lua_interface->SetSpawnValue(state, spawn);
  8973. return 1;
  8974. }
  8975. else {
  8976. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8977. }
  8978. return 0;
  8979. }
  8980. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8981. Spawn* player = lua_interface->GetSpawn(state);
  8982. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8983. string name = lua_interface->GetStringValue(state, 3);
  8984. float distance = lua_interface->GetFloatValue(state, 4);
  8985. string command = lua_interface->GetStringValue(state, 5);
  8986. string error_text = lua_interface->GetStringValue(state, 6);
  8987. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8988. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  8989. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  8990. if (distance == 0)
  8991. distance = 10.0f;
  8992. if (command.length() == 0)
  8993. command = name;
  8994. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  8995. if (spawns.size() == 0) {
  8996. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8997. return 0;
  8998. }
  8999. Spawn* spawn = 0;
  9000. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9001. spawn = *itr;
  9002. if (spawn) {
  9003. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9004. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9005. }
  9006. }
  9007. }
  9008. return 0;
  9009. }
  9010. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9011. if (!lua_interface)
  9012. return 0;
  9013. Client* client = 0;
  9014. Spawn* player = lua_interface->GetSpawn(state);
  9015. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9016. if (player && player->IsPlayer() && player->GetZone())
  9017. client = player->GetZone()->GetClientBySpawn(player);
  9018. else{
  9019. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9020. return 0;
  9021. }
  9022. if (client) {
  9023. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9024. if (packet) {
  9025. packet->setDataByName("goal_num", goal_num);
  9026. client->QueuePacket(packet->serialize());
  9027. safe_delete(packet);
  9028. }
  9029. }
  9030. return 0;
  9031. }
  9032. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9033. if (!lua_interface)
  9034. return 0;
  9035. Client* client = 0;
  9036. Spawn* player = lua_interface->GetSpawn(state);
  9037. if (player && player->IsPlayer() && player->GetZone())
  9038. client = player->GetZone()->GetClientBySpawn(player);
  9039. else {
  9040. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9041. return 0;
  9042. }
  9043. if (client) {
  9044. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9045. }
  9046. return 0;
  9047. }
  9048. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9049. if (!lua_interface)
  9050. return 0;
  9051. Client* client = 0;
  9052. Spawn* player = lua_interface->GetSpawn(state);
  9053. float duration = lua_interface->GetFloatValue(state, 2);
  9054. string text = lua_interface->GetStringValue(state, 3);
  9055. string voice = lua_interface->GetStringValue(state, 4);
  9056. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9057. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9058. string signal = lua_interface->GetStringValue(state, 7);
  9059. string goal1 = lua_interface->GetStringValue(state, 8);
  9060. string task1 = lua_interface->GetStringValue(state, 9);
  9061. string goal2 = lua_interface->GetStringValue(state, 10);
  9062. string task2 = lua_interface->GetStringValue(state, 11);
  9063. string goal3 = lua_interface->GetStringValue(state, 12);
  9064. string task3 = lua_interface->GetStringValue(state, 13);
  9065. string goal4 = lua_interface->GetStringValue(state, 14);
  9066. string task4 = lua_interface->GetStringValue(state, 15);
  9067. if (!player) {
  9068. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9069. return 0;
  9070. }
  9071. if (!player->IsPlayer()) {
  9072. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9073. return 0;
  9074. }
  9075. else
  9076. client = ((Player*)player)->GetClient();
  9077. if (!client) {
  9078. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9079. return 0;
  9080. }
  9081. if (text.length() == 0) {
  9082. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9083. return 0;
  9084. }
  9085. if (duration >= 0 && duration < 2)
  9086. duration = 2;
  9087. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9088. if (packet) {
  9089. packet->setDataByName("open_seconds_max", duration);
  9090. packet->setDataByName("text", text.c_str());
  9091. packet->setDataByName("voice", voice.c_str());
  9092. int8 num_goals = 1;
  9093. if (task2.length() > 0)
  9094. num_goals++;
  9095. if (task3.length() > 0)
  9096. num_goals++;
  9097. if (task4.length() > 0)
  9098. num_goals++;
  9099. packet->setArrayLengthByName("num_goals", num_goals);
  9100. for (int8 i = 0; i < num_goals; i++) {
  9101. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9102. }
  9103. if (goal1.length() > 0)
  9104. packet->setArrayDataByName("goal_text", goal1.c_str());
  9105. if (goal2.length() > 0)
  9106. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9107. if (goal3.length() > 0)
  9108. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9109. if (goal4.length() > 0)
  9110. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9111. packet->setSubArrayDataByName("task_text", task1.c_str());
  9112. if (task2.length() > 0)
  9113. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9114. if (task3.length() > 0)
  9115. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9116. if (task4.length() > 0)
  9117. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9118. packet->setDataByName("complete_sound", "click");
  9119. packet->setDataByName("signal", signal.c_str());
  9120. packet->setDataByName("voice_key1", voice_key1);
  9121. packet->setDataByName("voice_key2", voice_key2);
  9122. client->QueuePacket(packet->serialize());
  9123. safe_delete(packet);
  9124. }
  9125. return 0;
  9126. }
  9127. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9128. if (!lua_interface)
  9129. return 0;
  9130. Client* client = 0;
  9131. Spawn* player = lua_interface->GetSpawn(state);
  9132. string window = lua_interface->GetStringValue(state, 2);
  9133. int8 show = lua_interface->GetInt8Value(state, 3);
  9134. if (!player) {
  9135. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9136. return 0;
  9137. }
  9138. if (!player->IsPlayer()) {
  9139. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9140. return 0;
  9141. }
  9142. else
  9143. client = ((Player*)player)->GetClient();
  9144. if (!client) {
  9145. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9146. return 0;
  9147. }
  9148. if (window.length() == 0) {
  9149. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9150. return 0;
  9151. }
  9152. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9153. if (packet) {
  9154. packet->setDataByName("window", window.c_str());
  9155. packet->setDataByName("show", show);
  9156. client->QueuePacket(packet->serialize());
  9157. safe_delete(packet);
  9158. }
  9159. return 0;
  9160. }
  9161. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9162. //See GameEvents.txt for options that can be used for this function
  9163. if (!lua_interface)
  9164. return 0;
  9165. Client* client = 0;
  9166. Spawn* player = lua_interface->GetSpawn(state);
  9167. string event_name = lua_interface->GetStringValue(state, 2);
  9168. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9169. if (!player || !player->IsPlayer()) {
  9170. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9171. return 0;
  9172. }
  9173. if (player->GetZone())
  9174. client = player->GetZone()->GetClientBySpawn(player);
  9175. if (!client) {
  9176. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9177. return 0;
  9178. }
  9179. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9180. if (packet) {
  9181. packet->setDataByName("event_name", event_name.c_str());
  9182. packet->setDataByName("enabled", enabled);
  9183. client->QueuePacket(packet->serialize());
  9184. safe_delete(packet);
  9185. }
  9186. return 0;
  9187. }
  9188. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9189. if (!lua_interface)
  9190. return 0;
  9191. Spawn* player = lua_interface->GetSpawn(state);
  9192. if (player && player->IsPlayer()) {
  9193. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9194. return 1;
  9195. }
  9196. return 0;
  9197. }
  9198. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9199. if (!lua_interface)
  9200. return 0;
  9201. Spawn* player = lua_interface->GetSpawn(state);
  9202. int8 step = lua_interface->GetInt8Value(state, 2);
  9203. if (player && player->IsPlayer() && step > 0) {
  9204. ((Player*)player)->SetTutorialStep(step);
  9205. }
  9206. return 0;
  9207. }
  9208. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9209. if (!lua_interface)
  9210. return 0;
  9211. Client* client = 0;
  9212. Spawn* player = lua_interface->GetSpawn(state);
  9213. string window = lua_interface->GetStringValue(state, 2);
  9214. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9215. if (!player) {
  9216. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9217. return 0;
  9218. }
  9219. if (!player->IsPlayer()) {
  9220. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9221. return 0;
  9222. }
  9223. else
  9224. client = ((Player*)player)->GetClient();
  9225. if (!client) {
  9226. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9227. return 0;
  9228. }
  9229. if (window.length() == 0) {
  9230. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9231. return 0;
  9232. }
  9233. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9234. if (packet) {
  9235. packet->setDataByName("window", window.c_str());
  9236. packet->setDataByName("flash_seconds", flash_seconds);
  9237. client->QueuePacket(packet->serialize());
  9238. safe_delete(packet);
  9239. }
  9240. return 0;
  9241. }
  9242. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9243. if (!lua_interface)
  9244. return 0;
  9245. Spawn* spawn = lua_interface->GetSpawn(state);
  9246. Spawn* target = lua_interface->GetSpawn(state, 2);
  9247. if (spawn && target)
  9248. return spawn->CheckLoS(target);
  9249. return 0;
  9250. }
  9251. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9252. if (!lua_interface)
  9253. return 0;
  9254. Spawn* spawn = lua_interface->GetSpawn(state);
  9255. float x = lua_interface->GetFloatValue(state, 2);
  9256. float y = lua_interface->GetFloatValue(state, 3);
  9257. float z = lua_interface->GetFloatValue(state, 4);
  9258. if (spawn)
  9259. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9260. return 0;
  9261. }
  9262. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9263. if (!lua_interface)
  9264. return 0;
  9265. ZoneServer* zone = lua_interface->GetZone(state);
  9266. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9267. if (zone)
  9268. zone->SetExpansionFlag(xpackFlag);
  9269. return 0;
  9270. }
  9271. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9272. if (!lua_interface)
  9273. return 0;
  9274. ZoneServer* zone = lua_interface->GetZone(state);
  9275. if (zone) {
  9276. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9277. return 1;
  9278. }
  9279. return 0;
  9280. }
  9281. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9282. if (!lua_interface)
  9283. return 0;
  9284. ZoneServer* zone = lua_interface->GetZone(state);
  9285. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9286. if (zone)
  9287. zone->SetHolidayFlag(holidayFlag);
  9288. return 0;
  9289. }
  9290. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9291. if (!lua_interface)
  9292. return 0;
  9293. ZoneServer* zone = lua_interface->GetZone(state);
  9294. if (zone) {
  9295. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9296. return 1;
  9297. }
  9298. return 0;
  9299. }
  9300. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9301. if (!lua_interface)
  9302. return 0;
  9303. Spawn* spawn = lua_interface->GetSpawn(state);
  9304. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9305. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9306. float distance = lua_interface->GetFloatValue(state, 4);
  9307. string in_range_function = lua_interface->GetStringValue(state, 5);
  9308. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9309. if (spawn && distance > 0 && in_range_function.length() > 0)
  9310. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9311. return 0;
  9312. }
  9313. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9314. if (!lua_interface)
  9315. return 0;
  9316. Spawn* spawn = lua_interface->GetSpawn(state);
  9317. Spawn* target = lua_interface->GetSpawn(state, 2);
  9318. if (spawn && target)
  9319. {
  9320. if (spawn->IsPlayer() && target->IsEntity())
  9321. {
  9322. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9323. return 1;
  9324. }
  9325. else if (spawn->IsEntity() && target->IsEntity())
  9326. {
  9327. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9328. return 1;
  9329. }
  9330. }
  9331. return 0;
  9332. }
  9333. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9334. if (!lua_interface)
  9335. return 0;
  9336. Spawn* spawn = lua_interface->GetSpawn(state);
  9337. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9338. if (spawn && spawn->IsEntity())
  9339. {
  9340. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9341. if (spawn->IsPlayer())
  9342. {
  9343. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9344. if (client)
  9345. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9346. }
  9347. }
  9348. return 0;
  9349. }
  9350. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9351. if (!lua_interface)
  9352. return 0;
  9353. Spawn* spawn = lua_interface->GetSpawn(state);
  9354. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9355. if (spawn && spawn->IsEntity())
  9356. {
  9357. ((Entity*)spawn)->SetSeeHideSpell(val);
  9358. if (spawn->IsPlayer())
  9359. {
  9360. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9361. if (client)
  9362. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9363. }
  9364. }
  9365. return 0;
  9366. }
  9367. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9368. {
  9369. if (!lua_interface)
  9370. return 0;
  9371. Spawn* player = lua_interface->GetSpawn(state);
  9372. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9373. string command = lua_interface->GetStringValue(state, 3);
  9374. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9375. if (spawn && player && player->IsPlayer())
  9376. {
  9377. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9378. bool res = false;
  9379. if (cmd)
  9380. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9381. lua_interface->SetBooleanValue(state, res);
  9382. return 1;
  9383. }
  9384. return 0;
  9385. }
  9386. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9387. {
  9388. if (!lua_interface)
  9389. return 0;
  9390. Spawn* spawn = lua_interface->GetSpawn(state);
  9391. string command = lua_interface->GetStringValue(state, 2);
  9392. if (spawn && command.length() > 0)
  9393. spawn->RemovePrimaryEntityCommand(command.c_str());
  9394. return 0;
  9395. }
  9396. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9397. if (!lua_interface)
  9398. return 0;
  9399. Spawn* spawn = lua_interface->GetSpawn(state);
  9400. float distance = lua_interface->GetFloatValue(state, 2);
  9401. string command = lua_interface->GetStringValue(state, 3);
  9402. Spawn* player = lua_interface->GetSpawn(state, 4);
  9403. if (spawn) {
  9404. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9405. }
  9406. return 0;
  9407. }
  9408. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9409. if (!lua_interface)
  9410. return 0;
  9411. Spawn* spawn = lua_interface->GetSpawn(state);
  9412. Spawn* player = lua_interface->GetSpawn(state, 2);
  9413. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9414. if (spawn && player && transport_id && player->IsPlayer()) {
  9415. Client* client = 0;
  9416. if (player && player->IsPlayer())
  9417. client = player->GetZone()->GetClientBySpawn(player);
  9418. if (!client)
  9419. return 0;
  9420. vector<TransportDestination*> destinations;
  9421. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9422. if (destinations.size())
  9423. {
  9424. client->SetTemporaryTransportID(transport_id);
  9425. client->ProcessTeleport(spawn, &destinations, transport_id);
  9426. }
  9427. else
  9428. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9429. }
  9430. return 0;
  9431. }
  9432. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9433. if (!lua_interface)
  9434. return 0;
  9435. Spawn* player = lua_interface->GetSpawn(state);
  9436. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9437. if (player && player->IsPlayer()) {
  9438. Client* client = 0;
  9439. if (player && player->IsPlayer())
  9440. client = player->GetZone()->GetClientBySpawn(player);
  9441. if (!client)
  9442. return 0;
  9443. client->SetTemporaryTransportID(transport_id);
  9444. }
  9445. return 0;
  9446. }
  9447. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9448. if (!lua_interface)
  9449. return 0;
  9450. Spawn* player = lua_interface->GetSpawn(state);
  9451. if (player && player->IsPlayer()) {
  9452. Client* client = 0;
  9453. if (player && player->IsPlayer())
  9454. client = player->GetZone()->GetClientBySpawn(player);
  9455. if (!client)
  9456. return 0;
  9457. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9458. return 1;
  9459. }
  9460. return 0;
  9461. }
  9462. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9463. if (!lua_interface)
  9464. return 0;
  9465. Spawn* spawn = lua_interface->GetSpawn(state);
  9466. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9467. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9468. if (!spawn) {
  9469. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9470. return 0;
  9471. }
  9472. if (!spawn->IsEntity()) {
  9473. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9474. return 0;
  9475. }
  9476. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9477. {
  9478. 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);
  9479. return 0;
  9480. }
  9481. if (spell && spell->targets.size() > 0) {
  9482. ZoneServer* zone = spell->caster->GetZone();
  9483. for (int8 i = 0; i < spell->targets.size(); i++) {
  9484. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9485. if (target->IsEntity()) {
  9486. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9487. if (target->IsPlayer())
  9488. ((Player*)target)->SetCharSheetChanged(true);
  9489. }
  9490. }
  9491. }
  9492. else {
  9493. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9494. if (spawn->IsPlayer())
  9495. ((Player*)spawn)->SetCharSheetChanged(true);
  9496. }
  9497. return 0;
  9498. }
  9499. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9500. if (!lua_interface)
  9501. return 0;
  9502. Spawn* spawn = lua_interface->GetSpawn(state);
  9503. if (!spawn) {
  9504. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9505. return 0;
  9506. }
  9507. if (!spawn->IsEntity()) {
  9508. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9509. return 0;
  9510. }
  9511. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9512. return 1;
  9513. }
  9514. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9515. if (!lua_interface)
  9516. return 0;
  9517. int32 spell_id = lua_interface->GetInt32Value(state);
  9518. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9519. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9520. if (spell_id > 0) {
  9521. if (spell_tier == 0)
  9522. spell_tier = 1;
  9523. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9524. LuaSpell* lua_spell = 0;
  9525. if(custom_lua_script.size() < 1)
  9526. custom_lua_script = spell->GetSpellData()->lua_script;
  9527. if (lua_interface)
  9528. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9529. if (!lua_spell)
  9530. return 0;
  9531. lua_spell->spell = new Spell(spell);
  9532. lua_interface->AddCustomSpell(lua_spell);
  9533. lua_interface->SetSpellValue(state, lua_spell);
  9534. return 1;
  9535. }
  9536. return 0;
  9537. }
  9538. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9539. if (!lua_interface)
  9540. return 0;
  9541. LuaSpell* spell = lua_interface->GetSpell(state);
  9542. string field = lua_interface->GetStringValue(state, 2);
  9543. if (!spell) {
  9544. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9545. return 0;
  9546. }
  9547. if (!spell->spell || !spell->spell->GetSpellData()) {
  9548. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9549. return 0;
  9550. }
  9551. boost::to_lower(field);
  9552. return spell->spell->GetSpellData(state, field);
  9553. }
  9554. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9555. if (!lua_interface)
  9556. return 0;
  9557. LuaSpell* spell = lua_interface->GetSpell(state);
  9558. string field = lua_interface->GetStringValue(state, 2);
  9559. int8 fieldArg = 3; // field value after the initial set
  9560. if (!spell) {
  9561. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9562. return 0;
  9563. }
  9564. if (!spell->spell || !spell->spell->GetSpellData()) {
  9565. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9566. return 0;
  9567. }
  9568. boost::to_lower(field);
  9569. bool valSet = false;
  9570. spell->spell->SetSpellData(state, field, fieldArg);
  9571. return valSet;
  9572. }
  9573. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9574. if (!lua_interface)
  9575. return 0;
  9576. LuaSpell* spell = lua_interface->GetSpell(state);
  9577. int8 idx = lua_interface->GetInt32Value(state, 2);
  9578. if (!spell) {
  9579. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9580. return 0;
  9581. }
  9582. if (!spell->spell || !spell->spell->GetSpellData()) {
  9583. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9584. return 0;
  9585. }
  9586. if (spell->spell->lua_data.size() <= idx)
  9587. {
  9588. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9589. return 0;
  9590. }
  9591. bool setVal = true;
  9592. LUAData* data = spell->spell->lua_data[idx];
  9593. switch (data->type)
  9594. {
  9595. case 0:
  9596. {
  9597. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9598. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9599. data->int_value = value;
  9600. data->int_value2 = value2;
  9601. break;
  9602. }
  9603. case 1:
  9604. {
  9605. float value = lua_interface->GetFloatValue(state, 3);
  9606. float value2 = lua_interface->GetFloatValue(state, 4);
  9607. data->float_value = value;
  9608. data->float_value2 = value2;
  9609. break;
  9610. }
  9611. case 2:
  9612. {
  9613. bool value = lua_interface->GetBooleanValue(state, 3);
  9614. data->bool_value = value;
  9615. break;
  9616. }
  9617. case 3:
  9618. {
  9619. string value = lua_interface->GetStringValue(state, 3);
  9620. string value2 = lua_interface->GetStringValue(state, 4);
  9621. data->string_value = value;
  9622. data->string_value2 = value2;
  9623. break;
  9624. }
  9625. default:
  9626. setVal = false;
  9627. }
  9628. return setVal;
  9629. }
  9630. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9631. if (!lua_interface)
  9632. return 0;
  9633. LuaSpell* spell = lua_interface->GetSpell(state);
  9634. int8 idx = lua_interface->GetInt32Value(state, 2);
  9635. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9636. if (!spell) {
  9637. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9638. return 0;
  9639. }
  9640. if (!spell->spell || !spell->spell->GetSpellData()) {
  9641. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9642. return 0;
  9643. }
  9644. if (spell->spell->lua_data.size() <= idx)
  9645. {
  9646. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9647. return 0;
  9648. }
  9649. bool setVal = true;
  9650. LUAData* data = spell->spell->lua_data[idx];
  9651. switch (data->type)
  9652. {
  9653. case 0:
  9654. {
  9655. if(!secondfield)
  9656. lua_interface->SetSInt32Value(state, data->int_value);
  9657. else
  9658. lua_interface->SetSInt32Value(state, data->int_value2);
  9659. break;
  9660. }
  9661. case 1:
  9662. {
  9663. if (!secondfield)
  9664. lua_interface->SetFloatValue(state, data->float_value);
  9665. else
  9666. lua_interface->SetFloatValue(state, data->float_value2);
  9667. break;
  9668. }
  9669. case 2:
  9670. {
  9671. lua_interface->SetBooleanValue(state, data->bool_value);
  9672. break;
  9673. }
  9674. case 3:
  9675. {
  9676. if (!secondfield)
  9677. lua_interface->SetStringValue(state, data->string_value.c_str());
  9678. else
  9679. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9680. break;
  9681. }
  9682. default:
  9683. setVal = false;
  9684. }
  9685. return setVal;
  9686. }
  9687. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9688. if (!lua_interface)
  9689. return 0;
  9690. LuaSpell* spell = lua_interface->GetSpell(state);
  9691. int8 idx = lua_interface->GetInt32Value(state, 2);
  9692. string field = lua_interface->GetStringValue(state, 3);
  9693. boost::to_lower(field);
  9694. if (!spell) {
  9695. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9696. return 0;
  9697. }
  9698. if (!spell->spell || !spell->spell->GetSpellData()) {
  9699. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9700. return 0;
  9701. }
  9702. if (spell->spell->effects.size() <= idx)
  9703. {
  9704. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9705. return 0;
  9706. }
  9707. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9708. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9709. if (field == "description")
  9710. effect->description = string(lua_interface->GetStringValue(state, 4));
  9711. else if (field == "bullet")
  9712. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9713. else if (field == "percentage")
  9714. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9715. else // no match
  9716. return 0;
  9717. return 1;
  9718. }
  9719. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9720. if (!lua_interface)
  9721. return 0;
  9722. LuaSpell* spell = lua_interface->GetSpell(state);
  9723. int8 idx = lua_interface->GetInt32Value(state, 2);
  9724. string field = lua_interface->GetStringValue(state, 3);
  9725. boost::to_lower(field);
  9726. if (!spell) {
  9727. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9728. return 0;
  9729. }
  9730. if (!spell->spell || !spell->spell->GetSpellData()) {
  9731. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9732. return 0;
  9733. }
  9734. if (spell->spell->effects.size() <= idx)
  9735. {
  9736. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9737. return 0;
  9738. }
  9739. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9740. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9741. if (field == "description")
  9742. lua_interface->SetStringValue(state, effect->description.c_str());
  9743. else if (field == "bullet")
  9744. lua_interface->SetInt32Value(state, effect->subbullet);
  9745. else if (field == "percentage")
  9746. lua_interface->SetInt32Value(state, effect->percentage);
  9747. else // no match
  9748. return 0;
  9749. return 1;
  9750. }
  9751. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9752. if (!lua_interface)
  9753. return 0;
  9754. LuaSpell* spell = lua_interface->GetSpell(state);
  9755. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9756. Spawn* target = lua_interface->GetSpawn(state, 3);
  9757. if (!target) {
  9758. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9759. return 0;
  9760. }
  9761. if (!target->IsEntity()) {
  9762. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9763. return 0;
  9764. }
  9765. if (!spell) {
  9766. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9767. return 0;
  9768. }
  9769. if (caster && !caster->IsEntity()) {
  9770. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9771. return 0;
  9772. }
  9773. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9774. return 0;
  9775. }
  9776. int EQ2Emu_lua_InWater(lua_State* state) {
  9777. if (!lua_interface)
  9778. return 0;
  9779. Spawn* spawn = lua_interface->GetSpawn(state);
  9780. lua_interface->ResetFunctionStack(state);
  9781. if (spawn) {
  9782. lua_interface->SetBooleanValue(state, spawn->InWater());
  9783. return 1;
  9784. }
  9785. return 0;
  9786. }
  9787. int EQ2Emu_lua_InLava(lua_State* state) {
  9788. if (!lua_interface)
  9789. return 0;
  9790. Spawn* spawn = lua_interface->GetSpawn(state);
  9791. lua_interface->ResetFunctionStack(state);
  9792. if (spawn) {
  9793. lua_interface->SetBooleanValue(state, spawn->InLava());
  9794. return 1;
  9795. }
  9796. return 0;
  9797. }
  9798. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9799. if (!lua_interface)
  9800. return 0;
  9801. Spawn* attacker = lua_interface->GetSpawn(state);
  9802. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9803. int8 type = lua_interface->GetInt8Value(state, 3);
  9804. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9805. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9806. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9807. string spell_name = lua_interface->GetStringValue(state, 7);
  9808. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9809. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9810. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9811. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9812. lua_interface->ResetFunctionStack(state);
  9813. if (!attacker) {
  9814. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9815. return 0;
  9816. }
  9817. if (!attacker->IsEntity()) {
  9818. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9819. return 0;
  9820. }
  9821. if (!victim) {
  9822. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9823. return 0;
  9824. }
  9825. if (!victim->IsEntity()) {
  9826. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9827. return 0;
  9828. }
  9829. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9830. return 0;
  9831. }
  9832. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9833. if (!lua_interface)
  9834. return 0;
  9835. Spawn* spawn = lua_interface->GetSpawn(state);
  9836. lua_interface->ResetFunctionStack(state);
  9837. if (spawn) {
  9838. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9839. return 1;
  9840. }
  9841. return 0;
  9842. }
  9843. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9844. if (!lua_interface)
  9845. return 0;
  9846. Spawn* spawn = lua_interface->GetSpawn(state);
  9847. bool invul = lua_interface->GetBooleanValue(state, 2);
  9848. lua_interface->ResetFunctionStack(state);
  9849. if (spawn) {
  9850. spawn->SetInvulnerable(invul);
  9851. }
  9852. return 0;
  9853. }
  9854. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9855. if (!lua_interface)
  9856. return 0;
  9857. string category = lua_interface->GetStringValue(state);
  9858. string name = lua_interface->GetStringValue(state, 2);
  9859. lua_interface->ResetFunctionStack(state);
  9860. Rule *ret = 0;
  9861. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9862. lua_interface->SetInt32Value(state, ret->GetInt32());
  9863. return 1;
  9864. }
  9865. lua_interface->LogError("%s: LUA GetRuleFlag Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9866. return 0;
  9867. }
  9868. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  9869. if (!lua_interface)
  9870. return 0;
  9871. Spawn* spawn = lua_interface->GetSpawn(state);
  9872. string type = lua_interface->GetStringValue(state, 2);
  9873. lua_interface->ResetFunctionStack(state);
  9874. if (spawn) {
  9875. int res = 1;
  9876. boost::to_lower(type);
  9877. if(type == "assigned_aa")
  9878. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  9879. else if ( type == "unassigned_aa")
  9880. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  9881. else if ( type == "assigned_tradeskill_aa")
  9882. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  9883. else if ( type == "unassigned_tradeskill_aa")
  9884. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  9885. else if ( type == "assigned_prestige_aa")
  9886. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  9887. else if ( type == "unassigned_prestige_aa")
  9888. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  9889. else if ( type == "assigned_tradeskill_prestige_aa")
  9890. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  9891. else if ( type == "unassigned_tradeskill_prestige_aa")
  9892. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  9893. else
  9894. res = 0;
  9895. return res;
  9896. }
  9897. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  9898. return 0;
  9899. }
  9900. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  9901. if (!lua_interface)
  9902. return 0;
  9903. Spawn* spawn = lua_interface->GetSpawn(state);
  9904. string type = lua_interface->GetStringValue(state, 2);
  9905. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9906. lua_interface->ResetFunctionStack(state);
  9907. if (spawn) {
  9908. boost::to_lower(type);
  9909. if(type == "assigned_aa")
  9910. spawn->SetAssignedAA((sint16)value);
  9911. else if ( type == "unassigned_aa")
  9912. spawn->SetUnassignedAA((sint16)value);
  9913. else if ( type == "assigned_tradeskill_aa")
  9914. spawn->SetTradeskillAA((sint16)value);
  9915. else if ( type == "unassigned_tradeskill_aa")
  9916. spawn->SetUnassignedTradeskillAA((sint16)value);
  9917. else if ( type == "assigned_prestige_aa")
  9918. spawn->SetPrestigeAA((sint16)value);
  9919. else if ( type == "unassigned_prestige_aa")
  9920. spawn->SetUnassignedPrestigeAA((sint16)value);
  9921. else if ( type == "assigned_tradeskill_prestige_aa")
  9922. spawn->SetTradeskillPrestigeAA((sint16)value);
  9923. else if ( type == "unassigned_tradeskill_prestige_aa")
  9924. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  9925. if(spawn->IsPlayer())
  9926. ((Player*)spawn)->SetCharSheetChanged(true);
  9927. }
  9928. return 0;
  9929. }
  9930. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  9931. if (!lua_interface)
  9932. return 0;
  9933. string titleName = lua_interface->GetStringValue(state);
  9934. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  9935. lua_interface->ResetFunctionStack(state);
  9936. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  9937. lua_interface->SetSInt32Value(state, index);
  9938. return 1;
  9939. }
  9940. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  9941. if (!lua_interface)
  9942. return 0;
  9943. Spawn* spawn = lua_interface->GetSpawn(state);
  9944. string titleName = lua_interface->GetStringValue(state, 2);
  9945. lua_interface->ResetFunctionStack(state);
  9946. if(!spawn->IsPlayer())
  9947. {
  9948. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  9949. lua_interface->SetSInt32Value(state, -1);
  9950. return 1;
  9951. }
  9952. Player* player = (Player*)spawn;
  9953. // check if player already has the title, don't need to add twice
  9954. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  9955. if ( playerHasTitle)
  9956. {
  9957. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  9958. return 1;
  9959. }
  9960. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  9961. if(!title)
  9962. {
  9963. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9964. lua_interface->SetSInt32Value(state, -1);
  9965. return 1;
  9966. }
  9967. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  9968. if(returnIdx < 0)
  9969. {
  9970. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9971. }
  9972. lua_interface->SetSInt32Value(state, returnIdx);
  9973. player->GetClient()->SendTitleUpdate();
  9974. return 1;
  9975. }
  9976. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  9977. if (!lua_interface)
  9978. return 0;
  9979. Spawn* spawn = lua_interface->GetSpawn(state);
  9980. string titleName = lua_interface->GetStringValue(state, 2);
  9981. lua_interface->ResetFunctionStack(state);
  9982. if(!spawn->IsPlayer())
  9983. {
  9984. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  9985. return 0;
  9986. }
  9987. Player* player = (Player*)spawn;
  9988. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  9989. if(!title)
  9990. {
  9991. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  9992. return 0;
  9993. }
  9994. if(title->GetPrefix())
  9995. {
  9996. 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());
  9997. return 0;
  9998. }
  9999. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10000. player->GetClient()->SendTitleUpdate();
  10001. return 1;
  10002. }
  10003. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10004. if (!lua_interface)
  10005. return 0;
  10006. Spawn* spawn = lua_interface->GetSpawn(state);
  10007. string titleName = lua_interface->GetStringValue(state, 2);
  10008. lua_interface->ResetFunctionStack(state);
  10009. if(!spawn->IsPlayer())
  10010. {
  10011. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10012. return 0;
  10013. }
  10014. Player* player = (Player*)spawn;
  10015. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10016. if(!title)
  10017. {
  10018. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10019. return 0;
  10020. }
  10021. if(!title->GetPrefix())
  10022. {
  10023. 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());
  10024. return 0;
  10025. }
  10026. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10027. player->GetClient()->SendTitleUpdate();
  10028. return 1;
  10029. }
  10030. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10031. if (!lua_interface)
  10032. return 0;
  10033. Spawn* spawn = lua_interface->GetSpawn(state);
  10034. lua_interface->ResetFunctionStack(state);
  10035. if(!spawn->IsPlayer())
  10036. {
  10037. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10038. return 0;
  10039. }
  10040. Player* player = (Player*)spawn;
  10041. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10042. player->GetClient()->SendTitleUpdate();
  10043. return 1;
  10044. }
  10045. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10046. if (!lua_interface)
  10047. return 0;
  10048. Spawn* spawn = lua_interface->GetSpawn(state);
  10049. lua_interface->ResetFunctionStack(state);
  10050. if(!spawn->IsPlayer())
  10051. {
  10052. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10053. return 0;
  10054. }
  10055. Player* player = (Player*)spawn;
  10056. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10057. player->GetClient()->SendTitleUpdate();
  10058. return 1;
  10059. }
  10060. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10061. if (!lua_interface)
  10062. return 0;
  10063. Spawn* spawn = lua_interface->GetSpawn(state);
  10064. string field = lua_interface->GetStringValue(state, 2);
  10065. lua_interface->ResetFunctionStack(state);
  10066. if(!spawn || !spawn->IsEntity())
  10067. {
  10068. 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));
  10069. return 0;
  10070. }
  10071. Entity* ent = (Entity*)spawn;
  10072. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10073. return 1;
  10074. }
  10075. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10076. if (!lua_interface)
  10077. return 0;
  10078. Spawn* spawn = lua_interface->GetSpawn(state);
  10079. string field = lua_interface->GetStringValue(state, 2);
  10080. lua_interface->ResetFunctionStack(state);
  10081. if(!spawn || !spawn->IsEntity())
  10082. {
  10083. 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));
  10084. return 0;
  10085. }
  10086. Entity* ent = (Entity*)spawn;
  10087. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10088. return 1;
  10089. }
  10090. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10091. if (!lua_interface)
  10092. return 0;
  10093. Spawn* spawn = lua_interface->GetSpawn(state);
  10094. string field = lua_interface->GetStringValue(state, 2);
  10095. lua_interface->ResetFunctionStack(state);
  10096. if(!spawn || !spawn->IsEntity())
  10097. {
  10098. 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));
  10099. return 0;
  10100. }
  10101. Entity* ent = (Entity*)spawn;
  10102. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10103. return 1;
  10104. }
  10105. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10106. if (!lua_interface)
  10107. return 0;
  10108. Spawn* spawn = lua_interface->GetSpawn(state);
  10109. string field = lua_interface->GetStringValue(state, 2);
  10110. lua_interface->ResetFunctionStack(state);
  10111. if(!spawn || !spawn->IsEntity())
  10112. {
  10113. 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));
  10114. return 0;
  10115. }
  10116. Entity* ent = (Entity*)spawn;
  10117. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10118. return 1;
  10119. }
  10120. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10121. if (!lua_interface)
  10122. return 0;
  10123. Spawn* spawn = lua_interface->GetSpawn(state);
  10124. string field = lua_interface->GetStringValue(state, 2);
  10125. string value = lua_interface->GetStringValue(state, 3);
  10126. lua_interface->ResetFunctionStack(state);
  10127. if(!spawn || !spawn->IsEntity())
  10128. {
  10129. 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));
  10130. return 0;
  10131. }
  10132. Entity* ent = (Entity*)spawn;
  10133. bool set_ = ent->SetInfoStructString(field, value);
  10134. lua_interface->SetBooleanValue(state, set_);
  10135. return 1;
  10136. }
  10137. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10138. if (!lua_interface)
  10139. return 0;
  10140. Spawn* spawn = lua_interface->GetSpawn(state);
  10141. string field = lua_interface->GetStringValue(state, 2);
  10142. int64 value = lua_interface->GetInt64Value(state, 3);
  10143. lua_interface->ResetFunctionStack(state);
  10144. if(!spawn || !spawn->IsEntity())
  10145. {
  10146. 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));
  10147. return 0;
  10148. }
  10149. Entity* ent = (Entity*)spawn;
  10150. bool set_ = ent->SetInfoStructUInt(field, value);
  10151. lua_interface->SetBooleanValue(state, set_);
  10152. return 1;
  10153. }
  10154. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10155. if (!lua_interface)
  10156. return 0;
  10157. Spawn* spawn = lua_interface->GetSpawn(state);
  10158. string field = lua_interface->GetStringValue(state, 2);
  10159. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10160. lua_interface->ResetFunctionStack(state);
  10161. if(!spawn || !spawn->IsEntity())
  10162. {
  10163. 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));
  10164. return 0;
  10165. }
  10166. Entity* ent = (Entity*)spawn;
  10167. bool set_ = ent->SetInfoStructSInt(field, value);
  10168. lua_interface->SetBooleanValue(state, set_);
  10169. return 1;
  10170. }
  10171. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10172. if (!lua_interface)
  10173. return 0;
  10174. Spawn* spawn = lua_interface->GetSpawn(state);
  10175. string field = lua_interface->GetStringValue(state, 2);
  10176. float value = lua_interface->GetFloatValue(state, 3);
  10177. lua_interface->ResetFunctionStack(state);
  10178. if(!spawn || !spawn->IsEntity())
  10179. {
  10180. 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));
  10181. return 0;
  10182. }
  10183. Entity* ent = (Entity*)spawn;
  10184. bool set_ = ent->SetInfoStructFloat(field, value);
  10185. lua_interface->SetBooleanValue(state, set_);
  10186. return 1;
  10187. }
  10188. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10189. if (!lua_interface)
  10190. return 0;
  10191. Spawn* spawn = lua_interface->GetSpawn(state);
  10192. bool value = lua_interface->GetBooleanValue(state, 2);
  10193. lua_interface->ResetFunctionStack(state);
  10194. if(!spawn || !spawn->IsPlayer())
  10195. {
  10196. 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));
  10197. return 0;
  10198. }
  10199. ((Player*)spawn)->SetCharSheetChanged(value);
  10200. return 0;
  10201. }
  10202. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10203. if (!lua_interface)
  10204. return 0;
  10205. Spawn* spawn = lua_interface->GetSpawn(state);
  10206. std::string fromName = lua_interface->GetStringValue(state, 2);
  10207. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10208. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10209. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10210. int32 copper = lua_interface->GetInt32Value(state, 6);
  10211. int32 silver = lua_interface->GetInt32Value(state, 7);
  10212. int32 gold = lua_interface->GetInt32Value(state, 8);
  10213. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10214. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10215. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10216. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10217. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10218. lua_interface->ResetFunctionStack(state);
  10219. if(!spawn || !spawn->IsPlayer())
  10220. {
  10221. 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));
  10222. lua_interface->SetBooleanValue(state, false);
  10223. return 1;
  10224. }
  10225. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10226. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10227. lua_interface->SetBooleanValue(state, true);
  10228. return 1;
  10229. }
  10230. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10231. if (!lua_interface)
  10232. return 0;
  10233. int32 char_id = lua_interface->GetInt32Value(state);
  10234. std::string fromName = lua_interface->GetStringValue(state, 2);
  10235. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10236. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10237. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10238. int32 copper = lua_interface->GetInt32Value(state, 6);
  10239. int32 silver = lua_interface->GetInt32Value(state, 7);
  10240. int32 gold = lua_interface->GetInt32Value(state, 8);
  10241. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10242. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10243. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10244. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10245. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10246. lua_interface->ResetFunctionStack(state);
  10247. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10248. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10249. lua_interface->SetBooleanValue(state, true);
  10250. return 1;
  10251. }
  10252. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10253. Spawn* widget;
  10254. if (lua_interface) {
  10255. widget = lua_interface->GetSpawn(state);
  10256. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10257. lua_interface->ResetFunctionStack(state);
  10258. if (widget && widget->IsWidget())
  10259. {
  10260. ((Widget*)widget)->OpenDoor();
  10261. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10262. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10263. }
  10264. else
  10265. 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));
  10266. }
  10267. return 0;
  10268. }
  10269. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10270. Spawn* widget;
  10271. if (lua_interface) {
  10272. widget = lua_interface->GetSpawn(state);
  10273. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10274. lua_interface->ResetFunctionStack(state);
  10275. if (widget && widget->IsWidget())
  10276. {
  10277. ((Widget*)widget)->CloseDoor();
  10278. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10279. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10280. }
  10281. else
  10282. 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));
  10283. }
  10284. return 0;
  10285. }
  10286. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10287. if (!lua_interface)
  10288. return 0;
  10289. Spawn* widget = lua_interface->GetSpawn(state);
  10290. if (widget && widget->IsWidget())
  10291. {
  10292. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10293. return 1;
  10294. }
  10295. return 0;
  10296. }
  10297. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10298. if (!lua_interface)
  10299. return 0;
  10300. sint32 min = lua_interface->GetSInt32Value(state);
  10301. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10302. sint32 result = MakeRandomInt(min, max);
  10303. lua_interface->SetSInt32Value(state, result);
  10304. return 1;
  10305. }
  10306. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10307. if (!lua_interface)
  10308. return 0;
  10309. float min = lua_interface->GetFloatValue(state);
  10310. float max = lua_interface->GetFloatValue(state, 2);
  10311. float result = MakeRandomFloat(min, max);
  10312. lua_interface->SetFloatValue(state, result);
  10313. return 1;
  10314. }
  10315. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10316. if (!lua_interface)
  10317. return 0;
  10318. Spawn* spawn = lua_interface->GetSpawn(state);
  10319. int32 value = lua_interface->GetInt32Value(state, 2);
  10320. lua_interface->ResetFunctionStack(state);
  10321. if(!spawn)
  10322. {
  10323. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10324. lua_interface->SetBooleanValue(state, false);
  10325. return 1;
  10326. }
  10327. spawn->AddIconValue(value);
  10328. lua_interface->SetBooleanValue(state, true);
  10329. return 1;
  10330. }
  10331. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10332. if (!lua_interface)
  10333. return 0;
  10334. Spawn* spawn = lua_interface->GetSpawn(state);
  10335. int32 value = lua_interface->GetInt32Value(state, 2);
  10336. lua_interface->ResetFunctionStack(state);
  10337. if(!spawn)
  10338. {
  10339. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10340. lua_interface->SetBooleanValue(state, false);
  10341. return 1;
  10342. }
  10343. spawn->RemoveIconValue(value);
  10344. lua_interface->SetBooleanValue(state, true);
  10345. return 1;
  10346. }