LuaFunctions.cpp 283 KB

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