LuaFunctions.cpp 377 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. if (spawn) {
  156. const char* mp3 = 0;
  157. const char* text = 0;
  158. const char* emote = 0;
  159. if (mp3_string.length() > 0)
  160. mp3 = mp3_string.c_str();
  161. if (text_string.length() > 0)
  162. text = text_string.c_str();
  163. if (emote_string.length() > 0)
  164. emote = emote_string.c_str();
  165. Client* client = 0;
  166. if (player && player->IsPlayer())
  167. client = spawn->GetZone()->GetClientBySpawn(player);
  168. if (client) {
  169. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  170. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  171. }
  172. else
  173. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  174. }
  175. return 0;
  176. }
  177. int EQ2Emu_lua_PlaySound(lua_State* state) {
  178. if (!lua_interface)
  179. return 0;
  180. Spawn* spawn = lua_interface->GetSpawn(state);
  181. string sound_string = lua_interface->GetStringValue(state, 2);
  182. float x = lua_interface->GetFloatValue(state, 3);
  183. float y = lua_interface->GetFloatValue(state, 4);
  184. float z = lua_interface->GetFloatValue(state, 5);
  185. Spawn* player = lua_interface->GetSpawn(state, 6);
  186. if (spawn && sound_string.length() > 0) {
  187. Client* client = 0;
  188. if (player && player->IsPlayer())
  189. client = spawn->GetZone()->GetClientBySpawn(player);
  190. if (client)
  191. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  192. else
  193. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  194. }
  195. return 0;
  196. }
  197. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  202. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  203. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  204. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  205. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  206. if (!spawn) {
  207. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  208. return 0;
  209. }
  210. if (quest_id > 0) {
  211. //Add this quest to the list of required quests for this spawn
  212. spawn->SetQuestsRequired(quest_id, quest_step);
  213. //If private spawn value set
  214. if (private_spawn) {
  215. //Set the spawn to be private when not granted access through this quest
  216. spawn->AddAllowAccessSpawn(spawn);
  217. spawn->SetPrivateQuestSpawn(true);
  218. }
  219. //This value allows access after a quest step, or the whole quest has been completed
  220. if (continued_access)
  221. spawn->SetQuestsRequiredContinuedAccess(true);
  222. //This value will override vis_flags in the vis packet
  223. if (flag_override > 0)
  224. spawn->SetQuestsRequiredOverride(flag_override);
  225. }
  226. return 0;
  227. }
  228. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  229. if (!lua_interface)
  230. return 0;
  231. Spawn* spawn = lua_interface->GetSpawn(state);
  232. float max_distance = lua_interface->GetFloatValue(state, 2);
  233. string variable = lua_interface->GetStringValue(state, 3);
  234. string value = lua_interface->GetStringValue(state, 4);
  235. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  236. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  237. return 0;
  238. }
  239. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  240. if (!lua_interface)
  241. return 0;
  242. Client* client = 0;
  243. Spawn* player = lua_interface->GetSpawn(state);
  244. if (!player) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  246. return 0;
  247. }
  248. if (!player->IsPlayer()) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  250. return 0;
  251. }
  252. if (player->GetZone())
  253. client = player->GetZone()->GetClientBySpawn(player);
  254. if (!client) {
  255. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  256. return 0;
  257. }
  258. float intensity = lua_interface->GetFloatValue(state, 2);
  259. int8 direction = lua_interface->GetInt8Value(state, 3);
  260. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  261. if (packet) {
  262. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  263. v1 = *(float *)(a1 + 4);
  264. if ( v1 > 0.0 )
  265. v2 = fminf(v1, 1.0);
  266. else
  267. v2 = 0.1;
  268. */
  269. packet->setDataByName("intensity", intensity);
  270. if ( client->GetVersion() > 546 )
  271. packet->setDataByName("direction", direction);
  272. client->QueuePacket(packet->serialize());
  273. safe_delete(packet);
  274. }
  275. return 0;
  276. }
  277. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  278. if (!lua_interface)
  279. return 0;
  280. Spawn* dead = lua_interface->GetSpawn(state);
  281. Spawn* killer = lua_interface->GetSpawn(state, 2);
  282. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  283. if (dead && dead->Alive() && dead->GetZone())
  284. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  285. return 0;
  286. }
  287. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  288. if (!lua_interface)
  289. return 0;
  290. Spawn* spawn = lua_interface->GetSpawn(state);
  291. float max_distance = lua_interface->GetFloatValue(state, 2);
  292. bool include_players = lua_interface->GetInt8Value(state, 3);
  293. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  294. if (max_distance > 0 && spawn && spawn->GetZone())
  295. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  296. return 0;
  297. }
  298. int EQ2Emu_lua_Despawn(lua_State* state) {
  299. if (!lua_interface)
  300. return 0;
  301. Spawn* spawn = lua_interface->GetSpawn(state);
  302. int32 delay = lua_interface->GetInt32Value(state, 2);
  303. if (spawn && spawn->GetZone())
  304. spawn->GetZone()->Despawn(spawn, delay);
  305. return 0;
  306. }
  307. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* spawn = lua_interface->GetSpawn(state);
  311. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  312. if (spawn) {
  313. spawn->info_changed = true;
  314. spawn->SetShowHandIcon(displayHandIcon);
  315. }
  316. return 0;
  317. }
  318. //this function is used to force an update packet to be sent.
  319. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  320. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  321. if (!lua_interface)
  322. return 0;
  323. Spawn* spawn = lua_interface->GetSpawn(state);
  324. if (spawn) {
  325. spawn->vis_changed = true;
  326. spawn->GetZone()->AddChangedSpawn(spawn);
  327. }
  328. return 0;
  329. }
  330. //this function is used to force an update packet to be sent.
  331. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  332. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  333. if (!lua_interface)
  334. return 0;
  335. Spawn* spawn = lua_interface->GetSpawn(state);
  336. if (spawn) {
  337. spawn->info_changed = true;
  338. spawn->GetZone()->AddChangedSpawn(spawn);
  339. }
  340. return 0;
  341. }
  342. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. int32 new_state = lua_interface->GetInt32Value(state, 2);
  347. Spawn* player = lua_interface->GetSpawn(state, 3);
  348. lua_interface->ResetFunctionStack(state);
  349. if (spawn) {
  350. if(player)
  351. {
  352. if(player->IsPlayer())
  353. {
  354. Client* client = ((Player*)player)->GetClient();
  355. if(client)
  356. {
  357. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  358. lua_interface->SetBooleanValue(state, true);
  359. return 1;
  360. }
  361. else
  362. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  363. }
  364. else
  365. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  366. }
  367. else
  368. {
  369. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  370. lua_interface->SetBooleanValue(state, true);
  371. return 1;
  372. }
  373. }
  374. lua_interface->SetBooleanValue(state, false);
  375. return 1;
  376. }
  377. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. Spawn* spawn = lua_interface->GetSpawn(state);
  381. string variable = lua_interface->GetStringValue(state, 2);
  382. string value = lua_interface->GetStringValue(state, 3);
  383. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  384. bool temporary_flag = true;
  385. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  386. if(num_args >= 5)
  387. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  388. int32 type = commands.GetSpawnSetType(variable);
  389. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  390. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  391. return 0;
  392. }
  393. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  394. if (!lua_interface)
  395. return 0;
  396. Spawn* spawn = lua_interface->GetSpawn(state);
  397. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  398. if (spawn && spawn_id > 0) {
  399. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  400. if (closest_spawn) {
  401. lua_interface->SetSpawnValue(state, closest_spawn);
  402. return 1;
  403. }
  404. }
  405. return 0;
  406. }
  407. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  408. if (!lua_interface)
  409. return 0;
  410. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  411. int32 position = lua_interface->GetInt32Value(state, 2);
  412. if (spawnList) {
  413. if (spawnList->size() > position) {
  414. lua_interface->SetSpawnValue(state, spawnList->at(position));
  415. return 1;
  416. }
  417. else {
  418. return 0;
  419. }
  420. return spawnList->size();
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. if (spawnList) {
  429. return spawnList->size();
  430. }
  431. return 0;
  432. }
  433. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  434. if (!lua_interface)
  435. return 0;
  436. vector<Spawn*>* spawnList = new vector<Spawn*>();
  437. lua_interface->SetSpawnListValue(state, spawnList);
  438. return 1;
  439. }
  440. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  441. if (!lua_interface)
  442. return 0;
  443. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  444. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  445. if (spawnList) {
  446. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  447. if (it == spawnList->end())
  448. spawnList->push_back(spawn);
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  456. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  457. if (spawnList) {
  458. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  459. if(it != spawnList->end())
  460. spawnList->erase(it);
  461. }
  462. return 0;
  463. }
  464. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  465. if (!lua_interface)
  466. return 0;
  467. Spawn* spawn = lua_interface->GetSpawn(state);
  468. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  469. if (spawn) {
  470. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  471. if (spawns.size() > 0) {
  472. vector<Spawn*>* spawnList = new vector<Spawn*>();
  473. vector<Spawn*>::iterator itr;
  474. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  475. spawnList->push_back(*itr);
  476. }
  477. lua_interface->SetSpawnListValue(state, spawnList);
  478. return 1;
  479. }
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. Spawn* spawn = lua_interface->GetSpawn(state);
  487. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  488. if (spawn) {
  489. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  490. if (spawns.size() > 0) {
  491. vector<Spawn*>* spawnList = new vector<Spawn*>();
  492. vector<Spawn*>::iterator itr;
  493. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  494. spawnList->push_back(*itr);
  495. }
  496. lua_interface->SetSpawnListValue(state, spawnList);
  497. return 1;
  498. }
  499. }
  500. return 0;
  501. }
  502. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  503. if (!lua_interface)
  504. return 0;
  505. Spawn* spawn = lua_interface->GetSpawn(state);
  506. if (spawn) {
  507. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  508. if (spawns.size() > 0) {
  509. lua_createtable(state, spawns.size(), 0);
  510. int newTable = lua_gettop(state);
  511. for (int32 i = 0; i < spawns.size(); i++) {
  512. lua_interface->SetSpawnValue(state, spawns.at(i));
  513. lua_rawseti(state, newTable, i + 1);
  514. }
  515. return 1;
  516. }
  517. }
  518. return 0;
  519. }
  520. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  521. if (!lua_interface)
  522. return 0;
  523. string variable_name = lua_interface->GetStringValue(state);
  524. Variable* var = variables.FindVariable(variable_name);
  525. if (var) {
  526. lua_interface->SetStringValue(state, var->GetValue());
  527. return 1;
  528. }
  529. return 0;
  530. }
  531. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  532. if (!lua_interface)
  533. return 0;
  534. int32 total_coins = lua_interface->GetInt32Value(state);
  535. if (total_coins == 0) {
  536. lua_interface->SetStringValue(state, "0 copper");
  537. return 1;
  538. }
  539. char tmp[64] = { 0 };
  540. string message = "";
  541. int32 val = 0;
  542. if (total_coins >= 1000000) {
  543. val = total_coins / 1000000;
  544. total_coins -= 1000000 * val;
  545. sprintf(tmp, " %u Platinum", val);
  546. message.append(tmp);
  547. memset(tmp, 0, 64);
  548. }
  549. if (total_coins >= 10000) {
  550. val = total_coins / 10000;
  551. total_coins -= 10000 * val;
  552. sprintf(tmp, " %u Gold", val);
  553. message.append(tmp);
  554. memset(tmp, 0, 64);
  555. }
  556. if (total_coins >= 100) {
  557. val = total_coins / 100;
  558. total_coins -= 100 * val;
  559. sprintf(tmp, " %u Silver", val);
  560. message.append(tmp);
  561. memset(tmp, 0, 64);
  562. }
  563. if (total_coins > 0) {
  564. sprintf(tmp, " %u Copper", (int32)total_coins);
  565. message.append(tmp);
  566. }
  567. lua_interface->SetStringValue(state, message.c_str());
  568. return 1;
  569. }
  570. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  571. ZoneServer* zone = lua_interface->GetZone(state);
  572. int32 group_id = lua_interface->GetInt32Value(state, 2);
  573. if (zone) {
  574. Spawn* spawn = zone->GetSpawnGroup(group_id);
  575. if (spawn) {
  576. lua_interface->SetSpawnValue(state, spawn);
  577. return 1;
  578. }
  579. }
  580. return 0;
  581. }
  582. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  583. ZoneServer* zone = lua_interface->GetZone(state);
  584. int32 location_id = lua_interface->GetInt32Value(state, 2);
  585. if (zone) {
  586. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  587. if (spawn) {
  588. lua_interface->SetSpawnValue(state, spawn);
  589. return 1;
  590. }
  591. }
  592. return 0;
  593. }
  594. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  595. Spawn* spawn = lua_interface->GetSpawn(state);
  596. if (spawn) {
  597. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  598. return 1;
  599. }
  600. return 0;
  601. }
  602. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  603. Spawn* spawn = lua_interface->GetSpawn(state);
  604. if (spawn) {
  605. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  606. return 1;
  607. }
  608. return 0;
  609. }
  610. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  611. if (!lua_interface)
  612. return 0;
  613. Spawn* spawn = lua_interface->GetSpawn(state);
  614. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  615. lua_interface->ResetFunctionStack(state);
  616. if (spawn) {
  617. spawn->SetSpawnGroupID(new_group_id);
  618. lua_interface->SetBooleanValue(state, true);
  619. return 1;
  620. }
  621. lua_interface->SetBooleanValue(state, false);
  622. return 1;
  623. }
  624. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  625. if (!lua_interface)
  626. return 0;
  627. Spawn* spawn = lua_interface->GetSpawn(state);
  628. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  629. lua_interface->ResetFunctionStack(state);
  630. if (spawn) {
  631. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  632. lua_interface->SetBooleanValue(state, true);
  633. return 1;
  634. }
  635. lua_interface->SetBooleanValue(state, false);
  636. return 1;
  637. }
  638. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  639. Spawn* spawn = lua_interface->GetSpawn(state);
  640. if (spawn) {
  641. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  642. return 1;
  643. }
  644. return 0;
  645. }
  646. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  647. Spawn* spawn = lua_interface->GetSpawn(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  655. Player* player = (Player*)lua_interface->GetSpawn(state);
  656. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  657. if (player && player->IsPlayer() && faction_id > 0) {
  658. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 value = lua_interface->GetInt32Value(state, 2);
  668. if (spawn) {
  669. spawn->SetFactionID(value);
  670. }
  671. return 0;
  672. }
  673. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  674. Spawn* spawn = lua_interface->GetSpawn(state);
  675. if (spawn) {
  676. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  677. return 1;
  678. }
  679. return 0;
  680. }
  681. int EQ2Emu_lua_GetGender(lua_State* state) {
  682. Spawn* spawn = lua_interface->GetSpawn(state);
  683. if (spawn) {
  684. lua_interface->SetInt32Value(state, spawn->GetGender());
  685. return 1;
  686. }
  687. return 0;
  688. }
  689. int EQ2Emu_lua_GetTarget(lua_State* state) {
  690. Spawn* spawn = lua_interface->GetSpawn(state);
  691. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  692. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  693. return 1;
  694. }
  695. return 0;
  696. }
  697. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  698. if (!lua_interface)
  699. return 0;
  700. Spawn* spawn = lua_interface->GetSpawn(state);
  701. string mp3_string = lua_interface->GetStringValue(state, 2);
  702. int32 key1 = lua_interface->GetInt32Value(state, 3);
  703. int32 key2 = lua_interface->GetInt32Value(state, 4);
  704. Spawn* player = lua_interface->GetSpawn(state, 5);
  705. if (spawn && mp3_string.length() > 0) {
  706. Client* client = 0;
  707. if (player && player->IsPlayer())
  708. client = spawn->GetZone()->GetClientBySpawn(player);
  709. if (client) {
  710. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  711. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  712. }
  713. else
  714. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  715. }
  716. return 0;
  717. }
  718. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  719. if (!lua_interface)
  720. return 0;
  721. Spawn* spawn = lua_interface->GetSpawn(state);
  722. if (spawn) {
  723. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  724. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  725. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  726. return 3;
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  731. if (!lua_interface)
  732. return 0;
  733. Spawn* spawn = lua_interface->GetSpawn(state);
  734. if (spawn) {
  735. int32 item_id = lua_interface->GetInt32Value(state, 2);
  736. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  737. return 1;
  738. }
  739. return 0;
  740. }
  741. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  742. if (!lua_interface)
  743. return 0;
  744. Spawn* spawn = lua_interface->GetSpawn(state);
  745. if (spawn && spawn->IsEntity()) {
  746. int32 item_id = lua_interface->GetInt32Value(state, 2);
  747. int16 charges = lua_interface->GetInt16Value(state, 3);
  748. if (charges == 0)
  749. charges = 1;
  750. ((Entity*)spawn)->AddLootItem(item_id, charges);
  751. }
  752. return 0;
  753. }
  754. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  755. if (!lua_interface)
  756. return 0;
  757. Spawn* spawn = lua_interface->GetSpawn(state);
  758. if (spawn && spawn->IsEntity()) {
  759. int32 item_id = lua_interface->GetInt32Value(state, 2);
  760. Item* item = spawn->LootItem(item_id);
  761. safe_delete(item);
  762. }
  763. return 0;
  764. }
  765. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  766. if (!lua_interface)
  767. return 0;
  768. Spawn* spawn = lua_interface->GetSpawn(state);
  769. if (spawn) {
  770. int32 val = lua_interface->GetInt32Value(state, 2);
  771. spawn->AddLootCoins(val);
  772. }
  773. return 0;
  774. }
  775. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  776. if (!lua_interface)
  777. return 0;
  778. Spawn* entity = lua_interface->GetSpawn(state);
  779. Spawn* player = lua_interface->GetSpawn(state, 2);
  780. if (entity && player && player->IsPlayer()) {
  781. int32 coins = lua_interface->GetInt32Value(state, 3);
  782. vector<Item*>* items = 0;
  783. int i = 0;
  784. int32 item_id = 0;
  785. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  786. if (items == 0)
  787. items = new vector<Item*>;
  788. if (master_item_list.GetItem(item_id))
  789. items->push_back(master_item_list.GetItem(item_id));
  790. i++;
  791. }
  792. Client* client = 0;
  793. client = player->GetZone()->GetClientBySpawn(player);
  794. if (client)
  795. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  796. if(coins > 0)
  797. entity->AddLootCoins(coins);
  798. safe_delete(items);
  799. }
  800. return 0;
  801. }
  802. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  803. if (!lua_interface)
  804. return 0;
  805. Spawn* entity = lua_interface->GetSpawn(state);
  806. Spawn* player = lua_interface->GetSpawn(state, 2);
  807. int32 item_id = lua_interface->GetInt32Value(state, 3);
  808. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  809. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  810. return 1;
  811. }
  812. return 0;
  813. }
  814. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  815. if (!lua_interface)
  816. return 0;
  817. Spawn* entity = lua_interface->GetSpawn(state);
  818. Spawn* player = lua_interface->GetSpawn(state, 2);
  819. if (entity && player && player->IsPlayer()) {
  820. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  821. return 1;
  822. }
  823. return 0;
  824. }
  825. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  826. if (!lua_interface)
  827. return 0;
  828. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  829. safe_delete(conversation);
  830. conversation = new vector<ConversationOption>();
  831. lua_interface->SetConversationValue(state, conversation);
  832. return 1;
  833. }
  834. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  835. if (!lua_interface)
  836. return 0;
  837. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  838. if (conversation) {
  839. ConversationOption conv_option;
  840. conv_option.option = lua_interface->GetStringValue(state, 2);
  841. conv_option.function = lua_interface->GetStringValue(state, 3);
  842. if (conv_option.option.length() > 0)
  843. conversation->push_back(conv_option);
  844. }
  845. return 0;
  846. }
  847. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* npc = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. if (npc && player && player->IsPlayer() && player->GetZone()) {
  853. Client* client = player->GetZone()->GetClientBySpawn(player);
  854. if (client) {
  855. int32 conversation_id = client->GetConversationID(npc, 0);
  856. client->CloseDialog(conversation_id);
  857. }
  858. }
  859. return 0;
  860. }
  861. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  862. if (!lua_interface)
  863. return 0;
  864. Item* item = lua_interface->GetItem(state);
  865. Spawn* player = lua_interface->GetSpawn(state, 2);
  866. if (item && player && player->IsPlayer() && player->GetZone()) {
  867. Client* client = player->GetZone()->GetClientBySpawn(player);
  868. if (client) {
  869. int32 conversation_id = client->GetConversationID(0, item);
  870. client->CloseDialog(conversation_id);
  871. }
  872. }
  873. return 0;
  874. }
  875. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  876. if (!lua_interface)
  877. return 0;
  878. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  879. Spawn* spawn = 0;
  880. Item* item = 0;
  881. int8 type = lua_interface->GetInt8Value(state, 2);
  882. if (type == 1 || type == 3)
  883. spawn = lua_interface->GetSpawn(state, 3);
  884. else if (type == 2 || type == 4)
  885. item = lua_interface->GetItem(state, 3);
  886. Spawn* player = lua_interface->GetSpawn(state, 4);
  887. string text = lua_interface->GetStringValue(state, 5);
  888. string mp3 = lua_interface->GetStringValue(state, 6);
  889. int32 key1 = lua_interface->GetInt32Value(state, 7);
  890. int32 key2 = lua_interface->GetInt32Value(state, 8);
  891. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  892. Client* client = player->GetZone()->GetClientBySpawn(player);
  893. if (client) {
  894. if (spawn) {
  895. // Need to do this so the function works the same as it did before
  896. if (type == 1)
  897. type++;
  898. if (mp3.length() > 0)
  899. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  900. else
  901. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  902. }
  903. else {
  904. if (mp3.length() > 0)
  905. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  906. else
  907. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  908. }
  909. }
  910. }
  911. safe_delete(conversation);
  912. lua_interface->SetConversationValue(state, NULL);
  913. return 0;
  914. }
  915. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  916. if(!lua_interface)
  917. return 0;
  918. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  919. Item* item = lua_interface->GetItem(state, 2);
  920. Spawn* player = lua_interface->GetSpawn(state, 3);
  921. string text = lua_interface->GetStringValue(state, 4);
  922. string mp3 = lua_interface->GetStringValue(state, 5);
  923. int32 key1 = lua_interface->GetInt32Value(state, 6);
  924. int32 key2 = lua_interface->GetInt32Value(state, 7);
  925. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  926. Client* client = player->GetZone()->GetClientBySpawn(player);
  927. if(client){
  928. if(mp3.length() > 0)
  929. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  930. else
  931. client->DisplayConversation(item, conversation, (char*)text.c_str());
  932. }
  933. safe_delete(conversation);
  934. }
  935. return 0;
  936. }*/
  937. int EQ2Emu_lua_StartConversation(lua_State* state) {
  938. if (!lua_interface)
  939. return 0;
  940. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  941. Spawn* source = lua_interface->GetSpawn(state, 2);
  942. Spawn* player = lua_interface->GetSpawn(state, 3);
  943. string text = lua_interface->GetStringValue(state, 4);
  944. string mp3 = lua_interface->GetStringValue(state, 5);
  945. int32 key1 = lua_interface->GetInt32Value(state, 6);
  946. int32 key2 = lua_interface->GetInt32Value(state, 7);
  947. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  948. Client* client = source->GetZone()->GetClientBySpawn(player);
  949. if (mp3.length() > 0)
  950. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  951. else
  952. client->DisplayConversation(source, 1, conversation, text.c_str());
  953. safe_delete(conversation);
  954. lua_interface->SetConversationValue(state, NULL);
  955. }
  956. else
  957. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  958. return 0;
  959. }
  960. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  961. if (!lua_interface)
  962. return 0;
  963. Spawn* spawn = lua_interface->GetSpawn(state);
  964. float distance = lua_interface->GetFloatValue(state, 2);
  965. string in_range_function = lua_interface->GetStringValue(state, 3);
  966. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  967. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  968. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  969. return 0;
  970. }
  971. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  972. ZoneServer* zone = lua_interface->GetZone(state);
  973. float x = lua_interface->GetFloatValue(state, 2);
  974. float y = lua_interface->GetFloatValue(state, 3);
  975. float z = lua_interface->GetFloatValue(state, 4);
  976. float max_variation = lua_interface->GetFloatValue(state, 5);
  977. string in_range_function = lua_interface->GetStringValue(state, 6);
  978. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  979. if (zone && in_range_function.length() > 0)
  980. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  981. return 0;
  982. }
  983. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  984. if (!lua_interface)
  985. return 0;
  986. Spawn* spawn = lua_interface->GetSpawn(state);
  987. if (spawn && spawn->IsEntity()) {
  988. int32 val = lua_interface->GetInt32Value(state, 2);
  989. ((Entity*)spawn)->SetLootCoins(val);
  990. }
  991. return 0;
  992. }
  993. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  994. if (!lua_interface)
  995. return 0;
  996. Spawn* spawn = lua_interface->GetSpawn(state);
  997. if (spawn && spawn->IsEntity()) {
  998. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  999. return 1;
  1000. }
  1001. return 0;
  1002. }
  1003. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1004. if (!lua_interface)
  1005. return 0;
  1006. Spawn* spawn = lua_interface->GetSpawn(state);
  1007. float x = lua_interface->GetFloatValue(state, 2);
  1008. float y = lua_interface->GetFloatValue(state, 3);
  1009. float z = lua_interface->GetFloatValue(state, 4);
  1010. float speed = lua_interface->GetFloatValue(state, 5);
  1011. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1012. string function = lua_interface->GetStringValue(state, 7);
  1013. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1014. float heading = lua_interface->GetFloatValue(state, 8);
  1015. if (spawn) {
  1016. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1017. spawn->GetZone()->AddMovementNPC(spawn);
  1018. }
  1019. lua_interface->ResetFunctionStack(state);
  1020. return 0;
  1021. }
  1022. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1023. if (!lua_interface)
  1024. return 0;
  1025. Spawn* spawn = lua_interface->GetSpawn(state);
  1026. if (spawn) {
  1027. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1028. return 1;
  1029. }
  1030. return 0;
  1031. }
  1032. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1033. if (!lua_interface)
  1034. return 0;
  1035. Spawn* spawn = lua_interface->GetSpawn(state);
  1036. if (spawn && spawn->IsPlayer()) {
  1037. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1038. return 1;
  1039. }
  1040. lua_interface->SetInt32Value(state, 0);
  1041. return 1;
  1042. }
  1043. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1044. if (!lua_interface)
  1045. return 0;
  1046. Spawn* spawn = lua_interface->GetSpawn(state);
  1047. Spawn* target = lua_interface->GetSpawn(state, 2);
  1048. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1049. bool reset_action_state = true;
  1050. if(num_args > 2)
  1051. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1052. if (spawn && target) {
  1053. if (spawn->IsEntity())
  1054. // ((Entity*)spawn)->FaceTarget(target);
  1055. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1056. }
  1057. lua_interface->ResetFunctionStack(state);
  1058. return 0;
  1059. }
  1060. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1061. if (!lua_interface)
  1062. return 0;
  1063. Spawn* spawn = lua_interface->GetSpawn(state);
  1064. float x = lua_interface->GetFloatValue(state, 2);
  1065. float y = lua_interface->GetFloatValue(state, 3);
  1066. float z = lua_interface->GetFloatValue(state, 4);
  1067. float speed = lua_interface->GetFloatValue(state, 5);
  1068. string lua_function = lua_interface->GetStringValue(state, 6);
  1069. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1070. if (spawn) {
  1071. if (speed == 0)
  1072. speed = spawn->GetSpeed();
  1073. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1074. }
  1075. lua_interface->ResetFunctionStack(state);
  1076. return 0;
  1077. }
  1078. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1079. if (!lua_interface)
  1080. return 0;
  1081. Spawn* spawn = lua_interface->GetSpawn(state);
  1082. if (spawn) {
  1083. spawn->ClearRunningLocations();
  1084. }
  1085. return 0;
  1086. }
  1087. int EQ2Emu_lua_Say(lua_State* state) {
  1088. if (!lua_interface)
  1089. return 0;
  1090. Spawn* spawn = lua_interface->GetSpawn(state);
  1091. string message = lua_interface->GetStringValue(state, 2);
  1092. Spawn* player = lua_interface->GetSpawn(state, 3);
  1093. int32 language = lua_interface->GetInt32Value(state, 4);
  1094. if (spawn && message.length() > 0) {
  1095. Client* client = 0;
  1096. if (player && player->IsPlayer())
  1097. client = spawn->GetZone()->GetClientBySpawn(player);
  1098. if (client)
  1099. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1100. else
  1101. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1102. }
  1103. lua_interface->ResetFunctionStack(state);
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_Shout(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. Spawn* spawn = lua_interface->GetSpawn(state);
  1110. string message = lua_interface->GetStringValue(state, 2);
  1111. Spawn* player = lua_interface->GetSpawn(state, 3);
  1112. float dist = lua_interface->GetFloatValue(state, 4);
  1113. if (spawn && message.length() > 0) {
  1114. Client* client = 0;
  1115. if (player && player->IsPlayer())
  1116. client = spawn->GetZone()->GetClientBySpawn(player);
  1117. if (client)
  1118. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1119. else
  1120. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1121. }
  1122. lua_interface->ResetFunctionStack(state);
  1123. return 0;
  1124. }
  1125. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1126. if (!lua_interface)
  1127. return 0;
  1128. Spawn* spawn = lua_interface->GetSpawn(state);
  1129. string message = lua_interface->GetStringValue(state, 2);
  1130. Spawn* player = lua_interface->GetSpawn(state, 3);
  1131. if (spawn && message.length() > 0) {
  1132. Client* client = 0;
  1133. if (player && player->IsPlayer())
  1134. client = spawn->GetZone()->GetClientBySpawn(player);
  1135. if (client)
  1136. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1137. else
  1138. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1139. }
  1140. lua_interface->ResetFunctionStack(state);
  1141. return 0;
  1142. }
  1143. int EQ2Emu_lua_Emote(lua_State* state) {
  1144. if (!lua_interface)
  1145. return 0;
  1146. Spawn* spawn = lua_interface->GetSpawn(state);
  1147. string message = lua_interface->GetStringValue(state, 2);
  1148. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1149. Spawn* player = lua_interface->GetSpawn(state, 4);
  1150. char* to = 0;
  1151. if (spawn2)
  1152. to = spawn2->GetName();
  1153. if (spawn && message.length() > 0) {
  1154. Client* client = 0;
  1155. if (player && player->IsPlayer())
  1156. client = spawn->GetZone()->GetClientBySpawn(player);
  1157. if (client)
  1158. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1159. else
  1160. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1161. }
  1162. lua_interface->ResetFunctionStack(state);
  1163. return 0;
  1164. }
  1165. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1166. if (!lua_interface)
  1167. return 0;
  1168. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1169. if (!luaspell)
  1170. return 0;
  1171. Spawn* caster = luaspell->caster;
  1172. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1173. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1174. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1175. Spawn* target = lua_interface->GetSpawn(state, 4);
  1176. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1177. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1178. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1179. lua_interface->ResetFunctionStack(state);
  1180. boost::to_lower(heal_type);
  1181. if (caster && caster->IsEntity()) {
  1182. bool success = false;
  1183. luaspell->resisted = false;
  1184. if (target) {
  1185. float distance = caster->GetDistance(target, true);
  1186. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1187. success = true;
  1188. }
  1189. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1190. Spawn* target = 0;
  1191. ZoneServer* zone = luaspell->caster->GetZone();
  1192. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1193. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1194. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1195. float distance = caster->GetDistance(target, true);
  1196. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1197. }
  1198. }
  1199. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1200. success = true;
  1201. }
  1202. if (success) {
  1203. if (caster->GetZone())
  1204. caster->GetZone()->TriggerCharSheetTimer();
  1205. }
  1206. }
  1207. return 0;
  1208. }
  1209. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1210. if (!lua_interface)
  1211. return 0;
  1212. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1213. if (!luaspell)
  1214. return 0;
  1215. Spawn* caster = luaspell->caster;
  1216. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1217. float percentage = lua_interface->GetFloatValue(state, 2);
  1218. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1219. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1220. Spawn* target = lua_interface->GetSpawn(state, 5);
  1221. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1222. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1223. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1224. lua_interface->ResetFunctionStack(state);
  1225. boost::to_lower(heal_type);
  1226. int32 min_heal = 0, max_heal = 0;
  1227. if (caster && caster->IsEntity() && target) {
  1228. if(percentage <= 0.0f)
  1229. {
  1230. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1231. return 0;
  1232. }
  1233. if(heal_type == "power")
  1234. {
  1235. if(current_value)
  1236. {
  1237. if(caster_value)
  1238. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1239. else
  1240. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1241. }
  1242. else
  1243. {
  1244. if(caster_value)
  1245. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1246. else
  1247. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1248. }
  1249. }
  1250. else
  1251. {
  1252. if(current_value)
  1253. {
  1254. if(caster_value)
  1255. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1256. else
  1257. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1258. }
  1259. else
  1260. {
  1261. if(caster_value)
  1262. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1263. else
  1264. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1265. }
  1266. }
  1267. bool success = false;
  1268. luaspell->resisted = false;
  1269. if (target) {
  1270. float distance = caster->GetDistance(target, true);
  1271. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1272. success = true;
  1273. }
  1274. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1275. Spawn* target = 0;
  1276. ZoneServer* zone = luaspell->caster->GetZone();
  1277. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1278. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1279. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1280. float distance = caster->GetDistance(target, true);
  1281. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1282. }
  1283. }
  1284. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1285. success = true;
  1286. }
  1287. if (success) {
  1288. if (caster->GetZone())
  1289. caster->GetZone()->TriggerCharSheetTimer();
  1290. }
  1291. }
  1292. return 0;
  1293. }
  1294. int EQ2Emu_lua_AddItem(lua_State* state) {
  1295. if (!lua_interface)
  1296. return 0;
  1297. Spawn* spawn = lua_interface->GetSpawn(state);
  1298. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1299. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1300. // default of 1 quantity to add
  1301. if (quantity == 0)
  1302. quantity = 1;
  1303. if (spawn && spawn->IsPlayer()) {
  1304. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1305. if (client && item_id > 0) {
  1306. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1307. return 1;
  1308. }
  1309. }
  1310. lua_interface->SetBooleanValue(state, false);
  1311. return 1;
  1312. }
  1313. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1314. if (!lua_interface)
  1315. return 0;
  1316. Spawn* spawn = lua_interface->GetSpawn(state);
  1317. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1318. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1319. string location = lua_interface->GetStringValue(state, 4);
  1320. if (spawn && spawn->IsPlayer()) {
  1321. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1322. if (client && item_id > 0) {
  1323. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1324. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1325. else
  1326. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1327. if (send_messages) {
  1328. Item* item = master_item_list.GetItem(item_id);
  1329. if (item) {
  1330. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1331. string popup_text = "You receive " + item->name;
  1332. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1333. }
  1334. }
  1335. return 1;
  1336. }
  1337. }
  1338. lua_interface->SetBooleanValue(state, false);
  1339. return 1;
  1340. }
  1341. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1342. Spawn* spawn = lua_interface->GetSpawn(state);
  1343. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1344. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1345. // default of 1 to remove
  1346. if (quantity == 0)
  1347. quantity = 1;
  1348. Client* client;
  1349. Item* item;
  1350. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1351. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1352. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1353. if (client->RemoveItem(item, quantity)) {
  1354. lua_interface->SetBooleanValue(state, true);
  1355. return 1;
  1356. }
  1357. }
  1358. }
  1359. }
  1360. lua_interface->SetBooleanValue(state, false);
  1361. return 1;
  1362. }
  1363. int EQ2Emu_lua_HasItem(lua_State* state) {
  1364. Spawn* player = lua_interface->GetSpawn(state);
  1365. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1366. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1367. if (player && player->IsPlayer()) {
  1368. bool hasItem = false;
  1369. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1370. if (!hasItem)
  1371. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1372. lua_interface->SetBooleanValue(state, hasItem);
  1373. return 1;
  1374. }
  1375. lua_interface->SetBooleanValue(state, false);
  1376. return 1;
  1377. }
  1378. int EQ2Emu_lua_Spawn(lua_State* state) {
  1379. if (!lua_interface)
  1380. return 0;
  1381. ZoneServer* zone = lua_interface->GetZone(state);
  1382. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1383. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1384. float x = lua_interface->GetFloatValue(state, 4);
  1385. float y = lua_interface->GetFloatValue(state, 5);
  1386. float z = lua_interface->GetFloatValue(state, 6);
  1387. float heading = lua_interface->GetFloatValue(state, 7);
  1388. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1389. Spawn* spawn = zone->GetSpawn(spawn_id);
  1390. if (!spawn)
  1391. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1392. else {
  1393. spawn->SetX(x);
  1394. spawn->SetZ(z);
  1395. spawn->SetY(y,true,true);
  1396. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1397. spawn->SetHeading(heading);
  1398. if (restricted_npc)
  1399. spawn->AddAllowAccessSpawn(spawn);
  1400. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1401. bool scriptActive = false;
  1402. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1403. scriptActive = true;
  1404. spawn->SetSpawnScript(string(spawn_script));
  1405. }
  1406. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1407. zone->AddSpawn(spawn);
  1408. if (scriptActive) {
  1409. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1410. }
  1411. lua_interface->SetSpawnValue(state, spawn);
  1412. return 1;
  1413. }
  1414. }
  1415. else {
  1416. string output = "Invalid paramaters to LUA Spawn command: \n";
  1417. if (!zone)
  1418. output = output.append("\t").append("Missing zone reference. \n");
  1419. if (spawn_id == 0)
  1420. output = output.append("\t").append("Missing spawn_id.");
  1421. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1422. }
  1423. return 0;
  1424. }
  1425. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1426. if (!lua_interface)
  1427. return 0;
  1428. ZoneServer* zone = lua_interface->GetZone(state);
  1429. if (zone) {
  1430. lua_interface->SetStringValue(state, zone->GetZoneName());
  1431. return 1;
  1432. }
  1433. return 0;
  1434. }
  1435. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1436. if (!lua_interface)
  1437. return 0;
  1438. ZoneServer* zone = lua_interface->GetZone(state);
  1439. if (zone) {
  1440. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1441. return 1;
  1442. }
  1443. return 0;
  1444. }
  1445. int EQ2Emu_lua_GetZone(lua_State* state) {
  1446. if (!lua_interface)
  1447. return 0;
  1448. int32 zone_id = lua_interface->GetInt32Value(state);
  1449. ZoneServer* zone = 0;
  1450. if (zone_id > 0)
  1451. zone = zone_list.Get(zone_id);
  1452. else {
  1453. string zone_name = lua_interface->GetStringValue(state);
  1454. if (zone_name.length() > 0) {
  1455. zone = zone_list.Get(zone_name.c_str());
  1456. }
  1457. else {
  1458. Spawn* spawn = lua_interface->GetSpawn(state);
  1459. if (spawn)
  1460. zone = spawn->GetZone();
  1461. }
  1462. }
  1463. if (zone) {
  1464. lua_interface->SetZoneValue(state, zone);
  1465. return 1;
  1466. }
  1467. return 0;
  1468. }
  1469. int EQ2Emu_lua_AddHate(lua_State* state) {
  1470. Spawn* entity = lua_interface->GetSpawn(state);
  1471. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1472. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1473. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1474. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1475. if (entity && entity->IsEntity() && amount != 0) {
  1476. if (luaspell) {
  1477. ZoneServer* zone = luaspell->caster->GetZone();
  1478. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1479. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1480. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1481. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1482. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1483. if (send_packet)
  1484. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1485. }
  1486. }
  1487. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1488. }
  1489. else if (npc && npc->IsNPC() && npc->GetZone())
  1490. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1491. }
  1492. return 0;
  1493. }
  1494. int EQ2Emu_lua_Zone(lua_State* state) {
  1495. if (!lua_interface)
  1496. return 0;
  1497. ZoneServer* zone = lua_interface->GetZone(state);
  1498. Spawn* player = lua_interface->GetSpawn(state, 2);
  1499. Client* client = 0;
  1500. if (player && player->IsPlayer())
  1501. client = player->GetZone()->GetClientBySpawn(player);
  1502. float x = lua_interface->GetFloatValue(state, 3);
  1503. float y = lua_interface->GetFloatValue(state, 4);
  1504. float z = lua_interface->GetFloatValue(state, 5);
  1505. float heading = lua_interface->GetFloatValue(state, 6);
  1506. if (zone && client) {
  1507. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1508. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1509. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1510. {
  1511. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1512. return 0;
  1513. }
  1514. if (x != 0 || y != 0 || z != 0) {
  1515. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1516. player->SetX(x);
  1517. player->SetY(y);
  1518. player->SetZ(z);
  1519. player->SetHeading(heading);
  1520. client->Zone(zone->GetZoneName(), false);
  1521. }
  1522. else
  1523. client->Zone(zone->GetZoneName());
  1524. }
  1525. else
  1526. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1527. return 0;
  1528. }
  1529. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1530. if (!lua_interface)
  1531. return 0;
  1532. Spawn* spawn = lua_interface->GetSpawn(state);
  1533. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1534. if (spawn && spawn2)
  1535. spawn->AddAllowAccessSpawn(spawn2);
  1536. return 0;
  1537. }
  1538. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1539. if (!lua_interface)
  1540. return 0;
  1541. Spawn* target = lua_interface->GetSpawn(state);
  1542. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1543. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1544. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1545. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1546. if (!target) {
  1547. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1548. return 0;
  1549. }
  1550. if (!target->IsEntity()) {
  1551. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1552. return 0;
  1553. }
  1554. if (spell_id <= 0) {
  1555. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1556. return 0;
  1557. }
  1558. if (caster && !caster->IsEntity()) {
  1559. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1560. return 0;
  1561. }
  1562. if (spell_tier == 0)
  1563. spell_tier = 1;
  1564. if (!caster)
  1565. caster = target;
  1566. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1567. return 0;
  1568. }
  1569. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1570. if (!lua_interface)
  1571. return 0;
  1572. Spawn* target = lua_interface->GetSpawn(state);
  1573. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1574. if (!luaspell)
  1575. return 0;
  1576. Spawn* caster = luaspell->caster;
  1577. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1578. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1579. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1580. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1581. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1582. //lua_interface->ResetFunctionStack(state);
  1583. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1584. vector<int16> faction_req;
  1585. vector<int16> race_req;
  1586. int32 class_req = 0;
  1587. int32 i = 0;
  1588. int8 f = 0;
  1589. int8 r = 0;
  1590. while ((class_id = lua_interface->GetInt32Value(state, 7 + 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. if (caster && caster->IsEntity()) {
  1605. bool race_match = false;
  1606. bool success = false;
  1607. luaspell->resisted = false;
  1608. if (luaspell->targets.size() > 0) {
  1609. ZoneServer* zone = luaspell->caster->GetZone();
  1610. Spawn* target = 0;
  1611. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1612. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1613. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1614. if (race_req.size() > 0) {
  1615. for (int8 i = 0; i < race_req.size(); i++) {
  1616. if (target->GetLuaRaceId() == race_req[i]) {
  1617. race_match = true;
  1618. }
  1619. }
  1620. }
  1621. else
  1622. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1623. if (race_match == true) {
  1624. float distance = caster->GetDistance(target, true);
  1625. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1626. }
  1627. }
  1628. }
  1629. success = true;
  1630. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1631. }
  1632. else if (target) {
  1633. //check class and race/faction here
  1634. if (race_req.size() > 0) {
  1635. for (int8 i = 0; i < race_req.size(); i++) {
  1636. if (target->GetLuaRaceId() == race_req[i]) {
  1637. race_match = true;
  1638. }
  1639. }
  1640. }
  1641. else
  1642. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1643. if (race_match == true) {
  1644. float distance = caster->GetDistance(target, true);
  1645. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1646. success = true;
  1647. }
  1648. }
  1649. if (success) {
  1650. Spell* spell = luaspell->spell;
  1651. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1652. ((Player*)caster)->InCombat(true);
  1653. if (caster->GetZone())
  1654. caster->GetZone()->TriggerCharSheetTimer();
  1655. }
  1656. }
  1657. }
  1658. return 0;
  1659. }
  1660. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1661. if (!lua_interface)
  1662. return 0;
  1663. Spawn* spawn = lua_interface->GetSpawn(state);
  1664. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1665. lua_interface->ResetFunctionStack(state);
  1666. if (spawn && value != 0) {
  1667. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1668. spawn->SetPower(spawn->GetTotalPower());
  1669. else
  1670. spawn->SetPower(spawn->GetPower() + value);
  1671. }
  1672. return 0;
  1673. }
  1674. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1675. if (!lua_interface)
  1676. return 0;
  1677. Spawn* spawn = lua_interface->GetSpawn(state);
  1678. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1679. lua_interface->ResetFunctionStack(state);
  1680. if (spawn && value != 0) {
  1681. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1682. spawn->SetHP(spawn->GetTotalHP());
  1683. else
  1684. spawn->SetHP(spawn->GetHP() + value);
  1685. }
  1686. return 0;
  1687. }
  1688. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1689. if (!lua_interface)
  1690. return 0;
  1691. Spawn* spawn = lua_interface->GetSpawn(state);
  1692. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1693. lua_interface->ResetFunctionStack(state);
  1694. if (spawn && value != 0) {
  1695. spawn->SetPower(spawn->GetPower() + value);
  1696. if (value > spawn->GetTotalHPBase())
  1697. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1698. }
  1699. return 0;
  1700. }
  1701. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1702. if (!lua_interface)
  1703. return 0;
  1704. Spawn* spawn = lua_interface->GetSpawn(state);
  1705. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1706. lua_interface->ResetFunctionStack(state);
  1707. if (spawn && value != 0) {
  1708. spawn->SetHP(spawn->GetHP() + value);
  1709. if (value > spawn->GetTotalHPBase())
  1710. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1711. }
  1712. return 0;
  1713. }
  1714. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1715. if (!lua_interface)
  1716. return 0;
  1717. Spawn* spawn = lua_interface->GetSpawn(state);
  1718. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1719. lua_interface->ResetFunctionStack(state);
  1720. if (spawn) {
  1721. spawn->SetHP(value);
  1722. if (value > spawn->GetTotalHPBase())
  1723. spawn->SetTotalHP(value);
  1724. }
  1725. return 0;
  1726. }
  1727. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1728. if (!lua_interface)
  1729. return 0;
  1730. Spawn* spawn = lua_interface->GetSpawn(state);
  1731. float value = lua_interface->GetFloatValue(state, 2);
  1732. lua_interface->ResetFunctionStack(state);
  1733. if (spawn && spawn->IsEntity() && value > 0)
  1734. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1735. if (spawn->IsPlayer())
  1736. ((Player*)spawn)->SetCharSheetChanged(true);
  1737. return 0;
  1738. }
  1739. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1740. if (!lua_interface)
  1741. return 0;
  1742. Spawn* spawn = lua_interface->GetSpawn(state);
  1743. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1744. lua_interface->ResetFunctionStack(state);
  1745. if (spawn && spawn->IsEntity() && value > 0)
  1746. ((Entity*)spawn)->SetTotalHPBase(value);
  1747. return 0;
  1748. }
  1749. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1750. if (!lua_interface)
  1751. return 0;
  1752. Spawn* spawn = lua_interface->GetSpawn(state);
  1753. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1754. lua_interface->ResetFunctionStack(state);
  1755. if (spawn && value > 0) {
  1756. spawn->SetPower(value);
  1757. if (value > spawn->GetTotalPowerBase())
  1758. spawn->SetTotalPower(value);
  1759. }
  1760. return 0;
  1761. }
  1762. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1763. if (!lua_interface)
  1764. return 0;
  1765. Spawn* spawn = lua_interface->GetSpawn(state);
  1766. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1767. lua_interface->ResetFunctionStack(state);
  1768. if (spawn && spawn->IsEntity() && value > 0)
  1769. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1770. return 0;
  1771. }
  1772. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1773. if (!lua_interface)
  1774. return 0;
  1775. Spawn* spawn = lua_interface->GetSpawn(state);
  1776. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1777. lua_interface->ResetFunctionStack(state);
  1778. if (spawn && spawn->IsEntity() && value > 0)
  1779. ((Entity*)spawn)->SetTotalPowerBase(value);
  1780. return 0;
  1781. }
  1782. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1783. if (!lua_interface)
  1784. return 0;
  1785. Spawn* spawn = lua_interface->GetSpawn(state);
  1786. float x = lua_interface->GetFloatValue(state, 2);
  1787. float y = lua_interface->GetFloatValue(state, 3);
  1788. float z = lua_interface->GetFloatValue(state, 4);
  1789. float heading = lua_interface->GetFloatValue(state, 5);
  1790. lua_interface->ResetFunctionStack(state);
  1791. if (spawn) {
  1792. spawn->SetX(x);
  1793. spawn->SetY(y);
  1794. spawn->SetZ(z);
  1795. if (heading != 0)
  1796. spawn->SetHeading(heading);
  1797. spawn->SetSpawnOrigX(spawn->GetX());
  1798. spawn->SetSpawnOrigY(spawn->GetY());
  1799. spawn->SetSpawnOrigZ(spawn->GetZ());
  1800. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1801. if (spawn->IsPlayer()) {
  1802. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1803. if (client) {
  1804. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1805. client->QueuePacket(packet);
  1806. }
  1807. }
  1808. }
  1809. return 0;
  1810. }
  1811. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1812. if (!lua_interface)
  1813. return 0;
  1814. Spawn* spawn = lua_interface->GetSpawn(state);
  1815. float value = lua_interface->GetFloatValue(state, 2);
  1816. lua_interface->ResetFunctionStack(state);
  1817. if (spawn) {
  1818. spawn->SetHeading(value);
  1819. if (spawn->IsPlayer()) {
  1820. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1821. if (client) {
  1822. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1823. client->QueuePacket(packet);
  1824. }
  1825. }
  1826. }
  1827. return 0;
  1828. }
  1829. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1830. if (!lua_interface)
  1831. return 0;
  1832. Spawn* spawn = lua_interface->GetSpawn(state);
  1833. int16 value = lua_interface->GetInt16Value(state, 2);
  1834. lua_interface->ResetFunctionStack(state);
  1835. if (spawn)
  1836. spawn->SetModelType(value);
  1837. return 0;
  1838. }
  1839. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1840. if (!lua_interface)
  1841. return 0;
  1842. Spawn* spawn = lua_interface->GetSpawn(state);
  1843. int8 value = lua_interface->GetInt8Value(state, 2);
  1844. lua_interface->ResetFunctionStack(state);
  1845. if (spawn) {
  1846. if (spawn->IsPlayer())
  1847. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1848. else
  1849. spawn->SetAdventureClass(value);
  1850. }
  1851. return 0;
  1852. }
  1853. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1854. if (!lua_interface)
  1855. return 0;
  1856. Spawn* spawn = lua_interface->GetSpawn(state);
  1857. int8 value = lua_interface->GetInt8Value(state, 2);
  1858. lua_interface->ResetFunctionStack(state);
  1859. if (spawn) {
  1860. spawn->SetTradeskillClass(value);
  1861. if (spawn->IsEntity()) {
  1862. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1863. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1864. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1865. }
  1866. if (spawn->IsPlayer())
  1867. ((Player*)spawn)->SetCharSheetChanged(true);
  1868. }
  1869. return 0;
  1870. }
  1871. int EQ2Emu_lua_SetMount(lua_State* state) {
  1872. if (!lua_interface)
  1873. return 0;
  1874. Spawn* spawn = lua_interface->GetSpawn(state);
  1875. int16 value = lua_interface->GetInt16Value(state, 2);
  1876. if (spawn && spawn->IsEntity()) {
  1877. ((Entity*)spawn)->SetMount(value);
  1878. EQ2_Color color;
  1879. color.red = 255;
  1880. color.green = 255;
  1881. color.blue = 255;
  1882. ((Entity*)spawn)->SetMountColor(&color);
  1883. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1884. }
  1885. return 0;
  1886. }
  1887. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1888. if (!lua_interface)
  1889. return 0;
  1890. Spawn* spawn = lua_interface->GetSpawn(state);
  1891. EQ2_Color mount_color;
  1892. EQ2_Color saddle_color;
  1893. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1894. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1895. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1896. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1897. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1898. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1899. if (spawn && spawn->IsEntity()) {
  1900. ((Entity*)spawn)->SetMountColor(&mount_color);
  1901. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1902. }
  1903. return 0;
  1904. }
  1905. int EQ2Emu_lua_GetMount(lua_State* state) {
  1906. if (!lua_interface)
  1907. return 0;
  1908. Spawn* spawn = lua_interface->GetSpawn(state);
  1909. if (spawn && spawn->IsEntity()) {
  1910. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1911. return 1;
  1912. }
  1913. return 0;
  1914. }
  1915. int EQ2Emu_lua_GetRace(lua_State* state) {
  1916. if (!lua_interface)
  1917. return 0;
  1918. Spawn* spawn = lua_interface->GetSpawn(state);
  1919. if (spawn)
  1920. {
  1921. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1922. lua_interface->SetInt32Value(state, spawn->GetRace());
  1923. return 1;
  1924. }
  1925. return 0;
  1926. }
  1927. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1928. if (!lua_interface)
  1929. return 0;
  1930. Spawn* spawn = lua_interface->GetSpawn(state);
  1931. if (spawn) {
  1932. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1933. return 1;
  1934. }
  1935. return 0;
  1936. }
  1937. int EQ2Emu_lua_GetClass(lua_State* state) {
  1938. Spawn* spawn = lua_interface->GetSpawn(state);
  1939. if (spawn) {
  1940. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1941. return 1;
  1942. }
  1943. return 0;
  1944. }
  1945. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1946. Spawn* spawn = lua_interface->GetSpawn(state);
  1947. if (spawn) {
  1948. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1949. return 1;
  1950. }
  1951. return 0;
  1952. }
  1953. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1954. if (!lua_interface)
  1955. return 0;
  1956. Spawn* spawn = lua_interface->GetSpawn(state);
  1957. float value = lua_interface->GetFloatValue(state, 2);
  1958. lua_interface->ResetFunctionStack(state);
  1959. if (spawn) {
  1960. spawn->SetSpeed(value);
  1961. ((Entity*)spawn)->SetSpeed(value);
  1962. if (spawn->IsPlayer()) {
  1963. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1964. if (client) {
  1965. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1966. if (packet) {
  1967. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1968. packet->setDataByName("speed", value);
  1969. packet->setDataByName("size", 0.51);
  1970. EQ2Packet* app = packet->serialize();
  1971. client->QueuePacket(app);
  1972. safe_delete(packet);
  1973. }
  1974. }
  1975. }
  1976. }
  1977. return 0;
  1978. }
  1979. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1980. if (!lua_interface)
  1981. return 0;
  1982. Spawn* spawn = lua_interface->GetSpawn(state);
  1983. const int16 type = lua_interface->GetInt16Value(state, 2);
  1984. const float value = lua_interface->GetFloatValue(state, 3);
  1985. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1986. int64 class_req = 0;
  1987. int32 class_id = 0;
  1988. vector<int16> faction_req;
  1989. vector<int16> race_req;
  1990. int32 i = 0;
  1991. int8 f = 0;
  1992. int8 r = 0;
  1993. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1994. if (class_id < 100) {
  1995. class_req += pow(2.0, double(class_id - 1));
  1996. }
  1997. else if (class_id > 100 && class_id < 1000) {
  1998. race_req.push_back(class_id);
  1999. r++;
  2000. }
  2001. else {
  2002. faction_req.push_back(class_id);
  2003. f++;
  2004. }
  2005. i++;
  2006. }
  2007. if (value != 0 && type >= 0) {
  2008. if (luaspell && luaspell->spell && luaspell->caster) {
  2009. ZoneServer* zone = luaspell->caster->GetZone();
  2010. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2011. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2012. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2013. if (target) {
  2014. if (target->IsPlayer()) {
  2015. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2016. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2017. if (((Player*)target)->GetGroupMemberInfo())
  2018. ((Player*)target)->UpdateGroupMemberInfo();
  2019. ((Player*)target)->SetCharSheetChanged(true);
  2020. }
  2021. else if (target->IsNPC())
  2022. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2023. else
  2024. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2025. }
  2026. }
  2027. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2028. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2029. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2030. }
  2031. else if (spawn && spawn->IsEntity()) {
  2032. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2033. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2034. if (spawn->IsPlayer())
  2035. ((Player*)spawn)->SetCharSheetChanged(true);
  2036. }
  2037. else
  2038. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2039. }
  2040. else
  2041. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2042. return 0;
  2043. }
  2044. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2045. if (!lua_interface)
  2046. return 0;
  2047. Spawn* spawn = lua_interface->GetSpawn(state);
  2048. int16 type = lua_interface->GetInt16Value(state, 2);
  2049. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2050. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2051. if (!spawn) {
  2052. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2053. return 0;
  2054. }
  2055. if (!spawn->IsEntity()) {
  2056. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2057. return 0;
  2058. }
  2059. if (value == 0) {
  2060. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2061. return 0;
  2062. }
  2063. if (!luaspell || !luaspell->spell) {
  2064. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2065. return 0;
  2066. }
  2067. int32 class_req = 0;
  2068. vector<int16> faction_req;
  2069. vector<int16> race_req;
  2070. int32 class_id = 0;
  2071. int32 i = 0;
  2072. int8 f = 0;
  2073. int8 r = 0;
  2074. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2075. if (class_id < 100) {
  2076. class_req += pow(2.0, double(class_id - 1));
  2077. }
  2078. else if (class_id > 100 && class_id < 1000) {
  2079. race_req.push_back(class_id);
  2080. r++;
  2081. }
  2082. else {
  2083. faction_req.push_back(class_id);
  2084. f++;
  2085. }
  2086. i++;
  2087. }
  2088. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2089. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2090. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2091. if (spawn->IsPlayer())
  2092. ((Player*)spawn)->SetCharSheetChanged(true);
  2093. return 0;
  2094. }
  2095. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2096. if (!lua_interface)
  2097. return 0;
  2098. Spawn* spawn = lua_interface->GetSpawn(state);
  2099. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2100. if (!spawn) {
  2101. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2102. return 0;
  2103. }
  2104. if (!spawn->IsEntity()) {
  2105. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2106. return 0;
  2107. }
  2108. if (!luaspell || !luaspell->spell) {
  2109. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2110. return 0;
  2111. }
  2112. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2113. if (spawn->IsPlayer())
  2114. ((Player*)spawn)->SetCharSheetChanged(true);
  2115. return 0;
  2116. }
  2117. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2118. if (!lua_interface)
  2119. return 0;
  2120. Spawn* spawn = lua_interface->GetSpawn(state);
  2121. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2122. if (luaspell && luaspell->spell) {
  2123. ZoneServer* zone = luaspell->caster->GetZone();
  2124. Spawn* target = 0;
  2125. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2126. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2127. target = zone->GetSpawnByID(luaspell->targets[i]);
  2128. if (target && target->IsEntity()) {
  2129. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2130. if (target->IsPlayer())
  2131. ((Player*)target)->SetCharSheetChanged(true);
  2132. }
  2133. }
  2134. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2135. }
  2136. else if (spawn && spawn->IsEntity()) {
  2137. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2138. if (spawn->IsPlayer())
  2139. ((Player*)spawn)->SetCharSheetChanged(true);
  2140. }
  2141. return 0;
  2142. }
  2143. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2144. if (!lua_interface)
  2145. return 0;
  2146. Spawn* spawn = lua_interface->GetSpawn(state);
  2147. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2148. float value = lua_interface->GetFloatValue(state, 3);
  2149. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2150. if (value != 0) {
  2151. int32 spell_id = 0;
  2152. if (luaspell && luaspell->spell && luaspell->caster) {
  2153. spell_id = luaspell->spell->GetSpellID();
  2154. ZoneServer* zone = luaspell->caster->GetZone();
  2155. Spawn* target = 0;
  2156. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2157. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2158. target = zone->GetSpawnByID(luaspell->targets[i]);
  2159. if (target && target->Alive()) {
  2160. if (target->IsPlayer()) {
  2161. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2162. Client* client = target->GetZone()->GetClientBySpawn(target);
  2163. if (client) {
  2164. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2165. if (packet)
  2166. client->QueuePacket(packet);
  2167. }
  2168. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2169. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2170. }
  2171. else if (target->IsNPC()) {
  2172. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2173. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2174. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2175. }
  2176. else
  2177. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2178. }
  2179. }
  2180. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2181. }
  2182. else if (spawn) {
  2183. if (spawn->IsPlayer()) {
  2184. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2185. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2186. if (client) {
  2187. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2188. if (packet)
  2189. client->QueuePacket(packet);
  2190. }
  2191. }
  2192. else if (spawn->IsNPC())
  2193. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2194. else
  2195. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2196. }
  2197. }
  2198. else
  2199. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2200. return 0;
  2201. }
  2202. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2203. if (!lua_interface)
  2204. return 0;
  2205. Spawn* spawn = lua_interface->GetSpawn(state);
  2206. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2207. if (spawn && spawn->IsPlayer()) {
  2208. int32 spell_id = 0;
  2209. if (luaspell && luaspell->spell) {
  2210. spell_id = luaspell->spell->GetSpellID();
  2211. ZoneServer* zone = luaspell->caster->GetZone();
  2212. Spawn* target = 0;
  2213. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2214. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2215. target = zone->GetSpawnByID(luaspell->targets[i]);
  2216. if (target) {
  2217. if (target->IsPlayer()) {
  2218. ((Player*)target)->RemoveSkillBonus(spell_id);
  2219. Client* client = target->GetZone()->GetClientBySpawn(target);
  2220. if (client) {
  2221. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2222. if (packet)
  2223. client->QueuePacket(packet);
  2224. }
  2225. }
  2226. else if (target->IsNPC())
  2227. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2228. else
  2229. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2230. }
  2231. }
  2232. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2233. }
  2234. else if (spawn) {
  2235. if (spawn->IsPlayer()) {
  2236. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2237. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2238. if (client) {
  2239. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2240. if (packet)
  2241. client->QueuePacket(packet);
  2242. }
  2243. }
  2244. else if (spawn->IsNPC())
  2245. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2246. else
  2247. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2248. }
  2249. }
  2250. return 0;
  2251. }
  2252. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2253. if (!lua_interface)
  2254. return 0;
  2255. Spawn* spawn = lua_interface->GetSpawn(state);
  2256. int8 type = lua_interface->GetInt32Value(state, 2);
  2257. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2258. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2259. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2260. ZoneServer* zone = luaspell->caster->GetZone();
  2261. Spawn* target = 0;
  2262. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2263. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2264. target = zone->GetSpawnByID(luaspell->targets[i]);
  2265. if (target && target->IsEntity()) {
  2266. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2267. ((Entity*)target)->AddMezSpell(luaspell);
  2268. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2269. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2270. if (target->IsNPC())
  2271. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2272. }
  2273. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2274. ((Entity*)target)->AddStifleSpell(luaspell);
  2275. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2276. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2277. if (target->IsNPC())
  2278. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2279. }
  2280. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2281. ((Entity*)target)->AddDazeSpell(luaspell);
  2282. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2283. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2284. if (target->IsNPC())
  2285. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2286. }
  2287. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2288. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2289. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2290. ((Entity*)target)->AddStunSpell(luaspell);
  2291. if (target->IsNPC())
  2292. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2293. }
  2294. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2295. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2296. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2297. ((Entity*)target)->AddRootSpell(luaspell);
  2298. if (target->IsNPC())
  2299. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2300. }
  2301. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2302. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2303. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2304. ((Entity*)target)->AddFearSpell(luaspell);
  2305. if (target->IsNPC())
  2306. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2307. }
  2308. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2309. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2310. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2311. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2312. }
  2313. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2314. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2315. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2316. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2317. }
  2318. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2319. ((Entity*)target)->AddSnareSpell(luaspell);
  2320. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2321. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2322. if (target->IsNPC())
  2323. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2324. }
  2325. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2326. ((Entity*)target)->AddFlightSpell(luaspell);
  2327. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2328. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2329. }
  2330. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2331. ((Entity*)target)->AddGlideSpell(luaspell);
  2332. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2333. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2334. }
  2335. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2336. ((Entity*)target)->AddSafefallSpell(luaspell);
  2337. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2338. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2339. }
  2340. else
  2341. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2342. }
  2343. else
  2344. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2345. }
  2346. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2347. }
  2348. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2349. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2350. ((Entity*)spawn)->AddMezSpell(luaspell);
  2351. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2352. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2353. }
  2354. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2355. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2356. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2357. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2358. }
  2359. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2360. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2361. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2362. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2363. }
  2364. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2365. ((Entity*)spawn)->AddStunSpell(luaspell);
  2366. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2367. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2368. }
  2369. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2370. ((Entity*)spawn)->AddRootSpell(luaspell);
  2371. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2372. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2373. }
  2374. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2375. ((Entity*)spawn)->AddFearSpell(luaspell);
  2376. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2377. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2378. }
  2379. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2380. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2381. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2382. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2383. }
  2384. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2385. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2386. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2387. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2388. }
  2389. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2390. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2391. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2392. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2393. }
  2394. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2395. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2396. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2397. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2398. }
  2399. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2400. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2401. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2402. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2403. }
  2404. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2405. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2406. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2407. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2408. }
  2409. else
  2410. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2411. }
  2412. else
  2413. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2414. return 0;
  2415. }
  2416. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2417. if (!lua_interface)
  2418. return 0;
  2419. Spawn* spawn = lua_interface->GetSpawn(state);
  2420. int8 type = lua_interface->GetInt8Value(state, 2);
  2421. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2422. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2423. if (spawn && spawn->IsEntity()) {
  2424. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2425. ZoneServer* zone = luaspell->caster->GetZone();
  2426. Spawn* target = 0;
  2427. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2428. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2429. target = zone->GetSpawnByID(luaspell->targets[i]);
  2430. if (target) {
  2431. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2432. ((Entity*)target)->RemoveMezSpell(luaspell);
  2433. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2434. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2435. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2436. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2437. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2438. ((Entity*)target)->RemoveStunSpell(luaspell);
  2439. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2440. ((Entity*)target)->RemoveRootSpell(luaspell);
  2441. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2442. ((Entity*)target)->RemoveFearSpell(luaspell);
  2443. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2444. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2445. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2446. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2447. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2448. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2449. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2450. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2451. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2452. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2453. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2454. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2455. else
  2456. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2457. }
  2458. }
  2459. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2460. }
  2461. else if (only_remove_spawn) {
  2462. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2463. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2464. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2465. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2466. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2467. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2468. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2469. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2470. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2471. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2472. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2473. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2474. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2475. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2476. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2477. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2478. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2479. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2480. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2481. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2482. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2483. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2484. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2485. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2486. else
  2487. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2488. }
  2489. }
  2490. return 0;
  2491. }
  2492. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2493. if (!lua_interface)
  2494. return 0;
  2495. Spawn* spawn = lua_interface->GetSpawn(state);
  2496. int8 type = lua_interface->GetInt8Value(state, 2);
  2497. bool hasEffect = false;
  2498. if (!spawn)
  2499. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2500. else if (!spawn->IsEntity())
  2501. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2502. else if (type < CONTROL_MAX_EFFECTS)
  2503. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2504. else
  2505. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2506. lua_interface->SetBooleanValue(state, hasEffect);
  2507. return 1;
  2508. }
  2509. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2510. if (!lua_interface)
  2511. return 0;
  2512. Spawn* spawn = lua_interface->GetSpawn(state);
  2513. float distance = 0.0f;
  2514. if (!spawn)
  2515. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2516. else if (!spawn->IsNPC())
  2517. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2518. else
  2519. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2520. lua_interface->SetFloatValue(state, distance);
  2521. return 1;
  2522. }
  2523. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2524. if (!lua_interface)
  2525. return 0;
  2526. Spawn* spawn = lua_interface->GetSpawn(state);
  2527. float distance = 0.0f;
  2528. if (!spawn)
  2529. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2530. else if (!spawn->IsNPC())
  2531. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2532. else
  2533. distance = ((NPC*)spawn)->GetAggroRadius();
  2534. lua_interface->SetFloatValue(state, distance);
  2535. return 1;
  2536. }
  2537. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2538. if (!lua_interface)
  2539. return 0;
  2540. Spawn* spawn = lua_interface->GetSpawn(state);
  2541. float distance = lua_interface->GetFloatValue(state, 2);
  2542. bool override = lua_interface->GetBooleanValue(state, 3);
  2543. bool result = false;
  2544. lua_interface->ResetFunctionStack(state);
  2545. if (!spawn)
  2546. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2547. else if (!spawn->IsNPC())
  2548. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2549. else
  2550. {
  2551. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2552. result = true;
  2553. }
  2554. lua_interface->SetBooleanValue(state, result);
  2555. return 1;
  2556. }
  2557. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2558. if (!lua_interface)
  2559. return 0;
  2560. Spawn* spawn = lua_interface->GetSpawn(state);
  2561. int16 value = lua_interface->GetInt16Value(state, 2);
  2562. if (spawn && spawn->IsEntity()) {
  2563. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2564. if (spawn->IsPlayer())
  2565. ((Player*)spawn)->SetCharSheetChanged(true);
  2566. }
  2567. return 0;
  2568. }
  2569. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2570. if (!lua_interface)
  2571. return 0;
  2572. Spawn* spawn = lua_interface->GetSpawn(state);
  2573. int16 value = lua_interface->GetInt16Value(state, 2);
  2574. if (spawn && spawn->IsEntity()) {
  2575. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2576. if (spawn->IsPlayer())
  2577. ((Player*)spawn)->SetCharSheetChanged(true);
  2578. }
  2579. return 0;
  2580. }
  2581. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2582. if (!lua_interface)
  2583. return 0;
  2584. Spawn* spawn = lua_interface->GetSpawn(state);
  2585. int16 value = lua_interface->GetInt16Value(state, 2);
  2586. if (spawn && spawn->IsEntity()) {
  2587. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2588. if (spawn->IsPlayer())
  2589. ((Player*)spawn)->SetCharSheetChanged(true);
  2590. }
  2591. return 0;
  2592. }
  2593. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2594. if (!lua_interface)
  2595. return 0;
  2596. Spawn* spawn = lua_interface->GetSpawn(state);
  2597. int16 value = lua_interface->GetInt16Value(state, 2);
  2598. if (spawn && spawn->IsEntity()) {
  2599. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2600. if (spawn->IsPlayer())
  2601. ((Player*)spawn)->SetCharSheetChanged(true);
  2602. }
  2603. return 0;
  2604. }
  2605. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2606. if (!lua_interface)
  2607. return 0;
  2608. Spawn* spawn = lua_interface->GetSpawn(state);
  2609. int16 value = lua_interface->GetInt16Value(state, 2);
  2610. if (spawn && spawn->IsEntity()) {
  2611. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2612. if (spawn->IsPlayer())
  2613. ((Player*)spawn)->SetCharSheetChanged(true);
  2614. }
  2615. return 0;
  2616. }
  2617. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2618. if (!lua_interface)
  2619. return 0;
  2620. Spawn* spawn = lua_interface->GetSpawn(state);
  2621. int8 value = lua_interface->GetInt8Value(state, 2);
  2622. if (spawn && spawn->IsEntity()) {
  2623. ((Entity*)spawn)->SetDeity(value);
  2624. if (spawn->IsPlayer())
  2625. ((Player*)spawn)->SetCharSheetChanged(true);
  2626. }
  2627. lua_interface->ResetFunctionStack(state);
  2628. return 0;
  2629. }
  2630. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2631. if (!lua_interface)
  2632. return 0;
  2633. Spawn* spawn = lua_interface->GetSpawn(state);
  2634. if (spawn && spawn->IsEntity()) {
  2635. int8 deity = ((Entity*)spawn)->GetDeity();
  2636. lua_interface->SetInt32Value(state, deity);
  2637. return 1;
  2638. }
  2639. return 0;
  2640. }
  2641. int EQ2Emu_lua_SetInt(lua_State* state) {
  2642. if (!lua_interface)
  2643. return 0;
  2644. Spawn* spawn = lua_interface->GetSpawn(state);
  2645. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2646. if (spawn && spawn->IsEntity()) {
  2647. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2648. if (spawn->IsPlayer())
  2649. ((Player*)spawn)->SetCharSheetChanged(true);
  2650. }
  2651. return 0;
  2652. }
  2653. int EQ2Emu_lua_SetWis(lua_State* state) {
  2654. if (!lua_interface)
  2655. return 0;
  2656. Spawn* spawn = lua_interface->GetSpawn(state);
  2657. float value = lua_interface->GetFloatValue(state, 2);
  2658. if (spawn && spawn->IsEntity()) {
  2659. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2660. if (spawn->IsPlayer())
  2661. ((Player*)spawn)->SetCharSheetChanged(true);
  2662. }
  2663. return 0;
  2664. }
  2665. int EQ2Emu_lua_SetSta(lua_State* state) {
  2666. if (!lua_interface)
  2667. return 0;
  2668. Spawn* spawn = lua_interface->GetSpawn(state);
  2669. float value = lua_interface->GetFloatValue(state, 2);
  2670. if (spawn && spawn->IsEntity()) {
  2671. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2672. if (spawn->IsPlayer())
  2673. ((Player*)spawn)->SetCharSheetChanged(true);
  2674. }
  2675. return 0;
  2676. }
  2677. int EQ2Emu_lua_SetStr(lua_State* state) {
  2678. if (!lua_interface)
  2679. return 0;
  2680. Spawn* spawn = lua_interface->GetSpawn(state);
  2681. float value = lua_interface->GetFloatValue(state, 2);
  2682. if (spawn && spawn->IsEntity()) {
  2683. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2684. if (spawn->IsPlayer())
  2685. ((Player*)spawn)->SetCharSheetChanged(true);
  2686. }
  2687. return 0;
  2688. }
  2689. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2690. if (!lua_interface)
  2691. return 0;
  2692. Spawn* spawn = lua_interface->GetSpawn(state);
  2693. float value = lua_interface->GetFloatValue(state, 2);
  2694. if (spawn && spawn->IsEntity()) {
  2695. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2696. if (spawn->IsPlayer())
  2697. ((Player*)spawn)->SetCharSheetChanged(true);
  2698. }
  2699. return 0;
  2700. }
  2701. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2702. if (!lua_interface)
  2703. return 0;
  2704. Spawn* spawn = lua_interface->GetSpawn(state);
  2705. if (spawn) {
  2706. lua_interface->SetInt32Value(state, spawn->GetHP());
  2707. return 1;
  2708. }
  2709. return 0;
  2710. }
  2711. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2712. if (!lua_interface)
  2713. return 0;
  2714. Spawn* spawn = lua_interface->GetSpawn(state);
  2715. if (spawn) {
  2716. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2717. return 1;
  2718. }
  2719. return 0;
  2720. }
  2721. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2722. if (!lua_interface)
  2723. return 0;
  2724. Spawn* spawn = lua_interface->GetSpawn(state);
  2725. if (spawn) {
  2726. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2727. return 1;
  2728. }
  2729. return 0;
  2730. }
  2731. int EQ2Emu_lua_GetName(lua_State* state) {
  2732. if (!lua_interface)
  2733. return 0;
  2734. Spawn* spawn = lua_interface->GetSpawn(state);
  2735. if (spawn) {
  2736. lua_interface->SetStringValue(state, spawn->GetName());
  2737. return 1;
  2738. }
  2739. return 0;
  2740. }
  2741. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2742. Spawn* spawn = lua_interface->GetSpawn(state);
  2743. if (spawn) {
  2744. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2745. return 1;
  2746. }
  2747. return 0;
  2748. }
  2749. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2750. if (!lua_interface)
  2751. return 0;
  2752. Spawn* spawn = lua_interface->GetSpawn(state);
  2753. if (spawn) {
  2754. lua_interface->SetInt32Value(state, spawn->GetPower());
  2755. return 1;
  2756. }
  2757. return 0;
  2758. }
  2759. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2760. if (!lua_interface)
  2761. return 0;
  2762. Spawn* spawn = lua_interface->GetSpawn(state);
  2763. if (spawn) {
  2764. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2765. return 1;
  2766. }
  2767. return 0;
  2768. }
  2769. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2770. if (!lua_interface)
  2771. return 0;
  2772. Spawn* spawn = lua_interface->GetSpawn(state);
  2773. if (spawn) {
  2774. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2775. return 1;
  2776. }
  2777. return 0;
  2778. }
  2779. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2780. if (!lua_interface)
  2781. return 0;
  2782. Spawn* spawn = lua_interface->GetSpawn(state);
  2783. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2784. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2785. if (spawn && spawn2) {
  2786. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2787. lua_interface->SetFloatValue(state, distance);
  2788. return 1;
  2789. }
  2790. return 0;
  2791. }
  2792. int EQ2Emu_lua_GetX(lua_State* state) {
  2793. if (!lua_interface)
  2794. return 0;
  2795. Spawn* spawn = lua_interface->GetSpawn(state);
  2796. if (spawn) {
  2797. lua_interface->SetFloatValue(state, spawn->GetX());
  2798. return 1;
  2799. }
  2800. return 0;
  2801. }
  2802. int EQ2Emu_lua_GetY(lua_State* state) {
  2803. if (!lua_interface)
  2804. return 0;
  2805. Spawn* spawn = lua_interface->GetSpawn(state);
  2806. if (spawn) {
  2807. lua_interface->SetFloatValue(state, spawn->GetY());
  2808. return 1;
  2809. }
  2810. return 0;
  2811. }
  2812. int EQ2Emu_lua_GetZ(lua_State* state) {
  2813. if (!lua_interface)
  2814. return 0;
  2815. Spawn* spawn = lua_interface->GetSpawn(state);
  2816. if (spawn) {
  2817. lua_interface->SetFloatValue(state, spawn->GetZ());
  2818. return 1;
  2819. }
  2820. return 0;
  2821. }
  2822. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2823. if (!lua_interface)
  2824. return 0;
  2825. Spawn* spawn = lua_interface->GetSpawn(state);
  2826. if (spawn) {
  2827. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2828. return 1;
  2829. }
  2830. return 0;
  2831. }
  2832. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2833. if (!lua_interface)
  2834. return 0;
  2835. Spawn* spawn = lua_interface->GetSpawn(state);
  2836. if (spawn) {
  2837. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2838. return 1;
  2839. }
  2840. return 0;
  2841. }
  2842. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2843. if (!lua_interface)
  2844. return 0;
  2845. Spawn* spawn = lua_interface->GetSpawn(state);
  2846. if (spawn) {
  2847. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2848. return 1;
  2849. }
  2850. return 0;
  2851. }
  2852. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2853. if (!lua_interface)
  2854. return 0;
  2855. Spawn* spawn = lua_interface->GetSpawn(state);
  2856. if (spawn && spawn->IsEntity()) {
  2857. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2858. return 1;
  2859. }
  2860. return 0;
  2861. }
  2862. int EQ2Emu_lua_GetInt(lua_State* state) {
  2863. if (!lua_interface)
  2864. return 0;
  2865. Spawn* spawn = lua_interface->GetSpawn(state);
  2866. if (spawn && spawn->IsEntity()) {
  2867. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2868. return 1;
  2869. }
  2870. return 0;
  2871. }
  2872. int EQ2Emu_lua_GetWis(lua_State* state) {
  2873. if (!lua_interface)
  2874. return 0;
  2875. Spawn* spawn = lua_interface->GetSpawn(state);
  2876. if (spawn && spawn->IsEntity()) {
  2877. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2878. return 1;
  2879. }
  2880. return 0;
  2881. }
  2882. int EQ2Emu_lua_GetSta(lua_State* state) {
  2883. if (!lua_interface)
  2884. return 0;
  2885. Spawn* spawn = lua_interface->GetSpawn(state);
  2886. if (spawn && spawn->IsEntity()) {
  2887. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2888. return 1;
  2889. }
  2890. return 0;
  2891. }
  2892. int EQ2Emu_lua_GetStr(lua_State* state) {
  2893. if (!lua_interface)
  2894. return 0;
  2895. Spawn* spawn = lua_interface->GetSpawn(state);
  2896. if (spawn && spawn->IsEntity()) {
  2897. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2898. return 1;
  2899. }
  2900. return 0;
  2901. }
  2902. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2903. if (!lua_interface)
  2904. return 0;
  2905. Spawn* spawn = lua_interface->GetSpawn(state);
  2906. if (spawn && spawn->IsEntity()) {
  2907. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2908. return 1;
  2909. }
  2910. return 0;
  2911. }
  2912. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2913. if (!lua_interface)
  2914. return 0;
  2915. Spawn* spawn = lua_interface->GetSpawn(state);
  2916. if (spawn && spawn->IsEntity()) {
  2917. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2918. return 1;
  2919. }
  2920. return 0;
  2921. }
  2922. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2923. if (!lua_interface)
  2924. return 0;
  2925. Spawn* spawn = lua_interface->GetSpawn(state);
  2926. if (spawn && spawn->IsEntity()) {
  2927. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2928. return 1;
  2929. }
  2930. return 0;
  2931. }
  2932. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2933. if (!lua_interface)
  2934. return 0;
  2935. Spawn* spawn = lua_interface->GetSpawn(state);
  2936. if (spawn && spawn->IsEntity()) {
  2937. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2938. return 1;
  2939. }
  2940. return 0;
  2941. }
  2942. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2943. if (!lua_interface)
  2944. return 0;
  2945. Spawn* spawn = lua_interface->GetSpawn(state);
  2946. if (spawn && spawn->IsEntity()) {
  2947. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2948. return 1;
  2949. }
  2950. return 0;
  2951. }
  2952. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2953. if (!lua_interface)
  2954. return 0;
  2955. Spawn* spawn = lua_interface->GetSpawn(state);
  2956. if (spawn && spawn->IsEntity()) {
  2957. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2958. return 1;
  2959. }
  2960. return 0;
  2961. }
  2962. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2963. if (!lua_interface)
  2964. return 0;
  2965. Spawn* player = lua_interface->GetSpawn(state);
  2966. if (!player || !player->IsPlayer()) {
  2967. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2968. return 0;
  2969. }
  2970. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2971. if (quest_id <= 0) {
  2972. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2973. return 0;
  2974. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2975. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2976. return 0;
  2977. }
  2978. int32 step = lua_interface->GetInt32Value(state, 3);
  2979. if (step > 0) {
  2980. Client* client = player->GetZone()->GetClientBySpawn(player);
  2981. if (client)
  2982. client->AddPendingQuestUpdate(quest_id, step);
  2983. } else {
  2984. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2985. }
  2986. return 0;
  2987. }
  2988. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2989. Spawn* player = lua_interface->GetSpawn(state);
  2990. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2991. int32 step = lua_interface->GetInt32Value(state, 3);
  2992. int32 progress = lua_interface->GetInt32Value(state, 4);
  2993. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2994. Client* client = player->GetZone()->GetClientBySpawn(player);
  2995. if (client)
  2996. client->AddPendingQuestUpdate(quest_id, step, progress);
  2997. }
  2998. return 0;
  2999. }
  3000. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3001. if (!lua_interface)
  3002. return 0;
  3003. Spawn* player = lua_interface->GetSpawn(state);
  3004. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3005. if (player && player->IsPlayer() && quest_id > 0) {
  3006. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3007. return 1;
  3008. }
  3009. return 0;
  3010. }
  3011. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3012. if (!lua_interface)
  3013. return 0;
  3014. Spawn* player = lua_interface->GetSpawn(state);
  3015. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3016. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3017. if (player && player->IsPlayer() && quest_id > 0) {
  3018. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3019. return 1;
  3020. }
  3021. return 0;
  3022. }
  3023. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3024. if (!lua_interface)
  3025. return 0;
  3026. Spawn* player = lua_interface->GetSpawn(state);
  3027. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3028. if (player && player->IsPlayer() && quest_id > 0) {
  3029. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3030. return 1;
  3031. }
  3032. return 0;
  3033. }
  3034. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3035. if (!lua_interface)
  3036. return 0;
  3037. Quest* quest = lua_interface->GetQuest(state);
  3038. string name = lua_interface->GetStringValue(state, 2);
  3039. string type = lua_interface->GetStringValue(state, 3);
  3040. string zone = lua_interface->GetStringValue(state, 4);
  3041. int16 level = lua_interface->GetInt16Value(state, 5);
  3042. string description = lua_interface->GetStringValue(state, 6);
  3043. bool load = true;
  3044. if (!quest) {
  3045. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3046. load = false;
  3047. }
  3048. if (load && name.length() == 0) {
  3049. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3050. load = false;
  3051. }
  3052. if (load && type.length() == 0) {
  3053. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3054. load = false;
  3055. }
  3056. if (load && zone.length() == 0) {
  3057. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3058. load = false;
  3059. }
  3060. if (load && description.length() == 0) {
  3061. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3062. load = false;
  3063. }
  3064. if (load && level == 0) {
  3065. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3066. load = false;
  3067. }
  3068. if (load)
  3069. quest->RegisterQuest(name, type, zone, level, description);
  3070. return 0;
  3071. }
  3072. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3073. if (!lua_interface)
  3074. return 0;
  3075. Quest* quest = lua_interface->GetQuest(state);
  3076. if (quest) {
  3077. int8 level = lua_interface->GetInt16Value(state, 2);
  3078. quest->SetPrereqLevel(level);
  3079. }
  3080. return 0;
  3081. }
  3082. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3083. if (!lua_interface)
  3084. return 0;
  3085. Quest* quest = lua_interface->GetQuest(state);
  3086. if (quest) {
  3087. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3088. quest->AddPrereqQuest(quest_id);
  3089. }
  3090. return 0;
  3091. }
  3092. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3093. if (!lua_interface)
  3094. return 0;
  3095. Quest* quest = lua_interface->GetQuest(state);
  3096. if (quest) {
  3097. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3098. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3099. if (quantity == 0)
  3100. quantity = 1;
  3101. Item* master_item = master_item_list.GetItem(item_id);
  3102. if (master_item) {
  3103. Item* item = new Item(master_item);
  3104. item->details.count = quantity;
  3105. quest->AddPrereqItem(item);
  3106. }
  3107. }
  3108. return 0;
  3109. }
  3110. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3111. if (!lua_interface)
  3112. return 0;
  3113. Spawn* player = lua_interface->GetSpawn(state);
  3114. if(!player || !player->IsPlayer()) {
  3115. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3116. return 0;
  3117. }
  3118. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3119. if (quest_id > 0) {
  3120. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3121. return 1;
  3122. } else {
  3123. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3124. }
  3125. return 0;
  3126. }
  3127. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3128. if (!lua_interface)
  3129. return 0;
  3130. Quest* quest = lua_interface->GetQuest(state);
  3131. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3132. if (quest && spawn_id > 0)
  3133. quest->SetQuestReturnNPC(spawn_id);
  3134. return 0;
  3135. }
  3136. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3137. if (!lua_interface)
  3138. return 0;
  3139. Spawn* spawn = lua_interface->GetSpawn(state);
  3140. if (!spawn) {
  3141. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3142. return 0;
  3143. }
  3144. int32 time = lua_interface->GetInt32Value(state, 2);
  3145. if (time <= 0) {
  3146. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3147. return 0;
  3148. }
  3149. string function = lua_interface->GetStringValue(state, 3);
  3150. if (function.length() == 0) {
  3151. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3152. return 0;
  3153. }
  3154. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3155. Spawn* player = lua_interface->GetSpawn(state, 5);
  3156. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3157. if ( time < 10)
  3158. time = 10;
  3159. timer->timer = Timer::GetCurrentTime2() + time;
  3160. timer->function = function;
  3161. timer->spawn = spawn->GetID();
  3162. timer->player = player ? player->GetID() : 0;
  3163. if (max_count == 0)
  3164. max_count = 1;
  3165. timer->max_count = max_count;
  3166. timer->current_count = 0;
  3167. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3168. return 0;
  3169. }
  3170. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3171. if (!lua_interface)
  3172. return 0;
  3173. Spawn* player = lua_interface->GetSpawn(state);
  3174. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3175. if (player && player->IsPlayer() && quest_id > 0) {
  3176. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3177. return 1;
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Spawn* player = lua_interface->GetSpawn(state);
  3185. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3186. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3187. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3188. if (quest)
  3189. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3190. return 1;
  3191. }
  3192. return 0;
  3193. }
  3194. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3195. if (!lua_interface)
  3196. return 0;
  3197. Spawn* player = lua_interface->GetSpawn(state);
  3198. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3199. if (player && player->IsPlayer() && quest_id > 0) {
  3200. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3201. return 1;
  3202. }
  3203. return 0;
  3204. }
  3205. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3206. if (!lua_interface)
  3207. return 0;
  3208. Spawn* npc = lua_interface->GetSpawn(state);
  3209. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3210. if (npc && !npc->IsPlayer() && quest_id > 0)
  3211. npc->AddProvidedQuest(quest_id);
  3212. return 0;
  3213. }
  3214. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3215. if (!lua_interface)
  3216. return 0;
  3217. Spawn* npc = lua_interface->GetSpawn(state);
  3218. Spawn* player = lua_interface->GetSpawn(state, 2);
  3219. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3220. bool forced = lua_interface->GetBooleanValue(state, 4);
  3221. /* NPC is allowed to be null */
  3222. if (player && player->IsPlayer() && quest_id > 0) {
  3223. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3224. if (master_quest) {
  3225. Client* client = player->GetZone()->GetClientBySpawn(player);
  3226. if (!client) {
  3227. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3228. }
  3229. Quest* quest = new Quest(master_quest);
  3230. if (!quest) {
  3231. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3232. }
  3233. if (client && quest) {
  3234. if (npc)
  3235. quest->SetQuestGiver(npc->GetDatabaseID());
  3236. else
  3237. quest->SetQuestGiver(0);
  3238. client->AddPendingQuest(quest, forced);
  3239. }
  3240. }
  3241. else {
  3242. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3243. }
  3244. }
  3245. else {
  3246. lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
  3247. }
  3248. return 0;
  3249. }
  3250. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3251. if (!lua_interface)
  3252. return 0;
  3253. Quest* quest = lua_interface->GetQuest(state);
  3254. if (quest) {
  3255. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3256. quest->AddPrereqClass(class_id);
  3257. }
  3258. return 0;
  3259. }
  3260. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3261. if (!lua_interface)
  3262. return 0;
  3263. Quest* quest = lua_interface->GetQuest(state);
  3264. if (quest) {
  3265. int8 race = lua_interface->GetInt8Value(state, 2);
  3266. quest->AddPrereqRace(race);
  3267. }
  3268. return 0;
  3269. }
  3270. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3271. if (!lua_interface)
  3272. return 0;
  3273. Quest* quest = lua_interface->GetQuest(state);
  3274. if (quest) {
  3275. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3276. quest->AddPrereqModelType(model_type);
  3277. }
  3278. return 0;
  3279. }
  3280. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3281. if (!lua_interface)
  3282. return 0;
  3283. Quest* quest = lua_interface->GetQuest(state);
  3284. if (!quest) {
  3285. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3286. return 0;
  3287. }
  3288. int8 level = lua_interface->GetInt8Value(state, 2);
  3289. quest->SetPrereqTSLevel(level);
  3290. return 0;
  3291. }
  3292. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3293. if (!lua_interface)
  3294. return 0;
  3295. Quest* quest = lua_interface->GetQuest(state);
  3296. if (!quest) {
  3297. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3298. return 0;
  3299. }
  3300. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3301. quest->AddPrereqTradeskillClass(class_id);
  3302. return 0;
  3303. }
  3304. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3305. if (!lua_interface)
  3306. return 0;
  3307. Quest* quest = lua_interface->GetQuest(state);
  3308. if (quest) {
  3309. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3310. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3311. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3312. quest->AddPrereqFaction(faction_id, min, max);
  3313. }
  3314. return 0;
  3315. }
  3316. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3317. if (!lua_interface)
  3318. return 0;
  3319. Quest* quest = lua_interface->GetQuest(state);
  3320. if (quest) {
  3321. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3322. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3323. if (quantity == 0)
  3324. quantity = 1;
  3325. Item* master_item = master_item_list.GetItem(item_id);
  3326. if (master_item) {
  3327. Item* item = new Item(master_item);
  3328. item->details.count = quantity;
  3329. quest->AddSelectableRewardItem(item);
  3330. }
  3331. }
  3332. return 0;
  3333. }
  3334. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3335. if (!lua_interface)
  3336. return 0;
  3337. Quest* quest = lua_interface->GetQuest(state);
  3338. if (quest) {
  3339. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3340. vector<Item*>* items = quest->GetRewardItems();
  3341. if (items) {
  3342. vector<Item*>::iterator itr;
  3343. for (itr = items->begin(); itr != items->end(); itr++) {
  3344. if (*itr && (*itr)->details.item_id == item_id) {
  3345. lua_interface->SetBooleanValue(state, true);
  3346. return 1;
  3347. }
  3348. }
  3349. }
  3350. }
  3351. lua_interface->SetBooleanValue(state, false);
  3352. return 1;
  3353. }
  3354. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3355. if (!lua_interface)
  3356. return 0;
  3357. Quest* quest = lua_interface->GetQuest(state);
  3358. if (quest) {
  3359. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3360. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3361. if (quantity == 0)
  3362. quantity = 1;
  3363. Item* master_item = master_item_list.GetItem(item_id);
  3364. if (master_item) {
  3365. Item* item = new Item(master_item);
  3366. item->details.count = quantity;
  3367. quest->AddRewardItem(item);
  3368. }
  3369. }
  3370. return 0;
  3371. }
  3372. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3373. if (!lua_interface)
  3374. return 0;
  3375. Quest* quest = lua_interface->GetQuest(state);
  3376. if (quest) {
  3377. int32 copper = lua_interface->GetInt32Value(state, 2);
  3378. int32 silver = lua_interface->GetInt32Value(state, 3);
  3379. int32 gold = lua_interface->GetInt32Value(state, 4);
  3380. int32 plat = lua_interface->GetInt32Value(state, 5);
  3381. quest->AddRewardCoins(copper, silver, gold, plat);
  3382. }
  3383. return 0;
  3384. }
  3385. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3386. if (!lua_interface)
  3387. return 0;
  3388. Quest* quest = lua_interface->GetQuest(state);
  3389. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3390. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3391. if (quest && faction_id > 0 && amount != 0)
  3392. quest->AddRewardFaction(faction_id, amount);
  3393. return 0;
  3394. }
  3395. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3396. if (!lua_interface)
  3397. return 0;
  3398. Quest* quest = lua_interface->GetQuest(state);
  3399. if (quest) {
  3400. int32 status = lua_interface->GetInt32Value(state, 2);
  3401. quest->SetRewardStatus(status);
  3402. }
  3403. return 0;
  3404. }
  3405. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3406. if (!lua_interface)
  3407. return 0;
  3408. Quest* quest = lua_interface->GetQuest(state);
  3409. if (quest) {
  3410. int32 status = lua_interface->GetInt32Value(state, 2);
  3411. quest->SetStatusTmpReward(status);
  3412. }
  3413. return 0;
  3414. }
  3415. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3416. if (!lua_interface)
  3417. return 0;
  3418. Quest* quest = lua_interface->GetQuest(state);
  3419. if (quest) {
  3420. int64 coins = lua_interface->GetInt64Value(state, 2);
  3421. quest->SetCoinTmpReward(coins);
  3422. }
  3423. return 0;
  3424. }
  3425. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3426. if (!lua_interface)
  3427. return 0;
  3428. Quest* quest = lua_interface->GetQuest(state);
  3429. if (quest) {
  3430. string comment = lua_interface->GetStringValue(state, 2);
  3431. quest->SetRewardComment(comment);
  3432. }
  3433. return 0;
  3434. }
  3435. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3436. if (!lua_interface)
  3437. return 0;
  3438. Quest* quest = lua_interface->GetQuest(state);
  3439. if (quest) {
  3440. int32 exp = lua_interface->GetInt32Value(state, 2);
  3441. quest->SetRewardXP(exp);
  3442. }
  3443. return 0;
  3444. }
  3445. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3446. Quest* quest = lua_interface->GetQuest(state);
  3447. if (quest) {
  3448. int32 step = lua_interface->GetInt32Value(state, 2);
  3449. string description = lua_interface->GetStringValue(state, 3);
  3450. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3451. float percentage = lua_interface->GetFloatValue(state, 5);
  3452. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3453. int16 icon = lua_interface->GetInt16Value(state, 7);
  3454. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3455. const char* taskgroup = 0;
  3456. if (str_taskgroup.length() > 0)
  3457. taskgroup = str_taskgroup.c_str();
  3458. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3459. if (quest_step && icon && quantity > 0)
  3460. quest_step->SetIcon(icon);
  3461. }
  3462. return 0;
  3463. }
  3464. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3465. {
  3466. if (!lua_interface)
  3467. return 0;
  3468. Quest* quest = lua_interface->GetQuest(state);
  3469. if (quest) {
  3470. int32 step = lua_interface->GetInt32Value(state, 2);
  3471. string description = lua_interface->GetStringValue(state, 3);
  3472. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3473. float percentage = lua_interface->GetFloatValue(state, 5);
  3474. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3475. int16 icon = lua_interface->GetInt16Value(state, 7);
  3476. const char* taskgroup = 0;
  3477. if (str_taskgroup.length() > 0)
  3478. taskgroup = str_taskgroup.c_str();
  3479. int32 id = 0;
  3480. vector<int32>* ids = 0;
  3481. int i = 0;
  3482. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3483. if (ids == 0)
  3484. ids = new vector<int32>;
  3485. ids->push_back(id);
  3486. i++;
  3487. }
  3488. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3489. if (quest_step && icon > 0 && quantity > 0)
  3490. quest_step->SetIcon(icon);
  3491. if (quest->GetPlayer()) {
  3492. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3493. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3494. }
  3495. safe_delete(ids);
  3496. }
  3497. return 0;
  3498. }
  3499. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3500. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3501. }
  3502. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3503. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3504. }
  3505. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3506. if (!lua_interface)
  3507. return 0;
  3508. Quest* quest = lua_interface->GetQuest(state);
  3509. if (quest) {
  3510. int32 step = lua_interface->GetInt32Value(state, 2);
  3511. string description = lua_interface->GetStringValue(state, 3);
  3512. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3513. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3514. int16 icon = lua_interface->GetInt16Value(state, 6);
  3515. const char* taskgroup = 0;
  3516. if (str_taskgroup.length() > 0)
  3517. taskgroup = str_taskgroup.c_str();
  3518. int32 npc_id = 0;
  3519. vector<int32>* ids = 0;
  3520. int i = 0;
  3521. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3522. if (ids == 0)
  3523. ids = new vector<int32>;
  3524. ids->push_back(npc_id);
  3525. i++;
  3526. }
  3527. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3528. if (quest_step && icon > 0)
  3529. quest_step->SetIcon(icon);
  3530. if (quest->GetPlayer()) {
  3531. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3532. if(client)
  3533. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3534. }
  3535. safe_delete(ids);
  3536. }
  3537. return 0;
  3538. }
  3539. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3540. if (!lua_interface)
  3541. return 0;
  3542. Quest* quest = lua_interface->GetQuest(state);
  3543. if (quest) {
  3544. int32 step = lua_interface->GetInt32Value(state, 2);
  3545. string description = lua_interface->GetStringValue(state, 3);
  3546. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3547. float percentage = lua_interface->GetFloatValue(state, 5);
  3548. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3549. int16 icon = lua_interface->GetInt16Value(state, 7);
  3550. const char* taskgroup = 0;
  3551. if (str_taskgroup.length() > 0)
  3552. taskgroup = str_taskgroup.c_str();
  3553. int32 item_id = 0;
  3554. vector<int32>* ids = 0;
  3555. int i = 0;
  3556. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3557. if (ids == 0)
  3558. ids = new vector<int32>;
  3559. ids->push_back(item_id);
  3560. i++;
  3561. }
  3562. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3563. if (quest_step && icon > 0 && quantity > 0)
  3564. quest_step->SetIcon(icon);
  3565. if (quest->GetPlayer()) {
  3566. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3567. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3568. }
  3569. safe_delete(ids);
  3570. }
  3571. return 0;
  3572. }
  3573. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3574. if (!lua_interface)
  3575. return 0;
  3576. Quest* quest = lua_interface->GetQuest(state);
  3577. if (quest) {
  3578. int32 step = lua_interface->GetInt32Value(state, 2);
  3579. string description = lua_interface->GetStringValue(state, 3);
  3580. float max_variation = lua_interface->GetFloatValue(state, 4);
  3581. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3582. int16 icon = lua_interface->GetInt16Value(state, 6);
  3583. const char* taskgroup = 0;
  3584. if (str_taskgroup.length() > 0)
  3585. taskgroup = str_taskgroup.c_str();
  3586. vector<Location>* locations = 0;
  3587. int8 i = 7;
  3588. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3589. while (true) {
  3590. Location loc;
  3591. loc.x = lua_interface->GetFloatValue(state, i);
  3592. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3593. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3594. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3595. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3596. break;
  3597. if (locations == 0)
  3598. locations = new vector<Location>;
  3599. locations->push_back(loc);
  3600. i += 4;
  3601. }
  3602. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3603. if (quest_step && icon > 0)
  3604. quest_step->SetIcon(icon);
  3605. if (quest->GetPlayer()) {
  3606. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3607. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3608. }
  3609. }
  3610. return 0;
  3611. }
  3612. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3613. if (!lua_interface)
  3614. return 0;
  3615. Quest* quest = lua_interface->GetQuest(state);
  3616. if (quest) {
  3617. int32 step = lua_interface->GetInt32Value(state, 2);
  3618. string description = lua_interface->GetStringValue(state, 3);
  3619. float max_variation = lua_interface->GetFloatValue(state, 4);
  3620. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3621. int16 icon = lua_interface->GetInt16Value(state, 6);
  3622. const char* taskgroup = 0;
  3623. if (str_taskgroup.length() > 0)
  3624. taskgroup = str_taskgroup.c_str();
  3625. vector<Location>* locations = 0;
  3626. int8 i = 7;
  3627. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3628. while (true) {
  3629. Location loc;
  3630. loc.x = lua_interface->GetFloatValue(state, i);
  3631. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3632. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3633. loc.zone_id = 0;
  3634. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3635. break;
  3636. if (locations == 0)
  3637. locations = new vector<Location>;
  3638. locations->push_back(loc);
  3639. i += 3;
  3640. }
  3641. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3642. if (quest_step && icon > 0)
  3643. quest_step->SetIcon(icon);
  3644. if (quest->GetPlayer()) {
  3645. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3646. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3647. }
  3648. }
  3649. return 0;
  3650. }
  3651. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3652. if (!lua_interface)
  3653. return 0;
  3654. Quest* quest = lua_interface->GetQuest(state);
  3655. if (quest) {
  3656. int32 step = lua_interface->GetInt32Value(state, 2);
  3657. string description = lua_interface->GetStringValue(state, 3);
  3658. float max_variation = lua_interface->GetFloatValue(state, 4);
  3659. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3660. int16 icon = lua_interface->GetInt16Value(state, 6);
  3661. const char* taskgroup = 0;
  3662. if (str_taskgroup.length() > 0)
  3663. taskgroup = str_taskgroup.c_str();
  3664. vector<Location>* locations = 0;
  3665. int i = 7;
  3666. while (true) {
  3667. Location loc;
  3668. loc.x = lua_interface->GetFloatValue(state, i);
  3669. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3670. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3671. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3672. break;
  3673. if (locations == 0)
  3674. locations = new vector<Location>;
  3675. locations->push_back(loc);
  3676. i += 3;
  3677. }
  3678. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3679. if (quest_step && icon > 0)
  3680. quest_step->SetIcon(icon);
  3681. if (quest->GetPlayer()) {
  3682. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3683. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3684. }
  3685. }
  3686. return 0;
  3687. }
  3688. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3689. Quest* quest = lua_interface->GetQuest(state);
  3690. if (quest) {
  3691. int32 step = lua_interface->GetInt32Value(state, 2);
  3692. string description = lua_interface->GetStringValue(state, 3);
  3693. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3694. float percentage = lua_interface->GetFloatValue(state, 5);
  3695. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3696. int16 icon = lua_interface->GetInt16Value(state, 7);
  3697. const char* taskgroup = 0;
  3698. if (str_taskgroup.length() > 0)
  3699. taskgroup = str_taskgroup.c_str();
  3700. int32 spell_id = 0;
  3701. vector<int32>* ids = 0;
  3702. int i = 0;
  3703. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3704. if (ids == 0)
  3705. ids = new vector<int32>;
  3706. ids->push_back(spell_id);
  3707. i++;
  3708. }
  3709. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3710. if (quest_step && icon > 0 && quantity > 0)
  3711. quest_step->SetIcon(icon);
  3712. if (quest->GetPlayer()) {
  3713. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3714. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3715. }
  3716. safe_delete(ids);
  3717. }
  3718. return 0;
  3719. }
  3720. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3721. if (!lua_interface)
  3722. return 0;
  3723. Quest* quest = lua_interface->GetQuest(state);
  3724. if (quest) {
  3725. int32 step = lua_interface->GetInt32Value(state, 2);
  3726. string description = lua_interface->GetStringValue(state, 3);
  3727. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3728. float percentage = lua_interface->GetFloatValue(state, 5);
  3729. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3730. int16 icon = lua_interface->GetInt16Value(state, 7);
  3731. const char* taskgroup = 0;
  3732. if (str_taskgroup.length() > 0)
  3733. taskgroup = str_taskgroup.c_str();
  3734. int32 item_id = 0;
  3735. vector<int32>* ids = 0;
  3736. int i = 0;
  3737. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3738. if (ids == 0)
  3739. ids = new vector<int32>;
  3740. ids->push_back(item_id);
  3741. i++;
  3742. }
  3743. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3744. if (quest_step && icon > 0 && quantity > 0)
  3745. quest_step->SetIcon(icon);
  3746. if (quest->GetPlayer()) {
  3747. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3748. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3749. }
  3750. safe_delete(ids);
  3751. }
  3752. return 0;
  3753. }
  3754. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3755. if (!lua_interface)
  3756. return 0;
  3757. Quest* quest = lua_interface->GetQuest(state);
  3758. if (quest) {
  3759. int32 step = lua_interface->GetInt32Value(state, 2);
  3760. string description = lua_interface->GetStringValue(state, 3);
  3761. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3762. float percentage = lua_interface->GetFloatValue(state, 5);
  3763. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3764. int16 icon = lua_interface->GetInt16Value(state, 7);
  3765. const char* taskgroup = 0;
  3766. if (str_taskgroup.length() > 0)
  3767. taskgroup = str_taskgroup.c_str();
  3768. int32 item_id = 0;
  3769. vector<int32>* ids = 0;
  3770. int i = 0;
  3771. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3772. if (ids == 0)
  3773. ids = new vector<int32>;
  3774. ids->push_back(item_id);
  3775. i++;
  3776. }
  3777. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3778. if (quest_step && icon > 0 && quantity > 0)
  3779. quest_step->SetIcon(icon);
  3780. if (quest->GetPlayer()) {
  3781. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3782. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3783. }
  3784. safe_delete(ids);
  3785. }
  3786. return 0;
  3787. }
  3788. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3789. if (!lua_interface)
  3790. return 0;
  3791. Quest* quest = lua_interface->GetQuest(state);
  3792. if (quest) {
  3793. string action = lua_interface->GetStringValue(state, 2);
  3794. if (action.length() > 0)
  3795. quest->SetCompleteAction(action);
  3796. }
  3797. return 0;
  3798. }
  3799. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3800. if (!lua_interface)
  3801. return 0;
  3802. Quest* quest = lua_interface->GetQuest(state);
  3803. if (quest) {
  3804. int32 step = lua_interface->GetInt32Value(state, 2);
  3805. string action = lua_interface->GetStringValue(state, 3);
  3806. if (step > 0 && action.length() > 0)
  3807. quest->AddCompleteAction(step, action);
  3808. }
  3809. return 0;
  3810. }
  3811. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3812. if (!lua_interface)
  3813. return 0;
  3814. Quest* quest = lua_interface->GetQuest(state);
  3815. if (quest) {
  3816. int32 step = lua_interface->GetInt32Value(state, 2);
  3817. string action = lua_interface->GetStringValue(state, 3);
  3818. if (step > 0 && action.length() > 0)
  3819. quest->AddProgressAction(step, action);
  3820. }
  3821. return 0;
  3822. }
  3823. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3824. if (!lua_interface)
  3825. return 0;
  3826. Quest* quest = lua_interface->GetQuest(state);
  3827. string description = lua_interface->GetStringValue(state, 2);
  3828. if (quest && description.length() > 0)
  3829. quest->SetDescription(description);
  3830. return 0;
  3831. }
  3832. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3833. if (!lua_interface)
  3834. return 0;
  3835. Quest* quest = lua_interface->GetQuest(state);
  3836. string description = lua_interface->GetStringValue(state, 2);
  3837. if (quest && description.length() > 0)
  3838. quest->SetCompletedDescription(description);
  3839. return 0;
  3840. }
  3841. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3842. if (!lua_interface)
  3843. return 0;
  3844. Quest* quest = lua_interface->GetQuest(state);
  3845. int32 step = lua_interface->GetInt32Value(state, 2);
  3846. string description = lua_interface->GetStringValue(state, 3);
  3847. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3848. if (quest && step > 0 && description.length() > 0) {
  3849. quest->SetTaskGroupDescription(step, description, display_bullets);
  3850. /* if (quest->GetPlayer()) {
  3851. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3852. if (client)
  3853. client->SendQuestUpdateStep(quest, step, false);
  3854. }*/
  3855. }
  3856. return 0;
  3857. }
  3858. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3859. if (!lua_interface)
  3860. return 0;
  3861. Quest* quest = lua_interface->GetQuest(state);
  3862. int32 step = lua_interface->GetInt32Value(state, 2);
  3863. string description = lua_interface->GetStringValue(state, 3);
  3864. if (quest && step > 0 && description.length() > 0) {
  3865. quest->SetStepDescription(step, description);
  3866. /*if (quest->GetPlayer()) {
  3867. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3868. if (client)
  3869. client->SendQuestUpdateStepImmediately(quest, step);
  3870. }*/
  3871. }
  3872. return 0;
  3873. }
  3874. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3875. Quest* quest = lua_interface->GetQuest(state);
  3876. string zone = lua_interface->GetStringValue(state, 2);
  3877. if (quest && zone.length() > 0)
  3878. quest->SetZone(zone);
  3879. return 0;
  3880. }
  3881. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3882. if (!lua_interface)
  3883. return 0;
  3884. Quest* quest = lua_interface->GetQuest(state);
  3885. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3886. lua_interface->ResetFunctionStack(state);
  3887. if (quest && spawn) {
  3888. if (spawn->IsPlayer()) {
  3889. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3890. if (client)
  3891. {
  3892. client->AddPendingQuestAcceptReward(quest);
  3893. client->AddPendingQuestReward(quest);
  3894. }
  3895. }
  3896. }
  3897. return 0;
  3898. }
  3899. int EQ2Emu_lua_Harvest(lua_State* state) {
  3900. if (!lua_interface)
  3901. return 0;
  3902. Spawn* player = lua_interface->GetSpawn(state);
  3903. Spawn* node = lua_interface->GetSpawn(state, 2);
  3904. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3905. Client* client = player->GetZone()->GetClientBySpawn(player);
  3906. if (client) {
  3907. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3908. ((GroundSpawn*)node)->ProcessHarvest(client);
  3909. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3910. player->GetZone()->RemoveSpawn(node, true);
  3911. }
  3912. }
  3913. else if (player && player->IsPlayer()) {
  3914. Client* client = player->GetZone()->GetClientBySpawn(player);
  3915. if (client)
  3916. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3917. }
  3918. return 0;
  3919. }
  3920. int EQ2Emu_lua_Bind(lua_State* state) {
  3921. if (!lua_interface)
  3922. return 0;
  3923. Spawn* spawn = lua_interface->GetSpawn(state);
  3924. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3925. float x = lua_interface->GetFloatValue(state, 3);
  3926. float y = lua_interface->GetFloatValue(state, 4);
  3927. float z = lua_interface->GetFloatValue(state, 5);
  3928. float h = lua_interface->GetFloatValue(state, 6);
  3929. if (!spawn) {
  3930. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3931. return 0;
  3932. }
  3933. if (!spawn->IsPlayer()) {
  3934. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3935. return 0;
  3936. }
  3937. if (zone_id == 0) {
  3938. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3939. if (!client) {
  3940. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3941. return 0;
  3942. }
  3943. if (!client->Bind())
  3944. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3945. }
  3946. else {
  3947. Player* player = (Player*)spawn;
  3948. player->GetPlayerInfo()->SetBindZone(zone_id);
  3949. player->GetPlayerInfo()->SetBindX(x);
  3950. player->GetPlayerInfo()->SetBindY(y);
  3951. player->GetPlayerInfo()->SetBindZ(z);
  3952. player->GetPlayerInfo()->SetBindHeading(h);
  3953. }
  3954. return 0;
  3955. }
  3956. int EQ2Emu_lua_Gate(lua_State* state) {
  3957. if (!lua_interface)
  3958. return 0;
  3959. Spawn* spawn = lua_interface->GetSpawn(state);
  3960. if (spawn) {
  3961. if (spawn->IsPlayer()) {
  3962. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3963. if (client) {
  3964. if (!client->Gate())
  3965. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3966. }
  3967. }
  3968. }
  3969. return 0;
  3970. }
  3971. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3972. if (!lua_interface)
  3973. return 0;
  3974. bool ret = false;
  3975. Spawn* spawn = lua_interface->GetSpawn(state);
  3976. if (spawn) {
  3977. if (spawn->IsPlayer()) {
  3978. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3979. if (client)
  3980. ret = client->BindAllowed();
  3981. }
  3982. }
  3983. lua_interface->SetBooleanValue(state, ret);
  3984. return 1;
  3985. }
  3986. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3987. if (!lua_interface)
  3988. return 0;
  3989. bool ret = false;
  3990. Spawn* spawn = lua_interface->GetSpawn(state);
  3991. if (spawn) {
  3992. if (spawn->IsPlayer()) {
  3993. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3994. if (client)
  3995. ret = client->GateAllowed();
  3996. }
  3997. }
  3998. lua_interface->SetBooleanValue(state, ret);
  3999. return 1;
  4000. }
  4001. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4002. Spawn* spawn = lua_interface->GetSpawn(state);
  4003. if (spawn) {
  4004. lua_interface->SetBooleanValue(state, spawn->Alive());
  4005. return 1;
  4006. }
  4007. return 0;
  4008. }
  4009. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4010. if (!lua_interface)
  4011. return 0;
  4012. Spawn* spawn = lua_interface->GetSpawn(state);
  4013. if (spawn && spawn->IsEntity()) {
  4014. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4015. return 1;
  4016. }
  4017. return 0;
  4018. }
  4019. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4020. Spawn* spawn = lua_interface->GetSpawn(state);
  4021. string message = lua_interface->GetStringValue(state, 2);
  4022. string color_str = lua_interface->GetStringValue(state, 3);
  4023. int8 color = CHANNEL_NARRATIVE;
  4024. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4025. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4026. if (client) {
  4027. if (color_str.length() > 0) {
  4028. // leave for backwards compat, but all future should just use the number
  4029. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4030. color = CHANNEL_COLOR_RED;
  4031. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4032. color = CHANNEL_COLOR_YELLOW;
  4033. else
  4034. {
  4035. // use a number to specify the channel as per Commands/Commands.h defines
  4036. color = (int8)atoul(color_str.c_str());
  4037. }
  4038. }
  4039. client->SimpleMessage(color, message.c_str());
  4040. }
  4041. }
  4042. return 0;
  4043. }
  4044. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4045. Spawn* spawn = lua_interface->GetSpawn(state);
  4046. string message = lua_interface->GetStringValue(state, 2);
  4047. int8 red = lua_interface->GetInt8Value(state, 3);
  4048. int8 green = lua_interface->GetInt8Value(state, 4);
  4049. int8 blue = lua_interface->GetInt8Value(state, 5);
  4050. if (!spawn) {
  4051. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4052. return 0;
  4053. }
  4054. int32 words = ::CountWordsInString(message.c_str());
  4055. if (words < 5)
  4056. words = 5;
  4057. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4058. if (client)
  4059. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4060. return 0;
  4061. }
  4062. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4063. Spawn* spawn = lua_interface->GetSpawn(state);
  4064. int8 param = lua_interface->GetInt8Value(state, 2);
  4065. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4066. int8 value = lua_interface->GetInt8Value(state, 4);
  4067. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4068. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4069. if (client) {
  4070. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4071. switch (param) {
  4072. case 1: {
  4073. packet->setDataByName("parameter1", param_value);
  4074. break;
  4075. }
  4076. case 2: {
  4077. packet->setDataByName("parameter2", param_value);
  4078. break;
  4079. }
  4080. case 3: {
  4081. packet->setDataByName("parameter3", param_value);
  4082. break;
  4083. }
  4084. case 4: {
  4085. packet->setDataByName("parameter4", param_value);
  4086. break;
  4087. }
  4088. case 5: {
  4089. packet->setDataByName("parameter5", param_value);
  4090. break;
  4091. }
  4092. }
  4093. packet->setDataByName("value", value);
  4094. client->QueuePacket(packet->serialize());
  4095. safe_delete(packet);
  4096. }
  4097. }
  4098. return 0;
  4099. }
  4100. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4101. Spawn* spawn = lua_interface->GetSpawn(state);
  4102. if (spawn && spawn->IsPlayer()) {
  4103. if (((Player*)spawn)->GetIsTracking())
  4104. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4105. else
  4106. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4107. }
  4108. return 0;
  4109. }
  4110. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4111. Spawn* player = lua_interface->GetSpawn(state);
  4112. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4113. string name = lua_interface->GetStringValue(state, 3);
  4114. float distance = lua_interface->GetFloatValue(state, 4);
  4115. string command = lua_interface->GetStringValue(state, 5);
  4116. string error_text = lua_interface->GetStringValue(state, 6);
  4117. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4118. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4119. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4120. if (spawn) {
  4121. if (distance == 0)
  4122. distance = 10.0f;
  4123. if (command.length() == 0)
  4124. command = name;
  4125. if (command.length() < 1 && name.length() < 1)
  4126. {
  4127. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4128. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4129. spawn->RemovePrimaryCommands();
  4130. }
  4131. else
  4132. {
  4133. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4134. }
  4135. }
  4136. return 0;
  4137. }
  4138. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4139. if (!lua_interface)
  4140. return 0;
  4141. Spawn* player = lua_interface->GetSpawn(state);
  4142. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4143. int16 tier = lua_interface->GetInt16Value(state, 3);
  4144. if (player && player->IsPlayer()) {
  4145. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4146. return 1;
  4147. }
  4148. return 0;
  4149. }
  4150. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4151. if (!lua_interface)
  4152. return 0;
  4153. Spawn* player = lua_interface->GetSpawn(state);
  4154. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4155. int16 tier = lua_interface->GetInt16Value(state, 3);
  4156. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4157. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4158. bool add_to_hotbar = true;
  4159. if (num_args > 4) {
  4160. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4161. }
  4162. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4163. if (player && spell && player->IsPlayer()) {
  4164. Client* client = player->GetClient();
  4165. if (client) {
  4166. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4167. {
  4168. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4169. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4170. client->GetPlayer()->UnlockSpell(spell);
  4171. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4172. }
  4173. else
  4174. {
  4175. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4176. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4177. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4178. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4179. client->GetPlayer()->UnlockSpell(spell);
  4180. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4181. }
  4182. //if (client ) {
  4183. // ((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);
  4184. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4185. if (outapp)
  4186. client->QueuePacket(outapp);
  4187. }
  4188. }
  4189. return 0;
  4190. }
  4191. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4192. if (!lua_interface)
  4193. return 0;
  4194. Spawn* player = lua_interface->GetSpawn(state);
  4195. if (player && player->IsPlayer()) {
  4196. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4197. return 1;
  4198. }
  4199. return 0;
  4200. }
  4201. int EQ2Emu_lua_Attack(lua_State* state) {
  4202. if (lua_interface) {
  4203. Spawn* npc = lua_interface->GetSpawn(state);
  4204. Spawn* player = lua_interface->GetSpawn(state, 2);
  4205. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4206. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4207. }
  4208. return 0;
  4209. }
  4210. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4211. if (lua_interface) {
  4212. Spawn* target = lua_interface->GetSpawn(state);
  4213. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4214. if (target && target->GetZone())
  4215. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4216. }
  4217. return 0;
  4218. }
  4219. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4220. Spawn* player;
  4221. if (lua_interface) {
  4222. player = lua_interface->GetSpawn(state);
  4223. if (player && player->IsPlayer()) {
  4224. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4225. return 1;
  4226. }
  4227. }
  4228. return 0;
  4229. }
  4230. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4231. Spawn* player;
  4232. Client* client;
  4233. if (lua_interface) {
  4234. player = lua_interface->GetSpawn(state);
  4235. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4236. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4237. client->HandInCollections();
  4238. }
  4239. return 0;
  4240. }
  4241. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4242. Spawn* widget;
  4243. if (lua_interface) {
  4244. widget = lua_interface->GetSpawn(state);
  4245. if (widget && widget->IsWidget())
  4246. ((Widget*)widget)->HandleUse(nullptr, "");
  4247. }
  4248. return 0;
  4249. }
  4250. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4251. Spawn* spawn = 0;
  4252. int32 primary_list = 0;
  4253. int32 secondary_list = 0;
  4254. if (lua_interface) {
  4255. spawn = lua_interface->GetSpawn(state);
  4256. primary_list = lua_interface->GetInt32Value(state, 2);
  4257. secondary_list = lua_interface->GetInt32Value(state, 3);
  4258. if (!spawn->IsNPC()) {
  4259. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4260. return 0;
  4261. }
  4262. NPC* npc = (NPC*)spawn;
  4263. npc->SetPrimarySpellList(primary_list);
  4264. npc->SetSecondarySpellList(secondary_list);
  4265. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4266. }
  4267. return 0;
  4268. }
  4269. int EQ2Emu_lua_GetPet(lua_State* state) {
  4270. if (!lua_interface)
  4271. return 0;
  4272. Spawn* spawn = lua_interface->GetSpawn(state);
  4273. if (spawn) {
  4274. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4275. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4276. return 1;
  4277. }
  4278. }
  4279. return 0;
  4280. }
  4281. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4282. if (!lua_interface)
  4283. return 0;
  4284. Spawn* spawn = lua_interface->GetSpawn(state);
  4285. if (spawn) {
  4286. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4287. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4288. return 1;
  4289. }
  4290. }
  4291. return 0;
  4292. }
  4293. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4294. if (!lua_interface)
  4295. return 0;
  4296. Spawn* spawn = lua_interface->GetSpawn(state);
  4297. if (spawn) {
  4298. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4299. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4300. return 1;
  4301. }
  4302. }
  4303. return 0;
  4304. }
  4305. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4306. if (!lua_interface)
  4307. return 0;
  4308. Spawn* spawn = lua_interface->GetSpawn(state);
  4309. if (spawn) {
  4310. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4311. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4312. return 1;
  4313. }
  4314. }
  4315. return 0;
  4316. }
  4317. int EQ2Emu_lua_Charm(lua_State* state) {
  4318. if (!lua_interface)
  4319. return 0;
  4320. Spawn* owner = lua_interface->GetSpawn(state);
  4321. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4322. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4323. if (!luaspell) {
  4324. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4325. return 0;
  4326. }
  4327. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4328. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4329. pet->SetPet(true);
  4330. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4331. ((NPC*)pet)->SetOwner((Entity*)owner);
  4332. // If owner is player and player does not have a summoned pet set the players charsheet
  4333. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4334. Player* player = (Player*)owner;
  4335. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4336. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4337. player->GetInfoStruct()->set_pet_movement(2);
  4338. player->GetInfoStruct()->set_pet_behavior(3);
  4339. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4340. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4341. // Make sure the values get sent to the client
  4342. player->SetCharSheetChanged(true);
  4343. }
  4344. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4345. pet->SetSpawnScript("");
  4346. // Set faction to the same as the owner
  4347. pet->SetFactionID(owner->GetFactionID());
  4348. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4349. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4350. // Clear hate list
  4351. ((NPC*)pet)->Brain()->ClearHate();
  4352. // Set the brain to a pet brain
  4353. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4354. }
  4355. return 0;
  4356. }
  4357. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4358. if (!lua_interface)
  4359. return 0;
  4360. Spawn* spawn = lua_interface->GetSpawn(state);
  4361. if (!spawn) {
  4362. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4363. return 0;
  4364. }
  4365. vector<Spawn*> groupMembers;
  4366. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4367. groupMembers = *spawn->GetSpawnGroup();
  4368. }
  4369. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4370. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4371. deque<GroupMemberInfo*>::iterator itr;
  4372. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4373. if (group)
  4374. {
  4375. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4376. deque<GroupMemberInfo*>* members = group->GetMembers();
  4377. GroupMemberInfo* info = 0;
  4378. for (itr = members->begin(); itr != members->end(); itr++) {
  4379. info = *itr;
  4380. if (info->client)
  4381. groupMembers.push_back(info->client->GetPlayer());
  4382. }
  4383. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4384. }
  4385. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4386. }
  4387. else
  4388. return 0;
  4389. lua_createtable(state, groupMembers.size(), 0);
  4390. int newTable = lua_gettop(state);
  4391. for (int32 i = 0; i < groupMembers.size(); i++) {
  4392. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4393. lua_rawseti(state, newTable, i + 1);
  4394. }
  4395. return 1;
  4396. }
  4397. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4398. if (!lua_interface)
  4399. return 0;
  4400. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4401. lua_interface->SetOptionWindowValue(state, option_window);
  4402. return 1;
  4403. }
  4404. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4405. if (!lua_interface)
  4406. return 0;
  4407. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4408. if (option_window) {
  4409. OptionWindowOption option_window_option;
  4410. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4411. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4412. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4413. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4414. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4415. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4416. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4417. option_window->push_back(option_window_option);
  4418. }
  4419. return 0;
  4420. }
  4421. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4422. if (!lua_interface)
  4423. return 0;
  4424. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4425. Spawn* player = lua_interface->GetSpawn(state, 2);
  4426. string window_title = lua_interface->GetStringValue(state, 3);
  4427. string cancel_command = lua_interface->GetStringValue(state, 4);
  4428. Client* client = player->GetZone()->GetClientBySpawn(player);
  4429. if (option_window && window_title.length() > 0 && client) {
  4430. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4431. if (!packet)
  4432. return 0;
  4433. packet->setDataByName("title_text", window_title.c_str());
  4434. if (cancel_command.length() > 0)
  4435. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4436. packet->setArrayLengthByName("num_selections", option_window->size());
  4437. vector<OptionWindowOption>::iterator itr;
  4438. int8 i = 0;
  4439. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4440. OptionWindowOption opt = *itr;
  4441. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4442. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4443. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4444. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4445. if (opt.optionCommand.length() > 0)
  4446. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4447. if (opt.optionConfirmTitle.length() > 0)
  4448. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4449. i++;
  4450. }
  4451. client->QueuePacket(packet->serialize());
  4452. safe_delete(option_window);
  4453. safe_delete(packet);
  4454. }
  4455. return 0;
  4456. }
  4457. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4458. if (!lua_interface)
  4459. return 0;
  4460. Spawn* spawn = lua_interface->GetSpawn(state);
  4461. if (spawn) {
  4462. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4463. return 1;
  4464. }
  4465. else
  4466. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4467. return 0;
  4468. }
  4469. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4470. if (!lua_interface)
  4471. return 0;
  4472. Spawn* spawn = lua_interface->GetSpawn(state);
  4473. if (spawn) {
  4474. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4475. return 1;
  4476. }
  4477. else
  4478. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4479. return 0;
  4480. }
  4481. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4482. if (!lua_interface)
  4483. return 0;
  4484. Spawn* spawn = lua_interface->GetSpawn(state);
  4485. if (spawn) {
  4486. int8 class_id = spawn->GetTradeskillClass();
  4487. // Need to add 42 for the offset in the array
  4488. class_id += 44;
  4489. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4490. return 1;
  4491. }
  4492. else
  4493. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4494. return 0;
  4495. }
  4496. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4497. if (!lua_interface)
  4498. return 0;
  4499. Spawn* spawn = lua_interface->GetSpawn(state);
  4500. int16 level = lua_interface->GetInt8Value(state, 2);
  4501. if (spawn) {
  4502. if (spawn->IsPlayer())
  4503. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4504. else
  4505. spawn->SetTSLevel(level);
  4506. }
  4507. else
  4508. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4509. return 0;
  4510. }
  4511. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4512. if (!lua_interface)
  4513. return 0;
  4514. Spawn* spawn = lua_interface->GetSpawn(state);
  4515. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4516. if (spawn) {
  4517. spawn->SetAttackable(attackable);
  4518. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4519. }
  4520. return 0;
  4521. }
  4522. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4523. // Check to see if we have a valid lua_interface
  4524. if (!lua_interface)
  4525. return 0;
  4526. // Get the spawn that is getting the pet
  4527. Spawn* spawn = lua_interface->GetSpawn(state);
  4528. // Get the DB ID of the pet
  4529. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4530. // The max level the pet can gain
  4531. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4532. // Get the spell that this command was called from
  4533. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4534. // Check to make sure the spawn pointer is valid
  4535. if (!spawn) {
  4536. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4537. return 0;
  4538. }
  4539. // Check to make sure the spawn is an entity
  4540. if (!spawn->IsEntity()) {
  4541. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4542. return 0;
  4543. }
  4544. // Check to make sure the spawn doesn't already have a pet of this type
  4545. if (((Entity*)spawn)->GetPet()) {
  4546. if (spawn->IsPlayer()) {
  4547. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4548. if (client)
  4549. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4550. }
  4551. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4552. return 0;
  4553. }
  4554. // Check to see if the DB ID for the pet is set
  4555. if (pet_id == 0) {
  4556. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4557. return 0;
  4558. }
  4559. // Check to see if the pointer to the spell is valid
  4560. if (!luaspell) {
  4561. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4562. return 0;
  4563. }
  4564. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4565. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4566. if (!pet) {
  4567. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4568. return 0;
  4569. }
  4570. // Check to make sure the pet is an npc
  4571. if (!pet->IsNPC()) {
  4572. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4573. return 0;
  4574. }
  4575. // Spawn the pet at the same location as the owner
  4576. pet->SetX(spawn->GetX());
  4577. pet->SetY(spawn->GetY());
  4578. pet->SetZ(spawn->GetZ());
  4579. pet->SetLocation(spawn->GetLocation());
  4580. pet->SetHeading(spawn->GetHeading());
  4581. spawn->GetZone()->AddSpawn(pet);
  4582. /*
  4583. const char* spawn_script = world.GetSpawnScript(pet_id);
  4584. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4585. spawn->SetSpawnScript(string(spawn_script));
  4586. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4587. }*/
  4588. // Get a random pet name
  4589. string random_pet_name;
  4590. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4591. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4592. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4593. // If player set various values for the char sheet (pet window)
  4594. if (spawn->IsPlayer()) {
  4595. Player* player = (Player*)spawn;
  4596. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4597. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4598. player->GetInfoStruct()->set_pet_movement(2);
  4599. player->GetInfoStruct()->set_pet_behavior(3);
  4600. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4601. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4602. // Make sure the values get sent to the client
  4603. player->SetCharSheetChanged(true);
  4604. }
  4605. // Set the pets name
  4606. pet->SetName(random_pet_name.c_str());
  4607. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4608. if (max_level > 0)
  4609. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4610. else
  4611. pet->SetLevel(spawn->GetLevel());
  4612. // Set the max level this pet can reach
  4613. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4614. // Set the faction of the pet to the same faction as the owner
  4615. pet->SetFactionID(spawn->GetFactionID());
  4616. // Set the spawn as a pet
  4617. pet->SetPet(true);
  4618. // Give a pointer of the owner to the pet
  4619. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4620. // Give a pointer of the pet to the owner
  4621. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4622. // Set the pet type
  4623. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4624. // Set the spell id used to create this pet
  4625. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4626. // Set the spell tier used to create this pet
  4627. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4628. // Set the pets spawn type to 6
  4629. pet->SetSpawnType(6);
  4630. // Set the pets brain
  4631. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4632. // Check to see if the pet has a subtitle
  4633. if (strlen(pet->GetSubTitle()) > 0) {
  4634. // Add the players name to the front of the sub title
  4635. string pet_subtitle;
  4636. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4637. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4638. // Set the pets subtitle to the new one
  4639. pet->SetSubTitle(pet_subtitle.c_str());
  4640. }
  4641. // Add the "Pet Options" entity command to the pet
  4642. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4643. // Set the pet as the return value for this function
  4644. lua_interface->SetSpawnValue(state, pet);
  4645. return 1;
  4646. }
  4647. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4648. if (!lua_interface)
  4649. return 0;
  4650. Spawn* spawn = lua_interface->GetSpawn(state);
  4651. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4652. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4653. if (!spawn) {
  4654. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4655. return 0;
  4656. }
  4657. if (!spawn->IsEntity()) {
  4658. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4659. return 0;
  4660. }
  4661. if (((Entity*)spawn)->GetDeityPet()) {
  4662. if (spawn->IsPlayer()) {
  4663. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4664. if (client)
  4665. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4666. }
  4667. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4668. return 0;
  4669. }
  4670. if (pet_id == 0) {
  4671. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4672. return 0;
  4673. }
  4674. if (!luaspell) {
  4675. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4676. return 0;
  4677. }
  4678. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4679. if (!pet) {
  4680. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4681. return 0;
  4682. }
  4683. if (!pet->IsNPC()) {
  4684. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4685. return 0;
  4686. }
  4687. pet->SetX(spawn->GetX());
  4688. pet->SetY(spawn->GetY());
  4689. pet->SetZ(spawn->GetZ());
  4690. pet->SetLocation(spawn->GetLocation());
  4691. pet->SetHeading(spawn->GetHeading());
  4692. spawn->GetZone()->AddSpawn(pet);
  4693. string random_pet_name;
  4694. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4695. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4696. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4697. pet->SetName(random_pet_name.c_str());
  4698. pet->SetLevel(spawn->GetLevel());
  4699. pet->SetFactionID(spawn->GetFactionID());
  4700. pet->SetPet(true);
  4701. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4702. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4703. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4704. pet->SetSpawnType(6);
  4705. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4706. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4707. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4708. if (strlen(pet->GetSubTitle()) > 0) {
  4709. string pet_subtitle;
  4710. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4711. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4712. pet->SetSubTitle(pet_subtitle.c_str());
  4713. }
  4714. // deity and cosmetic pets are not attackable
  4715. pet->SetAttackable(false);
  4716. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4717. lua_interface->SetSpawnValue(state, pet);
  4718. return 1;
  4719. }
  4720. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4721. if (!lua_interface)
  4722. return 0;
  4723. Spawn* spawn = lua_interface->GetSpawn(state);
  4724. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4725. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4726. if (!spawn) {
  4727. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4728. return 0;
  4729. }
  4730. if (!spawn->IsEntity()) {
  4731. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4732. return 0;
  4733. }
  4734. if (((Entity*)spawn)->GetCosmeticPet()) {
  4735. if (spawn->IsPlayer()) {
  4736. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4737. if (client)
  4738. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4739. }
  4740. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4741. return 0;
  4742. }
  4743. if (pet_id == 0) {
  4744. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4745. return 0;
  4746. }
  4747. if (!luaspell) {
  4748. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4749. return 0;
  4750. }
  4751. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4752. if (!pet) {
  4753. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4754. return 0;
  4755. }
  4756. if (!pet->IsNPC()) {
  4757. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4758. return 0;
  4759. }
  4760. pet->SetX(spawn->GetX());
  4761. pet->SetY(spawn->GetY());
  4762. pet->SetZ(spawn->GetZ());
  4763. pet->SetLocation(spawn->GetLocation());
  4764. pet->SetHeading(spawn->GetHeading());
  4765. spawn->GetZone()->AddSpawn(pet);
  4766. string random_pet_name;
  4767. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4768. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4769. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4770. pet->SetName(random_pet_name.c_str());
  4771. pet->SetLevel(spawn->GetLevel());
  4772. pet->SetFactionID(spawn->GetFactionID());
  4773. pet->SetPet(true);
  4774. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4775. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4776. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4777. pet->SetSpawnType(6);
  4778. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4779. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4780. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4781. if (strlen(pet->GetSubTitle()) > 0) {
  4782. string pet_subtitle;
  4783. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4784. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4785. pet->SetSubTitle(pet_subtitle.c_str());
  4786. }
  4787. pet->SetAttackable(false);
  4788. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4789. lua_interface->SetSpawnValue(state, pet);
  4790. return 1;
  4791. }
  4792. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4793. if (!lua_interface)
  4794. return 0;
  4795. Spawn* spawn = lua_interface->GetSpawn(state);
  4796. if (!spawn) {
  4797. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4798. return 0;
  4799. }
  4800. if (!spawn->IsPet()) {
  4801. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4802. return 0;
  4803. }
  4804. if (!((NPC*)spawn)->IsDismissing())
  4805. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4806. return 0;
  4807. }
  4808. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4809. if (!lua_interface)
  4810. return 0;
  4811. Quest* quest = lua_interface->GetQuest(state);
  4812. if (!quest) {
  4813. 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));
  4814. return 0;
  4815. }
  4816. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4817. if (feather_color > 0)
  4818. quest->SetFeatherColor(feather_color);
  4819. return 0;
  4820. }
  4821. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4822. if (!lua_interface)
  4823. return 0;
  4824. Spawn* spawn = lua_interface->GetSpawn(state);
  4825. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4826. if (!spawn) {
  4827. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4828. return 0;
  4829. }
  4830. if (!spawn2) {
  4831. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4832. return 0;
  4833. }
  4834. spawn->RemoveSpawnAccess(spawn2);
  4835. return 0;
  4836. }
  4837. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4838. if (!lua_interface)
  4839. return 0;
  4840. ZoneServer* zone = lua_interface->GetZone(state);
  4841. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4842. if (!zone) {
  4843. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4844. return 0;
  4845. }
  4846. if (location_id == 0) {
  4847. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4848. return 0;
  4849. }
  4850. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4851. if (!location) {
  4852. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4853. return 0;
  4854. }
  4855. Spawn* spawn = 0;
  4856. if (location->entities[0]) {
  4857. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4858. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4859. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4860. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4861. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4862. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4863. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4864. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4865. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4866. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4867. if (spawn) {
  4868. const char* script = 0;
  4869. for (int x = 0; x < 3; x++) {
  4870. switch (x) {
  4871. case 0:
  4872. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4873. break;
  4874. case 1:
  4875. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4876. break;
  4877. case 2:
  4878. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4879. break;
  4880. }
  4881. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4882. spawn->SetSpawnScript(string(script));
  4883. break;
  4884. }
  4885. }
  4886. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4887. lua_interface->SetSpawnValue(state, spawn);
  4888. return 1;
  4889. }
  4890. else {
  4891. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4892. safe_delete(spawn);
  4893. }
  4894. }
  4895. return 0;
  4896. }
  4897. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4898. if (!lua_interface)
  4899. return 0;
  4900. Spawn* caster = lua_interface->GetSpawn(state);
  4901. Spawn* target = lua_interface->GetSpawn(state, 2);
  4902. int32 id = lua_interface->GetInt32Value(state, 3);
  4903. string command = lua_interface->GetStringValue(state, 4);
  4904. if (!caster) {
  4905. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4906. return 0;
  4907. }
  4908. if (!target) {
  4909. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4910. return 0;
  4911. }
  4912. if (!caster->IsPlayer()) {
  4913. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4914. return 0;
  4915. }
  4916. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4917. if (!entity_command) {
  4918. 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());
  4919. return 0;
  4920. }
  4921. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4922. if (!client) {
  4923. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4924. return 0;
  4925. }
  4926. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4927. return 0;
  4928. }
  4929. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4930. if (!lua_interface)
  4931. return 0;
  4932. Spawn* spawn = lua_interface->GetSpawn(state);
  4933. if (!spawn) {
  4934. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4935. return 0;
  4936. }
  4937. if (!spawn->IsNPC()) {
  4938. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4939. return 0;
  4940. }
  4941. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4942. return 0;
  4943. }
  4944. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4945. if (!lua_interface)
  4946. return 0;
  4947. Spawn* spawn = lua_interface->GetSpawn(state);
  4948. int16 tick = lua_interface->GetInt16Value(state, 2);
  4949. if (!spawn) {
  4950. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4951. return 0;
  4952. }
  4953. if (!spawn->IsNPC()) {
  4954. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4955. return 0;
  4956. }
  4957. if (tick < 20) {
  4958. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4959. return 0;
  4960. }
  4961. ((NPC*)spawn)->Brain()->SetTick(tick);
  4962. return 0;
  4963. }
  4964. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4965. if (!lua_interface)
  4966. return 0;
  4967. Spawn* spawn = lua_interface->GetSpawn(state);
  4968. Spawn* target = lua_interface->GetSpawn(state, 2);
  4969. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4970. if (!spawn) {
  4971. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4972. return 0;
  4973. }
  4974. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4975. spawn->SetFollowTarget(target, follow_distance);
  4976. return 0;
  4977. }
  4978. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4979. if (!lua_interface)
  4980. return 0;
  4981. Spawn* spawn = lua_interface->GetSpawn(state);
  4982. if (!spawn) {
  4983. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4984. return 0;
  4985. }
  4986. Spawn* target = spawn->GetFollowTarget();
  4987. if (target) {
  4988. lua_interface->SetSpawnValue(state, target);
  4989. return 1;
  4990. }
  4991. return 0;
  4992. }
  4993. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4994. if (!lua_interface)
  4995. return 0;
  4996. Spawn* spawn = lua_interface->GetSpawn(state);
  4997. if (!spawn) {
  4998. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4999. return 0;
  5000. }
  5001. if (spawn->following)
  5002. spawn->following = false;
  5003. else
  5004. spawn->following = true;
  5005. return 0;
  5006. }
  5007. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5008. if (!lua_interface)
  5009. return 0;
  5010. Spawn* spawn = lua_interface->GetSpawn(state);
  5011. if (!spawn) {
  5012. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5013. return 0;
  5014. }
  5015. lua_interface->SetBooleanValue(state, spawn->following);
  5016. return 1;
  5017. }
  5018. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5019. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5020. // I will attempt to explain how this function works for future refrence
  5021. // Fist lets make sure lua_interface is valid, if not return out
  5022. if (!lua_interface)
  5023. return 0;
  5024. // Next we grab the first 2 params same as we usually would
  5025. Spawn* spawn = lua_interface->GetSpawn(state);
  5026. string var = lua_interface->GetStringValue(state, 2);
  5027. // 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
  5028. // 1 = Spawn
  5029. // 2 = Zone
  5030. // 3 = Item
  5031. // 4 = Quest
  5032. // 5 = String
  5033. // 6 = nil (null)
  5034. int8 dataType = 0;
  5035. // Define pointers for each potential type
  5036. Spawn* spawnVal = 0;
  5037. ZoneServer* zone = 0;
  5038. Item* item = 0;
  5039. Quest* quest = 0;
  5040. string val;
  5041. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5042. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5043. // options window are also light user data be we do not handle those.
  5044. // We check with lua_islightuserdata(lua_State*, index)
  5045. if (lua_islightuserdata(state, 3)) {
  5046. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5047. // and convert it to LUAUserData*
  5048. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5049. // Check to make sure the data we got is valid, if not give an error
  5050. if (!data || !data->IsCorrectlyInitialized()) {
  5051. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5052. }
  5053. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5054. else if (data->IsSpawn()) {
  5055. spawnVal = data->spawn;
  5056. dataType = 1;
  5057. }
  5058. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5059. else if (data->IsZone()) {
  5060. zone = data->zone;
  5061. dataType = 2;
  5062. }
  5063. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5064. else if (data->IsItem()) {
  5065. item = data->item;
  5066. dataType = 3;
  5067. }
  5068. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5069. else if (data->IsQuest()) {
  5070. quest = data->quest;
  5071. dataType = 4;
  5072. }
  5073. }
  5074. // Wasn't light user data, check if it is nil(null)
  5075. else if (lua_isnil(state, 3)) {
  5076. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5077. dataType = 6;
  5078. }
  5079. // Wasn't light user data or nil (null), must be a string
  5080. else {
  5081. // Set the string and dataType variable
  5082. val = lua_interface->GetStringValue(state, 3);
  5083. dataType = 5;
  5084. }
  5085. // We now have all the params, lets check to make sure they are valid
  5086. if (!spawn) {
  5087. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5088. return 0;
  5089. }
  5090. if (var.length() == 0) {
  5091. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5092. return 0;
  5093. }
  5094. if (dataType == 0) {
  5095. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5096. return 0;
  5097. }
  5098. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5099. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5100. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5101. switch (dataType) {
  5102. case 1:
  5103. // 1 = Spawn
  5104. spawn->AddTempVariable(var, spawnVal);
  5105. break;
  5106. case 2:
  5107. // 2 = Zone
  5108. spawn->AddTempVariable(var, zone);
  5109. break;
  5110. case 3:
  5111. // 3 = Item
  5112. spawn->AddTempVariable(var, item);
  5113. break;
  5114. case 4:
  5115. // 4 = Quest
  5116. spawn->AddTempVariable(var, quest);
  5117. break;
  5118. case 5:
  5119. // 5 = String
  5120. spawn->AddTempVariable(var, val);
  5121. break;
  5122. case 6:
  5123. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5124. spawn->DeleteTempVariable(var);
  5125. break;
  5126. }
  5127. // And we are done so return out
  5128. return 0;
  5129. }
  5130. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5131. if (!lua_interface)
  5132. return 0;
  5133. Spawn* spawn = lua_interface->GetSpawn(state);
  5134. string var = lua_interface->GetStringValue(state, 2);
  5135. if (!spawn) {
  5136. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5137. return 0;
  5138. }
  5139. if (var.length() == 0) {
  5140. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5141. return 0;
  5142. }
  5143. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5144. int8 type = spawn->GetTempVariableType(var);
  5145. Spawn* spawn2 = 0;
  5146. ZoneServer* zone = 0;
  5147. Item* item = 0;
  5148. Quest* quest = 0;
  5149. // Set the lua function return value based on the type of data the variable contains
  5150. switch (type) {
  5151. case 1:
  5152. spawn2 = spawn->GetTempVariableSpawn(var);
  5153. if (!spawn2)
  5154. return 0;
  5155. lua_interface->SetSpawnValue(state, spawn2);
  5156. break;
  5157. case 2:
  5158. zone = spawn->GetTempVariableZone(var);
  5159. if (!zone)
  5160. return 0;
  5161. lua_interface->SetZoneValue(state, zone);
  5162. break;
  5163. case 3:
  5164. item = spawn->GetTempVariableItem(var);
  5165. if (!item)
  5166. return 0;
  5167. lua_interface->SetItemValue(state, item);
  5168. break;
  5169. case 4:
  5170. quest = spawn->GetTempVariableQuest(var);
  5171. if (!quest)
  5172. return 0;
  5173. lua_interface->SetQuestValue(state, quest);
  5174. break;
  5175. case 5:
  5176. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5177. break;
  5178. default:
  5179. // Not a valid type then the variable was not set so return out
  5180. return 0;
  5181. }
  5182. // Return value was set so return out
  5183. return 1;
  5184. }
  5185. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5186. {
  5187. if (!lua_interface)
  5188. return 0;
  5189. Quest* quest = lua_interface->GetQuest(state);
  5190. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5191. string description = lua_interface->GetStringValue(state, 3);
  5192. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5193. if (!quest) {
  5194. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5195. lua_interface->SetBooleanValue(state, false);
  5196. return 1;
  5197. }
  5198. if (!spawn) {
  5199. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5200. lua_interface->SetBooleanValue(state, false);
  5201. return 1;
  5202. }
  5203. if (!spawn->IsPlayer()) {
  5204. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5205. lua_interface->SetBooleanValue(state, false);
  5206. return 1;
  5207. }
  5208. if (item_id == 0) {
  5209. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5210. lua_interface->SetBooleanValue(state, false);
  5211. return 1;
  5212. }
  5213. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5214. if (!client) {
  5215. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5216. lua_interface->SetBooleanValue(state, false);
  5217. return 1;
  5218. }
  5219. Item* item = master_item_list.GetItem(item_id);
  5220. if (!item) {
  5221. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5222. lua_interface->SetBooleanValue(state, false);
  5223. return 1;
  5224. }
  5225. Item* firstItem = new Item(item);
  5226. quest->AddTmpRewardItem(firstItem);
  5227. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5228. bool itemsAddedSuccessfully = true;
  5229. if(num_args > 4)
  5230. {
  5231. for(int8 n=5;n<num_args+1;n++)
  5232. {
  5233. int32 new_item = lua_interface->GetInt32Value(state, n);
  5234. Item* tmpItem = master_item_list.GetItem(new_item);
  5235. if(tmpItem)
  5236. {
  5237. Item* newTmpItem = new Item(tmpItem);
  5238. quest->AddTmpRewardItem(newTmpItem);
  5239. }
  5240. else
  5241. itemsAddedSuccessfully = false;
  5242. }
  5243. }
  5244. client->AddPendingQuestAcceptReward(quest);
  5245. client->DisplayQuestComplete(quest, true, description);
  5246. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5247. return 1;
  5248. }
  5249. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5250. if (!lua_interface)
  5251. return 0;
  5252. Quest* quest = lua_interface->GetQuest(state);
  5253. if (!quest) {
  5254. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5255. return 0;
  5256. }
  5257. quest->SetRepeatable(true);
  5258. return 0;
  5259. }
  5260. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5261. if (!lua_interface)
  5262. return 0;
  5263. Spawn* spawn = lua_interface->GetSpawn(state);
  5264. if (!spawn) {
  5265. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5266. return 0;
  5267. }
  5268. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5269. string ret = classes.GetClassNameCase(base_class);
  5270. if (ret.length() > 0) {
  5271. lua_interface->SetStringValue(state, ret.c_str());
  5272. return 1;
  5273. }
  5274. return 0;
  5275. }
  5276. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5277. if (!lua_interface)
  5278. return 0;
  5279. Spawn* player = lua_interface->GetSpawn(state);
  5280. if (player && player->IsPlayer()) {
  5281. Client* client = player->GetClient();
  5282. if (client)
  5283. client->SendWaypoints();
  5284. }
  5285. return 0;
  5286. }
  5287. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5288. if (!lua_interface)
  5289. return 0;
  5290. Spawn* player = lua_interface->GetSpawn(state);
  5291. string name = lua_interface->GetStringValue(state, 2);
  5292. int32 type = lua_interface->GetInt32Value(state, 3);
  5293. if (type == 0)
  5294. type = 2;
  5295. if (name.length() > 0) {
  5296. if (player && player->IsPlayer()) {
  5297. Client* client = player->GetClient();
  5298. if (client)
  5299. client->AddWaypoint(name, type);
  5300. }
  5301. }
  5302. return 0;
  5303. }
  5304. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5305. if (!lua_interface)
  5306. return 0;
  5307. Spawn* player = lua_interface->GetSpawn(state);
  5308. string name = lua_interface->GetStringValue(state, 2);
  5309. if (name.length() > 0) {
  5310. if (player && player->IsPlayer()) {
  5311. Client* client = player->GetClient();
  5312. if (client)
  5313. client->RemoveWaypoint(name);
  5314. }
  5315. }
  5316. return 0;
  5317. }
  5318. int EQ2Emu_lua_AddWard(lua_State* state) {
  5319. if (!lua_interface)
  5320. return 0;
  5321. int32 damage = lua_interface->GetInt32Value(state);
  5322. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5323. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5324. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5325. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5326. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5327. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5328. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5329. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5330. bool ward_was_added = false;
  5331. ZoneServer* zone = spell->caster->GetZone();
  5332. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5333. for (int32 i = 0; i < spell->targets.size(); i++) {
  5334. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5335. if (!target)
  5336. continue;
  5337. if (target->IsEntity()) {
  5338. // If the ward is already active remove it
  5339. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5340. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5341. // Create new ward info
  5342. WardInfo* ward = new WardInfo;
  5343. ward->Spell = spell;
  5344. ward->BaseDamage = damage;
  5345. ward->DamageLeft = damage;
  5346. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5347. ward->keepWard = keepWard;
  5348. ward->WardType = wardType;
  5349. if (damageAbsorptionPercent > 100)
  5350. damageAbsorptionPercent = 100;
  5351. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5352. if (damageAbsorptionMaxHealthPercent > 100)
  5353. damageAbsorptionMaxHealthPercent = 100;
  5354. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5355. ward->RedirectDamagePercent = redirectDamagePercent;
  5356. ward->LastRedirectDamage = 0;
  5357. ward->LastAbsorbedDamage = 0;
  5358. ward->HitCount = 0;
  5359. spell->num_triggers = maxHitCount;
  5360. spell->had_triggers = true;
  5361. spell->cancel_after_all_triggers = false;
  5362. ward->MaxHitCount = maxHitCount;
  5363. if (wardType == WARD_TYPE_MAGICAL)
  5364. ward->DamageType = damageTypes;
  5365. // Add the ward to the entity
  5366. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5367. ward_was_added = true;
  5368. }
  5369. }
  5370. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5371. if (ward_was_added && spell->caster->IsPlayer()) {
  5372. spell->had_dmg_remaining = true;
  5373. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5374. }
  5375. return 0;
  5376. }
  5377. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5378. if (!lua_interface)
  5379. return 0;
  5380. int32 amount = lua_interface->GetInt32Value(state);
  5381. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5382. WardInfo* ward = 0;
  5383. ZoneServer* zone = spell->caster->GetZone();
  5384. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5385. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5386. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5387. ward = target->GetWard(spell->spell->GetSpellID());
  5388. if (target && ward) {
  5389. ward->DamageLeft += amount;
  5390. if (ward->DamageLeft > ward->BaseDamage)
  5391. ward->DamageLeft = ward->BaseDamage;
  5392. for (int32 i = 0; i < spell->targets.size(); i++) {
  5393. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5394. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5395. }
  5396. }
  5397. }
  5398. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5399. if (ward && spell->caster->IsPlayer())
  5400. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5401. return 0;
  5402. }
  5403. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5404. if (!lua_interface)
  5405. return 0;
  5406. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5407. if (!spell) {
  5408. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5409. return 0;
  5410. }
  5411. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5412. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5413. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5414. if (ward) {
  5415. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5416. return 1;
  5417. }
  5418. }
  5419. return 0;
  5420. }
  5421. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5422. if (!lua_interface)
  5423. return 0;
  5424. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5425. if (!spell) {
  5426. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5427. return 0;
  5428. }
  5429. string type = lua_interface->GetStringValue(state, 2);
  5430. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5431. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5432. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5433. if (ward) {
  5434. if (boost::iequals(type, "damageleft"))
  5435. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5436. else if (boost::iequals(type, "basedamage"))
  5437. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5438. else if (boost::iequals(type, "keepward"))
  5439. lua_interface->SetBooleanValue(state, ward->keepWard);
  5440. else if (boost::iequals(type, "wardtype"))
  5441. lua_interface->SetInt32Value(state, ward->WardType);
  5442. else if (boost::iequals(type, "dmgabsorptionpct"))
  5443. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5444. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5445. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5446. else if (boost::iequals(type, "redirectdamagepercent"))
  5447. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5448. else if (boost::iequals(type, "lastredirectdamage"))
  5449. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5450. else if (boost::iequals(type, "lastabsorbeddamage"))
  5451. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5452. else if (boost::iequals(type, "hitcount"))
  5453. lua_interface->SetInt32Value(state, ward->HitCount);
  5454. else if (boost::iequals(type, "maxhitcount"))
  5455. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5456. else
  5457. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5458. return 1;
  5459. }
  5460. }
  5461. return 0;
  5462. }
  5463. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5464. if (!lua_interface)
  5465. return 0;
  5466. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5467. ZoneServer* zone = spell->caster->GetZone();
  5468. Spawn* target = 0;
  5469. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5470. for (int32 i = 0; i < spell->targets.size(); i++) {
  5471. target = zone->GetSpawnByID(spell->targets.at(i));
  5472. if (target && target->IsEntity()) {
  5473. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5474. }
  5475. }
  5476. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5477. return 0;
  5478. }
  5479. int EQ2Emu_lua_Interrupt(lua_State* state)
  5480. {
  5481. if (!lua_interface)
  5482. return 0;
  5483. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5484. Spawn* target = lua_interface->GetSpawn(state, 2);
  5485. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5486. if (!caster)
  5487. {
  5488. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5489. return 0;
  5490. }
  5491. if (!target)
  5492. {
  5493. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5494. return 0;
  5495. }
  5496. if (!spell) {
  5497. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5498. return 0;
  5499. }
  5500. if (!target->IsEntity() && !spell)
  5501. {
  5502. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5503. return 0;
  5504. }
  5505. if (!target && spell) {
  5506. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5507. for (int8 i = 0; i < spell->targets.size(); i++) {
  5508. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5509. if (!target || !target->IsEntity())
  5510. continue;
  5511. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5512. }
  5513. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5514. }
  5515. else
  5516. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5517. return 0;
  5518. }
  5519. int EQ2Emu_lua_Stealth(lua_State* state) {
  5520. if (!lua_interface)
  5521. return 0;
  5522. int8 type = lua_interface->GetInt8Value(state);
  5523. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5524. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5525. if (!spell) {
  5526. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5527. return 0;
  5528. }
  5529. ZoneServer* zone = spell->caster->GetZone();
  5530. if (spawn) {
  5531. if (spawn->IsEntity()) {
  5532. if (type == 1) {
  5533. ((Entity*)spawn)->AddStealthSpell(spell);
  5534. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5535. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5536. }
  5537. else if (type == 2) {
  5538. ((Entity*)spawn)->AddInvisSpell(spell);
  5539. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5540. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5541. }
  5542. return 0;
  5543. }
  5544. else {
  5545. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5546. return 0;
  5547. }
  5548. }
  5549. else {
  5550. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5551. for (int32 i = 0; i < spell->targets.size(); i++) {
  5552. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5553. if (!spawn || !spawn->IsEntity())
  5554. continue;
  5555. if (type == 1) {
  5556. ((Entity*)spawn)->AddStealthSpell(spell);
  5557. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5558. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5559. }
  5560. else if (type == 2) {
  5561. ((Entity*)spawn)->AddInvisSpell(spell);
  5562. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5563. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5564. }
  5565. else {
  5566. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5567. break;
  5568. }
  5569. }
  5570. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5571. }
  5572. return 0;
  5573. }
  5574. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5575. if (!lua_interface)
  5576. return 0;
  5577. Spawn* spawn = lua_interface->GetSpawn(state);
  5578. if (!spawn) {
  5579. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5580. return 0;
  5581. }
  5582. if (spawn->IsEntity()) {
  5583. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5584. return 1;
  5585. }
  5586. else
  5587. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5588. return 0;
  5589. }
  5590. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5591. if (!lua_interface)
  5592. return 0;
  5593. Spawn* spawn = lua_interface->GetSpawn(state);
  5594. if (!spawn) {
  5595. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5596. return 0;
  5597. }
  5598. if (spawn->IsEntity()) {
  5599. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5600. return 1;
  5601. }
  5602. else
  5603. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5604. return 0;
  5605. }
  5606. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5607. if (!lua_interface)
  5608. return 0;
  5609. Spawn* player = lua_interface->GetSpawn(state);
  5610. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5611. lua_interface->ResetFunctionStack(state);
  5612. if (!player->IsPlayer()) {
  5613. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5614. return 0;
  5615. }
  5616. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5617. return 1;
  5618. }
  5619. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5620. if (!lua_interface)
  5621. return 0;
  5622. Spawn* player = lua_interface->GetSpawn(state);
  5623. int8 slot = lua_interface->GetInt8Value(state, 2);
  5624. lua_interface->ResetFunctionStack(state);
  5625. if (!player) {
  5626. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5627. return 0;
  5628. }
  5629. if (!player->IsPlayer()) {
  5630. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5631. return 0;
  5632. }
  5633. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5634. if (!item) {
  5635. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5636. return 0;
  5637. }
  5638. lua_interface->SetItemValue(state, item);
  5639. return 1;
  5640. }
  5641. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5642. if (!lua_interface)
  5643. return 0;
  5644. Spawn* player = lua_interface->GetSpawn(state);
  5645. int32 id = lua_interface->GetInt32Value(state, 2);
  5646. lua_interface->ResetFunctionStack(state);
  5647. if (!player) {
  5648. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5649. return 0;
  5650. }
  5651. if (!player->IsPlayer()) {
  5652. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5653. return 0;
  5654. }
  5655. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5656. if (!item) {
  5657. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5658. return 0;
  5659. }
  5660. lua_interface->SetItemValue(state, item);
  5661. return 1;
  5662. }
  5663. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5664. if (!lua_interface)
  5665. return 0;
  5666. Spawn* spawn = lua_interface->GetSpawn(state);
  5667. int8 slot = lua_interface->GetInt8Value(state, 2);
  5668. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5669. lua_interface->ResetFunctionStack(state);
  5670. if (!spawn) {
  5671. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5672. return 0;
  5673. }
  5674. if (!spawn->IsEntity()) {
  5675. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5676. return 0;
  5677. }
  5678. Item* item = master_item_list.GetItem(item_id);
  5679. if (!item) {
  5680. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5681. return 0;
  5682. }
  5683. Item* copy = new Item(item);
  5684. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5685. if(result)
  5686. {
  5687. ((Entity*)spawn)->SetEquipment(copy, slot);
  5688. spawn->vis_changed = true;
  5689. if(spawn->IsPlayer())
  5690. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5691. }
  5692. else
  5693. {
  5694. safe_delete(copy);
  5695. }
  5696. lua_interface->SetBooleanValue(state, result);
  5697. return 1;
  5698. }
  5699. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5700. if (!lua_interface)
  5701. return 0;
  5702. Spawn* spawn = lua_interface->GetSpawn(state);
  5703. int8 slot = lua_interface->GetInt8Value(state, 2);
  5704. Item* item = lua_interface->GetItem(state, 3);
  5705. lua_interface->ResetFunctionStack(state);
  5706. if (!spawn) {
  5707. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5708. return 0;
  5709. }
  5710. if (!spawn->IsEntity()) {
  5711. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5712. return 0;
  5713. }
  5714. if (!item) {
  5715. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5716. return 0;
  5717. }
  5718. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5719. if(result)
  5720. {
  5721. ((Entity*)spawn)->SetEquipment(item, slot);
  5722. spawn->vis_changed = true;
  5723. if(spawn->IsPlayer())
  5724. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5725. }
  5726. lua_interface->SetBooleanValue(state, result);
  5727. return 1;
  5728. }
  5729. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5730. if (!lua_interface)
  5731. return 0;
  5732. Spawn* spawn = lua_interface->GetSpawn(state);
  5733. int8 slot = lua_interface->GetInt8Value(state, 2);
  5734. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5735. lua_interface->ResetFunctionStack(state);
  5736. if (!spawn) {
  5737. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5738. return 0;
  5739. }
  5740. if (!spawn->IsEntity()) {
  5741. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5742. return 0;
  5743. }
  5744. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5745. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5746. spawn->vis_changed = true;
  5747. if(spawn->IsPlayer())
  5748. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5749. lua_interface->SetBooleanValue(state, true);
  5750. return 1;
  5751. }
  5752. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5753. if (!lua_interface)
  5754. return 0;
  5755. Spawn* spawn = lua_interface->GetSpawn(state);
  5756. int8 slot = lua_interface->GetInt8Value(state, 2);
  5757. int16 type = lua_interface->GetInt16Value(state, 3);
  5758. int8 r = lua_interface->GetInt8Value(state, 4);
  5759. int8 g = lua_interface->GetInt8Value(state, 5);
  5760. int8 b = lua_interface->GetInt8Value(state, 6);
  5761. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5762. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5763. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5764. lua_interface->ResetFunctionStack(state);
  5765. if (!spawn) {
  5766. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5767. return 0;
  5768. }
  5769. if (!spawn->IsEntity()) {
  5770. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5771. return 0;
  5772. }
  5773. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5774. spawn->vis_changed = true;
  5775. lua_interface->SetBooleanValue(state, true);
  5776. return 1;
  5777. }
  5778. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5779. if (!lua_interface)
  5780. return 0;
  5781. Spawn* player = lua_interface->GetSpawn(state);
  5782. int32 id = lua_interface->GetInt32Value(state, 2);
  5783. int8 count = lua_interface->GetInt8Value(state, 3);
  5784. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5785. lua_interface->ResetFunctionStack(state);
  5786. if (!player) {
  5787. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5788. return 0;
  5789. }
  5790. if (!player->IsPlayer()) {
  5791. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5792. return 0;
  5793. }
  5794. if (!count)
  5795. count = 1;
  5796. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5797. if (!item) {
  5798. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5799. return 0;
  5800. }
  5801. lua_interface->SetItemValue(state, item);
  5802. return 1;
  5803. }
  5804. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5805. if (!lua_interface)
  5806. return 0;
  5807. Spawn* spawn = lua_interface->GetSpawn(state);
  5808. int32 anim = lua_interface->GetInt32Value(state, 2);
  5809. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5810. int8 type = lua_interface->GetInt8Value(state, 4);
  5811. if (!spawn) {
  5812. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5813. return 0;
  5814. }
  5815. if (spawn2) {
  5816. if (spawn2->IsPlayer()) {
  5817. if (type != 1 && type != 2)
  5818. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5819. else
  5820. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5821. return 0;
  5822. }
  5823. else {
  5824. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5825. return 0;
  5826. }
  5827. }
  5828. else
  5829. spawn->GetZone()->PlayAnimation(spawn, anim);
  5830. return 0;
  5831. }
  5832. int EQ2Emu_lua_IsPet(lua_State* state) {
  5833. if (!lua_interface)
  5834. return 0;
  5835. Spawn* spawn = lua_interface->GetSpawn(state);
  5836. if (!spawn) {
  5837. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5838. return 0;
  5839. }
  5840. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5841. return 1;
  5842. }
  5843. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5844. if (!lua_interface)
  5845. return 0;
  5846. Spawn* spawn = lua_interface->GetSpawn(state);
  5847. if (!spawn) {
  5848. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5849. return 0;
  5850. }
  5851. if (!spawn->IsNPC()) {
  5852. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5853. return 0;
  5854. }
  5855. if (((NPC*)spawn)->GetOwner()) {
  5856. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5857. return 1;
  5858. }
  5859. return 0;
  5860. }
  5861. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5862. if (!lua_interface)
  5863. return 0;
  5864. Spawn* spawn = lua_interface->GetSpawn(state);
  5865. Spawn* target = lua_interface->GetSpawn(state, 2);
  5866. if (!spawn) {
  5867. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5868. return 0;
  5869. }
  5870. if (!spawn) {
  5871. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5872. return 0;
  5873. }
  5874. spawn->SetTarget(target);
  5875. return 0;
  5876. }
  5877. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5878. if (!lua_interface)
  5879. return 0;
  5880. Spawn* spawn = lua_interface->GetSpawn(state);
  5881. bool val = lua_interface->GetBooleanValue(state, 2);
  5882. if (!spawn) {
  5883. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5884. return 0;
  5885. }
  5886. if (!spawn->IsEntity()) {
  5887. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5888. return 0;
  5889. }
  5890. ((Entity*)spawn)->InCombat(val);
  5891. if (val) {
  5892. spawn->ClearRunningLocations();
  5893. spawn->CalculateRunningLocation(true);
  5894. }
  5895. return 0;
  5896. }
  5897. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5898. if (!lua_interface)
  5899. return 0;
  5900. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5901. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5902. if (!spawn1) {
  5903. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5904. return 0;
  5905. }
  5906. if (!spawn2) {
  5907. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5908. return 0;
  5909. }
  5910. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5911. return 1;
  5912. }
  5913. int EQ2Emu_lua_Runback(lua_State* state) {
  5914. if (!lua_interface)
  5915. return 0;
  5916. Spawn* spawn = lua_interface->GetSpawn(state);
  5917. if (!spawn) {
  5918. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5919. return 0;
  5920. }
  5921. if (!spawn->IsNPC()) {
  5922. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5923. return 0;
  5924. }
  5925. ((NPC*)spawn)->Runback();
  5926. return 0;
  5927. }
  5928. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5929. if (!lua_interface)
  5930. return 0;
  5931. Spawn* spawn = lua_interface->GetSpawn(state);
  5932. if (!spawn) {
  5933. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5934. return 0;
  5935. }
  5936. if (!spawn->IsNPC()) {
  5937. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5938. return 0;
  5939. }
  5940. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5941. return 1;
  5942. }
  5943. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5944. if (!lua_interface)
  5945. return 0;
  5946. Spawn* spawn = lua_interface->GetSpawn(state);
  5947. if (!spawn) {
  5948. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5949. return 0;
  5950. }
  5951. if (!spawn->IsEntity()) {
  5952. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5953. return 0;
  5954. }
  5955. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5956. return 1;
  5957. }
  5958. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5959. if (!lua_interface)
  5960. return 0;
  5961. Spawn* spawn = lua_interface->GetSpawn(state);
  5962. if (!spawn) {
  5963. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5964. return 0;
  5965. }
  5966. if (!spawn->IsEntity()) {
  5967. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5968. return 0;
  5969. }
  5970. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5971. return 1;
  5972. }
  5973. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5974. if (!lua_interface)
  5975. return 0;
  5976. Spawn* spawn = lua_interface->GetSpawn(state);
  5977. if (!spawn) {
  5978. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5979. return 0;
  5980. }
  5981. if (!spawn->IsEntity()) {
  5982. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5983. return 0;
  5984. }
  5985. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5986. return 1;
  5987. }
  5988. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5989. if (!lua_interface)
  5990. return 0;
  5991. Spawn* spawn = lua_interface->GetSpawn(state);
  5992. if (!spawn) {
  5993. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5994. return 0;
  5995. }
  5996. if (!spawn->IsEntity()) {
  5997. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5998. return 0;
  5999. }
  6000. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6001. return 1;
  6002. }
  6003. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6004. if (!lua_interface)
  6005. return 0;
  6006. Spawn* spawn = lua_interface->GetSpawn(state);
  6007. Spawn* target = lua_interface->GetSpawn(state, 2);
  6008. float distance = lua_interface->GetFloatValue(state, 3);
  6009. if (!spawn) {
  6010. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6011. return 0;
  6012. }
  6013. if (!target) {
  6014. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6015. return 0;
  6016. }
  6017. if (!spawn->IsNPC()) {
  6018. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6019. return 0;
  6020. }
  6021. if (!target->IsEntity()) {
  6022. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6023. return 0;
  6024. }
  6025. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6026. return 1;
  6027. }
  6028. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6029. if (!lua_interface)
  6030. return 0;
  6031. Spawn* spawn = lua_interface->GetSpawn(state);
  6032. Spawn* target = lua_interface->GetSpawn(state, 2);
  6033. float distance = lua_interface->GetFloatValue(state, 3);
  6034. if (!spawn) {
  6035. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6036. return 0;
  6037. }
  6038. if (!target) {
  6039. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6040. return 0;
  6041. }
  6042. if (!spawn->IsNPC()) {
  6043. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6044. return 0;
  6045. }
  6046. if (!target->IsEntity()) {
  6047. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6048. return 0;
  6049. }
  6050. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6051. return 0;
  6052. }
  6053. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6054. if (!lua_interface)
  6055. return 0;
  6056. Spawn* spawn = lua_interface->GetSpawn(state);
  6057. if (!spawn) {
  6058. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6059. return 0;
  6060. }
  6061. if (!spawn->IsNPC()) {
  6062. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6063. return 0;
  6064. }
  6065. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6066. return 1;
  6067. }
  6068. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6069. if (!lua_interface)
  6070. return 0;
  6071. Spawn* spawn = lua_interface->GetSpawn(state);
  6072. if (!spawn) {
  6073. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6074. return 0;
  6075. }
  6076. if (!spawn->IsNPC()) {
  6077. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6078. return 0;
  6079. }
  6080. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6081. return 1;
  6082. }
  6083. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6084. if (!lua_interface)
  6085. return 0;
  6086. Spawn* spawn = lua_interface->GetSpawn(state);
  6087. if (!spawn) {
  6088. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6089. return 0;
  6090. }
  6091. if (!spawn->IsNPC()) {
  6092. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6093. return 0;
  6094. }
  6095. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6096. if (hated) {
  6097. lua_interface->SetSpawnValue(state, hated);
  6098. return 1;
  6099. }
  6100. return 0;
  6101. }
  6102. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6103. if (!lua_interface)
  6104. return 0;
  6105. Spawn* spawn = lua_interface->GetSpawn(state);
  6106. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6107. if (!spawn) {
  6108. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6109. return 0;
  6110. }
  6111. if (!spawn->IsNPC()) {
  6112. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6113. return 0;
  6114. }
  6115. if (!hated) {
  6116. ((NPC*)spawn)->Brain()->ClearHate();
  6117. return 0;
  6118. }
  6119. else
  6120. {
  6121. if (!hated->IsEntity()) {
  6122. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6123. return 0;
  6124. }
  6125. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6126. return 0;
  6127. }
  6128. return 0;
  6129. }
  6130. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6131. if (!lua_interface)
  6132. return 0;
  6133. Spawn* spawn = lua_interface->GetSpawn(state);
  6134. if (!spawn) {
  6135. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. if (!spawn->IsNPC()) {
  6139. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6140. return 0;
  6141. }
  6142. ((NPC*)spawn)->Brain()->ClearEncounter();
  6143. return 0;
  6144. }
  6145. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6146. if (!lua_interface)
  6147. return 0;
  6148. Spawn* spawn = lua_interface->GetSpawn(state);
  6149. if (!spawn) {
  6150. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6151. return 0;
  6152. }
  6153. if (!spawn->IsNPC()) {
  6154. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6155. return 0;
  6156. }
  6157. // Temp list to store hate list
  6158. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6159. if (encounterList->size() == 0) {
  6160. safe_delete(encounterList);
  6161. return 0;
  6162. }
  6163. lua_createtable(state, encounterList->size(), 0);
  6164. int newTable = lua_gettop(state);
  6165. for (int32 i = 0; i < encounterList->size(); i++) {
  6166. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6167. if (temp)
  6168. lua_interface->SetSpawnValue(state, temp);
  6169. lua_rawseti(state, newTable, i + 1);
  6170. }
  6171. safe_delete(encounterList);
  6172. return 1;
  6173. }
  6174. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6175. if (!lua_interface)
  6176. return 0;
  6177. Spawn* spawn = lua_interface->GetSpawn(state);
  6178. if (!spawn) {
  6179. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6180. return 0;
  6181. }
  6182. if (!spawn->IsNPC()) {
  6183. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6184. return 0;
  6185. }
  6186. // Temp list to store hate list
  6187. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6188. if (hateList->size() == 0) {
  6189. safe_delete(hateList);
  6190. return 0;
  6191. }
  6192. lua_createtable(state, hateList->size(), 0);
  6193. int newTable = lua_gettop(state);
  6194. for (int32 i = 0; i < hateList->size(); i++) {
  6195. lua_interface->SetSpawnValue(state, hateList->at(i));
  6196. lua_rawseti(state, newTable, i + 1);
  6197. }
  6198. safe_delete(hateList);
  6199. return 1;
  6200. }
  6201. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6202. if (!lua_interface)
  6203. return 0;
  6204. Spawn* spawn = lua_interface->GetSpawn(state);
  6205. if (!spawn) {
  6206. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6207. return 0;
  6208. }
  6209. if (spawn->IsPlayer()) {
  6210. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6211. lua_interface->SetBooleanValue(state, true);
  6212. else
  6213. lua_interface->SetBooleanValue(state, false);
  6214. return 1;
  6215. }
  6216. else {
  6217. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6218. return 1;
  6219. }
  6220. }
  6221. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6222. if (!lua_interface)
  6223. return 0;
  6224. Quest* quest = lua_interface->GetQuest(state);
  6225. if (!quest) {
  6226. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6227. return 0;
  6228. }
  6229. quest->SetCompletedFlag(true);
  6230. return 0;
  6231. }
  6232. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6233. if (!lua_interface)
  6234. return 0;
  6235. Spawn* spawn = lua_interface->GetSpawn(state);
  6236. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6237. int8 tier = lua_interface->GetInt8Value(state, 3);
  6238. if (!spawn) {
  6239. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6240. return 0;
  6241. }
  6242. if (!spawn->IsEntity()) {
  6243. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6244. return 0;
  6245. }
  6246. if (spellID == 0) {
  6247. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6248. return 0;
  6249. }
  6250. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6251. if (effect) {
  6252. if (tier > 0) {
  6253. // If a tier was passed chec to see if it is the same as the effect
  6254. if (tier == effect->tier)
  6255. lua_interface->SetBooleanValue(state, true);
  6256. else
  6257. lua_interface->SetBooleanValue(state, false);
  6258. return 1;
  6259. }
  6260. else {
  6261. // Have an effect but no tier was passed so return true
  6262. lua_interface->SetBooleanValue(state, true);
  6263. }
  6264. return 1;
  6265. }
  6266. // no effect so return false
  6267. lua_interface->SetBooleanValue(state, false);
  6268. return 1;
  6269. }
  6270. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6271. if (!lua_interface)
  6272. return 0;
  6273. Spawn* spawn = lua_interface->GetSpawn(state);
  6274. int32 id = lua_interface->GetInt32Value(state, 2);
  6275. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6276. Spawn* spawn2 = 0;
  6277. vector<Spawn*> list;
  6278. if (!spawn) {
  6279. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6280. return 0;
  6281. }
  6282. //If zone not provided, use spawn's zone
  6283. if (!zone)
  6284. zone = spawn->GetZone();
  6285. list = zone->GetSpawnsByID(id);
  6286. if (list.size() == 0) {
  6287. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6288. return 0;
  6289. }
  6290. vector<Spawn*>::iterator itr = list.begin();
  6291. for (int8 i = 0; i < list.size(); i++) {
  6292. spawn2 = itr[i];
  6293. if (spawn2)
  6294. spawn2->AddAllowAccessSpawn(spawn);
  6295. }
  6296. return 0;
  6297. }
  6298. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6299. if (!lua_interface)
  6300. return 0;
  6301. Spawn* spawn = lua_interface->GetSpawn(state);
  6302. int32 id = lua_interface->GetInt32Value(state, 2);
  6303. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6304. Spawn* spawn2 = 0;
  6305. if (!spawn) {
  6306. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6307. return 0;
  6308. }
  6309. //If zone not provided, use spawn's zone
  6310. if (!zone)
  6311. zone = spawn->GetZone();
  6312. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6313. vector<Spawn*>::iterator itr = list.begin();
  6314. if (list.size() == 0) {
  6315. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6316. return 0;
  6317. }
  6318. for (int8 i = 0; i < list.size(); i++) {
  6319. spawn2 = itr[i];
  6320. if (spawn2)
  6321. spawn2->RemoveSpawnAccess(spawn);
  6322. }
  6323. return 0;
  6324. }
  6325. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6326. if (!lua_interface)
  6327. return 0;
  6328. Quest* quest = lua_interface->GetQuest(state);
  6329. if (!quest) {
  6330. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6331. return 0;
  6332. }
  6333. quest->SetYellowName(true);
  6334. return 0;
  6335. }
  6336. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6337. if (!lua_interface)
  6338. return 0;
  6339. Spawn* spawn = lua_interface->GetSpawn(state);
  6340. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6341. if (!spawn) {
  6342. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6343. return 0;
  6344. }
  6345. if (!spawn->IsPlayer()) {
  6346. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6347. return 0;
  6348. }
  6349. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6350. return 1;
  6351. }
  6352. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6353. if (!lua_interface)
  6354. return 0;
  6355. Spawn* spawn = lua_interface->GetSpawn(state);
  6356. if (!spawn) {
  6357. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6358. return 0;
  6359. }
  6360. if (!spawn->IsPlayer()) {
  6361. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6362. return 0;
  6363. }
  6364. ZoneServer* zone = spawn->GetZone();
  6365. if (!zone) {
  6366. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6367. return 0;
  6368. }
  6369. Instance_Type iType = zone->GetInstanceType();
  6370. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6371. iType == GROUP_LOCKOUT_INSTANCE ||
  6372. iType == RAID_LOCKOUT_INSTANCE ||
  6373. iType == SOLO_PERSIST_INSTANCE ||
  6374. iType == GROUP_PERSIST_INSTANCE ||
  6375. iType == RAID_PERSIST_INSTANCE) {
  6376. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6377. if (data) {
  6378. // Check to see if the timer has already been set, if it has return out.
  6379. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6380. return 0;
  6381. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6382. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6383. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6384. if (client) {
  6385. string time_msg = "";
  6386. int32 time = data->success_lockout_time;
  6387. int16 hour;
  6388. int8 min;
  6389. int8 sec;
  6390. hour = time / 3600;
  6391. time = time % 3600;
  6392. min = time / 60;
  6393. time = time % 60;
  6394. sec = time;
  6395. if (hour > 0) {
  6396. char temp[10];
  6397. sprintf(temp, " %i", hour);
  6398. time_msg.append(temp);
  6399. time_msg.append(" hour");
  6400. time_msg.append((hour > 1) ? "s" : "");
  6401. }
  6402. if (min > 0) {
  6403. char temp[5];
  6404. sprintf(temp, " %i", min);
  6405. time_msg.append(temp);
  6406. time_msg.append(" minute");
  6407. time_msg.append((min > 1) ? "s" : "");
  6408. }
  6409. // Only add seconds if minutes and hours are 0
  6410. if (hour == 0 && min == 0 && sec > 0) {
  6411. char temp[5];
  6412. sprintf(temp, " %i", sec);
  6413. time_msg.append(temp);
  6414. time_msg.append(" second");
  6415. time_msg.append((sec > 1) ? "s" : "");
  6416. }
  6417. 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());
  6418. }
  6419. }
  6420. else
  6421. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6422. }
  6423. else
  6424. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6425. return 0;
  6426. }
  6427. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6428. if (!lua_interface)
  6429. return 0;
  6430. Spawn* spawn = lua_interface->GetSpawn(state);
  6431. if (!spawn) {
  6432. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6433. return 0;
  6434. }
  6435. if (!spawn->IsPlayer()) {
  6436. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6437. return 0;
  6438. }
  6439. ZoneServer* zone = spawn->GetZone();
  6440. if (!zone) {
  6441. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6442. return 0;
  6443. }
  6444. Instance_Type iType = zone->GetInstanceType();
  6445. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6446. iType == GROUP_LOCKOUT_INSTANCE ||
  6447. iType == RAID_LOCKOUT_INSTANCE ||
  6448. iType == SOLO_PERSIST_INSTANCE ||
  6449. iType == GROUP_PERSIST_INSTANCE ||
  6450. iType == RAID_PERSIST_INSTANCE) {
  6451. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6452. if (data) {
  6453. // Check to see if the timer has already been set, if it has return out.
  6454. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6455. return 0;
  6456. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6457. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6458. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6459. if (client) {
  6460. string time_msg = "";
  6461. int32 time = data->failure_lockout_time;
  6462. int16 hour;
  6463. int8 min;
  6464. int8 sec;
  6465. hour = time / 3600;
  6466. time = time % 3600;
  6467. min = time / 60;
  6468. time = time % 60;
  6469. sec = time;
  6470. if (hour > 0) {
  6471. char temp[10];
  6472. sprintf(temp, " %i", hour);
  6473. time_msg.append(temp);
  6474. time_msg.append(" hour");
  6475. time_msg.append((hour > 1) ? "s" : "");
  6476. }
  6477. if (min > 0) {
  6478. char temp[5];
  6479. sprintf(temp, " %i", min);
  6480. time_msg.append(temp);
  6481. time_msg.append(" minute");
  6482. time_msg.append((min > 1) ? "s" : "");
  6483. }
  6484. // Only add seconds if minutes and hours are 0
  6485. if (hour == 0 && min == 0 && sec > 0) {
  6486. char temp[5];
  6487. sprintf(temp, " %i", sec);
  6488. time_msg.append(temp);
  6489. time_msg.append(" second");
  6490. time_msg.append((sec > 1) ? "s" : "");
  6491. }
  6492. 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());
  6493. }
  6494. }
  6495. else
  6496. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6497. }
  6498. else
  6499. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6500. return 0;
  6501. }
  6502. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6503. if (!lua_interface)
  6504. return 0;
  6505. Spawn* spawn = lua_interface->GetSpawn(state);
  6506. if (!spawn) {
  6507. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6508. return 0;
  6509. }
  6510. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6511. return 1;
  6512. }
  6513. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6514. if (!lua_interface)
  6515. return 0;
  6516. Spawn* player = lua_interface->GetSpawn(state);
  6517. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6518. if (!player) {
  6519. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6520. return 0;
  6521. }
  6522. if (!player->IsPlayer()) {
  6523. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6524. return 0;
  6525. }
  6526. if (!ground) {
  6527. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6528. return 0;
  6529. }
  6530. if (!ground->IsGroundSpawn()) {
  6531. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6532. return 0;
  6533. }
  6534. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6535. if (!groundspawn_entries) {
  6536. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6537. return 0;
  6538. }
  6539. Skill* skill = 0;
  6540. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6541. if (collection_skill == "Collecting")
  6542. skill = ((Player*)player)->GetSkillByName("Gathering");
  6543. else
  6544. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6545. if (!skill) {
  6546. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6547. return 0;
  6548. }
  6549. vector<GroundSpawnEntry*>::iterator itr;
  6550. GroundSpawnEntry* entry = 0;
  6551. bool can_harvest = false;
  6552. sint32 min_skill = -1;
  6553. int16 totalSkill = skill->current_val;
  6554. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6555. if(skillID != 0xFFFFFFFF)
  6556. {
  6557. ((Entity*)player)->MStats.lock();
  6558. totalSkill += ((Entity*)player)->stats[skillID];
  6559. ((Entity*)player)->MStats.unlock();
  6560. }
  6561. // first, iterate through groundspawn_entries, discard tables player cannot use
  6562. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6563. {
  6564. entry = *itr;
  6565. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6566. min_skill = entry->min_skill_level;
  6567. // if player lacks skill, skip table
  6568. if (entry->min_skill_level > totalSkill)
  6569. continue;
  6570. // if bonus, but player lacks level, skip table
  6571. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6572. continue;
  6573. can_harvest = true;
  6574. break;
  6575. }
  6576. lua_interface->SetBooleanValue(state, can_harvest);
  6577. // If false, send the message to the client
  6578. if (!can_harvest) {
  6579. Client* client = player->GetZone()->GetClientBySpawn(player);
  6580. if (client) {
  6581. string msg = "You do not have enough skill to ";
  6582. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6583. msg.append("gather");
  6584. else if (collection_skill == "Mining")
  6585. msg.append("mine");
  6586. else if (collection_skill == "Trapping")
  6587. msg.append("trap");
  6588. else if (collection_skill == "Foresting")
  6589. msg.append("forest");
  6590. else if (collection_skill == "Fishing")
  6591. msg.append("catch");
  6592. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6593. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6594. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6595. }
  6596. }
  6597. return 1;
  6598. }
  6599. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6600. if (!lua_interface)
  6601. return 0;
  6602. Spawn* player = lua_interface->GetSpawn(state);
  6603. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6604. if (!player) {
  6605. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6606. return 0;
  6607. }
  6608. if (!player->IsPlayer()) {
  6609. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6610. return 0;
  6611. }
  6612. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6613. lua_interface->SetBooleanValue(state, ret);
  6614. return 1;
  6615. }
  6616. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6617. // Check to see if we have a valid lua_interface
  6618. if (!lua_interface)
  6619. return 0;
  6620. // Get the spawn that is getting the pet
  6621. Spawn* spawn = lua_interface->GetSpawn(state);
  6622. Spawn* target = lua_interface->GetSpawn(state, 2);
  6623. // Get the DB ID of the pet
  6624. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6625. float x = lua_interface->GetFloatValue(state, 4);
  6626. float y = lua_interface->GetFloatValue(state, 5);
  6627. float z = lua_interface->GetFloatValue(state, 6);
  6628. // Get the spell that this command was called from
  6629. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6630. // Check to make sure the spawn pointer is valid
  6631. if (!spawn) {
  6632. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6633. return 0;
  6634. }
  6635. // Check to make sure the spawn is an entity
  6636. if (!spawn->IsEntity()) {
  6637. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6638. return 0;
  6639. }
  6640. if (!target) {
  6641. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6642. return 0;
  6643. }
  6644. if (!target->IsEntity()) {
  6645. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6646. return 0;
  6647. }
  6648. // Check to see if the DB ID for the pet is set
  6649. if (pet_id == 0) {
  6650. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6651. return 0;
  6652. }
  6653. // Check to see if the pointer to the spell is valid
  6654. if (!luaspell) {
  6655. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6656. return 0;
  6657. }
  6658. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6659. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6660. if (!pet) {
  6661. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6662. return 0;
  6663. }
  6664. // Check to make sure the pet is an npc
  6665. if (!pet->IsNPC()) {
  6666. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6667. return 0;
  6668. }
  6669. if (x == 0)
  6670. x = spawn->GetX();
  6671. if (y == 0)
  6672. y = spawn->GetY();
  6673. if (z == 0)
  6674. z = spawn->GetZ();
  6675. // Spawn the pet at the same location as the owner
  6676. pet->SetX(x);
  6677. pet->SetY(y);
  6678. pet->SetZ(z);
  6679. pet->SetLocation(spawn->GetLocation());
  6680. pet->SetHeading(spawn->GetHeading());
  6681. spawn->GetZone()->AddSpawn(pet);
  6682. /*
  6683. const char* spawn_script = world.GetSpawnScript(pet_id);
  6684. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6685. spawn->SetSpawnScript(string(spawn_script));
  6686. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6687. }*/
  6688. // Get a random pet name
  6689. string random_pet_name;
  6690. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6691. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6692. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6693. // Set the pets name
  6694. pet->SetName(random_pet_name.c_str());
  6695. // Set the level of the pet to the owners level
  6696. pet->SetLevel(spawn->GetLevel());
  6697. // Set the faction of the pet to the same faction as the owner
  6698. pet->SetFactionID(spawn->GetFactionID());
  6699. // Set the spawn as a pet
  6700. pet->SetPet(true);
  6701. // Give a pointer of the owner to the pet
  6702. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6703. // Set the pet type
  6704. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6705. // Set the spell id used to create this pet
  6706. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6707. // Set the spell tier used to create this pet
  6708. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6709. // Set the pets spawn type to 6
  6710. pet->SetSpawnType(6);
  6711. // Set the pets brain
  6712. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6713. // Check to see if the pet has a subtitle
  6714. if (strlen(pet->GetSubTitle()) > 0) {
  6715. // Add the players name to the front of the sub title
  6716. string pet_subtitle;
  6717. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6718. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6719. // Set the pets subtitle to the new one
  6720. pet->SetSubTitle(pet_subtitle.c_str());
  6721. }
  6722. // Set the pet as the return value for this function
  6723. lua_interface->SetSpawnValue(state, pet);
  6724. return 1;
  6725. }
  6726. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6727. if (!lua_interface)
  6728. return 0;
  6729. Spawn* spawn = lua_interface->GetSpawn(state);
  6730. Spawn* player = lua_interface->GetSpawn(state, 2);
  6731. float max_distance = lua_interface->GetFloatValue(state, 3);
  6732. string type = lua_interface->GetStringValue(state, 4);
  6733. if (!spawn || (spawn && spawn->IsPlayer())) {
  6734. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6735. return 0;
  6736. }
  6737. if (!player || (player && !player->IsPlayer())) {
  6738. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6739. return 0;
  6740. }
  6741. Client* client = 0;
  6742. if (player->GetZone())
  6743. client = player->GetZone()->GetClientBySpawn(player);
  6744. if (!client) {
  6745. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6746. return 0;
  6747. }
  6748. //Set max_distance to default if not set or not proper value
  6749. if (max_distance <= 0)
  6750. max_distance = 500;
  6751. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6752. if (packet) {
  6753. float unknown2_3 = 0;
  6754. int8 placement_mode = 0;
  6755. if (type == "wall") {
  6756. placement_mode = 2;
  6757. unknown2_3 = 150;
  6758. }
  6759. else if (type == "ceiling")
  6760. placement_mode = 1;
  6761. packet->setDataByName("placement_mode", placement_mode);
  6762. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6763. packet->setDataByName("model_type", spawn->GetModelType());
  6764. packet->setDataByName("unknown", 1); //size
  6765. packet->setDataByName("unknown2", 1); //size 2
  6766. packet->setDataByName("unknown2", .5, 1); //size 3
  6767. packet->setDataByName("unknown2", 3, 2);
  6768. packet->setDataByName("unknown2", unknown2_3, 3);
  6769. packet->setDataByName("max_distance", max_distance);
  6770. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6771. client->QueuePacket(packet->serialize());
  6772. safe_delete(packet);
  6773. }
  6774. return 0;
  6775. }
  6776. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6777. if (!lua_interface)
  6778. return 0;
  6779. Item* item = lua_interface->GetItem(state);
  6780. if (!item) {
  6781. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6782. return 0;
  6783. }
  6784. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6785. return 1;
  6786. }
  6787. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6788. if (!lua_interface)
  6789. return 0;
  6790. Spawn* spawn = lua_interface->GetSpawn(state);
  6791. if (!spawn) {
  6792. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6793. return 0;
  6794. }
  6795. if (spawn->GetZone())
  6796. spawn->GetZone()->AddTransportSpawn(spawn);
  6797. return 0;
  6798. }
  6799. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  6800. if (!lua_interface)
  6801. return 0;
  6802. Spawn* spawn = lua_interface->GetSpawn(state);
  6803. if (!spawn) {
  6804. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6805. return 0;
  6806. }
  6807. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  6808. return 1;
  6809. }
  6810. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6811. if (!lua_interface)
  6812. return 0;
  6813. Skill* skill = lua_interface->GetSkill(state);
  6814. if (!skill) {
  6815. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6816. return 0;
  6817. }
  6818. lua_interface->SetInt32Value(state, skill->current_val);
  6819. return 1;
  6820. }
  6821. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6822. if (!lua_interface)
  6823. return 0;
  6824. Skill* skill = lua_interface->GetSkill(state);
  6825. if (!skill) {
  6826. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6827. return 0;
  6828. }
  6829. lua_interface->SetInt32Value(state, skill->max_val);
  6830. return 1;
  6831. }
  6832. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6833. if (!lua_interface)
  6834. return 0;
  6835. Skill* skill = lua_interface->GetSkill(state);
  6836. if (!skill) {
  6837. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6841. return 1;
  6842. }
  6843. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6844. if (!lua_interface)
  6845. return 0;
  6846. Skill* skill = lua_interface->GetSkill(state);
  6847. int16 value = lua_interface->GetInt16Value(state, 2);
  6848. if (!skill) {
  6849. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6850. return 0;
  6851. }
  6852. skill->max_val = value;
  6853. if (skill->max_val < skill->current_val)
  6854. skill->current_val = skill->max_val;
  6855. return 0;
  6856. }
  6857. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6858. if (!lua_interface)
  6859. return 0;
  6860. Skill* skill = lua_interface->GetSkill(state);
  6861. int16 value = lua_interface->GetInt16Value(state, 2);
  6862. if (!skill) {
  6863. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6864. return 0;
  6865. }
  6866. if (value > skill->max_val)
  6867. skill->current_val = skill->max_val;
  6868. else
  6869. skill->current_val = value;
  6870. return 0;
  6871. }
  6872. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6873. if (!lua_interface)
  6874. return 0;
  6875. Spawn* player = lua_interface->GetSpawn(state);
  6876. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6877. if (skill_id > 0 && player && player->IsPlayer()) {
  6878. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6879. return 1;
  6880. }
  6881. return 0;
  6882. }
  6883. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6884. if (!lua_interface)
  6885. return 0;
  6886. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6887. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6888. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6889. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6890. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6891. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6892. if (player_spawn && player_spawn->IsPlayer()) {
  6893. Player* player = (Player*)player_spawn;
  6894. bool added = false;
  6895. if (!player->skill_list.HasSkill(skill_id)) {
  6896. player->AddSkill(skill_id, current_val, max_val, true);
  6897. added = true;
  6898. }
  6899. if (!more_to_add) { //need to send update regardless, even if THIS skill wasn't added, otherwise if you have a list and the last item wasn't added but the previous ones were, it wouldn't send the update
  6900. Client* client = player->GetClient();
  6901. if (client) {
  6902. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6903. if (packet)
  6904. client->QueuePacket(packet);
  6905. }
  6906. }
  6907. if (added) {
  6908. lua_interface->SetBooleanValue(state, true);
  6909. return 1;
  6910. }
  6911. }
  6912. else {
  6913. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6914. }
  6915. }
  6916. else {
  6917. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6918. }
  6919. lua_interface->SetBooleanValue(state, false);
  6920. return 1;
  6921. }
  6922. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6923. if (!lua_interface)
  6924. return 0;
  6925. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6926. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6927. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6928. if (skill_id > 0) {
  6929. if (player_spawn && player_spawn->IsPlayer()) {
  6930. Player* player = (Player*)player_spawn;
  6931. if (player->skill_list.HasSkill(skill_id)) {
  6932. player->RemovePlayerSkill(skill_id);
  6933. if (!more_to_remove) {
  6934. Client* client = player->GetClient();
  6935. if (client) {
  6936. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6937. if (packet)
  6938. client->QueuePacket(packet);
  6939. }
  6940. }
  6941. }
  6942. }
  6943. else {
  6944. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6945. }
  6946. }
  6947. else {
  6948. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6949. }
  6950. return 0;
  6951. }
  6952. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6953. if (!lua_interface)
  6954. return 0;
  6955. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6956. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6957. int16 amount = lua_interface->GetInt8Value(state, 3);
  6958. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6959. if (amount > 0 && skill_type < 100) {
  6960. if (player_spawn && player_spawn->IsPlayer()) {
  6961. Player* player = (Player*)player_spawn;
  6962. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6963. if (!more_to_increase) {
  6964. Client* client = player->GetClient();
  6965. if (client) {
  6966. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6967. if (packet)
  6968. client->QueuePacket(packet);
  6969. }
  6970. }
  6971. }
  6972. else {
  6973. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6974. }
  6975. }
  6976. else {
  6977. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6978. }
  6979. return 0;
  6980. }
  6981. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6982. if (!lua_interface)
  6983. return 0;
  6984. Spawn* spawn = lua_interface->GetSpawn(state);
  6985. string name = lua_interface->GetStringValue(state, 2);
  6986. if (!spawn) {
  6987. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6988. return 0;
  6989. }
  6990. if (!spawn->IsEntity()) {
  6991. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6992. return 0;
  6993. }
  6994. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6995. if (skill) {
  6996. lua_interface->SetSkillValue(state, skill);
  6997. return 1;
  6998. }
  6999. return 0;
  7000. }
  7001. int EQ2Emu_lua_AddProc(lua_State* state) {
  7002. if (!lua_interface)
  7003. return 0;
  7004. Spawn* spawn = lua_interface->GetSpawn(state);
  7005. int8 type = lua_interface->GetInt8Value(state, 2);
  7006. float chance = lua_interface->GetFloatValue(state, 3);
  7007. Item* item = lua_interface->GetItem(state, 4);
  7008. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7009. LuaSpell* spell = 0;
  7010. if (!spawn && (!spell || !use_all_spelltargets)) {
  7011. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7012. return 0;
  7013. }
  7014. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7015. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7016. return 0;
  7017. }
  7018. if (!item)
  7019. spell = lua_interface->GetCurrentSpell(state);
  7020. if (!item && !spell) {
  7021. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7022. return 0;
  7023. }
  7024. if (spell && use_all_spelltargets) {
  7025. Spawn* target;
  7026. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7027. for (int8 i = 0; i < spell->targets.size(); i++) {
  7028. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7029. if (!target || !target->IsEntity())
  7030. continue;
  7031. ((Entity*)target)->AddProc(type, chance, item, spell);
  7032. }
  7033. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7034. }
  7035. else
  7036. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7037. return 0;
  7038. }
  7039. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7040. if (!lua_interface)
  7041. return 0;
  7042. Spawn* spawn = lua_interface->GetSpawn(state);
  7043. Item* item = lua_interface->GetItem(state, 2);
  7044. LuaSpell* spell = 0;
  7045. if (!spawn) {
  7046. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7047. return 0;
  7048. }
  7049. if (!spawn->IsEntity()) {
  7050. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7051. return 0;
  7052. }
  7053. if (!item)
  7054. spell = lua_interface->GetCurrentSpell(state);
  7055. if (!item && !spell) {
  7056. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7057. return 0;
  7058. }
  7059. if (spell) {
  7060. Spawn* target;
  7061. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7062. for (int8 i = 0; i < spell->targets.size(); i++) {
  7063. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7064. if (!target || !target->IsEntity())
  7065. continue;
  7066. ((Entity*)target)->RemoveProc(item, spell);
  7067. }
  7068. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7069. spell->caster->RemoveProc(item, spell);
  7070. }
  7071. else
  7072. ((Entity*)spawn)->RemoveProc(item, spell);
  7073. return 0;
  7074. }
  7075. int EQ2Emu_lua_Knockback(lua_State* state) {
  7076. if (!lua_interface)
  7077. return 0;
  7078. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7079. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7080. int32 duration = lua_interface->GetInt32Value(state, 3);
  7081. float vertical = lua_interface->GetFloatValue(state, 4);
  7082. float horizontal = lua_interface->GetFloatValue(state, 5);
  7083. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7084. if (!target_spawn) {
  7085. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7086. return 0;
  7087. }
  7088. if (!spawn) {
  7089. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7090. return 0;
  7091. }
  7092. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7093. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7094. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7095. if (packet) {
  7096. packet->setDataByName("target_x", target_spawn->GetX());
  7097. packet->setDataByName("target_y", target_spawn->GetY());
  7098. packet->setDataByName("target_z", target_spawn->GetZ());
  7099. packet->setDataByName("vertical_movement", vertical);
  7100. packet->setDataByName("horizontal_movement", horizontal);
  7101. if (use_heading)
  7102. packet->setDataByName("use_player_heading", 1);
  7103. client->QueuePacket(packet->serialize());
  7104. }
  7105. safe_delete(packet);
  7106. }
  7107. return 0;
  7108. }
  7109. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7110. if (!lua_interface)
  7111. return 0;
  7112. Spawn* spawn = lua_interface->GetSpawn(state);
  7113. if (!spawn) {
  7114. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7115. return 0;
  7116. }
  7117. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7118. return 1;
  7119. }
  7120. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7121. if (!lua_interface)
  7122. return 0;
  7123. Spawn* caster = lua_interface->GetSpawn(state);
  7124. Spawn* target = lua_interface->GetSpawn(state, 2);
  7125. string name = lua_interface->GetStringValue(state, 3);
  7126. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7127. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7128. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7129. string success_msg = lua_interface->GetStringValue(state, 7);
  7130. string effect_msg = lua_interface->GetStringValue(state, 8);
  7131. if (!caster) {
  7132. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7133. return 0;
  7134. }
  7135. if (!caster->IsEntity()) {
  7136. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7137. return 0;
  7138. }
  7139. if (!target) {
  7140. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7141. return 0;
  7142. }
  7143. if (!target->IsEntity()) {
  7144. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7145. return 0;
  7146. }
  7147. if (name.length() == 0) {
  7148. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7149. return 0;
  7150. }
  7151. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7152. return 0;
  7153. }
  7154. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7155. if (!lua_interface)
  7156. return 0;
  7157. string name = lua_interface->GetStringValue(state);
  7158. if (name.length() == 0) {
  7159. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7160. return 0;
  7161. }
  7162. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7163. if (!skill) {
  7164. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7165. return 0;
  7166. }
  7167. lua_interface->SetInt32Value(state, skill->skill_id);
  7168. return 1;
  7169. }
  7170. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7171. if (!lua_interface)
  7172. return 0;
  7173. Spawn* spawn = lua_interface->GetSpawn(state);
  7174. if (!spawn) {
  7175. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7176. return 0;
  7177. }
  7178. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7179. return 1;
  7180. }
  7181. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7182. if (!lua_interface)
  7183. return 0;
  7184. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7185. if (!luaspell) {
  7186. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7187. return 0;
  7188. }
  7189. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7190. return 1;
  7191. }
  7192. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7193. if (!lua_interface)
  7194. return 0;
  7195. Spawn* spawn = lua_interface->GetSpawn(state);
  7196. Spawn* target = lua_interface->GetSpawn(state, 2);
  7197. if (!spawn) {
  7198. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7199. return 0;
  7200. }
  7201. if (!spawn->IsEntity()) {
  7202. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7203. return 0;
  7204. }
  7205. if (!target) {
  7206. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7207. return 0;
  7208. }
  7209. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7210. return 1;
  7211. }
  7212. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7213. if (!lua_interface)
  7214. return 0;
  7215. Spawn* spawn = lua_interface->GetSpawn(state);
  7216. Spawn* target = lua_interface->GetSpawn(state, 2);
  7217. if (!spawn) {
  7218. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7219. return 0;
  7220. }
  7221. if (!spawn->IsEntity()) {
  7222. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7223. return 0;
  7224. }
  7225. if (!target) {
  7226. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7227. return 0;
  7228. }
  7229. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7230. return 1;
  7231. }
  7232. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7233. if (!lua_interface)
  7234. return 0;
  7235. Item* item = lua_interface->GetItem(state);
  7236. if (!item) {
  7237. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7238. return 0;
  7239. }
  7240. lua_interface->SetInt32Value(state, item->details.count);
  7241. return 1;
  7242. }
  7243. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7244. if (!lua_interface)
  7245. return 0;
  7246. Item* item = lua_interface->GetItem(state);
  7247. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7248. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7249. if (!item) {
  7250. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7251. return 0;
  7252. }
  7253. if (!owner) {
  7254. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7255. return 0;
  7256. }
  7257. if (!owner->IsPlayer()) {
  7258. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7259. return 0;
  7260. }
  7261. if (item->stack_count < new_count) {
  7262. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7263. return 0;
  7264. }
  7265. if (new_count > 0) {
  7266. item->details.count = new_count;
  7267. item->save_needed = true;
  7268. }
  7269. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7270. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7271. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7272. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7273. else
  7274. {
  7275. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7276. return 0;
  7277. }
  7278. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7279. if (!client)
  7280. return 0;
  7281. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7282. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7283. if (app)
  7284. client->QueuePacket(app);
  7285. return 0;
  7286. }
  7287. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7288. if (!lua_interface)
  7289. return 0;
  7290. int32 time = lua_interface->GetInt32Value(state);
  7291. string function = lua_interface->GetStringValue(state, 2);
  7292. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7293. Spawn* target = lua_interface->GetSpawn(state, 4);
  7294. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7295. if (time == 0) {
  7296. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7297. return 0;
  7298. }
  7299. if (function.length() == 0) {
  7300. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7301. return 0;
  7302. }
  7303. if (!spell) {
  7304. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7305. return 0;
  7306. }
  7307. SpellScriptTimer* timer = new SpellScriptTimer;
  7308. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7309. #ifdef WIN32
  7310. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7311. #else
  7312. bzero(timer, sizeof(SpellScriptTimer));
  7313. #endif*/
  7314. timer->caster = 0;
  7315. timer->deleteWhenDone = false;
  7316. timer->target = 0;
  7317. timer->time = Timer::GetCurrentTime2() + time;
  7318. timer->customFunction = function;
  7319. timer->spell = spell;
  7320. if (caster)
  7321. timer->caster = caster->GetID();
  7322. if (target)
  7323. timer->target = target->GetID();
  7324. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7325. return 0;
  7326. }
  7327. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7328. if (!lua_interface)
  7329. return 0;
  7330. float hp_perc = lua_interface->GetFloatValue(state);
  7331. float power_perc = lua_interface->GetFloatValue(state, 2);
  7332. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7333. Spawn* target = lua_interface->GetSpawn(state, 4);
  7334. string heal_name = lua_interface->GetStringValue(state, 5);
  7335. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7336. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7337. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7338. if (!spell) {
  7339. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7340. return 0;
  7341. }
  7342. Entity* caster = spell->caster;
  7343. if (!caster) {
  7344. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7345. return 0;
  7346. }
  7347. Client* client = 0;
  7348. PendingResurrection* rez = 0;
  7349. ZoneServer* zone = spell->caster->GetZone();
  7350. if (!target) {
  7351. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7352. if (spell->targets.size() > 0) {
  7353. vector<int32> spell_targets = spell->targets;
  7354. for (int8 i = 0; i < spell_targets.size(); i++) {
  7355. target = zone->GetSpawnByID(spell_targets.at(i));
  7356. if (!target)
  7357. continue;
  7358. if (!target->IsPlayer())
  7359. continue;
  7360. client = target->GetZone()->GetClientBySpawn(target);
  7361. if (!client)
  7362. continue;
  7363. rez = client->GetCurrentRez();
  7364. if (rez->active)
  7365. continue;
  7366. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7367. rez->active = true;
  7368. rez->caster = caster;
  7369. rez->expire_timer = new Timer;
  7370. int32 duration = spell->spell->GetSpellDuration();
  7371. rez->expire_timer->Start(duration * 100);
  7372. rez->hp_perc = hp_perc;
  7373. rez->mp_perc = power_perc;
  7374. rez->range = spell->spell->GetSpellData()->range;
  7375. rez->spell_name = spell->spell->GetName();
  7376. if (heal_name.length() > 0)
  7377. rez->heal_name = heal_name;
  7378. else
  7379. rez->heal_name = rez->spell_name;
  7380. rez->no_calcs = no_calcs;
  7381. rez->crit_mod = crit_mod;
  7382. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7383. if (send_window)
  7384. client->SendResurrectionWindow();
  7385. else {
  7386. target->GetZone()->ResurrectSpawn(target, client);
  7387. rez->should_delete = true;
  7388. }
  7389. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7390. }
  7391. }
  7392. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7393. }
  7394. else {
  7395. client = target->GetZone()->GetClientBySpawn(target);
  7396. if (!client)
  7397. return 0;
  7398. rez = client->GetCurrentRez();
  7399. if (rez->active)
  7400. return 0;
  7401. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7402. rez->active = true;
  7403. rez->caster = caster;
  7404. rez->expire_timer = new Timer;
  7405. int32 duration = spell->spell->GetSpellDuration();
  7406. rez->expire_timer->Start(duration * 100);
  7407. rez->hp_perc = hp_perc;
  7408. rez->mp_perc = power_perc;
  7409. rez->range = spell->spell->GetSpellData()->range;
  7410. rez->spell_name = spell->spell->GetName();
  7411. if (heal_name.length() > 0)
  7412. rez->heal_name = heal_name;
  7413. else
  7414. rez->heal_name = rez->spell_name;
  7415. rez->no_calcs = no_calcs;
  7416. rez->crit_mod = crit_mod;
  7417. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7418. if (send_window)
  7419. client->SendResurrectionWindow();
  7420. else {
  7421. target->GetZone()->ResurrectSpawn(target, client);
  7422. rez->should_delete = true;
  7423. }
  7424. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7425. }
  7426. return 0;
  7427. }
  7428. int EQ2Emu_lua_SetVision(lua_State* state) {
  7429. if (!lua_interface)
  7430. return 0;
  7431. Spawn* spawn = lua_interface->GetSpawn(state);
  7432. int8 vision = lua_interface->GetInt8Value(state, 2);
  7433. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7434. if (!spawn) {
  7435. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7436. return 0;
  7437. }
  7438. if (!spawn->IsEntity()) {
  7439. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7440. return 0;
  7441. }
  7442. if (spell && spell->targets.size() > 0) {
  7443. ZoneServer* zone = spell->caster->GetZone();
  7444. for (int8 i = 0; i < spell->targets.size(); i++) {
  7445. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7446. if (target && target->IsEntity()) {
  7447. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7448. if (target->IsPlayer())
  7449. ((Player*)target)->SetCharSheetChanged(true);
  7450. }
  7451. }
  7452. }
  7453. else {
  7454. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7455. if (spawn->IsPlayer())
  7456. ((Player*)spawn)->SetCharSheetChanged(true);
  7457. }
  7458. return 0;
  7459. }
  7460. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7461. if (!lua_interface)
  7462. return 0;
  7463. Spawn* spawn = lua_interface->GetSpawn(state);
  7464. float intensity = lua_interface->GetFloatValue(state, 2);
  7465. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7466. if (!spawn) {
  7467. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7468. return 0;
  7469. }
  7470. if (!spawn->IsEntity()) {
  7471. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7472. return 0;
  7473. }
  7474. if (spell && spell->targets.size() > 0) {
  7475. ZoneServer* zone = spell->caster->GetZone();
  7476. for (int8 i = 0; i < spell->targets.size(); i++) {
  7477. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7478. if (target && target->IsEntity()) {
  7479. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7480. if (target->IsPlayer())
  7481. ((Player*)target)->SetCharSheetChanged(true);
  7482. }
  7483. }
  7484. }
  7485. else {
  7486. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7487. if (spawn->IsPlayer())
  7488. ((Player*)spawn)->SetCharSheetChanged(true);
  7489. }
  7490. return 0;
  7491. }
  7492. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7493. if (!lua_interface)
  7494. return 0;
  7495. Spawn* spawn = lua_interface->GetSpawn(state);
  7496. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7497. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7498. if (!spawn) {
  7499. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7500. return 0;
  7501. }
  7502. if (!spawn->IsEntity()) {
  7503. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7504. return 0;
  7505. }
  7506. if (spell && spell->targets.size() > 0) {
  7507. ZoneServer* zone = spell->caster->GetZone();
  7508. for (int8 i = 0; i < spell->targets.size(); i++) {
  7509. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7510. if (target && target->IsEntity()) {
  7511. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7512. if (target->IsPlayer())
  7513. ((Player*)target)->SetCharSheetChanged(true);
  7514. }
  7515. }
  7516. }
  7517. else {
  7518. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7519. if (spawn->IsPlayer())
  7520. ((Player*)spawn)->SetCharSheetChanged(true);
  7521. }
  7522. return 0;
  7523. }
  7524. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7525. if (!lua_interface)
  7526. return 0;
  7527. Item* item = lua_interface->GetItem(state);
  7528. int8 type = lua_interface->GetInt32Value(state, 2);
  7529. if (!item) {
  7530. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7531. return 0;
  7532. }
  7533. if (type == 1)
  7534. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7535. else if (type == 2)
  7536. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7537. return 1;
  7538. }
  7539. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7540. if (!lua_interface)
  7541. return 0;
  7542. Spawn* target = lua_interface->GetSpawn(state);
  7543. float val = lua_interface->GetFloatValue(state, 2);
  7544. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7545. // Added from Gangrenous post
  7546. if (spell && spell->resisted)
  7547. return 0;
  7548. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7549. if (val > 1.0f)
  7550. val = 1.0f - (val / 100.0f);
  7551. if (spell && spell->spell && spell->targets.size() > 0) {
  7552. ZoneServer* zone = spell->caster->GetZone();
  7553. for (int32 i = 0; i != spell->targets.size(); i++) {
  7554. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7555. if (spawn && spawn->IsEntity()) {
  7556. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7557. if (spawn->IsPlayer())
  7558. ((Player*)spawn)->SetCharSheetChanged(true);
  7559. }
  7560. }
  7561. }
  7562. else {
  7563. if (target && target->IsEntity()) {
  7564. ((Entity*)target)->SetSpeedMultiplier(val);
  7565. if (target->IsPlayer())
  7566. ((Player*)target)->SetCharSheetChanged(true);
  7567. }
  7568. }
  7569. return 0;
  7570. }
  7571. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7572. if (!lua_interface)
  7573. return 0;
  7574. Spawn* spawn = lua_interface->GetSpawn(state);
  7575. int16 model = lua_interface->GetInt16Value(state, 2);
  7576. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7577. if (spell && spell->spell && spell->targets.size() > 0) {
  7578. ZoneServer* zone = spell->caster->GetZone();
  7579. for (int32 i = 0; i < spell->targets.size(); i++) {
  7580. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7581. if (target)
  7582. target->SetIllusionModel(model);
  7583. }
  7584. }
  7585. else {
  7586. if (!spawn) {
  7587. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7588. return 0;
  7589. }
  7590. spawn->SetIllusionModel(model);
  7591. }
  7592. return 0;
  7593. }
  7594. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7595. if (!lua_interface)
  7596. return 0;
  7597. Spawn* spawn = lua_interface->GetSpawn(state);
  7598. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7599. if (spell && spell->spell && spell->targets.size() > 0) {
  7600. ZoneServer* zone = spell->caster->GetZone();
  7601. for (int32 i = 0; i < spell->targets.size(); i++) {
  7602. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7603. if (target)
  7604. target->SetIllusionModel(0);
  7605. }
  7606. }
  7607. else {
  7608. if (!spawn) {
  7609. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7610. return 0;
  7611. }
  7612. spawn->SetIllusionModel(0);
  7613. }
  7614. return 0;
  7615. }
  7616. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7617. if (!lua_interface)
  7618. return 0;
  7619. Spawn* caster = lua_interface->GetSpawn(state);
  7620. Spawn* target = lua_interface->GetSpawn(state, 2);
  7621. float chance = lua_interface->GetFloatValue(state, 3);
  7622. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7623. if (!caster) {
  7624. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7625. return 0;
  7626. }
  7627. if (!caster->IsEntity()) {
  7628. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7629. return 0;
  7630. }
  7631. if (!target) {
  7632. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7633. return 0;
  7634. }
  7635. if (!target->IsEntity()) {
  7636. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7637. return 0;
  7638. }
  7639. if (chance <= 0) {
  7640. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7641. return 0;
  7642. }
  7643. if (!spell) {
  7644. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7645. return 0;
  7646. }
  7647. if (((Entity*)caster)->GetThreatTransfer()) {
  7648. return 0;
  7649. }
  7650. ThreatTransfer* transfer = new ThreatTransfer;
  7651. transfer->Target = target->GetID();
  7652. transfer->Amount = chance;
  7653. transfer->Spell = spell;
  7654. ((Entity*)caster)->SetThreatTransfer(transfer);
  7655. return 0;
  7656. }
  7657. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7658. if (!lua_interface)
  7659. return 0;
  7660. Spawn* spawn = lua_interface->GetSpawn(state);
  7661. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7662. if (!spawn) {
  7663. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7664. return 0;
  7665. }
  7666. if (!spell) {
  7667. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7668. return 0;
  7669. }
  7670. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7671. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7672. ((Entity*)spawn)->SetThreatTransfer(0);
  7673. safe_delete(transfer);
  7674. }
  7675. return 0;
  7676. }
  7677. int EQ2Emu_lua_CureByType(lua_State* state) {
  7678. if (!lua_interface)
  7679. return 0;
  7680. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7681. if (!spell) {
  7682. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7683. return 0;
  7684. }
  7685. int8 cure_count = lua_interface->GetInt8Value(state);
  7686. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7687. string cure_name = lua_interface->GetStringValue(state, 3);
  7688. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7689. Spawn* target = lua_interface->GetSpawn(state, 5);
  7690. if (target) {
  7691. if (!target->IsEntity()) {
  7692. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7693. return 0;
  7694. }
  7695. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7696. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7697. }
  7698. else {
  7699. ZoneServer* zone = spell->caster->GetZone();
  7700. vector<int32> targets = spell->targets;
  7701. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7702. for (int8 i = 0; i < targets.size(); i++) {
  7703. target = zone->GetSpawnByID(targets.at(i));
  7704. if (!target || !target->IsEntity())
  7705. continue;
  7706. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7707. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7708. }
  7709. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7710. }
  7711. return 0;
  7712. }
  7713. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7714. if (!lua_interface)
  7715. return 0;
  7716. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7717. if (!spell) {
  7718. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7719. return 0;
  7720. }
  7721. int8 cure_count = lua_interface->GetInt8Value(state);
  7722. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7723. string cure_name = lua_interface->GetStringValue(state, 3);
  7724. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7725. Spawn* target = lua_interface->GetSpawn(state, 5);
  7726. if (target) {
  7727. if (!target->IsEntity()) {
  7728. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7729. return 0;
  7730. }
  7731. if (((Entity*)target)->GetDetCount() > 0)
  7732. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7733. }
  7734. else {
  7735. ZoneServer* zone = spell->caster->GetZone();
  7736. vector<int32> targets = spell->targets;
  7737. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7738. for (int8 i = 0; i < targets.size(); i++) {
  7739. target = zone->GetSpawnByID(targets.at(i));
  7740. if (!target || !target->IsEntity())
  7741. continue;
  7742. if (((Entity*)target)->GetDetCount() > 0)
  7743. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7744. }
  7745. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7746. }
  7747. return 0;
  7748. }
  7749. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7750. if (!lua_interface)
  7751. return 0;
  7752. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7753. if (!spell) {
  7754. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7755. return 0;
  7756. }
  7757. if (!spell->caster) {
  7758. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7759. return 0;
  7760. }
  7761. if (!spell->caster->GetZone()) {
  7762. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7763. return 0;
  7764. }
  7765. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7766. return 0;
  7767. }
  7768. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7769. if (!lua_interface)
  7770. return 0;
  7771. Spawn* spawn = lua_interface->GetSpawn(state);
  7772. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7773. if (!spell) {
  7774. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7775. return 0;
  7776. }
  7777. if (spawn && spawn->IsEntity())
  7778. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7779. else {
  7780. ZoneServer* zone = spell->caster->GetZone();
  7781. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7782. for (int32 i = 0; i < spell->targets.size(); i++) {
  7783. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7784. if (!spawn || !spawn->IsEntity())
  7785. continue;
  7786. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7787. }
  7788. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7789. }
  7790. return 0;
  7791. }
  7792. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7793. if (!lua_interface)
  7794. return 0;
  7795. Spawn* spawn = lua_interface->GetSpawn(state);
  7796. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7797. if (!spell) {
  7798. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7799. return 0;
  7800. }
  7801. if (spawn && spawn->IsEntity())
  7802. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7803. else {
  7804. ZoneServer* zone = spell->caster->GetZone();
  7805. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7806. for (int32 i = 0; i < spell->targets.size(); i++) {
  7807. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7808. if (!spawn || !spawn->IsEntity())
  7809. continue;
  7810. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7811. }
  7812. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7813. }
  7814. return 0;
  7815. }
  7816. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7817. if (!lua_interface)
  7818. return 0;
  7819. Spawn* caster = lua_interface->GetSpawn(state);
  7820. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7821. if (!caster) {
  7822. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7823. return 0;
  7824. }
  7825. if (!caster->IsPlayer()) {
  7826. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7827. return 0;
  7828. }
  7829. Spawn* target = caster->GetTarget();
  7830. if (!target) {
  7831. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7832. return 0;
  7833. }
  7834. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7835. if (!client) {
  7836. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7837. return 0;
  7838. }
  7839. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7840. if (ho) {
  7841. ho->SetTarget(target->GetID());
  7842. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7843. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7844. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7845. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7846. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7847. deque<GroupMemberInfo*>::iterator itr;
  7848. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7849. if (group)
  7850. {
  7851. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7852. deque<GroupMemberInfo*>* members = group->GetMembers();
  7853. for (itr = members->begin(); itr != members->end(); itr++) {
  7854. if ((*itr)->client)
  7855. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7856. }
  7857. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7858. }
  7859. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7860. }
  7861. else
  7862. safe_delete(ho);
  7863. }
  7864. else {
  7865. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7866. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7867. }
  7868. else
  7869. safe_delete(ho);
  7870. }
  7871. }
  7872. return 0;
  7873. }
  7874. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7875. if (!lua_interface)
  7876. return 0;
  7877. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7878. if (!spell) {
  7879. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7880. return 0;
  7881. }
  7882. int16 triggerCount = lua_interface->GetInt16Value(state);
  7883. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7884. if (!triggerCount) {
  7885. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7886. return 0;
  7887. }
  7888. spell->num_triggers = triggerCount;
  7889. spell->had_triggers = true;
  7890. spell->cancel_after_all_triggers = cancel_after_triggers;
  7891. return 0;
  7892. }
  7893. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7894. if (!lua_interface)
  7895. return 0;
  7896. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7897. if (!spell) {
  7898. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7899. return 0;
  7900. }
  7901. lua_interface->SetInt32Value(state, spell->num_triggers);
  7902. return 1;
  7903. }
  7904. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7905. if (!lua_interface)
  7906. return 0;
  7907. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7908. if (!spell) {
  7909. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7910. return 0;
  7911. }
  7912. int16 remove_count = lua_interface->GetInt16Value(state);
  7913. if (!remove_count)
  7914. remove_count = 1;
  7915. if (remove_count >= spell->num_triggers) {
  7916. spell->num_triggers = 0;
  7917. if (spell->cancel_after_all_triggers)
  7918. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7919. }
  7920. else {
  7921. spell->num_triggers -= remove_count;
  7922. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7923. }
  7924. return 0;
  7925. }
  7926. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7927. if (!lua_interface)
  7928. return 0;
  7929. Spawn* spawn = lua_interface->GetSpawn(state);
  7930. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7931. if (!spawn) {
  7932. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7933. return 0;
  7934. }
  7935. if (!copy_spawn) {
  7936. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7937. return 0;
  7938. }
  7939. spawn->CopySpawnAppearance(copy_spawn);
  7940. return 0;
  7941. }
  7942. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7943. Spawn* spawn = lua_interface->GetSpawn(state);
  7944. int8 type = lua_interface->GetInt8Value(state, 2);
  7945. if (!spawn) {
  7946. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7947. return 0;
  7948. }
  7949. else if (!spawn->IsEntity()) {
  7950. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7951. return 0;
  7952. }
  7953. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7954. return 1;
  7955. }
  7956. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7957. if (!lua_interface)
  7958. return 0;
  7959. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7960. int8 type = lua_interface->GetInt8Value(state);
  7961. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7962. if (!spell) {
  7963. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7964. return 0;
  7965. }
  7966. if (spawn) {
  7967. if (!spawn->IsEntity()) {
  7968. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7969. return 0;
  7970. }
  7971. Entity* entity = ((Entity*)spawn);
  7972. entity->AddImmunity(spell, type);
  7973. }
  7974. else {
  7975. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7976. for (int8 i = 0; i < spell->targets.size(); i++) {
  7977. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7978. if (!spawn || !spawn->IsEntity())
  7979. continue;
  7980. Entity* entity = ((Entity*)spawn);
  7981. entity->AddImmunity(spell, type);
  7982. }
  7983. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7984. }
  7985. return 0;
  7986. }
  7987. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7988. if (!lua_interface)
  7989. return 0;
  7990. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7991. int8 type = lua_interface->GetInt8Value(state);
  7992. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7993. if (!spell) {
  7994. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7995. return 0;
  7996. }
  7997. if (spawn) {
  7998. if (!spawn->IsEntity()) {
  7999. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8000. return 0;
  8001. }
  8002. Entity* entity = ((Entity*)spawn);
  8003. entity->RemoveImmunity(spell, type);
  8004. }
  8005. else {
  8006. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8007. for (int8 i = 0; i < spell->targets.size(); i++) {
  8008. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8009. if (!spawn || !spawn->IsEntity())
  8010. continue;
  8011. Entity* entity = ((Entity*)spawn);
  8012. entity->RemoveImmunity(spell, type);
  8013. }
  8014. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8015. }
  8016. return 0;
  8017. }
  8018. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8019. if (!lua_interface)
  8020. return 0;
  8021. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8022. if (!spell) {
  8023. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8024. return 0;
  8025. }
  8026. float snare = lua_interface->GetFloatValue(state);
  8027. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8028. // convert the val to the speed multipler value (100 - val)
  8029. float val = 100.0 - snare;
  8030. val /= 100.0;
  8031. if (spawn) {
  8032. if (!spawn->IsEntity()) {
  8033. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8034. return 0;
  8035. }
  8036. ((Entity*)spawn)->SetSnareValue(spell, val);
  8037. }
  8038. else {
  8039. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8040. for (int8 i = 0; i < spell->targets.size(); i++) {
  8041. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8042. if (!spawn || !spawn->IsEntity())
  8043. continue;
  8044. ((Entity*)spawn)->SetSnareValue(spell, val);
  8045. }
  8046. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8047. }
  8048. return 0;
  8049. }
  8050. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8051. if (!lua_interface)
  8052. return 0;
  8053. Spawn* spawn = lua_interface->GetSpawn(state);
  8054. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8055. if (!spawn) {
  8056. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8057. return 0;
  8058. }
  8059. if (race_id == 0) {
  8060. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8061. return 0;
  8062. }
  8063. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8064. return 1;
  8065. }
  8066. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8067. if (!lua_interface)
  8068. return 0;
  8069. Spawn* spawn = lua_interface->GetSpawn(state);
  8070. if (!spawn) {
  8071. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8072. return 0;
  8073. }
  8074. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8075. return 1;
  8076. }
  8077. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8078. if (!lua_interface)
  8079. return 0;
  8080. Spawn* spawn = lua_interface->GetSpawn(state);
  8081. if (!spawn) {
  8082. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8083. return 0;
  8084. }
  8085. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8086. return 1;
  8087. }
  8088. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8089. if (!lua_interface)
  8090. return 0;
  8091. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8092. if (!spell) {
  8093. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8094. return 0;
  8095. }
  8096. lua_interface->SetStringValue(state, spell->spell->GetName());
  8097. return 1;
  8098. }
  8099. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8100. if (!lua_interface)
  8101. return 0;
  8102. Quest* quest = lua_interface->GetQuest(state);
  8103. if (!quest) {
  8104. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8105. return 0;
  8106. }
  8107. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8108. return 1;
  8109. }
  8110. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8111. if (!lua_interface)
  8112. return 0;
  8113. Quest* quest = lua_interface->GetQuest(state);
  8114. int32 flags = lua_interface->GetInt32Value(state, 2);
  8115. if (!quest) {
  8116. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8117. return 0;
  8118. }
  8119. quest->SetQuestFlags(flags);
  8120. return 0;
  8121. }
  8122. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8123. if (!lua_interface)
  8124. return 0;
  8125. Quest* quest = lua_interface->GetQuest(state);
  8126. Spawn* player = lua_interface->GetSpawn(state, 2);
  8127. int32 step = lua_interface->GetInt32Value(state, 3);
  8128. int32 duration = lua_interface->GetInt32Value(state, 4);
  8129. string action = lua_interface->GetStringValue(state, 5);
  8130. if (!quest) {
  8131. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8132. return 0;
  8133. }
  8134. if (!player) {
  8135. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8136. return 0;
  8137. }
  8138. if (!player->IsPlayer()) {
  8139. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8140. return 0;
  8141. }
  8142. if (step == 0) {
  8143. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8144. return 0;
  8145. }
  8146. if (duration == 0) {
  8147. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8148. return 0;
  8149. }
  8150. if (action.length() == 0) {
  8151. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8152. return 0;
  8153. }
  8154. Client* client = player->GetZone()->GetClientBySpawn(player);
  8155. if (!client) {
  8156. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8157. return 0;
  8158. }
  8159. quest->SetTimerStep(step);
  8160. quest->AddFailedAction(step, action);
  8161. quest->SetStepTimer(duration);
  8162. client->AddQuestTimer(quest->GetQuestID());
  8163. return 0;
  8164. }
  8165. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8166. if (!lua_interface)
  8167. return 0;
  8168. Quest* quest = lua_interface->GetQuest(state);
  8169. Spawn* player = lua_interface->GetSpawn(state, 2);
  8170. if (!quest) {
  8171. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8172. return 0;
  8173. }
  8174. if (!player) {
  8175. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8176. return 0;
  8177. }
  8178. if (!player->IsPlayer()) {
  8179. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8180. return 0;
  8181. }
  8182. Client* client = player->GetZone()->GetClientBySpawn(player);
  8183. if (!client) {
  8184. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8185. return 0;
  8186. }
  8187. quest->SetTimerStep(0);
  8188. quest->SetStepTimer(0);
  8189. client->RemoveQuestTimer(quest->GetQuestID());
  8190. return 0;
  8191. }
  8192. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8193. if (!lua_interface)
  8194. return 0;
  8195. Spawn* player = lua_interface->GetSpawn(state);
  8196. Quest* quest = lua_interface->GetQuest(state, 2);
  8197. int32 step = lua_interface->GetInt32Value(state, 3);
  8198. if (!player) {
  8199. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8200. return 0;
  8201. }
  8202. if (!player->IsPlayer()) {
  8203. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8204. return 0;
  8205. }
  8206. if (!quest) {
  8207. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8208. return 0;
  8209. }
  8210. if (step == 0) {
  8211. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8212. return 0;
  8213. }
  8214. Client* client = player->GetZone()->GetClientBySpawn(player);
  8215. if (!client) {
  8216. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8217. return 0;
  8218. }
  8219. if (quest->RemoveQuestStep(step, client)) {
  8220. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8221. client->GetCurrentZone()->SendQuestUpdates(client);
  8222. }
  8223. else
  8224. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8225. return 0;
  8226. }
  8227. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8228. if (!lua_interface)
  8229. return 0;
  8230. Quest* quest = lua_interface->GetQuest(state, 1);
  8231. int32 step = lua_interface->GetInt32Value(state, 2);
  8232. string desc = lua_interface->GetStringValue(state, 3);
  8233. string task_group = lua_interface->GetStringValue(state, 4);
  8234. if (!quest) {
  8235. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8236. return 0;
  8237. }
  8238. if (step == 0) {
  8239. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8240. return 0;
  8241. }
  8242. QuestStep* quest_step = quest->GetQuestStep(step);
  8243. if (!quest_step) {
  8244. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. quest_step->SetStepProgress(0);
  8248. quest_step->SetTaskGroup(task_group);
  8249. quest_step->SetDescription(desc);
  8250. return 0;
  8251. }
  8252. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8253. if (!lua_interface)
  8254. return 0;
  8255. Quest* quest = lua_interface->GetQuest(state);
  8256. int32 step = lua_interface->GetInt32Value(state, 2);
  8257. string action = lua_interface->GetStringValue(state, 3);
  8258. if (!quest) {
  8259. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8260. return 0;
  8261. }
  8262. if (step == 0) {
  8263. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8264. return 0;
  8265. }
  8266. if (action.length() == 0) {
  8267. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8268. return 0;
  8269. }
  8270. quest->AddFailedAction(step, action);
  8271. return 0;
  8272. }
  8273. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8274. if (!lua_interface)
  8275. return 0;
  8276. Spawn* player = lua_interface->GetSpawn(state);
  8277. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8278. int32 step = lua_interface->GetInt32Value(state, 3);
  8279. if (!player) {
  8280. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8281. return 0;
  8282. }
  8283. if (!player->IsPlayer()) {
  8284. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8285. return 0;
  8286. }
  8287. if (quest_id == 0) {
  8288. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8289. return 0;
  8290. }
  8291. if (step == 0) {
  8292. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8293. return 0;
  8294. }
  8295. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8296. if (!quest) {
  8297. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8298. return 0;
  8299. }
  8300. quest->StepFailed(step);
  8301. return 0;
  8302. }
  8303. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8304. if (!lua_interface)
  8305. return 0;
  8306. Spawn* player = lua_interface->GetSpawn(state);
  8307. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8308. if (!player) {
  8309. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8310. return 0;
  8311. }
  8312. if (!player->IsPlayer()) {
  8313. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8314. return 0;
  8315. }
  8316. if (quest_id == 0) {
  8317. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8318. return 0;
  8319. }
  8320. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8321. if (!quest) {
  8322. lua_interface->SetInt32Value(state, 0);
  8323. return 1;
  8324. }
  8325. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8326. return 1;
  8327. }
  8328. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8329. if (!lua_interface)
  8330. return 0;
  8331. string name = lua_interface->GetStringValue(state);
  8332. string value = lua_interface->GetStringValue(state, 2);
  8333. string comment = lua_interface->GetStringValue(state, 3);
  8334. if (name.length() == 0) {
  8335. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8336. return 0;
  8337. }
  8338. if (value.length() == 0) {
  8339. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8340. return 0;
  8341. }
  8342. string varname = string("lua_").append(name);
  8343. Variable* var = variables.FindVariable(varname);
  8344. if (var)
  8345. var->SetValue(value.c_str());
  8346. else {
  8347. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8348. variables.AddVariable(var);
  8349. }
  8350. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8351. return 0;
  8352. }
  8353. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8354. if (!lua_interface)
  8355. return 0;
  8356. string name = lua_interface->GetStringValue(state);
  8357. if (name.length() == 0) {
  8358. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8359. return 0;
  8360. }
  8361. string varname = string("lua_").append(name);
  8362. Variable* var = variables.FindVariable(varname);
  8363. if (var)
  8364. lua_interface->SetStringValue(state, var->GetValue());
  8365. else
  8366. lua_interface->SetStringValue(state, "NULL");
  8367. return 1;
  8368. }
  8369. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8370. if (!lua_interface)
  8371. return 0;
  8372. Spawn* player = lua_interface->GetSpawn(state);
  8373. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8374. if (!player) {
  8375. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8376. return 0;
  8377. }
  8378. if (!player->IsPlayer()) {
  8379. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8380. return 0;
  8381. }
  8382. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8383. return 1;
  8384. }
  8385. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8386. if (!lua_interface)
  8387. return 0;
  8388. Spawn* player = lua_interface->GetSpawn(state);
  8389. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8390. if (!player) {
  8391. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8392. return 0;
  8393. }
  8394. if (!player->IsPlayer()) {
  8395. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8396. return 0;
  8397. }
  8398. Language* language = master_languages_list.GetLanguage(language_id);
  8399. if (language)
  8400. {
  8401. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8402. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8403. }
  8404. return 0;
  8405. }
  8406. int EQ2Emu_lua_IsNight(lua_State* state) {
  8407. if (!lua_interface)
  8408. return 0;
  8409. ZoneServer* zone = lua_interface->GetZone(state);
  8410. if (!zone) {
  8411. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8412. return 0;
  8413. }
  8414. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8415. return 1;
  8416. }
  8417. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8418. if (!lua_interface)
  8419. return 0;
  8420. Spawn* spawn = lua_interface->GetSpawn(state);
  8421. if (!spawn) {
  8422. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. if (!spawn->IsWidget()) {
  8426. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8427. return 0;
  8428. }
  8429. ((Widget*)spawn)->SetMultiFloorLift(true);
  8430. if (spawn->GetZone())
  8431. spawn->GetZone()->AddTransportSpawn(spawn);
  8432. return 0;
  8433. }
  8434. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8435. if (!lua_interface)
  8436. return 0;
  8437. Spawn* player = lua_interface->GetSpawn(state);
  8438. int32 path = lua_interface->GetInt32Value(state, 2);
  8439. if (!player) {
  8440. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8441. return 0;
  8442. }
  8443. if (!player->IsPlayer()) {
  8444. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8445. return 0;
  8446. }
  8447. if (path == 0) {
  8448. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8449. return 0;
  8450. }
  8451. Client* client = player->GetZone()->GetClientBySpawn(player);
  8452. if (!client) {
  8453. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8454. return 0;
  8455. }
  8456. client->SendFlightAutoMount(path);
  8457. return 0;
  8458. }
  8459. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8460. if (!lua_interface)
  8461. return 0;
  8462. Spawn* player = lua_interface->GetSpawn(state);
  8463. if (!player) {
  8464. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8465. return 0;
  8466. }
  8467. if (!player->IsPlayer()) {
  8468. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8469. return 0;
  8470. }
  8471. Client* client = player->GetZone()->GetClientBySpawn(player);
  8472. if (!client) {
  8473. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8474. return 0;
  8475. }
  8476. client->EndAutoMount();
  8477. return 0;
  8478. }
  8479. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8480. if (!lua_interface)
  8481. return 0;
  8482. Spawn* player = lua_interface->GetSpawn(state);
  8483. if (!player) {
  8484. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8485. return 0;
  8486. }
  8487. if (!player->IsPlayer()) {
  8488. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8489. return 0;
  8490. }
  8491. Client* client = player->GetZone()->GetClientBySpawn(player);
  8492. if (!client) {
  8493. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8494. return 0;
  8495. }
  8496. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8497. return 1;
  8498. }
  8499. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8500. if (!lua_interface)
  8501. return 0;
  8502. Spawn* player = lua_interface->GetSpawn(state);
  8503. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8504. int32 value = lua_interface->GetInt32Value(state, 3);
  8505. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8506. if (!player) {
  8507. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8508. return 0;
  8509. }
  8510. if (!player->IsPlayer()) {
  8511. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8512. return 0;
  8513. }
  8514. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8515. return 0;
  8516. }
  8517. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8518. if (!lua_interface)
  8519. return 0;
  8520. Spawn* player = lua_interface->GetSpawn(state);
  8521. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8522. if (!player) {
  8523. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8524. return 0;
  8525. }
  8526. if (!player->IsPlayer()) {
  8527. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8528. return 0;
  8529. }
  8530. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8531. if (!hd)
  8532. return 0;
  8533. lua_interface->SetInt32Value(state, hd->Value);
  8534. lua_interface->SetInt32Value(state, hd->Value2);
  8535. return 2;
  8536. }
  8537. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8538. if (!lua_interface)
  8539. return 0;
  8540. Spawn* spawn = lua_interface->GetSpawn(state);
  8541. int32 grid = lua_interface->GetInt32Value(state, 2);
  8542. if (!spawn) {
  8543. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8544. return 0;
  8545. }
  8546. if (grid == 0) {
  8547. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8548. return 0;
  8549. }
  8550. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8551. return 0;
  8552. }
  8553. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8554. if (!lua_interface)
  8555. return 0;
  8556. Spawn* spawn = lua_interface->GetSpawn(state);
  8557. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8558. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8559. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8560. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8561. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8562. if (!spawn) {
  8563. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8564. return 0;
  8565. }
  8566. //Add this quest to the list of required quests for this spawn
  8567. spawn->SetRequiredHistory(event_id, value1, value2);
  8568. //If private spawn value set
  8569. if (private_spawn) {
  8570. //Set the spawn to be private when not granted access via history
  8571. spawn->AddAllowAccessSpawn(spawn);
  8572. spawn->SetPrivateQuestSpawn(true);
  8573. }
  8574. //This value will override vis_flags in the vis packet
  8575. if (flag_override > 0)
  8576. spawn->SetQuestsRequiredOverride(flag_override);
  8577. return 0;
  8578. }
  8579. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8580. if (!lua_interface)
  8581. return 0;
  8582. Spawn* player = lua_interface->GetSpawn(state);
  8583. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8584. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8585. if (!player) {
  8586. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8587. return 0;
  8588. }
  8589. if (!player->IsPlayer()) {
  8590. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8591. return 0;
  8592. }
  8593. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8594. return 1;
  8595. }
  8596. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8597. if (!lua_interface)
  8598. return 0;
  8599. Spawn* player = lua_interface->GetSpawn(state);
  8600. int8 level = lua_interface->GetInt8Value(state, 2);
  8601. if (!player) {
  8602. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8603. return 0;
  8604. }
  8605. if (!player->IsPlayer()) {
  8606. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8607. return 0;
  8608. }
  8609. if (level == 0) {
  8610. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8611. return 0;
  8612. }
  8613. Client* client = player->GetZone()->GetClientBySpawn(player);
  8614. if (!client) {
  8615. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8616. return 0;
  8617. }
  8618. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8619. return 0;
  8620. }
  8621. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8622. if (!lua_interface)
  8623. return 0;
  8624. Spawn* player = lua_interface->GetSpawn(state);
  8625. int32 amount = lua_interface->GetInt32Value(state, 2);
  8626. if (!player) {
  8627. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8628. return 0;
  8629. }
  8630. if (!player->IsPlayer()) {
  8631. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8632. return 0;
  8633. }
  8634. if (amount == 0) {
  8635. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8636. return 0;
  8637. }
  8638. ((Player*)player)->AddCoins(amount);
  8639. return 0;
  8640. }
  8641. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8642. if (!lua_interface)
  8643. return 0;
  8644. Spawn* player = lua_interface->GetSpawn(state);
  8645. int32 amount = lua_interface->GetInt32Value(state, 2);
  8646. if (!player) {
  8647. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8648. return 0;
  8649. }
  8650. if (!player->IsPlayer()) {
  8651. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8652. return 0;
  8653. }
  8654. if (amount == 0) {
  8655. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8656. return 0;
  8657. }
  8658. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8659. return 1;
  8660. }
  8661. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8662. if (!lua_interface)
  8663. return 0;
  8664. ZoneServer* zone = lua_interface->GetZone(state);
  8665. if (!zone) {
  8666. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. vector<Entity*> players = zone->GetPlayers();
  8670. if (players.size() == 0)
  8671. return 0;
  8672. lua_createtable(state, players.size(), 0);
  8673. int newTable = lua_gettop(state);
  8674. for (int32 i = 0; i < players.size(); i++) {
  8675. lua_interface->SetSpawnValue(state, players.at(i));
  8676. lua_rawseti(state, newTable, i + 1);
  8677. }
  8678. return 1;
  8679. }
  8680. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8681. if (!lua_interface)
  8682. return 0;
  8683. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8684. if (!zone) {
  8685. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8686. return 0;
  8687. }
  8688. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8689. //Map of <placement_id, location_id>
  8690. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8691. map<int32, int32>::iterator itr;
  8692. vector<Spawn*> group;
  8693. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8694. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8695. if (!location) {
  8696. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8697. return 0;
  8698. }
  8699. Spawn* spawn = 0;
  8700. if (location->entities[0]) {
  8701. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8702. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8703. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8704. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8705. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8706. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8707. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8708. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8709. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8710. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8711. if (spawn) {
  8712. const char* script = 0;
  8713. for (int x = 0; x < 3; x++) {
  8714. switch (x) {
  8715. case 0:
  8716. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8717. break;
  8718. case 1:
  8719. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8720. break;
  8721. case 2:
  8722. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8723. break;
  8724. }
  8725. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8726. spawn->SetSpawnScript(string(script));
  8727. break;
  8728. }
  8729. }
  8730. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8731. lua_interface->SetSpawnValue(state, spawn);
  8732. group.push_back(spawn);
  8733. }
  8734. else {
  8735. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8736. safe_delete(spawn);
  8737. }
  8738. }
  8739. }
  8740. if (!group.empty()) {
  8741. lua_createtable(state, group.size(), 0);
  8742. int newTable = lua_gettop(state);
  8743. for (int32 i = 0; i < group.size(); i++) {
  8744. lua_interface->SetSpawnValue(state, group[i]);
  8745. lua_rawseti(state, newTable, i + 1);
  8746. }
  8747. }
  8748. else
  8749. lua_pushnil(state);
  8750. return 1;
  8751. }
  8752. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8753. if (!lua_interface)
  8754. return 0;
  8755. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8756. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8757. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8758. if (!spawn) {
  8759. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8760. return 0;
  8761. }
  8762. if (anim_id == 0) {
  8763. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8764. return 0;
  8765. }
  8766. if (leeway == 0)
  8767. leeway = 5000;
  8768. spawn->SetSpawnAnim(anim_id);
  8769. spawn->SetSpawnAnimLeeway(leeway);
  8770. return 0;
  8771. }
  8772. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8773. if (!lua_interface)
  8774. return 0;
  8775. Spawn* player = lua_interface->GetSpawn(state);
  8776. if (!player) {
  8777. return 0;
  8778. }
  8779. Client* client = player->GetZone()->GetClientBySpawn(player);
  8780. if (!client) {
  8781. return 0;
  8782. }
  8783. lua_interface->SetInt32Value(state, client->GetVersion());
  8784. return 1;
  8785. }
  8786. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8787. if (!lua_interface)
  8788. return 0;
  8789. Item* item = lua_interface->GetItem(state);
  8790. if (!item) {
  8791. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8792. return 0;
  8793. }
  8794. lua_interface->SetInt32Value(state, item->details.item_id);
  8795. return 1;
  8796. }
  8797. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8798. if (!lua_interface)
  8799. return 0;
  8800. Spawn* spawn = lua_interface->GetSpawn(state);
  8801. if (!spawn) {
  8802. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8803. return 0;
  8804. }
  8805. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8806. return 1;
  8807. }
  8808. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8809. if (!lua_interface)
  8810. return 0;
  8811. Spawn* spawn = lua_interface->GetSpawn(state);
  8812. if (!spawn) {
  8813. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8814. return 0;
  8815. }
  8816. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8817. return 1;
  8818. }
  8819. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8820. if (!lua_interface)
  8821. return 0;
  8822. Spawn* spawn = lua_interface->GetSpawn(state);
  8823. if (!spawn) {
  8824. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8825. return 0;
  8826. }
  8827. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8828. return 1;
  8829. }
  8830. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8831. if (!lua_interface)
  8832. return 0;
  8833. Spawn* spawn = lua_interface->GetSpawn(state);
  8834. if (!spawn) {
  8835. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8836. return 0;
  8837. }
  8838. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8839. return 1;
  8840. }
  8841. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8842. if (!lua_interface)
  8843. return 0;
  8844. Spawn* spawn = lua_interface->GetSpawn(state);
  8845. float pct = lua_interface->GetFloatValue(state, 2);
  8846. if (!spawn) {
  8847. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8848. return 0;
  8849. }
  8850. if (pct == 0) {
  8851. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8852. return 0;
  8853. }
  8854. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8855. lua_interface->SetInt32Value(state, amount);
  8856. return 1;
  8857. }
  8858. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8859. if (!lua_interface)
  8860. return 0;
  8861. Spawn* spawn = lua_interface->GetSpawn(state);
  8862. float pct = lua_interface->GetFloatValue(state, 2);
  8863. if (!spawn) {
  8864. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8865. return 0;
  8866. }
  8867. if (pct == 0) {
  8868. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8869. return 0;
  8870. }
  8871. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8872. lua_interface->SetInt32Value(state, amount);
  8873. return 1;
  8874. }
  8875. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8876. if (!lua_interface)
  8877. return 0;
  8878. Spawn* spawn = lua_interface->GetSpawn(state);
  8879. if (!spawn) {
  8880. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8881. return 0;
  8882. }
  8883. if (!spawn->IsPlayer()) {
  8884. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8885. return 0;
  8886. }
  8887. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8888. return 1;
  8889. }
  8890. int EQ2Emu_lua_Evac(lua_State* state) {
  8891. if (!lua_interface)
  8892. return 0;
  8893. Spawn* target = lua_interface->GetSpawn(state);
  8894. if (target) {
  8895. float x = target->GetZone()->GetSafeX();
  8896. float y = target->GetZone()->GetSafeY();
  8897. float z = target->GetZone()->GetSafeZ();
  8898. float h = target->GetZone()->GetSafeHeading();
  8899. target->SetX(x);
  8900. target->SetY(y);
  8901. target->SetZ(z);
  8902. target->SetHeading(h);
  8903. target->SetSpawnOrigX(target->GetX());
  8904. target->SetSpawnOrigY(target->GetY());
  8905. target->SetSpawnOrigZ(target->GetZ());
  8906. target->SetSpawnOrigHeading(target->GetHeading());
  8907. if (target->IsPlayer()) {
  8908. Client* client = target->GetZone()->GetClientBySpawn(target);
  8909. if (client) {
  8910. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8911. if (packet)
  8912. {
  8913. packet->setDataByName("x", x);
  8914. packet->setDataByName("y", y);
  8915. packet->setDataByName("z", z);
  8916. client->QueuePacket(packet->serialize());
  8917. safe_delete(packet);
  8918. }
  8919. }
  8920. }
  8921. }
  8922. else {
  8923. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8924. ZoneServer* zone = spell->caster->GetZone();
  8925. float x = spell->caster->GetZone()->GetSafeX();
  8926. float y = spell->caster->GetZone()->GetSafeY();
  8927. float z = spell->caster->GetZone()->GetSafeZ();
  8928. float h = spell->caster->GetZone()->GetSafeHeading();
  8929. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8930. for (int32 i = 0; i < spell->targets.size(); i++) {
  8931. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8932. if (!target2)
  8933. continue;
  8934. target2->SetX(x);
  8935. target2->SetY(y);
  8936. target2->SetZ(z);
  8937. target2->SetHeading(h);
  8938. target2->SetSpawnOrigX(target2->GetX());
  8939. target2->SetSpawnOrigY(target2->GetY());
  8940. target2->SetSpawnOrigZ(target2->GetZ());
  8941. target2->SetSpawnOrigHeading(target2->GetHeading());
  8942. if (target2->IsPlayer()) {
  8943. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8944. if (client) {
  8945. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8946. if (packet)
  8947. {
  8948. client->SetReloadingZone(true);
  8949. packet->setDataByName("x", x);
  8950. packet->setDataByName("y", y);
  8951. packet->setDataByName("z", z);
  8952. client->QueuePacket(packet->serialize());
  8953. safe_delete(packet);
  8954. }
  8955. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8956. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8957. }
  8958. }
  8959. }
  8960. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8961. }
  8962. return 0;
  8963. }
  8964. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8965. if (!lua_interface)
  8966. return 0;
  8967. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8968. if (!luaspell) {
  8969. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8970. return 0;
  8971. }
  8972. int8 tier = luaspell->spell->GetSpellTier();
  8973. lua_interface->SetInt32Value(state, tier);
  8974. return 1;
  8975. }
  8976. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8977. if (!lua_interface)
  8978. return 0;
  8979. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8980. if (!luaspell) {
  8981. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8982. return 0;
  8983. }
  8984. int32 spell_id = luaspell->spell->GetSpellID();
  8985. lua_interface->SetInt32Value(state, spell_id);
  8986. return 1;
  8987. }
  8988. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8989. if (!lua_interface)
  8990. return 0;
  8991. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8992. if (!spawn) {
  8993. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8994. return 0;
  8995. }
  8996. if (!spawn->IsPlayer()) {
  8997. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8998. return 0;
  8999. }
  9000. ZoneServer* zone = spawn->GetZone();
  9001. if (!zone) {
  9002. return 0;
  9003. }
  9004. Client* client = zone->GetClientBySpawn(spawn);
  9005. if (!client) {
  9006. return 0;
  9007. }
  9008. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9009. return 0;
  9010. }
  9011. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9012. if (!lua_interface)
  9013. return 0;
  9014. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9015. if (!spawn) {
  9016. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9017. return 0;
  9018. }
  9019. if (!spawn->IsPlayer()) {
  9020. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9021. return 0;
  9022. }
  9023. ZoneServer* zone = spawn->GetZone();
  9024. if (!zone) {
  9025. return 0;
  9026. }
  9027. Client* client = zone->GetClientBySpawn(spawn);
  9028. if (!client) {
  9029. return 0;
  9030. }
  9031. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9032. return 0;
  9033. }
  9034. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9035. if (!lua_interface)
  9036. return 0;
  9037. Spawn* caster = lua_interface->GetSpawn(state);
  9038. Spawn* target = lua_interface->GetSpawn(state, 2);
  9039. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9040. string spell_name = lua_interface->GetStringValue(state, 4);
  9041. if (!caster) {
  9042. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9043. return 0;
  9044. }
  9045. if (!caster->IsEntity()) {
  9046. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9047. return 0;
  9048. }
  9049. if (!target) {
  9050. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9051. return 0;
  9052. }
  9053. if (!target->IsEntity()) {
  9054. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9055. return 0;
  9056. }
  9057. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9058. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9059. return 0;
  9060. }
  9061. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9062. if (!lua_interface)
  9063. return 0;
  9064. Spawn* player = lua_interface->GetSpawn(state);
  9065. int32 amount = lua_interface->GetInt32Value(state, 2);
  9066. if (player && player->IsPlayer() && amount > 0) {
  9067. ((Player*)player)->AddXP(amount);
  9068. ((Player*)player)->SetCharSheetChanged(true);
  9069. Client* client = player->GetZone()->GetClientBySpawn(player);
  9070. if (client) {
  9071. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9072. }
  9073. }
  9074. return 0;
  9075. }
  9076. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9077. if (!lua_interface)
  9078. return 0;
  9079. Spawn* player = lua_interface->GetSpawn(state);
  9080. int8 type = lua_interface->GetInt8Value(state, 2);
  9081. string text = lua_interface->GetStringValue(state, 3);
  9082. Client* client = 0;
  9083. if (player && player->IsPlayer())
  9084. client = player->GetZone()->GetClientBySpawn(player);
  9085. if (!client || text.length() == 0) {
  9086. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9087. return 0;
  9088. }
  9089. client->SimpleMessage(type, text.c_str());
  9090. return 0;
  9091. }
  9092. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9093. if (!lua_interface)
  9094. return 0;
  9095. Spawn* player = lua_interface->GetSpawn(state);
  9096. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9097. Client* client = 0;
  9098. if (player && player->IsPlayer())
  9099. client = player->GetZone()->GetClientBySpawn(player);
  9100. if (!client || !spawn) {
  9101. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9102. return 0;
  9103. }
  9104. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9105. if (!items) {
  9106. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9107. return 0;
  9108. }
  9109. client->Loot(spawn->GetLootCoins(), items, spawn);
  9110. return 0;
  9111. }
  9112. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9113. if (!lua_interface)
  9114. return 0;
  9115. Spawn* spawnref = lua_interface->GetSpawn(state);
  9116. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9117. if (spawn_id > 0 && spawnref) {
  9118. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9119. if (spawns.size() == 0) {
  9120. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9121. return 0;
  9122. }
  9123. Spawn* spawn = 0;
  9124. int16 index = MakeRandomInt(0, spawns.size());
  9125. if (index >= spawns.size() || index < 0)
  9126. index = 0;
  9127. spawn = spawns[index];
  9128. lua_interface->SetSpawnValue(state, spawn);
  9129. return 1;
  9130. }
  9131. else {
  9132. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9133. }
  9134. return 0;
  9135. }
  9136. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9137. Spawn* player = lua_interface->GetSpawn(state);
  9138. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9139. string name = lua_interface->GetStringValue(state, 3);
  9140. float distance = lua_interface->GetFloatValue(state, 4);
  9141. string command = lua_interface->GetStringValue(state, 5);
  9142. string error_text = lua_interface->GetStringValue(state, 6);
  9143. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9144. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9145. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9146. if (distance == 0)
  9147. distance = 10.0f;
  9148. if (command.length() == 0)
  9149. command = name;
  9150. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9151. if (spawns.size() == 0) {
  9152. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9153. return 0;
  9154. }
  9155. Spawn* spawn = 0;
  9156. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9157. spawn = *itr;
  9158. if (spawn) {
  9159. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9160. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9161. }
  9162. }
  9163. }
  9164. return 0;
  9165. }
  9166. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9167. if (!lua_interface)
  9168. return 0;
  9169. Client* client = 0;
  9170. Spawn* player = lua_interface->GetSpawn(state);
  9171. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9172. if (player && player->IsPlayer() && player->GetZone())
  9173. client = player->GetZone()->GetClientBySpawn(player);
  9174. else{
  9175. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9176. return 0;
  9177. }
  9178. if (client) {
  9179. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9180. if (packet) {
  9181. packet->setDataByName("goal_num", goal_num);
  9182. client->QueuePacket(packet->serialize());
  9183. safe_delete(packet);
  9184. }
  9185. }
  9186. return 0;
  9187. }
  9188. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9189. if (!lua_interface)
  9190. return 0;
  9191. Client* client = 0;
  9192. Spawn* player = lua_interface->GetSpawn(state);
  9193. if (player && player->IsPlayer() && player->GetZone())
  9194. client = player->GetZone()->GetClientBySpawn(player);
  9195. else {
  9196. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9197. return 0;
  9198. }
  9199. if (client) {
  9200. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9201. }
  9202. return 0;
  9203. }
  9204. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9205. if (!lua_interface)
  9206. return 0;
  9207. Client* client = 0;
  9208. Spawn* player = lua_interface->GetSpawn(state);
  9209. float duration = lua_interface->GetFloatValue(state, 2);
  9210. string text = lua_interface->GetStringValue(state, 3);
  9211. string voice = lua_interface->GetStringValue(state, 4);
  9212. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9213. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9214. string signal = lua_interface->GetStringValue(state, 7);
  9215. string goal1 = lua_interface->GetStringValue(state, 8);
  9216. string task1 = lua_interface->GetStringValue(state, 9);
  9217. string goal2 = lua_interface->GetStringValue(state, 10);
  9218. string task2 = lua_interface->GetStringValue(state, 11);
  9219. string goal3 = lua_interface->GetStringValue(state, 12);
  9220. string task3 = lua_interface->GetStringValue(state, 13);
  9221. string goal4 = lua_interface->GetStringValue(state, 14);
  9222. string task4 = lua_interface->GetStringValue(state, 15);
  9223. if (!player) {
  9224. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9225. return 0;
  9226. }
  9227. if (!player->IsPlayer()) {
  9228. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9229. return 0;
  9230. }
  9231. else
  9232. client = ((Player*)player)->GetClient();
  9233. if (!client) {
  9234. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9235. return 0;
  9236. }
  9237. if (text.length() == 0) {
  9238. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9239. return 0;
  9240. }
  9241. if (duration >= 0 && duration < 2)
  9242. duration = 2;
  9243. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9244. if (packet) {
  9245. packet->setDataByName("open_seconds_max", duration);
  9246. packet->setDataByName("text", text.c_str());
  9247. packet->setDataByName("voice", voice.c_str());
  9248. int8 num_goals = 1;
  9249. if (task2.length() > 0)
  9250. num_goals++;
  9251. if (task3.length() > 0)
  9252. num_goals++;
  9253. if (task4.length() > 0)
  9254. num_goals++;
  9255. packet->setArrayLengthByName("num_goals", num_goals);
  9256. for (int8 i = 0; i < num_goals; i++) {
  9257. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9258. }
  9259. if (goal1.length() > 0)
  9260. packet->setArrayDataByName("goal_text", goal1.c_str());
  9261. if (goal2.length() > 0)
  9262. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9263. if (goal3.length() > 0)
  9264. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9265. if (goal4.length() > 0)
  9266. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9267. packet->setSubArrayDataByName("task_text", task1.c_str());
  9268. if (task2.length() > 0)
  9269. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9270. if (task3.length() > 0)
  9271. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9272. if (task4.length() > 0)
  9273. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9274. packet->setDataByName("complete_sound", "click");
  9275. packet->setDataByName("signal", signal.c_str());
  9276. packet->setDataByName("voice_key1", voice_key1);
  9277. packet->setDataByName("voice_key2", voice_key2);
  9278. client->QueuePacket(packet->serialize());
  9279. safe_delete(packet);
  9280. }
  9281. return 0;
  9282. }
  9283. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9284. if (!lua_interface)
  9285. return 0;
  9286. Client* client = 0;
  9287. Spawn* player = lua_interface->GetSpawn(state);
  9288. string window = lua_interface->GetStringValue(state, 2);
  9289. int8 show = lua_interface->GetInt8Value(state, 3);
  9290. if (!player) {
  9291. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9292. return 0;
  9293. }
  9294. if (!player->IsPlayer()) {
  9295. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9296. return 0;
  9297. }
  9298. else
  9299. client = ((Player*)player)->GetClient();
  9300. if (!client) {
  9301. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9302. return 0;
  9303. }
  9304. if (window.length() == 0) {
  9305. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9306. return 0;
  9307. }
  9308. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9309. if (packet) {
  9310. packet->setDataByName("window", window.c_str());
  9311. packet->setDataByName("show", show);
  9312. client->QueuePacket(packet->serialize());
  9313. safe_delete(packet);
  9314. }
  9315. return 0;
  9316. }
  9317. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9318. //See GameEvents.txt for options that can be used for this function
  9319. if (!lua_interface)
  9320. return 0;
  9321. Client* client = 0;
  9322. Spawn* player = lua_interface->GetSpawn(state);
  9323. string event_name = lua_interface->GetStringValue(state, 2);
  9324. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9325. if (!player || !player->IsPlayer()) {
  9326. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9327. return 0;
  9328. }
  9329. if (player->GetZone())
  9330. client = player->GetZone()->GetClientBySpawn(player);
  9331. if (!client) {
  9332. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9333. return 0;
  9334. }
  9335. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9336. if (packet) {
  9337. packet->setDataByName("event_name", event_name.c_str());
  9338. packet->setDataByName("enabled", enabled);
  9339. client->QueuePacket(packet->serialize());
  9340. safe_delete(packet);
  9341. }
  9342. return 0;
  9343. }
  9344. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9345. if (!lua_interface)
  9346. return 0;
  9347. Spawn* player = lua_interface->GetSpawn(state);
  9348. if (player && player->IsPlayer()) {
  9349. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9350. return 1;
  9351. }
  9352. return 0;
  9353. }
  9354. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9355. if (!lua_interface)
  9356. return 0;
  9357. Spawn* player = lua_interface->GetSpawn(state);
  9358. int8 step = lua_interface->GetInt8Value(state, 2);
  9359. if (player && player->IsPlayer() && step > 0) {
  9360. ((Player*)player)->SetTutorialStep(step);
  9361. }
  9362. return 0;
  9363. }
  9364. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9365. if (!lua_interface)
  9366. return 0;
  9367. Client* client = 0;
  9368. Spawn* player = lua_interface->GetSpawn(state);
  9369. string window = lua_interface->GetStringValue(state, 2);
  9370. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9371. if (!player) {
  9372. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9373. return 0;
  9374. }
  9375. if (!player->IsPlayer()) {
  9376. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9377. return 0;
  9378. }
  9379. else
  9380. client = ((Player*)player)->GetClient();
  9381. if (!client) {
  9382. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9383. return 0;
  9384. }
  9385. if (window.length() == 0) {
  9386. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9387. return 0;
  9388. }
  9389. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9390. if (packet) {
  9391. packet->setDataByName("window", window.c_str());
  9392. packet->setDataByName("flash_seconds", flash_seconds);
  9393. client->QueuePacket(packet->serialize());
  9394. safe_delete(packet);
  9395. }
  9396. return 0;
  9397. }
  9398. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9399. if (!lua_interface)
  9400. return 0;
  9401. Spawn* spawn = lua_interface->GetSpawn(state);
  9402. Spawn* target = lua_interface->GetSpawn(state, 2);
  9403. if (spawn && target)
  9404. return spawn->CheckLoS(target);
  9405. return 0;
  9406. }
  9407. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9408. if (!lua_interface)
  9409. return 0;
  9410. Spawn* spawn = lua_interface->GetSpawn(state);
  9411. float x = lua_interface->GetFloatValue(state, 2);
  9412. float y = lua_interface->GetFloatValue(state, 3);
  9413. float z = lua_interface->GetFloatValue(state, 4);
  9414. if (spawn)
  9415. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9416. return 0;
  9417. }
  9418. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9419. if (!lua_interface)
  9420. return 0;
  9421. ZoneServer* zone = lua_interface->GetZone(state);
  9422. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9423. if (zone)
  9424. zone->SetExpansionFlag(xpackFlag);
  9425. return 0;
  9426. }
  9427. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9428. if (!lua_interface)
  9429. return 0;
  9430. ZoneServer* zone = lua_interface->GetZone(state);
  9431. if (zone) {
  9432. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9433. return 1;
  9434. }
  9435. return 0;
  9436. }
  9437. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9438. if (!lua_interface)
  9439. return 0;
  9440. ZoneServer* zone = lua_interface->GetZone(state);
  9441. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9442. if (zone)
  9443. zone->SetHolidayFlag(holidayFlag);
  9444. return 0;
  9445. }
  9446. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9447. if (!lua_interface)
  9448. return 0;
  9449. ZoneServer* zone = lua_interface->GetZone(state);
  9450. if (zone) {
  9451. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9452. return 1;
  9453. }
  9454. return 0;
  9455. }
  9456. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9457. if (!lua_interface)
  9458. return 0;
  9459. Spawn* spawn = lua_interface->GetSpawn(state);
  9460. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9461. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9462. float distance = lua_interface->GetFloatValue(state, 4);
  9463. string in_range_function = lua_interface->GetStringValue(state, 5);
  9464. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9465. if (spawn && distance > 0 && in_range_function.length() > 0)
  9466. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9467. return 0;
  9468. }
  9469. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9470. if (!lua_interface)
  9471. return 0;
  9472. Spawn* spawn = lua_interface->GetSpawn(state);
  9473. Spawn* target = lua_interface->GetSpawn(state, 2);
  9474. if (spawn && target)
  9475. {
  9476. if (spawn->IsPlayer() && target->IsEntity())
  9477. {
  9478. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9479. return 1;
  9480. }
  9481. else if (spawn->IsEntity() && target->IsEntity())
  9482. {
  9483. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9484. return 1;
  9485. }
  9486. }
  9487. return 0;
  9488. }
  9489. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9490. if (!lua_interface)
  9491. return 0;
  9492. Spawn* spawn = lua_interface->GetSpawn(state);
  9493. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9494. if (spawn && spawn->IsEntity())
  9495. {
  9496. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9497. if (spawn->IsPlayer())
  9498. {
  9499. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9500. if (client)
  9501. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9502. }
  9503. }
  9504. return 0;
  9505. }
  9506. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9507. if (!lua_interface)
  9508. return 0;
  9509. Spawn* spawn = lua_interface->GetSpawn(state);
  9510. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9511. if (spawn && spawn->IsEntity())
  9512. {
  9513. ((Entity*)spawn)->SetSeeHideSpell(val);
  9514. if (spawn->IsPlayer())
  9515. {
  9516. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9517. if (client)
  9518. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9519. }
  9520. }
  9521. return 0;
  9522. }
  9523. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9524. {
  9525. if (!lua_interface)
  9526. return 0;
  9527. Spawn* player = lua_interface->GetSpawn(state);
  9528. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9529. string command = lua_interface->GetStringValue(state, 3);
  9530. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9531. lua_interface->ResetFunctionStack(state);
  9532. if (spawn && player && player->IsPlayer())
  9533. {
  9534. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9535. bool res = false;
  9536. if (cmd)
  9537. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9538. lua_interface->SetBooleanValue(state, res);
  9539. return 1;
  9540. }
  9541. return 0;
  9542. }
  9543. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9544. {
  9545. if (!lua_interface)
  9546. return 0;
  9547. Spawn* spawn = lua_interface->GetSpawn(state);
  9548. int32 charID = lua_interface->GetInt32Value(state, 2);
  9549. string command = lua_interface->GetStringValue(state, 3);
  9550. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9551. lua_interface->ResetFunctionStack(state);
  9552. if (spawn && charID)
  9553. {
  9554. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9555. bool res = false;
  9556. if (cmd)
  9557. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9558. lua_interface->SetBooleanValue(state, res);
  9559. return 1;
  9560. }
  9561. return 0;
  9562. }
  9563. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9564. {
  9565. if (!lua_interface)
  9566. return 0;
  9567. Spawn* spawn = lua_interface->GetSpawn(state);
  9568. string command = lua_interface->GetStringValue(state, 2);
  9569. lua_interface->ResetFunctionStack(state);
  9570. if (spawn && command.length() > 0)
  9571. spawn->RemovePrimaryEntityCommand(command.c_str());
  9572. return 0;
  9573. }
  9574. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9575. if (!lua_interface)
  9576. return 0;
  9577. Spawn* spawn = lua_interface->GetSpawn(state);
  9578. float distance = lua_interface->GetFloatValue(state, 2);
  9579. string command = lua_interface->GetStringValue(state, 3);
  9580. Spawn* player = lua_interface->GetSpawn(state, 4);
  9581. lua_interface->ResetFunctionStack(state);
  9582. if (spawn) {
  9583. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9584. }
  9585. return 0;
  9586. }
  9587. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9588. if (!lua_interface)
  9589. return 0;
  9590. Spawn* spawn = lua_interface->GetSpawn(state);
  9591. Spawn* player = lua_interface->GetSpawn(state, 2);
  9592. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9593. lua_interface->ResetFunctionStack(state);
  9594. if (spawn && player && transport_id && player->IsPlayer()) {
  9595. Client* client = 0;
  9596. if (player && player->IsPlayer())
  9597. client = player->GetZone()->GetClientBySpawn(player);
  9598. if (!client)
  9599. return 0;
  9600. vector<TransportDestination*> destinations;
  9601. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9602. if (destinations.size())
  9603. {
  9604. client->SetTemporaryTransportID(transport_id);
  9605. client->ProcessTeleport(spawn, &destinations, transport_id);
  9606. }
  9607. else
  9608. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9609. }
  9610. return 0;
  9611. }
  9612. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9613. if (!lua_interface)
  9614. return 0;
  9615. Spawn* player = lua_interface->GetSpawn(state);
  9616. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9617. lua_interface->ResetFunctionStack(state);
  9618. if (player && player->IsPlayer()) {
  9619. Client* client = 0;
  9620. if (player && player->IsPlayer())
  9621. client = player->GetZone()->GetClientBySpawn(player);
  9622. if (!client)
  9623. return 0;
  9624. client->SetTemporaryTransportID(transport_id);
  9625. }
  9626. return 0;
  9627. }
  9628. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9629. if (!lua_interface)
  9630. return 0;
  9631. Spawn* player = lua_interface->GetSpawn(state);
  9632. lua_interface->ResetFunctionStack(state);
  9633. if (player && player->IsPlayer()) {
  9634. Client* client = 0;
  9635. if (player && player->IsPlayer())
  9636. client = player->GetZone()->GetClientBySpawn(player);
  9637. if (!client)
  9638. return 0;
  9639. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9640. return 1;
  9641. }
  9642. return 0;
  9643. }
  9644. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9645. if (!lua_interface)
  9646. return 0;
  9647. Spawn* spawn = lua_interface->GetSpawn(state);
  9648. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9649. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9650. if (!spawn) {
  9651. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9652. return 0;
  9653. }
  9654. if (!spawn->IsEntity()) {
  9655. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9656. return 0;
  9657. }
  9658. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9659. {
  9660. lua_interface->LogError("%s: LUA SetAlignment command error: alignment value beyond supported min: %i and max: %i", lua_interface->GetScriptName(state), SCHAR_MIN, SCHAR_MAX);
  9661. return 0;
  9662. }
  9663. lua_interface->ResetFunctionStack(state);
  9664. if (spell && spell->targets.size() > 0) {
  9665. ZoneServer* zone = spell->caster->GetZone();
  9666. for (int8 i = 0; i < spell->targets.size(); i++) {
  9667. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9668. if (target && target->IsEntity()) {
  9669. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9670. if (target->IsPlayer())
  9671. ((Player*)target)->SetCharSheetChanged(true);
  9672. }
  9673. }
  9674. }
  9675. else {
  9676. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9677. if (spawn->IsPlayer())
  9678. ((Player*)spawn)->SetCharSheetChanged(true);
  9679. }
  9680. return 0;
  9681. }
  9682. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9683. if (!lua_interface)
  9684. return 0;
  9685. Spawn* spawn = lua_interface->GetSpawn(state);
  9686. lua_interface->ResetFunctionStack(state);
  9687. if (!spawn) {
  9688. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9689. return 0;
  9690. }
  9691. if (!spawn->IsEntity()) {
  9692. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9693. return 0;
  9694. }
  9695. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9696. return 1;
  9697. }
  9698. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9699. if (!lua_interface)
  9700. return 0;
  9701. int32 spell_id = lua_interface->GetInt32Value(state);
  9702. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9703. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9704. if (spell_id > 0) {
  9705. if (spell_tier == 0)
  9706. spell_tier = 1;
  9707. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9708. LuaSpell* lua_spell = 0;
  9709. if(custom_lua_script.size() > 0)
  9710. {
  9711. // attempt to load the custom script since it isn't already loaded
  9712. // we will re-obtain the lua_spell further below
  9713. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9714. {
  9715. LogWrite(LUA__WARNING, 0, "LUA", "GetSpell(%u, %u, '%s'), custom lua script not loaded, attempting to load.", spell_id, spell_tier, custom_lua_script.c_str());
  9716. lua_interface->LoadLuaSpell(custom_lua_script);
  9717. }
  9718. }
  9719. else
  9720. custom_lua_script = spell->GetSpellData()->lua_script;
  9721. if (!lua_spell && lua_interface)
  9722. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9723. if (!lua_spell)
  9724. {
  9725. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9726. return 0;
  9727. }
  9728. lua_spell->spell = new Spell(spell);
  9729. lua_interface->AddCustomSpell(lua_spell);
  9730. lua_interface->SetSpellValue(state, lua_spell);
  9731. return 1;
  9732. }
  9733. return 0;
  9734. }
  9735. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9736. if (!lua_interface)
  9737. return 0;
  9738. LuaSpell* spell = lua_interface->GetSpell(state);
  9739. string field = lua_interface->GetStringValue(state, 2);
  9740. if (!spell) {
  9741. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9742. return 0;
  9743. }
  9744. if (!spell->spell || !spell->spell->GetSpellData()) {
  9745. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9746. return 0;
  9747. }
  9748. boost::to_lower(field);
  9749. return spell->spell->GetSpellData(state, field);
  9750. }
  9751. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9752. if (!lua_interface)
  9753. return 0;
  9754. LuaSpell* spell = lua_interface->GetSpell(state);
  9755. string field = lua_interface->GetStringValue(state, 2);
  9756. int8 fieldArg = 3; // field value after the initial set
  9757. if (!spell) {
  9758. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9759. return 0;
  9760. }
  9761. if (!spell->spell || !spell->spell->GetSpellData()) {
  9762. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9763. return 0;
  9764. }
  9765. boost::to_lower(field);
  9766. bool valSet = false;
  9767. spell->spell->SetSpellData(state, field, fieldArg);
  9768. return valSet;
  9769. }
  9770. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9771. if (!lua_interface)
  9772. return 0;
  9773. LuaSpell* spell = lua_interface->GetSpell(state);
  9774. int8 idx = lua_interface->GetInt32Value(state, 2);
  9775. if (!spell) {
  9776. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9777. return 0;
  9778. }
  9779. if (!spell->spell || !spell->spell->GetSpellData()) {
  9780. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9781. return 0;
  9782. }
  9783. if (spell->spell->lua_data.size() <= idx)
  9784. {
  9785. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9786. return 0;
  9787. }
  9788. bool setVal = true;
  9789. LUAData* data = spell->spell->lua_data[idx];
  9790. switch (data->type)
  9791. {
  9792. case 0:
  9793. {
  9794. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9795. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9796. data->int_value = value;
  9797. data->int_value2 = value2;
  9798. break;
  9799. }
  9800. case 1:
  9801. {
  9802. float value = lua_interface->GetFloatValue(state, 3);
  9803. float value2 = lua_interface->GetFloatValue(state, 4);
  9804. data->float_value = value;
  9805. data->float_value2 = value2;
  9806. break;
  9807. }
  9808. case 2:
  9809. {
  9810. bool value = lua_interface->GetBooleanValue(state, 3);
  9811. data->bool_value = value;
  9812. break;
  9813. }
  9814. case 3:
  9815. {
  9816. string value = lua_interface->GetStringValue(state, 3);
  9817. string value2 = lua_interface->GetStringValue(state, 4);
  9818. data->string_value = value;
  9819. data->string_value2 = value2;
  9820. break;
  9821. }
  9822. default:
  9823. setVal = false;
  9824. }
  9825. return setVal;
  9826. }
  9827. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9828. if (!lua_interface)
  9829. return 0;
  9830. LuaSpell* spell = lua_interface->GetSpell(state);
  9831. int8 idx = lua_interface->GetInt32Value(state, 2);
  9832. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9833. if (!spell) {
  9834. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9835. return 0;
  9836. }
  9837. if (!spell->spell || !spell->spell->GetSpellData()) {
  9838. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9839. return 0;
  9840. }
  9841. if (spell->spell->lua_data.size() <= idx)
  9842. {
  9843. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9844. return 0;
  9845. }
  9846. bool setVal = true;
  9847. LUAData* data = spell->spell->lua_data[idx];
  9848. switch (data->type)
  9849. {
  9850. case 0:
  9851. {
  9852. if(!secondfield)
  9853. lua_interface->SetSInt32Value(state, data->int_value);
  9854. else
  9855. lua_interface->SetSInt32Value(state, data->int_value2);
  9856. break;
  9857. }
  9858. case 1:
  9859. {
  9860. if (!secondfield)
  9861. lua_interface->SetFloatValue(state, data->float_value);
  9862. else
  9863. lua_interface->SetFloatValue(state, data->float_value2);
  9864. break;
  9865. }
  9866. case 2:
  9867. {
  9868. lua_interface->SetBooleanValue(state, data->bool_value);
  9869. break;
  9870. }
  9871. case 3:
  9872. {
  9873. if (!secondfield)
  9874. lua_interface->SetStringValue(state, data->string_value.c_str());
  9875. else
  9876. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9877. break;
  9878. }
  9879. default:
  9880. setVal = false;
  9881. }
  9882. return setVal;
  9883. }
  9884. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9885. if (!lua_interface)
  9886. return 0;
  9887. LuaSpell* spell = lua_interface->GetSpell(state);
  9888. int8 idx = lua_interface->GetInt32Value(state, 2);
  9889. string field = lua_interface->GetStringValue(state, 3);
  9890. boost::to_lower(field);
  9891. if (!spell) {
  9892. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9893. return 0;
  9894. }
  9895. if (!spell->spell || !spell->spell->GetSpellData()) {
  9896. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9897. return 0;
  9898. }
  9899. if (spell->spell->effects.size() <= idx)
  9900. {
  9901. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9902. return 0;
  9903. }
  9904. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9905. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9906. if (field == "description")
  9907. effect->description = string(lua_interface->GetStringValue(state, 4));
  9908. else if (field == "bullet")
  9909. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9910. else if (field == "percentage")
  9911. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9912. else // no match
  9913. return 0;
  9914. return 1;
  9915. }
  9916. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9917. if (!lua_interface)
  9918. return 0;
  9919. LuaSpell* spell = lua_interface->GetSpell(state);
  9920. int8 idx = lua_interface->GetInt32Value(state, 2);
  9921. string field = lua_interface->GetStringValue(state, 3);
  9922. boost::to_lower(field);
  9923. if (!spell) {
  9924. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9925. return 0;
  9926. }
  9927. if (!spell->spell || !spell->spell->GetSpellData()) {
  9928. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9929. return 0;
  9930. }
  9931. if (spell->spell->effects.size() <= idx)
  9932. {
  9933. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9934. return 0;
  9935. }
  9936. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9937. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9938. if (field == "description")
  9939. lua_interface->SetStringValue(state, effect->description.c_str());
  9940. else if (field == "bullet")
  9941. lua_interface->SetInt32Value(state, effect->subbullet);
  9942. else if (field == "percentage")
  9943. lua_interface->SetInt32Value(state, effect->percentage);
  9944. else // no match
  9945. return 0;
  9946. return 1;
  9947. }
  9948. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9949. if (!lua_interface)
  9950. return 0;
  9951. LuaSpell* spell = lua_interface->GetSpell(state);
  9952. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9953. Spawn* target = lua_interface->GetSpawn(state, 3);
  9954. if (!target) {
  9955. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9956. return 0;
  9957. }
  9958. if (!target->IsEntity()) {
  9959. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9960. return 0;
  9961. }
  9962. if (!spell) {
  9963. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9964. return 0;
  9965. }
  9966. if (caster && !caster->IsEntity()) {
  9967. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9968. return 0;
  9969. }
  9970. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9971. return 0;
  9972. }
  9973. int EQ2Emu_lua_InWater(lua_State* state) {
  9974. if (!lua_interface)
  9975. return 0;
  9976. Spawn* spawn = lua_interface->GetSpawn(state);
  9977. lua_interface->ResetFunctionStack(state);
  9978. if (spawn) {
  9979. lua_interface->SetBooleanValue(state, spawn->InWater());
  9980. return 1;
  9981. }
  9982. return 0;
  9983. }
  9984. int EQ2Emu_lua_InLava(lua_State* state) {
  9985. if (!lua_interface)
  9986. return 0;
  9987. Spawn* spawn = lua_interface->GetSpawn(state);
  9988. lua_interface->ResetFunctionStack(state);
  9989. if (spawn) {
  9990. lua_interface->SetBooleanValue(state, spawn->InLava());
  9991. return 1;
  9992. }
  9993. return 0;
  9994. }
  9995. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9996. if (!lua_interface)
  9997. return 0;
  9998. Spawn* attacker = lua_interface->GetSpawn(state);
  9999. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10000. int8 type = lua_interface->GetInt8Value(state, 3);
  10001. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10002. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10003. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10004. string spell_name = lua_interface->GetStringValue(state, 7);
  10005. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10006. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10007. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10008. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10009. lua_interface->ResetFunctionStack(state);
  10010. if (!attacker) {
  10011. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10012. return 0;
  10013. }
  10014. if (!attacker->IsEntity()) {
  10015. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10016. return 0;
  10017. }
  10018. if (!victim) {
  10019. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10020. return 0;
  10021. }
  10022. if (!victim->IsEntity()) {
  10023. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10024. return 0;
  10025. }
  10026. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10027. return 0;
  10028. }
  10029. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10030. if (!lua_interface)
  10031. return 0;
  10032. Spawn* spawn = lua_interface->GetSpawn(state);
  10033. lua_interface->ResetFunctionStack(state);
  10034. if (spawn) {
  10035. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10036. return 1;
  10037. }
  10038. return 0;
  10039. }
  10040. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10041. if (!lua_interface)
  10042. return 0;
  10043. Spawn* spawn = lua_interface->GetSpawn(state);
  10044. bool invul = lua_interface->GetBooleanValue(state, 2);
  10045. lua_interface->ResetFunctionStack(state);
  10046. if (spawn) {
  10047. spawn->SetInvulnerable(invul);
  10048. }
  10049. return 0;
  10050. }
  10051. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10052. if (!lua_interface)
  10053. return 0;
  10054. string category = lua_interface->GetStringValue(state);
  10055. string name = lua_interface->GetStringValue(state, 2);
  10056. lua_interface->ResetFunctionStack(state);
  10057. Rule *ret = 0;
  10058. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10059. lua_interface->SetBooleanValue(state, ret->GetBool());
  10060. return 1;
  10061. }
  10062. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10063. return 0;
  10064. }
  10065. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10066. if (!lua_interface)
  10067. return 0;
  10068. string category = lua_interface->GetStringValue(state);
  10069. string name = lua_interface->GetStringValue(state, 2);
  10070. lua_interface->ResetFunctionStack(state);
  10071. Rule *ret = 0;
  10072. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10073. lua_interface->SetInt32Value(state, ret->GetInt32());
  10074. return 1;
  10075. }
  10076. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10077. return 0;
  10078. }
  10079. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10080. if (!lua_interface)
  10081. return 0;
  10082. string category = lua_interface->GetStringValue(state);
  10083. string name = lua_interface->GetStringValue(state, 2);
  10084. lua_interface->ResetFunctionStack(state);
  10085. Rule *ret = 0;
  10086. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10087. lua_interface->SetFloatValue(state, ret->GetFloat());
  10088. return 1;
  10089. }
  10090. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10091. return 0;
  10092. }
  10093. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10094. if (!lua_interface)
  10095. return 0;
  10096. Spawn* spawn = lua_interface->GetSpawn(state);
  10097. string type = lua_interface->GetStringValue(state, 2);
  10098. lua_interface->ResetFunctionStack(state);
  10099. if (spawn) {
  10100. int res = 1;
  10101. boost::to_lower(type);
  10102. if(type == "assigned_aa")
  10103. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10104. else if ( type == "unassigned_aa")
  10105. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10106. else if ( type == "assigned_tradeskill_aa")
  10107. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10108. else if ( type == "unassigned_tradeskill_aa")
  10109. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10110. else if ( type == "assigned_prestige_aa")
  10111. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10112. else if ( type == "unassigned_prestige_aa")
  10113. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10114. else if ( type == "assigned_tradeskill_prestige_aa")
  10115. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10116. else if ( type == "unassigned_tradeskill_prestige_aa")
  10117. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10118. else
  10119. res = 0;
  10120. return res;
  10121. }
  10122. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10123. return 0;
  10124. }
  10125. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10126. if (!lua_interface)
  10127. return 0;
  10128. Spawn* spawn = lua_interface->GetSpawn(state);
  10129. string type = lua_interface->GetStringValue(state, 2);
  10130. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10131. lua_interface->ResetFunctionStack(state);
  10132. if (spawn) {
  10133. boost::to_lower(type);
  10134. if(type == "assigned_aa")
  10135. spawn->SetAssignedAA((sint16)value);
  10136. else if ( type == "unassigned_aa")
  10137. spawn->SetUnassignedAA((sint16)value);
  10138. else if ( type == "assigned_tradeskill_aa")
  10139. spawn->SetTradeskillAA((sint16)value);
  10140. else if ( type == "unassigned_tradeskill_aa")
  10141. spawn->SetUnassignedTradeskillAA((sint16)value);
  10142. else if ( type == "assigned_prestige_aa")
  10143. spawn->SetPrestigeAA((sint16)value);
  10144. else if ( type == "unassigned_prestige_aa")
  10145. spawn->SetUnassignedPrestigeAA((sint16)value);
  10146. else if ( type == "assigned_tradeskill_prestige_aa")
  10147. spawn->SetTradeskillPrestigeAA((sint16)value);
  10148. else if ( type == "unassigned_tradeskill_prestige_aa")
  10149. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10150. if(spawn->IsPlayer())
  10151. ((Player*)spawn)->SetCharSheetChanged(true);
  10152. }
  10153. return 0;
  10154. }
  10155. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10156. if (!lua_interface)
  10157. return 0;
  10158. string titleName = lua_interface->GetStringValue(state);
  10159. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10160. lua_interface->ResetFunctionStack(state);
  10161. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10162. lua_interface->SetSInt32Value(state, index);
  10163. return 1;
  10164. }
  10165. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10166. if (!lua_interface)
  10167. return 0;
  10168. Spawn* spawn = lua_interface->GetSpawn(state);
  10169. string titleName = lua_interface->GetStringValue(state, 2);
  10170. lua_interface->ResetFunctionStack(state);
  10171. if(!spawn->IsPlayer())
  10172. {
  10173. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10174. lua_interface->SetSInt32Value(state, -1);
  10175. return 1;
  10176. }
  10177. Player* player = (Player*)spawn;
  10178. // check if player already has the title, don't need to add twice
  10179. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10180. if ( playerHasTitle)
  10181. {
  10182. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10183. return 1;
  10184. }
  10185. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10186. if(!title)
  10187. {
  10188. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10189. lua_interface->SetSInt32Value(state, -1);
  10190. return 1;
  10191. }
  10192. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10193. if(returnIdx < 0)
  10194. {
  10195. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10196. }
  10197. lua_interface->SetSInt32Value(state, returnIdx);
  10198. player->GetClient()->SendTitleUpdate();
  10199. return 1;
  10200. }
  10201. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10202. if (!lua_interface)
  10203. return 0;
  10204. Spawn* spawn = lua_interface->GetSpawn(state);
  10205. string titleName = lua_interface->GetStringValue(state, 2);
  10206. lua_interface->ResetFunctionStack(state);
  10207. if(!spawn->IsPlayer())
  10208. {
  10209. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10210. return 0;
  10211. }
  10212. Player* player = (Player*)spawn;
  10213. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10214. if(!title)
  10215. {
  10216. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10217. return 0;
  10218. }
  10219. if(title->GetPrefix())
  10220. {
  10221. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title with name '%s' is not valid as a suffix, only prefix", lua_interface->GetScriptName(state), titleName.c_str());
  10222. return 0;
  10223. }
  10224. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10225. player->GetClient()->SendTitleUpdate();
  10226. return 1;
  10227. }
  10228. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10229. if (!lua_interface)
  10230. return 0;
  10231. Spawn* spawn = lua_interface->GetSpawn(state);
  10232. string titleName = lua_interface->GetStringValue(state, 2);
  10233. lua_interface->ResetFunctionStack(state);
  10234. if(!spawn->IsPlayer())
  10235. {
  10236. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10237. return 0;
  10238. }
  10239. Player* player = (Player*)spawn;
  10240. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10241. if(!title)
  10242. {
  10243. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10244. return 0;
  10245. }
  10246. if(!title->GetPrefix())
  10247. {
  10248. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title with name '%s' is not valid as a prefix, only suffix", lua_interface->GetScriptName(state), titleName.c_str());
  10249. return 0;
  10250. }
  10251. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10252. player->GetClient()->SendTitleUpdate();
  10253. return 1;
  10254. }
  10255. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10256. if (!lua_interface)
  10257. return 0;
  10258. Spawn* spawn = lua_interface->GetSpawn(state);
  10259. lua_interface->ResetFunctionStack(state);
  10260. if(!spawn->IsPlayer())
  10261. {
  10262. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10263. return 0;
  10264. }
  10265. Player* player = (Player*)spawn;
  10266. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10267. player->GetClient()->SendTitleUpdate();
  10268. return 1;
  10269. }
  10270. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10271. if (!lua_interface)
  10272. return 0;
  10273. Spawn* spawn = lua_interface->GetSpawn(state);
  10274. lua_interface->ResetFunctionStack(state);
  10275. if(!spawn->IsPlayer())
  10276. {
  10277. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10278. return 0;
  10279. }
  10280. Player* player = (Player*)spawn;
  10281. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10282. player->GetClient()->SendTitleUpdate();
  10283. return 1;
  10284. }
  10285. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10286. if (!lua_interface)
  10287. return 0;
  10288. Spawn* spawn = lua_interface->GetSpawn(state);
  10289. string field = lua_interface->GetStringValue(state, 2);
  10290. lua_interface->ResetFunctionStack(state);
  10291. if(!spawn || !spawn->IsEntity())
  10292. {
  10293. lua_interface->LogError("%s: LUA GetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10294. return 0;
  10295. }
  10296. Entity* ent = (Entity*)spawn;
  10297. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10298. return 1;
  10299. }
  10300. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10301. if (!lua_interface)
  10302. return 0;
  10303. Spawn* spawn = lua_interface->GetSpawn(state);
  10304. string field = lua_interface->GetStringValue(state, 2);
  10305. lua_interface->ResetFunctionStack(state);
  10306. if(!spawn || !spawn->IsEntity())
  10307. {
  10308. lua_interface->LogError("%s: LUA GetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10309. return 0;
  10310. }
  10311. Entity* ent = (Entity*)spawn;
  10312. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10313. return 1;
  10314. }
  10315. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10316. if (!lua_interface)
  10317. return 0;
  10318. Spawn* spawn = lua_interface->GetSpawn(state);
  10319. string field = lua_interface->GetStringValue(state, 2);
  10320. lua_interface->ResetFunctionStack(state);
  10321. if(!spawn || !spawn->IsEntity())
  10322. {
  10323. lua_interface->LogError("%s: LUA GetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10324. return 0;
  10325. }
  10326. Entity* ent = (Entity*)spawn;
  10327. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10328. return 1;
  10329. }
  10330. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10331. if (!lua_interface)
  10332. return 0;
  10333. Spawn* spawn = lua_interface->GetSpawn(state);
  10334. string field = lua_interface->GetStringValue(state, 2);
  10335. lua_interface->ResetFunctionStack(state);
  10336. if(!spawn || !spawn->IsEntity())
  10337. {
  10338. lua_interface->LogError("%s: LUA GetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10339. return 0;
  10340. }
  10341. Entity* ent = (Entity*)spawn;
  10342. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10343. return 1;
  10344. }
  10345. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10346. if (!lua_interface)
  10347. return 0;
  10348. Spawn* spawn = lua_interface->GetSpawn(state);
  10349. string field = lua_interface->GetStringValue(state, 2);
  10350. string value = lua_interface->GetStringValue(state, 3);
  10351. lua_interface->ResetFunctionStack(state);
  10352. if(!spawn || !spawn->IsEntity())
  10353. {
  10354. lua_interface->LogError("%s: LUA SetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10355. return 0;
  10356. }
  10357. Entity* ent = (Entity*)spawn;
  10358. bool set_ = ent->SetInfoStructString(field, value);
  10359. lua_interface->SetBooleanValue(state, set_);
  10360. return 1;
  10361. }
  10362. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10363. if (!lua_interface)
  10364. return 0;
  10365. Spawn* spawn = lua_interface->GetSpawn(state);
  10366. string field = lua_interface->GetStringValue(state, 2);
  10367. int64 value = lua_interface->GetInt64Value(state, 3);
  10368. lua_interface->ResetFunctionStack(state);
  10369. if(!spawn || !spawn->IsEntity())
  10370. {
  10371. lua_interface->LogError("%s: LUA SetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10372. return 0;
  10373. }
  10374. Entity* ent = (Entity*)spawn;
  10375. bool set_ = ent->SetInfoStructUInt(field, value);
  10376. lua_interface->SetBooleanValue(state, set_);
  10377. return 1;
  10378. }
  10379. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10380. if (!lua_interface)
  10381. return 0;
  10382. Spawn* spawn = lua_interface->GetSpawn(state);
  10383. string field = lua_interface->GetStringValue(state, 2);
  10384. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10385. lua_interface->ResetFunctionStack(state);
  10386. if(!spawn || !spawn->IsEntity())
  10387. {
  10388. lua_interface->LogError("%s: LUA SetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10389. return 0;
  10390. }
  10391. Entity* ent = (Entity*)spawn;
  10392. bool set_ = ent->SetInfoStructSInt(field, value);
  10393. lua_interface->SetBooleanValue(state, set_);
  10394. return 1;
  10395. }
  10396. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10397. if (!lua_interface)
  10398. return 0;
  10399. Spawn* spawn = lua_interface->GetSpawn(state);
  10400. string field = lua_interface->GetStringValue(state, 2);
  10401. float value = lua_interface->GetFloatValue(state, 3);
  10402. lua_interface->ResetFunctionStack(state);
  10403. if(!spawn || !spawn->IsEntity())
  10404. {
  10405. lua_interface->LogError("%s: LUA SetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10406. return 0;
  10407. }
  10408. Entity* ent = (Entity*)spawn;
  10409. bool set_ = ent->SetInfoStructFloat(field, value);
  10410. lua_interface->SetBooleanValue(state, set_);
  10411. return 1;
  10412. }
  10413. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10414. if (!lua_interface)
  10415. return 0;
  10416. Spawn* spawn = lua_interface->GetSpawn(state);
  10417. bool value = lua_interface->GetBooleanValue(state, 2);
  10418. lua_interface->ResetFunctionStack(state);
  10419. if(!spawn || !spawn->IsPlayer())
  10420. {
  10421. lua_interface->LogError("%s: LUA SetCharSheetChanged command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  10422. return 0;
  10423. }
  10424. ((Player*)spawn)->SetCharSheetChanged(value);
  10425. return 0;
  10426. }
  10427. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10428. if (!lua_interface)
  10429. return 0;
  10430. Spawn* spawn = lua_interface->GetSpawn(state);
  10431. std::string fromName = lua_interface->GetStringValue(state, 2);
  10432. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10433. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10434. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10435. int32 copper = lua_interface->GetInt32Value(state, 6);
  10436. int32 silver = lua_interface->GetInt32Value(state, 7);
  10437. int32 gold = lua_interface->GetInt32Value(state, 8);
  10438. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10439. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10440. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10441. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10442. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10443. lua_interface->ResetFunctionStack(state);
  10444. if(!spawn || !spawn->IsPlayer())
  10445. {
  10446. lua_interface->LogError("%s: LUA AddPlayerMail command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  10447. lua_interface->SetBooleanValue(state, false);
  10448. return 1;
  10449. }
  10450. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10451. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10452. lua_interface->SetBooleanValue(state, true);
  10453. return 1;
  10454. }
  10455. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10456. if (!lua_interface)
  10457. return 0;
  10458. int32 char_id = lua_interface->GetInt32Value(state);
  10459. std::string fromName = lua_interface->GetStringValue(state, 2);
  10460. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10461. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10462. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10463. int32 copper = lua_interface->GetInt32Value(state, 6);
  10464. int32 silver = lua_interface->GetInt32Value(state, 7);
  10465. int32 gold = lua_interface->GetInt32Value(state, 8);
  10466. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10467. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10468. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10469. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10470. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10471. lua_interface->ResetFunctionStack(state);
  10472. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10473. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10474. lua_interface->SetBooleanValue(state, true);
  10475. return 1;
  10476. }
  10477. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10478. Spawn* widget;
  10479. if (lua_interface) {
  10480. widget = lua_interface->GetSpawn(state);
  10481. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10482. lua_interface->ResetFunctionStack(state);
  10483. if (widget && widget->IsWidget())
  10484. {
  10485. ((Widget*)widget)->OpenDoor();
  10486. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10487. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10488. }
  10489. else
  10490. lua_interface->LogError("%s: LUA OpenDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  10491. }
  10492. return 0;
  10493. }
  10494. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10495. Spawn* widget;
  10496. if (lua_interface) {
  10497. widget = lua_interface->GetSpawn(state);
  10498. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10499. lua_interface->ResetFunctionStack(state);
  10500. if (widget && widget->IsWidget())
  10501. {
  10502. ((Widget*)widget)->CloseDoor();
  10503. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10504. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10505. }
  10506. else
  10507. lua_interface->LogError("%s: LUA CloseDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  10508. }
  10509. return 0;
  10510. }
  10511. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10512. if (!lua_interface)
  10513. return 0;
  10514. Spawn* widget = lua_interface->GetSpawn(state);
  10515. lua_interface->ResetFunctionStack(state);
  10516. if (widget && widget->IsWidget())
  10517. {
  10518. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10519. return 1;
  10520. }
  10521. return 0;
  10522. }
  10523. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10524. if (!lua_interface)
  10525. return 0;
  10526. sint32 min = lua_interface->GetSInt32Value(state);
  10527. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10528. lua_interface->ResetFunctionStack(state);
  10529. sint32 result = MakeRandomInt(min, max);
  10530. lua_interface->SetSInt32Value(state, result);
  10531. return 1;
  10532. }
  10533. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10534. if (!lua_interface)
  10535. return 0;
  10536. float min = lua_interface->GetFloatValue(state);
  10537. float max = lua_interface->GetFloatValue(state, 2);
  10538. lua_interface->ResetFunctionStack(state);
  10539. float result = MakeRandomFloat(min, max);
  10540. lua_interface->SetFloatValue(state, result);
  10541. return 1;
  10542. }
  10543. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10544. if (!lua_interface)
  10545. return 0;
  10546. Spawn* spawn = lua_interface->GetSpawn(state);
  10547. int32 value = lua_interface->GetInt32Value(state, 2);
  10548. lua_interface->ResetFunctionStack(state);
  10549. if(!spawn)
  10550. {
  10551. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10552. lua_interface->SetBooleanValue(state, false);
  10553. return 1;
  10554. }
  10555. spawn->AddIconValue(value);
  10556. lua_interface->SetBooleanValue(state, true);
  10557. return 1;
  10558. }
  10559. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10560. if (!lua_interface)
  10561. return 0;
  10562. Spawn* spawn = lua_interface->GetSpawn(state);
  10563. int32 value = lua_interface->GetInt32Value(state, 2);
  10564. lua_interface->ResetFunctionStack(state);
  10565. if(!spawn)
  10566. {
  10567. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10568. lua_interface->SetBooleanValue(state, false);
  10569. return 1;
  10570. }
  10571. spawn->RemoveIconValue(value);
  10572. lua_interface->SetBooleanValue(state, true);
  10573. return 1;
  10574. }
  10575. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10576. Spawn* npc = lua_interface->GetSpawn(state);
  10577. lua_interface->ResetFunctionStack(state);
  10578. if (npc && npc->IsNPC()) {
  10579. NPC* shard = (NPC*)npc;
  10580. int32 shardid = shard->GetShardID();
  10581. lua_interface->SetInt32Value(state, shardid);
  10582. return 1;
  10583. }
  10584. lua_interface->SetInt32Value(state, 0);
  10585. return 1;
  10586. }
  10587. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10588. Spawn* npc = lua_interface->GetSpawn(state);
  10589. lua_interface->ResetFunctionStack(state);
  10590. if (npc && npc->IsNPC()) {
  10591. NPC* shard = (NPC*)npc;
  10592. int32 charid = shard->GetShardCharID();
  10593. lua_interface->SetInt32Value(state, charid);
  10594. return 1;
  10595. }
  10596. lua_interface->SetInt32Value(state, 0);
  10597. return 1;
  10598. }
  10599. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10600. Spawn* npc = lua_interface->GetSpawn(state);
  10601. lua_interface->ResetFunctionStack(state);
  10602. if (npc && npc->IsNPC()) {
  10603. NPC* shard = (NPC*)npc;
  10604. int64 timestamp = shard->GetShardCreatedTimestamp();
  10605. lua_interface->SetSInt64Value(state, timestamp);
  10606. return 1;
  10607. }
  10608. lua_interface->SetSInt64Value(state, 0);
  10609. return 1;
  10610. }
  10611. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10612. if (!lua_interface)
  10613. return 0;
  10614. int32 shardid = lua_interface->GetInt32Value(state);
  10615. lua_interface->ResetFunctionStack(state);
  10616. if(shardid < 1)
  10617. lua_interface->SetBooleanValue(state, false);
  10618. else
  10619. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10620. return 1;
  10621. }
  10622. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10623. if (!lua_interface)
  10624. return 0;
  10625. Spawn* spawn = lua_interface->GetSpawn(state);
  10626. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10627. if (spawn) {
  10628. spawn->PauseMovement(delay_in_ms);
  10629. }
  10630. lua_interface->ResetFunctionStack(state);
  10631. return 0;
  10632. }
  10633. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10634. if (!lua_interface)
  10635. return 0;
  10636. Spawn* spawn = lua_interface->GetSpawn(state);
  10637. if (spawn) {
  10638. spawn->StopMovement();
  10639. }
  10640. lua_interface->ResetFunctionStack(state);
  10641. return 0;
  10642. }
  10643. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10644. Player* player = (Player*)lua_interface->GetSpawn(state);
  10645. int8 level = lua_interface->GetInt8Value(state, 2);
  10646. lua_interface->ResetFunctionStack(state);
  10647. if (player && player->IsPlayer() && level > 0) {
  10648. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10649. return 1;
  10650. }
  10651. return 0;
  10652. }
  10653. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10654. Player* player = (Player*)lua_interface->GetSpawn(state);
  10655. int8 level = lua_interface->GetInt8Value(state, 2);
  10656. lua_interface->ResetFunctionStack(state);
  10657. if (player && player->IsPlayer() && level > 0) {
  10658. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10659. return 1;
  10660. }
  10661. return 0;
  10662. }
  10663. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10664. ZoneServer* zone = lua_interface->GetZone(state);
  10665. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10666. lua_interface->ResetFunctionStack(state);
  10667. if (zone) {
  10668. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10669. if (spawn) {
  10670. lua_interface->SetSpawnValue(state, spawn);
  10671. return 1;
  10672. }
  10673. }
  10674. return 0;
  10675. }
  10676. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10677. if (!lua_interface)
  10678. return 0;
  10679. Spawn* spawn = lua_interface->GetSpawn(state);
  10680. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10681. lua_interface->ResetFunctionStack(state);
  10682. bool res = false;
  10683. if(spawn && spawn->IsTransportSpawn())
  10684. {
  10685. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10686. spawn->SetRailID(rail_id);
  10687. res = true;
  10688. }
  10689. else if (!spawn) {
  10690. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10691. }
  10692. else if(!spawn->IsTransportSpawn()) {
  10693. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  10694. }
  10695. lua_interface->SetBooleanValue(state, res);
  10696. return 1;
  10697. }
  10698. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10699. ZoneServer* zone = lua_interface->GetZone(state);
  10700. lua_interface->ResetFunctionStack(state);
  10701. if (zone) {
  10702. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10703. return 1;
  10704. }
  10705. return 0;
  10706. }
  10707. int EQ2Emu_lua_IsRunning(lua_State* state) {
  10708. Spawn* spawn = lua_interface->GetSpawn(state);
  10709. lua_interface->ResetFunctionStack(state);
  10710. if (spawn) {
  10711. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  10712. return 1;
  10713. }
  10714. return 0;
  10715. }
  10716. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  10717. if (!lua_interface)
  10718. return 0;
  10719. Spawn* player = lua_interface->GetSpawn(state);
  10720. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  10721. bool displayClient = lua_interface->GetInt32Value(state, 3);
  10722. lua_interface->ResetFunctionStack(state);
  10723. if (!player || !player->IsPlayer() || !player->GetClient()) {
  10724. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  10725. }
  10726. else if(!zoneID) {
  10727. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  10728. }
  10729. else
  10730. {
  10731. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  10732. return 1;
  10733. }
  10734. return 0;
  10735. }