LuaFunctions.cpp 282 KB

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