LuaFunctions.cpp 326 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "../common/Log.h"
  29. #include <math.h>
  30. #include "HeroicOp/HeroicOp.h"
  31. #include "RaceTypes/RaceTypes.h"
  32. #include "ClientPacketFunctions.h"
  33. #include "Transmute.h"
  34. #include <boost/algorithm/string/predicate.hpp>
  35. #include <sstream>
  36. #include <boost/algorithm/string.hpp>
  37. extern MasterFactionList master_faction_list;
  38. extern WorldDatabase database;
  39. extern LuaInterface* lua_interface;
  40. extern ConfigReader configReader;
  41. extern MasterQuestList master_quest_list;
  42. extern MasterItemList master_item_list;
  43. extern MasterSpellList master_spell_list;
  44. extern World world;
  45. extern Commands commands;
  46. extern ZoneList zone_list;
  47. extern Races races;
  48. extern Classes classes;
  49. extern Variables variables;
  50. extern MasterSkillList master_skill_list;
  51. extern MasterHeroicOPList master_ho_list;
  52. extern MasterRaceTypeList race_types_list;
  53. extern MasterLanguagesList master_languages_list;
  54. vector<string> ParseString(string strVal, char delim) {
  55. stringstream ss(strVal);
  56. vector<string> ret;
  57. while (ss.good())
  58. {
  59. string substr;
  60. getline(ss, substr, delim);
  61. ret.push_back(substr);
  62. }
  63. return ret;
  64. }
  65. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  66. stringstream ss(strVal);
  67. vector<unsigned int> ret;
  68. while (ss.good())
  69. {
  70. string substr;
  71. getline(ss, substr, delim);
  72. stringstream valss(substr);
  73. unsigned int val = 0;
  74. valss >> val;
  75. ret.push_back(val);
  76. }
  77. return ret;
  78. }
  79. map<string, signed int> ParseStringMap(string strVal, char delim) {
  80. vector<string> pairs = ParseString(strVal, delim);
  81. vector<string>::iterator itr;
  82. map<string, signed int> ret;
  83. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  84. vector<string> keyvaluepair = ParseString(*itr, ':');
  85. if (keyvaluepair.size() == 2) {
  86. stringstream valss(keyvaluepair[1]);
  87. int32 val = 0;
  88. valss >> val;
  89. ret[keyvaluepair[0]] = val;
  90. }
  91. }
  92. return ret;
  93. }
  94. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  95. vector<string> pairs = ParseString(strVal, delim);
  96. vector<string>::iterator itr;
  97. map<unsigned int, unsigned short> ret;
  98. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  99. vector<string> keyvaluepair = ParseString(*itr, ':');
  100. int32 key = 0;
  101. if (keyvaluepair.size() > 0) {
  102. stringstream keyss(keyvaluepair[0]);
  103. keyss >> key;
  104. }
  105. if (keyvaluepair.size() == 1) {
  106. ret[key] = 1;
  107. }
  108. else if (keyvaluepair.size() == 2) {
  109. stringstream valss(keyvaluepair[1]);
  110. unsigned short val = 0;
  111. valss >> val;
  112. ret[key] = val;
  113. }
  114. }
  115. return ret;
  116. }
  117. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  118. vector<string> pairs = ParseString(strVal, delim);
  119. vector<string>::iterator itr;
  120. map<unsigned int, signed int> ret;
  121. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  122. vector<string> keyvaluepair = ParseString(*itr, ':');
  123. int32 key = 0;
  124. if (keyvaluepair.size() > 0) {
  125. stringstream keyss(keyvaluepair[0]);
  126. keyss >> key;
  127. }
  128. if (keyvaluepair.size() == 1) {
  129. ret[key] = 1;
  130. }
  131. else if (keyvaluepair.size() == 2) {
  132. stringstream valss(keyvaluepair[1]);
  133. signed int val = 0;
  134. valss >> val;
  135. ret[key] = val;
  136. }
  137. }
  138. return ret;
  139. }
  140. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  141. if (!lua_interface)
  142. return 0;
  143. Spawn* spawn = lua_interface->GetSpawn(state);
  144. string mp3_string = lua_interface->GetStringValue(state, 2);
  145. string text_string = lua_interface->GetStringValue(state, 3);
  146. string emote_string = lua_interface->GetStringValue(state, 4);
  147. int32 key1 = lua_interface->GetInt32Value(state, 5);
  148. int32 key2 = lua_interface->GetInt32Value(state, 6);
  149. Spawn* player = lua_interface->GetSpawn(state, 7);
  150. int8 language = lua_interface->GetInt8Value(state, 8);
  151. if (spawn) {
  152. const char* mp3 = 0;
  153. const char* text = 0;
  154. const char* emote = 0;
  155. if (mp3_string.length() > 0)
  156. mp3 = mp3_string.c_str();
  157. if (text_string.length() > 0)
  158. text = text_string.c_str();
  159. if (emote_string.length() > 0)
  160. emote = emote_string.c_str();
  161. Client* client = 0;
  162. if (player && player->IsPlayer())
  163. client = spawn->GetZone()->GetClientBySpawn(player);
  164. if (client) {
  165. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  166. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  167. }
  168. else
  169. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  170. }
  171. return 0;
  172. }
  173. int EQ2Emu_lua_PlaySound(lua_State* state) {
  174. if (!lua_interface)
  175. return 0;
  176. Spawn* spawn = lua_interface->GetSpawn(state);
  177. string sound_string = lua_interface->GetStringValue(state, 2);
  178. float x = lua_interface->GetFloatValue(state, 3);
  179. float y = lua_interface->GetFloatValue(state, 4);
  180. float z = lua_interface->GetFloatValue(state, 5);
  181. Spawn* player = lua_interface->GetSpawn(state, 6);
  182. if (spawn && sound_string.length() > 0) {
  183. Client* client = 0;
  184. if (player && player->IsPlayer())
  185. client = spawn->GetZone()->GetClientBySpawn(player);
  186. if (client)
  187. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  188. else
  189. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  190. }
  191. return 0;
  192. }
  193. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  194. if (!lua_interface)
  195. return 0;
  196. Spawn* spawn = lua_interface->GetSpawn(state);
  197. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  198. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  199. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  200. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  201. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  202. if (!spawn) {
  203. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  204. return 0;
  205. }
  206. if (quest_id > 0) {
  207. //Add this quest to the list of required quests for this spawn
  208. spawn->SetQuestsRequired(quest_id, quest_step);
  209. //If private spawn value set
  210. if (private_spawn) {
  211. //Set the spawn to be private when not granted access through this quest
  212. spawn->AddAllowAccessSpawn(spawn);
  213. spawn->SetPrivateQuestSpawn(true);
  214. }
  215. //This value allows access after a quest step, or the whole quest has been completed
  216. if (continued_access)
  217. spawn->SetQuestsRequiredContinuedAccess(true);
  218. //This value will override vis_flags in the vis packet
  219. if (flag_override > 0)
  220. spawn->SetQuestsRequiredOverride(flag_override);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. float max_distance = lua_interface->GetFloatValue(state, 2);
  229. string variable = lua_interface->GetStringValue(state, 3);
  230. string value = lua_interface->GetStringValue(state, 4);
  231. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  232. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  233. return 0;
  234. }
  235. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  236. if (!lua_interface)
  237. return 0;
  238. Client* client = 0;
  239. Spawn* player = lua_interface->GetSpawn(state);
  240. if (!player) {
  241. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  242. return 0;
  243. }
  244. if (!player->IsPlayer()) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  246. return 0;
  247. }
  248. if (player->GetZone())
  249. client = player->GetZone()->GetClientBySpawn(player);
  250. if (!client) {
  251. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  252. return 0;
  253. }
  254. float intensity = lua_interface->GetFloatValue(state, 2);
  255. int8 direction = lua_interface->GetInt8Value(state, 3);
  256. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  257. if (packet) {
  258. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  259. v1 = *(float *)(a1 + 4);
  260. if ( v1 > 0.0 )
  261. v2 = fminf(v1, 1.0);
  262. else
  263. v2 = 0.1;
  264. */
  265. packet->setDataByName("intensity", intensity);
  266. if ( client->GetVersion() > 546 )
  267. packet->setDataByName("direction", direction);
  268. client->QueuePacket(packet->serialize());
  269. safe_delete(packet);
  270. }
  271. return 0;
  272. }
  273. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  274. if (!lua_interface)
  275. return 0;
  276. Spawn* dead = lua_interface->GetSpawn(state);
  277. Spawn* killer = lua_interface->GetSpawn(state, 2);
  278. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  279. if (dead && dead->Alive() && dead->GetZone())
  280. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  281. return 0;
  282. }
  283. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  284. if (!lua_interface)
  285. return 0;
  286. Spawn* spawn = lua_interface->GetSpawn(state);
  287. float max_distance = lua_interface->GetFloatValue(state, 2);
  288. bool include_players = lua_interface->GetInt8Value(state, 3);
  289. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  290. if (max_distance > 0 && spawn && spawn->GetZone())
  291. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  292. return 0;
  293. }
  294. int EQ2Emu_lua_Despawn(lua_State* state) {
  295. if (!lua_interface)
  296. return 0;
  297. Spawn* spawn = lua_interface->GetSpawn(state);
  298. int32 delay = lua_interface->GetInt32Value(state, 2);
  299. if (spawn && spawn->GetZone())
  300. spawn->GetZone()->Despawn(spawn, delay);
  301. return 0;
  302. }
  303. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  304. if (!lua_interface)
  305. return 0;
  306. Spawn* spawn = lua_interface->GetSpawn(state);
  307. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  308. if (spawn) {
  309. spawn->info_changed = true;
  310. spawn->SetShowHandIcon(displayHandIcon);
  311. }
  312. return 0;
  313. }
  314. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  315. if (!lua_interface)
  316. return 0;
  317. Spawn* spawn = lua_interface->GetSpawn(state);
  318. int32 new_state = lua_interface->GetInt32Value(state, 2);
  319. if (spawn) {
  320. spawn->GetZone()->SendStateCommand(spawn, new_state);
  321. }
  322. return 0;
  323. }
  324. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  325. if (!lua_interface)
  326. return 0;
  327. Spawn* spawn = lua_interface->GetSpawn(state);
  328. string variable = lua_interface->GetStringValue(state, 2);
  329. string value = lua_interface->GetStringValue(state, 3);
  330. 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.
  331. bool temporary_flag = lua_interface->GetBooleanValue(state, 5); // default false as originally designed, allow user to set temporary_flag true to not update DB
  332. int32 type = commands.GetSpawnSetType(variable);
  333. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  334. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  335. return 0;
  336. }
  337. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  338. if (!lua_interface)
  339. return 0;
  340. Spawn* spawn = lua_interface->GetSpawn(state);
  341. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  342. if (spawn && spawn_id > 0) {
  343. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  344. if (closest_spawn) {
  345. lua_interface->SetSpawnValue(state, closest_spawn);
  346. return 1;
  347. }
  348. }
  349. return 0;
  350. }
  351. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  352. if (!lua_interface)
  353. return 0;
  354. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  355. int32 position = lua_interface->GetInt32Value(state, 2);
  356. if (spawnList) {
  357. if (spawnList->size() > position) {
  358. lua_interface->SetSpawnValue(state, spawnList->at(position));
  359. return 1;
  360. }
  361. else {
  362. return 0;
  363. }
  364. return spawnList->size();
  365. }
  366. return 0;
  367. }
  368. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  369. if (!lua_interface)
  370. return 0;
  371. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  372. if (spawnList) {
  373. return spawnList->size();
  374. }
  375. return 0;
  376. }
  377. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. vector<Spawn*>* spawnList = new vector<Spawn*>();
  381. lua_interface->SetSpawnListValue(state, spawnList);
  382. return 1;
  383. }
  384. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  385. if (!lua_interface)
  386. return 0;
  387. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  388. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  389. if (spawnList) {
  390. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  391. if (it == spawnList->end())
  392. spawnList->push_back(spawn);
  393. }
  394. return 0;
  395. }
  396. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  397. if (!lua_interface)
  398. return 0;
  399. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  400. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  401. if (spawnList) {
  402. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  403. if(it != spawnList->end())
  404. spawnList->erase(it);
  405. }
  406. return 0;
  407. }
  408. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  409. if (!lua_interface)
  410. return 0;
  411. Spawn* spawn = lua_interface->GetSpawn(state);
  412. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  413. if (spawn) {
  414. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  415. if (spawns.size() > 0) {
  416. vector<Spawn*>* spawnList = new vector<Spawn*>();
  417. vector<Spawn*>::iterator itr;
  418. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  419. spawnList->push_back(*itr);
  420. }
  421. lua_interface->SetSpawnListValue(state, spawnList);
  422. return 1;
  423. }
  424. }
  425. return 0;
  426. }
  427. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  428. if (!lua_interface)
  429. return 0;
  430. string variable_name = lua_interface->GetStringValue(state);
  431. Variable* var = variables.FindVariable(variable_name);
  432. if (var) {
  433. lua_interface->SetStringValue(state, var->GetValue());
  434. return 1;
  435. }
  436. return 0;
  437. }
  438. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  439. if (!lua_interface)
  440. return 0;
  441. int32 total_coins = lua_interface->GetInt32Value(state);
  442. if (total_coins == 0) {
  443. lua_interface->SetStringValue(state, "0 copper");
  444. return 1;
  445. }
  446. char tmp[64] = { 0 };
  447. string message = "";
  448. int32 val = 0;
  449. if (total_coins >= 1000000) {
  450. val = total_coins / 1000000;
  451. total_coins -= 1000000 * val;
  452. sprintf(tmp, " %u Platinum", val);
  453. message.append(tmp);
  454. memset(tmp, 0, 64);
  455. }
  456. if (total_coins >= 10000) {
  457. val = total_coins / 10000;
  458. total_coins -= 10000 * val;
  459. sprintf(tmp, " %u Gold", val);
  460. message.append(tmp);
  461. memset(tmp, 0, 64);
  462. }
  463. if (total_coins >= 100) {
  464. val = total_coins / 100;
  465. total_coins -= 100 * val;
  466. sprintf(tmp, " %u Silver", val);
  467. message.append(tmp);
  468. memset(tmp, 0, 64);
  469. }
  470. if (total_coins > 0) {
  471. sprintf(tmp, " %u Copper", (int32)total_coins);
  472. message.append(tmp);
  473. }
  474. lua_interface->SetStringValue(state, message.c_str());
  475. return 1;
  476. }
  477. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  478. ZoneServer* zone = lua_interface->GetZone(state);
  479. int32 group_id = lua_interface->GetInt32Value(state, 2);
  480. if (zone) {
  481. Spawn* spawn = zone->GetSpawnGroup(group_id);
  482. if (spawn) {
  483. lua_interface->SetSpawnValue(state, spawn);
  484. return 1;
  485. }
  486. }
  487. return 0;
  488. }
  489. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  490. ZoneServer* zone = lua_interface->GetZone(state);
  491. int32 location_id = lua_interface->GetInt32Value(state, 2);
  492. if (zone) {
  493. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  494. if (spawn) {
  495. lua_interface->SetSpawnValue(state, spawn);
  496. return 1;
  497. }
  498. }
  499. return 0;
  500. }
  501. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  502. Spawn* spawn = lua_interface->GetSpawn(state);
  503. if (spawn) {
  504. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  505. return 1;
  506. }
  507. return 0;
  508. }
  509. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  510. Spawn* spawn = lua_interface->GetSpawn(state);
  511. if (spawn) {
  512. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  513. return 1;
  514. }
  515. return 0;
  516. }
  517. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  518. Spawn* spawn = lua_interface->GetSpawn(state);
  519. if (spawn) {
  520. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  521. return 1;
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  526. Spawn* spawn = lua_interface->GetSpawn(state);
  527. if (spawn) {
  528. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  529. return 1;
  530. }
  531. return 0;
  532. }
  533. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  534. Player* player = (Player*)lua_interface->GetSpawn(state);
  535. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  536. if (player && player->IsPlayer() && faction_id > 0) {
  537. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  538. return 1;
  539. }
  540. return 0;
  541. }
  542. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  543. if (!lua_interface)
  544. return 0;
  545. Spawn* spawn = lua_interface->GetSpawn(state);
  546. int32 value = lua_interface->GetInt32Value(state, 2);
  547. if (spawn) {
  548. spawn->SetFactionID(value);
  549. }
  550. return 0;
  551. }
  552. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  553. Spawn* spawn = lua_interface->GetSpawn(state);
  554. if (spawn) {
  555. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  556. return 1;
  557. }
  558. return 0;
  559. }
  560. int EQ2Emu_lua_GetGender(lua_State* state) {
  561. Spawn* spawn = lua_interface->GetSpawn(state);
  562. if (spawn) {
  563. lua_interface->SetInt32Value(state, spawn->GetGender());
  564. return 1;
  565. }
  566. return 0;
  567. }
  568. int EQ2Emu_lua_GetTarget(lua_State* state) {
  569. Spawn* spawn = lua_interface->GetSpawn(state);
  570. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  571. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  572. return 1;
  573. }
  574. return 0;
  575. }
  576. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  577. if (!lua_interface)
  578. return 0;
  579. Spawn* spawn = lua_interface->GetSpawn(state);
  580. string mp3_string = lua_interface->GetStringValue(state, 2);
  581. int32 key1 = lua_interface->GetInt32Value(state, 3);
  582. int32 key2 = lua_interface->GetInt32Value(state, 4);
  583. Spawn* player = lua_interface->GetSpawn(state, 5);
  584. if (spawn && mp3_string.length() > 0) {
  585. Client* client = 0;
  586. if (player && player->IsPlayer())
  587. client = spawn->GetZone()->GetClientBySpawn(player);
  588. if (client) {
  589. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  590. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  591. }
  592. else
  593. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  594. }
  595. return 0;
  596. }
  597. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  598. if (!lua_interface)
  599. return 0;
  600. Spawn* spawn = lua_interface->GetSpawn(state);
  601. if (spawn) {
  602. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  603. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  604. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  605. return 3;
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  610. if (!lua_interface)
  611. return 0;
  612. Spawn* spawn = lua_interface->GetSpawn(state);
  613. if (spawn) {
  614. int32 item_id = lua_interface->GetInt32Value(state, 2);
  615. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  616. return 1;
  617. }
  618. return 0;
  619. }
  620. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  621. if (!lua_interface)
  622. return 0;
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. if (spawn && spawn->IsEntity()) {
  625. int32 item_id = lua_interface->GetInt32Value(state, 2);
  626. int16 charges = lua_interface->GetInt16Value(state, 3);
  627. if (charges == 0)
  628. charges = 1;
  629. ((Entity*)spawn)->AddLootItem(item_id, charges);
  630. }
  631. return 0;
  632. }
  633. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  634. if (!lua_interface)
  635. return 0;
  636. Spawn* spawn = lua_interface->GetSpawn(state);
  637. if (spawn && spawn->IsEntity()) {
  638. int32 item_id = lua_interface->GetInt32Value(state, 2);
  639. spawn->LootItem(item_id);
  640. }
  641. return 0;
  642. }
  643. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  644. if (!lua_interface)
  645. return 0;
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. if (spawn) {
  648. int32 val = lua_interface->GetInt32Value(state, 2);
  649. spawn->AddLootCoins(val);
  650. }
  651. return 0;
  652. }
  653. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  654. if (!lua_interface)
  655. return 0;
  656. Spawn* entity = lua_interface->GetSpawn(state);
  657. Spawn* player = lua_interface->GetSpawn(state, 2);
  658. if (entity && player && player->IsPlayer()) {
  659. int32 coins = lua_interface->GetInt32Value(state, 3);
  660. vector<Item*>* items = 0;
  661. int i = 0;
  662. int32 item_id = 0;
  663. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  664. if (items == 0)
  665. items = new vector<Item*>;
  666. if (master_item_list.GetItem(item_id))
  667. items->push_back(master_item_list.GetItem(item_id));
  668. i++;
  669. }
  670. Client* client = 0;
  671. client = player->GetZone()->GetClientBySpawn(player);
  672. if (client)
  673. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  674. if(coins > 0)
  675. entity->AddLootCoins(coins);
  676. safe_delete(items);
  677. }
  678. return 0;
  679. }
  680. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  681. if (!lua_interface)
  682. return 0;
  683. Spawn* entity = lua_interface->GetSpawn(state);
  684. Spawn* player = lua_interface->GetSpawn(state, 2);
  685. int32 item_id = lua_interface->GetInt32Value(state, 3);
  686. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  687. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  688. return 1;
  689. }
  690. return 0;
  691. }
  692. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  693. if (!lua_interface)
  694. return 0;
  695. Spawn* entity = lua_interface->GetSpawn(state);
  696. Spawn* player = lua_interface->GetSpawn(state, 2);
  697. if (entity && player && player->IsPlayer()) {
  698. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  699. return 1;
  700. }
  701. return 0;
  702. }
  703. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  704. if (!lua_interface)
  705. return 0;
  706. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  707. safe_delete(conversation);
  708. conversation = new vector<ConversationOption>();
  709. lua_interface->SetConversationValue(state, conversation);
  710. return 1;
  711. }
  712. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  713. if (!lua_interface)
  714. return 0;
  715. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  716. if (conversation) {
  717. ConversationOption conv_option;
  718. conv_option.option = lua_interface->GetStringValue(state, 2);
  719. conv_option.function = lua_interface->GetStringValue(state, 3);
  720. if (conv_option.option.length() > 0)
  721. conversation->push_back(conv_option);
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  726. if (!lua_interface)
  727. return 0;
  728. Spawn* npc = lua_interface->GetSpawn(state);
  729. Spawn* player = lua_interface->GetSpawn(state, 2);
  730. if (npc && player && player->IsPlayer() && player->GetZone()) {
  731. Client* client = player->GetZone()->GetClientBySpawn(player);
  732. if (client) {
  733. int32 conversation_id = client->GetConversationID(npc, 0);
  734. client->CloseDialog(conversation_id);
  735. }
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  740. if (!lua_interface)
  741. return 0;
  742. Item* item = lua_interface->GetItem(state);
  743. Spawn* player = lua_interface->GetSpawn(state, 2);
  744. if (item && player && player->IsPlayer() && player->GetZone()) {
  745. Client* client = player->GetZone()->GetClientBySpawn(player);
  746. if (client) {
  747. int32 conversation_id = client->GetConversationID(0, item);
  748. client->CloseDialog(conversation_id);
  749. }
  750. }
  751. return 0;
  752. }
  753. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  754. if (!lua_interface)
  755. return 0;
  756. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  757. Spawn* spawn = 0;
  758. Item* item = 0;
  759. int8 type = lua_interface->GetInt8Value(state, 2);
  760. if (type == 1 || type == 3)
  761. spawn = lua_interface->GetSpawn(state, 3);
  762. else if (type == 2 || type == 4)
  763. item = lua_interface->GetItem(state, 3);
  764. Spawn* player = lua_interface->GetSpawn(state, 4);
  765. string text = lua_interface->GetStringValue(state, 5);
  766. string mp3 = lua_interface->GetStringValue(state, 6);
  767. int32 key1 = lua_interface->GetInt32Value(state, 7);
  768. int32 key2 = lua_interface->GetInt32Value(state, 8);
  769. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  770. Client* client = player->GetZone()->GetClientBySpawn(player);
  771. if (client) {
  772. if (spawn) {
  773. // Need to do this so the function works the same as it did before
  774. if (type == 1)
  775. type++;
  776. if (mp3.length() > 0)
  777. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  778. else
  779. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  780. }
  781. else {
  782. if (mp3.length() > 0)
  783. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  784. else
  785. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  786. }
  787. }
  788. }
  789. safe_delete(conversation);
  790. lua_interface->SetConversationValue(state, NULL);
  791. return 0;
  792. }
  793. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  794. if(!lua_interface)
  795. return 0;
  796. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  797. Item* item = lua_interface->GetItem(state, 2);
  798. Spawn* player = lua_interface->GetSpawn(state, 3);
  799. string text = lua_interface->GetStringValue(state, 4);
  800. string mp3 = lua_interface->GetStringValue(state, 5);
  801. int32 key1 = lua_interface->GetInt32Value(state, 6);
  802. int32 key2 = lua_interface->GetInt32Value(state, 7);
  803. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  804. Client* client = player->GetZone()->GetClientBySpawn(player);
  805. if(client){
  806. if(mp3.length() > 0)
  807. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  808. else
  809. client->DisplayConversation(item, conversation, (char*)text.c_str());
  810. }
  811. safe_delete(conversation);
  812. }
  813. return 0;
  814. }*/
  815. int EQ2Emu_lua_StartConversation(lua_State* state) {
  816. if (!lua_interface)
  817. return 0;
  818. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  819. Spawn* npc = lua_interface->GetSpawn(state, 2);
  820. Spawn* player = lua_interface->GetSpawn(state, 3);
  821. string text = lua_interface->GetStringValue(state, 4);
  822. string mp3 = lua_interface->GetStringValue(state, 5);
  823. int32 key1 = lua_interface->GetInt32Value(state, 6);
  824. int32 key2 = lua_interface->GetInt32Value(state, 7);
  825. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  826. Client* client = npc->GetZone()->GetClientBySpawn(player);
  827. if (mp3.length() > 0)
  828. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  829. else
  830. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  831. safe_delete(conversation);
  832. lua_interface->SetConversationValue(state, NULL);
  833. }
  834. else
  835. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", npc ? npc->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  836. return 0;
  837. }
  838. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  839. if (!lua_interface)
  840. return 0;
  841. Spawn* spawn = lua_interface->GetSpawn(state);
  842. float distance = lua_interface->GetFloatValue(state, 2);
  843. string in_range_function = lua_interface->GetStringValue(state, 3);
  844. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  845. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  846. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  847. return 0;
  848. }
  849. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  850. ZoneServer* zone = lua_interface->GetZone(state);
  851. float x = lua_interface->GetFloatValue(state, 2);
  852. float y = lua_interface->GetFloatValue(state, 3);
  853. float z = lua_interface->GetFloatValue(state, 4);
  854. float max_variation = lua_interface->GetFloatValue(state, 5);
  855. string in_range_function = lua_interface->GetStringValue(state, 6);
  856. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  857. if (zone && in_range_function.length() > 0)
  858. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  859. return 0;
  860. }
  861. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  862. if (!lua_interface)
  863. return 0;
  864. Spawn* spawn = lua_interface->GetSpawn(state);
  865. if (spawn && spawn->IsEntity()) {
  866. int32 val = lua_interface->GetInt32Value(state, 2);
  867. ((Entity*)spawn)->SetLootCoins(val);
  868. }
  869. return 0;
  870. }
  871. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* spawn = lua_interface->GetSpawn(state);
  875. if (spawn && spawn->IsEntity()) {
  876. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  877. return 1;
  878. }
  879. return 0;
  880. }
  881. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  882. if (!lua_interface)
  883. return 0;
  884. Spawn* spawn = lua_interface->GetSpawn(state);
  885. float x = lua_interface->GetFloatValue(state, 2);
  886. float y = lua_interface->GetFloatValue(state, 3);
  887. float z = lua_interface->GetFloatValue(state, 4);
  888. float speed = lua_interface->GetFloatValue(state, 5);
  889. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  890. string function = lua_interface->GetStringValue(state, 7);
  891. if (spawn) {
  892. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  893. spawn->GetZone()->AddMovementNPC(spawn);
  894. }
  895. lua_interface->ResetFunctionStack(state);
  896. return 0;
  897. }
  898. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  899. if (!lua_interface)
  900. return 0;
  901. Spawn* spawn = lua_interface->GetSpawn(state);
  902. if (spawn) {
  903. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  904. return 1;
  905. }
  906. return 0;
  907. }
  908. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  909. if (!lua_interface)
  910. return 0;
  911. Spawn* spawn = lua_interface->GetSpawn(state);
  912. Spawn* target = lua_interface->GetSpawn(state, 2);
  913. if (spawn && target) {
  914. if (spawn->IsEntity())
  915. // ((Entity*)spawn)->FaceTarget(target);
  916. static_cast<Entity*>(spawn)->FaceTarget(target);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* spawn = lua_interface->GetSpawn(state);
  925. float x = lua_interface->GetFloatValue(state, 2);
  926. float y = lua_interface->GetFloatValue(state, 3);
  927. float z = lua_interface->GetFloatValue(state, 4);
  928. float speed = lua_interface->GetFloatValue(state, 5);
  929. string lua_function = lua_interface->GetStringValue(state, 6);
  930. bool more_points = lua_interface->GetBooleanValue(state, 7);
  931. if (spawn) {
  932. if (speed == 0)
  933. speed = spawn->GetSpeed();
  934. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  935. }
  936. lua_interface->ResetFunctionStack(state);
  937. return 0;
  938. }
  939. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  940. if (!lua_interface)
  941. return 0;
  942. Spawn* spawn = lua_interface->GetSpawn(state);
  943. if (spawn) {
  944. spawn->ClearRunningLocations();
  945. }
  946. return 0;
  947. }
  948. int EQ2Emu_lua_Say(lua_State* state) {
  949. if (!lua_interface)
  950. return 0;
  951. Spawn* spawn = lua_interface->GetSpawn(state);
  952. string message = lua_interface->GetStringValue(state, 2);
  953. Spawn* player = lua_interface->GetSpawn(state, 3);
  954. int32 language = lua_interface->GetInt32Value(state, 4);
  955. if (spawn && message.length() > 0) {
  956. Client* client = 0;
  957. if (player && player->IsPlayer())
  958. client = spawn->GetZone()->GetClientBySpawn(player);
  959. if (client)
  960. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  961. else
  962. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  963. }
  964. lua_interface->ResetFunctionStack(state);
  965. return 0;
  966. }
  967. int EQ2Emu_lua_Shout(lua_State* state) {
  968. if (!lua_interface)
  969. return 0;
  970. Spawn* spawn = lua_interface->GetSpawn(state);
  971. string message = lua_interface->GetStringValue(state, 2);
  972. Spawn* player = lua_interface->GetSpawn(state, 3);
  973. if (spawn && message.length() > 0) {
  974. Client* client = 0;
  975. if (player && player->IsPlayer())
  976. client = spawn->GetZone()->GetClientBySpawn(player);
  977. if (client)
  978. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  979. else
  980. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  981. }
  982. lua_interface->ResetFunctionStack(state);
  983. return 0;
  984. }
  985. int EQ2Emu_lua_SayOOC(lua_State* state) {
  986. if (!lua_interface)
  987. return 0;
  988. Spawn* spawn = lua_interface->GetSpawn(state);
  989. string message = lua_interface->GetStringValue(state, 2);
  990. Spawn* player = lua_interface->GetSpawn(state, 3);
  991. if (spawn && message.length() > 0) {
  992. Client* client = 0;
  993. if (player && player->IsPlayer())
  994. client = spawn->GetZone()->GetClientBySpawn(player);
  995. if (client)
  996. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  997. else
  998. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  999. }
  1000. lua_interface->ResetFunctionStack(state);
  1001. return 0;
  1002. }
  1003. int EQ2Emu_lua_Emote(lua_State* state) {
  1004. if (!lua_interface)
  1005. return 0;
  1006. Spawn* spawn = lua_interface->GetSpawn(state);
  1007. string message = lua_interface->GetStringValue(state, 2);
  1008. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1009. Spawn* player = lua_interface->GetSpawn(state, 4);
  1010. char* to = 0;
  1011. if (spawn2)
  1012. to = spawn2->GetName();
  1013. if (spawn && message.length() > 0) {
  1014. Client* client = 0;
  1015. if (player && player->IsPlayer())
  1016. client = spawn->GetZone()->GetClientBySpawn(player);
  1017. if (client)
  1018. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1019. else
  1020. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1021. }
  1022. lua_interface->ResetFunctionStack(state);
  1023. return 0;
  1024. }
  1025. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1026. if (!lua_interface)
  1027. return 0;
  1028. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1029. if (!luaspell)
  1030. return 0;
  1031. Spawn* caster = luaspell->caster;
  1032. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1033. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1034. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1035. Spawn* target = lua_interface->GetSpawn(state, 4);
  1036. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1037. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1038. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1039. lua_interface->ResetFunctionStack(state);
  1040. if (caster && caster->IsEntity()) {
  1041. bool success = false;
  1042. luaspell->resisted = false;
  1043. if (target) {
  1044. float distance = caster->GetDistance(target, true);
  1045. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1046. success = true;
  1047. }
  1048. if (luaspell->targets.size() > 0) {
  1049. Spawn* target = 0;
  1050. ZoneServer* zone = luaspell->caster->GetZone();
  1051. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1052. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1053. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1054. float distance = caster->GetDistance(target, true);
  1055. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1056. }
  1057. }
  1058. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1059. success = true;
  1060. }
  1061. if (success) {
  1062. if (caster->GetZone())
  1063. caster->GetZone()->TriggerCharSheetTimer();
  1064. }
  1065. }
  1066. return 0;
  1067. }
  1068. int EQ2Emu_lua_AddItem(lua_State* state) {
  1069. if (!lua_interface)
  1070. return 0;
  1071. Spawn* spawn = lua_interface->GetSpawn(state);
  1072. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1073. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1074. // default of 1 quantity to add
  1075. if (quantity == 0)
  1076. quantity = 1;
  1077. if (spawn && spawn->IsPlayer()) {
  1078. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1079. if (client && item_id > 0) {
  1080. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1081. return 1;
  1082. }
  1083. }
  1084. lua_interface->SetBooleanValue(state, false);
  1085. return 1;
  1086. }
  1087. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1088. if (!lua_interface)
  1089. return 0;
  1090. Spawn* spawn = lua_interface->GetSpawn(state);
  1091. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1092. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1093. string location = lua_interface->GetStringValue(state, 4);
  1094. if (spawn && spawn->IsPlayer()) {
  1095. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1096. if (client && item_id > 0) {
  1097. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1098. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1099. else
  1100. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1101. if (send_messages) {
  1102. Item* item = master_item_list.GetItem(item_id);
  1103. if (item) {
  1104. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1105. string popup_text = "You receive " + item->name;
  1106. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1107. }
  1108. }
  1109. return 1;
  1110. }
  1111. }
  1112. lua_interface->SetBooleanValue(state, false);
  1113. return 1;
  1114. }
  1115. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1116. Spawn* spawn = lua_interface->GetSpawn(state);
  1117. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1118. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1119. // default of 1 to remove
  1120. if (quantity == 0)
  1121. quantity = 1;
  1122. Client* client;
  1123. Item* item;
  1124. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1125. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1126. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1127. if (client->RemoveItem(item, quantity)) {
  1128. lua_interface->SetBooleanValue(state, true);
  1129. return 1;
  1130. }
  1131. }
  1132. }
  1133. }
  1134. lua_interface->SetBooleanValue(state, false);
  1135. return 1;
  1136. }
  1137. int EQ2Emu_lua_HasItem(lua_State* state) {
  1138. Spawn* player = lua_interface->GetSpawn(state);
  1139. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1140. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1141. if (player && player->IsPlayer()) {
  1142. bool hasItem = false;
  1143. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1144. if (!hasItem)
  1145. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1146. lua_interface->SetBooleanValue(state, hasItem);
  1147. return 1;
  1148. }
  1149. lua_interface->SetBooleanValue(state, false);
  1150. return 1;
  1151. }
  1152. int EQ2Emu_lua_Spawn(lua_State* state) {
  1153. if (!lua_interface)
  1154. return 0;
  1155. ZoneServer* zone = lua_interface->GetZone(state);
  1156. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1157. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1158. float x = lua_interface->GetFloatValue(state, 4);
  1159. float y = lua_interface->GetFloatValue(state, 5);
  1160. float z = lua_interface->GetFloatValue(state, 6);
  1161. float heading = lua_interface->GetFloatValue(state, 7);
  1162. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1163. Spawn* spawn = zone->GetSpawn(spawn_id);
  1164. if (!spawn)
  1165. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1166. else {
  1167. spawn->SetX(x);
  1168. spawn->SetZ(z);
  1169. spawn->SetY(y,true,true);
  1170. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1171. spawn->SetHeading(heading);
  1172. if (restricted_npc)
  1173. spawn->AddAllowAccessSpawn(spawn);
  1174. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1175. bool scriptActive = false;
  1176. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1177. scriptActive = true;
  1178. spawn->SetSpawnScript(string(spawn_script));
  1179. }
  1180. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1181. zone->AddSpawn(spawn);
  1182. if (scriptActive) {
  1183. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1184. }
  1185. lua_interface->SetSpawnValue(state, spawn);
  1186. return 1;
  1187. }
  1188. }
  1189. else {
  1190. string output = "Invalid paramaters to LUA Spawn command: \n";
  1191. if (!zone)
  1192. output = output.append("\t").append("Missing zone reference. \n");
  1193. if (spawn_id == 0)
  1194. output = output.append("\t").append("Missing spawn_id.");
  1195. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1196. }
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. ZoneServer* zone = lua_interface->GetZone(state);
  1203. if (zone) {
  1204. lua_interface->SetStringValue(state, zone->GetZoneName());
  1205. return 1;
  1206. }
  1207. return 0;
  1208. }
  1209. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1210. if (!lua_interface)
  1211. return 0;
  1212. ZoneServer* zone = lua_interface->GetZone(state);
  1213. if (zone) {
  1214. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1215. return 1;
  1216. }
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_GetZone(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. int32 zone_id = lua_interface->GetInt32Value(state);
  1223. ZoneServer* zone = 0;
  1224. if (zone_id > 0)
  1225. zone = zone_list.Get(zone_id);
  1226. else {
  1227. string zone_name = lua_interface->GetStringValue(state);
  1228. if (zone_name.length() > 0) {
  1229. zone = zone_list.Get(zone_name.c_str());
  1230. }
  1231. else {
  1232. Spawn* spawn = lua_interface->GetSpawn(state);
  1233. if (spawn)
  1234. zone = spawn->GetZone();
  1235. }
  1236. }
  1237. if (zone) {
  1238. lua_interface->SetZoneValue(state, zone);
  1239. return 1;
  1240. }
  1241. return 0;
  1242. }
  1243. int EQ2Emu_lua_AddHate(lua_State* state) {
  1244. Spawn* entity = lua_interface->GetSpawn(state);
  1245. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1246. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1247. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1248. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1249. if (entity && entity->IsEntity() && amount != 0) {
  1250. if (luaspell) {
  1251. ZoneServer* zone = luaspell->caster->GetZone();
  1252. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1253. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1254. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1255. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1256. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1257. if (send_packet)
  1258. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1259. }
  1260. }
  1261. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1262. }
  1263. else if (npc && npc->IsNPC() && npc->GetZone())
  1264. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1265. }
  1266. return 0;
  1267. }
  1268. int EQ2Emu_lua_Zone(lua_State* state) {
  1269. if (!lua_interface)
  1270. return 0;
  1271. ZoneServer* zone = lua_interface->GetZone(state);
  1272. Spawn* player = lua_interface->GetSpawn(state, 2);
  1273. Client* client = 0;
  1274. if (player && player->IsPlayer())
  1275. client = player->GetZone()->GetClientBySpawn(player);
  1276. float x = lua_interface->GetFloatValue(state, 3);
  1277. float y = lua_interface->GetFloatValue(state, 4);
  1278. float z = lua_interface->GetFloatValue(state, 5);
  1279. float heading = lua_interface->GetFloatValue(state, 6);
  1280. if (zone && client) {
  1281. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1282. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1283. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1284. {
  1285. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1286. return 0;
  1287. }
  1288. if (x != 0 || y != 0 || z != 0) {
  1289. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1290. player->SetX(x);
  1291. player->SetY(y);
  1292. player->SetZ(z);
  1293. player->SetHeading(heading);
  1294. client->Zone(zone->GetZoneName(), false);
  1295. }
  1296. else
  1297. client->Zone(zone->GetZoneName());
  1298. }
  1299. else
  1300. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1301. return 0;
  1302. }
  1303. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1304. if (!lua_interface)
  1305. return 0;
  1306. Spawn* spawn = lua_interface->GetSpawn(state);
  1307. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1308. if (spawn && spawn2)
  1309. spawn->AddAllowAccessSpawn(spawn2);
  1310. return 0;
  1311. }
  1312. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1313. if (!lua_interface)
  1314. return 0;
  1315. Spawn* target = lua_interface->GetSpawn(state);
  1316. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1317. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1318. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1319. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1320. if (!target) {
  1321. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1322. return 0;
  1323. }
  1324. if (!target->IsEntity()) {
  1325. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1326. return 0;
  1327. }
  1328. if (spell_id <= 0) {
  1329. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1330. return 0;
  1331. }
  1332. if (caster && !caster->IsEntity()) {
  1333. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1334. return 0;
  1335. }
  1336. if (spell_tier == 0)
  1337. spell_tier = 1;
  1338. if (!caster)
  1339. caster = target;
  1340. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1341. return 0;
  1342. }
  1343. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1344. if (!lua_interface)
  1345. return 0;
  1346. Spawn* target = lua_interface->GetSpawn(state);
  1347. int32 target_id = 0;
  1348. if (target)
  1349. target_id = target->GetID();
  1350. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1351. if (!luaspell)
  1352. return 0;
  1353. Spawn* caster = luaspell->caster;
  1354. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1355. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1356. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1357. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1358. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1359. //lua_interface->ResetFunctionStack(state);
  1360. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1361. vector<int16> faction_req;
  1362. vector<int16> race_req;
  1363. int32 class_req = 0;
  1364. int32 i = 0;
  1365. int8 f = 0;
  1366. int8 r = 0;
  1367. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1368. if (class_id < 100) {
  1369. class_req += pow(2.0, double(class_id - 1));
  1370. }
  1371. else if (class_id > 100 && class_id < 1000) {
  1372. race_req.push_back(class_id);
  1373. r++;
  1374. }
  1375. else {
  1376. faction_req.push_back(class_id);
  1377. f++;
  1378. }
  1379. i++;
  1380. }
  1381. if (caster && caster->IsEntity()) {
  1382. bool race_match = false;
  1383. bool success = false;
  1384. luaspell->resisted = false;
  1385. if (luaspell->initial_target == target_id) {
  1386. int xxx = 0;
  1387. }
  1388. if (luaspell->targets.size() > 0) {
  1389. ZoneServer* zone = luaspell->caster->GetZone();
  1390. Spawn* target = 0;
  1391. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1392. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1393. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1394. if (race_req.size() > 0) {
  1395. for (int8 i = 0; i < race_req.size(); i++) {
  1396. int32 xxx = target->GetLuaRaceId();
  1397. if (target->GetLuaRaceId() == race_req[i]) {
  1398. race_match = true;
  1399. }
  1400. }
  1401. }
  1402. else
  1403. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1404. if (race_match == true) {
  1405. float distance = caster->GetDistance(target, true);
  1406. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1407. }
  1408. }
  1409. }
  1410. success = true;
  1411. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1412. }
  1413. else if (target) {
  1414. //check class and race/faction here
  1415. if (race_req.size() > 0) {
  1416. for (int8 i = 0; i < race_req.size(); i++) {
  1417. if (target->GetLuaRaceId() == race_req[i]) {
  1418. race_match = true;
  1419. }
  1420. }
  1421. }
  1422. else
  1423. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1424. if (race_match == true) {
  1425. float distance = caster->GetDistance(target, true);
  1426. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1427. success = true;
  1428. }
  1429. }
  1430. if (success) {
  1431. Spell* spell = luaspell->spell;
  1432. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1433. ((Player*)caster)->InCombat(true);
  1434. if (caster->GetZone())
  1435. caster->GetZone()->TriggerCharSheetTimer();
  1436. }
  1437. }
  1438. }
  1439. return 0;
  1440. }
  1441. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1442. if (!lua_interface)
  1443. return 0;
  1444. Spawn* spawn = lua_interface->GetSpawn(state);
  1445. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1446. lua_interface->ResetFunctionStack(state);
  1447. if (spawn && value != 0) {
  1448. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1449. spawn->SetPower(spawn->GetTotalPower());
  1450. else
  1451. spawn->SetPower(spawn->GetPower() + value);
  1452. }
  1453. return 0;
  1454. }
  1455. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1456. if (!lua_interface)
  1457. return 0;
  1458. Spawn* spawn = lua_interface->GetSpawn(state);
  1459. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1460. lua_interface->ResetFunctionStack(state);
  1461. if (spawn && value != 0) {
  1462. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1463. spawn->SetHP(spawn->GetTotalHP());
  1464. else
  1465. spawn->SetHP(spawn->GetHP() + value);
  1466. }
  1467. return 0;
  1468. }
  1469. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1470. if (!lua_interface)
  1471. return 0;
  1472. Spawn* spawn = lua_interface->GetSpawn(state);
  1473. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1474. lua_interface->ResetFunctionStack(state);
  1475. if (spawn && value != 0) {
  1476. spawn->SetPower(spawn->GetPower() + value);
  1477. if (value > spawn->GetTotalHPBase())
  1478. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1479. }
  1480. return 0;
  1481. }
  1482. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1483. if (!lua_interface)
  1484. return 0;
  1485. Spawn* spawn = lua_interface->GetSpawn(state);
  1486. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1487. lua_interface->ResetFunctionStack(state);
  1488. if (spawn && value != 0) {
  1489. spawn->SetHP(spawn->GetHP() + value);
  1490. if (value > spawn->GetTotalHPBase())
  1491. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1492. }
  1493. return 0;
  1494. }
  1495. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1496. if (!lua_interface)
  1497. return 0;
  1498. Spawn* spawn = lua_interface->GetSpawn(state);
  1499. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1500. lua_interface->ResetFunctionStack(state);
  1501. if (spawn && value > 0) {
  1502. spawn->SetHP(value);
  1503. if (value > spawn->GetTotalHPBase())
  1504. spawn->SetTotalHP(value);
  1505. }
  1506. return 0;
  1507. }
  1508. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1509. if (!lua_interface)
  1510. return 0;
  1511. Spawn* spawn = lua_interface->GetSpawn(state);
  1512. float value = lua_interface->GetFloatValue(state, 2);
  1513. lua_interface->ResetFunctionStack(state);
  1514. if (spawn && spawn->IsEntity() && value > 0)
  1515. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1516. if (spawn->IsPlayer())
  1517. ((Player*)spawn)->SetCharSheetChanged(true);
  1518. return 0;
  1519. }
  1520. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1521. if (!lua_interface)
  1522. return 0;
  1523. Spawn* spawn = lua_interface->GetSpawn(state);
  1524. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1525. lua_interface->ResetFunctionStack(state);
  1526. if (spawn && spawn->IsEntity() && value > 0)
  1527. ((Entity*)spawn)->SetTotalHPBase(value);
  1528. return 0;
  1529. }
  1530. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1531. if (!lua_interface)
  1532. return 0;
  1533. Spawn* spawn = lua_interface->GetSpawn(state);
  1534. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1535. lua_interface->ResetFunctionStack(state);
  1536. if (spawn && value > 0) {
  1537. spawn->SetPower(value);
  1538. if (value > spawn->GetTotalPowerBase())
  1539. spawn->SetTotalPower(value);
  1540. }
  1541. return 0;
  1542. }
  1543. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1544. if (!lua_interface)
  1545. return 0;
  1546. Spawn* spawn = lua_interface->GetSpawn(state);
  1547. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1548. lua_interface->ResetFunctionStack(state);
  1549. if (spawn && spawn->IsEntity() && value > 0)
  1550. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1551. return 0;
  1552. }
  1553. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1554. if (!lua_interface)
  1555. return 0;
  1556. Spawn* spawn = lua_interface->GetSpawn(state);
  1557. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1558. lua_interface->ResetFunctionStack(state);
  1559. if (spawn && spawn->IsEntity() && value > 0)
  1560. ((Entity*)spawn)->SetTotalPowerBase(value);
  1561. return 0;
  1562. }
  1563. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1564. if (!lua_interface)
  1565. return 0;
  1566. Spawn* spawn = lua_interface->GetSpawn(state);
  1567. float x = lua_interface->GetFloatValue(state, 2);
  1568. float y = lua_interface->GetFloatValue(state, 3);
  1569. float z = lua_interface->GetFloatValue(state, 4);
  1570. float heading = lua_interface->GetFloatValue(state, 5);
  1571. lua_interface->ResetFunctionStack(state);
  1572. if (spawn) {
  1573. spawn->SetX(x);
  1574. spawn->SetY(y);
  1575. spawn->SetZ(z);
  1576. if (heading != 0)
  1577. spawn->SetHeading(heading);
  1578. spawn->SetSpawnOrigX(spawn->GetX());
  1579. spawn->SetSpawnOrigY(spawn->GetY());
  1580. spawn->SetSpawnOrigZ(spawn->GetZ());
  1581. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1582. if (spawn->IsPlayer()) {
  1583. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1584. if (client) {
  1585. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1586. client->QueuePacket(packet);
  1587. }
  1588. }
  1589. }
  1590. return 0;
  1591. }
  1592. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1593. if (!lua_interface)
  1594. return 0;
  1595. Spawn* spawn = lua_interface->GetSpawn(state);
  1596. float value = lua_interface->GetFloatValue(state, 2);
  1597. lua_interface->ResetFunctionStack(state);
  1598. if (spawn) {
  1599. spawn->SetHeading(value);
  1600. if (spawn->IsPlayer()) {
  1601. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1602. if (client) {
  1603. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1604. client->QueuePacket(packet);
  1605. }
  1606. }
  1607. }
  1608. return 0;
  1609. }
  1610. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1611. if (!lua_interface)
  1612. return 0;
  1613. Spawn* spawn = lua_interface->GetSpawn(state);
  1614. int16 value = lua_interface->GetInt16Value(state, 2);
  1615. lua_interface->ResetFunctionStack(state);
  1616. if (spawn)
  1617. spawn->SetModelType(value);
  1618. return 0;
  1619. }
  1620. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1621. if (!lua_interface)
  1622. return 0;
  1623. Spawn* spawn = lua_interface->GetSpawn(state);
  1624. int8 value = lua_interface->GetInt8Value(state, 2);
  1625. lua_interface->ResetFunctionStack(state);
  1626. if (spawn) {
  1627. if (spawn->IsPlayer())
  1628. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1629. else
  1630. spawn->SetAdventureClass(value);
  1631. }
  1632. return 0;
  1633. }
  1634. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1635. if (!lua_interface)
  1636. return 0;
  1637. Spawn* spawn = lua_interface->GetSpawn(state);
  1638. int8 value = lua_interface->GetInt8Value(state, 2);
  1639. lua_interface->ResetFunctionStack(state);
  1640. if (spawn) {
  1641. spawn->SetTradeskillClass(value);
  1642. if (spawn->IsEntity()) {
  1643. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1644. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1645. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1646. }
  1647. if (spawn->IsPlayer())
  1648. ((Player*)spawn)->SetCharSheetChanged(true);
  1649. }
  1650. return 0;
  1651. }
  1652. int EQ2Emu_lua_SetMount(lua_State* state) {
  1653. if (!lua_interface)
  1654. return 0;
  1655. Spawn* spawn = lua_interface->GetSpawn(state);
  1656. int16 value = lua_interface->GetInt16Value(state, 2);
  1657. if (spawn && spawn->IsEntity()) {
  1658. ((Entity*)spawn)->SetMount(value);
  1659. EQ2_Color color;
  1660. color.red = 255;
  1661. color.green = 255;
  1662. color.blue = 255;
  1663. ((Entity*)spawn)->SetMountColor(&color);
  1664. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1665. }
  1666. return 0;
  1667. }
  1668. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1669. if (!lua_interface)
  1670. return 0;
  1671. Spawn* spawn = lua_interface->GetSpawn(state);
  1672. EQ2_Color mount_color;
  1673. EQ2_Color saddle_color;
  1674. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1675. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1676. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1677. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1678. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1679. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1680. if (spawn && spawn->IsEntity()) {
  1681. ((Entity*)spawn)->SetMountColor(&mount_color);
  1682. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1683. }
  1684. return 0;
  1685. }
  1686. int EQ2Emu_lua_GetMount(lua_State* state) {
  1687. if (!lua_interface)
  1688. return 0;
  1689. Spawn* spawn = lua_interface->GetSpawn(state);
  1690. if (spawn && spawn->IsEntity()) {
  1691. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1692. return 1;
  1693. }
  1694. return 0;
  1695. }
  1696. int EQ2Emu_lua_GetRace(lua_State* state) {
  1697. if (!lua_interface)
  1698. return 0;
  1699. Spawn* spawn = lua_interface->GetSpawn(state);
  1700. if (spawn)
  1701. {
  1702. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1703. lua_interface->SetInt32Value(state, spawn->GetRace());
  1704. return 1;
  1705. }
  1706. return 0;
  1707. }
  1708. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1709. if (!lua_interface)
  1710. return 0;
  1711. Spawn* spawn = lua_interface->GetSpawn(state);
  1712. if (spawn) {
  1713. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1714. return 1;
  1715. }
  1716. return 0;
  1717. }
  1718. int EQ2Emu_lua_GetClass(lua_State* state) {
  1719. Spawn* spawn = lua_interface->GetSpawn(state);
  1720. if (spawn) {
  1721. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1722. return 1;
  1723. }
  1724. return 0;
  1725. }
  1726. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1727. Spawn* spawn = lua_interface->GetSpawn(state);
  1728. if (spawn) {
  1729. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1730. return 1;
  1731. }
  1732. return 0;
  1733. }
  1734. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1735. if (!lua_interface)
  1736. return 0;
  1737. Spawn* spawn = lua_interface->GetSpawn(state);
  1738. float value = lua_interface->GetFloatValue(state, 2);
  1739. lua_interface->ResetFunctionStack(state);
  1740. if (spawn) {
  1741. spawn->SetSpeed(value);
  1742. ((Entity*)spawn)->SetSpeed(value);
  1743. if (spawn->IsPlayer()) {
  1744. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1745. if (client) {
  1746. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1747. if (packet) {
  1748. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1749. packet->setDataByName("speed", value);
  1750. packet->setDataByName("size", 0.51);
  1751. EQ2Packet* app = packet->serialize();
  1752. client->QueuePacket(app);
  1753. safe_delete(packet);
  1754. }
  1755. }
  1756. }
  1757. }
  1758. return 0;
  1759. }
  1760. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1761. if (!lua_interface)
  1762. return 0;
  1763. Spawn* spawn = lua_interface->GetSpawn(state);
  1764. const int16 type = lua_interface->GetInt16Value(state, 2);
  1765. const float value = lua_interface->GetFloatValue(state, 3);
  1766. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1767. int64 class_req = 0;
  1768. int32 class_id = 0;
  1769. vector<int16> faction_req;
  1770. vector<int16> race_req;
  1771. int32 i = 0;
  1772. int8 f = 0;
  1773. int8 r = 0;
  1774. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1775. if (class_id < 100) {
  1776. class_req += pow(2.0, double(class_id - 1));
  1777. }
  1778. else if (class_id > 100 && class_id < 1000) {
  1779. race_req.push_back(class_id);
  1780. r++;
  1781. }
  1782. else {
  1783. faction_req.push_back(class_id);
  1784. f++;
  1785. }
  1786. i++;
  1787. }
  1788. if (value != 0 && type >= 0) {
  1789. if (luaspell && luaspell->spell && luaspell->caster) {
  1790. ZoneServer* zone = luaspell->caster->GetZone();
  1791. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1792. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1793. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1794. if (target) {
  1795. if (target->IsPlayer()) {
  1796. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1797. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1798. if (((Player*)target)->GetGroupMemberInfo())
  1799. ((Player*)target)->UpdateGroupMemberInfo();
  1800. ((Player*)target)->SetCharSheetChanged(true);
  1801. }
  1802. else if (target->IsNPC())
  1803. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1804. else
  1805. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1806. }
  1807. }
  1808. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1809. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1810. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1811. }
  1812. else if (spawn && spawn->IsEntity()) {
  1813. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1814. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1815. if (spawn->IsPlayer())
  1816. ((Player*)spawn)->SetCharSheetChanged(true);
  1817. }
  1818. else
  1819. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1820. }
  1821. else
  1822. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1823. return 0;
  1824. }
  1825. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1826. if (!lua_interface)
  1827. return 0;
  1828. Spawn* spawn = lua_interface->GetSpawn(state);
  1829. int16 type = lua_interface->GetInt16Value(state, 2);
  1830. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1831. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1832. if (!spawn) {
  1833. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1834. return 0;
  1835. }
  1836. if (!spawn->IsEntity()) {
  1837. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1838. return 0;
  1839. }
  1840. if (value == 0) {
  1841. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1842. return 0;
  1843. }
  1844. if (!luaspell || !luaspell->spell) {
  1845. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1846. return 0;
  1847. }
  1848. int32 class_req = 0;
  1849. vector<int16> faction_req;
  1850. vector<int16> race_req;
  1851. int32 class_id = 0;
  1852. int32 i = 0;
  1853. int8 f = 0;
  1854. int8 r = 0;
  1855. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1856. if (class_id < 100) {
  1857. class_req += pow(2.0, double(class_id - 1));
  1858. }
  1859. else if (class_id > 100 && class_id < 1000) {
  1860. race_req.push_back(class_id);
  1861. r++;
  1862. }
  1863. else {
  1864. faction_req.push_back(class_id);
  1865. f++;
  1866. }
  1867. i++;
  1868. }
  1869. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1870. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1871. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1872. if (spawn->IsPlayer())
  1873. ((Player*)spawn)->SetCharSheetChanged(true);
  1874. return 0;
  1875. }
  1876. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1877. if (!lua_interface)
  1878. return 0;
  1879. Spawn* spawn = lua_interface->GetSpawn(state);
  1880. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1881. if (luaspell && luaspell->spell) {
  1882. ZoneServer* zone = luaspell->caster->GetZone();
  1883. Spawn* target = 0;
  1884. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1885. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1886. target = zone->GetSpawnByID(luaspell->targets[i]);
  1887. if (target && target->IsEntity()) {
  1888. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1889. if (target->IsPlayer())
  1890. ((Player*)target)->SetCharSheetChanged(true);
  1891. }
  1892. }
  1893. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1894. }
  1895. else if (spawn && spawn->IsEntity()) {
  1896. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1897. if (spawn->IsPlayer())
  1898. ((Player*)spawn)->SetCharSheetChanged(true);
  1899. }
  1900. return 0;
  1901. }
  1902. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1903. if (!lua_interface)
  1904. return 0;
  1905. Spawn* spawn = lua_interface->GetSpawn(state);
  1906. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1907. float value = lua_interface->GetFloatValue(state, 3);
  1908. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1909. if (value != 0) {
  1910. int32 spell_id = 0;
  1911. if (luaspell && luaspell->spell && luaspell->caster) {
  1912. spell_id = luaspell->spell->GetSpellID();
  1913. ZoneServer* zone = luaspell->caster->GetZone();
  1914. Spawn* target = 0;
  1915. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1916. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1917. target = zone->GetSpawnByID(luaspell->targets[i]);
  1918. if (target && target->Alive()) {
  1919. if (target->IsPlayer()) {
  1920. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1921. Client* client = target->GetZone()->GetClientBySpawn(target);
  1922. if (client) {
  1923. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1924. if (packet)
  1925. client->QueuePacket(packet);
  1926. }
  1927. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1928. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1929. }
  1930. else if (target->IsNPC()) {
  1931. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1932. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1933. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1934. }
  1935. else
  1936. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1937. }
  1938. }
  1939. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1940. }
  1941. else if (spawn) {
  1942. if (spawn->IsPlayer()) {
  1943. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1944. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1945. if (client) {
  1946. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1947. if (packet)
  1948. client->QueuePacket(packet);
  1949. }
  1950. }
  1951. else if (spawn->IsNPC())
  1952. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1953. else
  1954. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1955. }
  1956. }
  1957. else
  1958. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1959. return 0;
  1960. }
  1961. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1962. if (!lua_interface)
  1963. return 0;
  1964. Spawn* spawn = lua_interface->GetSpawn(state);
  1965. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1966. if (spawn && spawn->IsPlayer()) {
  1967. int32 spell_id = 0;
  1968. if (luaspell && luaspell->spell) {
  1969. spell_id = luaspell->spell->GetSpellID();
  1970. ZoneServer* zone = luaspell->caster->GetZone();
  1971. Spawn* target = 0;
  1972. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1973. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1974. target = zone->GetSpawnByID(luaspell->targets[i]);
  1975. if (target) {
  1976. if (target->IsPlayer()) {
  1977. ((Player*)target)->RemoveSkillBonus(spell_id);
  1978. Client* client = target->GetZone()->GetClientBySpawn(target);
  1979. if (client) {
  1980. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1981. if (packet)
  1982. client->QueuePacket(packet);
  1983. }
  1984. }
  1985. else if (target->IsNPC())
  1986. ((NPC*)target)->RemoveSkillBonus(spell_id);
  1987. else
  1988. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1989. }
  1990. }
  1991. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1992. }
  1993. else if (spawn) {
  1994. if (spawn->IsPlayer()) {
  1995. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  1996. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1997. if (client) {
  1998. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1999. if (packet)
  2000. client->QueuePacket(packet);
  2001. }
  2002. }
  2003. else if (spawn->IsNPC())
  2004. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2005. else
  2006. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2007. }
  2008. }
  2009. return 0;
  2010. }
  2011. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2012. if (!lua_interface)
  2013. return 0;
  2014. Spawn* spawn = lua_interface->GetSpawn(state);
  2015. int8 type = lua_interface->GetInt32Value(state, 2);
  2016. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2017. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2018. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2019. ZoneServer* zone = luaspell->caster->GetZone();
  2020. Spawn* target = 0;
  2021. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2022. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2023. target = zone->GetSpawnByID(luaspell->targets[i]);
  2024. if (target && target->IsEntity()) {
  2025. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2026. ((Entity*)target)->AddMezSpell(luaspell);
  2027. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2028. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2029. if (target->IsNPC())
  2030. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2031. }
  2032. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2033. ((Entity*)target)->AddStifleSpell(luaspell);
  2034. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2035. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2036. if (target->IsNPC())
  2037. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2038. }
  2039. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2040. ((Entity*)target)->AddDazeSpell(luaspell);
  2041. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2042. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2043. if (target->IsNPC())
  2044. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2045. }
  2046. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2047. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2048. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2049. ((Entity*)target)->AddStunSpell(luaspell);
  2050. if (target->IsNPC())
  2051. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2052. }
  2053. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2054. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2055. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2056. ((Entity*)target)->AddRootSpell(luaspell);
  2057. if (target->IsNPC())
  2058. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2059. }
  2060. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2061. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2062. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2063. ((Entity*)target)->AddFearSpell(luaspell);
  2064. if (target->IsNPC())
  2065. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2066. }
  2067. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2068. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2069. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2070. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2071. }
  2072. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2073. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2074. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2075. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2076. }
  2077. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2078. ((Entity*)target)->AddSnareSpell(luaspell);
  2079. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2080. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2081. if (target->IsNPC())
  2082. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2083. }
  2084. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2085. ((Entity*)target)->AddFlightSpell(luaspell);
  2086. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2087. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2088. }
  2089. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2090. ((Entity*)target)->AddGlideSpell(luaspell);
  2091. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2092. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2093. }
  2094. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2095. ((Entity*)target)->AddSafefallSpell(luaspell);
  2096. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2097. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2098. }
  2099. else
  2100. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2101. }
  2102. else
  2103. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2104. }
  2105. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2106. }
  2107. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2108. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2109. ((Entity*)spawn)->AddMezSpell(luaspell);
  2110. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2111. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2112. }
  2113. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2114. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2115. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2116. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2117. }
  2118. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2119. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2120. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2121. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2122. }
  2123. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2124. ((Entity*)spawn)->AddStunSpell(luaspell);
  2125. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2126. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2127. }
  2128. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2129. ((Entity*)spawn)->AddRootSpell(luaspell);
  2130. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2131. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2132. }
  2133. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2134. ((Entity*)spawn)->AddFearSpell(luaspell);
  2135. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2136. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2137. }
  2138. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2139. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2140. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2141. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2142. }
  2143. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2144. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2145. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2146. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2147. }
  2148. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2149. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2150. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2151. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2152. }
  2153. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2154. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2155. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2156. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2157. }
  2158. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2159. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2160. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2161. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2162. }
  2163. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2164. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2165. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2166. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2167. }
  2168. else
  2169. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2170. }
  2171. else
  2172. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2173. return 0;
  2174. }
  2175. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2176. if (!lua_interface)
  2177. return 0;
  2178. Spawn* spawn = lua_interface->GetSpawn(state);
  2179. int8 type = lua_interface->GetInt8Value(state, 2);
  2180. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2181. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2182. if (spawn && spawn->IsEntity()) {
  2183. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2184. ZoneServer* zone = luaspell->caster->GetZone();
  2185. Spawn* target = 0;
  2186. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2187. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2188. target = zone->GetSpawnByID(luaspell->targets[i]);
  2189. if (target) {
  2190. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2191. ((Entity*)target)->RemoveMezSpell(luaspell);
  2192. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2193. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2194. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2195. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2196. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2197. ((Entity*)target)->RemoveStunSpell(luaspell);
  2198. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2199. ((Entity*)target)->RemoveRootSpell(luaspell);
  2200. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2201. ((Entity*)target)->RemoveFearSpell(luaspell);
  2202. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2203. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2204. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2205. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2206. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2207. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2208. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2209. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2210. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2211. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2212. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2213. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2214. else
  2215. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2216. }
  2217. }
  2218. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2219. }
  2220. else if (only_remove_spawn) {
  2221. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2222. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2223. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2224. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2225. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2226. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2227. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2228. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2229. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2230. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2231. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2232. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2233. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2234. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2235. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2236. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2237. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2238. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2239. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2240. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2241. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2242. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2243. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2244. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2245. else
  2246. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2247. }
  2248. }
  2249. return 0;
  2250. }
  2251. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2252. if (!lua_interface)
  2253. return 0;
  2254. Spawn* spawn = lua_interface->GetSpawn(state);
  2255. int16 value = lua_interface->GetInt16Value(state, 2);
  2256. if (spawn && spawn->IsEntity()) {
  2257. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2258. if (spawn->IsPlayer())
  2259. ((Player*)spawn)->SetCharSheetChanged(true);
  2260. }
  2261. return 0;
  2262. }
  2263. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2264. if (!lua_interface)
  2265. return 0;
  2266. Spawn* spawn = lua_interface->GetSpawn(state);
  2267. int16 value = lua_interface->GetInt16Value(state, 2);
  2268. if (spawn && spawn->IsEntity()) {
  2269. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2270. if (spawn->IsPlayer())
  2271. ((Player*)spawn)->SetCharSheetChanged(true);
  2272. }
  2273. return 0;
  2274. }
  2275. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2276. if (!lua_interface)
  2277. return 0;
  2278. Spawn* spawn = lua_interface->GetSpawn(state);
  2279. int16 value = lua_interface->GetInt16Value(state, 2);
  2280. if (spawn && spawn->IsEntity()) {
  2281. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2282. if (spawn->IsPlayer())
  2283. ((Player*)spawn)->SetCharSheetChanged(true);
  2284. }
  2285. return 0;
  2286. }
  2287. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2288. if (!lua_interface)
  2289. return 0;
  2290. Spawn* spawn = lua_interface->GetSpawn(state);
  2291. int16 value = lua_interface->GetInt16Value(state, 2);
  2292. if (spawn && spawn->IsEntity()) {
  2293. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2294. if (spawn->IsPlayer())
  2295. ((Player*)spawn)->SetCharSheetChanged(true);
  2296. }
  2297. return 0;
  2298. }
  2299. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2300. if (!lua_interface)
  2301. return 0;
  2302. Spawn* spawn = lua_interface->GetSpawn(state);
  2303. int16 value = lua_interface->GetInt16Value(state, 2);
  2304. if (spawn && spawn->IsEntity()) {
  2305. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2306. if (spawn->IsPlayer())
  2307. ((Player*)spawn)->SetCharSheetChanged(true);
  2308. }
  2309. return 0;
  2310. }
  2311. int EQ2Emu_lua_SetInt(lua_State* state) {
  2312. if (!lua_interface)
  2313. return 0;
  2314. Spawn* spawn = lua_interface->GetSpawn(state);
  2315. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2316. if (spawn && spawn->IsEntity()) {
  2317. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2318. if (spawn->IsPlayer())
  2319. ((Player*)spawn)->SetCharSheetChanged(true);
  2320. }
  2321. return 0;
  2322. }
  2323. int EQ2Emu_lua_SetWis(lua_State* state) {
  2324. if (!lua_interface)
  2325. return 0;
  2326. Spawn* spawn = lua_interface->GetSpawn(state);
  2327. float value = lua_interface->GetFloatValue(state, 2);
  2328. if (spawn && spawn->IsEntity()) {
  2329. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2330. if (spawn->IsPlayer())
  2331. ((Player*)spawn)->SetCharSheetChanged(true);
  2332. }
  2333. return 0;
  2334. }
  2335. int EQ2Emu_lua_SetSta(lua_State* state) {
  2336. if (!lua_interface)
  2337. return 0;
  2338. Spawn* spawn = lua_interface->GetSpawn(state);
  2339. float value = lua_interface->GetFloatValue(state, 2);
  2340. if (spawn && spawn->IsEntity()) {
  2341. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2342. if (spawn->IsPlayer())
  2343. ((Player*)spawn)->SetCharSheetChanged(true);
  2344. }
  2345. return 0;
  2346. }
  2347. int EQ2Emu_lua_SetStr(lua_State* state) {
  2348. if (!lua_interface)
  2349. return 0;
  2350. Spawn* spawn = lua_interface->GetSpawn(state);
  2351. float value = lua_interface->GetFloatValue(state, 2);
  2352. if (spawn && spawn->IsEntity()) {
  2353. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2354. if (spawn->IsPlayer())
  2355. ((Player*)spawn)->SetCharSheetChanged(true);
  2356. }
  2357. return 0;
  2358. }
  2359. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2360. if (!lua_interface)
  2361. return 0;
  2362. Spawn* spawn = lua_interface->GetSpawn(state);
  2363. float value = lua_interface->GetFloatValue(state, 2);
  2364. if (spawn && spawn->IsEntity()) {
  2365. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2366. if (spawn->IsPlayer())
  2367. ((Player*)spawn)->SetCharSheetChanged(true);
  2368. }
  2369. return 0;
  2370. }
  2371. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2372. if (!lua_interface)
  2373. return 0;
  2374. Spawn* spawn = lua_interface->GetSpawn(state);
  2375. if (spawn) {
  2376. lua_interface->SetInt32Value(state, spawn->GetHP());
  2377. return 1;
  2378. }
  2379. return 0;
  2380. }
  2381. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2382. if (!lua_interface)
  2383. return 0;
  2384. Spawn* spawn = lua_interface->GetSpawn(state);
  2385. if (spawn) {
  2386. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2387. return 1;
  2388. }
  2389. return 0;
  2390. }
  2391. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2392. if (!lua_interface)
  2393. return 0;
  2394. Spawn* spawn = lua_interface->GetSpawn(state);
  2395. if (spawn) {
  2396. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2397. return 1;
  2398. }
  2399. return 0;
  2400. }
  2401. int EQ2Emu_lua_GetName(lua_State* state) {
  2402. if (!lua_interface)
  2403. return 0;
  2404. Spawn* spawn = lua_interface->GetSpawn(state);
  2405. if (spawn) {
  2406. lua_interface->SetStringValue(state, spawn->GetName());
  2407. return 1;
  2408. }
  2409. return 0;
  2410. }
  2411. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2412. Spawn* spawn = lua_interface->GetSpawn(state);
  2413. if (spawn) {
  2414. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2415. return 1;
  2416. }
  2417. return 0;
  2418. }
  2419. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2420. if (!lua_interface)
  2421. return 0;
  2422. Spawn* spawn = lua_interface->GetSpawn(state);
  2423. if (spawn) {
  2424. lua_interface->SetInt32Value(state, spawn->GetPower());
  2425. return 1;
  2426. }
  2427. return 0;
  2428. }
  2429. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2430. if (!lua_interface)
  2431. return 0;
  2432. Spawn* spawn = lua_interface->GetSpawn(state);
  2433. if (spawn) {
  2434. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2435. return 1;
  2436. }
  2437. return 0;
  2438. }
  2439. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2440. if (!lua_interface)
  2441. return 0;
  2442. Spawn* spawn = lua_interface->GetSpawn(state);
  2443. if (spawn) {
  2444. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2445. return 1;
  2446. }
  2447. return 0;
  2448. }
  2449. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2450. if (!lua_interface)
  2451. return 0;
  2452. Spawn* spawn = lua_interface->GetSpawn(state);
  2453. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2454. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2455. if (spawn && spawn2) {
  2456. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2457. lua_interface->SetFloatValue(state, distance);
  2458. return 1;
  2459. }
  2460. return 0;
  2461. }
  2462. int EQ2Emu_lua_GetX(lua_State* state) {
  2463. if (!lua_interface)
  2464. return 0;
  2465. Spawn* spawn = lua_interface->GetSpawn(state);
  2466. if (spawn) {
  2467. lua_interface->SetFloatValue(state, spawn->GetX());
  2468. return 1;
  2469. }
  2470. return 0;
  2471. }
  2472. int EQ2Emu_lua_GetY(lua_State* state) {
  2473. if (!lua_interface)
  2474. return 0;
  2475. Spawn* spawn = lua_interface->GetSpawn(state);
  2476. if (spawn) {
  2477. lua_interface->SetFloatValue(state, spawn->GetY());
  2478. return 1;
  2479. }
  2480. return 0;
  2481. }
  2482. int EQ2Emu_lua_GetZ(lua_State* state) {
  2483. if (!lua_interface)
  2484. return 0;
  2485. Spawn* spawn = lua_interface->GetSpawn(state);
  2486. if (spawn) {
  2487. lua_interface->SetFloatValue(state, spawn->GetZ());
  2488. return 1;
  2489. }
  2490. return 0;
  2491. }
  2492. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2493. if (!lua_interface)
  2494. return 0;
  2495. Spawn* spawn = lua_interface->GetSpawn(state);
  2496. if (spawn) {
  2497. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2498. return 1;
  2499. }
  2500. return 0;
  2501. }
  2502. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2503. if (!lua_interface)
  2504. return 0;
  2505. Spawn* spawn = lua_interface->GetSpawn(state);
  2506. if (spawn) {
  2507. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2508. return 1;
  2509. }
  2510. return 0;
  2511. }
  2512. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2513. if (!lua_interface)
  2514. return 0;
  2515. Spawn* spawn = lua_interface->GetSpawn(state);
  2516. if (spawn) {
  2517. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2518. return 1;
  2519. }
  2520. return 0;
  2521. }
  2522. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2523. if (!lua_interface)
  2524. return 0;
  2525. Spawn* spawn = lua_interface->GetSpawn(state);
  2526. if (spawn && spawn->IsEntity()) {
  2527. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2528. return 1;
  2529. }
  2530. return 0;
  2531. }
  2532. int EQ2Emu_lua_GetInt(lua_State* state) {
  2533. if (!lua_interface)
  2534. return 0;
  2535. Spawn* spawn = lua_interface->GetSpawn(state);
  2536. if (spawn && spawn->IsEntity()) {
  2537. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2538. return 1;
  2539. }
  2540. return 0;
  2541. }
  2542. int EQ2Emu_lua_GetWis(lua_State* state) {
  2543. if (!lua_interface)
  2544. return 0;
  2545. Spawn* spawn = lua_interface->GetSpawn(state);
  2546. if (spawn && spawn->IsEntity()) {
  2547. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2548. return 1;
  2549. }
  2550. return 0;
  2551. }
  2552. int EQ2Emu_lua_GetSta(lua_State* state) {
  2553. if (!lua_interface)
  2554. return 0;
  2555. Spawn* spawn = lua_interface->GetSpawn(state);
  2556. if (spawn && spawn->IsEntity()) {
  2557. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2558. return 1;
  2559. }
  2560. return 0;
  2561. }
  2562. int EQ2Emu_lua_GetStr(lua_State* state) {
  2563. if (!lua_interface)
  2564. return 0;
  2565. Spawn* spawn = lua_interface->GetSpawn(state);
  2566. if (spawn && spawn->IsEntity()) {
  2567. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2568. return 1;
  2569. }
  2570. return 0;
  2571. }
  2572. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2573. if (!lua_interface)
  2574. return 0;
  2575. Spawn* spawn = lua_interface->GetSpawn(state);
  2576. if (spawn && spawn->IsEntity()) {
  2577. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2578. return 1;
  2579. }
  2580. return 0;
  2581. }
  2582. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2583. if (!lua_interface)
  2584. return 0;
  2585. Spawn* spawn = lua_interface->GetSpawn(state);
  2586. if (spawn && spawn->IsEntity()) {
  2587. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2588. return 1;
  2589. }
  2590. return 0;
  2591. }
  2592. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2593. if (!lua_interface)
  2594. return 0;
  2595. Spawn* spawn = lua_interface->GetSpawn(state);
  2596. if (spawn && spawn->IsEntity()) {
  2597. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2598. return 1;
  2599. }
  2600. return 0;
  2601. }
  2602. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2603. if (!lua_interface)
  2604. return 0;
  2605. Spawn* spawn = lua_interface->GetSpawn(state);
  2606. if (spawn && spawn->IsEntity()) {
  2607. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2608. return 1;
  2609. }
  2610. return 0;
  2611. }
  2612. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2613. if (!lua_interface)
  2614. return 0;
  2615. Spawn* spawn = lua_interface->GetSpawn(state);
  2616. if (spawn && spawn->IsEntity()) {
  2617. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2618. return 1;
  2619. }
  2620. return 0;
  2621. }
  2622. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2623. if (!lua_interface)
  2624. return 0;
  2625. Spawn* spawn = lua_interface->GetSpawn(state);
  2626. if (spawn && spawn->IsEntity()) {
  2627. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2628. return 1;
  2629. }
  2630. return 0;
  2631. }
  2632. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2633. if (!lua_interface)
  2634. return 0;
  2635. Spawn* player = lua_interface->GetSpawn(state);
  2636. if (!player || !player->IsPlayer()) {
  2637. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2638. return 0;
  2639. }
  2640. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2641. if (quest_id <= 0) {
  2642. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2643. return 0;
  2644. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2645. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2646. return 0;
  2647. }
  2648. int32 step = lua_interface->GetInt32Value(state, 3);
  2649. if (step > 0) {
  2650. Client* client = player->GetZone()->GetClientBySpawn(player);
  2651. if (client)
  2652. client->AddPendingQuestUpdate(quest_id, step);
  2653. } else {
  2654. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2655. }
  2656. return 0;
  2657. }
  2658. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2659. Spawn* player = lua_interface->GetSpawn(state);
  2660. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2661. int32 step = lua_interface->GetInt32Value(state, 3);
  2662. int32 progress = lua_interface->GetInt32Value(state, 4);
  2663. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2664. Client* client = player->GetZone()->GetClientBySpawn(player);
  2665. if (client)
  2666. client->AddPendingQuestUpdate(quest_id, step, progress);
  2667. }
  2668. return 0;
  2669. }
  2670. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2671. if (!lua_interface)
  2672. return 0;
  2673. Spawn* player = lua_interface->GetSpawn(state);
  2674. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2675. if (player && player->IsPlayer() && quest_id > 0) {
  2676. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2677. return 1;
  2678. }
  2679. return 0;
  2680. }
  2681. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2682. if (!lua_interface)
  2683. return 0;
  2684. Spawn* player = lua_interface->GetSpawn(state);
  2685. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2686. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2687. if (player && player->IsPlayer() && quest_id > 0) {
  2688. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2689. return 1;
  2690. }
  2691. return 0;
  2692. }
  2693. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2694. if (!lua_interface)
  2695. return 0;
  2696. Spawn* player = lua_interface->GetSpawn(state);
  2697. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2698. if (player && player->IsPlayer() && quest_id > 0) {
  2699. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2700. return 1;
  2701. }
  2702. return 0;
  2703. }
  2704. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2705. if (!lua_interface)
  2706. return 0;
  2707. Quest* quest = lua_interface->GetQuest(state);
  2708. string name = lua_interface->GetStringValue(state, 2);
  2709. string type = lua_interface->GetStringValue(state, 3);
  2710. string zone = lua_interface->GetStringValue(state, 4);
  2711. int16 level = lua_interface->GetInt16Value(state, 5);
  2712. string description = lua_interface->GetStringValue(state, 6);
  2713. bool load = true;
  2714. if (!quest) {
  2715. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2716. load = false;
  2717. }
  2718. if (load && name.length() == 0) {
  2719. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2720. load = false;
  2721. }
  2722. if (load && type.length() == 0) {
  2723. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2724. load = false;
  2725. }
  2726. if (load && zone.length() == 0) {
  2727. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2728. load = false;
  2729. }
  2730. if (load && description.length() == 0) {
  2731. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2732. load = false;
  2733. }
  2734. if (load && level == 0) {
  2735. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2736. load = false;
  2737. }
  2738. if (load)
  2739. quest->RegisterQuest(name, type, zone, level, description);
  2740. return 0;
  2741. }
  2742. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2743. if (!lua_interface)
  2744. return 0;
  2745. Quest* quest = lua_interface->GetQuest(state);
  2746. if (quest) {
  2747. int8 level = lua_interface->GetInt16Value(state, 2);
  2748. quest->SetPrereqLevel(level);
  2749. }
  2750. return 0;
  2751. }
  2752. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2753. if (!lua_interface)
  2754. return 0;
  2755. Quest* quest = lua_interface->GetQuest(state);
  2756. if (quest) {
  2757. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2758. quest->AddPrereqQuest(quest_id);
  2759. }
  2760. return 0;
  2761. }
  2762. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2763. if (!lua_interface)
  2764. return 0;
  2765. Quest* quest = lua_interface->GetQuest(state);
  2766. if (quest) {
  2767. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2768. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2769. if (quantity == 0)
  2770. quantity = 1;
  2771. Item* master_item = master_item_list.GetItem(item_id);
  2772. if (master_item) {
  2773. Item* item = new Item(master_item);
  2774. item->details.count = quantity;
  2775. quest->AddPrereqItem(item);
  2776. }
  2777. }
  2778. return 0;
  2779. }
  2780. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2781. if (!lua_interface)
  2782. return 0;
  2783. Spawn* player = lua_interface->GetSpawn(state);
  2784. if(!player || !player->IsPlayer()) {
  2785. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  2786. return 0;
  2787. }
  2788. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2789. if (quest_id > 0) {
  2790. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2791. return 1;
  2792. } else {
  2793. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2794. }
  2795. return 0;
  2796. }
  2797. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2798. if (!lua_interface)
  2799. return 0;
  2800. Quest* quest = lua_interface->GetQuest(state);
  2801. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2802. if (quest && spawn_id > 0)
  2803. quest->SetQuestReturnNPC(spawn_id);
  2804. return 0;
  2805. }
  2806. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2807. if (!lua_interface)
  2808. return 0;
  2809. Spawn* spawn = lua_interface->GetSpawn(state);
  2810. if (!spawn) {
  2811. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2812. return 0;
  2813. }
  2814. int32 time = lua_interface->GetInt32Value(state, 2);
  2815. if (time <= 0) {
  2816. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2817. return 0;
  2818. }
  2819. string function = lua_interface->GetStringValue(state, 3);
  2820. if (function.length() == 0) {
  2821. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2822. return 0;
  2823. }
  2824. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2825. Spawn* player = lua_interface->GetSpawn(state, 5);
  2826. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2827. timer->timer = Timer::GetCurrentTime2() + time;
  2828. timer->function = function;
  2829. timer->spawn = spawn->GetID();
  2830. timer->player = player ? player->GetID() : 0;
  2831. if (max_count == 0)
  2832. max_count = 1;
  2833. timer->max_count = max_count;
  2834. timer->current_count = 0;
  2835. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2836. return 0;
  2837. }
  2838. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2839. if (!lua_interface)
  2840. return 0;
  2841. Spawn* player = lua_interface->GetSpawn(state);
  2842. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2843. if (player && player->IsPlayer() && quest_id > 0) {
  2844. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2845. return 1;
  2846. }
  2847. return 0;
  2848. }
  2849. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2850. if (!lua_interface)
  2851. return 0;
  2852. Spawn* player = lua_interface->GetSpawn(state);
  2853. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2854. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2855. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2856. if (quest)
  2857. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2858. return 1;
  2859. }
  2860. return 0;
  2861. }
  2862. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2863. if (!lua_interface)
  2864. return 0;
  2865. Spawn* player = lua_interface->GetSpawn(state);
  2866. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2867. if (player && player->IsPlayer() && quest_id > 0) {
  2868. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2869. return 1;
  2870. }
  2871. return 0;
  2872. }
  2873. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2874. if (!lua_interface)
  2875. return 0;
  2876. Spawn* npc = lua_interface->GetSpawn(state);
  2877. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2878. if (npc && !npc->IsPlayer() && quest_id > 0)
  2879. npc->AddProvidedQuest(quest_id);
  2880. return 0;
  2881. }
  2882. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2883. if (!lua_interface)
  2884. return 0;
  2885. Spawn* npc = lua_interface->GetSpawn(state);
  2886. Spawn* player = lua_interface->GetSpawn(state, 2);
  2887. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  2888. bool forced = lua_interface->GetBooleanValue(state, 4);
  2889. /* NPC is allowed to be null */
  2890. if (player && player->IsPlayer() && quest_id > 0) {
  2891. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  2892. if (master_quest) {
  2893. Client* client = player->GetZone()->GetClientBySpawn(player);
  2894. if (!client) {
  2895. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  2896. }
  2897. Quest* quest = new Quest(master_quest);
  2898. if (!quest) {
  2899. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  2900. }
  2901. if (client && quest) {
  2902. client->AddPendingQuest(quest);
  2903. if (npc)
  2904. quest->SetQuestGiver(npc->GetDatabaseID());
  2905. else
  2906. quest->SetQuestGiver(0);
  2907. client->AddPendingQuest(quest, forced);
  2908. }
  2909. }
  2910. else {
  2911. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  2912. }
  2913. }
  2914. else {
  2915. 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);
  2916. }
  2917. return 0;
  2918. }
  2919. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  2920. if (!lua_interface)
  2921. return 0;
  2922. Quest* quest = lua_interface->GetQuest(state);
  2923. if (quest) {
  2924. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2925. quest->AddPrereqClass(class_id);
  2926. }
  2927. return 0;
  2928. }
  2929. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  2930. if (!lua_interface)
  2931. return 0;
  2932. Quest* quest = lua_interface->GetQuest(state);
  2933. if (quest) {
  2934. int8 race = lua_interface->GetInt8Value(state, 2);
  2935. quest->AddPrereqRace(race);
  2936. }
  2937. return 0;
  2938. }
  2939. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  2940. if (!lua_interface)
  2941. return 0;
  2942. Quest* quest = lua_interface->GetQuest(state);
  2943. if (quest) {
  2944. int16 model_type = lua_interface->GetInt16Value(state, 2);
  2945. quest->AddPrereqModelType(model_type);
  2946. }
  2947. return 0;
  2948. }
  2949. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  2950. if (!lua_interface)
  2951. return 0;
  2952. Quest* quest = lua_interface->GetQuest(state);
  2953. if (!quest) {
  2954. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  2955. return 0;
  2956. }
  2957. int8 level = lua_interface->GetInt8Value(state, 2);
  2958. quest->SetPrereqTSLevel(level);
  2959. return 0;
  2960. }
  2961. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  2962. if (!lua_interface)
  2963. return 0;
  2964. Quest* quest = lua_interface->GetQuest(state);
  2965. if (!quest) {
  2966. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  2967. return 0;
  2968. }
  2969. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2970. quest->AddPrereqTradeskillClass(class_id);
  2971. return 0;
  2972. }
  2973. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  2974. if (!lua_interface)
  2975. return 0;
  2976. Quest* quest = lua_interface->GetQuest(state);
  2977. if (quest) {
  2978. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2979. sint32 min = lua_interface->GetSInt32Value(state, 3);
  2980. sint32 max = lua_interface->GetSInt32Value(state, 4);
  2981. quest->AddPrereqFaction(faction_id, min, max);
  2982. }
  2983. return 0;
  2984. }
  2985. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  2986. if (!lua_interface)
  2987. return 0;
  2988. Quest* quest = lua_interface->GetQuest(state);
  2989. if (quest) {
  2990. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2991. int8 quantity = lua_interface->GetInt8Value(state, 3);
  2992. if (quantity == 0)
  2993. quantity = 1;
  2994. Item* master_item = master_item_list.GetItem(item_id);
  2995. if (master_item) {
  2996. Item* item = new Item(master_item);
  2997. item->details.count = quantity;
  2998. quest->AddSelectableRewardItem(item);
  2999. }
  3000. }
  3001. return 0;
  3002. }
  3003. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3004. if (!lua_interface)
  3005. return 0;
  3006. Quest* quest = lua_interface->GetQuest(state);
  3007. if (quest) {
  3008. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3009. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3010. if (quantity == 0)
  3011. quantity = 1;
  3012. Item* master_item = master_item_list.GetItem(item_id);
  3013. if (master_item) {
  3014. Item* item = new Item(master_item);
  3015. item->details.count = quantity;
  3016. quest->AddRewardItem(item);
  3017. }
  3018. }
  3019. return 0;
  3020. }
  3021. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3022. if (!lua_interface)
  3023. return 0;
  3024. Quest* quest = lua_interface->GetQuest(state);
  3025. if (quest) {
  3026. int32 copper = lua_interface->GetInt32Value(state, 2);
  3027. int32 silver = lua_interface->GetInt32Value(state, 3);
  3028. int32 gold = lua_interface->GetInt32Value(state, 4);
  3029. int32 plat = lua_interface->GetInt32Value(state, 5);
  3030. quest->AddRewardCoins(copper, silver, gold, plat);
  3031. }
  3032. return 0;
  3033. }
  3034. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3035. if (!lua_interface)
  3036. return 0;
  3037. Quest* quest = lua_interface->GetQuest(state);
  3038. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3039. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3040. if (quest && faction_id > 0 && amount != 0)
  3041. quest->AddRewardFaction(faction_id, amount);
  3042. return 0;
  3043. }
  3044. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3045. if (!lua_interface)
  3046. return 0;
  3047. Quest* quest = lua_interface->GetQuest(state);
  3048. if (quest) {
  3049. int32 status = lua_interface->GetInt32Value(state, 2);
  3050. quest->SetRewardStatus(status);
  3051. }
  3052. return 0;
  3053. }
  3054. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3055. if (!lua_interface)
  3056. return 0;
  3057. Quest* quest = lua_interface->GetQuest(state);
  3058. if (quest) {
  3059. string comment = lua_interface->GetStringValue(state, 2);
  3060. quest->SetRewardComment(comment);
  3061. }
  3062. return 0;
  3063. }
  3064. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3065. if (!lua_interface)
  3066. return 0;
  3067. Quest* quest = lua_interface->GetQuest(state);
  3068. if (quest) {
  3069. int32 exp = lua_interface->GetInt32Value(state, 2);
  3070. quest->SetRewardXP(exp);
  3071. }
  3072. return 0;
  3073. }
  3074. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3075. Quest* quest = lua_interface->GetQuest(state);
  3076. if (quest) {
  3077. int32 step = lua_interface->GetInt32Value(state, 2);
  3078. string description = lua_interface->GetStringValue(state, 3);
  3079. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3080. float percentage = lua_interface->GetFloatValue(state, 5);
  3081. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3082. int16 icon = lua_interface->GetInt16Value(state, 7);
  3083. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3084. const char* taskgroup = 0;
  3085. if (str_taskgroup.length() > 0)
  3086. taskgroup = str_taskgroup.c_str();
  3087. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3088. if (quest_step && icon && quantity > 0)
  3089. quest_step->SetIcon(icon);
  3090. }
  3091. return 0;
  3092. }
  3093. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3094. if (!lua_interface)
  3095. return 0;
  3096. Quest* quest = lua_interface->GetQuest(state);
  3097. if (quest) {
  3098. int32 step = lua_interface->GetInt32Value(state, 2);
  3099. string description = lua_interface->GetStringValue(state, 3);
  3100. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3101. float percentage = lua_interface->GetFloatValue(state, 5);
  3102. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3103. int16 icon = lua_interface->GetInt16Value(state, 7);
  3104. const char* taskgroup = 0;
  3105. if (str_taskgroup.length() > 0)
  3106. taskgroup = str_taskgroup.c_str();
  3107. int32 npc_id = 0;
  3108. vector<int32>* ids = 0;
  3109. Spawn* spawn = nullptr;
  3110. int i = 0;
  3111. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3112. if (ids == 0)
  3113. ids = new vector<int32>;
  3114. ids->push_back(npc_id);
  3115. i++;
  3116. }
  3117. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3118. if (quest_step && icon > 0 && quantity > 0)
  3119. quest_step->SetIcon(icon);
  3120. if (quest->GetPlayer()) {
  3121. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3122. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3123. }
  3124. }
  3125. return 0;
  3126. }
  3127. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3128. if (!lua_interface)
  3129. return 0;
  3130. Quest* quest = lua_interface->GetQuest(state);
  3131. if (quest) {
  3132. int32 step = lua_interface->GetInt32Value(state, 2);
  3133. string description = lua_interface->GetStringValue(state, 3);
  3134. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3135. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3136. int16 icon = lua_interface->GetInt16Value(state, 6);
  3137. const char* taskgroup = 0;
  3138. if (str_taskgroup.length() > 0)
  3139. taskgroup = str_taskgroup.c_str();
  3140. int32 npc_id = 0;
  3141. vector<int32>* ids = 0;
  3142. int i = 0;
  3143. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3144. if (ids == 0)
  3145. ids = new vector<int32>;
  3146. ids->push_back(npc_id);
  3147. i++;
  3148. }
  3149. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3150. if (quest_step && icon > 0)
  3151. quest_step->SetIcon(icon);
  3152. if (quest->GetPlayer()) {
  3153. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3154. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3155. }
  3156. }
  3157. return 0;
  3158. }
  3159. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3160. if (!lua_interface)
  3161. return 0;
  3162. Quest* quest = lua_interface->GetQuest(state);
  3163. if (quest) {
  3164. int32 step = lua_interface->GetInt32Value(state, 2);
  3165. string description = lua_interface->GetStringValue(state, 3);
  3166. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3167. float percentage = lua_interface->GetFloatValue(state, 5);
  3168. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3169. int16 icon = lua_interface->GetInt16Value(state, 7);
  3170. const char* taskgroup = 0;
  3171. if (str_taskgroup.length() > 0)
  3172. taskgroup = str_taskgroup.c_str();
  3173. int32 item_id = 0;
  3174. vector<int32>* ids = 0;
  3175. int i = 0;
  3176. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3177. if (ids == 0)
  3178. ids = new vector<int32>;
  3179. ids->push_back(item_id);
  3180. i++;
  3181. }
  3182. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3183. if (quest_step && icon > 0 && quantity > 0)
  3184. quest_step->SetIcon(icon);
  3185. if (quest->GetPlayer()) {
  3186. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3187. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3188. }
  3189. }
  3190. return 0;
  3191. }
  3192. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3193. if (!lua_interface)
  3194. return 0;
  3195. Quest* quest = lua_interface->GetQuest(state);
  3196. if (quest) {
  3197. int32 step = lua_interface->GetInt32Value(state, 2);
  3198. string description = lua_interface->GetStringValue(state, 3);
  3199. float max_variation = lua_interface->GetFloatValue(state, 4);
  3200. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3201. int16 icon = lua_interface->GetInt16Value(state, 6);
  3202. const char* taskgroup = 0;
  3203. if (str_taskgroup.length() > 0)
  3204. taskgroup = str_taskgroup.c_str();
  3205. vector<Location>* locations = 0;
  3206. int i = 7;
  3207. while (true) {
  3208. Location loc;
  3209. loc.x = lua_interface->GetFloatValue(state, i);
  3210. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3211. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3212. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3213. break;
  3214. if (locations == 0)
  3215. locations = new vector<Location>;
  3216. locations->push_back(loc);
  3217. i += 3;
  3218. }
  3219. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3220. if (quest_step && icon > 0)
  3221. quest_step->SetIcon(icon);
  3222. if (quest->GetPlayer()) {
  3223. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3224. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3225. }
  3226. }
  3227. return 0;
  3228. }
  3229. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3230. if (!lua_interface)
  3231. return 0;
  3232. Quest* quest = lua_interface->GetQuest(state);
  3233. if (quest) {
  3234. int32 step = lua_interface->GetInt32Value(state, 2);
  3235. string description = lua_interface->GetStringValue(state, 3);
  3236. float max_variation = lua_interface->GetFloatValue(state, 4);
  3237. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3238. int16 icon = lua_interface->GetInt16Value(state, 6);
  3239. const char* taskgroup = 0;
  3240. if (str_taskgroup.length() > 0)
  3241. taskgroup = str_taskgroup.c_str();
  3242. vector<Location>* locations = 0;
  3243. int i = 7;
  3244. while (true) {
  3245. Location loc;
  3246. loc.x = lua_interface->GetFloatValue(state, i);
  3247. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3248. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3249. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3250. break;
  3251. if (locations == 0)
  3252. locations = new vector<Location>;
  3253. locations->push_back(loc);
  3254. i += 3;
  3255. }
  3256. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3257. if (quest_step && icon > 0)
  3258. quest_step->SetIcon(icon);
  3259. if (quest->GetPlayer()) {
  3260. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3261. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3262. }
  3263. }
  3264. return 0;
  3265. }
  3266. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3267. Quest* quest = lua_interface->GetQuest(state);
  3268. if (quest) {
  3269. int32 step = lua_interface->GetInt32Value(state, 2);
  3270. string description = lua_interface->GetStringValue(state, 3);
  3271. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3272. float percentage = lua_interface->GetFloatValue(state, 5);
  3273. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3274. int16 icon = lua_interface->GetInt16Value(state, 7);
  3275. const char* taskgroup = 0;
  3276. if (str_taskgroup.length() > 0)
  3277. taskgroup = str_taskgroup.c_str();
  3278. int32 spell_id = 0;
  3279. vector<int32>* ids = 0;
  3280. int i = 0;
  3281. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3282. if (ids == 0)
  3283. ids = new vector<int32>;
  3284. ids->push_back(spell_id);
  3285. i++;
  3286. }
  3287. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3288. if (quest_step && icon > 0 && quantity > 0)
  3289. quest_step->SetIcon(icon);
  3290. if (quest->GetPlayer()) {
  3291. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3292. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3293. }
  3294. }
  3295. return 0;
  3296. }
  3297. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3298. if (!lua_interface)
  3299. return 0;
  3300. Quest* quest = lua_interface->GetQuest(state);
  3301. if (quest) {
  3302. int32 step = lua_interface->GetInt32Value(state, 2);
  3303. string description = lua_interface->GetStringValue(state, 3);
  3304. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3305. float percentage = lua_interface->GetFloatValue(state, 5);
  3306. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3307. int16 icon = lua_interface->GetInt16Value(state, 7);
  3308. const char* taskgroup = 0;
  3309. if (str_taskgroup.length() > 0)
  3310. taskgroup = str_taskgroup.c_str();
  3311. int32 item_id = 0;
  3312. vector<int32>* ids = 0;
  3313. int i = 0;
  3314. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3315. if (ids == 0)
  3316. ids = new vector<int32>;
  3317. ids->push_back(item_id);
  3318. i++;
  3319. }
  3320. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3321. if (quest_step && icon > 0 && quantity > 0)
  3322. quest_step->SetIcon(icon);
  3323. if (quest->GetPlayer()) {
  3324. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3325. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3326. }
  3327. }
  3328. return 0;
  3329. }
  3330. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3331. if (!lua_interface)
  3332. return 0;
  3333. Quest* quest = lua_interface->GetQuest(state);
  3334. if (quest) {
  3335. int32 step = lua_interface->GetInt32Value(state, 2);
  3336. string description = lua_interface->GetStringValue(state, 3);
  3337. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3338. float percentage = lua_interface->GetFloatValue(state, 5);
  3339. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3340. int16 icon = lua_interface->GetInt16Value(state, 7);
  3341. const char* taskgroup = 0;
  3342. if (str_taskgroup.length() > 0)
  3343. taskgroup = str_taskgroup.c_str();
  3344. int32 item_id = 0;
  3345. vector<int32>* ids = 0;
  3346. int i = 0;
  3347. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3348. if (ids == 0)
  3349. ids = new vector<int32>;
  3350. ids->push_back(item_id);
  3351. i++;
  3352. }
  3353. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3354. if (quest_step && icon > 0 && quantity > 0)
  3355. quest_step->SetIcon(icon);
  3356. if (quest->GetPlayer()) {
  3357. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3358. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3359. }
  3360. }
  3361. return 0;
  3362. }
  3363. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3364. if (!lua_interface)
  3365. return 0;
  3366. Quest* quest = lua_interface->GetQuest(state);
  3367. if (quest) {
  3368. string action = lua_interface->GetStringValue(state, 2);
  3369. if (action.length() > 0)
  3370. quest->SetCompleteAction(action);
  3371. }
  3372. return 0;
  3373. }
  3374. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3375. if (!lua_interface)
  3376. return 0;
  3377. Quest* quest = lua_interface->GetQuest(state);
  3378. if (quest) {
  3379. int32 step = lua_interface->GetInt32Value(state, 2);
  3380. string action = lua_interface->GetStringValue(state, 3);
  3381. if (step > 0 && action.length() > 0)
  3382. quest->AddCompleteAction(step, action);
  3383. }
  3384. return 0;
  3385. }
  3386. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3387. if (!lua_interface)
  3388. return 0;
  3389. Quest* quest = lua_interface->GetQuest(state);
  3390. if (quest) {
  3391. int32 step = lua_interface->GetInt32Value(state, 2);
  3392. string action = lua_interface->GetStringValue(state, 3);
  3393. if (step > 0 && action.length() > 0)
  3394. quest->AddProgressAction(step, action);
  3395. }
  3396. return 0;
  3397. }
  3398. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3399. if (!lua_interface)
  3400. return 0;
  3401. Quest* quest = lua_interface->GetQuest(state);
  3402. string description = lua_interface->GetStringValue(state, 2);
  3403. if (quest && description.length() > 0)
  3404. quest->SetDescription(description);
  3405. return 0;
  3406. }
  3407. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3408. if (!lua_interface)
  3409. return 0;
  3410. Quest* quest = lua_interface->GetQuest(state);
  3411. string description = lua_interface->GetStringValue(state, 2);
  3412. if (quest && description.length() > 0)
  3413. quest->SetCompletedDescription(description);
  3414. return 0;
  3415. }
  3416. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3417. if (!lua_interface)
  3418. return 0;
  3419. Quest* quest = lua_interface->GetQuest(state);
  3420. int32 step = lua_interface->GetInt32Value(state, 2);
  3421. string description = lua_interface->GetStringValue(state, 3);
  3422. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3423. if (quest && step > 0 && description.length() > 0) {
  3424. quest->SetTaskGroupDescription(step, description, display_bullets);
  3425. if (quest->GetPlayer()) {
  3426. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3427. if (client)
  3428. client->SendQuestUpdateStep(quest, step, false);
  3429. }
  3430. }
  3431. return 0;
  3432. }
  3433. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3434. if (!lua_interface)
  3435. return 0;
  3436. Quest* quest = lua_interface->GetQuest(state);
  3437. int32 step = lua_interface->GetInt32Value(state, 2);
  3438. string description = lua_interface->GetStringValue(state, 3);
  3439. if (quest && step > 0 && description.length() > 0) {
  3440. quest->SetStepDescription(step, description);
  3441. if (quest->GetPlayer()) {
  3442. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3443. if (client)
  3444. client->SendQuestUpdateStepImmediately(quest, step);
  3445. }
  3446. }
  3447. return 0;
  3448. }
  3449. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3450. Quest* quest = lua_interface->GetQuest(state);
  3451. string zone = lua_interface->GetStringValue(state, 2);
  3452. if (quest && zone.length() > 0)
  3453. quest->SetZone(zone);
  3454. return 0;
  3455. }
  3456. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3457. if (!lua_interface)
  3458. return 0;
  3459. Quest* quest = lua_interface->GetQuest(state);
  3460. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3461. int32 coin = lua_interface->GetInt32Value(state, 3);
  3462. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3463. string rewards_str = lua_interface->GetStringValue(state, 5);
  3464. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3465. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3466. string text = lua_interface->GetStringValue(state, 8);
  3467. int32 source_id = 0;
  3468. if (quest)
  3469. source_id = quest->GetQuestID();
  3470. if (playerSpawn && playerSpawn->IsPlayer()) {
  3471. Player* player = (Player*)playerSpawn;
  3472. Client* client = player->GetZone()->GetClientBySpawn(player);
  3473. if (client) {
  3474. vector<Item*> reward_items;
  3475. vector<Item*> selectable_reward_items;
  3476. if (rewards_str.length() > 0) {
  3477. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3478. map<unsigned int, unsigned short>::iterator itr;
  3479. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3480. if (itr->first > 0) {
  3481. Item* item = new Item(master_item_list.GetItem(itr->first));
  3482. if (item) {
  3483. if (itr->second > 0)
  3484. item->stack_count = itr->second;
  3485. reward_items.push_back(item);
  3486. }
  3487. }
  3488. }
  3489. }
  3490. if (select_rewards_str.length() > 0) {
  3491. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3492. map<unsigned int, unsigned short>::iterator itr;
  3493. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3494. if (itr->first > 0) {
  3495. Item* item = new Item(master_item_list.GetItem(itr->first));
  3496. if (item) {
  3497. if (itr->second > 0)
  3498. item->stack_count = itr->second;
  3499. selectable_reward_items.push_back(item);
  3500. }
  3501. }
  3502. }
  3503. }
  3504. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3505. const char* reward_type = "Quest Reward!";
  3506. if (!quest)
  3507. reward_type = "Reward!";
  3508. client->DisplayQuestRewards(0, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3509. }
  3510. }
  3511. /*PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", client->GetVersion());
  3512. if (packet2) {
  3513. player->AddCoins(coin);
  3514. client->PlaySound("coin_cha_ching");
  3515. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  3516. if(quest)
  3517. packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
  3518. else
  3519. packet2->setSubstructDataByName("reward_data", "reward", "Reward!");
  3520. packet2->setSubstructDataByName("reward_data", "coin", coin);
  3521. if (player->GetGuild()) {
  3522. player->GetInfoStruct()->status_points += status_points;
  3523. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  3524. }
  3525. if (rewards_str.length() > 0) {
  3526. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3527. vector<Item*> reward_items;
  3528. map<unsigned int, unsigned short>::iterator itr;
  3529. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3530. if (itr->first > 0) {
  3531. Item* item = new Item(master_item_list.GetItem(itr->first));
  3532. if (item) {
  3533. if (itr->second > 0)
  3534. item->stack_count = itr->second;
  3535. reward_items.push_back(item);
  3536. }
  3537. }
  3538. }
  3539. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", reward_items.size());
  3540. for (int i = 0; i < reward_items.size(); i++) {
  3541. Item* item = reward_items[i];
  3542. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  3543. packet2->setItemArrayDataByName("item", item, client->GetPlayer(), i, 0, -1);
  3544. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  3545. }
  3546. }
  3547. if (select_rewards_str.length() > 0) {
  3548. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3549. vector<Item*> reward_items;
  3550. map<unsigned int, unsigned short>::iterator itr;
  3551. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3552. if (itr->first > 0) {
  3553. Item* item = new Item(master_item_list.GetItem(itr->first));
  3554. if (item) {
  3555. if (itr->second > 0)
  3556. item->stack_count = itr->second;
  3557. reward_items.push_back(item);
  3558. }
  3559. }
  3560. }
  3561. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", reward_items.size());
  3562. for (int i = 0; i < reward_items.size(); i++) {
  3563. Item* item = reward_items[i];
  3564. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  3565. packet2->setItemArrayDataByName("select_item", item, client->GetPlayer(), i, 0, -1);
  3566. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  3567. }
  3568. }
  3569. if (factions_map_str.length() > 0) {
  3570. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3571. map<unsigned int, signed int>::iterator itr;
  3572. map<Faction*, signed int> factions;
  3573. for (itr = faction_rewards.begin(); itr != faction_rewards.end(); itr++) {
  3574. Faction* faction = master_faction_list.GetFaction(itr->first);
  3575. if (faction)
  3576. factions[faction] = itr->second;
  3577. }
  3578. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions.size());
  3579. map<Faction*, signed int>::iterator faction_itr;
  3580. int8 i = 0;
  3581. for (faction_itr = factions.begin(); faction_itr != factions.end(); faction_itr++) {
  3582. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  3583. sint32 amount = faction_itr->second;
  3584. packet2->setArrayDataByName("amount", amount, i);
  3585. if (amount > 0)
  3586. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  3587. else
  3588. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  3589. i++;
  3590. }
  3591. }
  3592. client->QueuePacket(packet2->serialize());
  3593. safe_delete(packet2);
  3594. }*/
  3595. return 0;
  3596. }
  3597. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3598. if (!lua_interface)
  3599. return 0;
  3600. Quest* quest = lua_interface->GetQuest(state);
  3601. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3602. if (quest && spawn) {
  3603. if (spawn->IsPlayer()) {
  3604. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3605. if (client)
  3606. client->AddPendingQuestReward(quest);
  3607. }
  3608. }
  3609. return 0;
  3610. }
  3611. int EQ2Emu_lua_Harvest(lua_State* state) {
  3612. if (!lua_interface)
  3613. return 0;
  3614. Spawn* player = lua_interface->GetSpawn(state);
  3615. Spawn* node = lua_interface->GetSpawn(state, 2);
  3616. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3617. Client* client = player->GetZone()->GetClientBySpawn(player);
  3618. if (client) {
  3619. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3620. ((GroundSpawn*)node)->ProcessHarvest(client);
  3621. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3622. player->GetZone()->RemoveSpawn(true, node, true);
  3623. }
  3624. }
  3625. else if (player && player->IsPlayer()) {
  3626. Client* client = player->GetZone()->GetClientBySpawn(player);
  3627. if (client)
  3628. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3629. }
  3630. return 0;
  3631. }
  3632. int EQ2Emu_lua_Bind(lua_State* state) {
  3633. if (!lua_interface)
  3634. return 0;
  3635. Spawn* spawn = lua_interface->GetSpawn(state);
  3636. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3637. float x = lua_interface->GetFloatValue(state, 3);
  3638. float y = lua_interface->GetFloatValue(state, 4);
  3639. float z = lua_interface->GetFloatValue(state, 5);
  3640. float h = lua_interface->GetFloatValue(state, 6);
  3641. if (!spawn) {
  3642. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3643. return 0;
  3644. }
  3645. if (!spawn->IsPlayer()) {
  3646. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3647. return 0;
  3648. }
  3649. if (zone_id == 0) {
  3650. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3651. if (!client) {
  3652. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3653. return 0;
  3654. }
  3655. if (!client->Bind())
  3656. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3657. }
  3658. else {
  3659. Player* player = (Player*)spawn;
  3660. player->GetPlayerInfo()->SetBindZone(zone_id);
  3661. player->GetPlayerInfo()->SetBindX(x);
  3662. player->GetPlayerInfo()->SetBindY(y);
  3663. player->GetPlayerInfo()->SetBindZ(z);
  3664. player->GetPlayerInfo()->SetBindHeading(h);
  3665. }
  3666. return 0;
  3667. }
  3668. int EQ2Emu_lua_Gate(lua_State* state) {
  3669. if (!lua_interface)
  3670. return 0;
  3671. Spawn* spawn = lua_interface->GetSpawn(state);
  3672. if (spawn) {
  3673. if (spawn->IsPlayer()) {
  3674. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3675. if (client) {
  3676. if (!client->Gate())
  3677. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3678. }
  3679. }
  3680. }
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. bool ret = false;
  3687. Spawn* spawn = lua_interface->GetSpawn(state);
  3688. if (spawn) {
  3689. if (spawn->IsPlayer()) {
  3690. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3691. if (client)
  3692. ret = client->BindAllowed();
  3693. }
  3694. }
  3695. lua_interface->SetBooleanValue(state, ret);
  3696. return 1;
  3697. }
  3698. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3699. if (!lua_interface)
  3700. return 0;
  3701. bool ret = false;
  3702. Spawn* spawn = lua_interface->GetSpawn(state);
  3703. if (spawn) {
  3704. if (spawn->IsPlayer()) {
  3705. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3706. if (client)
  3707. ret = client->GateAllowed();
  3708. }
  3709. }
  3710. lua_interface->SetBooleanValue(state, ret);
  3711. return 1;
  3712. }
  3713. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3714. Spawn* spawn = lua_interface->GetSpawn(state);
  3715. if (spawn) {
  3716. lua_interface->SetBooleanValue(state, spawn->Alive());
  3717. return 1;
  3718. }
  3719. return 0;
  3720. }
  3721. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3722. if (!lua_interface)
  3723. return 0;
  3724. Spawn* spawn = lua_interface->GetSpawn(state);
  3725. if (spawn && spawn->IsEntity()) {
  3726. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3727. return 1;
  3728. }
  3729. return 0;
  3730. }
  3731. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3732. Spawn* spawn = lua_interface->GetSpawn(state);
  3733. string message = lua_interface->GetStringValue(state, 2);
  3734. string color_str = lua_interface->GetStringValue(state, 3);
  3735. int8 color = CHANNEL_NARRATIVE;
  3736. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3737. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3738. if (client) {
  3739. if (color_str.length() > 0) {
  3740. // leave for backwards compat, but all future should just use the number
  3741. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3742. color = CHANNEL_COLOR_RED;
  3743. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3744. color = CHANNEL_COLOR_YELLOW;
  3745. else
  3746. {
  3747. // use a number to specify the channel as per Commands/Commands.h defines
  3748. color = (int8)atoul(color_str.c_str());
  3749. }
  3750. }
  3751. client->SimpleMessage(color, message.c_str());
  3752. }
  3753. }
  3754. return 0;
  3755. }
  3756. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3757. Spawn* spawn = lua_interface->GetSpawn(state);
  3758. string message = lua_interface->GetStringValue(state, 2);
  3759. int8 red = lua_interface->GetInt8Value(state, 3);
  3760. int8 green = lua_interface->GetInt8Value(state, 4);
  3761. int8 blue = lua_interface->GetInt8Value(state, 5);
  3762. if (!spawn) {
  3763. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3764. return 0;
  3765. }
  3766. int32 words = ::CountWordsInString(message.c_str());
  3767. if (words < 5)
  3768. words = 5;
  3769. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3770. if (client)
  3771. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3772. return 0;
  3773. }
  3774. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3775. Spawn* spawn = lua_interface->GetSpawn(state);
  3776. int8 param = lua_interface->GetInt8Value(state, 2);
  3777. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3778. int8 value = lua_interface->GetInt8Value(state, 4);
  3779. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3780. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3781. if (client) {
  3782. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3783. switch (param) {
  3784. case 1: {
  3785. packet->setDataByName("parameter1", param_value);
  3786. break;
  3787. }
  3788. case 2: {
  3789. packet->setDataByName("parameter2", param_value);
  3790. break;
  3791. }
  3792. case 3: {
  3793. packet->setDataByName("parameter3", param_value);
  3794. break;
  3795. }
  3796. case 4: {
  3797. packet->setDataByName("parameter4", param_value);
  3798. break;
  3799. }
  3800. case 5: {
  3801. packet->setDataByName("parameter5", param_value);
  3802. break;
  3803. }
  3804. }
  3805. packet->setDataByName("value", value);
  3806. client->QueuePacket(packet->serialize());
  3807. safe_delete(packet);
  3808. }
  3809. }
  3810. return 0;
  3811. }
  3812. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3813. Spawn* spawn = lua_interface->GetSpawn(state);
  3814. if (spawn && spawn->IsPlayer()) {
  3815. if (((Player*)spawn)->GetIsTracking())
  3816. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3817. else
  3818. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3819. }
  3820. return 0;
  3821. }
  3822. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3823. Spawn* player = lua_interface->GetSpawn(state);
  3824. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3825. string name = lua_interface->GetStringValue(state, 3);
  3826. float distance = lua_interface->GetFloatValue(state, 4);
  3827. string command = lua_interface->GetStringValue(state, 5);
  3828. string error_text = lua_interface->GetStringValue(state, 6);
  3829. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3830. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3831. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3832. if (spawn) {
  3833. if (distance == 0)
  3834. distance = 10.0f;
  3835. if (command.length() == 0)
  3836. command = name;
  3837. if (command.length() < 1 && name.length() < 1)
  3838. {
  3839. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3840. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3841. spawn->RemovePrimaryCommands();
  3842. }
  3843. else
  3844. {
  3845. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3846. }
  3847. }
  3848. return 0;
  3849. }
  3850. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3851. if (!lua_interface)
  3852. return 0;
  3853. Spawn* player = lua_interface->GetSpawn(state);
  3854. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3855. int16 tier = lua_interface->GetInt16Value(state, 3);
  3856. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3857. if (player && spell && player->IsPlayer()) {
  3858. Client* client = player->GetZone()->GetClientBySpawn(player);
  3859. if (client) {
  3860. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3861. {
  3862. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3863. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3864. client->GetPlayer()->UnlockSpell(spell);
  3865. client->SendSpellUpdate(spell);
  3866. }
  3867. else
  3868. {
  3869. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3870. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3871. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3872. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3873. client->GetPlayer()->UnlockSpell(spell);
  3874. client->SendSpellUpdate(spell);
  3875. }
  3876. //if (client ) {
  3877. // ((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);
  3878. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3879. if (outapp)
  3880. client->QueuePacket(outapp);
  3881. }
  3882. }
  3883. return 0;
  3884. }
  3885. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3886. if (!lua_interface)
  3887. return 0;
  3888. Spawn* player = lua_interface->GetSpawn(state);
  3889. if (player && player->IsPlayer()) {
  3890. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3891. return 1;
  3892. }
  3893. return 0;
  3894. }
  3895. int EQ2Emu_lua_Attack(lua_State* state) {
  3896. if (lua_interface) {
  3897. Spawn* npc = lua_interface->GetSpawn(state);
  3898. Spawn* player = lua_interface->GetSpawn(state, 2);
  3899. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3900. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3901. }
  3902. return 0;
  3903. }
  3904. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3905. if (lua_interface) {
  3906. Spawn* target = lua_interface->GetSpawn(state);
  3907. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3908. if (target && target->GetZone())
  3909. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3910. }
  3911. return 0;
  3912. }
  3913. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3914. Spawn* player;
  3915. if (lua_interface) {
  3916. player = lua_interface->GetSpawn(state);
  3917. if (player && player->IsPlayer()) {
  3918. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3919. return 1;
  3920. }
  3921. }
  3922. return 0;
  3923. }
  3924. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3925. Spawn* player;
  3926. Client* client;
  3927. if (lua_interface) {
  3928. player = lua_interface->GetSpawn(state);
  3929. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3930. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3931. client->HandInCollections();
  3932. }
  3933. return 0;
  3934. }
  3935. int EQ2Emu_lua_UseWidget(lua_State* state) {
  3936. Spawn* widget;
  3937. if (lua_interface) {
  3938. widget = lua_interface->GetSpawn(state);
  3939. if (widget && widget->IsWidget())
  3940. ((Widget*)widget)->HandleUse(NULL, "");
  3941. }
  3942. return 0;
  3943. }
  3944. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  3945. Spawn* spawn = 0;
  3946. int32 primary_list = 0;
  3947. int32 secondary_list = 0;
  3948. if (lua_interface) {
  3949. spawn = lua_interface->GetSpawn(state);
  3950. primary_list = lua_interface->GetInt32Value(state, 2);
  3951. secondary_list = lua_interface->GetInt32Value(state, 3);
  3952. if (!spawn->IsNPC()) {
  3953. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  3954. return 0;
  3955. }
  3956. NPC* npc = (NPC*)spawn;
  3957. npc->SetPrimarySpellList(primary_list);
  3958. npc->SetSecondarySpellList(secondary_list);
  3959. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  3960. }
  3961. return 0;
  3962. }
  3963. int EQ2Emu_lua_GetPet(lua_State* state) {
  3964. if (!lua_interface)
  3965. return 0;
  3966. Spawn* spawn = lua_interface->GetSpawn(state);
  3967. if (spawn) {
  3968. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  3969. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  3970. return 1;
  3971. }
  3972. }
  3973. return 0;
  3974. }
  3975. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  3976. if (!lua_interface)
  3977. return 0;
  3978. Spawn* spawn = lua_interface->GetSpawn(state);
  3979. if (spawn) {
  3980. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  3981. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  3982. return 1;
  3983. }
  3984. }
  3985. return 0;
  3986. }
  3987. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  3988. if (!lua_interface)
  3989. return 0;
  3990. Spawn* spawn = lua_interface->GetSpawn(state);
  3991. if (spawn) {
  3992. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  3993. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  3994. return 1;
  3995. }
  3996. }
  3997. return 0;
  3998. }
  3999. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4000. if (!lua_interface)
  4001. return 0;
  4002. Spawn* spawn = lua_interface->GetSpawn(state);
  4003. if (spawn) {
  4004. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4005. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4006. return 1;
  4007. }
  4008. }
  4009. return 0;
  4010. }
  4011. int EQ2Emu_lua_Charm(lua_State* state) {
  4012. if (!lua_interface)
  4013. return 0;
  4014. Spawn* owner = lua_interface->GetSpawn(state);
  4015. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4016. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4017. if (!luaspell) {
  4018. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4019. return 0;
  4020. }
  4021. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4022. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4023. pet->SetPet(true);
  4024. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4025. ((NPC*)pet)->SetOwner((Entity*)owner);
  4026. // If owner is player and player does not have a summoned pet set the players charsheet
  4027. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4028. Player* player = (Player*)owner;
  4029. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4030. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  4031. player->GetInfoStruct()->pet_movement = 2;
  4032. player->GetInfoStruct()->pet_behavior = 3;
  4033. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4034. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4035. // Make sure the values get sent to the client
  4036. player->SetCharSheetChanged(true);
  4037. }
  4038. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4039. pet->SetSpawnScript("");
  4040. // Set faction to the same as the owner
  4041. pet->SetFactionID(owner->GetFactionID());
  4042. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4043. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4044. // Clear hate list
  4045. ((NPC*)pet)->Brain()->ClearHate();
  4046. // Set the brain to a pet brain
  4047. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4048. }
  4049. return 0;
  4050. }
  4051. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4052. if (!lua_interface)
  4053. return 0;
  4054. Spawn* spawn = lua_interface->GetSpawn(state);
  4055. if (!spawn) {
  4056. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4057. return 0;
  4058. }
  4059. vector<Spawn*> groupMembers;
  4060. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4061. groupMembers = *spawn->GetSpawnGroup();
  4062. }
  4063. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4064. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4065. deque<GroupMemberInfo*>::iterator itr;
  4066. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4067. if (group)
  4068. {
  4069. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4070. deque<GroupMemberInfo*>* members = group->GetMembers();
  4071. GroupMemberInfo* info = 0;
  4072. for (itr = members->begin(); itr != members->end(); itr++) {
  4073. info = *itr;
  4074. if (info->client)
  4075. groupMembers.push_back(info->client->GetPlayer());
  4076. }
  4077. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4078. }
  4079. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4080. }
  4081. else
  4082. return 0;
  4083. lua_createtable(state, groupMembers.size(), 0);
  4084. int newTable = lua_gettop(state);
  4085. for (int32 i = 0; i < groupMembers.size(); i++) {
  4086. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4087. lua_rawseti(state, newTable, i + 1);
  4088. }
  4089. return 1;
  4090. }
  4091. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4092. if (!lua_interface)
  4093. return 0;
  4094. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4095. lua_interface->SetOptionWindowValue(state, option_window);
  4096. return 1;
  4097. }
  4098. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4099. if (!lua_interface)
  4100. return 0;
  4101. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4102. if (option_window) {
  4103. OptionWindowOption option_window_option;
  4104. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4105. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4106. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4107. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4108. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4109. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4110. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4111. option_window->push_back(option_window_option);
  4112. }
  4113. return 0;
  4114. }
  4115. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4116. if (!lua_interface)
  4117. return 0;
  4118. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4119. Spawn* player = lua_interface->GetSpawn(state, 2);
  4120. string window_title = lua_interface->GetStringValue(state, 3);
  4121. string cancel_command = lua_interface->GetStringValue(state, 4);
  4122. Client* client = player->GetZone()->GetClientBySpawn(player);
  4123. if (option_window && window_title.length() > 0 && client) {
  4124. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4125. if (!packet)
  4126. return 0;
  4127. packet->setDataByName("title_text", window_title.c_str());
  4128. if (cancel_command.length() > 0)
  4129. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4130. packet->setArrayLengthByName("num_selections", option_window->size());
  4131. vector<OptionWindowOption>::iterator itr;
  4132. int8 i = 0;
  4133. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4134. OptionWindowOption opt = *itr;
  4135. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4136. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4137. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4138. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4139. if (opt.optionCommand.length() > 0)
  4140. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4141. if (opt.optionConfirmTitle.length() > 0)
  4142. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4143. i++;
  4144. }
  4145. client->QueuePacket(packet->serialize());
  4146. safe_delete(option_window);
  4147. safe_delete(packet);
  4148. }
  4149. return 0;
  4150. }
  4151. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4152. if (!lua_interface)
  4153. return 0;
  4154. Spawn* spawn = lua_interface->GetSpawn(state);
  4155. if (spawn) {
  4156. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4157. return 1;
  4158. }
  4159. else
  4160. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4161. return 0;
  4162. }
  4163. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4164. if (!lua_interface)
  4165. return 0;
  4166. Spawn* spawn = lua_interface->GetSpawn(state);
  4167. if (spawn) {
  4168. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4169. return 1;
  4170. }
  4171. else
  4172. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4173. return 0;
  4174. }
  4175. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4176. if (!lua_interface)
  4177. return 0;
  4178. Spawn* spawn = lua_interface->GetSpawn(state);
  4179. if (spawn) {
  4180. int8 class_id = spawn->GetTradeskillClass();
  4181. // Need to add 42 for the offset in the array
  4182. class_id += 44;
  4183. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4184. return 1;
  4185. }
  4186. else
  4187. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4188. return 0;
  4189. }
  4190. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4191. if (!lua_interface)
  4192. return 0;
  4193. Spawn* spawn = lua_interface->GetSpawn(state);
  4194. int16 level = lua_interface->GetInt8Value(state, 2);
  4195. if (spawn) {
  4196. if (spawn->IsPlayer())
  4197. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4198. else
  4199. spawn->SetTSLevel(level);
  4200. }
  4201. else
  4202. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4203. return 0;
  4204. }
  4205. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4206. if (!lua_interface)
  4207. return 0;
  4208. Spawn* spawn = lua_interface->GetSpawn(state);
  4209. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4210. if (spawn) {
  4211. spawn->SetAttackable(attackable);
  4212. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4213. }
  4214. return 0;
  4215. }
  4216. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4217. // Check to see if we have a valid lua_interface
  4218. if (!lua_interface)
  4219. return 0;
  4220. // Get the spawn that is getting the pet
  4221. Spawn* spawn = lua_interface->GetSpawn(state);
  4222. // Get the DB ID of the pet
  4223. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4224. // The max level the pet can gain
  4225. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4226. // Get the spell that this command was called from
  4227. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4228. // Check to make sure the spawn pointer is valid
  4229. if (!spawn) {
  4230. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4231. return 0;
  4232. }
  4233. // Check to make sure the spawn is an entity
  4234. if (!spawn->IsEntity()) {
  4235. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4236. return 0;
  4237. }
  4238. // Check to make sure the spawn doesn't already have a pet of this type
  4239. if (((Entity*)spawn)->GetPet()) {
  4240. if (spawn->IsPlayer()) {
  4241. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4242. if (client)
  4243. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4244. }
  4245. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4246. return 0;
  4247. }
  4248. // Check to see if the DB ID for the pet is set
  4249. if (pet_id == 0) {
  4250. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4251. return 0;
  4252. }
  4253. // Check to see if the pointer to the spell is valid
  4254. if (!luaspell) {
  4255. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4256. return 0;
  4257. }
  4258. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4259. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4260. if (!pet) {
  4261. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4262. return 0;
  4263. }
  4264. // Check to make sure the pet is an npc
  4265. if (!pet->IsNPC()) {
  4266. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4267. return 0;
  4268. }
  4269. // Spawn the pet at the same location as the owner
  4270. pet->SetX(spawn->GetX());
  4271. pet->SetY(spawn->GetY());
  4272. pet->SetZ(spawn->GetZ());
  4273. pet->SetLocation(spawn->GetLocation());
  4274. pet->SetHeading(spawn->GetHeading());
  4275. spawn->GetZone()->AddSpawn(pet);
  4276. /*
  4277. const char* spawn_script = world.GetSpawnScript(pet_id);
  4278. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4279. spawn->SetSpawnScript(string(spawn_script));
  4280. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4281. }*/
  4282. // Get a random pet name
  4283. string random_pet_name;
  4284. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4285. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4286. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4287. // If player set various values for the char sheet (pet window)
  4288. if (spawn->IsPlayer()) {
  4289. Player* player = (Player*)spawn;
  4290. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4291. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  4292. player->GetInfoStruct()->pet_movement = 2;
  4293. player->GetInfoStruct()->pet_behavior = 3;
  4294. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4295. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4296. // Make sure the values get sent to the client
  4297. player->SetCharSheetChanged(true);
  4298. }
  4299. // Set the pets name
  4300. pet->SetName(random_pet_name.c_str());
  4301. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4302. if (max_level > 0)
  4303. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4304. else
  4305. pet->SetLevel(spawn->GetLevel());
  4306. // Set the max level this pet can reach
  4307. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4308. // Set the faction of the pet to the same faction as the owner
  4309. pet->SetFactionID(spawn->GetFactionID());
  4310. // Set the spawn as a pet
  4311. pet->SetPet(true);
  4312. // Give a pointer of the owner to the pet
  4313. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4314. // Give a pointer of the pet to the owner
  4315. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4316. // Set the pet type
  4317. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4318. // Set the spell id used to create this pet
  4319. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4320. // Set the spell tier used to create this pet
  4321. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4322. // Set the pets spawn type to 6
  4323. pet->SetSpawnType(6);
  4324. // Set the pets brain
  4325. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4326. // Check to see if the pet has a subtitle
  4327. if (strlen(pet->GetSubTitle()) > 0) {
  4328. // Add the players name to the front of the sub title
  4329. string pet_subtitle;
  4330. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4331. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4332. // Set the pets subtitle to the new one
  4333. pet->SetSubTitle(pet_subtitle.c_str());
  4334. }
  4335. // Add the "Pet Options" entity command to the pet
  4336. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4337. // Set the pet as the return value for this function
  4338. lua_interface->SetSpawnValue(state, pet);
  4339. return 1;
  4340. }
  4341. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4342. if (!lua_interface)
  4343. return 0;
  4344. Spawn* spawn = lua_interface->GetSpawn(state);
  4345. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4346. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4347. if (!spawn) {
  4348. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4349. return 0;
  4350. }
  4351. if (!spawn->IsEntity()) {
  4352. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4353. return 0;
  4354. }
  4355. if (((Entity*)spawn)->GetDeityPet()) {
  4356. if (spawn->IsPlayer()) {
  4357. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4358. if (client)
  4359. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4360. }
  4361. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4362. return 0;
  4363. }
  4364. if (pet_id == 0) {
  4365. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4366. return 0;
  4367. }
  4368. if (!luaspell) {
  4369. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4370. return 0;
  4371. }
  4372. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4373. if (!pet) {
  4374. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4375. return 0;
  4376. }
  4377. if (!pet->IsNPC()) {
  4378. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4379. return 0;
  4380. }
  4381. pet->SetX(spawn->GetX());
  4382. pet->SetY(spawn->GetY());
  4383. pet->SetZ(spawn->GetZ());
  4384. pet->SetLocation(spawn->GetLocation());
  4385. pet->SetHeading(spawn->GetHeading());
  4386. spawn->GetZone()->AddSpawn(pet);
  4387. string random_pet_name;
  4388. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4389. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4390. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4391. pet->SetName(random_pet_name.c_str());
  4392. pet->SetLevel(spawn->GetLevel());
  4393. pet->SetFactionID(spawn->GetFactionID());
  4394. pet->SetPet(true);
  4395. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4396. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4397. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4398. pet->SetSpawnType(6);
  4399. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4400. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4401. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4402. if (strlen(pet->GetSubTitle()) > 0) {
  4403. string pet_subtitle;
  4404. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4405. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4406. pet->SetSubTitle(pet_subtitle.c_str());
  4407. }
  4408. // deity and cosmetic pets are not attackable
  4409. pet->SetAttackable(false);
  4410. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4411. lua_interface->SetSpawnValue(state, pet);
  4412. return 1;
  4413. }
  4414. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4415. if (!lua_interface)
  4416. return 0;
  4417. Spawn* spawn = lua_interface->GetSpawn(state);
  4418. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4419. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4420. if (!spawn) {
  4421. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4422. return 0;
  4423. }
  4424. if (!spawn->IsEntity()) {
  4425. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4426. return 0;
  4427. }
  4428. if (((Entity*)spawn)->GetCosmeticPet()) {
  4429. if (spawn->IsPlayer()) {
  4430. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4431. if (client)
  4432. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4433. }
  4434. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4435. return 0;
  4436. }
  4437. if (pet_id == 0) {
  4438. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4439. return 0;
  4440. }
  4441. if (!luaspell) {
  4442. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4443. return 0;
  4444. }
  4445. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4446. if (!pet) {
  4447. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4448. return 0;
  4449. }
  4450. if (!pet->IsNPC()) {
  4451. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4452. return 0;
  4453. }
  4454. pet->SetX(spawn->GetX());
  4455. pet->SetY(spawn->GetY());
  4456. pet->SetZ(spawn->GetZ());
  4457. pet->SetLocation(spawn->GetLocation());
  4458. pet->SetHeading(spawn->GetHeading());
  4459. spawn->GetZone()->AddSpawn(pet);
  4460. string random_pet_name;
  4461. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4462. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4463. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4464. pet->SetName(random_pet_name.c_str());
  4465. pet->SetLevel(spawn->GetLevel());
  4466. pet->SetFactionID(spawn->GetFactionID());
  4467. pet->SetPet(true);
  4468. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4469. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4470. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4471. pet->SetSpawnType(6);
  4472. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4473. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4474. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4475. if (strlen(pet->GetSubTitle()) > 0) {
  4476. string pet_subtitle;
  4477. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4478. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4479. pet->SetSubTitle(pet_subtitle.c_str());
  4480. }
  4481. pet->SetAttackable(false);
  4482. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4483. lua_interface->SetSpawnValue(state, pet);
  4484. return 1;
  4485. }
  4486. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4487. if (!lua_interface)
  4488. return 0;
  4489. Spawn* spawn = lua_interface->GetSpawn(state);
  4490. if (!spawn) {
  4491. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4492. return 0;
  4493. }
  4494. if (!spawn->IsPet()) {
  4495. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4496. return 0;
  4497. }
  4498. if (!((NPC*)spawn)->IsDismissing())
  4499. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
  4500. return 0;
  4501. }
  4502. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4503. if (!lua_interface)
  4504. return 0;
  4505. Quest* quest = lua_interface->GetQuest(state);
  4506. if (!quest) {
  4507. 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));
  4508. return 0;
  4509. }
  4510. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4511. if (feather_color > 0)
  4512. quest->SetFeatherColor(feather_color);
  4513. return 0;
  4514. }
  4515. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4516. if (!lua_interface)
  4517. return 0;
  4518. Spawn* spawn = lua_interface->GetSpawn(state);
  4519. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4520. if (!spawn) {
  4521. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4522. return 0;
  4523. }
  4524. if (!spawn2) {
  4525. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4526. return 0;
  4527. }
  4528. spawn->RemoveSpawnAccess(spawn2);
  4529. return 0;
  4530. }
  4531. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4532. if (!lua_interface)
  4533. return 0;
  4534. ZoneServer* zone = lua_interface->GetZone(state);
  4535. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4536. if (!zone) {
  4537. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4538. return 0;
  4539. }
  4540. if (location_id == 0) {
  4541. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4542. return 0;
  4543. }
  4544. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4545. if (!location) {
  4546. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4547. return 0;
  4548. }
  4549. Spawn* spawn = 0;
  4550. if (location->entities[0]) {
  4551. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4552. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4553. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4554. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4555. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4556. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4557. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4558. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4559. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4560. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4561. if (spawn) {
  4562. const char* script = 0;
  4563. for (int x = 0; x < 3; x++) {
  4564. switch (x) {
  4565. case 0:
  4566. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4567. break;
  4568. case 1:
  4569. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4570. break;
  4571. case 2:
  4572. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4573. break;
  4574. }
  4575. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4576. spawn->SetSpawnScript(string(script));
  4577. break;
  4578. }
  4579. }
  4580. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4581. lua_interface->SetSpawnValue(state, spawn);
  4582. return 1;
  4583. }
  4584. else {
  4585. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4586. safe_delete(spawn);
  4587. }
  4588. }
  4589. return 0;
  4590. }
  4591. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4592. if (!lua_interface)
  4593. return 0;
  4594. Spawn* caster = lua_interface->GetSpawn(state);
  4595. Spawn* target = lua_interface->GetSpawn(state, 2);
  4596. int32 id = lua_interface->GetInt32Value(state, 3);
  4597. string command = lua_interface->GetStringValue(state, 4);
  4598. if (!caster) {
  4599. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4600. return 0;
  4601. }
  4602. if (!target) {
  4603. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4604. return 0;
  4605. }
  4606. if (!caster->IsPlayer()) {
  4607. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4608. return 0;
  4609. }
  4610. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4611. if (!entity_command) {
  4612. 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());
  4613. return 0;
  4614. }
  4615. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4616. if (!client) {
  4617. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4618. return 0;
  4619. }
  4620. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4621. return 0;
  4622. }
  4623. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4624. if (!lua_interface)
  4625. return 0;
  4626. Spawn* spawn = lua_interface->GetSpawn(state);
  4627. if (!spawn) {
  4628. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4629. return 0;
  4630. }
  4631. if (!spawn->IsNPC()) {
  4632. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4633. return 0;
  4634. }
  4635. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4636. return 0;
  4637. }
  4638. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4639. if (!lua_interface)
  4640. return 0;
  4641. Spawn* spawn = lua_interface->GetSpawn(state);
  4642. int16 tick = lua_interface->GetInt16Value(state, 2);
  4643. if (!spawn) {
  4644. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4645. return 0;
  4646. }
  4647. if (!spawn->IsNPC()) {
  4648. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4649. return 0;
  4650. }
  4651. if (tick < 20) {
  4652. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4653. return 0;
  4654. }
  4655. ((NPC*)spawn)->Brain()->SetTick(tick);
  4656. return 0;
  4657. }
  4658. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4659. if (!lua_interface)
  4660. return 0;
  4661. Spawn* spawn = lua_interface->GetSpawn(state);
  4662. Spawn* target = lua_interface->GetSpawn(state, 2);
  4663. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4664. if (!spawn) {
  4665. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4666. return 0;
  4667. }
  4668. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4669. spawn->SetFollowTarget(target, follow_distance);
  4670. return 0;
  4671. }
  4672. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4673. if (!lua_interface)
  4674. return 0;
  4675. Spawn* spawn = lua_interface->GetSpawn(state);
  4676. if (!spawn) {
  4677. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4678. return 0;
  4679. }
  4680. Spawn* target = spawn->GetFollowTarget();
  4681. if (target) {
  4682. lua_interface->SetSpawnValue(state, target);
  4683. return 1;
  4684. }
  4685. return 0;
  4686. }
  4687. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4688. if (!lua_interface)
  4689. return 0;
  4690. Spawn* spawn = lua_interface->GetSpawn(state);
  4691. if (!spawn) {
  4692. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4693. return 0;
  4694. }
  4695. if (spawn->following)
  4696. spawn->following = false;
  4697. else
  4698. spawn->following = true;
  4699. return 0;
  4700. }
  4701. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4702. if (!lua_interface)
  4703. return 0;
  4704. Spawn* spawn = lua_interface->GetSpawn(state);
  4705. if (!spawn) {
  4706. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4707. return 0;
  4708. }
  4709. lua_interface->SetBooleanValue(state, spawn->following);
  4710. return 1;
  4711. }
  4712. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4713. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4714. // I will attempt to explain how this function works for future refrence
  4715. // Fist lets make sure lua_interface is valid, if not return out
  4716. if (!lua_interface)
  4717. return 0;
  4718. // Next we grab the first 2 params same as we usually would
  4719. Spawn* spawn = lua_interface->GetSpawn(state);
  4720. string var = lua_interface->GetStringValue(state, 2);
  4721. // 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
  4722. // 1 = Spawn
  4723. // 2 = Zone
  4724. // 3 = Item
  4725. // 4 = Quest
  4726. // 5 = String
  4727. // 6 = nil (null)
  4728. int8 dataType = 0;
  4729. // Define pointers for each potential type
  4730. Spawn* spawnVal = 0;
  4731. ZoneServer* zone = 0;
  4732. Item* item = 0;
  4733. Quest* quest = 0;
  4734. string val;
  4735. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4736. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4737. // options window are also light user data be we do not handle those.
  4738. // We check with lua_islightuserdata(lua_State*, index)
  4739. if (lua_islightuserdata(state, 3)) {
  4740. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4741. // and convert it to LUAUserData*
  4742. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4743. // Check to make sure the data we got is valid, if not give an error
  4744. if (!data || !data->IsCorrectlyInitialized()) {
  4745. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4746. }
  4747. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4748. else if (data->IsSpawn()) {
  4749. spawnVal = data->spawn;
  4750. dataType = 1;
  4751. }
  4752. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4753. else if (data->IsZone()) {
  4754. zone = data->zone;
  4755. dataType = 2;
  4756. }
  4757. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4758. else if (data->IsItem()) {
  4759. item = data->item;
  4760. dataType = 3;
  4761. }
  4762. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4763. else if (data->IsQuest()) {
  4764. quest = data->quest;
  4765. dataType = 4;
  4766. }
  4767. }
  4768. // Wasn't light user data, check if it is nil(null)
  4769. else if (lua_isnil(state, 3)) {
  4770. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4771. dataType = 6;
  4772. }
  4773. // Wasn't light user data or nil (null), must be a string
  4774. else {
  4775. // Set the string and dataType variable
  4776. val = lua_interface->GetStringValue(state, 3);
  4777. dataType = 5;
  4778. }
  4779. // We now have all the params, lets check to make sure they are valid
  4780. if (!spawn) {
  4781. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4782. return 0;
  4783. }
  4784. if (var.length() == 0) {
  4785. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4786. return 0;
  4787. }
  4788. if (dataType == 0) {
  4789. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4790. return 0;
  4791. }
  4792. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4793. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4794. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4795. switch (dataType) {
  4796. case 1:
  4797. // 1 = Spawn
  4798. spawn->AddTempVariable(var, spawnVal);
  4799. break;
  4800. case 2:
  4801. // 2 = Zone
  4802. spawn->AddTempVariable(var, zone);
  4803. break;
  4804. case 3:
  4805. // 3 = Item
  4806. spawn->AddTempVariable(var, item);
  4807. break;
  4808. case 4:
  4809. // 4 = Quest
  4810. spawn->AddTempVariable(var, quest);
  4811. break;
  4812. case 5:
  4813. // 5 = String
  4814. spawn->AddTempVariable(var, val);
  4815. break;
  4816. case 6:
  4817. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4818. spawn->DeleteTempVariable(var);
  4819. break;
  4820. }
  4821. // And we are done so return out
  4822. return 0;
  4823. }
  4824. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4825. if (!lua_interface)
  4826. return 0;
  4827. Spawn* spawn = lua_interface->GetSpawn(state);
  4828. string var = lua_interface->GetStringValue(state, 2);
  4829. if (!spawn) {
  4830. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4831. return 0;
  4832. }
  4833. if (var.length() == 0) {
  4834. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4835. return 0;
  4836. }
  4837. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4838. int8 type = spawn->GetTempVariableType(var);
  4839. Spawn* spawn2 = 0;
  4840. ZoneServer* zone = 0;
  4841. Item* item = 0;
  4842. Quest* quest = 0;
  4843. // Set the lua function return value based on the type of data the variable contains
  4844. switch (type) {
  4845. case 1:
  4846. spawn2 = spawn->GetTempVariableSpawn(var);
  4847. if (!spawn2)
  4848. return 0;
  4849. lua_interface->SetSpawnValue(state, spawn2);
  4850. break;
  4851. case 2:
  4852. zone = spawn->GetTempVariableZone(var);
  4853. if (!zone)
  4854. return 0;
  4855. lua_interface->SetZoneValue(state, zone);
  4856. break;
  4857. case 3:
  4858. item = spawn->GetTempVariableItem(var);
  4859. if (!item)
  4860. return 0;
  4861. lua_interface->SetItemValue(state, item);
  4862. break;
  4863. case 4:
  4864. quest = spawn->GetTempVariableQuest(var);
  4865. if (!quest)
  4866. return 0;
  4867. lua_interface->SetQuestValue(state, quest);
  4868. break;
  4869. case 5:
  4870. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4871. break;
  4872. default:
  4873. // Not a valid type then the variable was not set so return out
  4874. return 0;
  4875. }
  4876. // Return value was set so return out
  4877. return 1;
  4878. }
  4879. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4880. {
  4881. if (!lua_interface)
  4882. return 0;
  4883. Quest* quest = lua_interface->GetQuest(state);
  4884. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4885. string description = lua_interface->GetStringValue(state, 3);
  4886. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4887. if (!quest) {
  4888. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4889. lua_interface->SetBooleanValue(state, false);
  4890. return 1;
  4891. }
  4892. if (!spawn) {
  4893. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4894. lua_interface->SetBooleanValue(state, false);
  4895. return 1;
  4896. }
  4897. if (!spawn->IsPlayer()) {
  4898. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4899. lua_interface->SetBooleanValue(state, false);
  4900. return 1;
  4901. }
  4902. if (item_id == 0) {
  4903. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4904. lua_interface->SetBooleanValue(state, false);
  4905. return 1;
  4906. }
  4907. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4908. if (!client) {
  4909. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4910. lua_interface->SetBooleanValue(state, false);
  4911. return 1;
  4912. }
  4913. Item* item = master_item_list.GetItem(item_id);
  4914. if (!item) {
  4915. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4916. lua_interface->SetBooleanValue(state, false);
  4917. return 1;
  4918. }
  4919. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4920. if (packet) {
  4921. packet->setDataByName("title", "Quest Reward!");
  4922. packet->setDataByName("name", quest->GetName());
  4923. packet->setDataByName("description", description.c_str());
  4924. packet->setDataByName("level", quest->GetLevel());
  4925. packet->setArrayLengthByName("num_rewards", 1);
  4926. packet->setArrayDataByName("reward_id", item->details.item_id);
  4927. if (client->GetVersion() < 860)
  4928. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4929. else if (client->GetVersion() < 1193)
  4930. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4931. else
  4932. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4933. client->QueuePacket(packet->serialize());
  4934. safe_delete(packet);
  4935. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  4936. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  4937. return 1;
  4938. }
  4939. lua_interface->SetBooleanValue(state, false);
  4940. return 1;
  4941. }
  4942. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  4943. if (!lua_interface)
  4944. return 0;
  4945. Quest* quest = lua_interface->GetQuest(state);
  4946. if (!quest) {
  4947. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  4948. return 0;
  4949. }
  4950. quest->SetRepeatable(true);
  4951. return 0;
  4952. }
  4953. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  4954. if (!lua_interface)
  4955. return 0;
  4956. Spawn* spawn = lua_interface->GetSpawn(state);
  4957. if (!spawn) {
  4958. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  4959. return 0;
  4960. }
  4961. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  4962. string ret = classes.GetClassNameCase(base_class);
  4963. if (ret.length() > 0) {
  4964. lua_interface->SetStringValue(state, ret.c_str());
  4965. return 1;
  4966. }
  4967. return 0;
  4968. }
  4969. int EQ2Emu_lua_AddWard(lua_State* state) {
  4970. if (!lua_interface)
  4971. return 0;
  4972. int32 damage = lua_interface->GetInt32Value(state);
  4973. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  4974. int8 wardType = lua_interface->GetInt8Value(state, 3);
  4975. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  4976. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  4977. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  4978. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  4979. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  4980. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4981. bool ward_was_added = false;
  4982. ZoneServer* zone = spell->caster->GetZone();
  4983. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4984. for (int32 i = 0; i < spell->targets.size(); i++) {
  4985. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  4986. if (!target)
  4987. continue;
  4988. if (target->IsEntity()) {
  4989. // If the ward is already active remove it
  4990. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  4991. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4992. // Create new ward info
  4993. WardInfo* ward = new WardInfo;
  4994. ward->Spell = spell;
  4995. ward->BaseDamage = damage;
  4996. ward->DamageLeft = damage;
  4997. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  4998. ward->keepWard = keepWard;
  4999. ward->WardType = wardType;
  5000. if (damageAbsorptionPercent > 100)
  5001. damageAbsorptionPercent = 100;
  5002. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5003. if (damageAbsorptionMaxHealthPercent > 100)
  5004. damageAbsorptionMaxHealthPercent = 100;
  5005. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5006. ward->RedirectDamagePercent = redirectDamagePercent;
  5007. ward->LastRedirectDamage = 0;
  5008. ward->LastAbsorbedDamage = 0;
  5009. ward->HitCount = 0;
  5010. spell->num_triggers = maxHitCount;
  5011. spell->had_triggers = true;
  5012. spell->cancel_after_all_triggers = false;
  5013. ward->MaxHitCount = maxHitCount;
  5014. if (wardType == WARD_TYPE_MAGICAL)
  5015. ward->DamageType = damageTypes;
  5016. // Add the ward to the entity
  5017. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5018. ward_was_added = true;
  5019. }
  5020. }
  5021. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5022. if (ward_was_added && spell->caster->IsPlayer()) {
  5023. spell->had_dmg_remaining = true;
  5024. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5025. }
  5026. return 0;
  5027. }
  5028. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5029. if (!lua_interface)
  5030. return 0;
  5031. int32 amount = lua_interface->GetInt32Value(state);
  5032. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5033. WardInfo* ward = 0;
  5034. ZoneServer* zone = spell->caster->GetZone();
  5035. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5036. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5037. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5038. ward = target->GetWard(spell->spell->GetSpellID());
  5039. if (ward) {
  5040. ward->DamageLeft += amount;
  5041. if (ward->DamageLeft > ward->BaseDamage)
  5042. ward->DamageLeft = ward->BaseDamage;
  5043. for (int32 i = 0; i < spell->targets.size(); i++) {
  5044. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5045. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5046. }
  5047. }
  5048. }
  5049. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5050. if (ward && spell->caster->IsPlayer())
  5051. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5052. return 0;
  5053. }
  5054. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5055. if (!lua_interface)
  5056. return 0;
  5057. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5058. if (!spell) {
  5059. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5060. return 0;
  5061. }
  5062. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5063. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5064. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5065. if (ward) {
  5066. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5067. return 1;
  5068. }
  5069. }
  5070. return 0;
  5071. }
  5072. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5073. if (!lua_interface)
  5074. return 0;
  5075. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5076. if (!spell) {
  5077. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5078. return 0;
  5079. }
  5080. string type = lua_interface->GetStringValue(state, 2);
  5081. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5082. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5083. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5084. if (ward) {
  5085. if (boost::iequals(type, "damageleft"))
  5086. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5087. else if (boost::iequals(type, "basedamage"))
  5088. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5089. else if (boost::iequals(type, "keepward"))
  5090. lua_interface->SetBooleanValue(state, ward->keepWard);
  5091. else if (boost::iequals(type, "wardtype"))
  5092. lua_interface->SetInt32Value(state, ward->WardType);
  5093. else if (boost::iequals(type, "dmgabsorptionpct"))
  5094. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5095. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5096. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5097. else if (boost::iequals(type, "redirectdamagepercent"))
  5098. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5099. else if (boost::iequals(type, "lastredirectdamage"))
  5100. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5101. else if (boost::iequals(type, "lastabsorbeddamage"))
  5102. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5103. else if (boost::iequals(type, "hitcount"))
  5104. lua_interface->SetInt32Value(state, ward->HitCount);
  5105. else if (boost::iequals(type, "maxhitcount"))
  5106. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5107. else
  5108. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5109. return 1;
  5110. }
  5111. }
  5112. return 0;
  5113. }
  5114. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5115. if (!lua_interface)
  5116. return 0;
  5117. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5118. ZoneServer* zone = spell->caster->GetZone();
  5119. Spawn* target = 0;
  5120. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5121. for (int32 i = 0; i < spell->targets.size(); i++) {
  5122. target = zone->GetSpawnByID(spell->targets.at(i));
  5123. if (target && target->IsEntity()) {
  5124. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5125. }
  5126. }
  5127. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5128. return 0;
  5129. }
  5130. int EQ2Emu_lua_Interrupt(lua_State* state)
  5131. {
  5132. if (!lua_interface)
  5133. return 0;
  5134. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5135. Spawn* target = lua_interface->GetSpawn(state, 2);
  5136. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5137. if (!caster)
  5138. {
  5139. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5140. return 0;
  5141. }
  5142. if (!target)
  5143. {
  5144. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5145. return 0;
  5146. }
  5147. if (!spell) {
  5148. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5149. return 0;
  5150. }
  5151. if (!target->IsEntity() && !spell)
  5152. {
  5153. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5154. return 0;
  5155. }
  5156. if (!target && spell) {
  5157. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5158. for (int8 i = 0; i < spell->targets.size(); i++) {
  5159. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5160. if (!target || !target->IsEntity())
  5161. continue;
  5162. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5163. }
  5164. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5165. }
  5166. else
  5167. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5168. return 0;
  5169. }
  5170. int EQ2Emu_lua_Stealth(lua_State* state) {
  5171. if (!lua_interface)
  5172. return 0;
  5173. int8 type = lua_interface->GetInt8Value(state);
  5174. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5175. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5176. if (!spell) {
  5177. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5178. return 0;
  5179. }
  5180. ZoneServer* zone = spell->caster->GetZone();
  5181. if (spawn) {
  5182. if (spawn->IsEntity()) {
  5183. if (type == 1) {
  5184. ((Entity*)spawn)->AddStealthSpell(spell);
  5185. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5186. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5187. }
  5188. else if (type == 2) {
  5189. ((Entity*)spawn)->AddInvisSpell(spell);
  5190. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5191. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5192. }
  5193. return 0;
  5194. }
  5195. else {
  5196. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5197. return 0;
  5198. }
  5199. }
  5200. else {
  5201. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5202. for (int32 i = 0; i < spell->targets.size(); i++) {
  5203. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5204. if (!spawn || !spawn->IsEntity())
  5205. continue;
  5206. if (type == 1) {
  5207. ((Entity*)spawn)->AddStealthSpell(spell);
  5208. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5209. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5210. }
  5211. else if (type == 2) {
  5212. ((Entity*)spawn)->AddInvisSpell(spell);
  5213. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5214. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5215. }
  5216. else {
  5217. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5218. break;
  5219. }
  5220. }
  5221. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5222. }
  5223. return 0;
  5224. }
  5225. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5226. if (!lua_interface)
  5227. return 0;
  5228. Spawn* spawn = lua_interface->GetSpawn(state);
  5229. if (!spawn) {
  5230. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5231. return 0;
  5232. }
  5233. if (spawn->IsEntity()) {
  5234. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5235. return 1;
  5236. }
  5237. else
  5238. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5239. return 0;
  5240. }
  5241. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5242. if (!lua_interface)
  5243. return 0;
  5244. Spawn* spawn = lua_interface->GetSpawn(state);
  5245. if (!spawn) {
  5246. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5247. return 0;
  5248. }
  5249. if (spawn->IsEntity()) {
  5250. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5251. return 1;
  5252. }
  5253. else
  5254. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5255. return 0;
  5256. }
  5257. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5258. if (!lua_interface)
  5259. return 0;
  5260. Spawn* player = lua_interface->GetSpawn(state);
  5261. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5262. if (!player->IsPlayer()) {
  5263. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5264. return 0;
  5265. }
  5266. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5267. return 1;
  5268. }
  5269. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5270. if (!lua_interface)
  5271. return 0;
  5272. Spawn* player = lua_interface->GetSpawn(state);
  5273. int8 slot = lua_interface->GetInt8Value(state, 2);
  5274. if (!player) {
  5275. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5276. return 0;
  5277. }
  5278. if (!player->IsPlayer()) {
  5279. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5280. return 0;
  5281. }
  5282. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5283. if (!item) {
  5284. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5285. return 0;
  5286. }
  5287. lua_interface->SetItemValue(state, item);
  5288. return 1;
  5289. }
  5290. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5291. if (!lua_interface)
  5292. return 0;
  5293. Spawn* player = lua_interface->GetSpawn(state);
  5294. int32 id = lua_interface->GetInt32Value(state, 2);
  5295. if (!player) {
  5296. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5297. return 0;
  5298. }
  5299. if (!player->IsPlayer()) {
  5300. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5301. return 0;
  5302. }
  5303. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5304. if (!item) {
  5305. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5306. return 0;
  5307. }
  5308. lua_interface->SetItemValue(state, item);
  5309. return 1;
  5310. }
  5311. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5312. if (!lua_interface)
  5313. return 0;
  5314. Spawn* player = lua_interface->GetSpawn(state);
  5315. int32 id = lua_interface->GetInt32Value(state, 2);
  5316. int8 count = lua_interface->GetInt8Value(state, 3);
  5317. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5318. if (!player) {
  5319. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5320. return 0;
  5321. }
  5322. if (!player->IsPlayer()) {
  5323. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5324. return 0;
  5325. }
  5326. if (!count)
  5327. count = 1;
  5328. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5329. if (!item) {
  5330. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5331. return 0;
  5332. }
  5333. lua_interface->SetItemValue(state, item);
  5334. return 1;
  5335. }
  5336. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5337. if (!lua_interface)
  5338. return 0;
  5339. Spawn* spawn = lua_interface->GetSpawn(state);
  5340. int32 anim = lua_interface->GetInt32Value(state, 2);
  5341. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5342. int8 type = lua_interface->GetInt8Value(state, 4);
  5343. if (!spawn) {
  5344. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5345. return 0;
  5346. }
  5347. if (spawn2) {
  5348. if (spawn2->IsPlayer()) {
  5349. if (type != 1 && type != 2)
  5350. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5351. else
  5352. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5353. return 0;
  5354. }
  5355. else {
  5356. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5357. return 0;
  5358. }
  5359. }
  5360. else
  5361. spawn->GetZone()->PlayAnimation(spawn, anim);
  5362. return 0;
  5363. }
  5364. int EQ2Emu_lua_IsPet(lua_State* state) {
  5365. if (!lua_interface)
  5366. return 0;
  5367. Spawn* spawn = lua_interface->GetSpawn(state);
  5368. if (!spawn) {
  5369. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5370. return 0;
  5371. }
  5372. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5373. return 1;
  5374. }
  5375. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5376. if (!lua_interface)
  5377. return 0;
  5378. Spawn* spawn = lua_interface->GetSpawn(state);
  5379. if (!spawn) {
  5380. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5381. return 0;
  5382. }
  5383. if (!spawn->IsNPC()) {
  5384. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5385. return 0;
  5386. }
  5387. if (((NPC*)spawn)->GetOwner()) {
  5388. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5389. return 1;
  5390. }
  5391. return 0;
  5392. }
  5393. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5394. if (!lua_interface)
  5395. return 0;
  5396. Spawn* spawn = lua_interface->GetSpawn(state);
  5397. Spawn* target = lua_interface->GetSpawn(state, 2);
  5398. if (!spawn) {
  5399. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5400. return 0;
  5401. }
  5402. if (!spawn) {
  5403. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5404. return 0;
  5405. }
  5406. spawn->SetTarget(target);
  5407. return 0;
  5408. }
  5409. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5410. if (!lua_interface)
  5411. return 0;
  5412. Spawn* spawn = lua_interface->GetSpawn(state);
  5413. bool val = lua_interface->GetBooleanValue(state, 2);
  5414. if (!spawn) {
  5415. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5416. return 0;
  5417. }
  5418. if (!spawn->IsEntity()) {
  5419. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5420. return 0;
  5421. }
  5422. ((Entity*)spawn)->InCombat(val);
  5423. if (val) {
  5424. spawn->ClearRunningLocations();
  5425. spawn->CalculateRunningLocation(true);
  5426. }
  5427. return 0;
  5428. }
  5429. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5430. if (!lua_interface)
  5431. return 0;
  5432. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5433. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5434. if (!spawn1) {
  5435. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5436. return 0;
  5437. }
  5438. if (!spawn2) {
  5439. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5440. return 0;
  5441. }
  5442. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5443. return 1;
  5444. }
  5445. int EQ2Emu_lua_Runback(lua_State* state) {
  5446. if (!lua_interface)
  5447. return 0;
  5448. Spawn* spawn = lua_interface->GetSpawn(state);
  5449. if (!spawn) {
  5450. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5451. return 0;
  5452. }
  5453. if (!spawn->IsNPC()) {
  5454. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5455. return 0;
  5456. }
  5457. ((NPC*)spawn)->Runback();
  5458. return 0;
  5459. }
  5460. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5461. if (!lua_interface)
  5462. return 0;
  5463. Spawn* spawn = lua_interface->GetSpawn(state);
  5464. if (!spawn) {
  5465. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5466. return 0;
  5467. }
  5468. if (!spawn->IsNPC()) {
  5469. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5470. return 0;
  5471. }
  5472. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5473. return 1;
  5474. }
  5475. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5476. if (!lua_interface)
  5477. return 0;
  5478. Spawn* spawn = lua_interface->GetSpawn(state);
  5479. if (!spawn) {
  5480. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5481. return 0;
  5482. }
  5483. if (!spawn->IsEntity()) {
  5484. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5485. return 0;
  5486. }
  5487. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5488. return 1;
  5489. }
  5490. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5491. if (!lua_interface)
  5492. return 0;
  5493. Spawn* spawn = lua_interface->GetSpawn(state);
  5494. if (!spawn) {
  5495. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5496. return 0;
  5497. }
  5498. if (!spawn->IsEntity()) {
  5499. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5500. return 0;
  5501. }
  5502. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5503. return 1;
  5504. }
  5505. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5506. if (!lua_interface)
  5507. return 0;
  5508. Spawn* spawn = lua_interface->GetSpawn(state);
  5509. if (!spawn) {
  5510. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5511. return 0;
  5512. }
  5513. if (!spawn->IsEntity()) {
  5514. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5515. return 0;
  5516. }
  5517. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5518. return 1;
  5519. }
  5520. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5521. if (!lua_interface)
  5522. return 0;
  5523. Spawn* spawn = lua_interface->GetSpawn(state);
  5524. if (!spawn) {
  5525. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5526. return 0;
  5527. }
  5528. if (!spawn->IsEntity()) {
  5529. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5530. return 0;
  5531. }
  5532. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5533. return 1;
  5534. }
  5535. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5536. if (!lua_interface)
  5537. return 0;
  5538. Spawn* spawn = lua_interface->GetSpawn(state);
  5539. Spawn* target = lua_interface->GetSpawn(state, 2);
  5540. float distance = lua_interface->GetFloatValue(state, 3);
  5541. if (!spawn) {
  5542. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5543. return 0;
  5544. }
  5545. if (!target) {
  5546. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5547. return 0;
  5548. }
  5549. if (!spawn->IsNPC()) {
  5550. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5551. return 0;
  5552. }
  5553. if (!target->IsEntity()) {
  5554. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5555. return 0;
  5556. }
  5557. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5558. return 1;
  5559. }
  5560. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5561. if (!lua_interface)
  5562. return 0;
  5563. Spawn* spawn = lua_interface->GetSpawn(state);
  5564. Spawn* target = lua_interface->GetSpawn(state, 2);
  5565. float distance = lua_interface->GetFloatValue(state, 3);
  5566. if (!spawn) {
  5567. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5568. return 0;
  5569. }
  5570. if (!target) {
  5571. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5572. return 0;
  5573. }
  5574. if (!spawn->IsNPC()) {
  5575. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5576. return 0;
  5577. }
  5578. if (!target->IsEntity()) {
  5579. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5580. return 0;
  5581. }
  5582. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5583. return 0;
  5584. }
  5585. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5586. if (!lua_interface)
  5587. return 0;
  5588. Spawn* spawn = lua_interface->GetSpawn(state);
  5589. if (!spawn) {
  5590. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5591. return 0;
  5592. }
  5593. if (!spawn->IsNPC()) {
  5594. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5595. return 0;
  5596. }
  5597. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5598. return 1;
  5599. }
  5600. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5601. if (!lua_interface)
  5602. return 0;
  5603. Spawn* spawn = lua_interface->GetSpawn(state);
  5604. if (!spawn) {
  5605. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5606. return 0;
  5607. }
  5608. if (!spawn->IsNPC()) {
  5609. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5610. return 0;
  5611. }
  5612. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5613. return 1;
  5614. }
  5615. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5616. if (!lua_interface)
  5617. return 0;
  5618. Spawn* spawn = lua_interface->GetSpawn(state);
  5619. if (!spawn) {
  5620. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5621. return 0;
  5622. }
  5623. if (!spawn->IsNPC()) {
  5624. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5625. return 0;
  5626. }
  5627. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5628. if (hated) {
  5629. lua_interface->SetSpawnValue(state, hated);
  5630. return 1;
  5631. }
  5632. return 0;
  5633. }
  5634. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5635. if (!lua_interface)
  5636. return 0;
  5637. Spawn* spawn = lua_interface->GetSpawn(state);
  5638. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5639. if (!spawn) {
  5640. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5641. return 0;
  5642. }
  5643. if (!spawn->IsNPC()) {
  5644. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5645. return 0;
  5646. }
  5647. if (!hated) {
  5648. ((NPC*)spawn)->Brain()->ClearHate();
  5649. return 0;
  5650. }
  5651. else
  5652. {
  5653. if (!hated->IsEntity()) {
  5654. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5655. return 0;
  5656. }
  5657. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5658. return 0;
  5659. }
  5660. return 0;
  5661. }
  5662. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5663. if (!lua_interface)
  5664. return 0;
  5665. Spawn* spawn = lua_interface->GetSpawn(state);
  5666. if (!spawn) {
  5667. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5668. return 0;
  5669. }
  5670. if (!spawn->IsNPC()) {
  5671. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5672. return 0;
  5673. }
  5674. ((NPC*)spawn)->Brain()->ClearEncounter();
  5675. return 0;
  5676. }
  5677. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5678. if (!lua_interface)
  5679. return 0;
  5680. Spawn* spawn = lua_interface->GetSpawn(state);
  5681. if (!spawn) {
  5682. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5683. return 0;
  5684. }
  5685. if (!spawn->IsNPC()) {
  5686. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5687. return 0;
  5688. }
  5689. // Temp list to store hate list
  5690. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5691. if (encounterList->size() == 0) {
  5692. safe_delete(encounterList);
  5693. return 0;
  5694. }
  5695. lua_createtable(state, encounterList->size(), 0);
  5696. int newTable = lua_gettop(state);
  5697. for (int32 i = 0; i < encounterList->size(); i++) {
  5698. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5699. if (temp)
  5700. lua_interface->SetSpawnValue(state, temp);
  5701. lua_rawseti(state, newTable, i + 1);
  5702. }
  5703. safe_delete(encounterList);
  5704. return 1;
  5705. }
  5706. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5707. if (!lua_interface)
  5708. return 0;
  5709. Spawn* spawn = lua_interface->GetSpawn(state);
  5710. if (!spawn) {
  5711. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5712. return 0;
  5713. }
  5714. if (!spawn->IsNPC()) {
  5715. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5716. return 0;
  5717. }
  5718. // Temp list to store hate list
  5719. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5720. if (hateList->size() == 0) {
  5721. safe_delete(hateList);
  5722. return 0;
  5723. }
  5724. lua_createtable(state, hateList->size(), 0);
  5725. int newTable = lua_gettop(state);
  5726. for (int32 i = 0; i < hateList->size(); i++) {
  5727. lua_interface->SetSpawnValue(state, hateList->at(i));
  5728. lua_rawseti(state, newTable, i + 1);
  5729. }
  5730. safe_delete(hateList);
  5731. return 1;
  5732. }
  5733. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5734. if (!lua_interface)
  5735. return 0;
  5736. Spawn* spawn = lua_interface->GetSpawn(state);
  5737. if (!spawn) {
  5738. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5739. return 0;
  5740. }
  5741. if (spawn->IsPlayer()) {
  5742. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5743. lua_interface->SetBooleanValue(state, true);
  5744. else
  5745. lua_interface->SetBooleanValue(state, false);
  5746. return 1;
  5747. }
  5748. else {
  5749. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5750. return 1;
  5751. }
  5752. }
  5753. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5754. if (!lua_interface)
  5755. return 0;
  5756. Quest* quest = lua_interface->GetQuest(state);
  5757. if (!quest) {
  5758. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5759. return 0;
  5760. }
  5761. quest->SetCompletedFlag(true);
  5762. return 0;
  5763. }
  5764. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5765. if (!lua_interface)
  5766. return 0;
  5767. Spawn* spawn = lua_interface->GetSpawn(state);
  5768. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5769. int8 tier = lua_interface->GetInt8Value(state, 3);
  5770. if (!spawn) {
  5771. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5772. return 0;
  5773. }
  5774. if (!spawn->IsEntity()) {
  5775. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5776. return 0;
  5777. }
  5778. if (spellID == 0) {
  5779. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5780. return 0;
  5781. }
  5782. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5783. if (effect) {
  5784. if (tier > 0) {
  5785. // If a tier was passed chec to see if it is the same as the effect
  5786. if (tier == effect->tier)
  5787. lua_interface->SetBooleanValue(state, true);
  5788. else
  5789. lua_interface->SetBooleanValue(state, false);
  5790. return 1;
  5791. }
  5792. else {
  5793. // Have an effect but no tier was passed so return true
  5794. lua_interface->SetBooleanValue(state, true);
  5795. }
  5796. return 1;
  5797. }
  5798. // no effect so return false
  5799. lua_interface->SetBooleanValue(state, false);
  5800. return 1;
  5801. }
  5802. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5803. if (!lua_interface)
  5804. return 0;
  5805. Spawn* spawn = lua_interface->GetSpawn(state);
  5806. int32 id = lua_interface->GetInt32Value(state, 2);
  5807. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5808. Spawn* spawn2 = 0;
  5809. vector<Spawn*> list;
  5810. if (!spawn) {
  5811. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5812. return 0;
  5813. }
  5814. //If zone not provided, use spawn's zone
  5815. if (!zone)
  5816. zone = spawn->GetZone();
  5817. list = zone->GetSpawnsByID(id);
  5818. if (list.size() == 0) {
  5819. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5820. return 0;
  5821. }
  5822. vector<Spawn*>::iterator itr = list.begin();
  5823. for (int8 i = 0; i < list.size(); i++) {
  5824. spawn2 = itr[i];
  5825. if (spawn2)
  5826. spawn2->AddAllowAccessSpawn(spawn);
  5827. }
  5828. return 0;
  5829. }
  5830. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5831. if (!lua_interface)
  5832. return 0;
  5833. Spawn* spawn = lua_interface->GetSpawn(state);
  5834. int32 id = lua_interface->GetInt32Value(state, 2);
  5835. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5836. Spawn* spawn2 = 0;
  5837. if (!spawn) {
  5838. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5839. return 0;
  5840. }
  5841. //If zone not provided, use spawn's zone
  5842. if (!zone)
  5843. zone = spawn->GetZone();
  5844. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5845. vector<Spawn*>::iterator itr = list.begin();
  5846. if (list.size() == 0) {
  5847. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5848. return 0;
  5849. }
  5850. for (int8 i = 0; i < list.size(); i++) {
  5851. spawn2 = itr[i];
  5852. if (spawn2)
  5853. spawn2->RemoveSpawnAccess(spawn);
  5854. }
  5855. return 0;
  5856. }
  5857. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5858. if (!lua_interface)
  5859. return 0;
  5860. Quest* quest = lua_interface->GetQuest(state);
  5861. if (!quest) {
  5862. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. quest->SetYellowName(true);
  5866. return 0;
  5867. }
  5868. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5869. if (!lua_interface)
  5870. return 0;
  5871. Spawn* spawn = lua_interface->GetSpawn(state);
  5872. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5873. if (!spawn) {
  5874. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5875. return 0;
  5876. }
  5877. if (!spawn->IsPlayer()) {
  5878. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5879. return 0;
  5880. }
  5881. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5882. return 1;
  5883. }
  5884. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5885. if (!lua_interface)
  5886. return 0;
  5887. Spawn* spawn = lua_interface->GetSpawn(state);
  5888. if (!spawn) {
  5889. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5890. return 0;
  5891. }
  5892. if (!spawn->IsPlayer()) {
  5893. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5894. return 0;
  5895. }
  5896. ZoneServer* zone = spawn->GetZone();
  5897. if (!zone) {
  5898. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5899. return 0;
  5900. }
  5901. Instance_Type iType = zone->GetInstanceType();
  5902. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5903. iType == GROUP_LOCKOUT_INSTANCE ||
  5904. iType == RAID_LOCKOUT_INSTANCE ||
  5905. iType == SOLO_PERSIST_INSTANCE ||
  5906. iType == GROUP_PERSIST_INSTANCE ||
  5907. iType == RAID_PERSIST_INSTANCE) {
  5908. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5909. if (data) {
  5910. // Check to see if the timer has already been set, if it has return out.
  5911. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  5912. return 0;
  5913. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  5914. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  5915. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5916. if (client) {
  5917. string time_msg = "";
  5918. int32 time = data->success_lockout_time;
  5919. int16 hour;
  5920. int8 min;
  5921. int8 sec;
  5922. hour = time / 3600;
  5923. time = time % 3600;
  5924. min = time / 60;
  5925. time = time % 60;
  5926. sec = time;
  5927. if (hour > 0) {
  5928. char temp[10];
  5929. sprintf(temp, " %i", hour);
  5930. time_msg.append(temp);
  5931. time_msg.append(" hour");
  5932. time_msg.append((hour > 1) ? "s" : "");
  5933. }
  5934. if (min > 0) {
  5935. char temp[5];
  5936. sprintf(temp, " %i", min);
  5937. time_msg.append(temp);
  5938. time_msg.append(" minute");
  5939. time_msg.append((min > 1) ? "s" : "");
  5940. }
  5941. // Only add seconds if minutes and hours are 0
  5942. if (hour == 0 && min == 0 && sec > 0) {
  5943. char temp[5];
  5944. sprintf(temp, " %i", sec);
  5945. time_msg.append(temp);
  5946. time_msg.append(" second");
  5947. time_msg.append((sec > 1) ? "s" : "");
  5948. }
  5949. 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());
  5950. }
  5951. }
  5952. else
  5953. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5954. }
  5955. else
  5956. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5957. return 0;
  5958. }
  5959. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  5960. if (!lua_interface)
  5961. return 0;
  5962. Spawn* spawn = lua_interface->GetSpawn(state);
  5963. if (!spawn) {
  5964. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5965. return 0;
  5966. }
  5967. if (!spawn->IsPlayer()) {
  5968. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5969. return 0;
  5970. }
  5971. ZoneServer* zone = spawn->GetZone();
  5972. if (!zone) {
  5973. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5974. return 0;
  5975. }
  5976. Instance_Type iType = zone->GetInstanceType();
  5977. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5978. iType == GROUP_LOCKOUT_INSTANCE ||
  5979. iType == RAID_LOCKOUT_INSTANCE ||
  5980. iType == SOLO_PERSIST_INSTANCE ||
  5981. iType == GROUP_PERSIST_INSTANCE ||
  5982. iType == RAID_PERSIST_INSTANCE) {
  5983. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5984. if (data) {
  5985. // Check to see if the timer has already been set, if it has return out.
  5986. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  5987. return 0;
  5988. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  5989. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  5990. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5991. if (client) {
  5992. string time_msg = "";
  5993. int32 time = data->failure_lockout_time;
  5994. int16 hour;
  5995. int8 min;
  5996. int8 sec;
  5997. hour = time / 3600;
  5998. time = time % 3600;
  5999. min = time / 60;
  6000. time = time % 60;
  6001. sec = time;
  6002. if (hour > 0) {
  6003. char temp[10];
  6004. sprintf(temp, " %i", hour);
  6005. time_msg.append(temp);
  6006. time_msg.append(" hour");
  6007. time_msg.append((hour > 1) ? "s" : "");
  6008. }
  6009. if (min > 0) {
  6010. char temp[5];
  6011. sprintf(temp, " %i", min);
  6012. time_msg.append(temp);
  6013. time_msg.append(" minute");
  6014. time_msg.append((min > 1) ? "s" : "");
  6015. }
  6016. // Only add seconds if minutes and hours are 0
  6017. if (hour == 0 && min == 0 && sec > 0) {
  6018. char temp[5];
  6019. sprintf(temp, " %i", sec);
  6020. time_msg.append(temp);
  6021. time_msg.append(" second");
  6022. time_msg.append((sec > 1) ? "s" : "");
  6023. }
  6024. 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());
  6025. }
  6026. }
  6027. else
  6028. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6029. }
  6030. else
  6031. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6032. return 0;
  6033. }
  6034. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6035. if (!lua_interface)
  6036. return 0;
  6037. Spawn* spawn = lua_interface->GetSpawn(state);
  6038. if (!spawn) {
  6039. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6040. return 0;
  6041. }
  6042. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6043. return 1;
  6044. }
  6045. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6046. if (!lua_interface)
  6047. return 0;
  6048. Spawn* player = lua_interface->GetSpawn(state);
  6049. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6050. if (!player) {
  6051. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6052. return 0;
  6053. }
  6054. if (!player->IsPlayer()) {
  6055. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6056. return 0;
  6057. }
  6058. if (!ground) {
  6059. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6060. return 0;
  6061. }
  6062. if (!ground->IsGroundSpawn()) {
  6063. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6064. return 0;
  6065. }
  6066. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6067. if (!groundspawn_entries) {
  6068. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6069. return 0;
  6070. }
  6071. Skill* skill = 0;
  6072. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6073. if (collection_skill == "Collecting")
  6074. skill = ((Player*)player)->GetSkillByName("Gathering");
  6075. else
  6076. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6077. if (!skill) {
  6078. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6079. return 0;
  6080. }
  6081. vector<GroundSpawnEntry*>::iterator itr;
  6082. GroundSpawnEntry* entry = 0;
  6083. bool can_harvest = false;
  6084. sint32 min_skill = -1;
  6085. // first, iterate through groundspawn_entries, discard tables player cannot use
  6086. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6087. {
  6088. entry = *itr;
  6089. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6090. min_skill = entry->min_skill_level;
  6091. // if player lacks skill, skip table
  6092. if (entry->min_skill_level > skill->current_val)
  6093. continue;
  6094. // if bonus, but player lacks level, skip table
  6095. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6096. continue;
  6097. can_harvest = true;
  6098. break;
  6099. }
  6100. lua_interface->SetBooleanValue(state, can_harvest);
  6101. // If false, send the message to the client
  6102. if (!can_harvest) {
  6103. Client* client = player->GetZone()->GetClientBySpawn(player);
  6104. if (client) {
  6105. string msg = "You do not have enough skill to ";
  6106. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6107. msg.append("gather");
  6108. else if (collection_skill == "Mining")
  6109. msg.append("mine");
  6110. else if (collection_skill == "Trapping")
  6111. msg.append("trap");
  6112. else if (collection_skill == "Foresting")
  6113. msg.append("forest");
  6114. else if (collection_skill == "Fishing")
  6115. msg.append("catch");
  6116. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6117. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  6118. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6119. }
  6120. }
  6121. return 1;
  6122. }
  6123. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6124. if (!lua_interface)
  6125. return 0;
  6126. Spawn* player = lua_interface->GetSpawn(state);
  6127. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6128. if (!player) {
  6129. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6130. return 0;
  6131. }
  6132. if (!player->IsPlayer()) {
  6133. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6134. return 0;
  6135. }
  6136. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6137. lua_interface->SetBooleanValue(state, ret);
  6138. return 1;
  6139. }
  6140. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6141. // Check to see if we have a valid lua_interface
  6142. if (!lua_interface)
  6143. return 0;
  6144. // Get the spawn that is getting the pet
  6145. Spawn* spawn = lua_interface->GetSpawn(state);
  6146. Spawn* target = lua_interface->GetSpawn(state, 2);
  6147. // Get the DB ID of the pet
  6148. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6149. float x = lua_interface->GetFloatValue(state, 4);
  6150. float y = lua_interface->GetFloatValue(state, 5);
  6151. float z = lua_interface->GetFloatValue(state, 6);
  6152. // Get the spell that this command was called from
  6153. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6154. // Check to make sure the spawn pointer is valid
  6155. if (!spawn) {
  6156. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6157. return 0;
  6158. }
  6159. // Check to make sure the spawn is an entity
  6160. if (!spawn->IsEntity()) {
  6161. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. if (!target) {
  6165. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. if (!target->IsEntity()) {
  6169. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6170. return 0;
  6171. }
  6172. // Check to see if the DB ID for the pet is set
  6173. if (pet_id == 0) {
  6174. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6175. return 0;
  6176. }
  6177. // Check to see if the pointer to the spell is valid
  6178. if (!luaspell) {
  6179. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6180. return 0;
  6181. }
  6182. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6183. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6184. if (!pet) {
  6185. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6186. return 0;
  6187. }
  6188. // Check to make sure the pet is an npc
  6189. if (!pet->IsNPC()) {
  6190. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6191. return 0;
  6192. }
  6193. if (x == 0)
  6194. x = spawn->GetX();
  6195. if (y == 0)
  6196. y = spawn->GetY();
  6197. if (z == 0)
  6198. z = spawn->GetZ();
  6199. // Spawn the pet at the same location as the owner
  6200. pet->SetX(x);
  6201. pet->SetY(y);
  6202. pet->SetZ(z);
  6203. pet->SetLocation(spawn->GetLocation());
  6204. pet->SetHeading(spawn->GetHeading());
  6205. spawn->GetZone()->AddSpawn(pet);
  6206. /*
  6207. const char* spawn_script = world.GetSpawnScript(pet_id);
  6208. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6209. spawn->SetSpawnScript(string(spawn_script));
  6210. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6211. }*/
  6212. // Get a random pet name
  6213. string random_pet_name;
  6214. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6215. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6216. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6217. // Set the pets name
  6218. pet->SetName(random_pet_name.c_str());
  6219. // Set the level of the pet to the owners level
  6220. pet->SetLevel(spawn->GetLevel());
  6221. // Set the faction of the pet to the same faction as the owner
  6222. pet->SetFactionID(spawn->GetFactionID());
  6223. // Set the spawn as a pet
  6224. pet->SetPet(true);
  6225. // Give a pointer of the owner to the pet
  6226. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6227. // Set the pet type
  6228. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6229. // Set the spell id used to create this pet
  6230. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6231. // Set the spell tier used to create this pet
  6232. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6233. // Set the pets spawn type to 6
  6234. pet->SetSpawnType(6);
  6235. // Set the pets brain
  6236. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6237. // Check to see if the pet has a subtitle
  6238. if (strlen(pet->GetSubTitle()) > 0) {
  6239. // Add the players name to the front of the sub title
  6240. string pet_subtitle;
  6241. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6242. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6243. // Set the pets subtitle to the new one
  6244. pet->SetSubTitle(pet_subtitle.c_str());
  6245. }
  6246. // Set the pet as the return value for this function
  6247. lua_interface->SetSpawnValue(state, pet);
  6248. return 1;
  6249. }
  6250. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6251. if (!lua_interface)
  6252. return 0;
  6253. Spawn* spawn = lua_interface->GetSpawn(state);
  6254. Spawn* player = lua_interface->GetSpawn(state, 2);
  6255. float max_distance = lua_interface->GetFloatValue(state, 3);
  6256. string type = lua_interface->GetStringValue(state, 4);
  6257. if (!spawn || (spawn && spawn->IsPlayer())) {
  6258. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6259. return 0;
  6260. }
  6261. if (!player || (player && !player->IsPlayer())) {
  6262. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6263. return 0;
  6264. }
  6265. Client* client = 0;
  6266. if (player->GetZone())
  6267. client = player->GetZone()->GetClientBySpawn(player);
  6268. if (!client) {
  6269. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. //Set max_distance to default if not set or not proper value
  6273. if (max_distance <= 0)
  6274. max_distance = 500;
  6275. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6276. if (packet) {
  6277. float unknown2_3 = 0;
  6278. int8 placement_mode = 0;
  6279. if (type == "wall") {
  6280. placement_mode = 2;
  6281. unknown2_3 = 150;
  6282. }
  6283. else if (type == "ceiling")
  6284. placement_mode = 1;
  6285. packet->setDataByName("placement_mode", placement_mode);
  6286. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6287. packet->setDataByName("model_type", spawn->GetModelType());
  6288. packet->setDataByName("unknown", 1); //size
  6289. packet->setDataByName("unknown2", 1); //size 2
  6290. packet->setDataByName("unknown2", .5, 1); //size 3
  6291. packet->setDataByName("unknown2", 3, 2);
  6292. packet->setDataByName("unknown2", unknown2_3, 3);
  6293. packet->setDataByName("max_distance", max_distance);
  6294. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6295. client->QueuePacket(packet->serialize());
  6296. safe_delete(packet);
  6297. }
  6298. return 0;
  6299. }
  6300. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6301. if (!lua_interface)
  6302. return 0;
  6303. Item* item = lua_interface->GetItem(state);
  6304. if (!item) {
  6305. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6306. return 0;
  6307. }
  6308. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6309. return 1;
  6310. }
  6311. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6312. if (!lua_interface)
  6313. return 0;
  6314. Spawn* spawn = lua_interface->GetSpawn(state);
  6315. if (!spawn) {
  6316. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6317. return 0;
  6318. }
  6319. if (spawn->GetZone())
  6320. spawn->GetZone()->AddTransportSpawn(spawn);
  6321. return 0;
  6322. }
  6323. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6324. if (!lua_interface)
  6325. return 0;
  6326. Skill* skill = lua_interface->GetSkill(state);
  6327. if (!skill) {
  6328. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6329. return 0;
  6330. }
  6331. lua_interface->SetInt32Value(state, skill->current_val);
  6332. return 1;
  6333. }
  6334. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6335. if (!lua_interface)
  6336. return 0;
  6337. Skill* skill = lua_interface->GetSkill(state);
  6338. if (!skill) {
  6339. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6340. return 0;
  6341. }
  6342. lua_interface->SetInt32Value(state, skill->max_val);
  6343. return 1;
  6344. }
  6345. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6346. if (!lua_interface)
  6347. return 0;
  6348. Skill* skill = lua_interface->GetSkill(state);
  6349. if (!skill) {
  6350. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6351. return 0;
  6352. }
  6353. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6354. return 1;
  6355. }
  6356. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6357. if (!lua_interface)
  6358. return 0;
  6359. Skill* skill = lua_interface->GetSkill(state);
  6360. int16 value = lua_interface->GetInt16Value(state, 2);
  6361. if (!skill) {
  6362. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6363. return 0;
  6364. }
  6365. skill->max_val = value;
  6366. if (skill->max_val < skill->current_val)
  6367. skill->current_val = skill->max_val;
  6368. return 0;
  6369. }
  6370. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6371. if (!lua_interface)
  6372. return 0;
  6373. Skill* skill = lua_interface->GetSkill(state);
  6374. int16 value = lua_interface->GetInt16Value(state, 2);
  6375. if (!skill) {
  6376. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6377. return 0;
  6378. }
  6379. if (value > skill->max_val)
  6380. skill->current_val = skill->max_val;
  6381. else
  6382. skill->current_val = value;
  6383. return 0;
  6384. }
  6385. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6386. if (!lua_interface)
  6387. return 0;
  6388. Spawn* spawn = lua_interface->GetSpawn(state);
  6389. string name = lua_interface->GetStringValue(state, 2);
  6390. if (!spawn) {
  6391. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6392. return 0;
  6393. }
  6394. if (!spawn->IsEntity()) {
  6395. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6396. return 0;
  6397. }
  6398. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6399. if (skill) {
  6400. lua_interface->SetSkillValue(state, skill);
  6401. return 1;
  6402. }
  6403. return 0;
  6404. }
  6405. int EQ2Emu_lua_AddProc(lua_State* state) {
  6406. if (!lua_interface)
  6407. return 0;
  6408. Spawn* spawn = lua_interface->GetSpawn(state);
  6409. int8 type = lua_interface->GetInt8Value(state, 2);
  6410. float chance = lua_interface->GetFloatValue(state, 3);
  6411. Item* item = lua_interface->GetItem(state, 4);
  6412. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6413. LuaSpell* spell = 0;
  6414. if (!spawn && (!spell || !use_all_spelltargets)) {
  6415. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6416. return 0;
  6417. }
  6418. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6419. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6420. return 0;
  6421. }
  6422. if (!item)
  6423. spell = lua_interface->GetCurrentSpell(state);
  6424. if (!item && !spell) {
  6425. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6426. return 0;
  6427. }
  6428. if (spell && use_all_spelltargets) {
  6429. Spawn* target;
  6430. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6431. for (int8 i = 0; i < spell->targets.size(); i++) {
  6432. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6433. if (!target || !target->IsEntity())
  6434. continue;
  6435. ((Entity*)target)->AddProc(type, chance, item, spell);
  6436. }
  6437. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6438. }
  6439. else
  6440. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6441. return 0;
  6442. }
  6443. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6444. if (!lua_interface)
  6445. return 0;
  6446. Spawn* spawn = lua_interface->GetSpawn(state);
  6447. Item* item = lua_interface->GetItem(state, 2);
  6448. LuaSpell* spell = 0;
  6449. if (!spawn) {
  6450. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6451. return 0;
  6452. }
  6453. if (!spawn->IsEntity()) {
  6454. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6455. return 0;
  6456. }
  6457. if (!item)
  6458. spell = lua_interface->GetCurrentSpell(state);
  6459. if (!item && !spell) {
  6460. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6461. return 0;
  6462. }
  6463. if (spell) {
  6464. Spawn* target;
  6465. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6466. for (int8 i = 0; i < spell->targets.size(); i++) {
  6467. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6468. if (!target || !target->IsEntity())
  6469. continue;
  6470. ((Entity*)target)->RemoveProc(item, spell);
  6471. }
  6472. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6473. spell->caster->RemoveProc(item, spell);
  6474. }
  6475. else
  6476. ((Entity*)spawn)->RemoveProc(item, spell);
  6477. return 0;
  6478. }
  6479. int EQ2Emu_lua_Knockback(lua_State* state) {
  6480. if (!lua_interface)
  6481. return 0;
  6482. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6483. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6484. int32 duration = lua_interface->GetInt32Value(state, 3);
  6485. float vertical = lua_interface->GetFloatValue(state, 4);
  6486. float horizontal = lua_interface->GetFloatValue(state, 5);
  6487. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6488. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6489. if (!target_spawn) {
  6490. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. if (!spawn) {
  6494. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6495. return 0;
  6496. }
  6497. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6498. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6499. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6500. if (packet) {
  6501. packet->setDataByName("target_x", target_spawn->GetX());
  6502. packet->setDataByName("target_y", target_spawn->GetY());
  6503. packet->setDataByName("target_z", target_spawn->GetZ());
  6504. packet->setDataByName("vertical_movement", vertical);
  6505. packet->setDataByName("horizontal_movement", horizontal);
  6506. if (use_heading)
  6507. packet->setDataByName("use_player_heading", 1);
  6508. client->QueuePacket(packet->serialize());
  6509. }
  6510. safe_delete(packet);
  6511. }
  6512. return 0;
  6513. }
  6514. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6515. if (!lua_interface)
  6516. return 0;
  6517. Spawn* spawn = lua_interface->GetSpawn(state);
  6518. if (!spawn) {
  6519. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6520. return 0;
  6521. }
  6522. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6523. return 1;
  6524. }
  6525. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6526. if (!lua_interface)
  6527. return 0;
  6528. Spawn* caster = lua_interface->GetSpawn(state);
  6529. Spawn* target = lua_interface->GetSpawn(state, 2);
  6530. string name = lua_interface->GetStringValue(state, 3);
  6531. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6532. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6533. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6534. string success_msg = lua_interface->GetStringValue(state, 7);
  6535. string effect_msg = lua_interface->GetStringValue(state, 8);
  6536. if (!caster) {
  6537. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6538. return 0;
  6539. }
  6540. if (!caster->IsEntity()) {
  6541. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6542. return 0;
  6543. }
  6544. if (!target) {
  6545. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6546. return 0;
  6547. }
  6548. if (!target->IsEntity()) {
  6549. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6550. return 0;
  6551. }
  6552. if (name.length() == 0) {
  6553. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6554. return 0;
  6555. }
  6556. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6557. return 0;
  6558. }
  6559. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6560. if (!lua_interface)
  6561. return 0;
  6562. string name = lua_interface->GetStringValue(state);
  6563. if (name.length() == 0) {
  6564. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6565. return 0;
  6566. }
  6567. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6568. if (!skill) {
  6569. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6570. return 0;
  6571. }
  6572. lua_interface->SetInt32Value(state, skill->skill_id);
  6573. return 1;
  6574. }
  6575. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6576. if (!lua_interface)
  6577. return 0;
  6578. Spawn* spawn = lua_interface->GetSpawn(state);
  6579. if (!spawn) {
  6580. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6581. return 0;
  6582. }
  6583. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6584. return 1;
  6585. }
  6586. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6587. if (!lua_interface)
  6588. return 0;
  6589. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6590. if (!luaspell) {
  6591. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6592. return 0;
  6593. }
  6594. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6595. return 1;
  6596. }
  6597. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6598. if (!lua_interface)
  6599. return 0;
  6600. Spawn* spawn = lua_interface->GetSpawn(state);
  6601. Spawn* target = lua_interface->GetSpawn(state, 2);
  6602. if (!spawn) {
  6603. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6604. return 0;
  6605. }
  6606. if (!spawn->IsEntity()) {
  6607. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6608. return 0;
  6609. }
  6610. if (!target) {
  6611. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6612. return 0;
  6613. }
  6614. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6615. return 1;
  6616. }
  6617. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6618. if (!lua_interface)
  6619. return 0;
  6620. Spawn* spawn = lua_interface->GetSpawn(state);
  6621. Spawn* target = lua_interface->GetSpawn(state, 2);
  6622. if (!spawn) {
  6623. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6624. return 0;
  6625. }
  6626. if (!spawn->IsEntity()) {
  6627. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6628. return 0;
  6629. }
  6630. if (!target) {
  6631. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6632. return 0;
  6633. }
  6634. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6635. return 1;
  6636. }
  6637. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6638. if (!lua_interface)
  6639. return 0;
  6640. Item* item = lua_interface->GetItem(state);
  6641. if (!item) {
  6642. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6643. return 0;
  6644. }
  6645. lua_interface->SetInt32Value(state, item->details.count);
  6646. return 1;
  6647. }
  6648. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6649. if (!lua_interface)
  6650. return 0;
  6651. Item* item = lua_interface->GetItem(state);
  6652. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6653. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6654. if (!item) {
  6655. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6656. return 0;
  6657. }
  6658. if (!owner) {
  6659. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6660. return 0;
  6661. }
  6662. if (!owner->IsPlayer()) {
  6663. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6664. return 0;
  6665. }
  6666. if (item->stack_count < new_count) {
  6667. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6668. return 0;
  6669. }
  6670. if (new_count > 0) {
  6671. item->details.count = new_count;
  6672. item->save_needed = true;
  6673. }
  6674. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6675. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6676. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6677. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6678. else
  6679. {
  6680. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6681. return 0;
  6682. }
  6683. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6684. if (!client)
  6685. return 0;
  6686. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6687. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6688. if (app)
  6689. client->QueuePacket(app);
  6690. return 0;
  6691. }
  6692. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6693. if (!lua_interface)
  6694. return 0;
  6695. int32 time = lua_interface->GetInt32Value(state);
  6696. string function = lua_interface->GetStringValue(state, 2);
  6697. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6698. Spawn* target = lua_interface->GetSpawn(state, 4);
  6699. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6700. if (time == 0) {
  6701. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6702. return 0;
  6703. }
  6704. if (function.length() == 0) {
  6705. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6706. return 0;
  6707. }
  6708. if (!spell) {
  6709. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6710. return 0;
  6711. }
  6712. SpellScriptTimer* timer = new SpellScriptTimer;
  6713. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6714. #ifdef WIN32
  6715. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6716. #else
  6717. bzero(timer, sizeof(SpellScriptTimer));
  6718. #endif*/
  6719. timer->caster = 0;
  6720. timer->deleteWhenDone = false;
  6721. timer->target = 0;
  6722. timer->time = Timer::GetCurrentTime2() + time;
  6723. timer->customFunction = function;
  6724. timer->spell = spell;
  6725. if (caster)
  6726. timer->caster = caster->GetID();
  6727. if (target)
  6728. timer->target = target->GetID();
  6729. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6730. return 0;
  6731. }
  6732. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6733. if (!lua_interface)
  6734. return 0;
  6735. float hp_perc = lua_interface->GetFloatValue(state);
  6736. float power_perc = lua_interface->GetFloatValue(state, 2);
  6737. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6738. Spawn* target = lua_interface->GetSpawn(state, 4);
  6739. string heal_name = lua_interface->GetStringValue(state, 5);
  6740. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6741. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6742. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6743. if (!spell) {
  6744. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6745. return 0;
  6746. }
  6747. Entity* caster = spell->caster;
  6748. if (!caster) {
  6749. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6750. return 0;
  6751. }
  6752. Client* client = 0;
  6753. PendingResurrection* rez = 0;
  6754. ZoneServer* zone = spell->caster->GetZone();
  6755. if (!target) {
  6756. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6757. if (spell->targets.size() > 0) {
  6758. vector<int32> spell_targets = spell->targets;
  6759. for (int8 i = 0; i < spell_targets.size(); i++) {
  6760. target = zone->GetSpawnByID(spell_targets.at(i));
  6761. if (!target)
  6762. continue;
  6763. if (!target->IsPlayer())
  6764. continue;
  6765. client = target->GetZone()->GetClientBySpawn(target);
  6766. if (!client)
  6767. continue;
  6768. rez = client->GetCurrentRez();
  6769. if (rez->active)
  6770. continue;
  6771. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6772. rez->active = true;
  6773. rez->caster = caster;
  6774. rez->expire_timer = new Timer;
  6775. int32 duration = spell->spell->GetSpellDuration();
  6776. rez->expire_timer->Start(duration * 100);
  6777. rez->hp_perc = hp_perc;
  6778. rez->mp_perc = power_perc;
  6779. rez->range = spell->spell->GetSpellData()->range;
  6780. rez->spell_name = spell->spell->GetName();
  6781. if (heal_name.length() > 0)
  6782. rez->heal_name = heal_name;
  6783. else
  6784. rez->heal_name = rez->spell_name;
  6785. rez->no_calcs = no_calcs;
  6786. rez->crit_mod = crit_mod;
  6787. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6788. if (send_window)
  6789. client->SendResurrectionWindow();
  6790. else {
  6791. target->GetZone()->ResurrectSpawn(target, client);
  6792. rez->should_delete = true;
  6793. }
  6794. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6795. }
  6796. }
  6797. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6798. }
  6799. else {
  6800. client = target->GetZone()->GetClientBySpawn(target);
  6801. if (!client)
  6802. return 0;
  6803. rez = client->GetCurrentRez();
  6804. if (rez->active)
  6805. return 0;
  6806. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6807. rez->active = true;
  6808. rez->caster = caster;
  6809. rez->expire_timer = new Timer;
  6810. int32 duration = spell->spell->GetSpellDuration();
  6811. rez->expire_timer->Start(duration * 100);
  6812. rez->hp_perc = hp_perc;
  6813. rez->mp_perc = power_perc;
  6814. rez->range = spell->spell->GetSpellData()->range;
  6815. rez->spell_name = spell->spell->GetName();
  6816. if (heal_name.length() > 0)
  6817. rez->heal_name = heal_name;
  6818. else
  6819. rez->heal_name = rez->spell_name;
  6820. rez->no_calcs = no_calcs;
  6821. rez->crit_mod = crit_mod;
  6822. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6823. if (send_window)
  6824. client->SendResurrectionWindow();
  6825. else {
  6826. target->GetZone()->ResurrectSpawn(target, client);
  6827. rez->should_delete = true;
  6828. }
  6829. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6830. }
  6831. return 0;
  6832. }
  6833. int EQ2Emu_lua_SetVision(lua_State* state) {
  6834. if (!lua_interface)
  6835. return 0;
  6836. Spawn* spawn = lua_interface->GetSpawn(state);
  6837. int8 vision = lua_interface->GetInt8Value(state, 2);
  6838. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6839. if (!spawn) {
  6840. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6841. return 0;
  6842. }
  6843. if (!spawn->IsEntity()) {
  6844. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6845. return 0;
  6846. }
  6847. if (spell && spell->targets.size() > 0) {
  6848. ZoneServer* zone = spell->caster->GetZone();
  6849. for (int8 i = 0; i < spell->targets.size(); i++) {
  6850. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6851. if (target->IsEntity()) {
  6852. ((Entity*)target)->GetInfoStruct()->vision = vision;
  6853. if (target->IsPlayer())
  6854. ((Player*)target)->SetCharSheetChanged(true);
  6855. }
  6856. }
  6857. }
  6858. else {
  6859. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  6860. if (spawn->IsPlayer())
  6861. ((Player*)spawn)->SetCharSheetChanged(true);
  6862. }
  6863. return 0;
  6864. }
  6865. int EQ2Emu_lua_BlurVision(lua_State* state) {
  6866. if (!lua_interface)
  6867. return 0;
  6868. Spawn* spawn = lua_interface->GetSpawn(state);
  6869. float intensity = lua_interface->GetFloatValue(state, 2);
  6870. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6871. if (!spawn) {
  6872. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6873. return 0;
  6874. }
  6875. if (!spawn->IsEntity()) {
  6876. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6877. return 0;
  6878. }
  6879. if (spell && spell->targets.size() > 0) {
  6880. ZoneServer* zone = spell->caster->GetZone();
  6881. for (int8 i = 0; i < spell->targets.size(); i++) {
  6882. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6883. if (target && target->IsEntity()) {
  6884. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  6885. if (target->IsPlayer())
  6886. ((Player*)target)->SetCharSheetChanged(true);
  6887. }
  6888. }
  6889. }
  6890. else {
  6891. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  6892. if (spawn->IsPlayer())
  6893. ((Player*)spawn)->SetCharSheetChanged(true);
  6894. }
  6895. return 0;
  6896. }
  6897. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  6898. if (!lua_interface)
  6899. return 0;
  6900. Spawn* spawn = lua_interface->GetSpawn(state);
  6901. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  6902. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6903. if (!spawn) {
  6904. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  6905. return 0;
  6906. }
  6907. if (!spawn->IsEntity()) {
  6908. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  6909. return 0;
  6910. }
  6911. if (spell && spell->targets.size() > 0) {
  6912. ZoneServer* zone = spell->caster->GetZone();
  6913. for (int8 i = 0; i < spell->targets.size(); i++) {
  6914. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6915. if (target->IsEntity()) {
  6916. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6917. if (target->IsPlayer())
  6918. ((Player*)target)->SetCharSheetChanged(true);
  6919. }
  6920. }
  6921. }
  6922. else {
  6923. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6924. if (spawn->IsPlayer())
  6925. ((Player*)spawn)->SetCharSheetChanged(true);
  6926. }
  6927. return 0;
  6928. }
  6929. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  6930. if (!lua_interface)
  6931. return 0;
  6932. Item* item = lua_interface->GetItem(state);
  6933. int8 type = lua_interface->GetInt32Value(state, 2);
  6934. if (!item) {
  6935. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  6936. return 0;
  6937. }
  6938. if (type == 1)
  6939. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  6940. else if (type == 2)
  6941. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  6942. return 1;
  6943. }
  6944. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  6945. if (!lua_interface)
  6946. return 0;
  6947. Spawn* target = lua_interface->GetSpawn(state);
  6948. float val = lua_interface->GetFloatValue(state, 2);
  6949. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6950. // Added from Gangrenous post
  6951. if (spell && spell->resisted)
  6952. return 0;
  6953. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  6954. if (val > 1.0f)
  6955. val = 1.0f - (val / 100.0f);
  6956. if (spell && spell->spell && spell->targets.size() > 0) {
  6957. ZoneServer* zone = spell->caster->GetZone();
  6958. for (int32 i = 0; i != spell->targets.size(); i++) {
  6959. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  6960. if (spawn && spawn->IsEntity()) {
  6961. ((Entity*)spawn)->SetSpeedMultiplier(val);
  6962. if (spawn->IsPlayer())
  6963. ((Player*)spawn)->SetCharSheetChanged(true);
  6964. }
  6965. }
  6966. }
  6967. else {
  6968. if (target && target->IsEntity()) {
  6969. ((Entity*)target)->SetSpeedMultiplier(val);
  6970. if (target->IsPlayer())
  6971. ((Player*)target)->SetCharSheetChanged(true);
  6972. }
  6973. }
  6974. return 0;
  6975. }
  6976. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  6977. if (!lua_interface)
  6978. return 0;
  6979. Spawn* spawn = lua_interface->GetSpawn(state);
  6980. int16 model = lua_interface->GetInt16Value(state, 2);
  6981. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6982. if (spell && spell->spell && spell->targets.size() > 0) {
  6983. ZoneServer* zone = spell->caster->GetZone();
  6984. for (int32 i = 0; i < spell->targets.size(); i++) {
  6985. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6986. if (target)
  6987. target->SetIllusionModel(model);
  6988. }
  6989. }
  6990. else {
  6991. if (!spawn) {
  6992. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6993. return 0;
  6994. }
  6995. spawn->SetIllusionModel(model);
  6996. }
  6997. return 0;
  6998. }
  6999. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7000. if (!lua_interface)
  7001. return 0;
  7002. Spawn* spawn = lua_interface->GetSpawn(state);
  7003. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7004. if (spell && spell->spell && spell->targets.size() > 0) {
  7005. ZoneServer* zone = spell->caster->GetZone();
  7006. for (int32 i = 0; i < spell->targets.size(); i++) {
  7007. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7008. if (target)
  7009. target->SetIllusionModel(0);
  7010. }
  7011. }
  7012. else {
  7013. if (!spawn) {
  7014. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7015. return 0;
  7016. }
  7017. spawn->SetIllusionModel(0);
  7018. }
  7019. return 0;
  7020. }
  7021. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7022. if (!lua_interface)
  7023. return 0;
  7024. Spawn* caster = lua_interface->GetSpawn(state);
  7025. Spawn* target = lua_interface->GetSpawn(state, 2);
  7026. float chance = lua_interface->GetFloatValue(state, 3);
  7027. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7028. if (!caster) {
  7029. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7030. return 0;
  7031. }
  7032. if (!caster->IsEntity()) {
  7033. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7034. return 0;
  7035. }
  7036. if (!target) {
  7037. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7038. return 0;
  7039. }
  7040. if (!target->IsEntity()) {
  7041. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7042. return 0;
  7043. }
  7044. if (chance <= 0) {
  7045. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7046. return 0;
  7047. }
  7048. if (!spell) {
  7049. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7050. return 0;
  7051. }
  7052. if (((Entity*)caster)->GetThreatTransfer()) {
  7053. return 0;
  7054. }
  7055. ThreatTransfer* transfer = new ThreatTransfer;
  7056. transfer->Target = target->GetID();
  7057. transfer->Amount = chance;
  7058. transfer->Spell = spell;
  7059. ((Entity*)caster)->SetThreatTransfer(transfer);
  7060. return 0;
  7061. }
  7062. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7063. if (!lua_interface)
  7064. return 0;
  7065. Spawn* spawn = lua_interface->GetSpawn(state);
  7066. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7067. if (!spawn) {
  7068. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7069. return 0;
  7070. }
  7071. if (!spell) {
  7072. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7073. return 0;
  7074. }
  7075. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7076. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7077. ((Entity*)spawn)->SetThreatTransfer(0);
  7078. safe_delete(transfer);
  7079. }
  7080. return 0;
  7081. }
  7082. int EQ2Emu_lua_CureByType(lua_State* state) {
  7083. if (!lua_interface)
  7084. return 0;
  7085. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7086. if (!spell) {
  7087. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7088. return 0;
  7089. }
  7090. int8 cure_count = lua_interface->GetInt8Value(state);
  7091. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7092. string cure_name = lua_interface->GetStringValue(state, 3);
  7093. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7094. Spawn* target = lua_interface->GetSpawn(state, 5);
  7095. if (target) {
  7096. if (!target->IsEntity()) {
  7097. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7098. return 0;
  7099. }
  7100. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7101. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7102. }
  7103. else {
  7104. ZoneServer* zone = spell->caster->GetZone();
  7105. vector<int32> targets = spell->targets;
  7106. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7107. for (int8 i = 0; i < targets.size(); i++) {
  7108. target = zone->GetSpawnByID(targets.at(i));
  7109. if (!target || !target->IsEntity())
  7110. continue;
  7111. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7112. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7113. }
  7114. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7115. }
  7116. return 0;
  7117. }
  7118. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7119. if (!lua_interface)
  7120. return 0;
  7121. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7122. if (!spell) {
  7123. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7124. return 0;
  7125. }
  7126. int8 cure_count = lua_interface->GetInt8Value(state);
  7127. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7128. string cure_name = lua_interface->GetStringValue(state, 3);
  7129. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7130. Spawn* target = lua_interface->GetSpawn(state, 5);
  7131. if (target) {
  7132. if (!target->IsEntity()) {
  7133. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7134. return 0;
  7135. }
  7136. if (((Entity*)target)->GetDetCount() > 0)
  7137. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7138. }
  7139. else {
  7140. ZoneServer* zone = spell->caster->GetZone();
  7141. vector<int32> targets = spell->targets;
  7142. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7143. for (int8 i = 0; i < targets.size(); i++) {
  7144. target = zone->GetSpawnByID(targets.at(i));
  7145. if (!target || !target->IsEntity())
  7146. continue;
  7147. if (((Entity*)target)->GetDetCount() > 0)
  7148. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7149. }
  7150. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7151. }
  7152. return 0;
  7153. }
  7154. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7155. if (!lua_interface)
  7156. return 0;
  7157. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7158. if (!spell) {
  7159. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7160. return 0;
  7161. }
  7162. if (!spell->caster) {
  7163. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7164. return 0;
  7165. }
  7166. if (!spell->caster->GetZone()) {
  7167. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7168. return 0;
  7169. }
  7170. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7171. return 0;
  7172. }
  7173. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7174. if (!lua_interface)
  7175. return 0;
  7176. Spawn* spawn = lua_interface->GetSpawn(state);
  7177. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7178. if (!spell) {
  7179. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7180. return 0;
  7181. }
  7182. if (spawn && spawn->IsEntity())
  7183. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7184. else {
  7185. ZoneServer* zone = spell->caster->GetZone();
  7186. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7187. for (int32 i = 0; i < spell->targets.size(); i++) {
  7188. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7189. if (!spawn || !spawn->IsEntity())
  7190. continue;
  7191. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7192. }
  7193. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7194. }
  7195. return 0;
  7196. }
  7197. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7198. if (!lua_interface)
  7199. return 0;
  7200. Spawn* spawn = lua_interface->GetSpawn(state);
  7201. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7202. if (!spell) {
  7203. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7204. return 0;
  7205. }
  7206. if (spawn && spawn->IsEntity())
  7207. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7208. else {
  7209. ZoneServer* zone = spell->caster->GetZone();
  7210. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7211. for (int32 i = 0; i < spell->targets.size(); i++) {
  7212. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7213. if (!spawn || !spawn->IsEntity())
  7214. continue;
  7215. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7216. }
  7217. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7218. }
  7219. return 0;
  7220. }
  7221. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7222. if (!lua_interface)
  7223. return 0;
  7224. Spawn* caster = lua_interface->GetSpawn(state);
  7225. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7226. if (!caster) {
  7227. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7228. return 0;
  7229. }
  7230. if (!caster->IsPlayer()) {
  7231. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7232. return 0;
  7233. }
  7234. Spawn* target = caster->GetTarget();
  7235. if (!target) {
  7236. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7237. return 0;
  7238. }
  7239. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7240. if (!client) {
  7241. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7242. return 0;
  7243. }
  7244. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7245. if (ho) {
  7246. ho->SetTarget(target->GetID());
  7247. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7248. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7249. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7250. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7251. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7252. deque<GroupMemberInfo*>::iterator itr;
  7253. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7254. if (group)
  7255. {
  7256. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7257. deque<GroupMemberInfo*>* members = group->GetMembers();
  7258. for (itr = members->begin(); itr != members->end(); itr++) {
  7259. if ((*itr)->client)
  7260. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7261. }
  7262. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7263. }
  7264. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7265. }
  7266. else
  7267. safe_delete(ho);
  7268. }
  7269. else {
  7270. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7271. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7272. }
  7273. else
  7274. safe_delete(ho);
  7275. }
  7276. }
  7277. return 0;
  7278. }
  7279. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7280. if (!lua_interface)
  7281. return 0;
  7282. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7283. if (!spell) {
  7284. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7285. return 0;
  7286. }
  7287. int16 triggerCount = lua_interface->GetInt16Value(state);
  7288. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7289. if (!triggerCount) {
  7290. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7291. return 0;
  7292. }
  7293. spell->num_triggers = triggerCount;
  7294. spell->had_triggers = true;
  7295. spell->cancel_after_all_triggers = cancel_after_triggers;
  7296. return 0;
  7297. }
  7298. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7299. if (!lua_interface)
  7300. return 0;
  7301. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7302. if (!spell) {
  7303. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7304. return 0;
  7305. }
  7306. lua_interface->SetInt32Value(state, spell->num_triggers);
  7307. return 1;
  7308. }
  7309. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7310. if (!lua_interface)
  7311. return 0;
  7312. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7313. if (!spell) {
  7314. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. int16 remove_count = lua_interface->GetInt16Value(state);
  7318. if (!remove_count)
  7319. remove_count = 1;
  7320. if (remove_count >= spell->num_triggers) {
  7321. spell->num_triggers = 0;
  7322. if (spell->cancel_after_all_triggers)
  7323. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7324. }
  7325. else {
  7326. spell->num_triggers -= remove_count;
  7327. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7328. }
  7329. return 0;
  7330. }
  7331. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7332. if (!lua_interface)
  7333. return 0;
  7334. Spawn* spawn = lua_interface->GetSpawn(state);
  7335. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7336. if (!spawn) {
  7337. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7338. return 0;
  7339. }
  7340. if (!copy_spawn) {
  7341. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7342. return 0;
  7343. }
  7344. spawn->CopySpawnAppearance(copy_spawn);
  7345. return 0;
  7346. }
  7347. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7348. if (!lua_interface)
  7349. return 0;
  7350. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7351. int8 type = lua_interface->GetInt8Value(state);
  7352. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7353. if (!spell) {
  7354. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7355. return 0;
  7356. }
  7357. if (spawn) {
  7358. if (!spawn->IsEntity()) {
  7359. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7360. return 0;
  7361. }
  7362. Entity* entity = ((Entity*)spawn);
  7363. switch (type) {
  7364. case IMMUNITY_TYPE_AOE:
  7365. entity->AddAOEImmunity(spell);
  7366. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7367. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7368. break;
  7369. case IMMUNITY_TYPE_STUN:
  7370. entity->AddStunImmunity(spell);
  7371. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7372. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7373. break;
  7374. case IMMUNITY_TYPE_ROOT:
  7375. entity->AddRootImmunity(spell);
  7376. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7377. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7378. break;
  7379. case IMMUNITY_TYPE_DAZE:
  7380. entity->AddDazeImmunity(spell);
  7381. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7382. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7383. break;
  7384. case IMMUNITY_TYPE_FEAR:
  7385. entity->AddFearImmunity(spell);
  7386. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7387. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7388. break;
  7389. case IMMUNITY_TYPE_MEZ:
  7390. entity->AddMezImmunity(spell);
  7391. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7392. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7393. break;
  7394. case IMMUNITY_TYPE_STIFLE:
  7395. entity->AddStifleImmunity(spell);
  7396. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7397. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7398. break;
  7399. default:
  7400. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7401. }
  7402. }
  7403. else {
  7404. bool should_break = false;
  7405. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7406. for (int8 i = 0; i < spell->targets.size(); i++) {
  7407. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7408. if (!spawn || !spawn->IsEntity())
  7409. continue;
  7410. Entity* entity = ((Entity*)spawn);
  7411. switch (type) {
  7412. case IMMUNITY_TYPE_AOE:
  7413. entity->AddAOEImmunity(spell);
  7414. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7415. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7416. break;
  7417. case IMMUNITY_TYPE_STUN:
  7418. entity->AddStunImmunity(spell);
  7419. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7420. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7421. break;
  7422. case IMMUNITY_TYPE_ROOT:
  7423. entity->AddRootImmunity(spell);
  7424. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7425. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7426. break;
  7427. case IMMUNITY_TYPE_DAZE:
  7428. entity->AddDazeImmunity(spell);
  7429. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7430. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7431. break;
  7432. case IMMUNITY_TYPE_FEAR:
  7433. entity->AddFearImmunity(spell);
  7434. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7435. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7436. break;
  7437. case IMMUNITY_TYPE_MEZ:
  7438. entity->AddMezImmunity(spell);
  7439. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7440. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7441. break;
  7442. case IMMUNITY_TYPE_STIFLE:
  7443. entity->AddStifleImmunity(spell);
  7444. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7445. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7446. break;
  7447. default:
  7448. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7449. should_break = true;
  7450. }
  7451. if (should_break)
  7452. break;
  7453. }
  7454. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7455. }
  7456. return 0;
  7457. }
  7458. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7459. if (!lua_interface)
  7460. return 0;
  7461. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7462. int8 type = lua_interface->GetInt8Value(state);
  7463. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7464. if (!spell) {
  7465. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7466. return 0;
  7467. }
  7468. if (spawn) {
  7469. if (!spawn->IsEntity()) {
  7470. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7471. return 0;
  7472. }
  7473. Entity* entity = ((Entity*)spawn);
  7474. switch (type) {
  7475. case IMMUNITY_TYPE_AOE:
  7476. entity->RemoveAOEImmunity(spell);
  7477. break;
  7478. case IMMUNITY_TYPE_STUN:
  7479. entity->RemoveStunImmunity(spell);
  7480. break;
  7481. case IMMUNITY_TYPE_ROOT:
  7482. entity->RemoveRootImmunity(spell);
  7483. break;
  7484. case IMMUNITY_TYPE_DAZE:
  7485. entity->RemoveDazeImmunity(spell);
  7486. break;
  7487. case IMMUNITY_TYPE_FEAR:
  7488. entity->RemoveFearImmunity(spell);
  7489. break;
  7490. case IMMUNITY_TYPE_MEZ:
  7491. entity->RemoveMezImmunity(spell);
  7492. break;
  7493. case IMMUNITY_TYPE_STIFLE:
  7494. entity->RemoveStifleImmunity(spell);
  7495. break;
  7496. default:
  7497. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7498. }
  7499. }
  7500. else {
  7501. bool should_break = false;
  7502. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7503. for (int8 i = 0; i < spell->targets.size(); i++) {
  7504. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7505. if (!spawn || !spawn->IsEntity())
  7506. continue;
  7507. Entity* entity = ((Entity*)spawn);
  7508. switch (type) {
  7509. case IMMUNITY_TYPE_AOE:
  7510. entity->RemoveAOEImmunity(spell);
  7511. break;
  7512. case IMMUNITY_TYPE_STUN:
  7513. entity->RemoveStunImmunity(spell);
  7514. break;
  7515. case IMMUNITY_TYPE_ROOT:
  7516. entity->RemoveRootImmunity(spell);
  7517. break;
  7518. case IMMUNITY_TYPE_DAZE:
  7519. entity->RemoveDazeImmunity(spell);
  7520. break;
  7521. case IMMUNITY_TYPE_FEAR:
  7522. entity->RemoveFearImmunity(spell);
  7523. break;
  7524. case IMMUNITY_TYPE_MEZ:
  7525. entity->RemoveMezImmunity(spell);
  7526. break;
  7527. case IMMUNITY_TYPE_STIFLE:
  7528. entity->RemoveStifleImmunity(spell);
  7529. break;
  7530. default:
  7531. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7532. should_break = true;
  7533. }
  7534. if (should_break)
  7535. break;
  7536. }
  7537. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7538. }
  7539. return 0;
  7540. }
  7541. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7542. if (!lua_interface)
  7543. return 0;
  7544. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7545. if (!spell) {
  7546. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7547. return 0;
  7548. }
  7549. float snare = lua_interface->GetFloatValue(state);
  7550. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7551. // convert the val to the speed multipler value (100 - val)
  7552. float val = 100.0 - snare;
  7553. val /= 100.0;
  7554. if (spawn) {
  7555. if (!spawn->IsEntity()) {
  7556. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7557. return 0;
  7558. }
  7559. ((Entity*)spawn)->SetSnareValue(spell, val);
  7560. }
  7561. else {
  7562. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7563. for (int8 i = 0; i < spell->targets.size(); i++) {
  7564. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7565. if (!spawn || !spawn->IsEntity())
  7566. continue;
  7567. ((Entity*)spawn)->SetSnareValue(spell, val);
  7568. }
  7569. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7570. }
  7571. return 0;
  7572. }
  7573. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7574. if (!lua_interface)
  7575. return 0;
  7576. Spawn* spawn = lua_interface->GetSpawn(state);
  7577. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7578. if (!spawn) {
  7579. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7580. return 0;
  7581. }
  7582. if (race_id == 0) {
  7583. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7584. return 0;
  7585. }
  7586. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7587. return 1;
  7588. }
  7589. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7590. if (!lua_interface)
  7591. return 0;
  7592. Spawn* spawn = lua_interface->GetSpawn(state);
  7593. if (!spawn) {
  7594. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7595. return 0;
  7596. }
  7597. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7598. return 1;
  7599. }
  7600. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7601. if (!lua_interface)
  7602. return 0;
  7603. Spawn* spawn = lua_interface->GetSpawn(state);
  7604. if (!spawn) {
  7605. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7606. return 0;
  7607. }
  7608. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7609. return 1;
  7610. }
  7611. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7612. if (!lua_interface)
  7613. return 0;
  7614. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7615. if (!spell) {
  7616. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7617. return 0;
  7618. }
  7619. lua_interface->SetStringValue(state, spell->spell->GetName());
  7620. return 1;
  7621. }
  7622. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7623. if (!lua_interface)
  7624. return 0;
  7625. Quest* quest = lua_interface->GetQuest(state);
  7626. if (!quest) {
  7627. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7628. return 0;
  7629. }
  7630. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7631. return 1;
  7632. }
  7633. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7634. if (!lua_interface)
  7635. return 0;
  7636. Quest* quest = lua_interface->GetQuest(state);
  7637. int32 flags = lua_interface->GetInt32Value(state, 2);
  7638. if (!quest) {
  7639. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7640. return 0;
  7641. }
  7642. quest->SetQuestFlags(flags);
  7643. return 0;
  7644. }
  7645. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7646. if (!lua_interface)
  7647. return 0;
  7648. Quest* quest = lua_interface->GetQuest(state);
  7649. Spawn* player = lua_interface->GetSpawn(state, 2);
  7650. int32 step = lua_interface->GetInt32Value(state, 3);
  7651. int32 duration = lua_interface->GetInt32Value(state, 4);
  7652. string action = lua_interface->GetStringValue(state, 5);
  7653. if (!quest) {
  7654. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7655. return 0;
  7656. }
  7657. if (!player) {
  7658. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7659. return 0;
  7660. }
  7661. if (!player->IsPlayer()) {
  7662. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7663. return 0;
  7664. }
  7665. if (step == 0) {
  7666. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7667. return 0;
  7668. }
  7669. if (duration == 0) {
  7670. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7671. return 0;
  7672. }
  7673. if (action.length() == 0) {
  7674. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7675. return 0;
  7676. }
  7677. Client* client = player->GetZone()->GetClientBySpawn(player);
  7678. if (!client) {
  7679. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7680. return 0;
  7681. }
  7682. quest->SetTimerStep(step);
  7683. quest->AddFailedAction(step, action);
  7684. quest->SetStepTimer(duration);
  7685. client->AddQuestTimer(quest->GetQuestID());
  7686. return 0;
  7687. }
  7688. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7689. if (!lua_interface)
  7690. return 0;
  7691. Quest* quest = lua_interface->GetQuest(state);
  7692. Spawn* player = lua_interface->GetSpawn(state, 2);
  7693. if (!quest) {
  7694. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7695. return 0;
  7696. }
  7697. if (!player) {
  7698. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7699. return 0;
  7700. }
  7701. if (!player->IsPlayer()) {
  7702. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7703. return 0;
  7704. }
  7705. Client* client = player->GetZone()->GetClientBySpawn(player);
  7706. if (!client) {
  7707. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7708. return 0;
  7709. }
  7710. quest->SetTimerStep(0);
  7711. quest->SetStepTimer(0);
  7712. client->RemoveQuestTimer(quest->GetQuestID());
  7713. return 0;
  7714. }
  7715. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7716. if (!lua_interface)
  7717. return 0;
  7718. Spawn* player = lua_interface->GetSpawn(state);
  7719. Quest* quest = lua_interface->GetQuest(state, 2);
  7720. int32 step = lua_interface->GetInt32Value(state, 3);
  7721. if (!player) {
  7722. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7723. return 0;
  7724. }
  7725. if (!player->IsPlayer()) {
  7726. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7727. return 0;
  7728. }
  7729. if (!quest) {
  7730. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7731. return 0;
  7732. }
  7733. if (step == 0) {
  7734. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7735. return 0;
  7736. }
  7737. Client* client = player->GetZone()->GetClientBySpawn(player);
  7738. if (!client) {
  7739. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7740. return 0;
  7741. }
  7742. if (quest->RemoveQuestStep(step, client)) {
  7743. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7744. client->GetCurrentZone()->SendQuestUpdates(client);
  7745. }
  7746. else
  7747. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7748. return 0;
  7749. }
  7750. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7751. if (!lua_interface)
  7752. return 0;
  7753. Quest* quest = lua_interface->GetQuest(state, 1);
  7754. int32 step = lua_interface->GetInt32Value(state, 2);
  7755. string desc = lua_interface->GetStringValue(state, 3);
  7756. string task_group = lua_interface->GetStringValue(state, 4);
  7757. if (!quest) {
  7758. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7759. return 0;
  7760. }
  7761. if (step == 0) {
  7762. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7763. return 0;
  7764. }
  7765. QuestStep* quest_step = quest->GetQuestStep(step);
  7766. if (!quest_step) {
  7767. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7768. return 0;
  7769. }
  7770. quest_step->SetStepProgress(0);
  7771. quest_step->SetTaskGroup(task_group);
  7772. quest_step->SetDescription(desc);
  7773. return 0;
  7774. }
  7775. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7776. if (!lua_interface)
  7777. return 0;
  7778. Quest* quest = lua_interface->GetQuest(state);
  7779. int32 step = lua_interface->GetInt32Value(state, 2);
  7780. string action = lua_interface->GetStringValue(state, 3);
  7781. if (!quest) {
  7782. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7783. return 0;
  7784. }
  7785. if (step == 0) {
  7786. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  7787. return 0;
  7788. }
  7789. if (action.length() == 0) {
  7790. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  7791. return 0;
  7792. }
  7793. quest->AddFailedAction(step, action);
  7794. return 0;
  7795. }
  7796. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  7797. if (!lua_interface)
  7798. return 0;
  7799. Spawn* player = lua_interface->GetSpawn(state);
  7800. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7801. int32 step = lua_interface->GetInt32Value(state, 3);
  7802. if (!player) {
  7803. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7804. return 0;
  7805. }
  7806. if (!player->IsPlayer()) {
  7807. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7808. return 0;
  7809. }
  7810. if (quest_id == 0) {
  7811. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  7812. return 0;
  7813. }
  7814. if (step == 0) {
  7815. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  7816. return 0;
  7817. }
  7818. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  7819. if (!quest) {
  7820. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  7821. return 0;
  7822. }
  7823. quest->StepFailed(step);
  7824. return 0;
  7825. }
  7826. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  7827. if (!lua_interface)
  7828. return 0;
  7829. Spawn* player = lua_interface->GetSpawn(state);
  7830. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7831. if (!player) {
  7832. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  7833. return 0;
  7834. }
  7835. if (!player->IsPlayer()) {
  7836. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  7837. return 0;
  7838. }
  7839. if (quest_id == 0) {
  7840. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  7841. return 0;
  7842. }
  7843. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  7844. if (!quest) {
  7845. lua_interface->SetInt32Value(state, 0);
  7846. return 1;
  7847. }
  7848. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  7849. return 1;
  7850. }
  7851. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  7852. if (!lua_interface)
  7853. return 0;
  7854. string name = lua_interface->GetStringValue(state);
  7855. string value = lua_interface->GetStringValue(state, 2);
  7856. string comment = lua_interface->GetStringValue(state, 3);
  7857. if (name.length() == 0) {
  7858. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7859. return 0;
  7860. }
  7861. if (value.length() == 0) {
  7862. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  7863. return 0;
  7864. }
  7865. string varname = string("lua_").append(name);
  7866. Variable* var = variables.FindVariable(varname);
  7867. if (var)
  7868. var->SetValue(value.c_str());
  7869. else {
  7870. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  7871. variables.AddVariable(var);
  7872. }
  7873. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  7874. return 0;
  7875. }
  7876. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  7877. if (!lua_interface)
  7878. return 0;
  7879. string name = lua_interface->GetStringValue(state);
  7880. if (name.length() == 0) {
  7881. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7882. return 0;
  7883. }
  7884. string varname = string("lua_").append(name);
  7885. Variable* var = variables.FindVariable(varname);
  7886. if (var)
  7887. lua_interface->SetStringValue(state, var->GetValue());
  7888. else
  7889. lua_interface->SetStringValue(state, "NULL");
  7890. return 1;
  7891. }
  7892. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  7893. if (!lua_interface)
  7894. return 0;
  7895. Spawn* player = lua_interface->GetSpawn(state);
  7896. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7897. if (!player) {
  7898. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7899. return 0;
  7900. }
  7901. if (!player->IsPlayer()) {
  7902. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7903. return 0;
  7904. }
  7905. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  7906. return 1;
  7907. }
  7908. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  7909. if (!lua_interface)
  7910. return 0;
  7911. Spawn* player = lua_interface->GetSpawn(state);
  7912. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7913. if (!player) {
  7914. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7915. return 0;
  7916. }
  7917. if (!player->IsPlayer()) {
  7918. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7919. return 0;
  7920. }
  7921. Language* language = master_languages_list.GetLanguage(language_id);
  7922. if (language)
  7923. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  7924. return 0;
  7925. }
  7926. int EQ2Emu_lua_IsNight(lua_State* state) {
  7927. if (!lua_interface)
  7928. return 0;
  7929. ZoneServer* zone = lua_interface->GetZone(state);
  7930. if (!zone) {
  7931. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  7932. return 0;
  7933. }
  7934. lua_interface->SetBooleanValue(state, zone->IsDusk());
  7935. return 1;
  7936. }
  7937. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  7938. if (!lua_interface)
  7939. return 0;
  7940. Spawn* spawn = lua_interface->GetSpawn(state);
  7941. if (!spawn) {
  7942. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  7943. return 0;
  7944. }
  7945. if (!spawn->IsWidget()) {
  7946. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  7947. return 0;
  7948. }
  7949. ((Widget*)spawn)->SetMultiFloorLift(true);
  7950. if (spawn->GetZone())
  7951. spawn->GetZone()->AddTransportSpawn(spawn);
  7952. return 0;
  7953. }
  7954. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  7955. if (!lua_interface)
  7956. return 0;
  7957. Spawn* player = lua_interface->GetSpawn(state);
  7958. int32 path = lua_interface->GetInt32Value(state, 2);
  7959. if (!player) {
  7960. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7961. return 0;
  7962. }
  7963. if (!player->IsPlayer()) {
  7964. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7965. return 0;
  7966. }
  7967. if (path == 0) {
  7968. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  7969. return 0;
  7970. }
  7971. Client* client = player->GetZone()->GetClientBySpawn(player);
  7972. if (!client) {
  7973. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7974. return 0;
  7975. }
  7976. client->SendFlightAutoMount(path);
  7977. return 0;
  7978. }
  7979. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  7980. if (!lua_interface)
  7981. return 0;
  7982. Spawn* player = lua_interface->GetSpawn(state);
  7983. if (!player) {
  7984. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7985. return 0;
  7986. }
  7987. if (!player->IsPlayer()) {
  7988. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7989. return 0;
  7990. }
  7991. Client* client = player->GetZone()->GetClientBySpawn(player);
  7992. if (!client) {
  7993. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7994. return 0;
  7995. }
  7996. client->EndAutoMount();
  7997. return 0;
  7998. }
  7999. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8000. if (!lua_interface)
  8001. return 0;
  8002. Spawn* player = lua_interface->GetSpawn(state);
  8003. if (!player) {
  8004. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8005. return 0;
  8006. }
  8007. if (!player->IsPlayer()) {
  8008. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8009. return 0;
  8010. }
  8011. Client* client = player->GetZone()->GetClientBySpawn(player);
  8012. if (!client) {
  8013. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8014. return 0;
  8015. }
  8016. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8017. return 1;
  8018. }
  8019. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8020. if (!lua_interface)
  8021. return 0;
  8022. Spawn* player = lua_interface->GetSpawn(state);
  8023. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8024. int32 value = lua_interface->GetInt32Value(state, 3);
  8025. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8026. if (!player) {
  8027. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8028. return 0;
  8029. }
  8030. if (!player->IsPlayer()) {
  8031. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8032. return 0;
  8033. }
  8034. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8035. return 0;
  8036. }
  8037. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8038. if (!lua_interface)
  8039. return 0;
  8040. Spawn* player = lua_interface->GetSpawn(state);
  8041. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8042. if (!player) {
  8043. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8044. return 0;
  8045. }
  8046. if (!player->IsPlayer()) {
  8047. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8048. return 0;
  8049. }
  8050. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8051. if (!hd)
  8052. return 0;
  8053. lua_interface->SetInt32Value(state, hd->Value);
  8054. lua_interface->SetInt32Value(state, hd->Value2);
  8055. return 2;
  8056. }
  8057. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8058. if (!lua_interface)
  8059. return 0;
  8060. Spawn* spawn = lua_interface->GetSpawn(state);
  8061. int32 grid = lua_interface->GetInt32Value(state, 2);
  8062. if (!spawn) {
  8063. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8064. return 0;
  8065. }
  8066. if (grid == 0) {
  8067. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8068. return 0;
  8069. }
  8070. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8071. return 0;
  8072. }
  8073. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8074. if (!lua_interface)
  8075. return 0;
  8076. Spawn* spawn = lua_interface->GetSpawn(state);
  8077. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8078. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8079. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8080. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8081. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8082. if (!spawn) {
  8083. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8084. return 0;
  8085. }
  8086. //Add this quest to the list of required quests for this spawn
  8087. spawn->SetRequiredHistory(event_id, value1, value2);
  8088. //If private spawn value set
  8089. if (private_spawn) {
  8090. //Set the spawn to be private when not granted access via history
  8091. spawn->AddAllowAccessSpawn(spawn);
  8092. spawn->SetPrivateQuestSpawn(true);
  8093. }
  8094. //This value will override vis_flags in the vis packet
  8095. if (flag_override > 0)
  8096. spawn->SetQuestsRequiredOverride(flag_override);
  8097. return 0;
  8098. }
  8099. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8100. if (!lua_interface)
  8101. return 0;
  8102. Spawn* player = lua_interface->GetSpawn(state);
  8103. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8104. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8105. if (!player) {
  8106. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8107. return 0;
  8108. }
  8109. if (!player->IsPlayer()) {
  8110. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8111. return 0;
  8112. }
  8113. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8114. return 1;
  8115. }
  8116. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8117. if (!lua_interface)
  8118. return 0;
  8119. Spawn* player = lua_interface->GetSpawn(state);
  8120. int8 level = lua_interface->GetInt8Value(state, 2);
  8121. if (!player) {
  8122. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8123. return 0;
  8124. }
  8125. if (!player->IsPlayer()) {
  8126. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8127. return 0;
  8128. }
  8129. if (level == 0) {
  8130. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8131. return 0;
  8132. }
  8133. Client* client = player->GetZone()->GetClientBySpawn(player);
  8134. if (!client) {
  8135. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8136. return 0;
  8137. }
  8138. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8139. client->GetPlayer()->SetXP(1);
  8140. client->GetPlayer()->SetNeededXP();
  8141. return 0;
  8142. }
  8143. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8144. if (!lua_interface)
  8145. return 0;
  8146. Spawn* player = lua_interface->GetSpawn(state);
  8147. int32 amount = lua_interface->GetInt32Value(state, 2);
  8148. if (!player) {
  8149. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8150. return 0;
  8151. }
  8152. if (!player->IsPlayer()) {
  8153. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8154. return 0;
  8155. }
  8156. if (amount == 0) {
  8157. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8158. return 0;
  8159. }
  8160. ((Player*)player)->AddCoins(amount);
  8161. return 0;
  8162. }
  8163. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8164. if (!lua_interface)
  8165. return 0;
  8166. Spawn* player = lua_interface->GetSpawn(state);
  8167. int32 amount = lua_interface->GetInt32Value(state, 2);
  8168. if (!player) {
  8169. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8170. return 0;
  8171. }
  8172. if (!player->IsPlayer()) {
  8173. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8174. return 0;
  8175. }
  8176. if (amount == 0) {
  8177. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8178. return 0;
  8179. }
  8180. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8181. return 1;
  8182. }
  8183. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8184. if (!lua_interface)
  8185. return 0;
  8186. ZoneServer* zone = lua_interface->GetZone(state);
  8187. if (!zone) {
  8188. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8189. return 0;
  8190. }
  8191. vector<Entity*> players = zone->GetPlayers();
  8192. if (players.size() == 0)
  8193. return 0;
  8194. lua_createtable(state, players.size(), 0);
  8195. int newTable = lua_gettop(state);
  8196. for (int32 i = 0; i < players.size(); i++) {
  8197. lua_interface->SetSpawnValue(state, players.at(i));
  8198. lua_rawseti(state, newTable, i + 1);
  8199. }
  8200. return 1;
  8201. }
  8202. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8203. if (!lua_interface)
  8204. return 0;
  8205. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8206. if (!zone) {
  8207. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8208. return 0;
  8209. }
  8210. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8211. //Map of <placement_id, location_id>
  8212. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8213. map<int32, int32>::iterator itr;
  8214. vector<Spawn*> group;
  8215. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8216. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8217. if (!location) {
  8218. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8219. return 0;
  8220. }
  8221. Spawn* spawn = 0;
  8222. if (location->entities[0]) {
  8223. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8224. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8225. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8226. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8227. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8228. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8229. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8230. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8231. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8232. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8233. if (spawn) {
  8234. const char* script = 0;
  8235. for (int x = 0; x < 3; x++) {
  8236. switch (x) {
  8237. case 0:
  8238. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8239. break;
  8240. case 1:
  8241. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8242. break;
  8243. case 2:
  8244. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8245. break;
  8246. }
  8247. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8248. spawn->SetSpawnScript(string(script));
  8249. break;
  8250. }
  8251. }
  8252. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8253. lua_interface->SetSpawnValue(state, spawn);
  8254. group.push_back(spawn);
  8255. }
  8256. else {
  8257. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8258. safe_delete(spawn);
  8259. }
  8260. }
  8261. }
  8262. if (!group.empty()) {
  8263. lua_createtable(state, group.size(), 0);
  8264. int newTable = lua_gettop(state);
  8265. for (int32 i = 0; i < group.size(); i++) {
  8266. lua_interface->SetSpawnValue(state, group[i]);
  8267. lua_rawseti(state, newTable, i + 1);
  8268. }
  8269. }
  8270. else
  8271. lua_pushnil(state);
  8272. return 1;
  8273. }
  8274. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8275. if (!lua_interface)
  8276. return 0;
  8277. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8278. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8279. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8280. if (!spawn) {
  8281. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8282. return 0;
  8283. }
  8284. if (anim_id == 0) {
  8285. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8286. return 0;
  8287. }
  8288. if (leeway == 0)
  8289. leeway = 5000;
  8290. spawn->SetSpawnAnim(anim_id);
  8291. spawn->SetSpawnAnimLeeway(leeway);
  8292. return 0;
  8293. }
  8294. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8295. if (!lua_interface)
  8296. return 0;
  8297. Spawn* player = lua_interface->GetSpawn(state);
  8298. if (!player) {
  8299. return 0;
  8300. }
  8301. Client* client = player->GetZone()->GetClientBySpawn(player);
  8302. if (!client) {
  8303. return 0;
  8304. }
  8305. lua_interface->SetInt32Value(state, client->GetVersion());
  8306. return 1;
  8307. }
  8308. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8309. if (!lua_interface)
  8310. return 0;
  8311. Item* item = lua_interface->GetItem(state);
  8312. if (!item) {
  8313. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8314. return 0;
  8315. }
  8316. lua_interface->SetInt32Value(state, item->details.item_id);
  8317. return 1;
  8318. }
  8319. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8320. if (!lua_interface)
  8321. return 0;
  8322. Spawn* spawn = lua_interface->GetSpawn(state);
  8323. if (!spawn) {
  8324. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8325. return 0;
  8326. }
  8327. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8328. return 1;
  8329. }
  8330. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8331. if (!lua_interface)
  8332. return 0;
  8333. Spawn* spawn = lua_interface->GetSpawn(state);
  8334. if (!spawn) {
  8335. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8336. return 0;
  8337. }
  8338. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8339. return 1;
  8340. }
  8341. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8342. if (!lua_interface)
  8343. return 0;
  8344. Spawn* spawn = lua_interface->GetSpawn(state);
  8345. if (!spawn) {
  8346. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8347. return 0;
  8348. }
  8349. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8350. return 1;
  8351. }
  8352. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8353. if (!lua_interface)
  8354. return 0;
  8355. Spawn* spawn = lua_interface->GetSpawn(state);
  8356. if (!spawn) {
  8357. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8358. return 0;
  8359. }
  8360. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8361. return 1;
  8362. }
  8363. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8364. if (!lua_interface)
  8365. return 0;
  8366. Spawn* spawn = lua_interface->GetSpawn(state);
  8367. float pct = lua_interface->GetFloatValue(state, 2);
  8368. if (!spawn) {
  8369. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8370. return 0;
  8371. }
  8372. if (pct == 0) {
  8373. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8374. return 0;
  8375. }
  8376. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8377. lua_interface->SetInt32Value(state, amount);
  8378. return 1;
  8379. }
  8380. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8381. if (!lua_interface)
  8382. return 0;
  8383. Spawn* spawn = lua_interface->GetSpawn(state);
  8384. float pct = lua_interface->GetFloatValue(state, 2);
  8385. if (!spawn) {
  8386. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8387. return 0;
  8388. }
  8389. if (pct == 0) {
  8390. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8391. return 0;
  8392. }
  8393. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8394. lua_interface->SetInt32Value(state, amount);
  8395. return 1;
  8396. }
  8397. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8398. if (!lua_interface)
  8399. return 0;
  8400. Spawn* spawn = lua_interface->GetSpawn(state);
  8401. if (!spawn) {
  8402. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8403. return 0;
  8404. }
  8405. if (!spawn->IsPlayer()) {
  8406. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8407. return 0;
  8408. }
  8409. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8410. return 1;
  8411. }
  8412. int EQ2Emu_lua_Evac(lua_State* state) {
  8413. if (!lua_interface)
  8414. return 0;
  8415. Spawn* target = lua_interface->GetSpawn(state);
  8416. if (target) {
  8417. float x = target->GetZone()->GetSafeX();
  8418. float y = target->GetZone()->GetSafeY();
  8419. float z = target->GetZone()->GetSafeZ();
  8420. float h = target->GetZone()->GetSafeHeading();
  8421. target->SetX(x);
  8422. target->SetY(y);
  8423. target->SetZ(z);
  8424. target->SetHeading(h);
  8425. target->SetSpawnOrigX(target->GetX());
  8426. target->SetSpawnOrigY(target->GetY());
  8427. target->SetSpawnOrigZ(target->GetZ());
  8428. target->SetSpawnOrigHeading(target->GetHeading());
  8429. if (target->IsPlayer()) {
  8430. Client* client = target->GetZone()->GetClientBySpawn(target);
  8431. if (client) {
  8432. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8433. if (packet)
  8434. {
  8435. packet->setDataByName("x", x);
  8436. packet->setDataByName("y", y);
  8437. packet->setDataByName("z", z);
  8438. client->QueuePacket(packet->serialize());
  8439. safe_delete(packet);
  8440. }
  8441. }
  8442. }
  8443. }
  8444. else {
  8445. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8446. ZoneServer* zone = spell->caster->GetZone();
  8447. float x = spell->caster->GetZone()->GetSafeX();
  8448. float y = spell->caster->GetZone()->GetSafeY();
  8449. float z = spell->caster->GetZone()->GetSafeZ();
  8450. float h = spell->caster->GetZone()->GetSafeHeading();
  8451. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8452. for (int32 i = 0; i < spell->targets.size(); i++) {
  8453. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8454. if (!target2)
  8455. continue;
  8456. target2->SetX(x);
  8457. target2->SetY(y);
  8458. target2->SetZ(z);
  8459. target2->SetHeading(h);
  8460. target2->SetSpawnOrigX(target2->GetX());
  8461. target2->SetSpawnOrigY(target2->GetY());
  8462. target2->SetSpawnOrigZ(target2->GetZ());
  8463. target2->SetSpawnOrigHeading(target2->GetHeading());
  8464. if (target2->IsPlayer()) {
  8465. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8466. if (client) {
  8467. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8468. if (packet)
  8469. {
  8470. packet->setDataByName("x", x);
  8471. packet->setDataByName("y", y);
  8472. packet->setDataByName("z", z);
  8473. client->QueuePacket(packet->serialize());
  8474. safe_delete(packet);
  8475. }
  8476. }
  8477. }
  8478. }
  8479. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8480. }
  8481. return 0;
  8482. }
  8483. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8484. if (!lua_interface)
  8485. return 0;
  8486. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8487. if (!luaspell) {
  8488. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8489. return 0;
  8490. }
  8491. int8 tier = luaspell->spell->GetSpellTier();
  8492. lua_interface->SetInt32Value(state, tier);
  8493. return 1;
  8494. }
  8495. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8496. if (!lua_interface)
  8497. return 0;
  8498. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8499. if (!luaspell) {
  8500. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8501. return 0;
  8502. }
  8503. int32 spell_id = luaspell->spell->GetSpellID();
  8504. lua_interface->SetInt32Value(state, spell_id);
  8505. return 1;
  8506. }
  8507. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8508. if (!lua_interface)
  8509. return 0;
  8510. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8511. if (!spawn) {
  8512. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8513. return 0;
  8514. }
  8515. if (!spawn->IsPlayer()) {
  8516. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8517. return 0;
  8518. }
  8519. ZoneServer* zone = spawn->GetZone();
  8520. if (!zone) {
  8521. return 0;
  8522. }
  8523. Client* client = zone->GetClientBySpawn(spawn);
  8524. if (!client) {
  8525. return 0;
  8526. }
  8527. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8528. return 0;
  8529. }
  8530. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8531. if (!lua_interface)
  8532. return 0;
  8533. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8534. if (!spawn) {
  8535. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. if (!spawn->IsPlayer()) {
  8539. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8540. return 0;
  8541. }
  8542. ZoneServer* zone = spawn->GetZone();
  8543. if (!zone) {
  8544. return 0;
  8545. }
  8546. Client* client = zone->GetClientBySpawn(spawn);
  8547. if (!client) {
  8548. return 0;
  8549. }
  8550. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8551. return 0;
  8552. }
  8553. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8554. if (!lua_interface)
  8555. return 0;
  8556. Spawn* caster = lua_interface->GetSpawn(state);
  8557. Spawn* target = lua_interface->GetSpawn(state, 2);
  8558. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8559. string spell_name = lua_interface->GetStringValue(state, 4);
  8560. if (!caster) {
  8561. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8562. return 0;
  8563. }
  8564. if (!caster->IsEntity()) {
  8565. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8566. return 0;
  8567. }
  8568. if (!target) {
  8569. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8570. return 0;
  8571. }
  8572. if (!target->IsEntity()) {
  8573. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8574. return 0;
  8575. }
  8576. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8577. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8578. return 0;
  8579. }
  8580. int EQ2Emu_lua_AddLootToObject(lua_State* state) {
  8581. if (!lua_interface)
  8582. return 0;
  8583. Spawn* object = lua_interface->GetSpawn(state);
  8584. Spawn* player = lua_interface->GetSpawn(state, 2);
  8585. if (object && player && player->IsPlayer()) {
  8586. int32 coins = lua_interface->GetInt32Value(state, 3);
  8587. vector<Item*>* items = 0;
  8588. int i = 0;
  8589. int32 item_id = 0;
  8590. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  8591. if (items == 0)
  8592. items = new vector<Item*>;
  8593. if (master_item_list.GetItem(item_id))
  8594. items->push_back(master_item_list.GetItem(item_id));
  8595. i++;
  8596. }
  8597. Client* client = 0;
  8598. client = object->GetZone()->GetClientBySpawn(player);
  8599. if (client) {
  8600. ((Player*)player)->AddPendingLootItems(object->GetID(), items);
  8601. }
  8602. safe_delete(items);
  8603. }
  8604. return 0;
  8605. }
  8606. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8607. if (!lua_interface)
  8608. return 0;
  8609. Spawn* player = lua_interface->GetSpawn(state);
  8610. int32 amount = lua_interface->GetInt32Value(state, 2);
  8611. if (player && player->IsPlayer() && amount > 0) {
  8612. ((Player*)player)->AddXP(amount);
  8613. ((Player*)player)->SetCharSheetChanged(true);
  8614. Client* client = player->GetZone()->GetClientBySpawn(player);
  8615. if (client) {
  8616. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8617. }
  8618. }
  8619. return 0;
  8620. }
  8621. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8622. if (!lua_interface)
  8623. return 0;
  8624. Spawn* player = lua_interface->GetSpawn(state);
  8625. int8 type = lua_interface->GetInt8Value(state, 2);
  8626. string text = lua_interface->GetStringValue(state, 3);
  8627. Client* client = 0;
  8628. if (player && player->IsPlayer())
  8629. client = player->GetZone()->GetClientBySpawn(player);
  8630. if (!client || text.length() == 0) {
  8631. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8632. return 0;
  8633. }
  8634. client->SimpleMessage(type, text.c_str());
  8635. return 0;
  8636. }
  8637. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8638. if (!lua_interface)
  8639. return 0;
  8640. Spawn* player = lua_interface->GetSpawn(state);
  8641. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8642. Client* client = 0;
  8643. if (player && player->IsPlayer())
  8644. client = player->GetZone()->GetClientBySpawn(player);
  8645. if (!client || !spawn) {
  8646. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8647. return 0;
  8648. }
  8649. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8650. if (!items) {
  8651. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8652. return 0;
  8653. }
  8654. client->Loot(spawn->GetLootCoins(), items, spawn);
  8655. return 0;
  8656. }
  8657. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8658. if (!lua_interface)
  8659. return 0;
  8660. Spawn* spawnref = lua_interface->GetSpawn(state);
  8661. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8662. if (spawn_id > 0 && spawnref) {
  8663. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8664. if (spawns.size() == 0) {
  8665. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8666. return 0;
  8667. }
  8668. Spawn* spawn = 0;
  8669. int16 index = MakeRandomInt(0, spawns.size());
  8670. if (index >= spawns.size() || index < 0)
  8671. index = 0;
  8672. spawn = spawns[index];
  8673. lua_interface->SetSpawnValue(state, spawn);
  8674. return 1;
  8675. }
  8676. else {
  8677. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8678. }
  8679. return 0;
  8680. }
  8681. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8682. Spawn* player = lua_interface->GetSpawn(state);
  8683. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8684. string name = lua_interface->GetStringValue(state, 3);
  8685. float distance = lua_interface->GetFloatValue(state, 4);
  8686. string command = lua_interface->GetStringValue(state, 5);
  8687. string error_text = lua_interface->GetStringValue(state, 6);
  8688. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8689. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  8690. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  8691. if (distance == 0)
  8692. distance = 10.0f;
  8693. if (command.length() == 0)
  8694. command = name;
  8695. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  8696. if (spawns.size() == 0) {
  8697. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8698. return 0;
  8699. }
  8700. Spawn* spawn = 0;
  8701. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  8702. spawn = *itr;
  8703. if (spawn) {
  8704. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  8705. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  8706. }
  8707. }
  8708. }
  8709. return 0;
  8710. }
  8711. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  8712. if (!lua_interface)
  8713. return 0;
  8714. Client* client = 0;
  8715. Spawn* player = lua_interface->GetSpawn(state);
  8716. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  8717. if (player && player->IsPlayer() && player->GetZone())
  8718. client = player->GetZone()->GetClientBySpawn(player);
  8719. else{
  8720. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  8721. return 0;
  8722. }
  8723. if (client) {
  8724. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8725. if (packet) {
  8726. packet->setDataByName("goal_num", goal_num);
  8727. client->QueuePacket(packet->serialize());
  8728. safe_delete(packet);
  8729. }
  8730. }
  8731. return 0;
  8732. }
  8733. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  8734. if (!lua_interface)
  8735. return 0;
  8736. Client* client = 0;
  8737. Spawn* player = lua_interface->GetSpawn(state);
  8738. if (player && player->IsPlayer() && player->GetZone())
  8739. client = player->GetZone()->GetClientBySpawn(player);
  8740. else {
  8741. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  8742. return 0;
  8743. }
  8744. if (client) {
  8745. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  8746. }
  8747. return 0;
  8748. }
  8749. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  8750. if (!lua_interface)
  8751. return 0;
  8752. Client* client = 0;
  8753. Spawn* player = lua_interface->GetSpawn(state);
  8754. float duration = lua_interface->GetFloatValue(state, 2);
  8755. string text = lua_interface->GetStringValue(state, 3);
  8756. string voice = lua_interface->GetStringValue(state, 4);
  8757. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  8758. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  8759. string signal = lua_interface->GetStringValue(state, 7);
  8760. string goal1 = lua_interface->GetStringValue(state, 8);
  8761. string task1 = lua_interface->GetStringValue(state, 9);
  8762. string goal2 = lua_interface->GetStringValue(state, 10);
  8763. string task2 = lua_interface->GetStringValue(state, 11);
  8764. string goal3 = lua_interface->GetStringValue(state, 12);
  8765. string task3 = lua_interface->GetStringValue(state, 13);
  8766. string goal4 = lua_interface->GetStringValue(state, 14);
  8767. string task4 = lua_interface->GetStringValue(state, 15);
  8768. if (!player) {
  8769. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  8770. return 0;
  8771. }
  8772. if (!player->IsPlayer()) {
  8773. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  8774. return 0;
  8775. }
  8776. else
  8777. client = ((Player*)player)->GetClient();
  8778. if (!client) {
  8779. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  8780. return 0;
  8781. }
  8782. if (text.length() == 0 || task1.length() == 0 || signal.length() == 0) {
  8783. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  8784. return 0;
  8785. }
  8786. if (duration >= 0 && duration < 2)
  8787. duration = 2;
  8788. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8789. if (packet) {
  8790. packet->setDataByName("open_seconds_max", duration);
  8791. packet->setDataByName("text", text.c_str());
  8792. packet->setDataByName("voice", voice.c_str());
  8793. int8 num_goals = 1;
  8794. if (task2.length() > 0)
  8795. num_goals++;
  8796. if (task3.length() > 0)
  8797. num_goals++;
  8798. if (task4.length() > 0)
  8799. num_goals++;
  8800. packet->setArrayLengthByName("num_goals", num_goals);
  8801. for (int8 i = 0; i < num_goals; i++) {
  8802. packet->setSubArrayLengthByName("num_tasks", 1, i);
  8803. }
  8804. if (goal1.length() > 0)
  8805. packet->setArrayDataByName("goal_text", goal1.c_str());
  8806. if (goal2.length() > 0)
  8807. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  8808. if (goal3.length() > 0)
  8809. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  8810. if (goal4.length() > 0)
  8811. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  8812. packet->setSubArrayDataByName("task_text", task1.c_str());
  8813. if (task2.length() > 0)
  8814. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  8815. if (task3.length() > 0)
  8816. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  8817. if (task4.length() > 0)
  8818. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  8819. packet->setDataByName("complete_sound", "click");
  8820. packet->setDataByName("signal", signal.c_str());
  8821. packet->setDataByName("voice_key1", voice_key1);
  8822. packet->setDataByName("voice_key2", voice_key2);
  8823. client->QueuePacket(packet->serialize());
  8824. safe_delete(packet);
  8825. }
  8826. return 0;
  8827. }
  8828. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  8829. if (!lua_interface)
  8830. return 0;
  8831. Client* client = 0;
  8832. Spawn* player = lua_interface->GetSpawn(state);
  8833. string window = lua_interface->GetStringValue(state, 2);
  8834. int8 show = lua_interface->GetInt8Value(state, 3);
  8835. if (!player) {
  8836. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  8837. return 0;
  8838. }
  8839. if (!player->IsPlayer()) {
  8840. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  8841. return 0;
  8842. }
  8843. else
  8844. client = ((Player*)player)->GetClient();
  8845. if (!client) {
  8846. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  8847. return 0;
  8848. }
  8849. if (window.length() == 0) {
  8850. lua_interface->LogError("LUA ShowWindow required parameters not given");
  8851. return 0;
  8852. }
  8853. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  8854. if (packet) {
  8855. packet->setDataByName("window", window.c_str());
  8856. packet->setDataByName("show", show);
  8857. client->QueuePacket(packet->serialize());
  8858. safe_delete(packet);
  8859. }
  8860. return 0;
  8861. }
  8862. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  8863. //See GameEvents.txt for options that can be used for this function
  8864. if (!lua_interface)
  8865. return 0;
  8866. Client* client = 0;
  8867. Spawn* player = lua_interface->GetSpawn(state);
  8868. string event_name = lua_interface->GetStringValue(state, 2);
  8869. int8 enabled = lua_interface->GetInt8Value(state, 3);
  8870. if (!player || !player->IsPlayer()) {
  8871. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  8872. return 0;
  8873. }
  8874. if (player->GetZone())
  8875. client = player->GetZone()->GetClientBySpawn(player);
  8876. if (!client) {
  8877. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  8878. return 0;
  8879. }
  8880. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  8881. if (packet) {
  8882. packet->setDataByName("event_name", event_name.c_str());
  8883. packet->setDataByName("enabled", enabled);
  8884. client->QueuePacket(packet->serialize());
  8885. safe_delete(packet);
  8886. }
  8887. return 0;
  8888. }
  8889. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  8890. if (!lua_interface)
  8891. return 0;
  8892. Spawn* player = lua_interface->GetSpawn(state);
  8893. if (player && player->IsPlayer()) {
  8894. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  8895. return 1;
  8896. }
  8897. return 0;
  8898. }
  8899. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  8900. if (!lua_interface)
  8901. return 0;
  8902. Spawn* player = lua_interface->GetSpawn(state);
  8903. int8 step = lua_interface->GetInt8Value(state, 2);
  8904. if (player && player->IsPlayer() && step > 0) {
  8905. ((Player*)player)->SetTutorialStep(step);
  8906. }
  8907. return 0;
  8908. }
  8909. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  8910. if (!lua_interface)
  8911. return 0;
  8912. Client* client = 0;
  8913. Spawn* player = lua_interface->GetSpawn(state);
  8914. string window = lua_interface->GetStringValue(state, 2);
  8915. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  8916. if (!player) {
  8917. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  8918. return 0;
  8919. }
  8920. if (!player->IsPlayer()) {
  8921. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  8922. return 0;
  8923. }
  8924. else
  8925. client = ((Player*)player)->GetClient();
  8926. if (!client) {
  8927. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  8928. return 0;
  8929. }
  8930. if (window.length() == 0) {
  8931. lua_interface->LogError("LUA FlashWindow required parameters not given");
  8932. return 0;
  8933. }
  8934. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  8935. if (packet) {
  8936. packet->setDataByName("window", window.c_str());
  8937. packet->setDataByName("flash_seconds", flash_seconds);
  8938. client->QueuePacket(packet->serialize());
  8939. safe_delete(packet);
  8940. }
  8941. return 0;
  8942. }
  8943. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  8944. if (!lua_interface)
  8945. return 0;
  8946. Spawn* spawn = lua_interface->GetSpawn(state);
  8947. Spawn* target = lua_interface->GetSpawn(state, 2);
  8948. if (spawn && target)
  8949. return spawn->CheckLoS(target);
  8950. return 0;
  8951. }
  8952. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  8953. if (!lua_interface)
  8954. return 0;
  8955. Spawn* spawn = lua_interface->GetSpawn(state);
  8956. float x = lua_interface->GetFloatValue(state, 2);
  8957. float y = lua_interface->GetFloatValue(state, 3);
  8958. float z = lua_interface->GetFloatValue(state, 4);
  8959. if (spawn)
  8960. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  8961. return 0;
  8962. }
  8963. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  8964. if (!lua_interface)
  8965. return 0;
  8966. ZoneServer* zone = lua_interface->GetZone(state);
  8967. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  8968. if (zone)
  8969. zone->SetExpansionFlag(xpackFlag);
  8970. return 0;
  8971. }
  8972. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  8973. if (!lua_interface)
  8974. return 0;
  8975. ZoneServer* zone = lua_interface->GetZone(state);
  8976. if (zone) {
  8977. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  8978. return 1;
  8979. }
  8980. return 0;
  8981. }
  8982. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  8983. if (!lua_interface)
  8984. return 0;
  8985. ZoneServer* zone = lua_interface->GetZone(state);
  8986. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  8987. if (zone)
  8988. zone->SetHolidayFlag(holidayFlag);
  8989. return 0;
  8990. }
  8991. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  8992. if (!lua_interface)
  8993. return 0;
  8994. ZoneServer* zone = lua_interface->GetZone(state);
  8995. if (zone) {
  8996. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  8997. return 1;
  8998. }
  8999. return 0;
  9000. }
  9001. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9002. if (!lua_interface)
  9003. return 0;
  9004. Spawn* spawn = lua_interface->GetSpawn(state);
  9005. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9006. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9007. float distance = lua_interface->GetFloatValue(state, 4);
  9008. string in_range_function = lua_interface->GetStringValue(state, 5);
  9009. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9010. if (spawn && distance > 0 && in_range_function.length() > 0)
  9011. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9012. return 0;
  9013. }
  9014. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9015. if (!lua_interface)
  9016. return 0;
  9017. Spawn* spawn = lua_interface->GetSpawn(state);
  9018. Spawn* target = lua_interface->GetSpawn(state, 2);
  9019. if (spawn && target)
  9020. {
  9021. if (spawn->IsPlayer() && target->IsEntity())
  9022. {
  9023. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9024. return 1;
  9025. }
  9026. else if (spawn->IsEntity() && target->IsEntity())
  9027. {
  9028. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9029. return 1;
  9030. }
  9031. }
  9032. return 0;
  9033. }
  9034. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9035. if (!lua_interface)
  9036. return 0;
  9037. Spawn* spawn = lua_interface->GetSpawn(state);
  9038. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9039. if (spawn && spawn->IsEntity())
  9040. {
  9041. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9042. if (spawn->IsPlayer())
  9043. {
  9044. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9045. if (client)
  9046. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9047. }
  9048. }
  9049. return 0;
  9050. }
  9051. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9052. if (!lua_interface)
  9053. return 0;
  9054. Spawn* spawn = lua_interface->GetSpawn(state);
  9055. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9056. if (spawn && spawn->IsEntity())
  9057. {
  9058. ((Entity*)spawn)->SetSeeHideSpell(val);
  9059. if (spawn->IsPlayer())
  9060. {
  9061. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9062. if (client)
  9063. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9064. }
  9065. }
  9066. return 0;
  9067. }
  9068. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9069. {
  9070. if (!lua_interface)
  9071. return 0;
  9072. Spawn* player = lua_interface->GetSpawn(state);
  9073. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9074. string command = lua_interface->GetStringValue(state, 3);
  9075. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9076. if (spawn && player && player->IsPlayer())
  9077. {
  9078. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9079. bool res = false;
  9080. if (cmd)
  9081. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9082. lua_interface->SetBooleanValue(state, res);
  9083. return 1;
  9084. }
  9085. return 0;
  9086. }
  9087. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9088. {
  9089. if (!lua_interface)
  9090. return 0;
  9091. Spawn* spawn = lua_interface->GetSpawn(state);
  9092. string command = lua_interface->GetStringValue(state, 2);
  9093. if (spawn && command.length() > 0)
  9094. spawn->RemovePrimaryEntityCommand(command.c_str());
  9095. return 0;
  9096. }
  9097. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9098. if (!lua_interface)
  9099. return 0;
  9100. Spawn* spawn = lua_interface->GetSpawn(state);
  9101. float distance = lua_interface->GetFloatValue(state, 2);
  9102. string command = lua_interface->GetStringValue(state, 3);
  9103. Spawn* player = lua_interface->GetSpawn(state, 4);
  9104. if (spawn) {
  9105. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9106. }
  9107. return 0;
  9108. }
  9109. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9110. if (!lua_interface)
  9111. return 0;
  9112. Spawn* spawn = lua_interface->GetSpawn(state);
  9113. Spawn* player = lua_interface->GetSpawn(state, 2);
  9114. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9115. if (spawn && player && transport_id && player->IsPlayer()) {
  9116. Client* client = 0;
  9117. if (player && player->IsPlayer())
  9118. client = player->GetZone()->GetClientBySpawn(player);
  9119. if (!client)
  9120. return 0;
  9121. vector<TransportDestination*> destinations;
  9122. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9123. if (destinations.size())
  9124. {
  9125. client->SetTemporaryTransportID(transport_id);
  9126. client->ProcessTeleport(spawn, &destinations, transport_id);
  9127. }
  9128. else
  9129. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9130. }
  9131. return 0;
  9132. }
  9133. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9134. if (!lua_interface)
  9135. return 0;
  9136. Spawn* player = lua_interface->GetSpawn(state);
  9137. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9138. if (player && player->IsPlayer()) {
  9139. Client* client = 0;
  9140. if (player && player->IsPlayer())
  9141. client = player->GetZone()->GetClientBySpawn(player);
  9142. if (!client)
  9143. return 0;
  9144. client->SetTemporaryTransportID(transport_id);
  9145. }
  9146. return 0;
  9147. }
  9148. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9149. if (!lua_interface)
  9150. return 0;
  9151. Spawn* player = lua_interface->GetSpawn(state);
  9152. if (player && player->IsPlayer()) {
  9153. Client* client = 0;
  9154. if (player && player->IsPlayer())
  9155. client = player->GetZone()->GetClientBySpawn(player);
  9156. if (!client)
  9157. return 0;
  9158. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9159. return 1;
  9160. }
  9161. return 0;
  9162. }
  9163. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9164. if (!lua_interface)
  9165. return 0;
  9166. Spawn* spawn = lua_interface->GetSpawn(state);
  9167. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9168. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9169. if (!spawn) {
  9170. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9171. return 0;
  9172. }
  9173. if (!spawn->IsEntity()) {
  9174. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9175. return 0;
  9176. }
  9177. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9178. {
  9179. 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);
  9180. return 0;
  9181. }
  9182. if (spell && spell->targets.size() > 0) {
  9183. ZoneServer* zone = spell->caster->GetZone();
  9184. for (int8 i = 0; i < spell->targets.size(); i++) {
  9185. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9186. if (target->IsEntity()) {
  9187. ((Entity*)target)->GetInfoStruct()->alignment = (sint8)alignment;
  9188. if (target->IsPlayer())
  9189. ((Player*)target)->SetCharSheetChanged(true);
  9190. }
  9191. }
  9192. }
  9193. else {
  9194. ((Entity*)spawn)->GetInfoStruct()->alignment = (sint8)alignment;
  9195. if (spawn->IsPlayer())
  9196. ((Player*)spawn)->SetCharSheetChanged(true);
  9197. }
  9198. return 0;
  9199. }
  9200. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9201. if (!lua_interface)
  9202. return 0;
  9203. Spawn* spawn = lua_interface->GetSpawn(state);
  9204. if (!spawn) {
  9205. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9206. return 0;
  9207. }
  9208. if (!spawn->IsEntity()) {
  9209. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9210. return 0;
  9211. }
  9212. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9213. return 1;
  9214. }
  9215. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9216. if (!lua_interface)
  9217. return 0;
  9218. int32 spell_id = lua_interface->GetInt32Value(state);
  9219. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9220. if (spell_id > 0) {
  9221. if (spell_tier == 0)
  9222. spell_tier = 1;
  9223. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9224. LuaSpell* lua_spell = 0;
  9225. if (lua_interface)
  9226. lua_spell = lua_interface->GetSpell(spell->GetSpellData()->lua_script.c_str());
  9227. if (!lua_spell)
  9228. return 0;
  9229. lua_spell->spell = new Spell(spell);
  9230. lua_interface->SetSpellValue(state, lua_spell);
  9231. return 1;
  9232. }
  9233. return 0;
  9234. }
  9235. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9236. if (!lua_interface)
  9237. return 0;
  9238. LuaSpell* spell = lua_interface->GetSpell(state);
  9239. string field = lua_interface->GetStringValue(state, 2);
  9240. if (!spell) {
  9241. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9242. return 0;
  9243. }
  9244. if (!spell->spell || !spell->spell->GetSpellData()) {
  9245. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9246. return 0;
  9247. }
  9248. boost::to_lower(field);
  9249. return spell->spell->GetSpellData(state, field);
  9250. }
  9251. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9252. if (!lua_interface)
  9253. return 0;
  9254. LuaSpell* spell = lua_interface->GetSpell(state);
  9255. string field = lua_interface->GetStringValue(state, 2);
  9256. int8 fieldArg = 3; // field value after the initial set
  9257. if (!spell) {
  9258. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9259. return 0;
  9260. }
  9261. if (!spell->spell || !spell->spell->GetSpellData()) {
  9262. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9263. return 0;
  9264. }
  9265. boost::to_lower(field);
  9266. bool valSet = false;
  9267. spell->spell->SetSpellData(state, field, fieldArg);
  9268. return valSet;
  9269. }
  9270. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9271. if (!lua_interface)
  9272. return 0;
  9273. LuaSpell* spell = lua_interface->GetSpell(state);
  9274. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9275. Spawn* target = lua_interface->GetSpawn(state, 3);
  9276. if (!target) {
  9277. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9278. return 0;
  9279. }
  9280. if (!target->IsEntity()) {
  9281. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9282. return 0;
  9283. }
  9284. if (!spell) {
  9285. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9286. return 0;
  9287. }
  9288. if (caster && !caster->IsEntity()) {
  9289. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9290. return 0;
  9291. }
  9292. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9293. return 0;
  9294. }