LuaFunctions.cpp 434 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167
  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. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 561 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //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
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //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
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. 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());
  399. }
  400. else
  401. 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());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. 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.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. 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
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. if(spawn->GetSpawnGroupID() == new_group_id) {
  685. lua_interface->SetBooleanValue(state, false);
  686. return 1;
  687. }
  688. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  689. lua_interface->SetBooleanValue(state, true);
  690. return 1;
  691. }
  692. lua_interface->SetBooleanValue(state, false);
  693. return 1;
  694. }
  695. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  696. Spawn* spawn = lua_interface->GetSpawn(state);
  697. lua_interface->ResetFunctionStack(state);
  698. if (spawn) {
  699. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  700. return 1;
  701. }
  702. return 0;
  703. }
  704. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  705. Spawn* spawn = lua_interface->GetSpawn(state);
  706. lua_interface->ResetFunctionStack(state);
  707. if (spawn) {
  708. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  709. return 1;
  710. }
  711. return 0;
  712. }
  713. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  714. Player* player = (Player*)lua_interface->GetSpawn(state);
  715. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  716. lua_interface->ResetFunctionStack(state);
  717. if (player && player->IsPlayer() && faction_id > 0) {
  718. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  719. return 1;
  720. }
  721. return 0;
  722. }
  723. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  724. if (!lua_interface)
  725. return 0;
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. int32 value = lua_interface->GetInt32Value(state, 2);
  728. lua_interface->ResetFunctionStack(state);
  729. if (spawn) {
  730. spawn->SetFactionID(value);
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  735. Spawn* spawn = lua_interface->GetSpawn(state);
  736. lua_interface->ResetFunctionStack(state);
  737. if (spawn) {
  738. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  739. return 1;
  740. }
  741. return 0;
  742. }
  743. int EQ2Emu_lua_GetGender(lua_State* state) {
  744. Spawn* spawn = lua_interface->GetSpawn(state);
  745. lua_interface->ResetFunctionStack(state);
  746. if (spawn) {
  747. lua_interface->SetInt32Value(state, spawn->GetGender());
  748. return 1;
  749. }
  750. return 0;
  751. }
  752. int EQ2Emu_lua_GetTarget(lua_State* state) {
  753. Spawn* spawn = lua_interface->GetSpawn(state);
  754. lua_interface->ResetFunctionStack(state);
  755. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  756. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  757. return 1;
  758. }
  759. return 0;
  760. }
  761. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  762. if (!lua_interface)
  763. return 0;
  764. Spawn* spawn = lua_interface->GetSpawn(state);
  765. string mp3_string = lua_interface->GetStringValue(state, 2);
  766. int32 key1 = lua_interface->GetInt32Value(state, 3);
  767. int32 key2 = lua_interface->GetInt32Value(state, 4);
  768. Spawn* player = lua_interface->GetSpawn(state, 5);
  769. lua_interface->ResetFunctionStack(state);
  770. if (spawn && mp3_string.length() > 0) {
  771. Client* client = 0;
  772. if (player && player->IsPlayer())
  773. client = ((Player*)player)->GetClient();
  774. if (client) {
  775. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  776. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  777. }
  778. else
  779. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  780. }
  781. return 0;
  782. }
  783. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  784. if (!lua_interface)
  785. return 0;
  786. Spawn* spawn = lua_interface->GetSpawn(state);
  787. lua_interface->ResetFunctionStack(state);
  788. if (spawn) {
  789. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  790. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  791. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  792. return 3;
  793. }
  794. return 0;
  795. }
  796. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. lua_interface->ResetFunctionStack(state);
  803. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  804. return 1;
  805. }
  806. lua_interface->ResetFunctionStack(state);
  807. return 0;
  808. }
  809. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  810. if (!lua_interface)
  811. return 0;
  812. Spawn* spawn = lua_interface->GetSpawn(state);
  813. if (spawn && spawn->IsEntity()) {
  814. int32 item_id = lua_interface->GetInt32Value(state, 2);
  815. int16 charges = lua_interface->GetInt16Value(state, 3);
  816. if (charges == 0)
  817. charges = 1;
  818. ((Entity*)spawn)->AddLootItem(item_id, charges);
  819. }
  820. lua_interface->ResetFunctionStack(state);
  821. return 0;
  822. }
  823. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  824. if (!lua_interface)
  825. return 0;
  826. Spawn* spawn = lua_interface->GetSpawn(state);
  827. if (spawn && spawn->IsEntity()) {
  828. int32 item_id = lua_interface->GetInt32Value(state, 2);
  829. Item* item = spawn->LootItem(item_id);
  830. lua_interface->SetLuaUserDataStale(item);
  831. safe_delete(item);
  832. }
  833. lua_interface->ResetFunctionStack(state);
  834. return 0;
  835. }
  836. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  837. if (!lua_interface)
  838. return 0;
  839. Spawn* spawn = lua_interface->GetSpawn(state);
  840. if (spawn) {
  841. int32 val = lua_interface->GetInt32Value(state, 2);
  842. spawn->AddLootCoins(val);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. if (entity && player && player->IsPlayer()) {
  853. int32 coins = lua_interface->GetInt32Value(state, 3);
  854. vector<Item*>* items = 0;
  855. int i = 0;
  856. int32 item_id = 0;
  857. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  858. if (items == 0)
  859. items = new vector<Item*>;
  860. if (master_item_list.GetItem(item_id))
  861. items->push_back(master_item_list.GetItem(item_id));
  862. i++;
  863. }
  864. Client* client = 0;
  865. client = ((Player*)player)->GetClient();
  866. if (client)
  867. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  868. if(coins > 0)
  869. entity->AddLootCoins(coins);
  870. safe_delete(items);
  871. }
  872. lua_interface->ResetFunctionStack(state);
  873. return 0;
  874. }
  875. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  876. if (!lua_interface)
  877. return 0;
  878. Spawn* entity = lua_interface->GetSpawn(state);
  879. Spawn* player = lua_interface->GetSpawn(state, 2);
  880. int32 item_id = lua_interface->GetInt32Value(state, 3);
  881. lua_interface->ResetFunctionStack(state);
  882. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  883. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  884. return 1;
  885. }
  886. return 0;
  887. }
  888. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  889. if (!lua_interface)
  890. return 0;
  891. Spawn* entity = lua_interface->GetSpawn(state);
  892. Spawn* player = lua_interface->GetSpawn(state, 2);
  893. lua_interface->ResetFunctionStack(state);
  894. if (entity && player && player->IsPlayer()) {
  895. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  896. return 1;
  897. }
  898. return 0;
  899. }
  900. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  901. if (!lua_interface)
  902. return 0;
  903. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  904. lua_interface->SetLuaUserDataStale(conversation);
  905. safe_delete(conversation);
  906. lua_interface->ResetFunctionStack(state);
  907. conversation = new vector<ConversationOption>();
  908. lua_interface->SetConversationValue(state, conversation);
  909. return 1;
  910. }
  911. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  915. if (conversation) {
  916. ConversationOption conv_option;
  917. conv_option.option = lua_interface->GetStringValue(state, 2);
  918. conv_option.function = lua_interface->GetStringValue(state, 3);
  919. if (conv_option.option.length() > 0)
  920. conversation->push_back(conv_option);
  921. }
  922. lua_interface->ResetFunctionStack(state);
  923. return 0;
  924. }
  925. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  926. if (!lua_interface)
  927. return 0;
  928. Spawn* npc = lua_interface->GetSpawn(state);
  929. Spawn* player = lua_interface->GetSpawn(state, 2);
  930. lua_interface->ResetFunctionStack(state);
  931. if (npc && player && player->IsPlayer() && player->GetZone()) {
  932. Client* client = ((Player*)player)->GetClient();
  933. if (client) {
  934. int32 conversation_id = client->GetConversationID(npc, 0);
  935. client->CloseDialog(conversation_id);
  936. }
  937. }
  938. return 0;
  939. }
  940. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  941. if (!lua_interface)
  942. return 0;
  943. Item* item = lua_interface->GetItem(state);
  944. Spawn* player = lua_interface->GetSpawn(state, 2);
  945. lua_interface->ResetFunctionStack(state);
  946. if (item && player && player->IsPlayer() && player->GetZone()) {
  947. Client* client = ((Player*)player)->GetClient();
  948. if (client) {
  949. int32 conversation_id = client->GetConversationID(0, item);
  950. client->CloseDialog(conversation_id);
  951. }
  952. }
  953. return 0;
  954. }
  955. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  956. if (!lua_interface)
  957. return 0;
  958. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  959. Spawn* spawn = 0;
  960. Item* item = 0;
  961. int8 type = lua_interface->GetInt8Value(state, 2);
  962. if (type == 1 || type == 3)
  963. spawn = lua_interface->GetSpawn(state, 3);
  964. else if (type == 2 || type == 4)
  965. item = lua_interface->GetItem(state, 3);
  966. Spawn* player = lua_interface->GetSpawn(state, 4);
  967. string text = lua_interface->GetStringValue(state, 5);
  968. string mp3 = lua_interface->GetStringValue(state, 6);
  969. int32 key1 = lua_interface->GetInt32Value(state, 7);
  970. int32 key2 = lua_interface->GetInt32Value(state, 8);
  971. int8 language = lua_interface->GetInt8Value(state, 9);
  972. int numargs = lua_interface->GetNumberOfArgs(state);
  973. int8 can_close = 1;
  974. if(numargs > 9)
  975. can_close = lua_interface->GetInt32Value(state, 10);
  976. lua_interface->ResetFunctionStack(state);
  977. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  978. Client* client = ((Player*)player)->GetClient();
  979. if (client) {
  980. if (spawn) {
  981. // Need to do this so the function works the same as it did before
  982. if (type == 1)
  983. type++;
  984. if (mp3.length() > 0)
  985. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  986. else
  987. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  988. }
  989. else {
  990. if (mp3.length() > 0)
  991. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  992. else
  993. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  994. }
  995. }
  996. }
  997. lua_interface->SetLuaUserDataStale(conversation);
  998. safe_delete(conversation);
  999. return 0;
  1000. }
  1001. int EQ2Emu_lua_StartConversation(lua_State* state) {
  1002. if (!lua_interface)
  1003. return 0;
  1004. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1005. Spawn* source = lua_interface->GetSpawn(state, 2);
  1006. Spawn* player = lua_interface->GetSpawn(state, 3);
  1007. string text = lua_interface->GetStringValue(state, 4);
  1008. string mp3 = lua_interface->GetStringValue(state, 5);
  1009. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1010. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1011. int8 language = lua_interface->GetInt32Value(state, 8);
  1012. int numargs = lua_interface->GetNumberOfArgs(state);
  1013. int8 can_close = 1;
  1014. if(numargs > 8)
  1015. can_close = lua_interface->GetInt32Value(state, 9);
  1016. lua_interface->ResetFunctionStack(state);
  1017. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1018. Client* client = ((Player*)player)->GetClient();
  1019. if (mp3.length() > 0)
  1020. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1021. else
  1022. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1023. lua_interface->SetLuaUserDataStale(conversation);
  1024. safe_delete(conversation);
  1025. }
  1026. else
  1027. 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);
  1028. return 0;
  1029. }
  1030. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1031. if (!lua_interface)
  1032. return 0;
  1033. Spawn* spawn = lua_interface->GetSpawn(state);
  1034. float distance = lua_interface->GetFloatValue(state, 2);
  1035. string in_range_function = lua_interface->GetStringValue(state, 3);
  1036. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1037. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1038. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1039. return 0;
  1040. }
  1041. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1042. ZoneServer* zone = lua_interface->GetZone(state);
  1043. float x = lua_interface->GetFloatValue(state, 2);
  1044. float y = lua_interface->GetFloatValue(state, 3);
  1045. float z = lua_interface->GetFloatValue(state, 4);
  1046. float max_variation = lua_interface->GetFloatValue(state, 5);
  1047. string in_range_function = lua_interface->GetStringValue(state, 6);
  1048. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1049. lua_interface->ResetFunctionStack(state);
  1050. if (zone && in_range_function.length() > 0)
  1051. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1052. return 0;
  1053. }
  1054. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1055. if (!lua_interface)
  1056. return 0;
  1057. Spawn* spawn = lua_interface->GetSpawn(state);
  1058. if (spawn && spawn->IsEntity()) {
  1059. int32 val = lua_interface->GetInt32Value(state, 2);
  1060. ((Entity*)spawn)->SetLootCoins(val);
  1061. }
  1062. lua_interface->ResetFunctionStack(state);
  1063. return 0;
  1064. }
  1065. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1066. if (!lua_interface)
  1067. return 0;
  1068. Spawn* spawn = lua_interface->GetSpawn(state);
  1069. lua_interface->ResetFunctionStack(state);
  1070. if (spawn && spawn->IsEntity()) {
  1071. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1072. return 1;
  1073. }
  1074. return 0;
  1075. }
  1076. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1077. if (!lua_interface)
  1078. return 0;
  1079. Spawn* spawn = lua_interface->GetSpawn(state);
  1080. float x = lua_interface->GetFloatValue(state, 2);
  1081. float y = lua_interface->GetFloatValue(state, 3);
  1082. float z = lua_interface->GetFloatValue(state, 4);
  1083. float speed = lua_interface->GetFloatValue(state, 5);
  1084. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1085. string function = lua_interface->GetStringValue(state, 7);
  1086. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1087. float heading = lua_interface->GetFloatValue(state, 8);
  1088. if (spawn) {
  1089. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1090. spawn->GetZone()->AddMovementNPC(spawn);
  1091. }
  1092. lua_interface->ResetFunctionStack(state);
  1093. return 0;
  1094. }
  1095. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1096. if (!lua_interface)
  1097. return 0;
  1098. Spawn* spawn = lua_interface->GetSpawn(state);
  1099. lua_interface->ResetFunctionStack(state);
  1100. if (spawn) {
  1101. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1102. return 1;
  1103. }
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. Spawn* spawn = lua_interface->GetSpawn(state);
  1110. lua_interface->ResetFunctionStack(state);
  1111. if (spawn && spawn->IsPlayer()) {
  1112. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1113. return 1;
  1114. }
  1115. lua_interface->SetInt32Value(state, 0);
  1116. return 1;
  1117. }
  1118. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. Spawn* target = lua_interface->GetSpawn(state, 2);
  1123. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1124. bool reset_action_state = true;
  1125. if(num_args > 2)
  1126. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1127. if (spawn && target) {
  1128. if (spawn->IsEntity())
  1129. // ((Entity*)spawn)->FaceTarget(target);
  1130. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1131. }
  1132. lua_interface->ResetFunctionStack(state);
  1133. return 0;
  1134. }
  1135. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1136. if (!lua_interface)
  1137. return 0;
  1138. Spawn* spawn = lua_interface->GetSpawn(state);
  1139. float x = lua_interface->GetFloatValue(state, 2);
  1140. float y = lua_interface->GetFloatValue(state, 3);
  1141. float z = lua_interface->GetFloatValue(state, 4);
  1142. float speed = lua_interface->GetFloatValue(state, 5);
  1143. string lua_function = lua_interface->GetStringValue(state, 6);
  1144. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1145. if (spawn) {
  1146. if (speed == 0)
  1147. speed = spawn->GetSpeed();
  1148. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1149. }
  1150. lua_interface->ResetFunctionStack(state);
  1151. return 0;
  1152. }
  1153. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1154. if (!lua_interface)
  1155. return 0;
  1156. Spawn* spawn = lua_interface->GetSpawn(state);
  1157. lua_interface->ResetFunctionStack(state);
  1158. if (spawn) {
  1159. spawn->ClearRunningLocations();
  1160. }
  1161. return 0;
  1162. }
  1163. int EQ2Emu_lua_Say(lua_State* state) {
  1164. if (!lua_interface)
  1165. return 0;
  1166. Spawn* spawn = lua_interface->GetSpawn(state);
  1167. string message = lua_interface->GetStringValue(state, 2);
  1168. Spawn* player = lua_interface->GetSpawn(state, 3);
  1169. float dist = lua_interface->GetFloatValue(state, 4);
  1170. int32 language = lua_interface->GetInt32Value(state, 5);
  1171. if (spawn && message.length() > 0) {
  1172. Client* client = 0;
  1173. if (player && player->IsPlayer())
  1174. client = ((Player*)player)->GetClient();
  1175. if (client)
  1176. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1177. else
  1178. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1179. }
  1180. lua_interface->ResetFunctionStack(state);
  1181. return 0;
  1182. }
  1183. int EQ2Emu_lua_Shout(lua_State* state) {
  1184. if (!lua_interface)
  1185. return 0;
  1186. Spawn* spawn = lua_interface->GetSpawn(state);
  1187. string message = lua_interface->GetStringValue(state, 2);
  1188. Spawn* player = lua_interface->GetSpawn(state, 3);
  1189. float dist = lua_interface->GetFloatValue(state, 4);
  1190. int32 language = lua_interface->GetInt32Value(state, 5);
  1191. if (spawn && message.length() > 0) {
  1192. Client* client = 0;
  1193. if (player && player->IsPlayer())
  1194. client = ((Player*)player)->GetClient();
  1195. if (client)
  1196. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1197. else
  1198. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1199. }
  1200. lua_interface->ResetFunctionStack(state);
  1201. return 0;
  1202. }
  1203. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1204. if (!lua_interface)
  1205. return 0;
  1206. Spawn* spawn = lua_interface->GetSpawn(state);
  1207. string message = lua_interface->GetStringValue(state, 2);
  1208. Spawn* player = lua_interface->GetSpawn(state, 3);
  1209. float dist = lua_interface->GetFloatValue(state, 4);
  1210. int32 language = lua_interface->GetInt32Value(state, 5);
  1211. if (spawn && message.length() > 0) {
  1212. Client* client = 0;
  1213. if (player && player->IsPlayer())
  1214. client = ((Player*)player)->GetClient();
  1215. if (client)
  1216. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1217. else
  1218. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1219. }
  1220. lua_interface->ResetFunctionStack(state);
  1221. return 0;
  1222. }
  1223. int EQ2Emu_lua_Emote(lua_State* state) {
  1224. if (!lua_interface)
  1225. return 0;
  1226. Spawn* spawn = lua_interface->GetSpawn(state);
  1227. string message = lua_interface->GetStringValue(state, 2);
  1228. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1229. Spawn* player = lua_interface->GetSpawn(state, 4);
  1230. char* to = 0;
  1231. if (spawn2)
  1232. to = spawn2->GetName();
  1233. if (spawn && message.length() > 0) {
  1234. Client* client = 0;
  1235. if (player && player->IsPlayer())
  1236. client = ((Player*)player)->GetClient();
  1237. if (client)
  1238. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1239. else
  1240. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1241. }
  1242. lua_interface->ResetFunctionStack(state);
  1243. return 0;
  1244. }
  1245. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1246. if (!lua_interface)
  1247. return 0;
  1248. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1249. if(!luaspell || luaspell->resisted) {
  1250. lua_interface->ResetFunctionStack(state);
  1251. return 0;
  1252. }
  1253. Spawn* caster = luaspell->caster;
  1254. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1255. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1256. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1257. Spawn* target = lua_interface->GetSpawn(state, 4);
  1258. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1259. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1260. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1261. lua_interface->ResetFunctionStack(state);
  1262. boost::to_lower(heal_type);
  1263. if (caster && caster->IsEntity()) {
  1264. bool success = false;
  1265. luaspell->resisted = false;
  1266. if (target) {
  1267. float distance = caster->GetDistance(target, true);
  1268. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1269. success = true;
  1270. }
  1271. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1272. Spawn* target = 0;
  1273. ZoneServer* zone = luaspell->caster->GetZone();
  1274. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1275. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1276. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1277. float distance = caster->GetDistance(target, true);
  1278. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1279. }
  1280. }
  1281. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1282. success = true;
  1283. }
  1284. if (success) {
  1285. if (caster->GetZone())
  1286. caster->GetZone()->TriggerCharSheetTimer();
  1287. }
  1288. }
  1289. return 0;
  1290. }
  1291. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1292. if (!lua_interface)
  1293. return 0;
  1294. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1295. if(!luaspell || luaspell->resisted) {
  1296. lua_interface->ResetFunctionStack(state);
  1297. return 0;
  1298. }
  1299. Spawn* caster = luaspell->caster;
  1300. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1301. float percentage = lua_interface->GetFloatValue(state, 2);
  1302. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1303. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1304. Spawn* target = lua_interface->GetSpawn(state, 5);
  1305. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1306. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1307. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1308. lua_interface->ResetFunctionStack(state);
  1309. boost::to_lower(heal_type);
  1310. int32 min_heal = 0, max_heal = 0;
  1311. if (caster && caster->IsEntity() && target) {
  1312. if(percentage <= 0.0f)
  1313. {
  1314. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1315. return 0;
  1316. }
  1317. if(heal_type == "power")
  1318. {
  1319. if(current_value)
  1320. {
  1321. if(caster_value)
  1322. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1323. else
  1324. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1325. }
  1326. else
  1327. {
  1328. if(caster_value)
  1329. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1330. else
  1331. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1332. }
  1333. }
  1334. else
  1335. {
  1336. if(current_value)
  1337. {
  1338. if(caster_value)
  1339. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1340. else
  1341. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1342. }
  1343. else
  1344. {
  1345. if(caster_value)
  1346. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1347. else
  1348. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1349. }
  1350. }
  1351. bool success = false;
  1352. luaspell->resisted = false;
  1353. if (target) {
  1354. float distance = caster->GetDistance(target, true);
  1355. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1356. success = true;
  1357. }
  1358. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1359. Spawn* target = 0;
  1360. ZoneServer* zone = luaspell->caster->GetZone();
  1361. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1362. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1363. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1364. float distance = caster->GetDistance(target, true);
  1365. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1366. }
  1367. }
  1368. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1369. success = true;
  1370. }
  1371. if (success) {
  1372. if (caster->GetZone())
  1373. caster->GetZone()->TriggerCharSheetTimer();
  1374. }
  1375. }
  1376. return 0;
  1377. }
  1378. int EQ2Emu_lua_AddItem(lua_State* state) {
  1379. if (!lua_interface)
  1380. return 0;
  1381. Spawn* spawn = lua_interface->GetSpawn(state);
  1382. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1383. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1384. lua_interface->ResetFunctionStack(state);
  1385. // default of 1 quantity to add
  1386. if (quantity == 0)
  1387. quantity = 1;
  1388. if (spawn && spawn->IsPlayer()) {
  1389. Client* client = ((Player*)spawn)->GetClient();
  1390. if (client && item_id > 0) {
  1391. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1392. return 1;
  1393. }
  1394. }
  1395. lua_interface->SetBooleanValue(state, false);
  1396. return 1;
  1397. }
  1398. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1399. if (!lua_interface)
  1400. return 0;
  1401. Spawn* spawn = lua_interface->GetSpawn(state);
  1402. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1403. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1404. string location = lua_interface->GetStringValue(state, 4);
  1405. int16 item_count = lua_interface->GetInt16Value(state,5);
  1406. //devn00b: if we dont have a count, assume 1 item.
  1407. if(!item_count) {
  1408. item_count = 1;
  1409. }
  1410. lua_interface->ResetFunctionStack(state);
  1411. if (spawn && spawn->IsPlayer()) {
  1412. Client* client = ((Player*)spawn)->GetClient();
  1413. if (client && item_id > 0) {
  1414. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1415. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1416. else
  1417. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1418. if (send_messages) {
  1419. Item* item = master_item_list.GetItem(item_id);
  1420. if (item) {
  1421. if(item_count > 1) {
  1422. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1423. string popup_text1 = "You receive "+ item_count;
  1424. string popup_text2 = " " + item->name;
  1425. string popup_text = popup_text1 + popup_text2;
  1426. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1427. // return 1;
  1428. } else {
  1429. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1430. string popup_text = "You receive " + item->name;
  1431. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1432. }
  1433. }
  1434. }
  1435. return 1;
  1436. }
  1437. }
  1438. lua_interface->SetBooleanValue(state, false);
  1439. return 1;
  1440. }
  1441. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1442. Spawn* spawn = lua_interface->GetSpawn(state);
  1443. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1444. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1445. lua_interface->ResetFunctionStack(state);
  1446. // default of 1 to remove
  1447. if (quantity == 0)
  1448. quantity = 1;
  1449. Client* client;
  1450. Item* item;
  1451. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1452. if ((client = ((Player*)spawn)->GetClient())) {
  1453. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1454. if (client->RemoveItem(item, quantity)) {
  1455. lua_interface->SetBooleanValue(state, true);
  1456. return 1;
  1457. }
  1458. }
  1459. }
  1460. }
  1461. lua_interface->SetBooleanValue(state, false);
  1462. return 1;
  1463. }
  1464. int EQ2Emu_lua_HasItem(lua_State* state) {
  1465. Spawn* player = lua_interface->GetSpawn(state);
  1466. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1467. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1468. lua_interface->ResetFunctionStack(state);
  1469. if (player && player->IsPlayer()) {
  1470. bool hasItem = false;
  1471. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1472. if (!hasItem)
  1473. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1474. lua_interface->SetBooleanValue(state, hasItem);
  1475. return 1;
  1476. }
  1477. lua_interface->SetBooleanValue(state, false);
  1478. return 1;
  1479. }
  1480. int EQ2Emu_lua_Spawn(lua_State* state) {
  1481. if (!lua_interface)
  1482. return 0;
  1483. ZoneServer* zone = lua_interface->GetZone(state);
  1484. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1485. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1486. float x = lua_interface->GetFloatValue(state, 4);
  1487. float y = lua_interface->GetFloatValue(state, 5);
  1488. float z = lua_interface->GetFloatValue(state, 6);
  1489. float heading = lua_interface->GetFloatValue(state, 7);
  1490. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1491. Spawn* spawn = zone->GetSpawn(spawn_id);
  1492. if (!spawn)
  1493. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1494. else {
  1495. spawn->SetX(x);
  1496. spawn->SetZ(z);
  1497. spawn->SetY(y,true,true);
  1498. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1499. spawn->SetHeading(heading);
  1500. if (restricted_npc)
  1501. spawn->AddAllowAccessSpawn(spawn);
  1502. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1503. bool scriptActive = false;
  1504. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1505. scriptActive = true;
  1506. spawn->SetSpawnScript(string(spawn_script));
  1507. }
  1508. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1509. zone->AddSpawn(spawn);
  1510. if (scriptActive) {
  1511. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1512. }
  1513. lua_interface->ResetFunctionStack(state);
  1514. lua_interface->SetSpawnValue(state, spawn);
  1515. return 1;
  1516. }
  1517. }
  1518. else {
  1519. string output = "Invalid paramaters to LUA Spawn command: \n";
  1520. if (!zone)
  1521. output = output.append("\t").append("Missing zone reference. \n");
  1522. if (spawn_id == 0)
  1523. output = output.append("\t").append("Missing spawn_id.");
  1524. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1525. }
  1526. lua_interface->ResetFunctionStack(state);
  1527. return 0;
  1528. }
  1529. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1530. if (!lua_interface)
  1531. return 0;
  1532. ZoneServer* zone = lua_interface->GetZone(state);
  1533. lua_interface->ResetFunctionStack(state);
  1534. if (zone) {
  1535. lua_interface->SetStringValue(state, zone->GetZoneName());
  1536. return 1;
  1537. }
  1538. return 0;
  1539. }
  1540. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1541. if (!lua_interface)
  1542. return 0;
  1543. ZoneServer* zone = lua_interface->GetZone(state);
  1544. lua_interface->ResetFunctionStack(state);
  1545. if (zone) {
  1546. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1547. return 1;
  1548. }
  1549. return 0;
  1550. }
  1551. int EQ2Emu_lua_GetZone(lua_State* state) {
  1552. if (!lua_interface)
  1553. return 0;
  1554. int32 zone_id = lua_interface->GetInt32Value(state);
  1555. ZoneServer* zone = 0;
  1556. if (zone_id > 0)
  1557. zone = zone_list.Get(zone_id, true, false, false);
  1558. else {
  1559. string zone_name = lua_interface->GetStringValue(state);
  1560. if (zone_name.length() > 0) {
  1561. zone = zone_list.Get(zone_name.c_str(), true, false, false);
  1562. }
  1563. else {
  1564. Spawn* spawn = lua_interface->GetSpawn(state);
  1565. if (spawn)
  1566. zone = spawn->GetZone();
  1567. }
  1568. }
  1569. lua_interface->ResetFunctionStack(state);
  1570. if (zone) {
  1571. lua_interface->SetZoneValue(state, zone);
  1572. return 1;
  1573. }
  1574. return 0;
  1575. }
  1576. int EQ2Emu_lua_AddHate(lua_State* state) {
  1577. Spawn* entity = lua_interface->GetSpawn(state);
  1578. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1579. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1580. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1581. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1582. if(luaspell && luaspell->resisted) {
  1583. lua_interface->ResetFunctionStack(state);
  1584. return 0;
  1585. }
  1586. if (entity && entity->IsEntity() && amount != 0) {
  1587. if (luaspell && luaspell->caster) {
  1588. ZoneServer* zone = luaspell->caster->GetZone();
  1589. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1590. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1591. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1592. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1593. entity->CheckEncounterState((Entity*)spawn);
  1594. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1595. if (send_packet)
  1596. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1597. }
  1598. }
  1599. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1600. }
  1601. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1602. entity->CheckEncounterState((Entity*)npc);
  1603. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1604. }
  1605. }
  1606. lua_interface->ResetFunctionStack(state);
  1607. return 0;
  1608. }
  1609. int EQ2Emu_lua_Zone(lua_State* state) {
  1610. if (!lua_interface)
  1611. return 0;
  1612. ZoneServer* zone = lua_interface->GetZone(state);
  1613. Spawn* player = lua_interface->GetSpawn(state, 2);
  1614. Client* client = 0;
  1615. if (player && player->IsPlayer())
  1616. client = ((Player*)player)->GetClient();
  1617. float x = lua_interface->GetFloatValue(state, 3);
  1618. float y = lua_interface->GetFloatValue(state, 4);
  1619. float z = lua_interface->GetFloatValue(state, 5);
  1620. float heading = lua_interface->GetFloatValue(state, 6);
  1621. if (zone && client) {
  1622. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1623. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1624. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1625. {
  1626. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1627. return 0;
  1628. }
  1629. if (x != 0 || y != 0 || z != 0) {
  1630. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1631. player->SetX(x);
  1632. player->SetY(y);
  1633. player->SetZ(z);
  1634. player->SetHeading(heading);
  1635. client->Zone(zone->GetZoneName(), false);
  1636. }
  1637. else
  1638. client->Zone(zone->GetZoneName());
  1639. }
  1640. else
  1641. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1642. lua_interface->ResetFunctionStack(state);
  1643. return 0;
  1644. }
  1645. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1646. if (!lua_interface)
  1647. return 0;
  1648. Spawn* spawn = lua_interface->GetSpawn(state);
  1649. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1650. if (spawn && spawn2)
  1651. spawn->AddAllowAccessSpawn(spawn2);
  1652. lua_interface->ResetFunctionStack(state);
  1653. return 0;
  1654. }
  1655. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1656. if (!lua_interface)
  1657. return 0;
  1658. Spawn* target = lua_interface->GetSpawn(state);
  1659. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1660. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1661. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1662. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1663. lua_interface->ResetFunctionStack(state);
  1664. if (!target) {
  1665. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1666. return 0;
  1667. }
  1668. if (!target->IsEntity()) {
  1669. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1670. return 0;
  1671. }
  1672. if (spell_id <= 0) {
  1673. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1674. return 0;
  1675. }
  1676. if (caster && !caster->IsEntity()) {
  1677. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1678. return 0;
  1679. }
  1680. if (spell_tier == 0)
  1681. spell_tier = 1;
  1682. if (!caster)
  1683. caster = target;
  1684. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1685. return 0;
  1686. }
  1687. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1688. if (!lua_interface)
  1689. return 0;
  1690. Spawn* target = lua_interface->GetSpawn(state);
  1691. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1692. if(!luaspell || luaspell->resisted) {
  1693. lua_interface->ResetFunctionStack(state);
  1694. lua_interface->SetBooleanValue(state, false);
  1695. return 1;
  1696. }
  1697. Spawn* caster = luaspell->caster;
  1698. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1699. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1700. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1701. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1702. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1703. //lua_interface->ResetFunctionStack(state);
  1704. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1705. vector<int16> faction_req;
  1706. vector<int16> race_req;
  1707. int32 class_req = 0;
  1708. int32 i = 0;
  1709. int8 f = 0;
  1710. int8 r = 0;
  1711. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1712. if (class_id < 100) {
  1713. class_req += pow(2.0, double(class_id - 1));
  1714. }
  1715. else if (class_id > 100 && class_id < 1000) {
  1716. race_req.push_back(class_id);
  1717. r++;
  1718. }
  1719. else {
  1720. faction_req.push_back(class_id);
  1721. f++;
  1722. }
  1723. i++;
  1724. }
  1725. lua_interface->ResetFunctionStack(state);
  1726. if (caster && caster->IsEntity()) {
  1727. bool race_match = false;
  1728. bool success = false;
  1729. luaspell->resisted = false;
  1730. if (luaspell->targets.size() > 0) {
  1731. ZoneServer* zone = luaspell->caster->GetZone();
  1732. Spawn* target = 0;
  1733. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1734. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1735. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1736. if (race_req.size() > 0) {
  1737. for (int8 i = 0; i < race_req.size(); i++) {
  1738. if(race_req[i] == target->GetRace() ||
  1739. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1740. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1741. race_match = true;
  1742. }
  1743. }
  1744. }
  1745. else
  1746. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1747. if (race_match == true) {
  1748. float distance = caster->GetDistance(target, true);
  1749. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1750. }
  1751. }
  1752. }
  1753. success = true;
  1754. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1755. }
  1756. else if (target) {
  1757. //check class and race/faction here
  1758. if (race_req.size() > 0) {
  1759. for (int8 i = 0; i < race_req.size(); i++) {
  1760. if(race_req[i] == target->GetRace() ||
  1761. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1762. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1763. race_match = true;
  1764. }
  1765. }
  1766. }
  1767. else
  1768. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1769. if (race_match == true) {
  1770. float distance = caster->GetDistance(target, true);
  1771. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1772. success = true;
  1773. }
  1774. }
  1775. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1776. if (success) {
  1777. Spell* spell = luaspell->spell;
  1778. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1779. ((Player*)caster)->InCombat(true);
  1780. if (caster->GetZone())
  1781. caster->GetZone()->TriggerCharSheetTimer();
  1782. }
  1783. }
  1784. }
  1785. else {
  1786. lua_interface->SetBooleanValue(state, false);
  1787. }
  1788. return 1;
  1789. }
  1790. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1791. if (!lua_interface)
  1792. return 0;
  1793. Spawn* target = lua_interface->GetSpawn(state);
  1794. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1795. if(!luaspell || luaspell->resisted) {
  1796. lua_interface->ResetFunctionStack(state);
  1797. lua_interface->SetBooleanValue(state, false);
  1798. return 1;
  1799. }
  1800. Spawn* caster = luaspell->caster;
  1801. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1802. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1803. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1804. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1805. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1806. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1807. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1808. //lua_interface->ResetFunctionStack(state);
  1809. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1810. vector<int16> faction_req;
  1811. vector<int16> race_req;
  1812. int32 class_req = 0;
  1813. int32 i = 0;
  1814. int8 f = 0;
  1815. int8 r = 0;
  1816. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1817. if (class_id < 100) {
  1818. class_req += pow(2.0, double(class_id - 1));
  1819. }
  1820. else if (class_id > 100 && class_id < 1000) {
  1821. race_req.push_back(class_id);
  1822. r++;
  1823. }
  1824. else {
  1825. faction_req.push_back(class_id);
  1826. f++;
  1827. }
  1828. i++;
  1829. }
  1830. lua_interface->ResetFunctionStack(state);
  1831. if (caster && caster->IsEntity()) {
  1832. bool race_match = false;
  1833. bool success = false;
  1834. luaspell->resisted = false;
  1835. if (luaspell->targets.size() > 0) {
  1836. ZoneServer* zone = luaspell->caster->GetZone();
  1837. Spawn* target = 0;
  1838. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1839. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1840. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1841. if (race_req.size() > 0) {
  1842. for (int8 i = 0; i < race_req.size(); i++) {
  1843. if(race_req[i] == target->GetRace() ||
  1844. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1845. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1846. race_match = true;
  1847. }
  1848. }
  1849. }
  1850. else
  1851. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1852. if (race_match == true) {
  1853. float distance = caster->GetDistance(target, true);
  1854. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1855. }
  1856. }
  1857. }
  1858. success = true;
  1859. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1860. }
  1861. else if (target) {
  1862. //check class and race/faction here
  1863. if (race_req.size() > 0) {
  1864. for (int8 i = 0; i < race_req.size(); i++) {
  1865. if(race_req[i] == target->GetRace() ||
  1866. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1867. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1868. race_match = true;
  1869. }
  1870. }
  1871. }
  1872. else
  1873. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1874. if (race_match == true) {
  1875. float distance = caster->GetDistance(target, true);
  1876. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1877. success = true;
  1878. }
  1879. }
  1880. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1881. if (success) {
  1882. Spell* spell = luaspell->spell;
  1883. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1884. ((Player*)caster)->InCombat(true);
  1885. if (caster->GetZone())
  1886. caster->GetZone()->TriggerCharSheetTimer();
  1887. }
  1888. }
  1889. }
  1890. else {
  1891. lua_interface->SetBooleanValue(state, false);
  1892. }
  1893. return 1;
  1894. }
  1895. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1896. if (!lua_interface)
  1897. return 0;
  1898. Spawn* spawn = lua_interface->GetSpawn(state);
  1899. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1900. lua_interface->ResetFunctionStack(state);
  1901. if (spawn && value != 0) {
  1902. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1903. spawn->SetPower(spawn->GetTotalPower());
  1904. else
  1905. spawn->SetPower(spawn->GetPower() + value);
  1906. }
  1907. return 0;
  1908. }
  1909. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1910. if (!lua_interface)
  1911. return 0;
  1912. Spawn* spawn = lua_interface->GetSpawn(state);
  1913. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1914. lua_interface->ResetFunctionStack(state);
  1915. if (spawn && value != 0) {
  1916. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1917. spawn->SetHP(spawn->GetTotalHP());
  1918. else
  1919. spawn->SetHP(spawn->GetHP() + value);
  1920. }
  1921. return 0;
  1922. }
  1923. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1924. if (!lua_interface)
  1925. return 0;
  1926. Spawn* spawn = lua_interface->GetSpawn(state);
  1927. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1928. lua_interface->ResetFunctionStack(state);
  1929. if (spawn && value != 0) {
  1930. spawn->SetTotalPower(value);
  1931. spawn->SetTotalPowerBaseInstance(value);
  1932. }
  1933. return 0;
  1934. }
  1935. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1936. if (!lua_interface)
  1937. return 0;
  1938. Spawn* spawn = lua_interface->GetSpawn(state);
  1939. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1940. lua_interface->ResetFunctionStack(state);
  1941. if (spawn && value != 0) {
  1942. spawn->SetTotalHP(value);
  1943. spawn->SetTotalHPBaseInstance(value);
  1944. }
  1945. return 0;
  1946. }
  1947. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1948. if (!lua_interface)
  1949. return 0;
  1950. Spawn* spawn = lua_interface->GetSpawn(state);
  1951. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1952. lua_interface->ResetFunctionStack(state);
  1953. if (spawn) {
  1954. spawn->SetHP(value);
  1955. if (value > spawn->GetTotalHPBase())
  1956. spawn->SetTotalHP(value);
  1957. }
  1958. return 0;
  1959. }
  1960. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1961. if (!lua_interface)
  1962. return 0;
  1963. Spawn* spawn = lua_interface->GetSpawn(state);
  1964. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1965. float value = lua_interface->GetFloatValue(state, 2);
  1966. lua_interface->ResetFunctionStack(state);
  1967. if (spawn && spawn->IsEntity() && value > 0)
  1968. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1969. if (spawn && spawn->IsPlayer())
  1970. ((Player*)spawn)->SetCharSheetChanged(true);
  1971. return 0;
  1972. }
  1973. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1974. if (!lua_interface)
  1975. return 0;
  1976. Spawn* spawn = lua_interface->GetSpawn(state);
  1977. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1978. lua_interface->ResetFunctionStack(state);
  1979. if (spawn && spawn->IsEntity() && value > 0)
  1980. ((Entity*)spawn)->SetTotalHPBase(value);
  1981. return 0;
  1982. }
  1983. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1984. if (!lua_interface)
  1985. return 0;
  1986. Spawn* spawn = lua_interface->GetSpawn(state);
  1987. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1988. lua_interface->ResetFunctionStack(state);
  1989. if (spawn && value > 0) {
  1990. spawn->SetPower(value);
  1991. if (value > spawn->GetTotalPowerBase())
  1992. spawn->SetTotalPower(value);
  1993. }
  1994. return 0;
  1995. }
  1996. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1997. if (!lua_interface)
  1998. return 0;
  1999. Spawn* spawn = lua_interface->GetSpawn(state);
  2000. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2001. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2002. lua_interface->ResetFunctionStack(state);
  2003. if (spawn && spawn->IsEntity() && value > 0)
  2004. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2005. return 0;
  2006. }
  2007. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2008. if (!lua_interface)
  2009. return 0;
  2010. Spawn* spawn = lua_interface->GetSpawn(state);
  2011. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2012. lua_interface->ResetFunctionStack(state);
  2013. if (spawn && spawn->IsEntity() && value > 0)
  2014. ((Entity*)spawn)->SetTotalPowerBase(value);
  2015. return 0;
  2016. }
  2017. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2018. if (!lua_interface)
  2019. return 0;
  2020. Spawn* spawn = lua_interface->GetSpawn(state);
  2021. float x = lua_interface->GetFloatValue(state, 2);
  2022. float y = lua_interface->GetFloatValue(state, 3);
  2023. float z = lua_interface->GetFloatValue(state, 4);
  2024. float heading = lua_interface->GetFloatValue(state, 5);
  2025. lua_interface->ResetFunctionStack(state);
  2026. if (spawn) {
  2027. spawn->SetX(x);
  2028. spawn->SetY(y);
  2029. spawn->SetZ(z);
  2030. if (heading != 0)
  2031. spawn->SetHeading(heading);
  2032. spawn->SetSpawnOrigX(spawn->GetX());
  2033. spawn->SetSpawnOrigY(spawn->GetY());
  2034. spawn->SetSpawnOrigZ(spawn->GetZ());
  2035. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2036. if (spawn->IsPlayer()) {
  2037. Client* client = ((Player*)spawn)->GetClient();
  2038. if (client) {
  2039. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2040. client->QueuePacket(packet);
  2041. }
  2042. }
  2043. }
  2044. return 0;
  2045. }
  2046. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2047. if (!lua_interface)
  2048. return 0;
  2049. Spawn* spawn = lua_interface->GetSpawn(state);
  2050. float value = lua_interface->GetFloatValue(state, 2);
  2051. lua_interface->ResetFunctionStack(state);
  2052. if (spawn) {
  2053. spawn->SetHeading(value);
  2054. if (spawn->IsPlayer()) {
  2055. Client* client = ((Player*)spawn)->GetClient();
  2056. if (client) {
  2057. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2058. client->QueuePacket(packet);
  2059. }
  2060. }
  2061. }
  2062. return 0;
  2063. }
  2064. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2065. if (!lua_interface)
  2066. return 0;
  2067. Spawn* spawn = lua_interface->GetSpawn(state);
  2068. int16 value = lua_interface->GetInt16Value(state, 2);
  2069. lua_interface->ResetFunctionStack(state);
  2070. if (spawn)
  2071. spawn->SetModelType(value);
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. int8 value = lua_interface->GetInt8Value(state, 2);
  2079. lua_interface->ResetFunctionStack(state);
  2080. if (spawn) {
  2081. if (spawn->IsPlayer())
  2082. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2083. else
  2084. spawn->SetAdventureClass(value);
  2085. }
  2086. return 0;
  2087. }
  2088. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2089. if (!lua_interface)
  2090. return 0;
  2091. Spawn* spawn = lua_interface->GetSpawn(state);
  2092. int8 value = lua_interface->GetInt8Value(state, 2);
  2093. lua_interface->ResetFunctionStack(state);
  2094. if (spawn) {
  2095. spawn->SetTradeskillClass(value);
  2096. if (spawn->IsEntity()) {
  2097. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2098. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2099. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2100. }
  2101. if (spawn->IsPlayer())
  2102. ((Player*)spawn)->SetCharSheetChanged(true);
  2103. }
  2104. return 0;
  2105. }
  2106. int EQ2Emu_lua_SetMount(lua_State* state) {
  2107. if (!lua_interface)
  2108. return 0;
  2109. Spawn* spawn = lua_interface->GetSpawn(state);
  2110. int16 value = lua_interface->GetInt16Value(state, 2);
  2111. if (spawn && spawn->IsEntity()) {
  2112. ((Entity*)spawn)->SetMount(value);
  2113. EQ2_Color color;
  2114. color.red = 255;
  2115. color.green = 255;
  2116. color.blue = 255;
  2117. ((Entity*)spawn)->SetMountColor(&color);
  2118. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2119. }
  2120. return 0;
  2121. }
  2122. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2123. if (!lua_interface)
  2124. return 0;
  2125. Spawn* spawn = lua_interface->GetSpawn(state);
  2126. EQ2_Color mount_color;
  2127. EQ2_Color saddle_color;
  2128. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2129. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2130. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2131. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2132. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2133. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2134. if (spawn && spawn->IsEntity()) {
  2135. ((Entity*)spawn)->SetMountColor(&mount_color);
  2136. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2137. }
  2138. return 0;
  2139. }
  2140. int EQ2Emu_lua_GetMount(lua_State* state) {
  2141. if (!lua_interface)
  2142. return 0;
  2143. Spawn* spawn = lua_interface->GetSpawn(state);
  2144. if (spawn && spawn->IsEntity()) {
  2145. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2146. return 1;
  2147. }
  2148. return 0;
  2149. }
  2150. int EQ2Emu_lua_GetRace(lua_State* state) {
  2151. if (!lua_interface)
  2152. return 0;
  2153. Spawn* spawn = lua_interface->GetSpawn(state);
  2154. if (spawn)
  2155. {
  2156. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2157. lua_interface->SetInt32Value(state, spawn->GetRace());
  2158. return 1;
  2159. }
  2160. return 0;
  2161. }
  2162. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2163. if (!lua_interface)
  2164. return 0;
  2165. Spawn* spawn = lua_interface->GetSpawn(state);
  2166. if (spawn) {
  2167. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2168. return 1;
  2169. }
  2170. return 0;
  2171. }
  2172. int EQ2Emu_lua_GetClass(lua_State* state) {
  2173. Spawn* spawn = lua_interface->GetSpawn(state);
  2174. if (spawn) {
  2175. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2176. return 1;
  2177. }
  2178. return 0;
  2179. }
  2180. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2181. Spawn* spawn = lua_interface->GetSpawn(state);
  2182. if (spawn) {
  2183. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2184. return 1;
  2185. }
  2186. return 0;
  2187. }
  2188. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2189. if (!lua_interface)
  2190. return 0;
  2191. Spawn* spawn = lua_interface->GetSpawn(state);
  2192. float value = lua_interface->GetFloatValue(state, 2);
  2193. lua_interface->ResetFunctionStack(state);
  2194. if (spawn) {
  2195. spawn->SetSpeed(value);
  2196. if(spawn->IsEntity())
  2197. ((Entity*)spawn)->SetSpeed(value);
  2198. if (spawn->IsPlayer()) {
  2199. Client* client = ((Player*)spawn)->GetClient();
  2200. if (client) {
  2201. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2202. if (packet) {
  2203. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2204. packet->setDataByName("speed", value);
  2205. packet->setDataByName("size", 0.51);
  2206. EQ2Packet* app = packet->serialize();
  2207. client->QueuePacket(app);
  2208. safe_delete(packet);
  2209. }
  2210. }
  2211. }
  2212. }
  2213. return 0;
  2214. }
  2215. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2216. if (!lua_interface)
  2217. return 0;
  2218. Spawn* spawn = lua_interface->GetSpawn(state);
  2219. const int16 type = lua_interface->GetInt16Value(state, 2);
  2220. const float value = lua_interface->GetFloatValue(state, 3);
  2221. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2222. if(!luaspell || luaspell->resisted) {
  2223. lua_interface->ResetFunctionStack(state);
  2224. return 0;
  2225. }
  2226. int64 class_req = 0;
  2227. int32 class_id = 0;
  2228. vector<int16> faction_req;
  2229. vector<int16> race_req;
  2230. int32 i = 0;
  2231. int8 f = 0;
  2232. int8 r = 0;
  2233. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2234. if (class_id < 100) {
  2235. class_req += pow(2.0, double(class_id - 1));
  2236. }
  2237. else if (class_id > 100 && class_id < 1000) {
  2238. race_req.push_back(class_id);
  2239. r++;
  2240. }
  2241. else {
  2242. faction_req.push_back(class_id);
  2243. f++;
  2244. }
  2245. i++;
  2246. }
  2247. if (value != 0 && type >= 0) {
  2248. if (luaspell && luaspell->spell && luaspell->caster) {
  2249. ZoneServer* zone = luaspell->caster->GetZone();
  2250. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2251. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2252. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2253. if (target) {
  2254. if (target->IsPlayer()) {
  2255. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2256. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2257. if (((Player*)target)->GetGroupMemberInfo())
  2258. ((Player*)target)->UpdateGroupMemberInfo();
  2259. ((Player*)target)->SetCharSheetChanged(true);
  2260. }
  2261. else if (target->IsNPC())
  2262. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2263. else
  2264. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2265. }
  2266. }
  2267. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2268. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2269. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2270. }
  2271. else if (spawn && spawn->IsEntity()) {
  2272. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2273. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2274. if (spawn->IsPlayer())
  2275. ((Player*)spawn)->SetCharSheetChanged(true);
  2276. }
  2277. else
  2278. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2279. }
  2280. else
  2281. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2282. return 0;
  2283. }
  2284. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2285. if (!lua_interface)
  2286. return 0;
  2287. Spawn* spawn = lua_interface->GetSpawn(state);
  2288. int16 type = lua_interface->GetInt16Value(state, 2);
  2289. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2291. if (!spawn) {
  2292. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2293. return 0;
  2294. }
  2295. if (!spawn->IsEntity()) {
  2296. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2297. return 0;
  2298. }
  2299. if (value == 0) {
  2300. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2301. return 0;
  2302. }
  2303. if (!luaspell || !luaspell->spell) {
  2304. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2305. return 0;
  2306. }
  2307. if(luaspell->resisted) {
  2308. lua_interface->ResetFunctionStack(state);
  2309. return 0;
  2310. }
  2311. int32 class_req = 0;
  2312. vector<int16> faction_req;
  2313. vector<int16> race_req;
  2314. int32 class_id = 0;
  2315. int32 i = 0;
  2316. int8 f = 0;
  2317. int8 r = 0;
  2318. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2319. if (class_id < 100) {
  2320. class_req += pow(2.0, double(class_id - 1));
  2321. }
  2322. else if (class_id > 100 && class_id < 1000) {
  2323. race_req.push_back(class_id);
  2324. r++;
  2325. }
  2326. else {
  2327. faction_req.push_back(class_id);
  2328. f++;
  2329. }
  2330. i++;
  2331. }
  2332. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2333. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2334. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2335. if (spawn->IsPlayer())
  2336. ((Player*)spawn)->SetCharSheetChanged(true);
  2337. return 0;
  2338. }
  2339. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2340. if (!lua_interface)
  2341. return 0;
  2342. Spawn* spawn = lua_interface->GetSpawn(state);
  2343. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2344. if (!spawn) {
  2345. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2346. return 0;
  2347. }
  2348. if (!spawn->IsEntity()) {
  2349. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2350. return 0;
  2351. }
  2352. if (!luaspell || !luaspell->spell) {
  2353. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2354. return 0;
  2355. }
  2356. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2357. if (spawn->IsPlayer())
  2358. ((Player*)spawn)->SetCharSheetChanged(true);
  2359. return 0;
  2360. }
  2361. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2362. if (!lua_interface)
  2363. return 0;
  2364. Spawn* spawn = lua_interface->GetSpawn(state);
  2365. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2366. if (luaspell && luaspell->spell) {
  2367. ZoneServer* zone = nullptr;
  2368. if (luaspell->caster != nullptr)
  2369. zone = luaspell->caster->GetZone();
  2370. if(!zone && spawn) {
  2371. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2372. }
  2373. Spawn* target = 0;
  2374. if(zone) {
  2375. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2376. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2377. target = zone->GetSpawnByID(luaspell->targets[i]);
  2378. if (target && target->IsEntity()) {
  2379. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2380. if (target->IsPlayer())
  2381. ((Player*)target)->SetCharSheetChanged(true);
  2382. }
  2383. }
  2384. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2385. }
  2386. else {
  2387. LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn->GetName());
  2388. }
  2389. }
  2390. else if (spawn && spawn->IsEntity()) {
  2391. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2392. if (spawn->IsPlayer())
  2393. ((Player*)spawn)->SetCharSheetChanged(true);
  2394. }
  2395. return 0;
  2396. }
  2397. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2398. if (!lua_interface)
  2399. return 0;
  2400. Spawn* spawn = lua_interface->GetSpawn(state);
  2401. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2402. float value = lua_interface->GetFloatValue(state, 3);
  2403. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2404. if (value != 0) {
  2405. int32 spell_id = 0;
  2406. if (luaspell && luaspell->spell && luaspell->caster) {
  2407. if(luaspell->resisted) {
  2408. lua_interface->ResetFunctionStack(state);
  2409. return 0;
  2410. }
  2411. spell_id = luaspell->spell->GetSpellID();
  2412. ZoneServer* zone = luaspell->caster->GetZone();
  2413. Spawn* target = 0;
  2414. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2415. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2416. target = zone->GetSpawnByID(luaspell->targets[i]);
  2417. if (target && target->Alive()) {
  2418. if (target->IsPlayer()) {
  2419. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2420. Client* client = ((Player*)target)->GetClient();
  2421. if (client) {
  2422. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2423. if (packet)
  2424. client->QueuePacket(packet);
  2425. }
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2428. }
  2429. else if (target->IsNPC()) {
  2430. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2431. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2432. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2433. }
  2434. else
  2435. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2436. }
  2437. }
  2438. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2439. }
  2440. else if (spawn) {
  2441. if (spawn->IsPlayer()) {
  2442. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2443. Client* client = ((Player*)spawn)->GetClient();
  2444. if (client) {
  2445. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2446. if (packet)
  2447. client->QueuePacket(packet);
  2448. }
  2449. }
  2450. else if (spawn->IsNPC())
  2451. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2452. else
  2453. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2454. }
  2455. }
  2456. else
  2457. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2458. return 0;
  2459. }
  2460. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2461. if (!lua_interface)
  2462. return 0;
  2463. Spawn* spawn = lua_interface->GetSpawn(state);
  2464. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2465. if (spawn && spawn->IsPlayer()) {
  2466. int32 spell_id = 0;
  2467. if (luaspell && luaspell->spell && luaspell->caster) {
  2468. if(luaspell->resisted) {
  2469. lua_interface->ResetFunctionStack(state);
  2470. return 0;
  2471. }
  2472. spell_id = luaspell->spell->GetSpellID();
  2473. ZoneServer* zone = luaspell->caster->GetZone();
  2474. Spawn* target = 0;
  2475. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2476. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2477. target = zone->GetSpawnByID(luaspell->targets[i]);
  2478. if (target) {
  2479. if (target->IsPlayer()) {
  2480. ((Player*)target)->RemoveSkillBonus(spell_id);
  2481. Client* client = ((Player*)target)->GetClient();
  2482. if (client) {
  2483. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2484. if (packet)
  2485. client->QueuePacket(packet);
  2486. }
  2487. }
  2488. else if (target->IsNPC())
  2489. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2490. else
  2491. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2492. }
  2493. }
  2494. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2495. }
  2496. else if (spawn) {
  2497. if (spawn->IsPlayer()) {
  2498. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2499. Client* client = ((Player*)spawn)->GetClient();
  2500. if (client) {
  2501. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2502. if (packet)
  2503. client->QueuePacket(packet);
  2504. }
  2505. }
  2506. else if (spawn->IsNPC())
  2507. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2508. else
  2509. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2510. }
  2511. }
  2512. return 0;
  2513. }
  2514. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2515. if (!lua_interface)
  2516. return 0;
  2517. Spawn* spawn = lua_interface->GetSpawn(state);
  2518. int8 type = lua_interface->GetInt32Value(state, 2);
  2519. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2520. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2521. if(luaspell && luaspell->resisted) {
  2522. lua_interface->ResetFunctionStack(state);
  2523. return 0;
  2524. }
  2525. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2526. ZoneServer* zone = luaspell->caster->GetZone();
  2527. Spawn* target = 0;
  2528. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2529. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2530. target = zone->GetSpawnByID(luaspell->targets[i]);
  2531. if (target && target->IsEntity()) {
  2532. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2533. ((Entity*)target)->AddMezSpell(luaspell);
  2534. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2535. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2536. if (target->IsNPC())
  2537. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2538. }
  2539. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2540. ((Entity*)target)->AddStifleSpell(luaspell);
  2541. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2542. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2543. if (target->IsNPC())
  2544. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2545. }
  2546. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2547. ((Entity*)target)->AddDazeSpell(luaspell);
  2548. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2549. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2550. if (target->IsNPC())
  2551. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2552. }
  2553. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2554. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2555. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2556. ((Entity*)target)->AddStunSpell(luaspell);
  2557. if (target->IsNPC())
  2558. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2559. }
  2560. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2561. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2562. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2563. ((Entity*)target)->AddRootSpell(luaspell);
  2564. if (target->IsNPC())
  2565. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2566. }
  2567. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2568. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2569. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2570. ((Entity*)target)->AddFearSpell(luaspell);
  2571. if (target->IsNPC())
  2572. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2573. }
  2574. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2575. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2576. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2577. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2578. }
  2579. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2580. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2581. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2582. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2583. }
  2584. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2585. ((Entity*)target)->AddSnareSpell(luaspell);
  2586. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2587. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2588. if (target->IsNPC())
  2589. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2590. }
  2591. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2592. ((Entity*)target)->AddFlightSpell(luaspell);
  2593. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2594. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2595. }
  2596. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2597. ((Entity*)target)->AddGlideSpell(luaspell);
  2598. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2599. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2600. }
  2601. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2602. ((Entity*)target)->AddSafefallSpell(luaspell);
  2603. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2604. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2605. }
  2606. else
  2607. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2608. }
  2609. else
  2610. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2611. }
  2612. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2613. }
  2614. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2615. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2616. ((Entity*)spawn)->AddMezSpell(luaspell);
  2617. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2618. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2619. }
  2620. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2621. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2622. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2623. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2624. }
  2625. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2626. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2627. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2628. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2629. }
  2630. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2631. ((Entity*)spawn)->AddStunSpell(luaspell);
  2632. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2633. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2634. }
  2635. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2636. ((Entity*)spawn)->AddRootSpell(luaspell);
  2637. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2638. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2639. }
  2640. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2641. ((Entity*)spawn)->AddFearSpell(luaspell);
  2642. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2643. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2644. }
  2645. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2646. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2647. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2648. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2649. }
  2650. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2651. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2652. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2653. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2654. }
  2655. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2656. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2657. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2658. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2659. }
  2660. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2661. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2662. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2663. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2664. }
  2665. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2666. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2667. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2668. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2669. }
  2670. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2671. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2672. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2673. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2674. }
  2675. else
  2676. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2677. }
  2678. else
  2679. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2680. return 0;
  2681. }
  2682. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2683. if (!lua_interface)
  2684. return 0;
  2685. Spawn* spawn = lua_interface->GetSpawn(state);
  2686. int8 type = lua_interface->GetInt8Value(state, 2);
  2687. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2688. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2689. if (spawn && spawn->IsEntity()) {
  2690. if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
  2691. ZoneServer* zone = luaspell->caster->GetZone();
  2692. Spawn* target = 0;
  2693. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2694. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2695. target = zone->GetSpawnByID(luaspell->targets[i]);
  2696. if (target) {
  2697. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2698. ((Entity*)target)->RemoveMezSpell(luaspell);
  2699. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2700. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2701. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2702. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2703. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2704. ((Entity*)target)->RemoveStunSpell(luaspell);
  2705. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2706. ((Entity*)target)->RemoveRootSpell(luaspell);
  2707. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2708. ((Entity*)target)->RemoveFearSpell(luaspell);
  2709. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2710. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2711. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2712. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2713. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2714. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2715. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2716. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2717. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2718. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2719. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2720. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2721. else
  2722. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2723. }
  2724. }
  2725. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2726. }
  2727. else if (only_remove_spawn) {
  2728. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2729. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2730. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2731. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2732. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2733. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2734. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2735. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2736. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2737. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2738. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2739. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2740. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2741. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2742. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2743. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2744. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2745. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2746. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2747. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2748. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2749. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2750. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2751. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2752. else
  2753. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2754. }
  2755. }
  2756. return 0;
  2757. }
  2758. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2759. if (!lua_interface)
  2760. return 0;
  2761. Spawn* spawn = lua_interface->GetSpawn(state);
  2762. int8 type = lua_interface->GetInt8Value(state, 2);
  2763. bool hasEffect = false;
  2764. if (!spawn)
  2765. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2766. else if (!spawn->IsEntity())
  2767. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2768. else if (type < CONTROL_MAX_EFFECTS)
  2769. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2770. else
  2771. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2772. lua_interface->SetBooleanValue(state, hasEffect);
  2773. return 1;
  2774. }
  2775. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. float distance = 0.0f;
  2780. if (!spawn)
  2781. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2782. else if (!spawn->IsNPC())
  2783. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2784. else
  2785. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2786. lua_interface->SetFloatValue(state, distance);
  2787. return 1;
  2788. }
  2789. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2790. if (!lua_interface)
  2791. return 0;
  2792. Spawn* spawn = lua_interface->GetSpawn(state);
  2793. float distance = 0.0f;
  2794. if (!spawn)
  2795. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2796. else if (!spawn->IsNPC())
  2797. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2798. else
  2799. distance = ((NPC*)spawn)->GetAggroRadius();
  2800. lua_interface->SetFloatValue(state, distance);
  2801. return 1;
  2802. }
  2803. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2804. if (!lua_interface)
  2805. return 0;
  2806. Spawn* spawn = lua_interface->GetSpawn(state);
  2807. float distance = lua_interface->GetFloatValue(state, 2);
  2808. bool override = lua_interface->GetBooleanValue(state, 3);
  2809. bool result = false;
  2810. lua_interface->ResetFunctionStack(state);
  2811. if (!spawn)
  2812. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2813. else if (!spawn->IsNPC())
  2814. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2815. else
  2816. {
  2817. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2818. result = true;
  2819. }
  2820. lua_interface->SetBooleanValue(state, result);
  2821. return 1;
  2822. }
  2823. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2824. if (!lua_interface)
  2825. return 0;
  2826. Spawn* spawn = lua_interface->GetSpawn(state);
  2827. int16 value = lua_interface->GetInt16Value(state, 2);
  2828. if (spawn && spawn->IsEntity()) {
  2829. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2830. if (spawn->IsPlayer())
  2831. ((Player*)spawn)->SetCharSheetChanged(true);
  2832. }
  2833. return 0;
  2834. }
  2835. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2836. if (!lua_interface)
  2837. return 0;
  2838. Spawn* spawn = lua_interface->GetSpawn(state);
  2839. int16 value = lua_interface->GetInt16Value(state, 2);
  2840. if (spawn && spawn->IsEntity()) {
  2841. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2842. if (spawn->IsPlayer())
  2843. ((Player*)spawn)->SetCharSheetChanged(true);
  2844. }
  2845. return 0;
  2846. }
  2847. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2848. if (!lua_interface)
  2849. return 0;
  2850. Spawn* spawn = lua_interface->GetSpawn(state);
  2851. int16 value = lua_interface->GetInt16Value(state, 2);
  2852. if (spawn && spawn->IsEntity()) {
  2853. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2854. if (spawn->IsPlayer())
  2855. ((Player*)spawn)->SetCharSheetChanged(true);
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. int16 value = lua_interface->GetInt16Value(state, 2);
  2864. if (spawn && spawn->IsEntity()) {
  2865. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2866. if (spawn->IsPlayer())
  2867. ((Player*)spawn)->SetCharSheetChanged(true);
  2868. }
  2869. return 0;
  2870. }
  2871. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2872. if (!lua_interface)
  2873. return 0;
  2874. Spawn* spawn = lua_interface->GetSpawn(state);
  2875. int16 value = lua_interface->GetInt16Value(state, 2);
  2876. if (spawn && spawn->IsEntity()) {
  2877. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2878. if (spawn->IsPlayer())
  2879. ((Player*)spawn)->SetCharSheetChanged(true);
  2880. }
  2881. return 0;
  2882. }
  2883. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2884. if (!lua_interface)
  2885. return 0;
  2886. Spawn* spawn = lua_interface->GetSpawn(state);
  2887. int8 value = lua_interface->GetInt8Value(state, 2);
  2888. if (spawn && spawn->IsEntity()) {
  2889. ((Entity*)spawn)->SetDeity(value);
  2890. if (spawn->IsPlayer())
  2891. ((Player*)spawn)->SetCharSheetChanged(true);
  2892. }
  2893. lua_interface->ResetFunctionStack(state);
  2894. return 0;
  2895. }
  2896. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2897. if (!lua_interface)
  2898. return 0;
  2899. Spawn* spawn = lua_interface->GetSpawn(state);
  2900. if (spawn && spawn->IsEntity()) {
  2901. int8 deity = ((Entity*)spawn)->GetDeity();
  2902. lua_interface->SetInt32Value(state, deity);
  2903. return 1;
  2904. }
  2905. return 0;
  2906. }
  2907. int EQ2Emu_lua_SetInt(lua_State* state) {
  2908. if (!lua_interface)
  2909. return 0;
  2910. Spawn* spawn = lua_interface->GetSpawn(state);
  2911. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2912. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2913. if (spawn && spawn->IsEntity()) {
  2914. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2915. if (spawn->IsPlayer())
  2916. ((Player*)spawn)->SetCharSheetChanged(true);
  2917. }
  2918. return 0;
  2919. }
  2920. int EQ2Emu_lua_SetWis(lua_State* state) {
  2921. if (!lua_interface)
  2922. return 0;
  2923. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2924. Spawn* spawn = lua_interface->GetSpawn(state);
  2925. float value = lua_interface->GetFloatValue(state, 2);
  2926. if (spawn && spawn->IsEntity()) {
  2927. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2928. if (spawn->IsPlayer())
  2929. ((Player*)spawn)->SetCharSheetChanged(true);
  2930. }
  2931. return 0;
  2932. }
  2933. int EQ2Emu_lua_SetSta(lua_State* state) {
  2934. if (!lua_interface)
  2935. return 0;
  2936. Spawn* spawn = lua_interface->GetSpawn(state);
  2937. float value = lua_interface->GetFloatValue(state, 2);
  2938. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2939. if (spawn && spawn->IsEntity()) {
  2940. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2941. if (spawn->IsPlayer())
  2942. ((Player*)spawn)->SetCharSheetChanged(true);
  2943. }
  2944. return 0;
  2945. }
  2946. int EQ2Emu_lua_SetStr(lua_State* state) {
  2947. if (!lua_interface)
  2948. return 0;
  2949. Spawn* spawn = lua_interface->GetSpawn(state);
  2950. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2951. float value = lua_interface->GetFloatValue(state, 2);
  2952. if (spawn && spawn->IsEntity()) {
  2953. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2954. if (spawn->IsPlayer())
  2955. ((Player*)spawn)->SetCharSheetChanged(true);
  2956. }
  2957. return 0;
  2958. }
  2959. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2960. if (!lua_interface)
  2961. return 0;
  2962. Spawn* spawn = lua_interface->GetSpawn(state);
  2963. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2964. float value = lua_interface->GetFloatValue(state, 2);
  2965. if (spawn && spawn->IsEntity()) {
  2966. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2967. if (spawn->IsPlayer())
  2968. ((Player*)spawn)->SetCharSheetChanged(true);
  2969. }
  2970. return 0;
  2971. }
  2972. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2973. if (!lua_interface)
  2974. return 0;
  2975. Spawn* spawn = lua_interface->GetSpawn(state);
  2976. if (spawn) {
  2977. lua_interface->SetInt32Value(state, spawn->GetHP());
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2983. if (!lua_interface)
  2984. return 0;
  2985. Spawn* spawn = lua_interface->GetSpawn(state);
  2986. if (spawn) {
  2987. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2988. return 1;
  2989. }
  2990. return 0;
  2991. }
  2992. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2993. if (!lua_interface)
  2994. return 0;
  2995. Spawn* spawn = lua_interface->GetSpawn(state);
  2996. if (spawn) {
  2997. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2998. return 1;
  2999. }
  3000. return 0;
  3001. }
  3002. int EQ2Emu_lua_GetName(lua_State* state) {
  3003. if (!lua_interface)
  3004. return 0;
  3005. Spawn* spawn = lua_interface->GetSpawn(state);
  3006. if (spawn) {
  3007. lua_interface->SetStringValue(state, spawn->GetName());
  3008. return 1;
  3009. }
  3010. return 0;
  3011. }
  3012. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3013. Spawn* spawn = lua_interface->GetSpawn(state);
  3014. if (spawn) {
  3015. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3016. return 1;
  3017. }
  3018. return 0;
  3019. }
  3020. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3021. Spawn* spawn = lua_interface->GetSpawn(state);
  3022. if (spawn) {
  3023. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3024. return 1;
  3025. }
  3026. return 0;
  3027. }
  3028. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3029. if (!lua_interface)
  3030. return 0;
  3031. Spawn* spawn = lua_interface->GetSpawn(state);
  3032. if (spawn) {
  3033. lua_interface->SetInt32Value(state, spawn->GetPower());
  3034. return 1;
  3035. }
  3036. return 0;
  3037. }
  3038. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3039. if (!lua_interface)
  3040. return 0;
  3041. Spawn* spawn = lua_interface->GetSpawn(state);
  3042. if (spawn) {
  3043. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3044. return 1;
  3045. }
  3046. return 0;
  3047. }
  3048. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3049. if (!lua_interface)
  3050. return 0;
  3051. Spawn* spawn = lua_interface->GetSpawn(state);
  3052. if (spawn) {
  3053. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3054. return 1;
  3055. }
  3056. return 0;
  3057. }
  3058. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3059. if (!lua_interface)
  3060. return 0;
  3061. Spawn* spawn = lua_interface->GetSpawn(state);
  3062. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3063. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3064. if (spawn && spawn2) {
  3065. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3066. lua_interface->SetFloatValue(state, distance);
  3067. return 1;
  3068. }
  3069. return 0;
  3070. }
  3071. int EQ2Emu_lua_GetX(lua_State* state) {
  3072. if (!lua_interface)
  3073. return 0;
  3074. Spawn* spawn = lua_interface->GetSpawn(state);
  3075. if (spawn) {
  3076. lua_interface->SetFloatValue(state, spawn->GetX());
  3077. return 1;
  3078. }
  3079. return 0;
  3080. }
  3081. int EQ2Emu_lua_GetY(lua_State* state) {
  3082. if (!lua_interface)
  3083. return 0;
  3084. Spawn* spawn = lua_interface->GetSpawn(state);
  3085. if (spawn) {
  3086. lua_interface->SetFloatValue(state, spawn->GetY());
  3087. return 1;
  3088. }
  3089. return 0;
  3090. }
  3091. int EQ2Emu_lua_GetZ(lua_State* state) {
  3092. if (!lua_interface)
  3093. return 0;
  3094. Spawn* spawn = lua_interface->GetSpawn(state);
  3095. if (spawn) {
  3096. lua_interface->SetFloatValue(state, spawn->GetZ());
  3097. return 1;
  3098. }
  3099. return 0;
  3100. }
  3101. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3102. if (!lua_interface)
  3103. return 0;
  3104. Spawn* spawn = lua_interface->GetSpawn(state);
  3105. if (spawn) {
  3106. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3107. return 1;
  3108. }
  3109. return 0;
  3110. }
  3111. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3112. if (!lua_interface)
  3113. return 0;
  3114. Spawn* spawn = lua_interface->GetSpawn(state);
  3115. if (spawn) {
  3116. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3117. return 1;
  3118. }
  3119. return 0;
  3120. }
  3121. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3122. if (!lua_interface)
  3123. return 0;
  3124. Spawn* spawn = lua_interface->GetSpawn(state);
  3125. if (spawn) {
  3126. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3127. return 1;
  3128. }
  3129. return 0;
  3130. }
  3131. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3132. if (!lua_interface)
  3133. return 0;
  3134. Spawn* spawn = lua_interface->GetSpawn(state);
  3135. if (spawn && spawn->IsEntity()) {
  3136. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3137. return 1;
  3138. }
  3139. return 0;
  3140. }
  3141. int EQ2Emu_lua_GetInt(lua_State* state) {
  3142. if (!lua_interface)
  3143. return 0;
  3144. Spawn* spawn = lua_interface->GetSpawn(state);
  3145. if (spawn && spawn->IsEntity()) {
  3146. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3147. return 1;
  3148. }
  3149. return 0;
  3150. }
  3151. int EQ2Emu_lua_GetWis(lua_State* state) {
  3152. if (!lua_interface)
  3153. return 0;
  3154. Spawn* spawn = lua_interface->GetSpawn(state);
  3155. if (spawn && spawn->IsEntity()) {
  3156. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3157. return 1;
  3158. }
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_GetSta(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Spawn* spawn = lua_interface->GetSpawn(state);
  3165. if (spawn && spawn->IsEntity()) {
  3166. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3167. return 1;
  3168. }
  3169. return 0;
  3170. }
  3171. int EQ2Emu_lua_GetStr(lua_State* state) {
  3172. if (!lua_interface)
  3173. return 0;
  3174. Spawn* spawn = lua_interface->GetSpawn(state);
  3175. if (spawn && spawn->IsEntity()) {
  3176. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3177. return 1;
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Spawn* spawn = lua_interface->GetSpawn(state);
  3185. if (spawn && spawn->IsEntity()) {
  3186. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3187. return 1;
  3188. }
  3189. return 0;
  3190. }
  3191. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3192. if (!lua_interface)
  3193. return 0;
  3194. Spawn* spawn = lua_interface->GetSpawn(state);
  3195. if (spawn && spawn->IsEntity()) {
  3196. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3197. return 1;
  3198. }
  3199. return 0;
  3200. }
  3201. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3202. if (!lua_interface)
  3203. return 0;
  3204. Spawn* spawn = lua_interface->GetSpawn(state);
  3205. if (spawn && spawn->IsEntity()) {
  3206. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3207. return 1;
  3208. }
  3209. return 0;
  3210. }
  3211. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3212. if (!lua_interface)
  3213. return 0;
  3214. Spawn* spawn = lua_interface->GetSpawn(state);
  3215. if (spawn && spawn->IsEntity()) {
  3216. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3217. return 1;
  3218. }
  3219. return 0;
  3220. }
  3221. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3222. if (!lua_interface)
  3223. return 0;
  3224. Spawn* spawn = lua_interface->GetSpawn(state);
  3225. if (spawn && spawn->IsEntity()) {
  3226. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3227. return 1;
  3228. }
  3229. return 0;
  3230. }
  3231. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3232. if (!lua_interface)
  3233. return 0;
  3234. Spawn* spawn = lua_interface->GetSpawn(state);
  3235. if (spawn && spawn->IsEntity()) {
  3236. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3237. return 1;
  3238. }
  3239. return 0;
  3240. }
  3241. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3242. if (!lua_interface)
  3243. return 0;
  3244. Spawn* player = lua_interface->GetSpawn(state);
  3245. if (!player || !player->IsPlayer()) {
  3246. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3247. return 0;
  3248. }
  3249. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3250. if (quest_id <= 0) {
  3251. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3252. return 0;
  3253. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3254. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3255. return 0;
  3256. }
  3257. int32 step = lua_interface->GetInt32Value(state, 3);
  3258. if (step > 0) {
  3259. Client* client = ((Player*)player)->GetClient();
  3260. if (client)
  3261. client->AddPendingQuestUpdate(quest_id, step);
  3262. } else {
  3263. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3264. }
  3265. return 0;
  3266. }
  3267. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3268. Spawn* player = lua_interface->GetSpawn(state);
  3269. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3270. int32 step = lua_interface->GetInt32Value(state, 3);
  3271. int32 progress = lua_interface->GetInt32Value(state, 4);
  3272. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3273. Client* client = ((Player*)player)->GetClient();
  3274. if (client)
  3275. client->AddPendingQuestUpdate(quest_id, step, progress);
  3276. }
  3277. return 0;
  3278. }
  3279. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3280. if (!lua_interface)
  3281. return 0;
  3282. Spawn* player = lua_interface->GetSpawn(state);
  3283. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3284. if (player && player->IsPlayer() && quest_id > 0) {
  3285. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3286. return 1;
  3287. }
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Spawn* player = lua_interface->GetSpawn(state);
  3294. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3295. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3296. if (player && player->IsPlayer() && quest_id > 0) {
  3297. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3298. return 1;
  3299. }
  3300. return 0;
  3301. }
  3302. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3303. if (!lua_interface)
  3304. return 0;
  3305. Spawn* player = lua_interface->GetSpawn(state);
  3306. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3307. if (player && player->IsPlayer() && quest_id > 0) {
  3308. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3309. return 1;
  3310. }
  3311. return 0;
  3312. }
  3313. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3314. if (!lua_interface)
  3315. return 0;
  3316. Quest* quest = lua_interface->GetQuest(state);
  3317. string name = lua_interface->GetStringValue(state, 2);
  3318. string type = lua_interface->GetStringValue(state, 3);
  3319. string zone = lua_interface->GetStringValue(state, 4);
  3320. int16 level = lua_interface->GetInt16Value(state, 5);
  3321. string description = lua_interface->GetStringValue(state, 6);
  3322. bool load = true;
  3323. if (!quest) {
  3324. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3325. load = false;
  3326. }
  3327. if (load && name.length() == 0) {
  3328. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3329. load = false;
  3330. }
  3331. if (load && type.length() == 0) {
  3332. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3333. load = false;
  3334. }
  3335. if (load && zone.length() == 0) {
  3336. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3337. load = false;
  3338. }
  3339. if (load && description.length() == 0) {
  3340. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3341. load = false;
  3342. }
  3343. if (load && level == 0) {
  3344. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3345. load = false;
  3346. }
  3347. if (load)
  3348. quest->RegisterQuest(name, type, zone, level, description);
  3349. return 0;
  3350. }
  3351. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3352. if (!lua_interface)
  3353. return 0;
  3354. Quest* quest = lua_interface->GetQuest(state);
  3355. if (quest) {
  3356. int8 level = lua_interface->GetInt16Value(state, 2);
  3357. quest->SetPrereqLevel(level);
  3358. }
  3359. return 0;
  3360. }
  3361. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3362. if (!lua_interface)
  3363. return 0;
  3364. Quest* quest = lua_interface->GetQuest(state);
  3365. if (quest) {
  3366. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3367. quest->AddPrereqQuest(quest_id);
  3368. }
  3369. return 0;
  3370. }
  3371. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3372. if (!lua_interface)
  3373. return 0;
  3374. Quest* quest = lua_interface->GetQuest(state);
  3375. if (quest) {
  3376. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3377. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3378. if (quantity == 0)
  3379. quantity = 1;
  3380. Item* master_item = master_item_list.GetItem(item_id);
  3381. if (master_item) {
  3382. Item* item = new Item(master_item);
  3383. item->details.count = quantity;
  3384. quest->AddPrereqItem(item);
  3385. }
  3386. }
  3387. return 0;
  3388. }
  3389. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3390. if (!lua_interface)
  3391. return 0;
  3392. Spawn* player = lua_interface->GetSpawn(state);
  3393. if(!player || !player->IsPlayer()) {
  3394. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3395. return 0;
  3396. }
  3397. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3398. if (quest_id > 0) {
  3399. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) == TRUE));
  3400. return 1;
  3401. } else {
  3402. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3403. }
  3404. return 0;
  3405. }
  3406. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3407. if (!lua_interface)
  3408. return 0;
  3409. Quest* quest = lua_interface->GetQuest(state);
  3410. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3411. lua_interface->ResetFunctionStack(state);
  3412. if (quest && spawn_id > 0)
  3413. quest->SetQuestReturnNPC(spawn_id);
  3414. return 0;
  3415. }
  3416. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3417. if (!lua_interface)
  3418. return 0;
  3419. Spawn* spawn = lua_interface->GetSpawn(state);
  3420. int32 time = lua_interface->GetInt32Value(state, 2);
  3421. string function = lua_interface->GetStringValue(state, 3);
  3422. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3423. Spawn* player = lua_interface->GetSpawn(state, 5);
  3424. lua_interface->ResetFunctionStack(state);
  3425. if (!spawn) {
  3426. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3427. return 0;
  3428. }
  3429. if (time <= 0) {
  3430. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3431. return 0;
  3432. }
  3433. if (function.length() == 0) {
  3434. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3435. return 0;
  3436. }
  3437. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3438. if ( time < 10)
  3439. time = 10;
  3440. timer->timer = Timer::GetCurrentTime2() + time;
  3441. timer->function = function;
  3442. timer->spawn = spawn->GetID();
  3443. timer->player = player ? player->GetID() : 0;
  3444. if (max_count == 0)
  3445. max_count = 1;
  3446. timer->max_count = max_count;
  3447. timer->current_count = 0;
  3448. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3449. return 0;
  3450. }
  3451. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3452. if (!lua_interface)
  3453. return 0;
  3454. Spawn* spawn = lua_interface->GetSpawn(state);
  3455. string function = lua_interface->GetStringValue(state, 2);
  3456. lua_interface->ResetFunctionStack(state);
  3457. if (!spawn) {
  3458. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3459. return 0;
  3460. }
  3461. if(!spawn->GetZone()) {
  3462. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3463. return 0;
  3464. }
  3465. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3466. return 0;
  3467. }
  3468. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3469. if (!lua_interface)
  3470. return 0;
  3471. Spawn* player = lua_interface->GetSpawn(state);
  3472. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3473. lua_interface->ResetFunctionStack(state);
  3474. if (player && player->IsPlayer() && quest_id > 0) {
  3475. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3476. return 1;
  3477. }
  3478. return 0;
  3479. }
  3480. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3481. if (!lua_interface)
  3482. return 0;
  3483. Spawn* player = lua_interface->GetSpawn(state);
  3484. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3485. lua_interface->ResetFunctionStack(state);
  3486. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3487. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3488. if (quest)
  3489. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3490. return 1;
  3491. }
  3492. return 0;
  3493. }
  3494. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3495. if (!lua_interface)
  3496. return 0;
  3497. Spawn* player = lua_interface->GetSpawn(state);
  3498. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3499. lua_interface->ResetFunctionStack(state);
  3500. if (player && player->IsPlayer() && quest_id > 0) {
  3501. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3502. return 1;
  3503. }
  3504. return 0;
  3505. }
  3506. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3507. if (!lua_interface)
  3508. return 0;
  3509. Spawn* npc = lua_interface->GetSpawn(state);
  3510. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3511. lua_interface->ResetFunctionStack(state);
  3512. if (npc && !npc->IsPlayer() && quest_id > 0)
  3513. npc->AddProvidedQuest(quest_id);
  3514. return 0;
  3515. }
  3516. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3517. if (!lua_interface)
  3518. return 0;
  3519. Spawn* npc = lua_interface->GetSpawn(state);
  3520. Spawn* player = lua_interface->GetSpawn(state, 2);
  3521. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3522. bool forced = lua_interface->GetBooleanValue(state, 4);
  3523. lua_interface->ResetFunctionStack(state);
  3524. /* NPC is allowed to be null */
  3525. if (player && player->IsPlayer() && quest_id > 0) {
  3526. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3527. if (master_quest) {
  3528. Client* client = ((Player*)player)->GetClient();
  3529. if (!client) {
  3530. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3531. }
  3532. Quest* quest = new Quest(master_quest);
  3533. if (!quest) {
  3534. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3535. }
  3536. if (client && quest) {
  3537. if (npc)
  3538. quest->SetQuestGiver(npc->GetDatabaseID());
  3539. else
  3540. quest->SetQuestGiver(0);
  3541. client->AddPendingQuest(quest, forced);
  3542. }
  3543. }
  3544. else {
  3545. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3546. }
  3547. }
  3548. else {
  3549. 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);
  3550. }
  3551. return 0;
  3552. }
  3553. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3554. if (!lua_interface)
  3555. return 0;
  3556. Quest* quest = lua_interface->GetQuest(state);
  3557. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3558. lua_interface->ResetFunctionStack(state);
  3559. if (quest) {
  3560. quest->AddPrereqClass(class_id);
  3561. }
  3562. return 0;
  3563. }
  3564. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3565. if (!lua_interface)
  3566. return 0;
  3567. Quest* quest = lua_interface->GetQuest(state);
  3568. int8 race = lua_interface->GetInt8Value(state, 2);
  3569. lua_interface->ResetFunctionStack(state);
  3570. if (quest) {
  3571. quest->AddPrereqRace(race);
  3572. }
  3573. return 0;
  3574. }
  3575. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3576. if (!lua_interface)
  3577. return 0;
  3578. Quest* quest = lua_interface->GetQuest(state);
  3579. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3580. lua_interface->ResetFunctionStack(state);
  3581. if (quest) {
  3582. quest->AddPrereqModelType(model_type);
  3583. }
  3584. return 0;
  3585. }
  3586. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3587. if (!lua_interface)
  3588. return 0;
  3589. Quest* quest = lua_interface->GetQuest(state);
  3590. int8 level = lua_interface->GetInt8Value(state, 2);
  3591. lua_interface->ResetFunctionStack(state);
  3592. if (!quest) {
  3593. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3594. return 0;
  3595. }
  3596. quest->SetPrereqTSLevel(level);
  3597. return 0;
  3598. }
  3599. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3600. if (!lua_interface)
  3601. return 0;
  3602. Quest* quest = lua_interface->GetQuest(state);
  3603. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3604. lua_interface->ResetFunctionStack(state);
  3605. if (!quest) {
  3606. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3607. return 0;
  3608. }
  3609. quest->AddPrereqTradeskillClass(class_id);
  3610. return 0;
  3611. }
  3612. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3613. if (!lua_interface)
  3614. return 0;
  3615. Quest* quest = lua_interface->GetQuest(state);
  3616. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3617. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3618. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3619. lua_interface->ResetFunctionStack(state);
  3620. if (quest) {
  3621. quest->AddPrereqFaction(faction_id, min, max);
  3622. }
  3623. return 0;
  3624. }
  3625. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3626. if (!lua_interface)
  3627. return 0;
  3628. Quest* quest = lua_interface->GetQuest(state);
  3629. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3630. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3631. lua_interface->ResetFunctionStack(state);
  3632. if (quest) {
  3633. if (quantity == 0)
  3634. quantity = 1;
  3635. Item* master_item = master_item_list.GetItem(item_id);
  3636. if (master_item) {
  3637. Item* item = new Item(master_item);
  3638. item->details.count = quantity;
  3639. quest->AddSelectableRewardItem(item);
  3640. }
  3641. }
  3642. return 0;
  3643. }
  3644. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3645. if (!lua_interface)
  3646. return 0;
  3647. Quest* quest = lua_interface->GetQuest(state);
  3648. if (quest) {
  3649. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3650. vector<Item*>* items = quest->GetRewardItems();
  3651. if (items) {
  3652. vector<Item*>::iterator itr;
  3653. for (itr = items->begin(); itr != items->end(); itr++) {
  3654. if (*itr && (*itr)->details.item_id == item_id) {
  3655. lua_interface->SetBooleanValue(state, true);
  3656. return 1;
  3657. }
  3658. }
  3659. }
  3660. }
  3661. lua_interface->SetBooleanValue(state, false);
  3662. return 1;
  3663. }
  3664. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3665. if (!lua_interface)
  3666. return 0;
  3667. Quest* quest = lua_interface->GetQuest(state);
  3668. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3669. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3670. lua_interface->ResetFunctionStack(state);
  3671. if (quest) {
  3672. if (quantity == 0)
  3673. quantity = 1;
  3674. Item* master_item = master_item_list.GetItem(item_id);
  3675. if (master_item) {
  3676. Item* item = new Item(master_item);
  3677. item->details.count = quantity;
  3678. quest->AddRewardItem(item);
  3679. }
  3680. }
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Quest* quest = lua_interface->GetQuest(state);
  3687. int32 copper = lua_interface->GetInt32Value(state, 2);
  3688. int32 silver = lua_interface->GetInt32Value(state, 3);
  3689. int32 gold = lua_interface->GetInt32Value(state, 4);
  3690. int32 plat = lua_interface->GetInt32Value(state, 5);
  3691. lua_interface->ResetFunctionStack(state);
  3692. if (quest) {
  3693. quest->AddRewardCoins(copper, silver, gold, plat);
  3694. }
  3695. return 0;
  3696. }
  3697. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3698. if (!lua_interface)
  3699. return 0;
  3700. Quest* quest = lua_interface->GetQuest(state);
  3701. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3702. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3703. lua_interface->ResetFunctionStack(state);
  3704. if (quest && faction_id > 0 && amount != 0)
  3705. quest->AddRewardFaction(faction_id, amount);
  3706. return 0;
  3707. }
  3708. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3709. if (!lua_interface)
  3710. return 0;
  3711. Quest* quest = lua_interface->GetQuest(state);
  3712. int32 status = lua_interface->GetInt32Value(state, 2);
  3713. lua_interface->ResetFunctionStack(state);
  3714. if (quest) {
  3715. quest->SetRewardStatus(status);
  3716. }
  3717. return 0;
  3718. }
  3719. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3720. if (!lua_interface)
  3721. return 0;
  3722. Quest* quest = lua_interface->GetQuest(state);
  3723. int32 status = lua_interface->GetInt32Value(state, 2);
  3724. lua_interface->ResetFunctionStack(state);
  3725. if (quest) {
  3726. quest->SetStatusTmpReward(status);
  3727. }
  3728. return 0;
  3729. }
  3730. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3731. if (!lua_interface)
  3732. return 0;
  3733. Quest* quest = lua_interface->GetQuest(state);
  3734. int64 coins = lua_interface->GetInt64Value(state, 2);
  3735. lua_interface->ResetFunctionStack(state);
  3736. if (quest) {
  3737. quest->SetCoinTmpReward(coins);
  3738. }
  3739. return 0;
  3740. }
  3741. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3742. if (!lua_interface)
  3743. return 0;
  3744. Quest* quest = lua_interface->GetQuest(state);
  3745. string comment = lua_interface->GetStringValue(state, 2);
  3746. lua_interface->ResetFunctionStack(state);
  3747. if (quest) {
  3748. quest->SetRewardComment(comment);
  3749. }
  3750. return 0;
  3751. }
  3752. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3753. if (!lua_interface)
  3754. return 0;
  3755. Quest* quest = lua_interface->GetQuest(state);
  3756. int32 exp = lua_interface->GetInt32Value(state, 2);
  3757. lua_interface->ResetFunctionStack(state);
  3758. if (quest) {
  3759. quest->SetRewardXP(exp);
  3760. }
  3761. return 0;
  3762. }
  3763. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3764. Quest* quest = lua_interface->GetQuest(state);
  3765. int32 step = lua_interface->GetInt32Value(state, 2);
  3766. string description = lua_interface->GetStringValue(state, 3);
  3767. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3768. float percentage = lua_interface->GetFloatValue(state, 5);
  3769. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3770. int16 icon = lua_interface->GetInt16Value(state, 7);
  3771. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3772. if (quest) {
  3773. const char* taskgroup = 0;
  3774. if (str_taskgroup.length() > 0)
  3775. taskgroup = str_taskgroup.c_str();
  3776. int32 id = 0;
  3777. vector<int32>* ids = 0;
  3778. int i = 0;
  3779. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3780. if (ids == 0)
  3781. ids = new vector<int32>;
  3782. ids->push_back(id);
  3783. i++;
  3784. }
  3785. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3786. if (quest_step && icon && quantity > 0)
  3787. quest_step->SetIcon(icon);
  3788. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3789. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3790. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3791. }
  3792. }
  3793. lua_interface->ResetFunctionStack(state);
  3794. return 0;
  3795. }
  3796. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3797. {
  3798. if (!lua_interface)
  3799. return 0;
  3800. Quest* quest = lua_interface->GetQuest(state);
  3801. int32 step = lua_interface->GetInt32Value(state, 2);
  3802. string description = lua_interface->GetStringValue(state, 3);
  3803. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3804. float percentage = lua_interface->GetFloatValue(state, 5);
  3805. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3806. int16 icon = lua_interface->GetInt16Value(state, 7);
  3807. if (quest) {
  3808. const char* taskgroup = 0;
  3809. if (str_taskgroup.length() > 0)
  3810. taskgroup = str_taskgroup.c_str();
  3811. int32 id = 0;
  3812. vector<int32>* ids = 0;
  3813. int i = 0;
  3814. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3815. if (ids == 0)
  3816. ids = new vector<int32>;
  3817. ids->push_back(id);
  3818. i++;
  3819. }
  3820. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3821. if (quest_step && icon > 0 && quantity > 0)
  3822. quest_step->SetIcon(icon);
  3823. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3824. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3825. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3826. }
  3827. safe_delete(ids);
  3828. }
  3829. lua_interface->ResetFunctionStack(state);
  3830. return 0;
  3831. }
  3832. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3833. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3834. }
  3835. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3836. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3837. }
  3838. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3839. if (!lua_interface)
  3840. return 0;
  3841. Quest* quest = lua_interface->GetQuest(state);
  3842. int32 step = lua_interface->GetInt32Value(state, 2);
  3843. string description = lua_interface->GetStringValue(state, 3);
  3844. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3845. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3846. int16 icon = lua_interface->GetInt16Value(state, 6);
  3847. if (quest) {
  3848. const char* taskgroup = 0;
  3849. if (str_taskgroup.length() > 0)
  3850. taskgroup = str_taskgroup.c_str();
  3851. int32 npc_id = 0;
  3852. vector<int32>* ids = 0;
  3853. int i = 0;
  3854. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3855. if (ids == 0)
  3856. ids = new vector<int32>;
  3857. ids->push_back(npc_id);
  3858. i++;
  3859. }
  3860. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3861. if (quest_step && icon > 0)
  3862. quest_step->SetIcon(icon);
  3863. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3864. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3865. if(client)
  3866. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3867. }
  3868. safe_delete(ids);
  3869. }
  3870. lua_interface->ResetFunctionStack(state);
  3871. return 0;
  3872. }
  3873. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3874. if (!lua_interface)
  3875. return 0;
  3876. Quest* quest = lua_interface->GetQuest(state);
  3877. int32 step = lua_interface->GetInt32Value(state, 2);
  3878. string description = lua_interface->GetStringValue(state, 3);
  3879. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3880. float percentage = lua_interface->GetFloatValue(state, 5);
  3881. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3882. int16 icon = lua_interface->GetInt16Value(state, 7);
  3883. if (quest) {
  3884. const char* taskgroup = 0;
  3885. if (str_taskgroup.length() > 0)
  3886. taskgroup = str_taskgroup.c_str();
  3887. int32 item_id = 0;
  3888. vector<int32>* ids = 0;
  3889. int i = 0;
  3890. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3891. if (ids == 0)
  3892. ids = new vector<int32>;
  3893. ids->push_back(item_id);
  3894. i++;
  3895. }
  3896. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3897. if (quest_step && icon > 0 && quantity > 0)
  3898. quest_step->SetIcon(icon);
  3899. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3900. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3901. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3902. }
  3903. safe_delete(ids);
  3904. }
  3905. lua_interface->ResetFunctionStack(state);
  3906. return 0;
  3907. }
  3908. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3909. if (!lua_interface)
  3910. return 0;
  3911. Quest* quest = lua_interface->GetQuest(state);
  3912. int32 step = lua_interface->GetInt32Value(state, 2);
  3913. string description = lua_interface->GetStringValue(state, 3);
  3914. float max_variation = lua_interface->GetFloatValue(state, 4);
  3915. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3916. int16 icon = lua_interface->GetInt16Value(state, 6);
  3917. if (quest) {
  3918. const char* taskgroup = 0;
  3919. if (str_taskgroup.length() > 0)
  3920. taskgroup = str_taskgroup.c_str();
  3921. vector<Location>* locations = 0;
  3922. int8 i = 7;
  3923. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3924. while (true) {
  3925. Location loc;
  3926. loc.x = lua_interface->GetFloatValue(state, i);
  3927. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3928. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3929. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3930. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3931. break;
  3932. if (locations == 0)
  3933. locations = new vector<Location>;
  3934. locations->push_back(loc);
  3935. i += 4;
  3936. }
  3937. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3938. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3939. if (quest_step && icon > 0)
  3940. quest_step->SetIcon(icon);
  3941. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3942. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3943. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3944. }
  3945. }
  3946. lua_interface->ResetFunctionStack(state);
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3950. if (!lua_interface)
  3951. return 0;
  3952. Quest* quest = lua_interface->GetQuest(state);
  3953. int32 step = lua_interface->GetInt32Value(state, 2);
  3954. string description = lua_interface->GetStringValue(state, 3);
  3955. float max_variation = lua_interface->GetFloatValue(state, 4);
  3956. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3957. int16 icon = lua_interface->GetInt16Value(state, 6);
  3958. if (quest) {
  3959. const char* taskgroup = 0;
  3960. if (str_taskgroup.length() > 0)
  3961. taskgroup = str_taskgroup.c_str();
  3962. vector<Location>* locations = 0;
  3963. int8 i = 7;
  3964. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3965. while (true) {
  3966. Location loc;
  3967. loc.x = lua_interface->GetFloatValue(state, i);
  3968. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3969. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3970. loc.zone_id = 0;
  3971. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3972. break;
  3973. if (locations == 0)
  3974. locations = new vector<Location>;
  3975. locations->push_back(loc);
  3976. i += 3;
  3977. }
  3978. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3979. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3980. if (quest_step && icon > 0)
  3981. quest_step->SetIcon(icon);
  3982. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3983. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3984. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3985. }
  3986. }
  3987. lua_interface->ResetFunctionStack(state);
  3988. return 0;
  3989. }
  3990. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3991. if (!lua_interface)
  3992. return 0;
  3993. Quest* quest = lua_interface->GetQuest(state);
  3994. int32 step = lua_interface->GetInt32Value(state, 2);
  3995. string description = lua_interface->GetStringValue(state, 3);
  3996. float max_variation = lua_interface->GetFloatValue(state, 4);
  3997. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3998. int16 icon = lua_interface->GetInt16Value(state, 6);
  3999. if (quest) {
  4000. const char* taskgroup = 0;
  4001. if (str_taskgroup.length() > 0)
  4002. taskgroup = str_taskgroup.c_str();
  4003. vector<Location>* locations = 0;
  4004. int i = 7;
  4005. while (true) {
  4006. Location loc;
  4007. loc.x = lua_interface->GetFloatValue(state, i);
  4008. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4009. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4010. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4011. break;
  4012. if (locations == 0)
  4013. locations = new vector<Location>;
  4014. locations->push_back(loc);
  4015. i += 3;
  4016. }
  4017. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4018. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4019. if (quest_step && icon > 0)
  4020. quest_step->SetIcon(icon);
  4021. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4022. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4023. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4024. }
  4025. }
  4026. lua_interface->ResetFunctionStack(state);
  4027. return 0;
  4028. }
  4029. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4030. Quest* quest = lua_interface->GetQuest(state);
  4031. int32 step = lua_interface->GetInt32Value(state, 2);
  4032. string description = lua_interface->GetStringValue(state, 3);
  4033. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4034. float percentage = lua_interface->GetFloatValue(state, 5);
  4035. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4036. int16 icon = lua_interface->GetInt16Value(state, 7);
  4037. if (quest) {
  4038. const char* taskgroup = 0;
  4039. if (str_taskgroup.length() > 0)
  4040. taskgroup = str_taskgroup.c_str();
  4041. int32 spell_id = 0;
  4042. vector<int32>* ids = 0;
  4043. int i = 0;
  4044. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4045. if (ids == 0)
  4046. ids = new vector<int32>;
  4047. ids->push_back(spell_id);
  4048. i++;
  4049. }
  4050. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4051. if (quest_step && icon > 0 && quantity > 0)
  4052. quest_step->SetIcon(icon);
  4053. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4054. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4055. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4056. }
  4057. safe_delete(ids);
  4058. }
  4059. lua_interface->ResetFunctionStack(state);
  4060. return 0;
  4061. }
  4062. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4063. if (!lua_interface)
  4064. return 0;
  4065. Quest* quest = lua_interface->GetQuest(state);
  4066. int32 step = lua_interface->GetInt32Value(state, 2);
  4067. string description = lua_interface->GetStringValue(state, 3);
  4068. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4069. float percentage = lua_interface->GetFloatValue(state, 5);
  4070. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4071. int16 icon = lua_interface->GetInt16Value(state, 7);
  4072. if (quest) {
  4073. const char* taskgroup = 0;
  4074. if (str_taskgroup.length() > 0)
  4075. taskgroup = str_taskgroup.c_str();
  4076. int32 item_id = 0;
  4077. vector<int32>* ids = 0;
  4078. int i = 0;
  4079. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4080. if (ids == 0)
  4081. ids = new vector<int32>;
  4082. ids->push_back(item_id);
  4083. i++;
  4084. }
  4085. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4086. if (quest_step && icon > 0 && quantity > 0)
  4087. quest_step->SetIcon(icon);
  4088. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4089. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4090. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4091. }
  4092. safe_delete(ids);
  4093. }
  4094. lua_interface->ResetFunctionStack(state);
  4095. return 0;
  4096. }
  4097. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4098. if (!lua_interface)
  4099. return 0;
  4100. Quest* quest = lua_interface->GetQuest(state);
  4101. int32 step = lua_interface->GetInt32Value(state, 2);
  4102. string description = lua_interface->GetStringValue(state, 3);
  4103. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4104. float percentage = lua_interface->GetFloatValue(state, 5);
  4105. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4106. int16 icon = lua_interface->GetInt16Value(state, 7);
  4107. if (quest) {
  4108. const char* taskgroup = 0;
  4109. if (str_taskgroup.length() > 0)
  4110. taskgroup = str_taskgroup.c_str();
  4111. int32 item_id = 0;
  4112. vector<int32>* ids = 0;
  4113. int i = 0;
  4114. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4115. if (ids == 0)
  4116. ids = new vector<int32>;
  4117. ids->push_back(item_id);
  4118. i++;
  4119. }
  4120. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4121. if (quest_step && icon > 0 && quantity > 0)
  4122. quest_step->SetIcon(icon);
  4123. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4124. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4125. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4126. }
  4127. safe_delete(ids);
  4128. }
  4129. lua_interface->ResetFunctionStack(state);
  4130. return 0;
  4131. }
  4132. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4133. if (!lua_interface)
  4134. return 0;
  4135. Quest* quest = lua_interface->GetQuest(state);
  4136. string action = lua_interface->GetStringValue(state, 2);
  4137. lua_interface->ResetFunctionStack(state);
  4138. if (quest) {
  4139. if (action.length() > 0)
  4140. quest->SetCompleteAction(action);
  4141. }
  4142. return 0;
  4143. }
  4144. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4145. if (!lua_interface)
  4146. return 0;
  4147. Quest* quest = lua_interface->GetQuest(state);
  4148. int32 step = lua_interface->GetInt32Value(state, 2);
  4149. string action = lua_interface->GetStringValue(state, 3);
  4150. lua_interface->ResetFunctionStack(state);
  4151. if (quest) {
  4152. if (step > 0 && action.length() > 0)
  4153. quest->AddCompleteAction(step, action);
  4154. }
  4155. return 0;
  4156. }
  4157. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4158. if (!lua_interface)
  4159. return 0;
  4160. Quest* quest = lua_interface->GetQuest(state);
  4161. int32 step = lua_interface->GetInt32Value(state, 2);
  4162. string action = lua_interface->GetStringValue(state, 3);
  4163. lua_interface->ResetFunctionStack(state);
  4164. if (quest) {
  4165. if (step > 0 && action.length() > 0)
  4166. quest->AddProgressAction(step, action);
  4167. }
  4168. return 0;
  4169. }
  4170. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4171. if (!lua_interface)
  4172. return 0;
  4173. Quest* quest = lua_interface->GetQuest(state);
  4174. string description = lua_interface->GetStringValue(state, 2);
  4175. lua_interface->ResetFunctionStack(state);
  4176. if (quest && description.length() > 0)
  4177. quest->SetDescription(description);
  4178. return 0;
  4179. }
  4180. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4181. if (!lua_interface)
  4182. return 0;
  4183. Quest* quest = lua_interface->GetQuest(state);
  4184. string description = lua_interface->GetStringValue(state, 2);
  4185. lua_interface->ResetFunctionStack(state);
  4186. if (quest && description.length() > 0)
  4187. quest->SetCompletedDescription(description);
  4188. return 0;
  4189. }
  4190. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4191. if (!lua_interface)
  4192. return 0;
  4193. Quest* quest = lua_interface->GetQuest(state);
  4194. int32 step = lua_interface->GetInt32Value(state, 2);
  4195. string description = lua_interface->GetStringValue(state, 3);
  4196. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4197. lua_interface->ResetFunctionStack(state);
  4198. if (quest && step > 0 && description.length() > 0) {
  4199. quest->SetTaskGroupDescription(step, description, display_bullets);
  4200. }
  4201. return 0;
  4202. }
  4203. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4204. if (!lua_interface)
  4205. return 0;
  4206. Quest* quest = lua_interface->GetQuest(state);
  4207. int32 step = lua_interface->GetInt32Value(state, 2);
  4208. string description = lua_interface->GetStringValue(state, 3);
  4209. lua_interface->ResetFunctionStack(state);
  4210. if (quest && step > 0 && description.length() > 0) {
  4211. quest->SetStepDescription(step, description);
  4212. }
  4213. return 0;
  4214. }
  4215. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4216. Quest* quest = lua_interface->GetQuest(state);
  4217. string zone = lua_interface->GetStringValue(state, 2);
  4218. lua_interface->ResetFunctionStack(state);
  4219. if (quest && zone.length() > 0)
  4220. quest->SetZone(zone);
  4221. return 0;
  4222. }
  4223. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4224. if (!lua_interface)
  4225. return 0;
  4226. Quest* quest = lua_interface->GetQuest(state);
  4227. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4228. lua_interface->ResetFunctionStack(state);
  4229. if (quest && spawn) {
  4230. if (spawn->IsPlayer()) {
  4231. Client* client = ((Player*)spawn)->GetClient();
  4232. if (client) {
  4233. client->AddPendingQuestReward(quest);
  4234. }
  4235. }
  4236. }
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_Harvest(lua_State* state) {
  4240. if (!lua_interface)
  4241. return 0;
  4242. Spawn* player = lua_interface->GetSpawn(state);
  4243. Spawn* node = lua_interface->GetSpawn(state, 2);
  4244. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4245. Client* client = ((Player*)player)->GetClient();
  4246. if (client) {
  4247. ((GroundSpawn*)node)->ProcessHarvest(client);
  4248. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4249. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4250. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4251. }
  4252. }
  4253. }
  4254. else if (player && player->IsPlayer()) {
  4255. Client* client = ((Player*)player)->GetClient();
  4256. if (client)
  4257. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4258. }
  4259. lua_interface->ResetFunctionStack(state);
  4260. return 0;
  4261. }
  4262. int EQ2Emu_lua_Bind(lua_State* state) {
  4263. if (!lua_interface)
  4264. return 0;
  4265. Spawn* spawn = lua_interface->GetSpawn(state);
  4266. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4267. float x = lua_interface->GetFloatValue(state, 3);
  4268. float y = lua_interface->GetFloatValue(state, 4);
  4269. float z = lua_interface->GetFloatValue(state, 5);
  4270. float h = lua_interface->GetFloatValue(state, 6);
  4271. lua_interface->ResetFunctionStack(state);
  4272. if (!spawn) {
  4273. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4274. return 0;
  4275. }
  4276. if (!spawn->IsPlayer()) {
  4277. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4278. return 0;
  4279. }
  4280. if (zone_id == 0) {
  4281. Client* client = ((Player*)spawn)->GetClient();
  4282. if (!client) {
  4283. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4284. return 0;
  4285. }
  4286. if (!client->Bind())
  4287. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4288. }
  4289. else {
  4290. Player* player = (Player*)spawn;
  4291. player->GetPlayerInfo()->SetBindZone(zone_id);
  4292. player->GetPlayerInfo()->SetBindX(x);
  4293. player->GetPlayerInfo()->SetBindY(y);
  4294. player->GetPlayerInfo()->SetBindZ(z);
  4295. player->GetPlayerInfo()->SetBindHeading(h);
  4296. }
  4297. return 0;
  4298. }
  4299. int EQ2Emu_lua_Gate(lua_State* state) {
  4300. if (!lua_interface)
  4301. return 0;
  4302. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4303. Spawn* spawn = lua_interface->GetSpawn(state);
  4304. lua_interface->ResetFunctionStack(state);
  4305. if (spawn) {
  4306. if (spawn->IsPlayer()) {
  4307. Client* client = ((Player*)spawn)->GetClient();
  4308. if (client) {
  4309. if (!client->Gate((spell != nullptr) ? true : false))
  4310. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4311. }
  4312. }
  4313. }
  4314. return 0;
  4315. }
  4316. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4317. if (!lua_interface)
  4318. return 0;
  4319. bool ret = false;
  4320. Spawn* spawn = lua_interface->GetSpawn(state);
  4321. lua_interface->ResetFunctionStack(state);
  4322. if (spawn) {
  4323. if (spawn->IsPlayer()) {
  4324. Client* client = ((Player*)spawn)->GetClient();
  4325. if (client)
  4326. ret = client->BindAllowed();
  4327. }
  4328. }
  4329. lua_interface->SetBooleanValue(state, ret);
  4330. return 1;
  4331. }
  4332. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4333. if (!lua_interface)
  4334. return 0;
  4335. bool ret = false;
  4336. Spawn* spawn = lua_interface->GetSpawn(state);
  4337. lua_interface->ResetFunctionStack(state);
  4338. if (spawn) {
  4339. if (spawn->IsPlayer()) {
  4340. Client* client = ((Player*)spawn)->GetClient();
  4341. ZoneServer* zone = lua_interface->GetZone(state);
  4342. if (client && zone){
  4343. ret = zone->GetCanGate();
  4344. }
  4345. }
  4346. }
  4347. lua_interface->SetBooleanValue(state, ret);
  4348. return 1;
  4349. }
  4350. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4351. Spawn* spawn = lua_interface->GetSpawn(state);
  4352. lua_interface->ResetFunctionStack(state);
  4353. if (spawn) {
  4354. lua_interface->SetBooleanValue(state, spawn->Alive());
  4355. return 1;
  4356. }
  4357. return 0;
  4358. }
  4359. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4360. if (!lua_interface)
  4361. return 0;
  4362. Spawn* spawn = lua_interface->GetSpawn(state);
  4363. lua_interface->ResetFunctionStack(state);
  4364. if (spawn && spawn->IsEntity()) {
  4365. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4366. return 1;
  4367. }
  4368. return 0;
  4369. }
  4370. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4371. Spawn* spawn = lua_interface->GetSpawn(state);
  4372. string message = lua_interface->GetStringValue(state, 2);
  4373. string color_str = lua_interface->GetStringValue(state, 3);
  4374. lua_interface->ResetFunctionStack(state);
  4375. int8 color = CHANNEL_NARRATIVE;
  4376. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4377. Client* client = ((Player*)spawn)->GetClient();
  4378. if (client) {
  4379. if (color_str.length() > 0) {
  4380. // leave for backwards compat, but all future should just use the number
  4381. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4382. color = CHANNEL_COLOR_RED;
  4383. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4384. color = CHANNEL_COLOR_YELLOW;
  4385. else
  4386. {
  4387. // use a number to specify the channel as per Commands/Commands.h defines
  4388. color = (int8)atoul(color_str.c_str());
  4389. }
  4390. }
  4391. client->SimpleMessage(color, message.c_str());
  4392. }
  4393. }
  4394. return 0;
  4395. }
  4396. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4397. Spawn* spawn = lua_interface->GetSpawn(state);
  4398. string message = lua_interface->GetStringValue(state, 2);
  4399. int8 red = lua_interface->GetInt8Value(state, 3);
  4400. int8 green = lua_interface->GetInt8Value(state, 4);
  4401. int8 blue = lua_interface->GetInt8Value(state, 5);
  4402. lua_interface->ResetFunctionStack(state);
  4403. if (!spawn) {
  4404. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4405. return 0;
  4406. }
  4407. if (!spawn->IsPlayer()) {
  4408. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4409. return 0;
  4410. }
  4411. int32 words = ::CountWordsInString(message.c_str());
  4412. if (words < 5)
  4413. words = 5;
  4414. Client* client = ((Player*)spawn)->GetClient();
  4415. if (client)
  4416. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4417. return 0;
  4418. }
  4419. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4420. Spawn* spawn = lua_interface->GetSpawn(state);
  4421. int8 param = lua_interface->GetInt8Value(state, 2);
  4422. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4423. int8 value = lua_interface->GetInt8Value(state, 4);
  4424. lua_interface->ResetFunctionStack(state);
  4425. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4426. Client* client = ((Player*)spawn)->GetClient();
  4427. if (client) {
  4428. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4429. switch (param) {
  4430. case 1: {
  4431. packet->setDataByName("parameter1", param_value);
  4432. break;
  4433. }
  4434. case 2: {
  4435. packet->setDataByName("parameter2", param_value);
  4436. break;
  4437. }
  4438. case 3: {
  4439. packet->setDataByName("parameter3", param_value);
  4440. break;
  4441. }
  4442. case 4: {
  4443. packet->setDataByName("parameter4", param_value);
  4444. break;
  4445. }
  4446. case 5: {
  4447. packet->setDataByName("parameter5", param_value);
  4448. break;
  4449. }
  4450. }
  4451. packet->setDataByName("value", value);
  4452. client->QueuePacket(packet->serialize());
  4453. safe_delete(packet);
  4454. }
  4455. }
  4456. return 0;
  4457. }
  4458. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4459. Spawn* spawn = lua_interface->GetSpawn(state);
  4460. lua_interface->ResetFunctionStack(state);
  4461. if (spawn && spawn->IsPlayer()) {
  4462. if (((Player*)spawn)->GetIsTracking())
  4463. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4464. else
  4465. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4466. }
  4467. return 0;
  4468. }
  4469. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4470. Spawn* player = lua_interface->GetSpawn(state);
  4471. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4472. string name = lua_interface->GetStringValue(state, 3);
  4473. float distance = lua_interface->GetFloatValue(state, 4);
  4474. string command = lua_interface->GetStringValue(state, 5);
  4475. string error_text = lua_interface->GetStringValue(state, 6);
  4476. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4477. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4478. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4479. lua_interface->ResetFunctionStack(state);
  4480. if (spawn) {
  4481. if (distance == 0)
  4482. distance = 10.0f;
  4483. if (command.length() == 0)
  4484. command = name;
  4485. if (command.length() < 1 && name.length() < 1)
  4486. {
  4487. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4488. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4489. spawn->RemovePrimaryCommands();
  4490. }
  4491. else
  4492. {
  4493. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4494. }
  4495. }
  4496. return 0;
  4497. }
  4498. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4499. if (!lua_interface)
  4500. return 0;
  4501. Spawn* player = lua_interface->GetSpawn(state);
  4502. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4503. int16 tier = lua_interface->GetInt16Value(state, 3);
  4504. lua_interface->ResetFunctionStack(state);
  4505. if (player && player->IsPlayer()) {
  4506. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4507. return 1;
  4508. }
  4509. return 0;
  4510. }
  4511. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4512. if (!lua_interface)
  4513. return 0;
  4514. Spawn* player = lua_interface->GetSpawn(state);
  4515. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4516. int16 tier = lua_interface->GetInt16Value(state, 3);
  4517. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4518. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4519. bool add_to_hotbar = true;
  4520. if (num_args > 4) {
  4521. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4522. }
  4523. lua_interface->ResetFunctionStack(state);
  4524. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4525. if (player && spell && player->IsPlayer()) {
  4526. Client* client = player->GetClient();
  4527. if (client) {
  4528. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4529. {
  4530. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4531. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4532. client->GetPlayer()->UnlockSpell(spell);
  4533. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4534. }
  4535. else
  4536. {
  4537. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4538. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4539. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4540. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4541. client->GetPlayer()->UnlockSpell(spell);
  4542. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4543. }
  4544. //if (client ) {
  4545. // ((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);
  4546. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4547. if (outapp)
  4548. client->QueuePacket(outapp);
  4549. }
  4550. }
  4551. return 0;
  4552. }
  4553. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4554. if (!lua_interface)
  4555. return 0;
  4556. Spawn* player = lua_interface->GetSpawn(state);
  4557. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4558. lua_interface->ResetFunctionStack(state);
  4559. if (player && player->IsPlayer()) {
  4560. Client* client = player->GetClient();
  4561. if (client) {
  4562. ((Player*)player)->DeleteSpellBook(type_selection);
  4563. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4564. if (outapp)
  4565. client->QueuePacket(outapp);
  4566. }
  4567. }
  4568. return 0;
  4569. }
  4570. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4571. if (!lua_interface)
  4572. return 0;
  4573. Spawn* player = lua_interface->GetSpawn(state);
  4574. lua_interface->ResetFunctionStack(state);
  4575. if (player && player->IsPlayer()) {
  4576. Client* client = player->GetClient();
  4577. if (client) {
  4578. client->SendNewAdventureSpells();
  4579. }
  4580. }
  4581. return 0;
  4582. }
  4583. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4584. if (!lua_interface)
  4585. return 0;
  4586. Spawn* player = lua_interface->GetSpawn(state);
  4587. lua_interface->ResetFunctionStack(state);
  4588. if (player && player->IsPlayer()) {
  4589. Client* client = player->GetClient();
  4590. if (client) {
  4591. client->SendNewTradeskillSpells();
  4592. }
  4593. }
  4594. return 0;
  4595. }
  4596. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4597. if (!lua_interface)
  4598. return 0;
  4599. Spawn* player = lua_interface->GetSpawn(state);
  4600. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4601. lua_interface->ResetFunctionStack(state);
  4602. if (player && player->IsPlayer()) {
  4603. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4604. Client* client = player->GetClient();
  4605. if (sbe && client) {
  4606. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4607. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4608. if (outapp)
  4609. client->QueuePacket(outapp);
  4610. }
  4611. }
  4612. return 0;
  4613. }
  4614. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4615. if (!lua_interface)
  4616. return 0;
  4617. Spawn* player = lua_interface->GetSpawn(state);
  4618. lua_interface->ResetFunctionStack(state);
  4619. if (player && player->IsPlayer()) {
  4620. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4621. return 1;
  4622. }
  4623. return 0;
  4624. }
  4625. int EQ2Emu_lua_Attack(lua_State* state) {
  4626. if (lua_interface) {
  4627. Spawn* npc = lua_interface->GetSpawn(state);
  4628. Spawn* player = lua_interface->GetSpawn(state, 2);
  4629. lua_interface->ResetFunctionStack(state);
  4630. if (npc && player && npc->IsNPC() && player->IsEntity())
  4631. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4632. }
  4633. return 0;
  4634. }
  4635. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4636. if (lua_interface) {
  4637. Spawn* target = lua_interface->GetSpawn(state);
  4638. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4639. lua_interface->ResetFunctionStack(state);
  4640. if (target && target->GetZone())
  4641. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4642. }
  4643. return 0;
  4644. }
  4645. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4646. Spawn* player;
  4647. if (lua_interface) {
  4648. player = lua_interface->GetSpawn(state);
  4649. lua_interface->ResetFunctionStack(state);
  4650. if (player && player->IsPlayer()) {
  4651. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4652. return 1;
  4653. }
  4654. }
  4655. return 0;
  4656. }
  4657. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4658. Spawn* player;
  4659. Client* client;
  4660. if (lua_interface) {
  4661. player = lua_interface->GetSpawn(state);
  4662. lua_interface->ResetFunctionStack(state);
  4663. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4664. if ((client = ((Player*)player)->GetClient()))
  4665. client->HandInCollections();
  4666. }
  4667. return 0;
  4668. }
  4669. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4670. Spawn* widget;
  4671. if (lua_interface) {
  4672. widget = lua_interface->GetSpawn(state);
  4673. lua_interface->ResetFunctionStack(state);
  4674. if (widget && widget->IsWidget())
  4675. ((Widget*)widget)->HandleUse(nullptr, "");
  4676. }
  4677. return 0;
  4678. }
  4679. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4680. Spawn* spawn = 0;
  4681. int32 primary_list = 0;
  4682. int32 secondary_list = 0;
  4683. if (lua_interface) {
  4684. spawn = lua_interface->GetSpawn(state);
  4685. primary_list = lua_interface->GetInt32Value(state, 2);
  4686. secondary_list = lua_interface->GetInt32Value(state, 3);
  4687. lua_interface->ResetFunctionStack(state);
  4688. if (!spawn->IsNPC()) {
  4689. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4690. return 0;
  4691. }
  4692. NPC* npc = (NPC*)spawn;
  4693. npc->SetPrimarySpellList(primary_list);
  4694. npc->SetSecondarySpellList(secondary_list);
  4695. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4696. }
  4697. return 0;
  4698. }
  4699. int EQ2Emu_lua_GetPet(lua_State* state) {
  4700. if (!lua_interface)
  4701. return 0;
  4702. Spawn* spawn = lua_interface->GetSpawn(state);
  4703. lua_interface->ResetFunctionStack(state);
  4704. if (spawn) {
  4705. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4706. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4707. return 1;
  4708. }
  4709. }
  4710. return 0;
  4711. }
  4712. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4713. if (!lua_interface)
  4714. return 0;
  4715. Spawn* spawn = lua_interface->GetSpawn(state);
  4716. lua_interface->ResetFunctionStack(state);
  4717. if (spawn) {
  4718. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4719. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4720. return 1;
  4721. }
  4722. }
  4723. return 0;
  4724. }
  4725. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4726. if (!lua_interface)
  4727. return 0;
  4728. Spawn* spawn = lua_interface->GetSpawn(state);
  4729. lua_interface->ResetFunctionStack(state);
  4730. if (spawn) {
  4731. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4732. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4733. return 1;
  4734. }
  4735. }
  4736. return 0;
  4737. }
  4738. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4739. if (!lua_interface)
  4740. return 0;
  4741. Spawn* spawn = lua_interface->GetSpawn(state);
  4742. lua_interface->ResetFunctionStack(state);
  4743. if (spawn) {
  4744. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4745. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4746. return 1;
  4747. }
  4748. }
  4749. return 0;
  4750. }
  4751. int EQ2Emu_lua_Charm(lua_State* state) {
  4752. if (!lua_interface)
  4753. return 0;
  4754. Spawn* owner = lua_interface->GetSpawn(state);
  4755. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4756. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4757. lua_interface->ResetFunctionStack(state);
  4758. if (!luaspell) {
  4759. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4760. return 0;
  4761. }
  4762. if(luaspell->resisted) {
  4763. return 0;
  4764. }
  4765. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4766. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4767. pet->SetPet(true);
  4768. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4769. ((NPC*)pet)->SetOwner((Entity*)owner);
  4770. // If owner is player and player does not have a summoned pet set the players charsheet
  4771. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4772. Player* player = (Player*)owner;
  4773. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4774. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4775. player->GetInfoStruct()->set_pet_movement(2);
  4776. player->GetInfoStruct()->set_pet_behavior(3);
  4777. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4778. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4779. // Make sure the values get sent to the client
  4780. player->SetCharSheetChanged(true);
  4781. }
  4782. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4783. pet->SetSpawnScript("");
  4784. // Set faction to the same as the owner
  4785. pet->SetFactionID(owner->GetFactionID());
  4786. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4787. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4788. // Clear hate list
  4789. ((NPC*)pet)->Brain()->ClearHate();
  4790. // Set the brain to a pet brain
  4791. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4792. }
  4793. return 0;
  4794. }
  4795. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4796. if (!lua_interface)
  4797. return 0;
  4798. Spawn* spawn = lua_interface->GetSpawn(state);
  4799. lua_interface->ResetFunctionStack(state);
  4800. if (!spawn) {
  4801. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4802. return 0;
  4803. }
  4804. vector<Spawn*> groupMembers;
  4805. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4806. groupMembers = *spawn->GetSpawnGroup();
  4807. }
  4808. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4809. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4810. deque<GroupMemberInfo*>::iterator itr;
  4811. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4812. if (group)
  4813. {
  4814. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4815. deque<GroupMemberInfo*>* members = group->GetMembers();
  4816. GroupMemberInfo* info = 0;
  4817. for (itr = members->begin(); itr != members->end(); itr++) {
  4818. info = *itr;
  4819. if (info->client)
  4820. groupMembers.push_back(info->client->GetPlayer());
  4821. }
  4822. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4823. }
  4824. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4825. }
  4826. else
  4827. return 0;
  4828. lua_createtable(state, groupMembers.size(), 0);
  4829. int newTable = lua_gettop(state);
  4830. for (int32 i = 0; i < groupMembers.size(); i++) {
  4831. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4832. lua_rawseti(state, newTable, i + 1);
  4833. }
  4834. return 1;
  4835. }
  4836. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4837. if (!lua_interface)
  4838. return 0;
  4839. lua_interface->ResetFunctionStack(state);
  4840. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4841. lua_interface->SetOptionWindowValue(state, option_window);
  4842. return 1;
  4843. }
  4844. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4845. if (!lua_interface)
  4846. return 0;
  4847. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4848. if (option_window) {
  4849. OptionWindowOption option_window_option;
  4850. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4851. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4852. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4853. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4854. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4855. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4856. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4857. option_window->push_back(option_window_option);
  4858. }
  4859. lua_interface->ResetFunctionStack(state);
  4860. return 0;
  4861. }
  4862. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4863. if (!lua_interface)
  4864. return 0;
  4865. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4866. Spawn* player = lua_interface->GetSpawn(state, 2);
  4867. string window_title = lua_interface->GetStringValue(state, 3);
  4868. string cancel_command = lua_interface->GetStringValue(state, 4);
  4869. lua_interface->ResetFunctionStack(state);
  4870. if (!player->IsPlayer()) {
  4871. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4872. return 0;
  4873. }
  4874. Client* client = ((Player*)player)->GetClient();
  4875. if (option_window && window_title.length() > 0 && client) {
  4876. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4877. if (!packet)
  4878. return 0;
  4879. packet->setDataByName("title_text", window_title.c_str());
  4880. if (cancel_command.length() > 0)
  4881. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4882. packet->setArrayLengthByName("num_selections", option_window->size());
  4883. vector<OptionWindowOption>::iterator itr;
  4884. int8 i = 0;
  4885. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4886. OptionWindowOption opt = *itr;
  4887. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4888. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4889. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4890. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4891. if (opt.optionCommand.length() > 0)
  4892. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4893. if (opt.optionConfirmTitle.length() > 0)
  4894. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4895. i++;
  4896. }
  4897. client->QueuePacket(packet->serialize());
  4898. lua_interface->SetLuaUserDataStale(option_window);
  4899. safe_delete(option_window);
  4900. safe_delete(packet);
  4901. }
  4902. return 0;
  4903. }
  4904. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4905. if (!lua_interface)
  4906. return 0;
  4907. Spawn* spawn = lua_interface->GetSpawn(state);
  4908. lua_interface->ResetFunctionStack(state);
  4909. if (spawn) {
  4910. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4911. return 1;
  4912. }
  4913. else
  4914. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4915. return 0;
  4916. }
  4917. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4918. if (!lua_interface)
  4919. return 0;
  4920. Spawn* spawn = lua_interface->GetSpawn(state);
  4921. lua_interface->ResetFunctionStack(state);
  4922. if (spawn) {
  4923. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4924. return 1;
  4925. }
  4926. else
  4927. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4928. return 0;
  4929. }
  4930. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4931. if (!lua_interface)
  4932. return 0;
  4933. Spawn* spawn = lua_interface->GetSpawn(state);
  4934. lua_interface->ResetFunctionStack(state);
  4935. if (spawn) {
  4936. int8 class_id = spawn->GetTradeskillClass();
  4937. // Need to add 42 for the offset in the array
  4938. class_id += 44;
  4939. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4940. return 1;
  4941. }
  4942. else
  4943. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4944. return 0;
  4945. }
  4946. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4947. if (!lua_interface)
  4948. return 0;
  4949. Spawn* spawn = lua_interface->GetSpawn(state);
  4950. int16 level = lua_interface->GetInt8Value(state, 2);
  4951. lua_interface->ResetFunctionStack(state);
  4952. if (spawn) {
  4953. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4954. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4955. else
  4956. spawn->SetTSLevel(level);
  4957. }
  4958. else
  4959. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4960. return 0;
  4961. }
  4962. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4963. if (!lua_interface)
  4964. return 0;
  4965. Spawn* spawn = lua_interface->GetSpawn(state);
  4966. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4967. lua_interface->ResetFunctionStack(state);
  4968. if (spawn) {
  4969. spawn->SetAttackable(attackable);
  4970. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4971. }
  4972. return 0;
  4973. }
  4974. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4975. // Check to see if we have a valid lua_interface
  4976. if (!lua_interface)
  4977. return 0;
  4978. // Get the spawn that is getting the pet
  4979. Spawn* spawn = lua_interface->GetSpawn(state);
  4980. // Get the DB ID of the pet
  4981. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4982. // The max level the pet can gain
  4983. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4984. // Get the spell that this command was called from
  4985. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4986. lua_interface->ResetFunctionStack(state);
  4987. // Check to make sure the spawn pointer is valid
  4988. if (!spawn) {
  4989. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4990. return 0;
  4991. }
  4992. // Check to make sure the spawn is an entity
  4993. if (!spawn->IsEntity()) {
  4994. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4995. return 0;
  4996. }
  4997. // Check to make sure the spawn doesn't already have a pet of this type
  4998. if (((Entity*)spawn)->GetPet()) {
  4999. if (spawn->IsPlayer()) {
  5000. Client* client = ((Player*)spawn)->GetClient();
  5001. if (client)
  5002. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  5003. }
  5004. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5005. return 0;
  5006. }
  5007. // Check to see if the DB ID for the pet is set
  5008. if (pet_id == 0) {
  5009. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5010. return 0;
  5011. }
  5012. // Check to see if the pointer to the spell is valid
  5013. if (!luaspell) {
  5014. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5015. return 0;
  5016. }
  5017. if(luaspell->resisted) {
  5018. return 0;
  5019. }
  5020. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5021. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5022. if (!pet) {
  5023. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5024. return 0;
  5025. }
  5026. // Check to make sure the pet is an npc
  5027. if (!pet->IsNPC()) {
  5028. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5029. return 0;
  5030. }
  5031. // Spawn the pet at the same location as the owner
  5032. pet->SetX(spawn->GetX());
  5033. pet->SetY(spawn->GetY());
  5034. pet->SetZ(spawn->GetZ());
  5035. pet->SetLocation(spawn->GetLocation());
  5036. pet->SetHeading(spawn->GetHeading());
  5037. std::string petName = std::string("");
  5038. if(spawn->IsEntity()) {
  5039. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5040. }
  5041. if(petName.size() < 1) {
  5042. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5043. petName = spawn->GetZone()->pet_names.at(rand_index);
  5044. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5045. }
  5046. // If player set various values for the char sheet (pet window)
  5047. if (spawn->IsPlayer()) {
  5048. Player* player = (Player*)spawn;
  5049. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5050. player->GetInfoStruct()->set_pet_name(petName);
  5051. player->GetInfoStruct()->set_pet_movement(2);
  5052. player->GetInfoStruct()->set_pet_behavior(3);
  5053. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5054. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5055. // Make sure the values get sent to the client
  5056. player->SetCharSheetChanged(true);
  5057. }
  5058. // Set the pets name
  5059. pet->SetName(petName.c_str());
  5060. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5061. if (max_level > 0)
  5062. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5063. else
  5064. pet->SetLevel(spawn->GetLevel());
  5065. // Set the max level this pet can reach
  5066. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5067. ((NPC*)pet)->UpdateWeapons();
  5068. // Set the faction of the pet to the same faction as the owner
  5069. pet->SetFactionID(spawn->GetFactionID());
  5070. // Set the spawn as a pet
  5071. pet->SetPet(true);
  5072. // Give a pointer of the owner to the pet
  5073. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5074. // Give a pointer of the pet to the owner
  5075. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5076. // Set the pet type
  5077. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5078. // Set the spell id used to create this pet
  5079. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5080. // Set the spell tier used to create this pet
  5081. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5082. // Set the pets spawn type to 6
  5083. pet->SetSpawnType(6);
  5084. // Set the pets brain
  5085. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5086. // Check to see if the pet has a subtitle
  5087. if (strlen(pet->GetSubTitle()) > 0) {
  5088. // Add the players name to the front of the sub title
  5089. string pet_subtitle;
  5090. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5091. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5092. // Set the pets subtitle to the new one
  5093. pet->SetSubTitle(pet_subtitle.c_str());
  5094. }
  5095. // Add the "Pet Options" entity command to the pet
  5096. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5097. const char* spawn_script = world.GetSpawnScript(pet_id);
  5098. bool runScript = false;
  5099. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5100. runScript = true;
  5101. pet->SetSpawnScript(string(spawn_script));
  5102. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5103. }
  5104. spawn->GetZone()->AddSpawn(pet);
  5105. if(runScript){
  5106. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5107. }
  5108. // Set the pet as the return value for this function
  5109. lua_interface->SetSpawnValue(state, pet);
  5110. return 1;
  5111. }
  5112. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5113. if (!lua_interface)
  5114. return 0;
  5115. Spawn* spawn = lua_interface->GetSpawn(state);
  5116. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5117. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5118. lua_interface->ResetFunctionStack(state);
  5119. if (!spawn) {
  5120. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5121. return 0;
  5122. }
  5123. if (!spawn->IsEntity()) {
  5124. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5125. return 0;
  5126. }
  5127. if (((Entity*)spawn)->GetDeityPet()) {
  5128. if (spawn->IsPlayer()) {
  5129. Client* client = ((Player*)spawn)->GetClient();
  5130. if (client)
  5131. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5132. }
  5133. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5134. return 0;
  5135. }
  5136. if (pet_id == 0) {
  5137. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5138. return 0;
  5139. }
  5140. if (!luaspell) {
  5141. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5142. return 0;
  5143. }
  5144. if(luaspell->resisted) {
  5145. return 0;
  5146. }
  5147. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5148. if (!pet) {
  5149. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5150. return 0;
  5151. }
  5152. if (!pet->IsNPC()) {
  5153. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5154. return 0;
  5155. }
  5156. pet->SetX(spawn->GetX());
  5157. pet->SetY(spawn->GetY());
  5158. pet->SetZ(spawn->GetZ());
  5159. pet->SetLocation(spawn->GetLocation());
  5160. pet->SetHeading(spawn->GetHeading());
  5161. spawn->GetZone()->AddSpawn(pet);
  5162. string random_pet_name;
  5163. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5164. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5165. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5166. pet->SetName(random_pet_name.c_str());
  5167. pet->SetLevel(spawn->GetLevel());
  5168. pet->SetFactionID(spawn->GetFactionID());
  5169. pet->SetPet(true);
  5170. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5171. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5172. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5173. pet->SetSpawnType(6);
  5174. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5175. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5176. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5177. if (strlen(pet->GetSubTitle()) > 0) {
  5178. string pet_subtitle;
  5179. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5180. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5181. pet->SetSubTitle(pet_subtitle.c_str());
  5182. }
  5183. // deity and cosmetic pets are not attackable
  5184. pet->SetAttackable(false);
  5185. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5186. lua_interface->SetSpawnValue(state, pet);
  5187. return 1;
  5188. }
  5189. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5190. if (!lua_interface)
  5191. return 0;
  5192. Spawn* spawn = lua_interface->GetSpawn(state);
  5193. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5194. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5195. lua_interface->ResetFunctionStack(state);
  5196. if (!spawn) {
  5197. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5198. return 0;
  5199. }
  5200. if (!spawn->IsEntity()) {
  5201. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5202. return 0;
  5203. }
  5204. if (((Entity*)spawn)->GetCosmeticPet()) {
  5205. if (spawn->IsPlayer()) {
  5206. Client* client = ((Player*)spawn)->GetClient();
  5207. if (client)
  5208. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5209. }
  5210. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5211. return 0;
  5212. }
  5213. if (pet_id == 0) {
  5214. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5215. return 0;
  5216. }
  5217. if (!luaspell) {
  5218. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5219. return 0;
  5220. }
  5221. if(luaspell->resisted) {
  5222. return 0;
  5223. }
  5224. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5225. if (!pet) {
  5226. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5227. return 0;
  5228. }
  5229. if (!pet->IsNPC()) {
  5230. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5231. return 0;
  5232. }
  5233. pet->SetX(spawn->GetX());
  5234. pet->SetY(spawn->GetY());
  5235. pet->SetZ(spawn->GetZ());
  5236. pet->SetLocation(spawn->GetLocation());
  5237. pet->SetHeading(spawn->GetHeading());
  5238. spawn->GetZone()->AddSpawn(pet);
  5239. string random_pet_name;
  5240. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5241. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5242. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5243. pet->SetName(random_pet_name.c_str());
  5244. pet->SetLevel(spawn->GetLevel());
  5245. pet->SetFactionID(spawn->GetFactionID());
  5246. pet->SetPet(true);
  5247. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5248. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5249. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5250. pet->SetSpawnType(6);
  5251. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5252. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5253. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5254. if (strlen(pet->GetSubTitle()) > 0) {
  5255. string pet_subtitle;
  5256. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5257. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5258. pet->SetSubTitle(pet_subtitle.c_str());
  5259. }
  5260. pet->SetAttackable(false);
  5261. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5262. lua_interface->SetSpawnValue(state, pet);
  5263. return 1;
  5264. }
  5265. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5266. if (!lua_interface)
  5267. return 0;
  5268. Spawn* spawn = lua_interface->GetSpawn(state);
  5269. lua_interface->ResetFunctionStack(state);
  5270. if (!spawn) {
  5271. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5272. return 0;
  5273. }
  5274. if (!spawn->IsPet()) {
  5275. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5276. return 0;
  5277. }
  5278. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5279. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5280. return 0;
  5281. }
  5282. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5283. if (!lua_interface)
  5284. return 0;
  5285. Quest* quest = lua_interface->GetQuest(state);
  5286. if (!quest) {
  5287. 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));
  5288. lua_interface->ResetFunctionStack(state);
  5289. return 0;
  5290. }
  5291. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5292. lua_interface->ResetFunctionStack(state);
  5293. if (feather_color > 0)
  5294. quest->SetFeatherColor(feather_color);
  5295. return 0;
  5296. }
  5297. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5298. if (!lua_interface)
  5299. return 0;
  5300. Spawn* spawn = lua_interface->GetSpawn(state);
  5301. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5302. lua_interface->ResetFunctionStack(state);
  5303. if (!spawn) {
  5304. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5305. return 0;
  5306. }
  5307. if (!spawn2) {
  5308. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5309. return 0;
  5310. }
  5311. spawn->RemoveSpawnAccess(spawn2);
  5312. return 0;
  5313. }
  5314. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5315. if (!lua_interface)
  5316. return 0;
  5317. ZoneServer* zone = lua_interface->GetZone(state);
  5318. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5319. lua_interface->ResetFunctionStack(state);
  5320. if (!zone) {
  5321. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5322. return 0;
  5323. }
  5324. if (location_id == 0) {
  5325. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5326. return 0;
  5327. }
  5328. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5329. if (!location) {
  5330. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5331. return 0;
  5332. }
  5333. Spawn* spawn = 0;
  5334. if (location->entities[0]) {
  5335. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5336. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5337. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5338. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5339. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5340. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5341. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5342. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5343. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5344. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5345. if(spawn && spawn->IsOmittedByDBFlag())
  5346. {
  5347. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5348. safe_delete(spawn);
  5349. spawn = 0;
  5350. return 0;
  5351. }
  5352. if (spawn) {
  5353. const char* script = 0;
  5354. for (int x = 0; x < 3; x++) {
  5355. switch (x) {
  5356. case 0:
  5357. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5358. break;
  5359. case 1:
  5360. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5361. break;
  5362. case 2:
  5363. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5364. break;
  5365. }
  5366. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5367. spawn->SetSpawnScript(string(script));
  5368. break;
  5369. }
  5370. }
  5371. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5372. lua_interface->SetSpawnValue(state, spawn);
  5373. return 1;
  5374. }
  5375. else {
  5376. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5377. safe_delete(spawn);
  5378. }
  5379. }
  5380. return 0;
  5381. }
  5382. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5383. if (!lua_interface)
  5384. return 0;
  5385. Spawn* caster = lua_interface->GetSpawn(state);
  5386. Spawn* target = lua_interface->GetSpawn(state, 2);
  5387. int32 id = lua_interface->GetInt32Value(state, 3);
  5388. string command = lua_interface->GetStringValue(state, 4);
  5389. lua_interface->ResetFunctionStack(state);
  5390. if (!caster) {
  5391. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5392. return 0;
  5393. }
  5394. if (!target) {
  5395. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5396. return 0;
  5397. }
  5398. if (!caster->IsPlayer()) {
  5399. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5400. return 0;
  5401. }
  5402. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5403. if (!entity_command) {
  5404. 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());
  5405. return 0;
  5406. }
  5407. Client* client = ((Player*)caster)->GetClient();
  5408. if (!client) {
  5409. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5410. return 0;
  5411. }
  5412. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5413. return 0;
  5414. }
  5415. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5416. if (!lua_interface)
  5417. return 0;
  5418. Spawn* spawn = lua_interface->GetSpawn(state);
  5419. lua_interface->ResetFunctionStack(state);
  5420. if (!spawn) {
  5421. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5422. return 0;
  5423. }
  5424. if (!spawn->IsNPC()) {
  5425. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5426. return 0;
  5427. }
  5428. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5429. return 0;
  5430. }
  5431. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5432. if (!lua_interface)
  5433. return 0;
  5434. Spawn* spawn = lua_interface->GetSpawn(state);
  5435. int16 tick = lua_interface->GetInt16Value(state, 2);
  5436. lua_interface->ResetFunctionStack(state);
  5437. if (!spawn) {
  5438. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5439. return 0;
  5440. }
  5441. if (!spawn->IsNPC()) {
  5442. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5443. return 0;
  5444. }
  5445. if (tick < 20) {
  5446. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5447. return 0;
  5448. }
  5449. ((NPC*)spawn)->Brain()->SetTick(tick);
  5450. return 0;
  5451. }
  5452. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5453. if (!lua_interface)
  5454. return 0;
  5455. Spawn* spawn = lua_interface->GetSpawn(state);
  5456. Spawn* target = lua_interface->GetSpawn(state, 2);
  5457. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5458. lua_interface->ResetFunctionStack(state);
  5459. if (!spawn) {
  5460. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5461. return 0;
  5462. }
  5463. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5464. spawn->SetFollowTarget(target, follow_distance);
  5465. return 0;
  5466. }
  5467. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5468. if (!lua_interface)
  5469. return 0;
  5470. Spawn* spawn = lua_interface->GetSpawn(state);
  5471. lua_interface->ResetFunctionStack(state);
  5472. if (!spawn) {
  5473. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5474. return 0;
  5475. }
  5476. Spawn* target = spawn->GetFollowTarget();
  5477. if (target) {
  5478. lua_interface->SetSpawnValue(state, target);
  5479. return 1;
  5480. }
  5481. return 0;
  5482. }
  5483. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5484. if (!lua_interface)
  5485. return 0;
  5486. Spawn* spawn = lua_interface->GetSpawn(state);
  5487. lua_interface->ResetFunctionStack(state);
  5488. if (!spawn) {
  5489. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5490. return 0;
  5491. }
  5492. if (spawn->following)
  5493. spawn->following = false;
  5494. else
  5495. spawn->following = true;
  5496. return 0;
  5497. }
  5498. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5499. if (!lua_interface)
  5500. return 0;
  5501. Spawn* spawn = lua_interface->GetSpawn(state);
  5502. lua_interface->ResetFunctionStack(state);
  5503. if (!spawn) {
  5504. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5505. return 0;
  5506. }
  5507. lua_interface->SetBooleanValue(state, spawn->following);
  5508. return 1;
  5509. }
  5510. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5511. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5512. // I will attempt to explain how this function works for future refrence
  5513. // Fist lets make sure lua_interface is valid, if not return out
  5514. if (!lua_interface)
  5515. return 0;
  5516. // Next we grab the first 2 params same as we usually would
  5517. Spawn* spawn = lua_interface->GetSpawn(state);
  5518. string var = lua_interface->GetStringValue(state, 2);
  5519. // 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
  5520. // 1 = Spawn
  5521. // 2 = Zone
  5522. // 3 = Item
  5523. // 4 = Quest
  5524. // 5 = String
  5525. // 6 = nil (null)
  5526. int8 dataType = 0;
  5527. // Define pointers for each potential type
  5528. Spawn* spawnVal = 0;
  5529. ZoneServer* zone = 0;
  5530. Item* item = 0;
  5531. Quest* quest = 0;
  5532. string val;
  5533. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5534. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5535. // options window are also light user data be we do not handle those.
  5536. // We check with lua_islightuserdata(lua_State*, index)
  5537. if (lua_islightuserdata(state, 3)) {
  5538. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5539. // and convert it to LUAUserData*
  5540. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5541. // Check to make sure the data we got is valid, if not give an error
  5542. if (!data || !data->IsCorrectlyInitialized()) {
  5543. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5544. }
  5545. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5546. else if (data->IsSpawn()) {
  5547. spawnVal = data->spawn;
  5548. dataType = 1;
  5549. }
  5550. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5551. else if (data->IsZone()) {
  5552. zone = data->zone;
  5553. dataType = 2;
  5554. }
  5555. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5556. else if (data->IsItem()) {
  5557. item = data->item;
  5558. dataType = 3;
  5559. }
  5560. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5561. else if (data->IsQuest()) {
  5562. quest = data->quest;
  5563. dataType = 4;
  5564. }
  5565. }
  5566. // Wasn't light user data, check if it is nil(null)
  5567. else if (lua_isnil(state, 3)) {
  5568. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5569. dataType = 6;
  5570. }
  5571. // Wasn't light user data or nil (null), must be a string
  5572. else {
  5573. // Set the string and dataType variable
  5574. val = lua_interface->GetStringValue(state, 3);
  5575. dataType = 5;
  5576. }
  5577. lua_interface->ResetFunctionStack(state);
  5578. // We now have all the params, lets check to make sure they are valid
  5579. if (!spawn) {
  5580. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5581. return 0;
  5582. }
  5583. if (var.length() == 0) {
  5584. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5585. return 0;
  5586. }
  5587. if (dataType == 0) {
  5588. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5589. return 0;
  5590. }
  5591. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5592. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5593. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5594. switch (dataType) {
  5595. case 1:
  5596. // 1 = Spawn
  5597. spawn->AddTempVariable(var, spawnVal);
  5598. break;
  5599. case 2:
  5600. // 2 = Zone
  5601. spawn->AddTempVariable(var, zone);
  5602. break;
  5603. case 3:
  5604. // 3 = Item
  5605. spawn->AddTempVariable(var, item);
  5606. break;
  5607. case 4:
  5608. // 4 = Quest
  5609. spawn->AddTempVariable(var, quest);
  5610. break;
  5611. case 5:
  5612. // 5 = String
  5613. spawn->AddTempVariable(var, val);
  5614. break;
  5615. case 6:
  5616. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5617. spawn->DeleteTempVariable(var);
  5618. break;
  5619. }
  5620. // And we are done so return out
  5621. return 0;
  5622. }
  5623. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5624. if (!lua_interface)
  5625. return 0;
  5626. Spawn* spawn = lua_interface->GetSpawn(state);
  5627. string var = lua_interface->GetStringValue(state, 2);
  5628. lua_interface->ResetFunctionStack(state);
  5629. if (!spawn) {
  5630. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5631. return 0;
  5632. }
  5633. if (var.length() == 0) {
  5634. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5635. return 0;
  5636. }
  5637. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5638. int8 type = spawn->GetTempVariableType(var);
  5639. Spawn* spawn2 = 0;
  5640. ZoneServer* zone = 0;
  5641. Item* item = 0;
  5642. Quest* quest = 0;
  5643. // Set the lua function return value based on the type of data the variable contains
  5644. switch (type) {
  5645. case 1:
  5646. spawn2 = spawn->GetTempVariableSpawn(var);
  5647. if (!spawn2)
  5648. return 0;
  5649. lua_interface->SetSpawnValue(state, spawn2);
  5650. break;
  5651. case 2:
  5652. zone = spawn->GetTempVariableZone(var);
  5653. if (!zone)
  5654. return 0;
  5655. lua_interface->SetZoneValue(state, zone);
  5656. break;
  5657. case 3:
  5658. item = spawn->GetTempVariableItem(var);
  5659. if (!item)
  5660. return 0;
  5661. lua_interface->SetItemValue(state, item);
  5662. break;
  5663. case 4:
  5664. quest = spawn->GetTempVariableQuest(var);
  5665. if (!quest)
  5666. return 0;
  5667. lua_interface->SetQuestValue(state, quest);
  5668. break;
  5669. case 5:
  5670. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5671. break;
  5672. default:
  5673. // Not a valid type then the variable was not set so return out
  5674. return 0;
  5675. }
  5676. // Return value was set so return out
  5677. return 1;
  5678. }
  5679. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5680. {
  5681. if (!lua_interface)
  5682. return 0;
  5683. Quest* quest = lua_interface->GetQuest(state);
  5684. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5685. string description = lua_interface->GetStringValue(state, 3);
  5686. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5687. if (!quest) {
  5688. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5689. lua_interface->ResetFunctionStack(state);
  5690. lua_interface->SetBooleanValue(state, false);
  5691. return 1;
  5692. }
  5693. if (!spawn) {
  5694. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5695. lua_interface->ResetFunctionStack(state);
  5696. lua_interface->SetBooleanValue(state, false);
  5697. return 1;
  5698. }
  5699. if (!spawn->IsPlayer()) {
  5700. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5701. lua_interface->ResetFunctionStack(state);
  5702. lua_interface->SetBooleanValue(state, false);
  5703. return 1;
  5704. }
  5705. if (item_id == 0) {
  5706. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5707. lua_interface->ResetFunctionStack(state);
  5708. lua_interface->SetBooleanValue(state, false);
  5709. return 1;
  5710. }
  5711. Client* client = ((Player*)spawn)->GetClient();
  5712. if (!client) {
  5713. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5714. lua_interface->ResetFunctionStack(state);
  5715. lua_interface->SetBooleanValue(state, false);
  5716. return 1;
  5717. }
  5718. Item* item = master_item_list.GetItem(item_id);
  5719. if (!item) {
  5720. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5721. lua_interface->ResetFunctionStack(state);
  5722. lua_interface->SetBooleanValue(state, false);
  5723. return 1;
  5724. }
  5725. Item* firstItem = new Item(item);
  5726. quest->AddTmpRewardItem(firstItem);
  5727. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5728. bool itemsAddedSuccessfully = true;
  5729. if(num_args > 4)
  5730. {
  5731. for(int8 n=5;n<num_args+1;n++)
  5732. {
  5733. int32 new_item = lua_interface->GetInt32Value(state, n);
  5734. Item* tmpItem = master_item_list.GetItem(new_item);
  5735. if(tmpItem)
  5736. {
  5737. Item* newTmpItem = new Item(tmpItem);
  5738. quest->AddTmpRewardItem(newTmpItem);
  5739. }
  5740. else
  5741. itemsAddedSuccessfully = false;
  5742. }
  5743. }
  5744. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5745. lua_interface->ResetFunctionStack(state);
  5746. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5747. return 1;
  5748. }
  5749. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5750. if (!lua_interface)
  5751. return 0;
  5752. Quest* quest = lua_interface->GetQuest(state);
  5753. lua_interface->ResetFunctionStack(state);
  5754. if (!quest) {
  5755. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5756. return 0;
  5757. }
  5758. quest->SetRepeatable(true);
  5759. return 0;
  5760. }
  5761. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5762. if (!lua_interface)
  5763. return 0;
  5764. Spawn* spawn = lua_interface->GetSpawn(state);
  5765. lua_interface->ResetFunctionStack(state);
  5766. if (!spawn) {
  5767. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5768. return 0;
  5769. }
  5770. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5771. string ret = classes.GetClassNameCase(base_class);
  5772. if (ret.length() > 0) {
  5773. lua_interface->SetStringValue(state, ret.c_str());
  5774. return 1;
  5775. }
  5776. return 0;
  5777. }
  5778. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5779. if (!lua_interface)
  5780. return 0;
  5781. Spawn* player = lua_interface->GetSpawn(state);
  5782. lua_interface->ResetFunctionStack(state);
  5783. if (player && player->IsPlayer()) {
  5784. Client* client = player->GetClient();
  5785. if (client)
  5786. client->SendWaypoints();
  5787. }
  5788. return 0;
  5789. }
  5790. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5791. if (!lua_interface)
  5792. return 0;
  5793. Spawn* player = lua_interface->GetSpawn(state);
  5794. string name = lua_interface->GetStringValue(state, 2);
  5795. int32 type = lua_interface->GetInt32Value(state, 3);
  5796. lua_interface->ResetFunctionStack(state);
  5797. if (type == 0)
  5798. type = 2;
  5799. if (name.length() > 0) {
  5800. if (player && player->IsPlayer()) {
  5801. Client* client = player->GetClient();
  5802. if (client)
  5803. client->AddWaypoint(name, type);
  5804. }
  5805. }
  5806. return 0;
  5807. }
  5808. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5809. if (!lua_interface)
  5810. return 0;
  5811. Spawn* player = lua_interface->GetSpawn(state);
  5812. string name = lua_interface->GetStringValue(state, 2);
  5813. lua_interface->ResetFunctionStack(state);
  5814. if (name.length() > 0) {
  5815. if (player && player->IsPlayer()) {
  5816. Client* client = player->GetClient();
  5817. if (client)
  5818. client->RemoveWaypoint(name);
  5819. }
  5820. }
  5821. return 0;
  5822. }
  5823. int EQ2Emu_lua_AddWard(lua_State* state) {
  5824. if (!lua_interface)
  5825. return 0;
  5826. int32 damage = lua_interface->GetInt32Value(state);
  5827. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5828. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5829. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5830. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5831. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5832. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5833. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5834. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5835. lua_interface->ResetFunctionStack(state);
  5836. if(!spell || spell->resisted) {
  5837. return 0;
  5838. }
  5839. bool ward_was_added = false;
  5840. ZoneServer* zone = spell->caster->GetZone();
  5841. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5842. for (int32 i = 0; i < spell->targets.size(); i++) {
  5843. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5844. if (!target)
  5845. continue;
  5846. if (target->IsEntity()) {
  5847. // If the ward is already active remove it
  5848. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5849. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5850. // Create new ward info
  5851. WardInfo* ward = new WardInfo;
  5852. ward->Spell = spell;
  5853. ward->BaseDamage = damage;
  5854. ward->DamageLeft = damage;
  5855. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5856. ward->keepWard = keepWard;
  5857. ward->WardType = wardType;
  5858. if (damageAbsorptionPercent > 100)
  5859. damageAbsorptionPercent = 100;
  5860. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5861. if (damageAbsorptionMaxHealthPercent > 100)
  5862. damageAbsorptionMaxHealthPercent = 100;
  5863. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5864. ward->RedirectDamagePercent = redirectDamagePercent;
  5865. ward->LastRedirectDamage = 0;
  5866. ward->LastAbsorbedDamage = 0;
  5867. ward->HitCount = 0;
  5868. spell->num_triggers = maxHitCount;
  5869. spell->had_triggers = true;
  5870. spell->cancel_after_all_triggers = false;
  5871. ward->MaxHitCount = maxHitCount;
  5872. ward->RoundTriggered = false;
  5873. if (wardType == WARD_TYPE_MAGICAL)
  5874. ward->DamageType = damageTypes;
  5875. // Add the ward to the entity
  5876. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5877. ward_was_added = true;
  5878. }
  5879. }
  5880. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5881. if (ward_was_added && spell->caster->IsPlayer()) {
  5882. spell->had_dmg_remaining = true;
  5883. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5884. }
  5885. return 0;
  5886. }
  5887. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5888. if (!lua_interface)
  5889. return 0;
  5890. int32 amount = lua_interface->GetInt32Value(state);
  5891. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5892. lua_interface->ResetFunctionStack(state);
  5893. WardInfo* ward = 0;
  5894. if(!spell || spell->resisted) {
  5895. return 0;
  5896. }
  5897. ZoneServer* zone = spell->caster->GetZone();
  5898. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5899. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5900. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5901. ward = target->GetWard(spell->spell->GetSpellID());
  5902. if (target && ward) {
  5903. ward->DamageLeft += amount;
  5904. if (ward->DamageLeft > ward->BaseDamage)
  5905. ward->DamageLeft = ward->BaseDamage;
  5906. for (int32 i = 0; i < spell->targets.size(); i++) {
  5907. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5908. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5909. }
  5910. }
  5911. }
  5912. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5913. if (ward && spell->caster->IsPlayer())
  5914. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5915. return 0;
  5916. }
  5917. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5918. if (!lua_interface)
  5919. return 0;
  5920. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5921. lua_interface->ResetFunctionStack(state);
  5922. if (!spell) {
  5923. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5924. return 0;
  5925. }
  5926. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5927. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5928. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5929. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5930. if (ward) {
  5931. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5932. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5933. return 1;
  5934. }
  5935. }
  5936. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5937. return 0;
  5938. }
  5939. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5940. if (!lua_interface)
  5941. return 0;
  5942. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5943. if (!spell) {
  5944. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5945. lua_interface->ResetFunctionStack(state);
  5946. return 0;
  5947. }
  5948. string type = lua_interface->GetStringValue(state, 2);
  5949. lua_interface->ResetFunctionStack(state);
  5950. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5951. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5952. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5953. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5954. if (ward) {
  5955. if (boost::iequals(type, "damageleft"))
  5956. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5957. else if (boost::iequals(type, "basedamage"))
  5958. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5959. else if (boost::iequals(type, "keepward"))
  5960. lua_interface->SetBooleanValue(state, ward->keepWard);
  5961. else if (boost::iequals(type, "wardtype"))
  5962. lua_interface->SetInt32Value(state, ward->WardType);
  5963. else if (boost::iequals(type, "dmgabsorptionpct"))
  5964. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5965. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5966. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5967. else if (boost::iequals(type, "redirectdamagepercent"))
  5968. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5969. else if (boost::iequals(type, "lastredirectdamage"))
  5970. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5971. else if (boost::iequals(type, "lastabsorbeddamage"))
  5972. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5973. else if (boost::iequals(type, "hitcount"))
  5974. lua_interface->SetInt32Value(state, ward->HitCount);
  5975. else if (boost::iequals(type, "maxhitcount"))
  5976. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5977. else
  5978. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5979. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5980. return 1;
  5981. }
  5982. }
  5983. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5984. return 0;
  5985. }
  5986. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5987. if (!lua_interface)
  5988. return 0;
  5989. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5990. lua_interface->ResetFunctionStack(state);
  5991. if(!spell) {
  5992. return 0;
  5993. }
  5994. ZoneServer* zone = spell->caster->GetZone();
  5995. Spawn* target = 0;
  5996. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5997. for (int32 i = 0; i < spell->targets.size(); i++) {
  5998. target = zone->GetSpawnByID(spell->targets.at(i));
  5999. if (target && target->IsEntity()) {
  6000. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  6001. }
  6002. }
  6003. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6004. return 0;
  6005. }
  6006. int EQ2Emu_lua_Interrupt(lua_State* state)
  6007. {
  6008. if (!lua_interface)
  6009. return 0;
  6010. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6011. Spawn* target = lua_interface->GetSpawn(state, 2);
  6012. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6013. lua_interface->ResetFunctionStack(state);
  6014. if (!caster)
  6015. {
  6016. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6017. return 0;
  6018. }
  6019. if (!target)
  6020. {
  6021. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6022. return 0;
  6023. }
  6024. if (!spell) {
  6025. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6026. return 0;
  6027. }
  6028. if (!target->IsEntity() && !spell)
  6029. {
  6030. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6031. return 0;
  6032. }
  6033. if (!target && spell) {
  6034. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6035. for (int8 i = 0; i < spell->targets.size(); i++) {
  6036. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6037. if (!target || !target->IsEntity())
  6038. continue;
  6039. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6040. }
  6041. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6042. }
  6043. else
  6044. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6045. return 0;
  6046. }
  6047. int EQ2Emu_lua_Stealth(lua_State* state) {
  6048. if (!lua_interface)
  6049. return 0;
  6050. int8 type = lua_interface->GetInt8Value(state);
  6051. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6052. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6053. lua_interface->ResetFunctionStack(state);
  6054. if (!spell) {
  6055. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6056. return 0;
  6057. }
  6058. ZoneServer* zone = spell->caster->GetZone();
  6059. if (spawn) {
  6060. if (spawn->IsEntity()) {
  6061. if (type == 1) {
  6062. ((Entity*)spawn)->AddStealthSpell(spell);
  6063. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6064. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6065. }
  6066. else if (type == 2) {
  6067. ((Entity*)spawn)->AddInvisSpell(spell);
  6068. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6069. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6070. }
  6071. return 0;
  6072. }
  6073. else {
  6074. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6075. return 0;
  6076. }
  6077. }
  6078. else {
  6079. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6080. for (int32 i = 0; i < spell->targets.size(); i++) {
  6081. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6082. if (!spawn || !spawn->IsEntity())
  6083. continue;
  6084. if (type == 1) {
  6085. ((Entity*)spawn)->AddStealthSpell(spell);
  6086. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6087. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6088. }
  6089. else if (type == 2) {
  6090. ((Entity*)spawn)->AddInvisSpell(spell);
  6091. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6092. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6093. }
  6094. else {
  6095. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6096. break;
  6097. }
  6098. }
  6099. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6100. }
  6101. return 0;
  6102. }
  6103. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6104. if (!lua_interface)
  6105. return 0;
  6106. Spawn* spawn = lua_interface->GetSpawn(state);
  6107. lua_interface->ResetFunctionStack(state);
  6108. if (!spawn) {
  6109. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6110. return 0;
  6111. }
  6112. if (spawn->IsEntity()) {
  6113. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6114. return 1;
  6115. }
  6116. else
  6117. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6118. return 0;
  6119. }
  6120. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6121. if (!lua_interface)
  6122. return 0;
  6123. Spawn* spawn = lua_interface->GetSpawn(state);
  6124. lua_interface->ResetFunctionStack(state);
  6125. if (!spawn) {
  6126. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6127. return 0;
  6128. }
  6129. if (spawn->IsEntity()) {
  6130. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6131. return 1;
  6132. }
  6133. else
  6134. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6135. return 0;
  6136. }
  6137. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6138. if (!lua_interface)
  6139. return 0;
  6140. Spawn* player = lua_interface->GetSpawn(state);
  6141. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6142. lua_interface->ResetFunctionStack(state);
  6143. if (!player->IsPlayer()) {
  6144. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6145. return 0;
  6146. }
  6147. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6148. return 1;
  6149. }
  6150. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6151. if (!lua_interface)
  6152. return 0;
  6153. Spawn* spawn = lua_interface->GetSpawn(state);
  6154. int8 slot = lua_interface->GetInt8Value(state, 2);
  6155. lua_interface->ResetFunctionStack(state);
  6156. if (!spawn) {
  6157. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6158. return 0;
  6159. }
  6160. if (!spawn->IsEntity()) {
  6161. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6165. if (!item) {
  6166. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6167. return 0;
  6168. }
  6169. lua_interface->SetItemValue(state, item);
  6170. return 1;
  6171. }
  6172. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6173. if (!lua_interface)
  6174. return 0;
  6175. Spawn* player = lua_interface->GetSpawn(state);
  6176. int32 id = lua_interface->GetInt32Value(state, 2);
  6177. lua_interface->ResetFunctionStack(state);
  6178. if (!player) {
  6179. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6180. return 0;
  6181. }
  6182. if (!player->IsPlayer()) {
  6183. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6184. return 0;
  6185. }
  6186. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6187. if (!item) {
  6188. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6189. return 0;
  6190. }
  6191. lua_interface->SetItemValue(state, item);
  6192. return 1;
  6193. }
  6194. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6195. if (!lua_interface)
  6196. return 0;
  6197. Spawn* spawn = lua_interface->GetSpawn(state);
  6198. int8 slot = lua_interface->GetInt8Value(state, 2);
  6199. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6200. lua_interface->ResetFunctionStack(state);
  6201. if (!spawn) {
  6202. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6203. return 0;
  6204. }
  6205. if (!spawn->IsEntity()) {
  6206. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6207. return 0;
  6208. }
  6209. Item* item = master_item_list.GetItem(item_id);
  6210. if (!item) {
  6211. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6212. return 0;
  6213. }
  6214. Item* copy = new Item(item);
  6215. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6216. if(result)
  6217. {
  6218. ((Entity*)spawn)->SetEquipment(copy, slot);
  6219. spawn->vis_changed = true;
  6220. if(spawn->IsPlayer())
  6221. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6222. }
  6223. else
  6224. {
  6225. safe_delete(copy);
  6226. }
  6227. lua_interface->SetBooleanValue(state, result);
  6228. return 1;
  6229. }
  6230. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6231. if (!lua_interface)
  6232. return 0;
  6233. Spawn* spawn = lua_interface->GetSpawn(state);
  6234. int8 slot = lua_interface->GetInt8Value(state, 2);
  6235. Item* item = lua_interface->GetItem(state, 3);
  6236. lua_interface->ResetFunctionStack(state);
  6237. if (!spawn) {
  6238. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6239. return 0;
  6240. }
  6241. if (!spawn->IsEntity()) {
  6242. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6243. return 0;
  6244. }
  6245. if (!item) {
  6246. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6247. return 0;
  6248. }
  6249. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6250. if(result)
  6251. {
  6252. ((Entity*)spawn)->SetEquipment(item, slot);
  6253. spawn->vis_changed = true;
  6254. if(spawn->IsPlayer())
  6255. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6256. }
  6257. lua_interface->SetBooleanValue(state, result);
  6258. return 1;
  6259. }
  6260. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6261. if (!lua_interface)
  6262. return 0;
  6263. Spawn* spawn = lua_interface->GetSpawn(state);
  6264. int8 slot = lua_interface->GetInt8Value(state, 2);
  6265. bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  6266. lua_interface->ResetFunctionStack(state);
  6267. if (!spawn) {
  6268. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6269. return 0;
  6270. }
  6271. if (!spawn->IsEntity()) {
  6272. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6273. return 0;
  6274. }
  6275. if(slot >= NUM_SLOTS) {
  6276. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6277. return 0;
  6278. }
  6279. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6280. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6281. if(item) {
  6282. item->save_needed = true;
  6283. if(no_delete_item) {
  6284. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6285. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6286. }
  6287. else{
  6288. Client* client = ((Player*)spawn)->GetClient();
  6289. client->UnequipItem(item->details.index);
  6290. }
  6291. }
  6292. }
  6293. else
  6294. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6295. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6296. spawn->vis_changed = true;
  6297. if(spawn->IsPlayer())
  6298. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6299. lua_interface->SetBooleanValue(state, true);
  6300. return 1;
  6301. }
  6302. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6303. if (!lua_interface)
  6304. return 0;
  6305. Spawn* spawn = lua_interface->GetSpawn(state);
  6306. int8 slot = lua_interface->GetInt8Value(state, 2);
  6307. int16 type = lua_interface->GetInt16Value(state, 3);
  6308. int8 r = lua_interface->GetInt8Value(state, 4);
  6309. int8 g = lua_interface->GetInt8Value(state, 5);
  6310. int8 b = lua_interface->GetInt8Value(state, 6);
  6311. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6312. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6313. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6314. lua_interface->ResetFunctionStack(state);
  6315. if (!spawn) {
  6316. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6317. return 0;
  6318. }
  6319. if (!spawn->IsEntity()) {
  6320. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6321. return 0;
  6322. }
  6323. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6324. spawn->vis_changed = true;
  6325. lua_interface->SetBooleanValue(state, true);
  6326. return 1;
  6327. }
  6328. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6329. if (!lua_interface)
  6330. return 0;
  6331. Spawn* player = lua_interface->GetSpawn(state);
  6332. int32 id = lua_interface->GetInt32Value(state, 2);
  6333. int8 count = lua_interface->GetInt8Value(state, 3);
  6334. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6335. lua_interface->ResetFunctionStack(state);
  6336. if (!player) {
  6337. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6338. return 0;
  6339. }
  6340. if (!player->IsPlayer()) {
  6341. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6342. return 0;
  6343. }
  6344. if (!count)
  6345. count = 1;
  6346. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6347. if (!item) {
  6348. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6349. return 0;
  6350. }
  6351. lua_interface->SetItemValue(state, item);
  6352. return 1;
  6353. }
  6354. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6355. if (!lua_interface)
  6356. return 0;
  6357. Spawn* spawn = lua_interface->GetSpawn(state);
  6358. int32 anim = lua_interface->GetInt32Value(state, 2);
  6359. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6360. int8 type = lua_interface->GetInt8Value(state, 4);
  6361. lua_interface->ResetFunctionStack(state);
  6362. if (!spawn) {
  6363. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6364. return 0;
  6365. }
  6366. if (spawn2) {
  6367. if (spawn2->IsPlayer()) {
  6368. if (type != 1 && type != 2)
  6369. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6370. else
  6371. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6372. return 0;
  6373. }
  6374. else {
  6375. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6376. return 0;
  6377. }
  6378. }
  6379. else
  6380. spawn->GetZone()->PlayAnimation(spawn, anim);
  6381. return 0;
  6382. }
  6383. int EQ2Emu_lua_IsPet(lua_State* state) {
  6384. if (!lua_interface)
  6385. return 0;
  6386. Spawn* spawn = lua_interface->GetSpawn(state);
  6387. lua_interface->ResetFunctionStack(state);
  6388. if (!spawn) {
  6389. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6390. return 0;
  6391. }
  6392. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6393. return 1;
  6394. }
  6395. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6396. if (!lua_interface)
  6397. return 0;
  6398. Spawn* spawn = lua_interface->GetSpawn(state);
  6399. lua_interface->ResetFunctionStack(state);
  6400. if (!spawn) {
  6401. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6402. return 0;
  6403. }
  6404. if (!spawn->IsNPC()) {
  6405. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6406. return 0;
  6407. }
  6408. if (((NPC*)spawn)->GetOwner()) {
  6409. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6410. return 1;
  6411. }
  6412. return 0;
  6413. }
  6414. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6415. if (!lua_interface)
  6416. return 0;
  6417. Spawn* spawn = lua_interface->GetSpawn(state);
  6418. Spawn* target = lua_interface->GetSpawn(state, 2);
  6419. lua_interface->ResetFunctionStack(state);
  6420. if (!spawn) {
  6421. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6422. return 0;
  6423. }
  6424. if (!spawn) {
  6425. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6426. return 0;
  6427. }
  6428. spawn->SetTarget(target);
  6429. return 0;
  6430. }
  6431. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6432. if (!lua_interface)
  6433. return 0;
  6434. Spawn* spawn = lua_interface->GetSpawn(state);
  6435. bool val = lua_interface->GetBooleanValue(state, 2);
  6436. lua_interface->ResetFunctionStack(state);
  6437. if (!spawn) {
  6438. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6439. return 0;
  6440. }
  6441. if (!spawn->IsEntity()) {
  6442. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6443. return 0;
  6444. }
  6445. ((Entity*)spawn)->InCombat(val);
  6446. if (val) {
  6447. spawn->ClearRunningLocations();
  6448. spawn->CalculateRunningLocation(true);
  6449. }
  6450. return 0;
  6451. }
  6452. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6453. if (!lua_interface)
  6454. return 0;
  6455. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6456. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6457. lua_interface->ResetFunctionStack(state);
  6458. if (!spawn1) {
  6459. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6460. return 0;
  6461. }
  6462. if (!spawn2) {
  6463. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6464. return 0;
  6465. }
  6466. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6467. return 1;
  6468. }
  6469. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6470. if (!lua_interface)
  6471. return 0;
  6472. Spawn* spawn = lua_interface->GetSpawn(state);
  6473. lua_interface->ResetFunctionStack(state);
  6474. if (!spawn) {
  6475. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6476. return 0;
  6477. }
  6478. if (!spawn->IsNPC()) {
  6479. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6480. return 0;
  6481. }
  6482. ((NPC*)spawn)->ClearRunback();
  6483. return 0;
  6484. }
  6485. int EQ2Emu_lua_Runback(lua_State* state) {
  6486. if (!lua_interface)
  6487. return 0;
  6488. Spawn* spawn = lua_interface->GetSpawn(state);
  6489. lua_interface->ResetFunctionStack(state);
  6490. if (!spawn) {
  6491. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6492. return 0;
  6493. }
  6494. if (!spawn->IsNPC()) {
  6495. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6496. return 0;
  6497. }
  6498. ((NPC*)spawn)->Runback();
  6499. return 0;
  6500. }
  6501. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6502. if (!lua_interface)
  6503. return 0;
  6504. Spawn* spawn = lua_interface->GetSpawn(state);
  6505. lua_interface->ResetFunctionStack(state);
  6506. if (!spawn) {
  6507. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6508. return 0;
  6509. }
  6510. if (!spawn->IsNPC()) {
  6511. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6512. return 0;
  6513. }
  6514. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6515. return 1;
  6516. }
  6517. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6518. if (!lua_interface)
  6519. return 0;
  6520. Spawn* spawn = lua_interface->GetSpawn(state);
  6521. lua_interface->ResetFunctionStack(state);
  6522. if (!spawn) {
  6523. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6524. return 0;
  6525. }
  6526. if (!spawn->IsEntity()) {
  6527. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6528. return 0;
  6529. }
  6530. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6531. return 1;
  6532. }
  6533. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6534. if (!lua_interface)
  6535. return 0;
  6536. Spawn* spawn = lua_interface->GetSpawn(state);
  6537. lua_interface->ResetFunctionStack(state);
  6538. if (!spawn) {
  6539. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6540. return 0;
  6541. }
  6542. if (!spawn->IsEntity()) {
  6543. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6544. return 0;
  6545. }
  6546. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6547. return 1;
  6548. }
  6549. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6550. if (!lua_interface)
  6551. return 0;
  6552. Spawn* spawn = lua_interface->GetSpawn(state);
  6553. lua_interface->ResetFunctionStack(state);
  6554. if (!spawn) {
  6555. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6556. return 0;
  6557. }
  6558. if (!spawn->IsEntity()) {
  6559. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6560. return 0;
  6561. }
  6562. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6563. return 1;
  6564. }
  6565. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6566. if (!lua_interface)
  6567. return 0;
  6568. Spawn* spawn = lua_interface->GetSpawn(state);
  6569. lua_interface->ResetFunctionStack(state);
  6570. if (!spawn) {
  6571. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6572. return 0;
  6573. }
  6574. if (!spawn->IsEntity()) {
  6575. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6576. return 0;
  6577. }
  6578. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6579. return 1;
  6580. }
  6581. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6582. if (!lua_interface)
  6583. return 0;
  6584. Spawn* spawn = lua_interface->GetSpawn(state);
  6585. Spawn* target = lua_interface->GetSpawn(state, 2);
  6586. float distance = lua_interface->GetFloatValue(state, 3);
  6587. lua_interface->ResetFunctionStack(state);
  6588. if (!spawn) {
  6589. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6590. return 0;
  6591. }
  6592. if (!target) {
  6593. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6594. return 0;
  6595. }
  6596. if (!spawn->IsNPC()) {
  6597. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6598. return 0;
  6599. }
  6600. if (!target->IsEntity()) {
  6601. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6602. return 0;
  6603. }
  6604. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6605. return 1;
  6606. }
  6607. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6608. if (!lua_interface)
  6609. return 0;
  6610. Spawn* spawn = lua_interface->GetSpawn(state);
  6611. Spawn* target = lua_interface->GetSpawn(state, 2);
  6612. float distance = lua_interface->GetFloatValue(state, 3);
  6613. lua_interface->ResetFunctionStack(state);
  6614. if (!spawn) {
  6615. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6616. return 0;
  6617. }
  6618. if (!target) {
  6619. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6620. return 0;
  6621. }
  6622. if (!spawn->IsNPC()) {
  6623. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6624. return 0;
  6625. }
  6626. if (!target->IsEntity()) {
  6627. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6628. return 0;
  6629. }
  6630. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6631. return 0;
  6632. }
  6633. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6634. if (!lua_interface)
  6635. return 0;
  6636. Spawn* spawn = lua_interface->GetSpawn(state);
  6637. lua_interface->ResetFunctionStack(state);
  6638. if (!spawn) {
  6639. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6640. return 0;
  6641. }
  6642. if (!spawn->IsNPC()) {
  6643. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6644. return 0;
  6645. }
  6646. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6647. return 1;
  6648. }
  6649. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6650. if (!lua_interface)
  6651. return 0;
  6652. Spawn* spawn = lua_interface->GetSpawn(state);
  6653. lua_interface->ResetFunctionStack(state);
  6654. if (!spawn) {
  6655. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6656. return 0;
  6657. }
  6658. if (!spawn->IsNPC()) {
  6659. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6660. return 0;
  6661. }
  6662. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6663. return 1;
  6664. }
  6665. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6666. if (!lua_interface)
  6667. return 0;
  6668. Spawn* spawn = lua_interface->GetSpawn(state);
  6669. lua_interface->ResetFunctionStack(state);
  6670. if (!spawn) {
  6671. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6672. return 0;
  6673. }
  6674. if (!spawn->IsNPC()) {
  6675. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6676. return 0;
  6677. }
  6678. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6679. if (hated) {
  6680. lua_interface->SetSpawnValue(state, hated);
  6681. return 1;
  6682. }
  6683. return 0;
  6684. }
  6685. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6686. if (!lua_interface)
  6687. return 0;
  6688. Spawn* spawn = lua_interface->GetSpawn(state);
  6689. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6690. lua_interface->ResetFunctionStack(state);
  6691. if (!spawn) {
  6692. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6693. return 0;
  6694. }
  6695. if (!spawn->IsNPC()) {
  6696. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6697. return 0;
  6698. }
  6699. if (!hated) {
  6700. ((NPC*)spawn)->Brain()->ClearHate();
  6701. return 0;
  6702. }
  6703. else
  6704. {
  6705. if (!hated->IsEntity()) {
  6706. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6707. return 0;
  6708. }
  6709. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6710. return 0;
  6711. }
  6712. return 0;
  6713. }
  6714. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6715. if (!lua_interface)
  6716. return 0;
  6717. Spawn* spawn = lua_interface->GetSpawn(state);
  6718. lua_interface->ResetFunctionStack(state);
  6719. if (!spawn) {
  6720. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6721. return 0;
  6722. }
  6723. if (!spawn->IsNPC()) {
  6724. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6725. return 0;
  6726. }
  6727. ((NPC*)spawn)->Brain()->ClearEncounter();
  6728. return 0;
  6729. }
  6730. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6731. if (!lua_interface)
  6732. return 0;
  6733. Spawn* spawn = lua_interface->GetSpawn(state);
  6734. lua_interface->ResetFunctionStack(state);
  6735. if (!spawn) {
  6736. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6737. return 0;
  6738. }
  6739. if (!spawn->IsNPC()) {
  6740. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6741. return 0;
  6742. }
  6743. // Temp list to store hate list
  6744. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6745. if (encounterList->size() == 0) {
  6746. safe_delete(encounterList);
  6747. return 0;
  6748. }
  6749. lua_createtable(state, encounterList->size(), 0);
  6750. int newTable = lua_gettop(state);
  6751. for (int32 i = 0; i < encounterList->size(); i++) {
  6752. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6753. if (temp)
  6754. lua_interface->SetSpawnValue(state, temp);
  6755. lua_rawseti(state, newTable, i + 1);
  6756. }
  6757. safe_delete(encounterList);
  6758. return 1;
  6759. }
  6760. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6761. if (!lua_interface)
  6762. return 0;
  6763. Spawn* spawn = lua_interface->GetSpawn(state);
  6764. lua_interface->ResetFunctionStack(state);
  6765. if (!spawn) {
  6766. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6767. return 0;
  6768. }
  6769. if (!spawn->IsNPC()) {
  6770. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6771. return 0;
  6772. }
  6773. // Temp list to store hate list
  6774. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6775. if (hateList->size() == 0) {
  6776. safe_delete(hateList);
  6777. return 0;
  6778. }
  6779. lua_createtable(state, hateList->size(), 0);
  6780. int newTable = lua_gettop(state);
  6781. for (int32 i = 0; i < hateList->size(); i++) {
  6782. lua_interface->SetSpawnValue(state, hateList->at(i));
  6783. lua_rawseti(state, newTable, i + 1);
  6784. }
  6785. safe_delete(hateList);
  6786. return 1;
  6787. }
  6788. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6789. if (!lua_interface)
  6790. return 0;
  6791. Spawn* spawn = lua_interface->GetSpawn(state);
  6792. lua_interface->ResetFunctionStack(state);
  6793. if (!spawn) {
  6794. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6795. return 0;
  6796. }
  6797. if (spawn->IsPlayer()) {
  6798. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6799. lua_interface->SetBooleanValue(state, true);
  6800. else
  6801. lua_interface->SetBooleanValue(state, false);
  6802. return 1;
  6803. }
  6804. else {
  6805. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6806. return 1;
  6807. }
  6808. }
  6809. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6810. if (!lua_interface)
  6811. return 0;
  6812. Quest* quest = lua_interface->GetQuest(state);
  6813. lua_interface->ResetFunctionStack(state);
  6814. if (!quest) {
  6815. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6816. return 0;
  6817. }
  6818. quest->SetCompletedFlag(true);
  6819. return 0;
  6820. }
  6821. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6822. if (!lua_interface)
  6823. return 0;
  6824. Spawn* spawn = lua_interface->GetSpawn(state);
  6825. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6826. int8 tier = lua_interface->GetInt8Value(state, 3);
  6827. lua_interface->ResetFunctionStack(state);
  6828. if (!spawn) {
  6829. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6830. return 0;
  6831. }
  6832. if (!spawn->IsEntity()) {
  6833. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6834. return 0;
  6835. }
  6836. if (spellID == 0) {
  6837. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6841. if (effect) {
  6842. if (tier > 0) {
  6843. // If a tier was passed chec to see if it is the same as the effect
  6844. if (tier == effect->tier)
  6845. lua_interface->SetBooleanValue(state, true);
  6846. else
  6847. lua_interface->SetBooleanValue(state, false);
  6848. return 1;
  6849. }
  6850. else {
  6851. // Have an effect but no tier was passed so return true
  6852. lua_interface->SetBooleanValue(state, true);
  6853. }
  6854. return 1;
  6855. }
  6856. // no effect so return false
  6857. lua_interface->SetBooleanValue(state, false);
  6858. return 1;
  6859. }
  6860. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6861. if (!lua_interface)
  6862. return 0;
  6863. Spawn* spawn = lua_interface->GetSpawn(state);
  6864. int32 id = lua_interface->GetInt32Value(state, 2);
  6865. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6866. lua_interface->ResetFunctionStack(state);
  6867. Spawn* spawn2 = 0;
  6868. vector<Spawn*> list;
  6869. if (!spawn) {
  6870. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6871. return 0;
  6872. }
  6873. //If zone not provided, use spawn's zone
  6874. if (!zone)
  6875. zone = spawn->GetZone();
  6876. list = zone->GetSpawnsByID(id);
  6877. if (list.size() == 0) {
  6878. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6879. return 0;
  6880. }
  6881. vector<Spawn*>::iterator itr = list.begin();
  6882. for (int8 i = 0; i < list.size(); i++) {
  6883. spawn2 = itr[i];
  6884. if (spawn2)
  6885. spawn2->AddAllowAccessSpawn(spawn);
  6886. }
  6887. return 0;
  6888. }
  6889. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6890. if (!lua_interface)
  6891. return 0;
  6892. Spawn* spawn = lua_interface->GetSpawn(state);
  6893. int32 id = lua_interface->GetInt32Value(state, 2);
  6894. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6895. lua_interface->ResetFunctionStack(state);
  6896. Spawn* spawn2 = 0;
  6897. if (!spawn) {
  6898. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6899. return 0;
  6900. }
  6901. //If zone not provided, use spawn's zone
  6902. if (!zone)
  6903. zone = spawn->GetZone();
  6904. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6905. vector<Spawn*>::iterator itr = list.begin();
  6906. if (list.size() == 0) {
  6907. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6908. return 0;
  6909. }
  6910. for (int8 i = 0; i < list.size(); i++) {
  6911. spawn2 = itr[i];
  6912. if (spawn2)
  6913. spawn2->RemoveSpawnAccess(spawn);
  6914. }
  6915. return 0;
  6916. }
  6917. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6918. if (!lua_interface)
  6919. return 0;
  6920. Quest* quest = lua_interface->GetQuest(state);
  6921. lua_interface->ResetFunctionStack(state);
  6922. if (!quest) {
  6923. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6924. return 0;
  6925. }
  6926. quest->SetYellowName(true);
  6927. return 0;
  6928. }
  6929. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6930. if (!lua_interface)
  6931. return 0;
  6932. Spawn* spawn = lua_interface->GetSpawn(state);
  6933. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6934. lua_interface->ResetFunctionStack(state);
  6935. if (!spawn) {
  6936. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6937. return 0;
  6938. }
  6939. if (!spawn->IsPlayer()) {
  6940. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6941. return 0;
  6942. }
  6943. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6944. return 1;
  6945. }
  6946. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6947. if (!lua_interface)
  6948. return 0;
  6949. Spawn* spawn = lua_interface->GetSpawn(state);
  6950. lua_interface->ResetFunctionStack(state);
  6951. if (!spawn) {
  6952. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6953. return 0;
  6954. }
  6955. if (!spawn->IsPlayer()) {
  6956. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6957. return 0;
  6958. }
  6959. ZoneServer* zone = spawn->GetZone();
  6960. if (!zone) {
  6961. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6962. return 0;
  6963. }
  6964. Instance_Type iType = zone->GetInstanceType();
  6965. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6966. iType == GROUP_LOCKOUT_INSTANCE ||
  6967. iType == RAID_LOCKOUT_INSTANCE ||
  6968. iType == SOLO_PERSIST_INSTANCE ||
  6969. iType == GROUP_PERSIST_INSTANCE ||
  6970. iType == RAID_PERSIST_INSTANCE) {
  6971. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6972. if (data) {
  6973. // Check to see if the timer has already been set, if it has return out.
  6974. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6975. return 0;
  6976. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6977. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6978. if(spawn->IsPlayer()) {
  6979. Client* client = ((Player*)spawn)->GetClient();
  6980. if (client) {
  6981. string time_msg = "";
  6982. int32 time = data->success_lockout_time;
  6983. int16 hour;
  6984. int8 min;
  6985. int8 sec;
  6986. hour = time / 3600;
  6987. time = time % 3600;
  6988. min = time / 60;
  6989. time = time % 60;
  6990. sec = time;
  6991. if (hour > 0) {
  6992. char temp[10];
  6993. sprintf(temp, " %i", hour);
  6994. time_msg.append(temp);
  6995. time_msg.append(" hour");
  6996. time_msg.append((hour > 1) ? "s" : "");
  6997. }
  6998. if (min > 0) {
  6999. char temp[5];
  7000. sprintf(temp, " %i", min);
  7001. time_msg.append(temp);
  7002. time_msg.append(" minute");
  7003. time_msg.append((min > 1) ? "s" : "");
  7004. }
  7005. // Only add seconds if minutes and hours are 0
  7006. if (hour == 0 && min == 0 && sec > 0) {
  7007. char temp[5];
  7008. sprintf(temp, " %i", sec);
  7009. time_msg.append(temp);
  7010. time_msg.append(" second");
  7011. time_msg.append((sec > 1) ? "s" : "");
  7012. }
  7013. 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());
  7014. }
  7015. else {
  7016. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7017. }
  7018. }
  7019. }
  7020. else
  7021. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7022. }
  7023. else
  7024. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7025. return 0;
  7026. }
  7027. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7028. if (!lua_interface)
  7029. return 0;
  7030. Spawn* spawn = lua_interface->GetSpawn(state);
  7031. lua_interface->ResetFunctionStack(state);
  7032. if (!spawn) {
  7033. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7034. return 0;
  7035. }
  7036. if (!spawn->IsPlayer()) {
  7037. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7038. return 0;
  7039. }
  7040. ZoneServer* zone = spawn->GetZone();
  7041. if (!zone) {
  7042. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7043. return 0;
  7044. }
  7045. Instance_Type iType = zone->GetInstanceType();
  7046. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7047. iType == GROUP_LOCKOUT_INSTANCE ||
  7048. iType == RAID_LOCKOUT_INSTANCE ||
  7049. iType == SOLO_PERSIST_INSTANCE ||
  7050. iType == GROUP_PERSIST_INSTANCE ||
  7051. iType == RAID_PERSIST_INSTANCE) {
  7052. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7053. if (data) {
  7054. // Check to see if the timer has already been set, if it has return out.
  7055. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7056. return 0;
  7057. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7058. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7059. if(spawn->IsPlayer()) {
  7060. Client* client = ((Player*)spawn)->GetClient();
  7061. if (client) {
  7062. string time_msg = "";
  7063. int32 time = data->failure_lockout_time;
  7064. int16 hour;
  7065. int8 min;
  7066. int8 sec;
  7067. hour = time / 3600;
  7068. time = time % 3600;
  7069. min = time / 60;
  7070. time = time % 60;
  7071. sec = time;
  7072. if (hour > 0) {
  7073. char temp[10];
  7074. sprintf(temp, " %i", hour);
  7075. time_msg.append(temp);
  7076. time_msg.append(" hour");
  7077. time_msg.append((hour > 1) ? "s" : "");
  7078. }
  7079. if (min > 0) {
  7080. char temp[5];
  7081. sprintf(temp, " %i", min);
  7082. time_msg.append(temp);
  7083. time_msg.append(" minute");
  7084. time_msg.append((min > 1) ? "s" : "");
  7085. }
  7086. // Only add seconds if minutes and hours are 0
  7087. if (hour == 0 && min == 0 && sec > 0) {
  7088. char temp[5];
  7089. sprintf(temp, " %i", sec);
  7090. time_msg.append(temp);
  7091. time_msg.append(" second");
  7092. time_msg.append((sec > 1) ? "s" : "");
  7093. }
  7094. 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());
  7095. }
  7096. }
  7097. else {
  7098. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7099. }
  7100. }
  7101. else
  7102. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7103. }
  7104. else
  7105. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7106. return 0;
  7107. }
  7108. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7109. if (!lua_interface)
  7110. return 0;
  7111. Spawn* spawn = lua_interface->GetSpawn(state);
  7112. lua_interface->ResetFunctionStack(state);
  7113. if (!spawn) {
  7114. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7115. return 0;
  7116. }
  7117. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7118. return 1;
  7119. }
  7120. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7121. if (!lua_interface)
  7122. return 0;
  7123. Spawn* player = lua_interface->GetSpawn(state);
  7124. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7125. if (!player) {
  7126. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7127. lua_interface->ResetFunctionStack(state);
  7128. return 0;
  7129. }
  7130. if (!player->IsPlayer()) {
  7131. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7132. lua_interface->ResetFunctionStack(state);
  7133. return 0;
  7134. }
  7135. if (!ground) {
  7136. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7137. lua_interface->ResetFunctionStack(state);
  7138. return 0;
  7139. }
  7140. if (!ground->IsGroundSpawn()) {
  7141. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7142. lua_interface->ResetFunctionStack(state);
  7143. return 0;
  7144. }
  7145. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7146. if (!groundspawn_entries) {
  7147. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7148. lua_interface->ResetFunctionStack(state);
  7149. return 0;
  7150. }
  7151. Skill* skill = 0;
  7152. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7153. if (collection_skill == "Collecting")
  7154. skill = ((Player*)player)->GetSkillByName("Gathering");
  7155. else
  7156. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7157. if (!skill) {
  7158. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7159. lua_interface->ResetFunctionStack(state);
  7160. return 0;
  7161. }
  7162. vector<GroundSpawnEntry*>::iterator itr;
  7163. GroundSpawnEntry* entry = 0;
  7164. bool can_harvest = false;
  7165. sint32 min_skill = -1;
  7166. int16 totalSkill = skill->current_val;
  7167. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7168. if(skillID != 0xFFFFFFFF)
  7169. {
  7170. ((Entity*)player)->MStats.lock();
  7171. totalSkill += ((Entity*)player)->stats[skillID];
  7172. ((Entity*)player)->MStats.unlock();
  7173. }
  7174. // first, iterate through groundspawn_entries, discard tables player cannot use
  7175. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7176. {
  7177. entry = *itr;
  7178. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7179. min_skill = entry->min_skill_level;
  7180. // if player lacks skill, skip table
  7181. if (entry->min_skill_level > totalSkill)
  7182. continue;
  7183. // if bonus, but player lacks level, skip table
  7184. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7185. continue;
  7186. can_harvest = true;
  7187. break;
  7188. }
  7189. lua_interface->SetBooleanValue(state, can_harvest);
  7190. // If false, send the message to the client
  7191. if (!can_harvest) {
  7192. Client* client = ((Player*)player)->GetClient();
  7193. if (client) {
  7194. string msg = "You do not have enough skill to ";
  7195. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7196. msg.append("gather");
  7197. else if (collection_skill == "Mining")
  7198. msg.append("mine");
  7199. else if (collection_skill == "Trapping")
  7200. msg.append("trap");
  7201. else if (collection_skill == "Foresting")
  7202. msg.append("forest");
  7203. else if (collection_skill == "Fishing")
  7204. msg.append("catch");
  7205. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7206. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7207. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7208. }
  7209. }
  7210. lua_interface->ResetFunctionStack(state);
  7211. return 1;
  7212. }
  7213. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7214. if (!lua_interface)
  7215. return 0;
  7216. Spawn* player = lua_interface->GetSpawn(state);
  7217. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7218. lua_interface->ResetFunctionStack(state);
  7219. if (!player) {
  7220. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7221. return 0;
  7222. }
  7223. if (!player->IsPlayer()) {
  7224. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7225. return 0;
  7226. }
  7227. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7228. lua_interface->SetBooleanValue(state, ret);
  7229. return 1;
  7230. }
  7231. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7232. // Check to see if we have a valid lua_interface
  7233. if (!lua_interface)
  7234. return 0;
  7235. // Get the spawn that is getting the pet
  7236. Spawn* spawn = lua_interface->GetSpawn(state);
  7237. Spawn* target = lua_interface->GetSpawn(state, 2);
  7238. // Get the DB ID of the pet
  7239. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7240. float x = lua_interface->GetFloatValue(state, 4);
  7241. float y = lua_interface->GetFloatValue(state, 5);
  7242. float z = lua_interface->GetFloatValue(state, 6);
  7243. // Get the spell that this command was called from
  7244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7245. lua_interface->ResetFunctionStack(state);
  7246. // Check to make sure the spawn pointer is valid
  7247. if (!spawn) {
  7248. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7249. return 0;
  7250. }
  7251. // Check to make sure the spawn is an entity
  7252. if (!spawn->IsEntity()) {
  7253. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7254. return 0;
  7255. }
  7256. if (!target) {
  7257. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7258. return 0;
  7259. }
  7260. if (!target->IsEntity()) {
  7261. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7262. return 0;
  7263. }
  7264. // Check to see if the DB ID for the pet is set
  7265. if (pet_id == 0) {
  7266. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7267. return 0;
  7268. }
  7269. // Check to see if the pointer to the spell is valid
  7270. if (!luaspell) {
  7271. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7272. return 0;
  7273. }
  7274. if(luaspell->resisted) {
  7275. return 0;
  7276. }
  7277. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7278. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7279. if (!pet) {
  7280. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7281. return 0;
  7282. }
  7283. // Check to make sure the pet is an npc
  7284. if (!pet->IsNPC()) {
  7285. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7286. return 0;
  7287. }
  7288. if (x == 0)
  7289. x = spawn->GetX();
  7290. if (y == 0)
  7291. y = spawn->GetY();
  7292. if (z == 0)
  7293. z = spawn->GetZ();
  7294. // Spawn the pet at the same location as the owner
  7295. pet->SetX(x);
  7296. pet->SetY(y);
  7297. pet->SetZ(z);
  7298. pet->SetLocation(spawn->GetLocation());
  7299. pet->SetHeading(spawn->GetHeading());
  7300. spawn->GetZone()->AddSpawn(pet);
  7301. const char* spawn_script = world.GetSpawnScript(pet_id);
  7302. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7303. spawn->SetSpawnScript(string(spawn_script));
  7304. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7305. }
  7306. std::string petName = std::string("");
  7307. if(spawn->IsEntity()) {
  7308. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7309. }
  7310. if(petName.size() < 1) {
  7311. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7312. petName = spawn->GetZone()->pet_names.at(rand_index);
  7313. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7314. }
  7315. // Set the pets name
  7316. pet->SetName(petName.c_str());
  7317. // Set the level of the pet to the owners level
  7318. pet->SetLevel(spawn->GetLevel());
  7319. // Set the faction of the pet to the same faction as the owner
  7320. pet->SetFactionID(spawn->GetFactionID());
  7321. // Set the spawn as a pet
  7322. pet->SetPet(true);
  7323. // Give a pointer of the owner to the pet
  7324. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7325. // Set the pet type
  7326. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7327. // Set the spell id used to create this pet
  7328. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7329. // Set the spell tier used to create this pet
  7330. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7331. // Set the pets spawn type to 6
  7332. pet->SetSpawnType(6);
  7333. // Set the pets brain
  7334. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7335. // Check to see if the pet has a subtitle
  7336. if (strlen(pet->GetSubTitle()) > 0) {
  7337. // Add the players name to the front of the sub title
  7338. string pet_subtitle;
  7339. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7340. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7341. // Set the pets subtitle to the new one
  7342. pet->SetSubTitle(pet_subtitle.c_str());
  7343. }
  7344. // Set the pet as the return value for this function
  7345. lua_interface->SetSpawnValue(state, pet);
  7346. return 1;
  7347. }
  7348. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7349. if (!lua_interface)
  7350. return 0;
  7351. Spawn* spawn = lua_interface->GetSpawn(state);
  7352. Spawn* player = lua_interface->GetSpawn(state, 2);
  7353. float max_distance = lua_interface->GetFloatValue(state, 3);
  7354. string type = lua_interface->GetStringValue(state, 4);
  7355. lua_interface->ResetFunctionStack(state);
  7356. if (!spawn || (spawn && spawn->IsPlayer())) {
  7357. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7358. return 0;
  7359. }
  7360. if (!player || !player->IsPlayer()) {
  7361. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7362. return 0;
  7363. }
  7364. Client* client = ((Player*)player)->GetClient();
  7365. if (!client) {
  7366. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7367. return 0;
  7368. }
  7369. //Set max_distance to default if not set or not proper value
  7370. if (max_distance <= 0)
  7371. max_distance = 500;
  7372. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7373. if (packet) {
  7374. float unknown2_3 = 0;
  7375. int8 placement_mode = 0;
  7376. if (type == "wall") {
  7377. placement_mode = 2;
  7378. unknown2_3 = 150;
  7379. }
  7380. else if (type == "ceiling")
  7381. placement_mode = 1;
  7382. packet->setDataByName("placement_mode", placement_mode);
  7383. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7384. packet->setDataByName("model_type", spawn->GetModelType());
  7385. packet->setDataByName("unknown", 1); //size
  7386. packet->setDataByName("unknown2", 1); //size 2
  7387. packet->setDataByName("unknown2", .5, 1); //size 3
  7388. packet->setDataByName("unknown2", 3, 2);
  7389. packet->setDataByName("unknown2", unknown2_3, 3);
  7390. packet->setDataByName("max_distance", max_distance);
  7391. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7392. client->QueuePacket(packet->serialize());
  7393. safe_delete(packet);
  7394. }
  7395. return 0;
  7396. }
  7397. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7398. if (!lua_interface)
  7399. return 0;
  7400. Item* item = lua_interface->GetItem(state);
  7401. lua_interface->ResetFunctionStack(state);
  7402. if (!item) {
  7403. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7404. return 0;
  7405. }
  7406. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7407. return 1;
  7408. }
  7409. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7410. if (!lua_interface)
  7411. return 0;
  7412. Item* item = lua_interface->GetItem(state);
  7413. lua_interface->ResetFunctionStack(state);
  7414. if (!item) {
  7415. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7416. return 0;
  7417. }
  7418. lua_interface->SetInt32Value(state, item->effect_type);
  7419. return 1;
  7420. }
  7421. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7422. if (!lua_interface)
  7423. return 0;
  7424. Spawn* spawn = lua_interface->GetSpawn(state);
  7425. lua_interface->ResetFunctionStack(state);
  7426. if (!spawn) {
  7427. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7428. return 0;
  7429. }
  7430. if (spawn->GetZone())
  7431. spawn->GetZone()->AddTransportSpawn(spawn);
  7432. return 0;
  7433. }
  7434. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7435. if (!lua_interface)
  7436. return 0;
  7437. Spawn* spawn = lua_interface->GetSpawn(state);
  7438. lua_interface->ResetFunctionStack(state);
  7439. if (!spawn) {
  7440. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7441. return 0;
  7442. }
  7443. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7444. return 1;
  7445. }
  7446. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7447. if (!lua_interface)
  7448. return 0;
  7449. Skill* skill = lua_interface->GetSkill(state);
  7450. lua_interface->ResetFunctionStack(state);
  7451. if (!skill) {
  7452. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7453. return 0;
  7454. }
  7455. lua_interface->SetInt32Value(state, skill->current_val);
  7456. return 1;
  7457. }
  7458. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7459. if (!lua_interface)
  7460. return 0;
  7461. Skill* skill = lua_interface->GetSkill(state);
  7462. lua_interface->ResetFunctionStack(state);
  7463. if (!skill) {
  7464. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7465. return 0;
  7466. }
  7467. lua_interface->SetInt32Value(state, skill->max_val);
  7468. return 1;
  7469. }
  7470. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7471. if (!lua_interface)
  7472. return 0;
  7473. Skill* skill = lua_interface->GetSkill(state);
  7474. lua_interface->ResetFunctionStack(state);
  7475. if (!skill) {
  7476. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7477. return 0;
  7478. }
  7479. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7480. return 1;
  7481. }
  7482. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7483. if (!lua_interface)
  7484. return 0;
  7485. Skill* skill = lua_interface->GetSkill(state);
  7486. int16 value = lua_interface->GetInt16Value(state, 2);
  7487. lua_interface->ResetFunctionStack(state);
  7488. if (!skill) {
  7489. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7490. return 0;
  7491. }
  7492. skill->max_val = value;
  7493. if (skill->max_val < skill->current_val)
  7494. skill->current_val = skill->max_val;
  7495. return 0;
  7496. }
  7497. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7498. if (!lua_interface)
  7499. return 0;
  7500. Skill* skill = lua_interface->GetSkill(state);
  7501. int16 value = lua_interface->GetInt16Value(state, 2);
  7502. lua_interface->ResetFunctionStack(state);
  7503. if (!skill) {
  7504. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7505. return 0;
  7506. }
  7507. if (value > skill->max_val)
  7508. skill->current_val = skill->max_val;
  7509. else
  7510. skill->current_val = value;
  7511. return 0;
  7512. }
  7513. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7514. if (!lua_interface)
  7515. return 0;
  7516. Spawn* player = lua_interface->GetSpawn(state);
  7517. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7518. lua_interface->ResetFunctionStack(state);
  7519. if (skill_id > 0 && player && player->IsPlayer()) {
  7520. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7521. return 1;
  7522. }
  7523. return 0;
  7524. }
  7525. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7526. if (!lua_interface)
  7527. return 0;
  7528. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7529. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7530. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7531. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7532. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7533. lua_interface->ResetFunctionStack(state);
  7534. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7535. if (player_spawn && player_spawn->IsPlayer()) {
  7536. Player* player = (Player*)player_spawn;
  7537. bool added = false;
  7538. if (!player->skill_list.HasSkill(skill_id)) {
  7539. player->AddSkill(skill_id, current_val, max_val, true);
  7540. added = true;
  7541. }
  7542. 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
  7543. Client* client = player->GetClient();
  7544. if (client) {
  7545. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7546. if (packet)
  7547. client->QueuePacket(packet);
  7548. }
  7549. }
  7550. if (added) {
  7551. lua_interface->SetBooleanValue(state, true);
  7552. return 1;
  7553. }
  7554. }
  7555. else {
  7556. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7557. }
  7558. }
  7559. else {
  7560. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7561. }
  7562. lua_interface->SetBooleanValue(state, false);
  7563. return 1;
  7564. }
  7565. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7566. if (!lua_interface)
  7567. return 0;
  7568. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7569. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7570. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7571. lua_interface->ResetFunctionStack(state);
  7572. if (skill_id > 0) {
  7573. if (player_spawn && player_spawn->IsPlayer()) {
  7574. Player* player = (Player*)player_spawn;
  7575. if (player->skill_list.HasSkill(skill_id)) {
  7576. player->RemovePlayerSkill(skill_id, true);
  7577. if (!more_to_remove) {
  7578. Client* client = player->GetClient();
  7579. if (client) {
  7580. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7581. if (packet)
  7582. client->QueuePacket(packet);
  7583. }
  7584. }
  7585. }
  7586. }
  7587. else {
  7588. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7589. }
  7590. }
  7591. else {
  7592. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7593. }
  7594. return 0;
  7595. }
  7596. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7597. if (!lua_interface)
  7598. return 0;
  7599. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7600. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7601. int16 amount = lua_interface->GetInt8Value(state, 3);
  7602. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7603. lua_interface->ResetFunctionStack(state);
  7604. if (amount > 0 && skill_type < 100) {
  7605. if (player_spawn && player_spawn->IsPlayer()) {
  7606. Player* player = (Player*)player_spawn;
  7607. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7608. if (!more_to_increase) {
  7609. Client* client = player->GetClient();
  7610. if (client) {
  7611. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7612. if (packet)
  7613. client->QueuePacket(packet);
  7614. }
  7615. }
  7616. }
  7617. else {
  7618. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7619. }
  7620. }
  7621. else {
  7622. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7623. }
  7624. return 0;
  7625. }
  7626. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7627. if (!lua_interface)
  7628. return 0;
  7629. Spawn* spawn = lua_interface->GetSpawn(state);
  7630. string name = lua_interface->GetStringValue(state, 2);
  7631. lua_interface->ResetFunctionStack(state);
  7632. if (!spawn) {
  7633. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7634. return 0;
  7635. }
  7636. if (!spawn->IsEntity()) {
  7637. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7638. return 0;
  7639. }
  7640. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7641. if (skill) {
  7642. lua_interface->SetSkillValue(state, skill);
  7643. return 1;
  7644. }
  7645. return 0;
  7646. }
  7647. int EQ2Emu_lua_AddProc(lua_State* state) {
  7648. if (!lua_interface)
  7649. return 0;
  7650. Spawn* spawn = lua_interface->GetSpawn(state);
  7651. int8 type = lua_interface->GetInt8Value(state, 2);
  7652. float chance = lua_interface->GetFloatValue(state, 3);
  7653. Item* item = lua_interface->GetItem(state, 4);
  7654. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7655. LuaSpell* spell = 0;
  7656. if (!item)
  7657. spell = lua_interface->GetCurrentSpell(state);
  7658. if (!spawn && (!spell || !use_all_spelltargets)) {
  7659. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7660. return 0;
  7661. }
  7662. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7663. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7664. return 0;
  7665. }
  7666. if (!item && !spell) {
  7667. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7668. return 0;
  7669. }
  7670. if(spell && spell->resisted) {
  7671. return 0;
  7672. }
  7673. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7674. Spawn* target;
  7675. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7676. for (int8 i = 0; i < spell->targets.size(); i++) {
  7677. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7678. if (!target || !target->IsEntity())
  7679. continue;
  7680. ((Entity*)target)->AddProc(type, chance, item, spell);
  7681. }
  7682. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7683. }
  7684. else
  7685. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7686. return 0;
  7687. }
  7688. int EQ2Emu_lua_AddProcExt(lua_State* state) {
  7689. if (!lua_interface)
  7690. return 0;
  7691. Spawn* spawn = lua_interface->GetSpawn(state);
  7692. int8 type = lua_interface->GetInt8Value(state, 2);
  7693. int8 damage_type = lua_interface->GetInt8Value(state, 3);
  7694. float chance = lua_interface->GetFloatValue(state, 4);
  7695. int8 hp_ratio = lua_interface->GetInt8Value(state, 5);
  7696. bool below_health = lua_interface->GetBooleanValue(state, 6);
  7697. bool target_health = lua_interface->GetBooleanValue(state, 7);
  7698. Item* item = lua_interface->GetItem(state, 8);
  7699. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 9) == 1);
  7700. bool extended_version = true;
  7701. LuaSpell* spell = 0;
  7702. if (!item)
  7703. spell = lua_interface->GetCurrentSpell(state);
  7704. if (!spawn && (!spell || !use_all_spelltargets)) {
  7705. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7706. return 0;
  7707. }
  7708. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7709. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7710. return 0;
  7711. }
  7712. if (!item && !spell) {
  7713. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7714. return 0;
  7715. }
  7716. if(spell && spell->resisted) {
  7717. return 0;
  7718. }
  7719. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7720. Spawn* target;
  7721. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7722. for (int8 i = 0; i < spell->targets.size(); i++) {
  7723. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7724. if (!target || !target->IsEntity())
  7725. continue;
  7726. ((Entity*)target)->AddProc(type, chance, item, spell, damage_type, hp_ratio, below_health, target_health, extended_version);
  7727. }
  7728. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7729. }
  7730. else
  7731. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7732. return 0;
  7733. }
  7734. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7735. if (!lua_interface)
  7736. return 0;
  7737. Spawn* spawn = lua_interface->GetSpawn(state);
  7738. Item* item = lua_interface->GetItem(state, 2);
  7739. LuaSpell* spell = 0;
  7740. if (!spawn) {
  7741. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7742. lua_interface->ResetFunctionStack(state);
  7743. return 0;
  7744. }
  7745. if (!spawn->IsEntity()) {
  7746. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7747. lua_interface->ResetFunctionStack(state);
  7748. return 0;
  7749. }
  7750. if (!item)
  7751. spell = lua_interface->GetCurrentSpell(state);
  7752. lua_interface->ResetFunctionStack(state);
  7753. if (!item && !spell) {
  7754. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7755. return 0;
  7756. }
  7757. if (spell && spell->caster && spell->caster->GetZone()) {
  7758. Spawn* target;
  7759. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7760. for (int8 i = 0; i < spell->targets.size(); i++) {
  7761. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7762. if (!target || !target->IsEntity())
  7763. continue;
  7764. ((Entity*)target)->RemoveProc(item, spell);
  7765. }
  7766. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7767. spell->caster->RemoveProc(item, spell);
  7768. }
  7769. else
  7770. ((Entity*)spawn)->RemoveProc(item, spell);
  7771. return 0;
  7772. }
  7773. int EQ2Emu_lua_Knockback(lua_State* state) {
  7774. if (!lua_interface)
  7775. return 0;
  7776. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7777. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7778. int32 duration = lua_interface->GetInt32Value(state, 3);
  7779. float vertical = lua_interface->GetFloatValue(state, 4);
  7780. float horizontal = lua_interface->GetFloatValue(state, 5);
  7781. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7782. lua_interface->ResetFunctionStack(state);
  7783. if (!target_spawn) {
  7784. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7785. return 0;
  7786. }
  7787. if (!spawn) {
  7788. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7789. return 0;
  7790. }
  7791. if ((vertical != 0 || horizontal != 0)) {
  7792. if(spawn->IsPlayer()) {
  7793. Client* client = ((Player*)spawn)->GetClient();
  7794. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7795. if (packet) {
  7796. packet->setDataByName("target_x", target_spawn->GetX());
  7797. packet->setDataByName("target_y", target_spawn->GetY());
  7798. packet->setDataByName("target_z", target_spawn->GetZ());
  7799. packet->setDataByName("vertical_movement", vertical);
  7800. packet->setDataByName("horizontal_movement", horizontal);
  7801. if (use_heading)
  7802. packet->setDataByName("use_player_heading", 1);
  7803. client->QueuePacket(packet->serialize());
  7804. }
  7805. safe_delete(packet);
  7806. }
  7807. else {
  7808. spawn->SetKnockback(target_spawn, duration, vertical, horizontal);
  7809. }
  7810. }
  7811. return 0;
  7812. }
  7813. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7814. if (!lua_interface)
  7815. return 0;
  7816. Spawn* spawn = lua_interface->GetSpawn(state);
  7817. lua_interface->ResetFunctionStack(state);
  7818. if (!spawn) {
  7819. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7820. return 0;
  7821. }
  7822. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7823. return 1;
  7824. }
  7825. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7826. if (!lua_interface)
  7827. return 0;
  7828. Spawn* caster = lua_interface->GetSpawn(state);
  7829. Spawn* target = lua_interface->GetSpawn(state, 2);
  7830. string name = lua_interface->GetStringValue(state, 3);
  7831. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7832. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7833. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7834. string success_msg = lua_interface->GetStringValue(state, 7);
  7835. string effect_msg = lua_interface->GetStringValue(state, 8);
  7836. lua_interface->ResetFunctionStack(state);
  7837. if (!caster) {
  7838. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7839. return 0;
  7840. }
  7841. if (!caster->IsEntity()) {
  7842. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. if (!target) {
  7846. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7847. return 0;
  7848. }
  7849. if (!target->IsEntity()) {
  7850. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7851. return 0;
  7852. }
  7853. if (name.length() == 0) {
  7854. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7855. return 0;
  7856. }
  7857. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7858. return 0;
  7859. }
  7860. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7861. if (!lua_interface)
  7862. return 0;
  7863. string name = lua_interface->GetStringValue(state);
  7864. lua_interface->ResetFunctionStack(state);
  7865. if (name.length() == 0) {
  7866. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7867. return 0;
  7868. }
  7869. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7870. if (!skill) {
  7871. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7872. return 0;
  7873. }
  7874. lua_interface->SetInt32Value(state, skill->skill_id);
  7875. return 1;
  7876. }
  7877. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7878. if (!lua_interface)
  7879. return 0;
  7880. Spawn* spawn = lua_interface->GetSpawn(state);
  7881. lua_interface->ResetFunctionStack(state);
  7882. if (!spawn) {
  7883. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7884. return 0;
  7885. }
  7886. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7887. return 1;
  7888. }
  7889. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7890. if (!lua_interface)
  7891. return 0;
  7892. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7893. lua_interface->ResetFunctionStack(state);
  7894. if (!luaspell) {
  7895. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7896. return 0;
  7897. }
  7898. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7899. return 1;
  7900. }
  7901. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7902. if (!lua_interface)
  7903. return 0;
  7904. Spawn* spawn = lua_interface->GetSpawn(state);
  7905. Spawn* target = lua_interface->GetSpawn(state, 2);
  7906. lua_interface->ResetFunctionStack(state);
  7907. if (!spawn) {
  7908. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7909. return 0;
  7910. }
  7911. if (!spawn->IsEntity()) {
  7912. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7913. return 0;
  7914. }
  7915. if (!target) {
  7916. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7917. return 0;
  7918. }
  7919. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7920. return 1;
  7921. }
  7922. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7923. if (!lua_interface)
  7924. return 0;
  7925. Spawn* spawn = lua_interface->GetSpawn(state);
  7926. Spawn* target = lua_interface->GetSpawn(state, 2);
  7927. lua_interface->ResetFunctionStack(state);
  7928. if (!spawn) {
  7929. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7930. return 0;
  7931. }
  7932. if (!spawn->IsEntity()) {
  7933. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7934. return 0;
  7935. }
  7936. if (!target) {
  7937. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7938. return 0;
  7939. }
  7940. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7941. return 1;
  7942. }
  7943. int EQ2Emu_lua_InFront(lua_State* state) {
  7944. if (!lua_interface)
  7945. return 0;
  7946. Spawn* spawn = lua_interface->GetSpawn(state);
  7947. Spawn* target = lua_interface->GetSpawn(state, 2);
  7948. lua_interface->ResetFunctionStack(state);
  7949. if (!spawn) {
  7950. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7951. return 0;
  7952. }
  7953. if (!spawn->IsEntity()) {
  7954. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7955. return 0;
  7956. }
  7957. if (!target) {
  7958. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  7959. return 0;
  7960. }
  7961. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  7962. return 1;
  7963. }
  7964. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7965. if (!lua_interface)
  7966. return 0;
  7967. Item* item = lua_interface->GetItem(state);
  7968. lua_interface->ResetFunctionStack(state);
  7969. if (!item) {
  7970. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7971. return 0;
  7972. }
  7973. lua_interface->SetInt32Value(state, item->details.count);
  7974. return 1;
  7975. }
  7976. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7977. if (!lua_interface)
  7978. return 0;
  7979. Item* item = lua_interface->GetItem(state);
  7980. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7981. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7982. lua_interface->ResetFunctionStack(state);
  7983. if (!item) {
  7984. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7985. return 0;
  7986. }
  7987. if (!owner) {
  7988. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7989. return 0;
  7990. }
  7991. if (!owner->IsPlayer()) {
  7992. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7993. return 0;
  7994. }
  7995. if (item->stack_count < new_count) {
  7996. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7997. return 0;
  7998. }
  7999. if (new_count > 0) {
  8000. item->details.count = new_count;
  8001. item->save_needed = true;
  8002. }
  8003. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  8004. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  8005. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  8006. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  8007. else
  8008. {
  8009. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  8010. return 0;
  8011. }
  8012. Client* client = ((Player*)owner)->GetClient();
  8013. if (!client)
  8014. return 0;
  8015. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  8016. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  8017. if (app)
  8018. client->QueuePacket(app);
  8019. return 0;
  8020. }
  8021. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  8022. if (!lua_interface)
  8023. return 0;
  8024. int32 time = lua_interface->GetInt32Value(state);
  8025. string function = lua_interface->GetStringValue(state, 2);
  8026. Spawn* caster = lua_interface->GetSpawn(state, 3);
  8027. Spawn* target = lua_interface->GetSpawn(state, 4);
  8028. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8029. lua_interface->ResetFunctionStack(state);
  8030. if (time == 0) {
  8031. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  8032. return 0;
  8033. }
  8034. if (function.length() == 0) {
  8035. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  8036. return 0;
  8037. }
  8038. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  8039. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  8040. return 0;
  8041. }
  8042. SpellScriptTimer* timer = new SpellScriptTimer;
  8043. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  8044. #ifdef WIN32
  8045. ZeroMemory(timer, sizeof(SpellScriptTimer));
  8046. #else
  8047. bzero(timer, sizeof(SpellScriptTimer));
  8048. #endif*/
  8049. timer->caster = 0;
  8050. timer->deleteWhenDone = false;
  8051. timer->target = 0;
  8052. timer->time = Timer::GetCurrentTime2() + time;
  8053. timer->customFunction = function;
  8054. timer->spell = spell;
  8055. if (caster)
  8056. timer->caster = caster->GetID();
  8057. if (target)
  8058. timer->target = target->GetID();
  8059. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8060. return 0;
  8061. }
  8062. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8063. if (!lua_interface)
  8064. return 0;
  8065. float hp_perc = lua_interface->GetFloatValue(state);
  8066. float power_perc = lua_interface->GetFloatValue(state, 2);
  8067. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8068. Spawn* target = lua_interface->GetSpawn(state, 4);
  8069. string heal_name = lua_interface->GetStringValue(state, 5);
  8070. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8071. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8072. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8073. lua_interface->ResetFunctionStack(state);
  8074. if (!spell) {
  8075. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8076. return 0;
  8077. }
  8078. Entity* caster = spell->caster;
  8079. if (!caster) {
  8080. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8081. return 0;
  8082. }
  8083. Client* client = 0;
  8084. PendingResurrection* rez = 0;
  8085. ZoneServer* zone = spell->caster->GetZone();
  8086. if (!target) {
  8087. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8088. if (spell->targets.size() > 0) {
  8089. vector<int32> spell_targets = spell->targets;
  8090. for (int8 i = 0; i < spell_targets.size(); i++) {
  8091. target = zone->GetSpawnByID(spell_targets.at(i));
  8092. if (!target)
  8093. continue;
  8094. if (!target->IsPlayer())
  8095. continue;
  8096. client = ((Player*)target)->GetClient();
  8097. if (!client)
  8098. continue;
  8099. rez = client->GetCurrentRez();
  8100. if (rez->active)
  8101. continue;
  8102. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8103. rez->active = true;
  8104. rez->caster = caster;
  8105. rez->expire_timer = new Timer;
  8106. int32 duration = spell->spell->GetSpellDuration();
  8107. rez->expire_timer->Start(duration * 100);
  8108. rez->hp_perc = hp_perc;
  8109. rez->mp_perc = power_perc;
  8110. rez->range = spell->spell->GetSpellData()->range;
  8111. rez->spell_name = spell->spell->GetName();
  8112. if (heal_name.length() > 0)
  8113. rez->heal_name = heal_name;
  8114. else
  8115. rez->heal_name = rez->spell_name;
  8116. rez->no_calcs = no_calcs;
  8117. rez->crit_mod = crit_mod;
  8118. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8119. if (send_window)
  8120. client->SendResurrectionWindow();
  8121. else {
  8122. target->GetZone()->ResurrectSpawn(target, client);
  8123. rez->should_delete = true;
  8124. }
  8125. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8126. }
  8127. }
  8128. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8129. }
  8130. else {
  8131. if(!target->IsPlayer())
  8132. return 0;
  8133. client = ((Player*)target)->GetClient();
  8134. if (!client)
  8135. return 0;
  8136. rez = client->GetCurrentRez();
  8137. if (rez->active)
  8138. return 0;
  8139. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8140. rez->active = true;
  8141. rez->caster = caster;
  8142. rez->expire_timer = new Timer;
  8143. int32 duration = spell->spell->GetSpellDuration();
  8144. rez->expire_timer->Start(duration * 100);
  8145. rez->hp_perc = hp_perc;
  8146. rez->mp_perc = power_perc;
  8147. rez->range = spell->spell->GetSpellData()->range;
  8148. rez->spell_name = spell->spell->GetName();
  8149. if (heal_name.length() > 0)
  8150. rez->heal_name = heal_name;
  8151. else
  8152. rez->heal_name = rez->spell_name;
  8153. rez->no_calcs = no_calcs;
  8154. rez->crit_mod = crit_mod;
  8155. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8156. if (send_window)
  8157. client->SendResurrectionWindow();
  8158. else {
  8159. target->GetZone()->ResurrectSpawn(target, client);
  8160. rez->should_delete = true;
  8161. }
  8162. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8163. }
  8164. return 0;
  8165. }
  8166. int EQ2Emu_lua_SetVision(lua_State* state) {
  8167. if (!lua_interface)
  8168. return 0;
  8169. Spawn* spawn = lua_interface->GetSpawn(state);
  8170. int32 vision = lua_interface->GetInt32Value(state, 2);
  8171. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8172. lua_interface->ResetFunctionStack(state);
  8173. if (!spawn) {
  8174. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8175. return 0;
  8176. }
  8177. if (!spawn->IsEntity()) {
  8178. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8179. return 0;
  8180. }
  8181. if (spell && spell->targets.size() > 0) {
  8182. ZoneServer* zone = spell->caster->GetZone();
  8183. for (int8 i = 0; i < spell->targets.size(); i++) {
  8184. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8185. if (target && target->IsEntity()) {
  8186. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8187. if (target->IsPlayer())
  8188. ((Player*)target)->SetCharSheetChanged(true);
  8189. }
  8190. }
  8191. }
  8192. else {
  8193. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8194. if (spawn->IsPlayer())
  8195. ((Player*)spawn)->SetCharSheetChanged(true);
  8196. }
  8197. return 0;
  8198. }
  8199. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8200. if (!lua_interface)
  8201. return 0;
  8202. Spawn* spawn = lua_interface->GetSpawn(state);
  8203. float intensity = lua_interface->GetFloatValue(state, 2);
  8204. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8205. lua_interface->ResetFunctionStack(state);
  8206. if (!spawn) {
  8207. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8208. return 0;
  8209. }
  8210. if (!spawn->IsEntity()) {
  8211. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8212. return 0;
  8213. }
  8214. if (spell && spell->targets.size() > 0) {
  8215. ZoneServer* zone = spell->caster->GetZone();
  8216. for (int8 i = 0; i < spell->targets.size(); i++) {
  8217. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8218. if (target && target->IsEntity()) {
  8219. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8220. if (target->IsPlayer())
  8221. ((Player*)target)->SetCharSheetChanged(true);
  8222. }
  8223. }
  8224. }
  8225. else {
  8226. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8227. if (spawn->IsPlayer())
  8228. ((Player*)spawn)->SetCharSheetChanged(true);
  8229. }
  8230. return 0;
  8231. }
  8232. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8233. if (!lua_interface)
  8234. return 0;
  8235. Spawn* spawn = lua_interface->GetSpawn(state);
  8236. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8237. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8238. lua_interface->ResetFunctionStack(state);
  8239. if (!spawn) {
  8240. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8241. return 0;
  8242. }
  8243. if (!spawn->IsEntity()) {
  8244. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. if (spell && spell->targets.size() > 0) {
  8248. ZoneServer* zone = spell->caster->GetZone();
  8249. for (int8 i = 0; i < spell->targets.size(); i++) {
  8250. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8251. if (target && target->IsEntity()) {
  8252. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8253. if (target->IsPlayer())
  8254. ((Player*)target)->SetCharSheetChanged(true);
  8255. }
  8256. }
  8257. }
  8258. else {
  8259. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8260. if (spawn->IsPlayer())
  8261. ((Player*)spawn)->SetCharSheetChanged(true);
  8262. }
  8263. return 0;
  8264. }
  8265. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8266. if (!lua_interface)
  8267. return 0;
  8268. Item* item = lua_interface->GetItem(state);
  8269. int8 type = lua_interface->GetInt32Value(state, 2);
  8270. lua_interface->ResetFunctionStack(state);
  8271. if (!item) {
  8272. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8273. return 0;
  8274. }
  8275. if (type == 1)
  8276. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8277. else if (type == 2)
  8278. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8279. return 1;
  8280. }
  8281. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8282. if (!lua_interface)
  8283. return 0;
  8284. Spawn* target = lua_interface->GetSpawn(state);
  8285. float val = lua_interface->GetFloatValue(state, 2);
  8286. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8287. lua_interface->ResetFunctionStack(state);
  8288. // Added from Gangrenous post
  8289. if (spell && spell->resisted)
  8290. return 0;
  8291. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8292. if (val > 1.0f)
  8293. val = 1.0f - (val / 100.0f);
  8294. if (spell && spell->spell && spell->targets.size() > 0) {
  8295. ZoneServer* zone = spell->caster->GetZone();
  8296. for (int32 i = 0; i != spell->targets.size(); i++) {
  8297. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8298. if (spawn && spawn->IsEntity()) {
  8299. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8300. if (spawn->IsPlayer())
  8301. ((Player*)spawn)->SetCharSheetChanged(true);
  8302. }
  8303. }
  8304. }
  8305. else {
  8306. if (target && target->IsEntity()) {
  8307. ((Entity*)target)->SetSpeedMultiplier(val);
  8308. if (target->IsPlayer())
  8309. ((Player*)target)->SetCharSheetChanged(true);
  8310. }
  8311. }
  8312. return 0;
  8313. }
  8314. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8315. if (!lua_interface)
  8316. return 0;
  8317. Spawn* spawn = lua_interface->GetSpawn(state);
  8318. int16 model = lua_interface->GetInt16Value(state, 2);
  8319. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8320. lua_interface->ResetFunctionStack(state);
  8321. if (spell && spell->spell && spell->targets.size() > 0) {
  8322. ZoneServer* zone = spell->caster->GetZone();
  8323. for (int32 i = 0; i < spell->targets.size(); i++) {
  8324. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8325. if (target)
  8326. target->SetIllusionModel(model);
  8327. }
  8328. }
  8329. else {
  8330. if (!spawn) {
  8331. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8332. return 0;
  8333. }
  8334. spawn->SetIllusionModel(model);
  8335. }
  8336. return 0;
  8337. }
  8338. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8339. if (!lua_interface)
  8340. return 0;
  8341. Spawn* spawn = lua_interface->GetSpawn(state);
  8342. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8343. lua_interface->ResetFunctionStack(state);
  8344. if (spell && spell->spell && spell->targets.size() > 0) {
  8345. ZoneServer* zone = spell->caster->GetZone();
  8346. for (int32 i = 0; i < spell->targets.size(); i++) {
  8347. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8348. if (target)
  8349. target->SetIllusionModel(0);
  8350. }
  8351. }
  8352. else {
  8353. if (!spawn) {
  8354. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8355. return 0;
  8356. }
  8357. spawn->SetIllusionModel(0);
  8358. }
  8359. return 0;
  8360. }
  8361. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8362. if (!lua_interface)
  8363. return 0;
  8364. Spawn* caster = lua_interface->GetSpawn(state);
  8365. Spawn* target = lua_interface->GetSpawn(state, 2);
  8366. float chance = lua_interface->GetFloatValue(state, 3);
  8367. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8368. lua_interface->ResetFunctionStack(state);
  8369. if (!caster) {
  8370. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8371. return 0;
  8372. }
  8373. if (!caster->IsEntity()) {
  8374. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8375. return 0;
  8376. }
  8377. if (!target) {
  8378. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8379. return 0;
  8380. }
  8381. if (!target->IsEntity()) {
  8382. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8383. return 0;
  8384. }
  8385. if (chance <= 0) {
  8386. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8387. return 0;
  8388. }
  8389. if (!spell) {
  8390. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8391. return 0;
  8392. }
  8393. if(spell->resisted) {
  8394. return 0;
  8395. }
  8396. if (((Entity*)caster)->GetThreatTransfer()) {
  8397. return 0;
  8398. }
  8399. ThreatTransfer* transfer = new ThreatTransfer;
  8400. transfer->Target = target->GetID();
  8401. transfer->Amount = chance;
  8402. transfer->Spell = spell;
  8403. ((Entity*)caster)->SetThreatTransfer(transfer);
  8404. return 0;
  8405. }
  8406. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8407. if (!lua_interface)
  8408. return 0;
  8409. Spawn* spawn = lua_interface->GetSpawn(state);
  8410. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8411. lua_interface->ResetFunctionStack(state);
  8412. if (!spawn) {
  8413. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8414. return 0;
  8415. }
  8416. if (!spell) {
  8417. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8418. return 0;
  8419. }
  8420. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8421. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8422. if(transfer && transfer->Spell != spell) {
  8423. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8424. return 0;
  8425. }
  8426. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8427. }
  8428. return 0;
  8429. }
  8430. int EQ2Emu_lua_CureByType(lua_State* state) {
  8431. if (!lua_interface)
  8432. return 0;
  8433. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8434. int8 cure_count = lua_interface->GetInt8Value(state);
  8435. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8436. string cure_name = lua_interface->GetStringValue(state, 3);
  8437. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8438. Spawn* target = lua_interface->GetSpawn(state, 5);
  8439. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8440. lua_interface->ResetFunctionStack(state);
  8441. if(spell && spell->resisted) {
  8442. return 0;
  8443. }
  8444. if (target) {
  8445. if (!target->IsEntity()) {
  8446. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8447. return 0;
  8448. }
  8449. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8450. std::string alternate_name = "item";
  8451. if(spell)
  8452. alternate_name = std::string(spell->spell->GetName());
  8453. if(!caster && spell)
  8454. caster = (Spawn*)spell->caster;
  8455. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8456. }
  8457. }
  8458. else {
  8459. ZoneServer* zone = spell->caster->GetZone();
  8460. vector<int32> targets = spell->targets;
  8461. vector<Entity*> targets_to_cure;
  8462. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8463. for (int8 i = 0; i < targets.size(); i++) {
  8464. target = zone->GetSpawnByID(targets.at(i));
  8465. if (!target || !target->IsEntity())
  8466. continue;
  8467. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8468. targets_to_cure.push_back((Entity*)target);
  8469. }
  8470. }
  8471. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8472. vector<Entity*>::iterator itr;
  8473. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8474. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8475. }
  8476. }
  8477. return 0;
  8478. }
  8479. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8480. if (!lua_interface)
  8481. return 0;
  8482. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8483. if (!spell) {
  8484. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8485. lua_interface->ResetFunctionStack(state);
  8486. return 0;
  8487. }
  8488. if(spell->resisted) {
  8489. lua_interface->ResetFunctionStack(state);
  8490. return 0;
  8491. }
  8492. int8 cure_count = lua_interface->GetInt8Value(state);
  8493. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8494. string cure_name = lua_interface->GetStringValue(state, 3);
  8495. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8496. Spawn* target = lua_interface->GetSpawn(state, 5);
  8497. lua_interface->ResetFunctionStack(state);
  8498. if (target) {
  8499. if (!target->IsEntity()) {
  8500. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8501. return 0;
  8502. }
  8503. if (((Entity*)target)->GetDetCount() > 0)
  8504. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8505. }
  8506. else {
  8507. ZoneServer* zone = spell->caster->GetZone();
  8508. vector<int32> targets = spell->targets;
  8509. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8510. for (int8 i = 0; i < targets.size(); i++) {
  8511. target = zone->GetSpawnByID(targets.at(i));
  8512. if (!target || !target->IsEntity())
  8513. continue;
  8514. if (((Entity*)target)->GetDetCount() > 0)
  8515. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8516. }
  8517. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8518. }
  8519. return 0;
  8520. }
  8521. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8522. if (!lua_interface)
  8523. return 0;
  8524. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8525. lua_interface->ResetFunctionStack(state);
  8526. if (!spell) {
  8527. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8528. return 0;
  8529. }
  8530. if (!spell->caster) {
  8531. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8532. return 0;
  8533. }
  8534. if (!spell->caster->GetZone()) {
  8535. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8539. return 0;
  8540. }
  8541. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8542. if (!lua_interface)
  8543. return 0;
  8544. Spawn* spawn = lua_interface->GetSpawn(state);
  8545. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8546. lua_interface->ResetFunctionStack(state);
  8547. if (!spell) {
  8548. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8549. return 0;
  8550. }
  8551. if (spawn && spawn->IsEntity())
  8552. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8553. else {
  8554. ZoneServer* zone = spell->caster->GetZone();
  8555. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8556. for (int32 i = 0; i < spell->targets.size(); i++) {
  8557. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8558. if (!spawn || !spawn->IsEntity())
  8559. continue;
  8560. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8561. }
  8562. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8563. }
  8564. return 0;
  8565. }
  8566. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8567. if (!lua_interface)
  8568. return 0;
  8569. Spawn* spawn = lua_interface->GetSpawn(state);
  8570. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8571. lua_interface->ResetFunctionStack(state);
  8572. if (!spell) {
  8573. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8574. return 0;
  8575. }
  8576. if (spawn && spawn->IsEntity())
  8577. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8578. else {
  8579. ZoneServer* zone = spell->caster->GetZone();
  8580. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8581. for (int32 i = 0; i < spell->targets.size(); i++) {
  8582. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8583. if (!spawn || !spawn->IsEntity())
  8584. continue;
  8585. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8586. }
  8587. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8588. }
  8589. return 0;
  8590. }
  8591. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8592. if (!lua_interface)
  8593. return 0;
  8594. Spawn* caster = lua_interface->GetSpawn(state);
  8595. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8596. lua_interface->ResetFunctionStack(state);
  8597. if (!caster) {
  8598. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8599. return 0;
  8600. }
  8601. if (!caster->IsPlayer()) {
  8602. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8603. return 0;
  8604. }
  8605. Spawn* target = caster->GetTarget();
  8606. if (!target) {
  8607. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8608. return 0;
  8609. }
  8610. Client* client = ((Player*)caster)->GetClient();
  8611. if (!client) {
  8612. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8613. return 0;
  8614. }
  8615. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8616. if (ho) {
  8617. ho->SetTarget(target->GetID());
  8618. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8619. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8620. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8621. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8622. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8623. deque<GroupMemberInfo*>::iterator itr;
  8624. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8625. if (group)
  8626. {
  8627. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8628. deque<GroupMemberInfo*>* members = group->GetMembers();
  8629. for (itr = members->begin(); itr != members->end(); itr++) {
  8630. if ((*itr)->client)
  8631. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8632. }
  8633. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8634. }
  8635. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8636. }
  8637. else
  8638. safe_delete(ho);
  8639. }
  8640. else {
  8641. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8642. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8643. }
  8644. else
  8645. safe_delete(ho);
  8646. }
  8647. }
  8648. return 0;
  8649. }
  8650. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8651. if (!lua_interface)
  8652. return 0;
  8653. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8654. if (!spell) {
  8655. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8656. return 0;
  8657. }
  8658. int16 triggerCount = lua_interface->GetInt16Value(state);
  8659. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8660. if (!triggerCount) {
  8661. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8662. return 0;
  8663. }
  8664. spell->num_triggers = triggerCount;
  8665. spell->had_triggers = true;
  8666. spell->cancel_after_all_triggers = cancel_after_triggers;
  8667. return 0;
  8668. }
  8669. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8670. if (!lua_interface)
  8671. return 0;
  8672. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8673. lua_interface->ResetFunctionStack(state);
  8674. if (!spell) {
  8675. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8676. return 0;
  8677. }
  8678. lua_interface->SetInt32Value(state, spell->num_triggers);
  8679. return 1;
  8680. }
  8681. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8682. if (!lua_interface)
  8683. return 0;
  8684. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8685. if (!spell) {
  8686. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8687. lua_interface->ResetFunctionStack(state);
  8688. return 0;
  8689. }
  8690. if (!spell->caster || !spell->caster->GetZone()) {
  8691. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8692. lua_interface->ResetFunctionStack(state);
  8693. return 0;
  8694. }
  8695. int16 remove_count = lua_interface->GetInt16Value(state);
  8696. lua_interface->ResetFunctionStack(state);
  8697. if (!remove_count)
  8698. remove_count = 1;
  8699. if (remove_count >= spell->num_triggers) {
  8700. spell->num_triggers = 0;
  8701. if (spell->cancel_after_all_triggers)
  8702. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8703. }
  8704. else {
  8705. spell->num_triggers -= remove_count;
  8706. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8707. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8708. }
  8709. return 0;
  8710. }
  8711. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8712. if (!lua_interface)
  8713. return 0;
  8714. Spawn* spawn = lua_interface->GetSpawn(state);
  8715. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8716. lua_interface->ResetFunctionStack(state);
  8717. if (!spawn) {
  8718. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8719. return 0;
  8720. }
  8721. if (!copy_spawn) {
  8722. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8723. return 0;
  8724. }
  8725. spawn->CopySpawnAppearance(copy_spawn);
  8726. return 0;
  8727. }
  8728. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8729. Spawn* spawn = lua_interface->GetSpawn(state);
  8730. int8 type = lua_interface->GetInt8Value(state, 2);
  8731. lua_interface->ResetFunctionStack(state);
  8732. if (!spawn) {
  8733. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8734. return 0;
  8735. }
  8736. else if (!spawn->IsEntity()) {
  8737. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8738. return 0;
  8739. }
  8740. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8741. return 1;
  8742. }
  8743. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8744. if (!lua_interface)
  8745. return 0;
  8746. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8747. int8 type = lua_interface->GetInt8Value(state);
  8748. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8749. lua_interface->ResetFunctionStack(state);
  8750. if (!spell) {
  8751. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8752. return 0;
  8753. }
  8754. if(spell->resisted) {
  8755. return 0;
  8756. }
  8757. if (spawn) {
  8758. if (!spawn->IsEntity()) {
  8759. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8760. return 0;
  8761. }
  8762. Entity* entity = ((Entity*)spawn);
  8763. entity->AddImmunity(spell, type);
  8764. }
  8765. else if(spell->caster && spell->caster->GetZone()) {
  8766. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8767. for (int8 i = 0; i < spell->targets.size(); i++) {
  8768. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8769. if (!spawn || !spawn->IsEntity())
  8770. continue;
  8771. Entity* entity = ((Entity*)spawn);
  8772. entity->AddImmunity(spell, type);
  8773. }
  8774. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8775. }
  8776. return 0;
  8777. }
  8778. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8779. if (!lua_interface)
  8780. return 0;
  8781. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8782. int8 type = lua_interface->GetInt8Value(state);
  8783. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8784. lua_interface->ResetFunctionStack(state);
  8785. if (!spell) {
  8786. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8787. return 0;
  8788. }
  8789. if (spawn) {
  8790. if (!spawn->IsEntity()) {
  8791. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8792. return 0;
  8793. }
  8794. Entity* entity = ((Entity*)spawn);
  8795. entity->RemoveImmunity(spell, type);
  8796. }
  8797. else if(spell->caster && spell->caster->GetZone()) {
  8798. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8799. for (int8 i = 0; i < spell->targets.size(); i++) {
  8800. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8801. if (!spawn || !spawn->IsEntity())
  8802. continue;
  8803. Entity* entity = ((Entity*)spawn);
  8804. entity->RemoveImmunity(spell, type);
  8805. }
  8806. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8807. }
  8808. return 0;
  8809. }
  8810. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8811. if (!lua_interface)
  8812. return 0;
  8813. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8814. if (!spell) {
  8815. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8816. lua_interface->ResetFunctionStack(state);
  8817. return 0;
  8818. }
  8819. if(spell->resisted) {
  8820. lua_interface->ResetFunctionStack(state);
  8821. return 0;
  8822. }
  8823. float snare = lua_interface->GetFloatValue(state);
  8824. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8825. lua_interface->ResetFunctionStack(state);
  8826. // convert the val to the speed multipler value (100 - val)
  8827. float val = 100.0 - snare;
  8828. val /= 100.0;
  8829. if (spawn) {
  8830. if (!spawn->IsEntity()) {
  8831. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8832. return 0;
  8833. }
  8834. ((Entity*)spawn)->SetSnareValue(spell, val);
  8835. }
  8836. else if(spell->caster && spell->caster->GetZone()) {
  8837. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8838. for (int8 i = 0; i < spell->targets.size(); i++) {
  8839. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8840. if (!spawn || !spawn->IsEntity())
  8841. continue;
  8842. ((Entity*)spawn)->SetSnareValue(spell, val);
  8843. }
  8844. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8845. }
  8846. return 0;
  8847. }
  8848. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8849. if (!lua_interface)
  8850. return 0;
  8851. Spawn* spawn = lua_interface->GetSpawn(state);
  8852. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8853. lua_interface->ResetFunctionStack(state);
  8854. if (!spawn) {
  8855. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8856. return 0;
  8857. }
  8858. if (race_id == 0) {
  8859. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8860. return 0;
  8861. }
  8862. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8863. return 1;
  8864. }
  8865. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8866. if (!lua_interface)
  8867. return 0;
  8868. Spawn* spawn = lua_interface->GetSpawn(state);
  8869. lua_interface->ResetFunctionStack(state);
  8870. if (!spawn) {
  8871. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8872. return 0;
  8873. }
  8874. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8875. return 1;
  8876. }
  8877. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8878. if (!lua_interface)
  8879. return 0;
  8880. Spawn* spawn = lua_interface->GetSpawn(state);
  8881. lua_interface->ResetFunctionStack(state);
  8882. if (!spawn) {
  8883. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8884. return 0;
  8885. }
  8886. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8887. return 1;
  8888. }
  8889. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8890. if (!lua_interface)
  8891. return 0;
  8892. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8893. lua_interface->ResetFunctionStack(state);
  8894. if (!spell) {
  8895. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8896. return 0;
  8897. }
  8898. lua_interface->SetStringValue(state, spell->spell->GetName());
  8899. return 1;
  8900. }
  8901. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8902. if (!lua_interface)
  8903. return 0;
  8904. Quest* quest = lua_interface->GetQuest(state);
  8905. lua_interface->ResetFunctionStack(state);
  8906. if (!quest) {
  8907. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8908. return 0;
  8909. }
  8910. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8911. return 1;
  8912. }
  8913. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8914. if (!lua_interface)
  8915. return 0;
  8916. Quest* quest = lua_interface->GetQuest(state);
  8917. int32 flags = lua_interface->GetInt32Value(state, 2);
  8918. lua_interface->ResetFunctionStack(state);
  8919. if (!quest) {
  8920. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8921. return 0;
  8922. }
  8923. quest->SetQuestFlags(flags);
  8924. return 0;
  8925. }
  8926. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8927. if (!lua_interface)
  8928. return 0;
  8929. Quest* quest = lua_interface->GetQuest(state);
  8930. Spawn* player = lua_interface->GetSpawn(state, 2);
  8931. int32 step = lua_interface->GetInt32Value(state, 3);
  8932. int32 duration = lua_interface->GetInt32Value(state, 4);
  8933. string action = lua_interface->GetStringValue(state, 5);
  8934. lua_interface->ResetFunctionStack(state);
  8935. if (!quest) {
  8936. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8937. return 0;
  8938. }
  8939. if (!player) {
  8940. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8941. return 0;
  8942. }
  8943. if (!player->IsPlayer()) {
  8944. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8945. return 0;
  8946. }
  8947. if (step == 0) {
  8948. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8949. return 0;
  8950. }
  8951. if (duration == 0) {
  8952. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8953. return 0;
  8954. }
  8955. if (action.length() == 0) {
  8956. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8957. return 0;
  8958. }
  8959. Client* client = ((Player*)player)->GetClient();
  8960. if (!client) {
  8961. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8962. return 0;
  8963. }
  8964. quest->SetTimerStep(step);
  8965. quest->AddFailedAction(step, action);
  8966. quest->SetStepTimer(duration);
  8967. client->AddQuestTimer(quest->GetQuestID());
  8968. return 0;
  8969. }
  8970. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8971. if (!lua_interface)
  8972. return 0;
  8973. Quest* quest = lua_interface->GetQuest(state);
  8974. Spawn* player = lua_interface->GetSpawn(state, 2);
  8975. lua_interface->ResetFunctionStack(state);
  8976. if (!quest) {
  8977. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8978. return 0;
  8979. }
  8980. if (!player) {
  8981. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8982. return 0;
  8983. }
  8984. if (!player->IsPlayer()) {
  8985. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8986. return 0;
  8987. }
  8988. Client* client = ((Player*)player)->GetClient();
  8989. if (!client) {
  8990. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8991. return 0;
  8992. }
  8993. quest->SetTimerStep(0);
  8994. quest->SetStepTimer(0);
  8995. client->RemoveQuestTimer(quest->GetQuestID());
  8996. return 0;
  8997. }
  8998. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8999. if (!lua_interface)
  9000. return 0;
  9001. Spawn* player = lua_interface->GetSpawn(state);
  9002. Quest* quest = lua_interface->GetQuest(state, 2);
  9003. int32 step = lua_interface->GetInt32Value(state, 3);
  9004. lua_interface->ResetFunctionStack(state);
  9005. if (!player) {
  9006. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9007. return 0;
  9008. }
  9009. if (!player->IsPlayer()) {
  9010. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9011. return 0;
  9012. }
  9013. if (!quest) {
  9014. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9015. return 0;
  9016. }
  9017. if (step == 0) {
  9018. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9019. return 0;
  9020. }
  9021. Client* client = ((Player*)player)->GetClient();
  9022. if (!client) {
  9023. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  9024. return 0;
  9025. }
  9026. if (quest->RemoveQuestStep(step, client)) {
  9027. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  9028. client->GetCurrentZone()->SendQuestUpdates(client);
  9029. }
  9030. else
  9031. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  9032. return 0;
  9033. }
  9034. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  9035. if (!lua_interface)
  9036. return 0;
  9037. Quest* quest = lua_interface->GetQuest(state, 1);
  9038. int32 step = lua_interface->GetInt32Value(state, 2);
  9039. string desc = lua_interface->GetStringValue(state, 3);
  9040. string task_group = lua_interface->GetStringValue(state, 4);
  9041. lua_interface->ResetFunctionStack(state);
  9042. if (!quest) {
  9043. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9044. return 0;
  9045. }
  9046. if (step == 0) {
  9047. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9048. return 0;
  9049. }
  9050. QuestStep* quest_step = quest->GetQuestStep(step);
  9051. if (!quest_step) {
  9052. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  9053. return 0;
  9054. }
  9055. quest_step->SetStepProgress(0);
  9056. quest_step->SetTaskGroup(task_group);
  9057. quest_step->SetDescription(desc);
  9058. return 0;
  9059. }
  9060. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9061. if (!lua_interface)
  9062. return 0;
  9063. Quest* quest = lua_interface->GetQuest(state);
  9064. int32 step = lua_interface->GetInt32Value(state, 2);
  9065. string action = lua_interface->GetStringValue(state, 3);
  9066. lua_interface->ResetFunctionStack(state);
  9067. if (!quest) {
  9068. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9069. return 0;
  9070. }
  9071. if (step == 0) {
  9072. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9073. return 0;
  9074. }
  9075. if (action.length() == 0) {
  9076. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9077. return 0;
  9078. }
  9079. quest->AddFailedAction(step, action);
  9080. return 0;
  9081. }
  9082. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9083. if (!lua_interface)
  9084. return 0;
  9085. Spawn* player = lua_interface->GetSpawn(state);
  9086. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9087. int32 step = lua_interface->GetInt32Value(state, 3);
  9088. lua_interface->ResetFunctionStack(state);
  9089. if (!player) {
  9090. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9091. return 0;
  9092. }
  9093. if (!player->IsPlayer()) {
  9094. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9095. return 0;
  9096. }
  9097. if (quest_id == 0) {
  9098. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9099. return 0;
  9100. }
  9101. if (step == 0) {
  9102. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9103. return 0;
  9104. }
  9105. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9106. if (!quest) {
  9107. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9108. return 0;
  9109. }
  9110. quest->StepFailed(step);
  9111. return 0;
  9112. }
  9113. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9114. if (!lua_interface)
  9115. return 0;
  9116. Spawn* player = lua_interface->GetSpawn(state);
  9117. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9118. lua_interface->ResetFunctionStack(state);
  9119. if (!player) {
  9120. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9121. return 0;
  9122. }
  9123. if (!player->IsPlayer()) {
  9124. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9125. return 0;
  9126. }
  9127. if (quest_id == 0) {
  9128. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9129. return 0;
  9130. }
  9131. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9132. return 1;
  9133. }
  9134. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9135. if (!lua_interface)
  9136. return 0;
  9137. string name = lua_interface->GetStringValue(state);
  9138. string value = lua_interface->GetStringValue(state, 2);
  9139. string comment = lua_interface->GetStringValue(state, 3);
  9140. lua_interface->ResetFunctionStack(state);
  9141. if (name.length() == 0) {
  9142. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9143. return 0;
  9144. }
  9145. if (value.length() == 0) {
  9146. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9147. return 0;
  9148. }
  9149. string varname = string("lua_").append(name);
  9150. Variable* var = variables.FindVariable(varname);
  9151. if (var)
  9152. var->SetValue(value.c_str());
  9153. else {
  9154. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9155. variables.AddVariable(var);
  9156. }
  9157. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9158. return 0;
  9159. }
  9160. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9161. if (!lua_interface)
  9162. return 0;
  9163. string name = lua_interface->GetStringValue(state);
  9164. lua_interface->ResetFunctionStack(state);
  9165. if (name.length() == 0) {
  9166. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9167. return 0;
  9168. }
  9169. string varname = string("lua_").append(name);
  9170. Variable* var = variables.FindVariable(varname);
  9171. if (var)
  9172. lua_interface->SetStringValue(state, var->GetValue());
  9173. else
  9174. lua_interface->SetStringValue(state, "NULL");
  9175. return 1;
  9176. }
  9177. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9178. if (!lua_interface)
  9179. return 0;
  9180. Spawn* player = lua_interface->GetSpawn(state);
  9181. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9182. lua_interface->ResetFunctionStack(state);
  9183. if (!player) {
  9184. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9185. return 0;
  9186. }
  9187. if (!player->IsPlayer()) {
  9188. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9189. return 0;
  9190. }
  9191. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9192. return 1;
  9193. }
  9194. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9195. if (!lua_interface)
  9196. return 0;
  9197. Spawn* player = lua_interface->GetSpawn(state);
  9198. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9199. lua_interface->ResetFunctionStack(state);
  9200. if (!player) {
  9201. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9202. return 0;
  9203. }
  9204. if (!player->IsPlayer()) {
  9205. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9206. return 0;
  9207. }
  9208. Language* language = master_languages_list.GetLanguage(language_id);
  9209. if (language)
  9210. {
  9211. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9212. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9213. }
  9214. return 0;
  9215. }
  9216. int EQ2Emu_lua_IsNight(lua_State* state) {
  9217. if (!lua_interface)
  9218. return 0;
  9219. ZoneServer* zone = lua_interface->GetZone(state);
  9220. lua_interface->ResetFunctionStack(state);
  9221. if (!zone) {
  9222. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9223. return 0;
  9224. }
  9225. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9226. return 1;
  9227. }
  9228. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9229. if (!lua_interface)
  9230. return 0;
  9231. Spawn* spawn = lua_interface->GetSpawn(state);
  9232. lua_interface->ResetFunctionStack(state);
  9233. if (!spawn) {
  9234. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9235. return 0;
  9236. }
  9237. if (!spawn->IsWidget()) {
  9238. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9239. return 0;
  9240. }
  9241. ((Widget*)spawn)->SetMultiFloorLift(true);
  9242. if (spawn->GetZone())
  9243. spawn->GetZone()->AddTransportSpawn(spawn);
  9244. return 0;
  9245. }
  9246. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9247. if (!lua_interface)
  9248. return 0;
  9249. Spawn* player = lua_interface->GetSpawn(state);
  9250. int32 path = lua_interface->GetInt32Value(state, 2);
  9251. lua_interface->ResetFunctionStack(state);
  9252. if (!player) {
  9253. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9254. return 0;
  9255. }
  9256. if (!player->IsPlayer()) {
  9257. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9258. return 0;
  9259. }
  9260. if (path == 0) {
  9261. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9262. return 0;
  9263. }
  9264. Client* client = ((Player*)player)->GetClient();
  9265. if (!client) {
  9266. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9267. return 0;
  9268. }
  9269. client->SendFlightAutoMount(path);
  9270. return 0;
  9271. }
  9272. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9273. if (!lua_interface)
  9274. return 0;
  9275. Spawn* player = lua_interface->GetSpawn(state);
  9276. if (!player) {
  9277. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9278. return 0;
  9279. }
  9280. if (!player->IsPlayer()) {
  9281. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9282. return 0;
  9283. }
  9284. Client* client = ((Player*)player)->GetClient();
  9285. if (!client) {
  9286. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9287. return 0;
  9288. }
  9289. client->EndAutoMount();
  9290. return 0;
  9291. }
  9292. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9293. if (!lua_interface)
  9294. return 0;
  9295. Spawn* player = lua_interface->GetSpawn(state);
  9296. lua_interface->ResetFunctionStack(state);
  9297. if (!player) {
  9298. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9299. return 0;
  9300. }
  9301. if (!player->IsPlayer()) {
  9302. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9303. return 0;
  9304. }
  9305. Client* client = ((Player*)player)->GetClient();
  9306. if (!client) {
  9307. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9308. return 0;
  9309. }
  9310. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9311. return 1;
  9312. }
  9313. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9314. if (!lua_interface)
  9315. return 0;
  9316. Spawn* player = lua_interface->GetSpawn(state);
  9317. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9318. int32 value = lua_interface->GetInt32Value(state, 3);
  9319. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9320. lua_interface->ResetFunctionStack(state);
  9321. if (!player) {
  9322. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9323. return 0;
  9324. }
  9325. if (!player->IsPlayer()) {
  9326. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9327. return 0;
  9328. }
  9329. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9330. return 0;
  9331. }
  9332. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9333. if (!lua_interface)
  9334. return 0;
  9335. Spawn* player = lua_interface->GetSpawn(state);
  9336. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9337. lua_interface->ResetFunctionStack(state);
  9338. if (!player) {
  9339. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9340. return 0;
  9341. }
  9342. if (!player->IsPlayer()) {
  9343. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9344. return 0;
  9345. }
  9346. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9347. if (!hd)
  9348. return 0;
  9349. lua_interface->SetInt32Value(state, hd->Value);
  9350. lua_interface->SetInt32Value(state, hd->Value2);
  9351. return 2;
  9352. }
  9353. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9354. if (!lua_interface)
  9355. return 0;
  9356. Spawn* spawn = lua_interface->GetSpawn(state);
  9357. int32 grid = lua_interface->GetInt32Value(state, 2);
  9358. lua_interface->ResetFunctionStack(state);
  9359. if (!spawn) {
  9360. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9361. return 0;
  9362. }
  9363. if (grid == 0) {
  9364. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9365. return 0;
  9366. }
  9367. spawn->SetLocation(grid);
  9368. return 0;
  9369. }
  9370. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9371. if (!lua_interface)
  9372. return 0;
  9373. Spawn* spawn = lua_interface->GetSpawn(state);
  9374. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9375. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9376. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9377. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9378. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9379. lua_interface->ResetFunctionStack(state);
  9380. if (!spawn) {
  9381. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9382. return 0;
  9383. }
  9384. //Add this quest to the list of required quests for this spawn
  9385. spawn->SetRequiredHistory(event_id, value1, value2);
  9386. //If private spawn value set
  9387. if (private_spawn) {
  9388. //Set the spawn to be private when not granted access via history
  9389. spawn->AddAllowAccessSpawn(spawn);
  9390. spawn->SetPrivateQuestSpawn(true);
  9391. }
  9392. //This value will override vis_flags in the vis packet
  9393. if (flag_override > 0)
  9394. spawn->SetQuestsRequiredOverride(flag_override);
  9395. return 0;
  9396. }
  9397. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9398. if (!lua_interface)
  9399. return 0;
  9400. Spawn* player = lua_interface->GetSpawn(state);
  9401. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9402. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9403. lua_interface->ResetFunctionStack(state);
  9404. if (!player) {
  9405. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9406. return 0;
  9407. }
  9408. if (!player->IsPlayer()) {
  9409. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9410. return 0;
  9411. }
  9412. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9413. return 1;
  9414. }
  9415. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9416. if (!lua_interface)
  9417. return 0;
  9418. Spawn* player = lua_interface->GetSpawn(state);
  9419. int8 level = lua_interface->GetInt8Value(state, 2);
  9420. lua_interface->ResetFunctionStack(state);
  9421. if (!player) {
  9422. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9423. return 0;
  9424. }
  9425. if (!player->IsPlayer()) {
  9426. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9427. return 0;
  9428. }
  9429. if (level == 0) {
  9430. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9431. return 0;
  9432. }
  9433. Client* client = ((Player*)player)->GetClient();
  9434. if (!client) {
  9435. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9436. return 0;
  9437. }
  9438. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9439. return 0;
  9440. }
  9441. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9442. if (!lua_interface)
  9443. return 0;
  9444. Spawn* player = lua_interface->GetSpawn(state);
  9445. int32 amount = lua_interface->GetInt32Value(state, 2);
  9446. lua_interface->ResetFunctionStack(state);
  9447. if (!player) {
  9448. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9449. return 0;
  9450. }
  9451. if (!player->IsPlayer()) {
  9452. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9453. return 0;
  9454. }
  9455. if (amount == 0) {
  9456. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9457. return 0;
  9458. }
  9459. ((Player*)player)->AddCoins(amount);
  9460. return 0;
  9461. }
  9462. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9463. if (!lua_interface)
  9464. return 0;
  9465. Spawn* player = lua_interface->GetSpawn(state);
  9466. int32 amount = lua_interface->GetInt32Value(state, 2);
  9467. lua_interface->ResetFunctionStack(state);
  9468. if (!player) {
  9469. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9470. return 0;
  9471. }
  9472. if (!player->IsPlayer()) {
  9473. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9474. return 0;
  9475. }
  9476. if (amount == 0) {
  9477. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9478. return 0;
  9479. }
  9480. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9481. return 1;
  9482. }
  9483. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9484. if (!lua_interface)
  9485. return 0;
  9486. ZoneServer* zone = lua_interface->GetZone(state);
  9487. lua_interface->ResetFunctionStack(state);
  9488. if (!zone) {
  9489. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9490. return 0;
  9491. }
  9492. vector<Entity*> players = zone->GetPlayers();
  9493. if (players.size() == 0)
  9494. return 0;
  9495. lua_createtable(state, players.size(), 0);
  9496. int newTable = lua_gettop(state);
  9497. for (int32 i = 0; i < players.size(); i++) {
  9498. lua_interface->SetSpawnValue(state, players.at(i));
  9499. lua_rawseti(state, newTable, i + 1);
  9500. }
  9501. return 1;
  9502. }
  9503. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9504. if (!lua_interface)
  9505. return 0;
  9506. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9507. if (!zone) {
  9508. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9509. return 0;
  9510. }
  9511. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9512. int16 custom_level = lua_interface->GetInt32Value(state, 3);
  9513. lua_interface->ResetFunctionStack(state);
  9514. //Map of <placement_id, location_id>
  9515. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9516. map<int32, int32>::iterator itr;
  9517. vector<Spawn*> group;
  9518. Spawn* leader = 0;
  9519. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9520. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9521. if (!location) {
  9522. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9523. return 0;
  9524. }
  9525. Spawn* spawn = 0;
  9526. if (location->entities[0]) {
  9527. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9528. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9529. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9530. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9531. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9532. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9533. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9534. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9535. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9536. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9537. if(spawn && spawn->IsOmittedByDBFlag())
  9538. {
  9539. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  9540. safe_delete(spawn);
  9541. continue;
  9542. }
  9543. if (spawn) {
  9544. if(!leader)
  9545. leader = spawn;
  9546. if(leader)
  9547. leader->AddSpawnToGroup(spawn);
  9548. spawn->SetSpawnGroupID(group_id);
  9549. if(custom_level > 0 && custom_level != 0xFFFF) {
  9550. spawn->SetLevel(custom_level);
  9551. }
  9552. const char* script = 0;
  9553. for (int x = 0; x < 3; x++) {
  9554. switch (x) {
  9555. case 0:
  9556. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9557. break;
  9558. case 1:
  9559. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9560. break;
  9561. case 2:
  9562. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9563. break;
  9564. }
  9565. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9566. spawn->SetSpawnScript(string(script));
  9567. break;
  9568. }
  9569. }
  9570. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9571. lua_interface->SetSpawnValue(state, spawn);
  9572. group.push_back(spawn);
  9573. }
  9574. else {
  9575. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9576. safe_delete(spawn);
  9577. }
  9578. }
  9579. }
  9580. if (!group.empty()) {
  9581. lua_createtable(state, group.size(), 0);
  9582. int newTable = lua_gettop(state);
  9583. for (int32 i = 0; i < group.size(); i++) {
  9584. lua_interface->SetSpawnValue(state, group[i]);
  9585. lua_rawseti(state, newTable, i + 1);
  9586. }
  9587. }
  9588. else
  9589. lua_pushnil(state);
  9590. return 1;
  9591. }
  9592. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9593. if (!lua_interface)
  9594. return 0;
  9595. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9596. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9597. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9598. lua_interface->ResetFunctionStack(state);
  9599. if (!spawn) {
  9600. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9601. return 0;
  9602. }
  9603. if (anim_id == 0) {
  9604. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9605. return 0;
  9606. }
  9607. if (leeway == 0)
  9608. leeway = 5000;
  9609. spawn->SetSpawnAnim(anim_id);
  9610. spawn->SetSpawnAnimLeeway(leeway);
  9611. return 0;
  9612. }
  9613. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9614. if (!lua_interface)
  9615. return 0;
  9616. Spawn* player = lua_interface->GetSpawn(state);
  9617. lua_interface->ResetFunctionStack(state);
  9618. if (!player || !player->IsPlayer()) {
  9619. return 0;
  9620. }
  9621. Client* client = ((Player*)player)->GetClient();
  9622. if (!client) {
  9623. return 0;
  9624. }
  9625. lua_interface->SetInt32Value(state, client->GetVersion());
  9626. return 1;
  9627. }
  9628. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9629. if (!lua_interface)
  9630. return 0;
  9631. Item* item = lua_interface->GetItem(state);
  9632. lua_interface->ResetFunctionStack(state);
  9633. if (!item) {
  9634. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9635. return 0;
  9636. }
  9637. lua_interface->SetInt32Value(state, item->details.item_id);
  9638. return 1;
  9639. }
  9640. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9641. if (!lua_interface)
  9642. return 0;
  9643. Spawn* spawn = lua_interface->GetSpawn(state);
  9644. lua_interface->ResetFunctionStack(state);
  9645. if (!spawn) {
  9646. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9647. return 0;
  9648. }
  9649. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9650. return 1;
  9651. }
  9652. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9653. if (!lua_interface)
  9654. return 0;
  9655. Spawn* spawn = lua_interface->GetSpawn(state);
  9656. lua_interface->ResetFunctionStack(state);
  9657. if (!spawn) {
  9658. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9659. return 0;
  9660. }
  9661. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9662. return 1;
  9663. }
  9664. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9665. if (!lua_interface)
  9666. return 0;
  9667. Spawn* spawn = lua_interface->GetSpawn(state);
  9668. lua_interface->ResetFunctionStack(state);
  9669. if (!spawn) {
  9670. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9671. return 0;
  9672. }
  9673. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9674. return 1;
  9675. }
  9676. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9677. if (!lua_interface)
  9678. return 0;
  9679. Spawn* spawn = lua_interface->GetSpawn(state);
  9680. lua_interface->ResetFunctionStack(state);
  9681. if (!spawn) {
  9682. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9683. return 0;
  9684. }
  9685. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9686. return 1;
  9687. }
  9688. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9689. if (!lua_interface)
  9690. return 0;
  9691. Spawn* spawn = lua_interface->GetSpawn(state);
  9692. float pct = lua_interface->GetFloatValue(state, 2);
  9693. lua_interface->ResetFunctionStack(state);
  9694. if (!spawn) {
  9695. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9696. return 0;
  9697. }
  9698. if (pct == 0) {
  9699. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9700. return 0;
  9701. }
  9702. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9703. lua_interface->SetInt32Value(state, amount);
  9704. return 1;
  9705. }
  9706. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9707. if (!lua_interface)
  9708. return 0;
  9709. Spawn* spawn = lua_interface->GetSpawn(state);
  9710. float pct = lua_interface->GetFloatValue(state, 2);
  9711. lua_interface->ResetFunctionStack(state);
  9712. if (!spawn) {
  9713. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9714. return 0;
  9715. }
  9716. if (pct == 0) {
  9717. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9718. return 0;
  9719. }
  9720. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9721. lua_interface->SetInt32Value(state, amount);
  9722. return 1;
  9723. }
  9724. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9725. if (!lua_interface)
  9726. return 0;
  9727. Spawn* spawn = lua_interface->GetSpawn(state);
  9728. lua_interface->ResetFunctionStack(state);
  9729. if (!spawn) {
  9730. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9731. return 0;
  9732. }
  9733. if (!spawn->IsPlayer()) {
  9734. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9735. return 0;
  9736. }
  9737. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9738. return 1;
  9739. }
  9740. int EQ2Emu_lua_Evac(lua_State* state) {
  9741. if (!lua_interface)
  9742. return 0;
  9743. Spawn* target = lua_interface->GetSpawn(state);
  9744. if (target) {
  9745. float x = target->GetZone()->GetSafeX();
  9746. float y = target->GetZone()->GetSafeY();
  9747. float z = target->GetZone()->GetSafeZ();
  9748. float h = target->GetZone()->GetSafeHeading();
  9749. target->SetX(x);
  9750. target->SetY(y);
  9751. target->SetZ(z);
  9752. target->SetHeading(h);
  9753. target->SetSpawnOrigX(x);
  9754. target->SetSpawnOrigY(y);
  9755. target->SetSpawnOrigZ(z);
  9756. target->SetSpawnOrigHeading(h);
  9757. if (target->IsPlayer()) {
  9758. Client* client = ((Player*)target)->GetClient();
  9759. if (client) {
  9760. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9761. int numargs = lua_interface->GetNumberOfArgs(state);
  9762. if(numargs == 4) {
  9763. x = lua_interface->GetFloatValue(state,1);
  9764. y = lua_interface->GetFloatValue(state,2);
  9765. z = lua_interface->GetFloatValue(state,3);
  9766. h = lua_interface->GetFloatValue(state,4);
  9767. }
  9768. client->SetReloadingZone(true);
  9769. target->SetX(x);
  9770. target->SetY(y);
  9771. target->SetZ(z);
  9772. target->SetHeading(h);
  9773. target->SetSpawnOrigX(x);
  9774. target->SetSpawnOrigY(y);
  9775. target->SetSpawnOrigZ(z);
  9776. target->SetSpawnOrigHeading(h);
  9777. target->SetAppearancePosition(x,y,z);
  9778. client->SetZoningCoords(x,y,z,h);
  9779. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9780. if (packet)
  9781. {
  9782. packet->setDataByName("x", x);
  9783. packet->setDataByName("y", y);
  9784. packet->setDataByName("z", z);
  9785. client->QueuePacket(packet->serialize());
  9786. safe_delete(packet);
  9787. }
  9788. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9789. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9790. }
  9791. }
  9792. lua_interface->ResetFunctionStack(state);
  9793. }
  9794. else {
  9795. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9796. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9797. lua_interface->ResetFunctionStack(state);
  9798. return 0;
  9799. }
  9800. ZoneServer* zone = spell->caster->GetZone();
  9801. float x = spell->caster->GetZone()->GetSafeX();
  9802. float y = spell->caster->GetZone()->GetSafeY();
  9803. float z = spell->caster->GetZone()->GetSafeZ();
  9804. float h = spell->caster->GetZone()->GetSafeHeading();
  9805. int numargs = lua_interface->GetNumberOfArgs(state);
  9806. if(numargs == 4) {
  9807. x = lua_interface->GetFloatValue(state,1);
  9808. y = lua_interface->GetFloatValue(state,2);
  9809. z = lua_interface->GetFloatValue(state,3);
  9810. h = lua_interface->GetFloatValue(state,4);
  9811. }
  9812. lua_interface->ResetFunctionStack(state);
  9813. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9814. for (int32 i = 0; i < spell->targets.size(); i++) {
  9815. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9816. if (!target2)
  9817. continue;
  9818. if (target2->IsPlayer()) {
  9819. Client* client = ((Player*)target2)->GetClient();
  9820. if (client) {
  9821. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9822. client->SetReloadingZone(true);
  9823. target2->SetX(x);
  9824. target2->SetY(y);
  9825. target2->SetZ(z);
  9826. target2->SetHeading(h);
  9827. target2->SetSpawnOrigX(x);
  9828. target2->SetSpawnOrigY(y);
  9829. target2->SetSpawnOrigZ(z);
  9830. target2->SetSpawnOrigHeading(h);
  9831. target2->SetAppearancePosition(x,y,z);
  9832. client->SetZoningCoords(x,y,z,h);
  9833. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9834. if (packet)
  9835. {
  9836. packet->setDataByName("x", x);
  9837. packet->setDataByName("y", y);
  9838. packet->setDataByName("z", z);
  9839. client->QueuePacket(packet->serialize());
  9840. safe_delete(packet);
  9841. }
  9842. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9843. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9844. }
  9845. }
  9846. }
  9847. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9848. }
  9849. return 0;
  9850. }
  9851. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9852. if (!lua_interface)
  9853. return 0;
  9854. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9855. lua_interface->ResetFunctionStack(state);
  9856. if (!luaspell || !luaspell->spell) {
  9857. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9858. return 0;
  9859. }
  9860. int8 tier = luaspell->spell->GetSpellTier();
  9861. lua_interface->SetInt32Value(state, tier);
  9862. return 1;
  9863. }
  9864. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9865. if (!lua_interface)
  9866. return 0;
  9867. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9868. lua_interface->ResetFunctionStack(state);
  9869. if (!luaspell || !luaspell->spell) {
  9870. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9871. return 0;
  9872. }
  9873. int32 spell_id = luaspell->spell->GetSpellID();
  9874. lua_interface->SetInt32Value(state, spell_id);
  9875. return 1;
  9876. }
  9877. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9878. if (!lua_interface)
  9879. return 0;
  9880. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9881. lua_interface->ResetFunctionStack(state);
  9882. if (!spawn) {
  9883. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9884. return 0;
  9885. }
  9886. if (!spawn->IsPlayer()) {
  9887. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9888. return 0;
  9889. }
  9890. ZoneServer* zone = spawn->GetZone();
  9891. if (!zone) {
  9892. return 0;
  9893. }
  9894. Client* client = ((Player*)spawn)->GetClient();
  9895. if (!client) {
  9896. return 0;
  9897. }
  9898. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9899. return 0;
  9900. }
  9901. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9902. if (!lua_interface)
  9903. return 0;
  9904. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9905. lua_interface->ResetFunctionStack(state);
  9906. if (!spawn) {
  9907. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9908. return 0;
  9909. }
  9910. if (!spawn->IsPlayer()) {
  9911. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9912. return 0;
  9913. }
  9914. ZoneServer* zone = spawn->GetZone();
  9915. if (!zone) {
  9916. return 0;
  9917. }
  9918. Client* client = ((Player*)spawn)->GetClient();
  9919. if (!client) {
  9920. return 0;
  9921. }
  9922. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9923. return 0;
  9924. }
  9925. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9926. if (!lua_interface)
  9927. return 0;
  9928. Spawn* caster = lua_interface->GetSpawn(state);
  9929. Spawn* target = lua_interface->GetSpawn(state, 2);
  9930. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9931. string spell_name = lua_interface->GetStringValue(state, 4);
  9932. lua_interface->ResetFunctionStack(state);
  9933. if (!caster) {
  9934. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9935. return 0;
  9936. }
  9937. if (!caster->IsEntity()) {
  9938. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9939. return 0;
  9940. }
  9941. if (!target) {
  9942. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9943. return 0;
  9944. }
  9945. if (!target->IsEntity()) {
  9946. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9947. return 0;
  9948. }
  9949. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9950. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9951. return 0;
  9952. }
  9953. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9954. if (!lua_interface)
  9955. return 0;
  9956. Spawn* player = lua_interface->GetSpawn(state);
  9957. int32 amount = lua_interface->GetInt32Value(state, 2);
  9958. lua_interface->ResetFunctionStack(state);
  9959. if (player && player->IsPlayer() && amount > 0) {
  9960. ((Player*)player)->AddXP(amount);
  9961. }
  9962. return 0;
  9963. }
  9964. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9965. if (!lua_interface)
  9966. return 0;
  9967. Spawn* player = lua_interface->GetSpawn(state);
  9968. int8 type = lua_interface->GetInt8Value(state, 2);
  9969. string text = lua_interface->GetStringValue(state, 3);
  9970. lua_interface->ResetFunctionStack(state);
  9971. Client* client = 0;
  9972. if (player && player->IsPlayer())
  9973. client = ((Player*)player)->GetClient();
  9974. if (!client || text.length() == 0) {
  9975. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9976. return 0;
  9977. }
  9978. client->SimpleMessage(type, text.c_str());
  9979. return 0;
  9980. }
  9981. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9982. if (!lua_interface)
  9983. return 0;
  9984. Spawn* player = lua_interface->GetSpawn(state);
  9985. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9986. lua_interface->ResetFunctionStack(state);
  9987. Client* client = 0;
  9988. if (player && player->IsPlayer())
  9989. client = ((Player*)player)->GetClient();
  9990. if (!client || !spawn) {
  9991. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9992. return 0;
  9993. }
  9994. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9995. if (!items) {
  9996. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9997. return 0;
  9998. }
  9999. client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
  10000. return 0;
  10001. }
  10002. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  10003. if (!lua_interface)
  10004. return 0;
  10005. Spawn* spawnref = lua_interface->GetSpawn(state);
  10006. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10007. lua_interface->ResetFunctionStack(state);
  10008. if (spawn_id > 0 && spawnref) {
  10009. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  10010. if (spawns.size() == 0) {
  10011. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10012. return 0;
  10013. }
  10014. Spawn* spawn = 0;
  10015. int16 index = MakeRandomInt(0, spawns.size());
  10016. if (index >= spawns.size() || index < 0)
  10017. index = 0;
  10018. spawn = spawns[index];
  10019. lua_interface->SetSpawnValue(state, spawn);
  10020. return 1;
  10021. }
  10022. else {
  10023. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  10024. }
  10025. return 0;
  10026. }
  10027. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  10028. Spawn* player = lua_interface->GetSpawn(state);
  10029. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10030. string name = lua_interface->GetStringValue(state, 3);
  10031. float distance = lua_interface->GetFloatValue(state, 4);
  10032. string command = lua_interface->GetStringValue(state, 5);
  10033. string error_text = lua_interface->GetStringValue(state, 6);
  10034. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  10035. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  10036. lua_interface->ResetFunctionStack(state);
  10037. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  10038. if (distance == 0)
  10039. distance = 10.0f;
  10040. if (command.length() == 0)
  10041. command = name;
  10042. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  10043. if (spawns.size() == 0) {
  10044. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10045. return 0;
  10046. }
  10047. Spawn* spawn = 0;
  10048. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  10049. spawn = *itr;
  10050. if (spawn) {
  10051. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  10052. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  10053. }
  10054. }
  10055. }
  10056. return 0;
  10057. }
  10058. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  10059. if (!lua_interface)
  10060. return 0;
  10061. Client* client = 0;
  10062. Spawn* player = lua_interface->GetSpawn(state);
  10063. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10064. lua_interface->ResetFunctionStack(state);
  10065. if (player && player->IsPlayer() && player->GetZone())
  10066. client = ((Player*)player)->GetClient();
  10067. else{
  10068. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10069. return 0;
  10070. }
  10071. if (client) {
  10072. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10073. if (packet) {
  10074. packet->setDataByName("goal_num", goal_num);
  10075. client->QueuePacket(packet->serialize());
  10076. safe_delete(packet);
  10077. }
  10078. }
  10079. return 0;
  10080. }
  10081. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10082. if (!lua_interface)
  10083. return 0;
  10084. Client* client = 0;
  10085. Spawn* player = lua_interface->GetSpawn(state);
  10086. lua_interface->ResetFunctionStack(state);
  10087. if (player && player->IsPlayer() && player->GetZone())
  10088. client = ((Player*)player)->GetClient();
  10089. else {
  10090. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10091. return 0;
  10092. }
  10093. if (client && client->GetVersion() >= 374) {
  10094. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10095. }
  10096. return 0;
  10097. }
  10098. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10099. if (!lua_interface)
  10100. return 0;
  10101. Client* client = 0;
  10102. Spawn* player = lua_interface->GetSpawn(state);
  10103. float duration = lua_interface->GetFloatValue(state, 2);
  10104. string text = lua_interface->GetStringValue(state, 3);
  10105. string voice = lua_interface->GetStringValue(state, 4);
  10106. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10107. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10108. string signal = lua_interface->GetStringValue(state, 7);
  10109. string goal1 = lua_interface->GetStringValue(state, 8);
  10110. string task1 = lua_interface->GetStringValue(state, 9);
  10111. string goal2 = lua_interface->GetStringValue(state, 10);
  10112. string task2 = lua_interface->GetStringValue(state, 11);
  10113. string goal3 = lua_interface->GetStringValue(state, 12);
  10114. string task3 = lua_interface->GetStringValue(state, 13);
  10115. string goal4 = lua_interface->GetStringValue(state, 14);
  10116. string task4 = lua_interface->GetStringValue(state, 15);
  10117. lua_interface->ResetFunctionStack(state);
  10118. if (!player) {
  10119. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10120. return 0;
  10121. }
  10122. if (!player->IsPlayer()) {
  10123. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10124. return 0;
  10125. }
  10126. else
  10127. client = ((Player*)player)->GetClient();
  10128. if (!client) {
  10129. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10130. return 0;
  10131. }
  10132. if (text.length() == 0) {
  10133. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10134. return 0;
  10135. }
  10136. if (duration >= 0 && duration < 2)
  10137. duration = 2;
  10138. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10139. if (packet) {
  10140. packet->setDataByName("open_seconds_max", duration);
  10141. packet->setDataByName("text", text.c_str());
  10142. packet->setDataByName("voice", voice.c_str());
  10143. int8 num_goals = 1;
  10144. if (task2.length() > 0)
  10145. num_goals++;
  10146. if (task3.length() > 0)
  10147. num_goals++;
  10148. if (task4.length() > 0)
  10149. num_goals++;
  10150. packet->setArrayLengthByName("num_goals", num_goals);
  10151. for (int8 i = 0; i < num_goals; i++) {
  10152. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10153. }
  10154. if (goal1.length() > 0)
  10155. packet->setArrayDataByName("goal_text", goal1.c_str());
  10156. if (goal2.length() > 0)
  10157. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10158. if (goal3.length() > 0)
  10159. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10160. if (goal4.length() > 0)
  10161. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10162. packet->setSubArrayDataByName("task_text", task1.c_str());
  10163. if (task2.length() > 0)
  10164. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10165. if (task3.length() > 0)
  10166. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10167. if (task4.length() > 0)
  10168. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10169. packet->setDataByName("complete_sound", "click");
  10170. packet->setDataByName("signal", signal.c_str());
  10171. packet->setDataByName("voice_key1", voice_key1);
  10172. packet->setDataByName("voice_key2", voice_key2);
  10173. client->QueuePacket(packet->serialize());
  10174. safe_delete(packet);
  10175. }
  10176. return 0;
  10177. }
  10178. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10179. if (!lua_interface)
  10180. return 0;
  10181. Client* client = 0;
  10182. Spawn* player = lua_interface->GetSpawn(state);
  10183. string window = lua_interface->GetStringValue(state, 2);
  10184. int8 show = lua_interface->GetInt8Value(state, 3);
  10185. lua_interface->ResetFunctionStack(state);
  10186. if (!player) {
  10187. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10188. return 0;
  10189. }
  10190. if (!player->IsPlayer()) {
  10191. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10192. return 0;
  10193. }
  10194. else
  10195. client = ((Player*)player)->GetClient();
  10196. if (!client) {
  10197. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10198. return 0;
  10199. }
  10200. if (window.length() == 0) {
  10201. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10202. return 0;
  10203. }
  10204. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10205. if (packet) {
  10206. packet->setDataByName("window", window.c_str());
  10207. packet->setDataByName("show", show);
  10208. client->QueuePacket(packet->serialize());
  10209. safe_delete(packet);
  10210. }
  10211. return 0;
  10212. }
  10213. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10214. //See GameEvents.txt for options that can be used for this function
  10215. if (!lua_interface)
  10216. return 0;
  10217. Client* client = 0;
  10218. Spawn* player = lua_interface->GetSpawn(state);
  10219. string event_name = lua_interface->GetStringValue(state, 2);
  10220. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10221. lua_interface->ResetFunctionStack(state);
  10222. if (!player || !player->IsPlayer()) {
  10223. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10224. return 0;
  10225. }
  10226. client = ((Player*)player)->GetClient();
  10227. if (!client) {
  10228. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10229. return 0;
  10230. }
  10231. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10232. if (packet) {
  10233. packet->setDataByName("event_name", event_name.c_str());
  10234. packet->setDataByName("enabled", enabled);
  10235. client->QueuePacket(packet->serialize());
  10236. safe_delete(packet);
  10237. }
  10238. return 0;
  10239. }
  10240. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10241. if (!lua_interface)
  10242. return 0;
  10243. Spawn* player = lua_interface->GetSpawn(state);
  10244. lua_interface->ResetFunctionStack(state);
  10245. if (player && player->IsPlayer()) {
  10246. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10247. return 1;
  10248. }
  10249. return 0;
  10250. }
  10251. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10252. if (!lua_interface)
  10253. return 0;
  10254. Spawn* player = lua_interface->GetSpawn(state);
  10255. int8 step = lua_interface->GetInt8Value(state, 2);
  10256. lua_interface->ResetFunctionStack(state);
  10257. if (player && player->IsPlayer() && step > 0) {
  10258. ((Player*)player)->SetTutorialStep(step);
  10259. }
  10260. return 0;
  10261. }
  10262. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10263. if (!lua_interface)
  10264. return 0;
  10265. Client* client = 0;
  10266. Spawn* player = lua_interface->GetSpawn(state);
  10267. string window = lua_interface->GetStringValue(state, 2);
  10268. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10269. lua_interface->ResetFunctionStack(state);
  10270. if (!player) {
  10271. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10272. return 0;
  10273. }
  10274. if (!player->IsPlayer()) {
  10275. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10276. return 0;
  10277. }
  10278. else
  10279. client = ((Player*)player)->GetClient();
  10280. if (!client) {
  10281. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10282. return 0;
  10283. }
  10284. if (window.length() == 0) {
  10285. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10286. return 0;
  10287. }
  10288. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10289. if (packet) {
  10290. packet->setDataByName("window", window.c_str());
  10291. packet->setDataByName("flash_seconds", flash_seconds);
  10292. client->QueuePacket(packet->serialize());
  10293. safe_delete(packet);
  10294. }
  10295. return 0;
  10296. }
  10297. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10298. if (!lua_interface)
  10299. return 0;
  10300. Spawn* spawn = lua_interface->GetSpawn(state);
  10301. Spawn* target = lua_interface->GetSpawn(state, 2);
  10302. lua_interface->ResetFunctionStack(state);
  10303. if (spawn && target)
  10304. return spawn->CheckLoS(target);
  10305. return 0;
  10306. }
  10307. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10308. if (!lua_interface)
  10309. return 0;
  10310. Spawn* spawn = lua_interface->GetSpawn(state);
  10311. float x = lua_interface->GetFloatValue(state, 2);
  10312. float y = lua_interface->GetFloatValue(state, 3);
  10313. float z = lua_interface->GetFloatValue(state, 4);
  10314. lua_interface->ResetFunctionStack(state);
  10315. if (spawn)
  10316. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10317. return 0;
  10318. }
  10319. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10320. if (!lua_interface)
  10321. return 0;
  10322. ZoneServer* zone = lua_interface->GetZone(state);
  10323. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10324. lua_interface->ResetFunctionStack(state);
  10325. if (zone)
  10326. zone->SetExpansionFlag(xpackFlag);
  10327. return 0;
  10328. }
  10329. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10330. if (!lua_interface)
  10331. return 0;
  10332. ZoneServer* zone = lua_interface->GetZone(state);
  10333. lua_interface->ResetFunctionStack(state);
  10334. if (zone) {
  10335. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10336. return 1;
  10337. }
  10338. return 0;
  10339. }
  10340. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10341. if (!lua_interface)
  10342. return 0;
  10343. ZoneServer* zone = lua_interface->GetZone(state);
  10344. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10345. lua_interface->ResetFunctionStack(state);
  10346. if (zone)
  10347. zone->SetHolidayFlag(holidayFlag);
  10348. return 0;
  10349. }
  10350. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10351. if (!lua_interface)
  10352. return 0;
  10353. ZoneServer* zone = lua_interface->GetZone(state);
  10354. lua_interface->ResetFunctionStack(state);
  10355. if (zone) {
  10356. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10357. return 1;
  10358. }
  10359. return 0;
  10360. }
  10361. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10362. if (!lua_interface)
  10363. return 0;
  10364. Spawn* spawn = lua_interface->GetSpawn(state);
  10365. bool canbind = lua_interface->GetInt32Value(state, 2);
  10366. lua_interface->ResetFunctionStack(state);
  10367. if(!spawn) {
  10368. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10369. return 0;
  10370. }
  10371. ZoneServer* zone = spawn->GetZone();
  10372. if (zone)
  10373. zone->SetCanBind(canbind);
  10374. return 0;
  10375. }
  10376. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10377. if (!lua_interface)
  10378. return 0;
  10379. Spawn* spawn = lua_interface->GetSpawn(state);
  10380. lua_interface->ResetFunctionStack(state);
  10381. if(!spawn) {
  10382. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10383. return 0;
  10384. }
  10385. ZoneServer* zone = spawn->GetZone();
  10386. if (zone) {
  10387. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10388. return 1;
  10389. }
  10390. return 0;
  10391. }
  10392. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10393. if (!lua_interface)
  10394. return 0;
  10395. Spawn* spawn = lua_interface->GetSpawn(state);
  10396. bool cangate = lua_interface->GetInt32Value(state, 2);
  10397. lua_interface->ResetFunctionStack(state);
  10398. if(!spawn) {
  10399. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10400. return 0;
  10401. }
  10402. ZoneServer* zone = spawn->GetZone();
  10403. if (zone)
  10404. zone->SetCanGate(cangate);
  10405. return 0;
  10406. }
  10407. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10408. if (!lua_interface)
  10409. return 0;
  10410. Spawn* spawn = lua_interface->GetSpawn(state);
  10411. lua_interface->ResetFunctionStack(state);
  10412. if(!spawn) {
  10413. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10414. return 0;
  10415. }
  10416. ZoneServer* zone = spawn->GetZone();
  10417. if (zone) {
  10418. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10419. return 1;
  10420. }
  10421. return 0;
  10422. }
  10423. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10424. if (!lua_interface)
  10425. return 0;
  10426. Spawn* spawn = lua_interface->GetSpawn(state);
  10427. bool canevac = lua_interface->GetInt32Value(state, 2);
  10428. lua_interface->ResetFunctionStack(state);
  10429. if(!spawn) {
  10430. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10431. return 0;
  10432. }
  10433. ZoneServer* zone = spawn->GetZone();
  10434. if (zone)
  10435. zone->SetCanEvac(canevac);
  10436. return 0;
  10437. }
  10438. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10439. if (!lua_interface)
  10440. return 0;
  10441. Spawn* spawn = lua_interface->GetSpawn(state);
  10442. lua_interface->ResetFunctionStack(state);
  10443. if(!spawn) {
  10444. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10445. return 0;
  10446. }
  10447. ZoneServer* zone = spawn->GetZone();
  10448. if (zone) {
  10449. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10450. return 1;
  10451. }
  10452. return 0;
  10453. }
  10454. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10455. if (!lua_interface)
  10456. return 0;
  10457. Spawn* spawn = lua_interface->GetSpawn(state);
  10458. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10459. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10460. float distance = lua_interface->GetFloatValue(state, 4);
  10461. string in_range_function = lua_interface->GetStringValue(state, 5);
  10462. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10463. lua_interface->ResetFunctionStack(state);
  10464. if (spawn && distance > 0 && in_range_function.length() > 0)
  10465. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10466. return 0;
  10467. }
  10468. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10469. if (!lua_interface)
  10470. return 0;
  10471. Spawn* spawn = lua_interface->GetSpawn(state);
  10472. Spawn* target = lua_interface->GetSpawn(state, 2);
  10473. lua_interface->ResetFunctionStack(state);
  10474. if (spawn && target)
  10475. {
  10476. if (spawn->IsPlayer() && target->IsEntity())
  10477. {
  10478. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10479. return 1;
  10480. }
  10481. else if (spawn->IsEntity() && target->IsEntity())
  10482. {
  10483. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10484. return 1;
  10485. }
  10486. }
  10487. return 0;
  10488. }
  10489. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10490. if (!lua_interface)
  10491. return 0;
  10492. Spawn* spawn = lua_interface->GetSpawn(state);
  10493. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10494. lua_interface->ResetFunctionStack(state);
  10495. if (spawn && spawn->IsEntity())
  10496. {
  10497. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10498. if (spawn->IsPlayer())
  10499. {
  10500. Client* client = ((Player*)spawn)->GetClient();
  10501. if (client)
  10502. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10503. }
  10504. }
  10505. return 0;
  10506. }
  10507. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10508. if (!lua_interface)
  10509. return 0;
  10510. Spawn* spawn = lua_interface->GetSpawn(state);
  10511. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10512. lua_interface->ResetFunctionStack(state);
  10513. if (spawn && spawn->IsEntity())
  10514. {
  10515. ((Entity*)spawn)->SetSeeHideSpell(val);
  10516. if (spawn->IsPlayer())
  10517. {
  10518. Client* client = ((Player*)spawn)->GetClient();
  10519. if (client)
  10520. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10521. }
  10522. }
  10523. return 0;
  10524. }
  10525. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10526. {
  10527. if (!lua_interface)
  10528. return 0;
  10529. Spawn* player = lua_interface->GetSpawn(state);
  10530. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10531. string command = lua_interface->GetStringValue(state, 3);
  10532. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10533. lua_interface->ResetFunctionStack(state);
  10534. if (spawn && player && player->IsPlayer())
  10535. {
  10536. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10537. bool res = false;
  10538. if (cmd)
  10539. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10540. lua_interface->SetBooleanValue(state, res);
  10541. return 1;
  10542. }
  10543. return 0;
  10544. }
  10545. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10546. {
  10547. if (!lua_interface)
  10548. return 0;
  10549. Spawn* spawn = lua_interface->GetSpawn(state);
  10550. int32 charID = lua_interface->GetInt32Value(state, 2);
  10551. string command = lua_interface->GetStringValue(state, 3);
  10552. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10553. lua_interface->ResetFunctionStack(state);
  10554. if (spawn && charID)
  10555. {
  10556. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10557. bool res = false;
  10558. if (cmd)
  10559. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10560. lua_interface->SetBooleanValue(state, res);
  10561. return 1;
  10562. }
  10563. return 0;
  10564. }
  10565. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10566. {
  10567. if (!lua_interface)
  10568. return 0;
  10569. Spawn* spawn = lua_interface->GetSpawn(state);
  10570. string command = lua_interface->GetStringValue(state, 2);
  10571. lua_interface->ResetFunctionStack(state);
  10572. if (spawn && command.length() > 0)
  10573. spawn->RemovePrimaryEntityCommand(command.c_str());
  10574. return 0;
  10575. }
  10576. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10577. if (!lua_interface)
  10578. return 0;
  10579. Spawn* spawn = lua_interface->GetSpawn(state);
  10580. float distance = lua_interface->GetFloatValue(state, 2);
  10581. string command = lua_interface->GetStringValue(state, 3);
  10582. Spawn* player = lua_interface->GetSpawn(state, 4);
  10583. lua_interface->ResetFunctionStack(state);
  10584. if (spawn) {
  10585. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10586. }
  10587. return 0;
  10588. }
  10589. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10590. if (!lua_interface)
  10591. return 0;
  10592. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10593. Spawn* spawn = lua_interface->GetSpawn(state);
  10594. Spawn* player = lua_interface->GetSpawn(state, 2);
  10595. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10596. lua_interface->ResetFunctionStack(state);
  10597. if (spawn && player && transport_id && player->IsPlayer()) {
  10598. Client* client = 0;
  10599. if (player && player->IsPlayer())
  10600. client = ((Player*)player)->GetClient();
  10601. if (!client)
  10602. return 0;
  10603. vector<TransportDestination*> destinations;
  10604. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10605. if (destinations.size())
  10606. {
  10607. client->SetTemporaryTransportID(transport_id);
  10608. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10609. }
  10610. else
  10611. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10612. }
  10613. return 0;
  10614. }
  10615. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10616. if (!lua_interface)
  10617. return 0;
  10618. Spawn* player = lua_interface->GetSpawn(state);
  10619. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10620. lua_interface->ResetFunctionStack(state);
  10621. if (player && player->IsPlayer()) {
  10622. Client* client = 0;
  10623. if (player && player->IsPlayer())
  10624. client = ((Player*)player)->GetClient();
  10625. if (!client)
  10626. return 0;
  10627. client->SetTemporaryTransportID(transport_id);
  10628. }
  10629. return 0;
  10630. }
  10631. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10632. if (!lua_interface)
  10633. return 0;
  10634. Spawn* player = lua_interface->GetSpawn(state);
  10635. lua_interface->ResetFunctionStack(state);
  10636. if (player && player->IsPlayer()) {
  10637. Client* client = 0;
  10638. if (player && player->IsPlayer())
  10639. client = ((Player*)player)->GetClient();
  10640. if (!client)
  10641. return 0;
  10642. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10643. return 1;
  10644. }
  10645. return 0;
  10646. }
  10647. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10648. if (!lua_interface)
  10649. return 0;
  10650. Spawn* spawn = lua_interface->GetSpawn(state);
  10651. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10652. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10653. if (!spawn) {
  10654. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10655. return 0;
  10656. }
  10657. if (!spawn->IsEntity()) {
  10658. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10659. return 0;
  10660. }
  10661. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10662. {
  10663. 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);
  10664. return 0;
  10665. }
  10666. lua_interface->ResetFunctionStack(state);
  10667. if (spell && spell->targets.size() > 0) {
  10668. ZoneServer* zone = spell->caster->GetZone();
  10669. for (int8 i = 0; i < spell->targets.size(); i++) {
  10670. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10671. if (target && target->IsEntity()) {
  10672. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10673. if (target->IsPlayer())
  10674. ((Player*)target)->SetCharSheetChanged(true);
  10675. }
  10676. }
  10677. }
  10678. else {
  10679. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10680. if (spawn->IsPlayer())
  10681. ((Player*)spawn)->SetCharSheetChanged(true);
  10682. }
  10683. return 0;
  10684. }
  10685. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10686. if (!lua_interface)
  10687. return 0;
  10688. Spawn* spawn = lua_interface->GetSpawn(state);
  10689. lua_interface->ResetFunctionStack(state);
  10690. if (!spawn) {
  10691. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10692. return 0;
  10693. }
  10694. if (!spawn->IsEntity()) {
  10695. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10696. return 0;
  10697. }
  10698. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10699. return 1;
  10700. }
  10701. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10702. if (!lua_interface)
  10703. return 0;
  10704. int32 spell_id = lua_interface->GetInt32Value(state);
  10705. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10706. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10707. if (spell_id > 0) {
  10708. if (spell_tier == 0)
  10709. spell_tier = 1;
  10710. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10711. if(!spell) {
  10712. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10713. lua_interface->ResetFunctionStack(state);
  10714. return 0;
  10715. }
  10716. LuaSpell* lua_spell = 0;
  10717. if(custom_lua_script.size() > 0)
  10718. {
  10719. // attempt to load the custom script since it isn't already loaded
  10720. // we will re-obtain the lua_spell further below
  10721. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10722. {
  10723. 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());
  10724. lua_interface->LoadLuaSpell(custom_lua_script);
  10725. }
  10726. }
  10727. else
  10728. custom_lua_script = spell->GetSpellData()->lua_script;
  10729. if (!lua_spell && lua_interface)
  10730. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10731. lua_interface->ResetFunctionStack(state);
  10732. if (!lua_spell)
  10733. {
  10734. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10735. return 0;
  10736. }
  10737. lua_spell->spell = new Spell(spell);
  10738. lua_interface->AddCustomSpell(lua_spell);
  10739. lua_interface->SetSpellValue(state, lua_spell);
  10740. return 1;
  10741. }
  10742. return 0;
  10743. }
  10744. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10745. if (!lua_interface)
  10746. return 0;
  10747. LuaSpell* spell = lua_interface->GetSpell(state);
  10748. string field = lua_interface->GetStringValue(state, 2);
  10749. lua_interface->ResetFunctionStack(state);
  10750. if (!spell) {
  10751. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10752. return 0;
  10753. }
  10754. if (!spell->spell || !spell->spell->GetSpellData()) {
  10755. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10756. return 0;
  10757. }
  10758. boost::to_lower(field);
  10759. return spell->spell->GetSpellData(state, field);
  10760. }
  10761. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10762. if (!lua_interface)
  10763. return 0;
  10764. LuaSpell* spell = lua_interface->GetSpell(state);
  10765. string field = lua_interface->GetStringValue(state, 2);
  10766. int8 fieldArg = 3; // field value after the initial set
  10767. if (!spell) {
  10768. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10769. lua_interface->ResetFunctionStack(state);
  10770. return 0;
  10771. }
  10772. if (!spell->spell || !spell->spell->GetSpellData()) {
  10773. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10774. lua_interface->ResetFunctionStack(state);
  10775. return 0;
  10776. }
  10777. boost::to_lower(field);
  10778. bool valSet = false;
  10779. spell->spell->SetSpellData(state, field, fieldArg);
  10780. lua_interface->ResetFunctionStack(state);
  10781. return valSet;
  10782. }
  10783. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10784. if (!lua_interface)
  10785. return 0;
  10786. LuaSpell* spell = lua_interface->GetSpell(state);
  10787. int8 idx = lua_interface->GetInt32Value(state, 2);
  10788. if (!spell) {
  10789. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10790. lua_interface->ResetFunctionStack(state);
  10791. return 0;
  10792. }
  10793. if (!spell->spell || !spell->spell->GetSpellData()) {
  10794. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10795. lua_interface->ResetFunctionStack(state);
  10796. return 0;
  10797. }
  10798. if (spell->spell->lua_data.size() <= idx)
  10799. {
  10800. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10801. lua_interface->ResetFunctionStack(state);
  10802. return 0;
  10803. }
  10804. bool setVal = true;
  10805. LUAData* data = spell->spell->lua_data[idx];
  10806. switch (data->type)
  10807. {
  10808. case 0:
  10809. {
  10810. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10811. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10812. data->int_value = value;
  10813. data->int_value2 = value2;
  10814. break;
  10815. }
  10816. case 1:
  10817. {
  10818. float value = lua_interface->GetFloatValue(state, 3);
  10819. float value2 = lua_interface->GetFloatValue(state, 4);
  10820. data->float_value = value;
  10821. data->float_value2 = value2;
  10822. break;
  10823. }
  10824. case 2:
  10825. {
  10826. bool value = lua_interface->GetBooleanValue(state, 3);
  10827. data->bool_value = value;
  10828. break;
  10829. }
  10830. case 3:
  10831. {
  10832. string value = lua_interface->GetStringValue(state, 3);
  10833. string value2 = lua_interface->GetStringValue(state, 4);
  10834. data->string_value = value;
  10835. data->string_value2 = value2;
  10836. break;
  10837. }
  10838. default:
  10839. setVal = false;
  10840. }
  10841. lua_interface->ResetFunctionStack(state);
  10842. return setVal;
  10843. }
  10844. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10845. if (!lua_interface)
  10846. return 0;
  10847. LuaSpell* spell = lua_interface->GetSpell(state);
  10848. int8 idx = lua_interface->GetInt32Value(state, 2);
  10849. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10850. lua_interface->ResetFunctionStack(state);
  10851. if (!spell) {
  10852. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10853. return 0;
  10854. }
  10855. if (!spell->spell || !spell->spell->GetSpellData()) {
  10856. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10857. return 0;
  10858. }
  10859. if (spell->spell->lua_data.size() <= idx)
  10860. {
  10861. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10862. return 0;
  10863. }
  10864. bool setVal = true;
  10865. LUAData* data = spell->spell->lua_data[idx];
  10866. switch (data->type)
  10867. {
  10868. case 0:
  10869. {
  10870. if(!secondfield)
  10871. lua_interface->SetSInt32Value(state, data->int_value);
  10872. else
  10873. lua_interface->SetSInt32Value(state, data->int_value2);
  10874. break;
  10875. }
  10876. case 1:
  10877. {
  10878. if (!secondfield)
  10879. lua_interface->SetFloatValue(state, data->float_value);
  10880. else
  10881. lua_interface->SetFloatValue(state, data->float_value2);
  10882. break;
  10883. }
  10884. case 2:
  10885. {
  10886. lua_interface->SetBooleanValue(state, data->bool_value);
  10887. break;
  10888. }
  10889. case 3:
  10890. {
  10891. if (!secondfield)
  10892. lua_interface->SetStringValue(state, data->string_value.c_str());
  10893. else
  10894. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10895. break;
  10896. }
  10897. default:
  10898. setVal = false;
  10899. }
  10900. return setVal;
  10901. }
  10902. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10903. if (!lua_interface)
  10904. return 0;
  10905. LuaSpell* spell = lua_interface->GetSpell(state);
  10906. int8 idx = lua_interface->GetInt32Value(state, 2);
  10907. string field = lua_interface->GetStringValue(state, 3);
  10908. boost::to_lower(field);
  10909. if (!spell) {
  10910. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10911. lua_interface->ResetFunctionStack(state);
  10912. return 0;
  10913. }
  10914. if (!spell->spell || !spell->spell->GetSpellData()) {
  10915. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10916. lua_interface->ResetFunctionStack(state);
  10917. return 0;
  10918. }
  10919. if (spell->spell->effects.size() <= idx)
  10920. {
  10921. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10922. lua_interface->ResetFunctionStack(state);
  10923. return 0;
  10924. }
  10925. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10926. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10927. if (field == "description")
  10928. effect->description = string(lua_interface->GetStringValue(state, 4));
  10929. else if (field == "bullet")
  10930. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10931. else if (field == "percentage")
  10932. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10933. else { // no match
  10934. lua_interface->ResetFunctionStack(state);
  10935. return 0;
  10936. }
  10937. lua_interface->ResetFunctionStack(state);
  10938. return 1;
  10939. }
  10940. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10941. if (!lua_interface)
  10942. return 0;
  10943. LuaSpell* spell = lua_interface->GetSpell(state);
  10944. int8 idx = lua_interface->GetInt32Value(state, 2);
  10945. string field = lua_interface->GetStringValue(state, 3);
  10946. lua_interface->ResetFunctionStack(state);
  10947. boost::to_lower(field);
  10948. if (!spell) {
  10949. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10950. return 0;
  10951. }
  10952. if (!spell->spell || !spell->spell->GetSpellData()) {
  10953. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10954. return 0;
  10955. }
  10956. if (spell->spell->effects.size() <= idx)
  10957. {
  10958. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10959. return 0;
  10960. }
  10961. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10962. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10963. if (field == "description")
  10964. lua_interface->SetStringValue(state, effect->description.c_str());
  10965. else if (field == "bullet")
  10966. lua_interface->SetInt32Value(state, effect->subbullet);
  10967. else if (field == "percentage")
  10968. lua_interface->SetInt32Value(state, effect->percentage);
  10969. else // no match
  10970. return 0;
  10971. return 1;
  10972. }
  10973. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10974. if (!lua_interface)
  10975. return 0;
  10976. LuaSpell* spell = lua_interface->GetSpell(state);
  10977. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10978. Spawn* target = lua_interface->GetSpawn(state, 3);
  10979. lua_interface->ResetFunctionStack(state);
  10980. if (!target) {
  10981. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10982. return 0;
  10983. }
  10984. if (!target->IsEntity()) {
  10985. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10986. return 0;
  10987. }
  10988. if (!spell) {
  10989. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10990. return 0;
  10991. }
  10992. if (caster && !caster->IsEntity()) {
  10993. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10994. return 0;
  10995. }
  10996. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10997. return 0;
  10998. }
  10999. int EQ2Emu_lua_InWater(lua_State* state) {
  11000. if (!lua_interface)
  11001. return 0;
  11002. Spawn* spawn = lua_interface->GetSpawn(state);
  11003. lua_interface->ResetFunctionStack(state);
  11004. if (spawn) {
  11005. lua_interface->SetBooleanValue(state, spawn->InWater());
  11006. return 1;
  11007. }
  11008. return 0;
  11009. }
  11010. int EQ2Emu_lua_InLava(lua_State* state) {
  11011. if (!lua_interface)
  11012. return 0;
  11013. Spawn* spawn = lua_interface->GetSpawn(state);
  11014. lua_interface->ResetFunctionStack(state);
  11015. if (spawn) {
  11016. lua_interface->SetBooleanValue(state, spawn->InLava());
  11017. return 1;
  11018. }
  11019. return 0;
  11020. }
  11021. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  11022. if (!lua_interface)
  11023. return 0;
  11024. Spawn* attacker = lua_interface->GetSpawn(state);
  11025. Spawn* victim = lua_interface->GetSpawn(state, 2);
  11026. int8 type = lua_interface->GetInt8Value(state, 3);
  11027. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  11028. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  11029. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  11030. string spell_name = lua_interface->GetStringValue(state, 7);
  11031. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  11032. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  11033. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  11034. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  11035. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  11036. lua_interface->ResetFunctionStack(state);
  11037. if (!attacker) {
  11038. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  11039. lua_interface->SetBooleanValue(state, false);
  11040. return 1;
  11041. }
  11042. if (!attacker->IsEntity()) {
  11043. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  11044. lua_interface->SetBooleanValue(state, false);
  11045. return 1;
  11046. }
  11047. if (!victim) {
  11048. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  11049. lua_interface->SetBooleanValue(state, false);
  11050. return 1;
  11051. }
  11052. if (!victim->IsEntity()) {
  11053. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  11054. lua_interface->SetBooleanValue(state, false);
  11055. return 1;
  11056. }
  11057. bool has_damaged = ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker, take_power);
  11058. lua_interface->SetBooleanValue(state, has_damaged);
  11059. return 1;
  11060. }
  11061. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  11062. if (!lua_interface)
  11063. return 0;
  11064. Spawn* spawn = lua_interface->GetSpawn(state);
  11065. lua_interface->ResetFunctionStack(state);
  11066. if (spawn) {
  11067. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11068. return 1;
  11069. }
  11070. return 0;
  11071. }
  11072. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11073. if (!lua_interface)
  11074. return 0;
  11075. Spawn* spawn = lua_interface->GetSpawn(state);
  11076. bool invul = lua_interface->GetBooleanValue(state, 2);
  11077. lua_interface->ResetFunctionStack(state);
  11078. if (spawn) {
  11079. spawn->SetInvulnerable(invul);
  11080. }
  11081. return 0;
  11082. }
  11083. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11084. if (!lua_interface)
  11085. return 0;
  11086. string category = lua_interface->GetStringValue(state);
  11087. string name = lua_interface->GetStringValue(state, 2);
  11088. lua_interface->ResetFunctionStack(state);
  11089. Rule *ret = 0;
  11090. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11091. lua_interface->SetBooleanValue(state, ret->GetBool());
  11092. return 1;
  11093. }
  11094. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11095. return 0;
  11096. }
  11097. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11098. if (!lua_interface)
  11099. return 0;
  11100. string category = lua_interface->GetStringValue(state);
  11101. string name = lua_interface->GetStringValue(state, 2);
  11102. lua_interface->ResetFunctionStack(state);
  11103. Rule *ret = 0;
  11104. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11105. lua_interface->SetInt32Value(state, ret->GetInt32());
  11106. return 1;
  11107. }
  11108. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11109. return 0;
  11110. }
  11111. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11112. if (!lua_interface)
  11113. return 0;
  11114. string category = lua_interface->GetStringValue(state);
  11115. string name = lua_interface->GetStringValue(state, 2);
  11116. lua_interface->ResetFunctionStack(state);
  11117. Rule *ret = 0;
  11118. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11119. lua_interface->SetFloatValue(state, ret->GetFloat());
  11120. return 1;
  11121. }
  11122. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11123. return 0;
  11124. }
  11125. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11126. if (!lua_interface)
  11127. return 0;
  11128. Spawn* spawn = lua_interface->GetSpawn(state);
  11129. string type = lua_interface->GetStringValue(state, 2);
  11130. lua_interface->ResetFunctionStack(state);
  11131. if (spawn) {
  11132. int res = 1;
  11133. boost::to_lower(type);
  11134. if(type == "assigned_aa")
  11135. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11136. else if ( type == "unassigned_aa")
  11137. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11138. else if ( type == "assigned_tradeskill_aa")
  11139. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11140. else if ( type == "unassigned_tradeskill_aa")
  11141. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11142. else if ( type == "assigned_prestige_aa")
  11143. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11144. else if ( type == "unassigned_prestige_aa")
  11145. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11146. else if ( type == "assigned_tradeskill_prestige_aa")
  11147. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11148. else if ( type == "unassigned_tradeskill_prestige_aa")
  11149. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11150. else
  11151. res = 0;
  11152. return res;
  11153. }
  11154. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11155. return 0;
  11156. }
  11157. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11158. if (!lua_interface)
  11159. return 0;
  11160. Spawn* spawn = lua_interface->GetSpawn(state);
  11161. string type = lua_interface->GetStringValue(state, 2);
  11162. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11163. lua_interface->ResetFunctionStack(state);
  11164. if (spawn) {
  11165. boost::to_lower(type);
  11166. if(type == "assigned_aa")
  11167. spawn->SetAssignedAA((sint16)value);
  11168. else if ( type == "unassigned_aa")
  11169. spawn->SetUnassignedAA((sint16)value);
  11170. else if ( type == "assigned_tradeskill_aa")
  11171. spawn->SetTradeskillAA((sint16)value);
  11172. else if ( type == "unassigned_tradeskill_aa")
  11173. spawn->SetUnassignedTradeskillAA((sint16)value);
  11174. else if ( type == "assigned_prestige_aa")
  11175. spawn->SetPrestigeAA((sint16)value);
  11176. else if ( type == "unassigned_prestige_aa")
  11177. spawn->SetUnassignedPrestigeAA((sint16)value);
  11178. else if ( type == "assigned_tradeskill_prestige_aa")
  11179. spawn->SetTradeskillPrestigeAA((sint16)value);
  11180. else if ( type == "unassigned_tradeskill_prestige_aa")
  11181. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11182. if(spawn->IsPlayer())
  11183. ((Player*)spawn)->SetCharSheetChanged(true);
  11184. }
  11185. return 0;
  11186. }
  11187. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11188. if (!lua_interface)
  11189. return 0;
  11190. string titleName = lua_interface->GetStringValue(state);
  11191. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11192. lua_interface->ResetFunctionStack(state);
  11193. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11194. lua_interface->SetSInt32Value(state, index);
  11195. return 1;
  11196. }
  11197. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11198. if (!lua_interface)
  11199. return 0;
  11200. Spawn* spawn = lua_interface->GetSpawn(state);
  11201. string titleName = lua_interface->GetStringValue(state, 2);
  11202. lua_interface->ResetFunctionStack(state);
  11203. if(!spawn->IsPlayer())
  11204. {
  11205. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11206. lua_interface->SetSInt32Value(state, -1);
  11207. return 1;
  11208. }
  11209. Player* player = (Player*)spawn;
  11210. // check if player already has the title, don't need to add twice
  11211. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11212. if ( playerHasTitle)
  11213. {
  11214. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11215. return 1;
  11216. }
  11217. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11218. if(!title)
  11219. {
  11220. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11221. lua_interface->SetSInt32Value(state, -1);
  11222. return 1;
  11223. }
  11224. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11225. if(returnIdx < 0)
  11226. {
  11227. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11228. }
  11229. lua_interface->SetSInt32Value(state, returnIdx);
  11230. player->GetClient()->SendTitleUpdate();
  11231. return 1;
  11232. }
  11233. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11234. if (!lua_interface)
  11235. return 0;
  11236. Spawn* spawn = lua_interface->GetSpawn(state);
  11237. string titleName = lua_interface->GetStringValue(state, 2);
  11238. lua_interface->ResetFunctionStack(state);
  11239. if(!spawn->IsPlayer())
  11240. {
  11241. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11242. return 0;
  11243. }
  11244. Player* player = (Player*)spawn;
  11245. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11246. if(!title)
  11247. {
  11248. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11249. return 0;
  11250. }
  11251. if(title->GetPrefix())
  11252. {
  11253. 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());
  11254. return 0;
  11255. }
  11256. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11257. player->GetClient()->SendTitleUpdate();
  11258. return 1;
  11259. }
  11260. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11261. if (!lua_interface)
  11262. return 0;
  11263. Spawn* spawn = lua_interface->GetSpawn(state);
  11264. string titleName = lua_interface->GetStringValue(state, 2);
  11265. lua_interface->ResetFunctionStack(state);
  11266. if(!spawn->IsPlayer())
  11267. {
  11268. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11269. return 0;
  11270. }
  11271. Player* player = (Player*)spawn;
  11272. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11273. if(!title)
  11274. {
  11275. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11276. return 0;
  11277. }
  11278. if(!title->GetPrefix())
  11279. {
  11280. 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());
  11281. return 0;
  11282. }
  11283. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11284. player->GetClient()->SendTitleUpdate();
  11285. return 1;
  11286. }
  11287. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11288. if (!lua_interface)
  11289. return 0;
  11290. Spawn* spawn = lua_interface->GetSpawn(state);
  11291. lua_interface->ResetFunctionStack(state);
  11292. if(!spawn->IsPlayer())
  11293. {
  11294. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11295. return 0;
  11296. }
  11297. Player* player = (Player*)spawn;
  11298. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11299. player->GetClient()->SendTitleUpdate();
  11300. return 1;
  11301. }
  11302. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11303. if (!lua_interface)
  11304. return 0;
  11305. Spawn* spawn = lua_interface->GetSpawn(state);
  11306. lua_interface->ResetFunctionStack(state);
  11307. if(!spawn->IsPlayer())
  11308. {
  11309. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11310. return 0;
  11311. }
  11312. Player* player = (Player*)spawn;
  11313. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11314. player->GetClient()->SendTitleUpdate();
  11315. return 1;
  11316. }
  11317. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11318. if (!lua_interface)
  11319. return 0;
  11320. Spawn* spawn = lua_interface->GetSpawn(state);
  11321. string field = lua_interface->GetStringValue(state, 2);
  11322. lua_interface->ResetFunctionStack(state);
  11323. if(!spawn || !spawn->IsEntity())
  11324. {
  11325. 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));
  11326. return 0;
  11327. }
  11328. Entity* ent = (Entity*)spawn;
  11329. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11330. return 1;
  11331. }
  11332. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11333. if (!lua_interface)
  11334. return 0;
  11335. Spawn* spawn = lua_interface->GetSpawn(state);
  11336. string field = lua_interface->GetStringValue(state, 2);
  11337. lua_interface->ResetFunctionStack(state);
  11338. if(!spawn || !spawn->IsEntity())
  11339. {
  11340. 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));
  11341. return 0;
  11342. }
  11343. Entity* ent = (Entity*)spawn;
  11344. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11345. return 1;
  11346. }
  11347. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11348. if (!lua_interface)
  11349. return 0;
  11350. Spawn* spawn = lua_interface->GetSpawn(state);
  11351. string field = lua_interface->GetStringValue(state, 2);
  11352. lua_interface->ResetFunctionStack(state);
  11353. if(!spawn || !spawn->IsEntity())
  11354. {
  11355. 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));
  11356. return 0;
  11357. }
  11358. Entity* ent = (Entity*)spawn;
  11359. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11360. return 1;
  11361. }
  11362. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11363. if (!lua_interface)
  11364. return 0;
  11365. Spawn* spawn = lua_interface->GetSpawn(state);
  11366. string field = lua_interface->GetStringValue(state, 2);
  11367. lua_interface->ResetFunctionStack(state);
  11368. if(!spawn || !spawn->IsEntity())
  11369. {
  11370. 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));
  11371. return 0;
  11372. }
  11373. Entity* ent = (Entity*)spawn;
  11374. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11375. return 1;
  11376. }
  11377. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11378. if (!lua_interface)
  11379. return 0;
  11380. Spawn* spawn = lua_interface->GetSpawn(state);
  11381. string field = lua_interface->GetStringValue(state, 2);
  11382. string value = lua_interface->GetStringValue(state, 3);
  11383. lua_interface->ResetFunctionStack(state);
  11384. if(!spawn || !spawn->IsEntity())
  11385. {
  11386. 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));
  11387. return 0;
  11388. }
  11389. Entity* ent = (Entity*)spawn;
  11390. bool set_ = ent->SetInfoStructString(field, value);
  11391. lua_interface->SetBooleanValue(state, set_);
  11392. return 1;
  11393. }
  11394. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11395. if (!lua_interface)
  11396. return 0;
  11397. Spawn* spawn = lua_interface->GetSpawn(state);
  11398. string field = lua_interface->GetStringValue(state, 2);
  11399. int64 value = lua_interface->GetInt64Value(state, 3);
  11400. lua_interface->ResetFunctionStack(state);
  11401. if(!spawn || !spawn->IsEntity())
  11402. {
  11403. 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));
  11404. return 0;
  11405. }
  11406. Entity* ent = (Entity*)spawn;
  11407. bool set_ = ent->SetInfoStructUInt(field, value);
  11408. lua_interface->SetBooleanValue(state, set_);
  11409. return 1;
  11410. }
  11411. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11412. if (!lua_interface)
  11413. return 0;
  11414. Spawn* spawn = lua_interface->GetSpawn(state);
  11415. string field = lua_interface->GetStringValue(state, 2);
  11416. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11417. lua_interface->ResetFunctionStack(state);
  11418. if(!spawn || !spawn->IsEntity())
  11419. {
  11420. 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));
  11421. return 0;
  11422. }
  11423. Entity* ent = (Entity*)spawn;
  11424. bool set_ = ent->SetInfoStructSInt(field, value);
  11425. lua_interface->SetBooleanValue(state, set_);
  11426. return 1;
  11427. }
  11428. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11429. if (!lua_interface)
  11430. return 0;
  11431. Spawn* spawn = lua_interface->GetSpawn(state);
  11432. string field = lua_interface->GetStringValue(state, 2);
  11433. float value = lua_interface->GetFloatValue(state, 3);
  11434. lua_interface->ResetFunctionStack(state);
  11435. if(!spawn || !spawn->IsEntity())
  11436. {
  11437. 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));
  11438. return 0;
  11439. }
  11440. Entity* ent = (Entity*)spawn;
  11441. bool set_ = ent->SetInfoStructFloat(field, value);
  11442. lua_interface->SetBooleanValue(state, set_);
  11443. return 1;
  11444. }
  11445. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11446. if (!lua_interface)
  11447. return 0;
  11448. Spawn* spawn = lua_interface->GetSpawn(state);
  11449. bool value = lua_interface->GetBooleanValue(state, 2);
  11450. lua_interface->ResetFunctionStack(state);
  11451. if(!spawn || !spawn->IsPlayer())
  11452. {
  11453. 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));
  11454. return 0;
  11455. }
  11456. ((Player*)spawn)->SetCharSheetChanged(value);
  11457. return 0;
  11458. }
  11459. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11460. if (!lua_interface)
  11461. return 0;
  11462. Spawn* spawn = lua_interface->GetSpawn(state);
  11463. std::string fromName = lua_interface->GetStringValue(state, 2);
  11464. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11465. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11466. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11467. int32 copper = lua_interface->GetInt32Value(state, 6);
  11468. int32 silver = lua_interface->GetInt32Value(state, 7);
  11469. int32 gold = lua_interface->GetInt32Value(state, 8);
  11470. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11471. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11472. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11473. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11474. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11475. lua_interface->ResetFunctionStack(state);
  11476. if(!spawn || !spawn->IsPlayer())
  11477. {
  11478. 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));
  11479. lua_interface->SetBooleanValue(state, false);
  11480. return 1;
  11481. }
  11482. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11483. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11484. lua_interface->SetBooleanValue(state, true);
  11485. return 1;
  11486. }
  11487. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11488. if (!lua_interface)
  11489. return 0;
  11490. int32 char_id = lua_interface->GetInt32Value(state);
  11491. std::string fromName = lua_interface->GetStringValue(state, 2);
  11492. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11493. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11494. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11495. int32 copper = lua_interface->GetInt32Value(state, 6);
  11496. int32 silver = lua_interface->GetInt32Value(state, 7);
  11497. int32 gold = lua_interface->GetInt32Value(state, 8);
  11498. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11499. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11500. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11501. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11502. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11503. lua_interface->ResetFunctionStack(state);
  11504. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11505. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11506. lua_interface->SetBooleanValue(state, true);
  11507. return 1;
  11508. }
  11509. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11510. Spawn* widget;
  11511. if (lua_interface) {
  11512. widget = lua_interface->GetSpawn(state);
  11513. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11514. lua_interface->ResetFunctionStack(state);
  11515. if (widget && widget->IsWidget())
  11516. {
  11517. ((Widget*)widget)->OpenDoor();
  11518. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11519. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11520. }
  11521. else
  11522. 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));
  11523. }
  11524. return 0;
  11525. }
  11526. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11527. Spawn* widget;
  11528. if (lua_interface) {
  11529. widget = lua_interface->GetSpawn(state);
  11530. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11531. lua_interface->ResetFunctionStack(state);
  11532. if (widget && widget->IsWidget())
  11533. {
  11534. ((Widget*)widget)->CloseDoor();
  11535. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11536. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11537. }
  11538. else
  11539. 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));
  11540. }
  11541. return 0;
  11542. }
  11543. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11544. if (!lua_interface)
  11545. return 0;
  11546. Spawn* widget = lua_interface->GetSpawn(state);
  11547. lua_interface->ResetFunctionStack(state);
  11548. if (widget && widget->IsWidget())
  11549. {
  11550. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11551. return 1;
  11552. }
  11553. return 0;
  11554. }
  11555. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11556. if (!lua_interface)
  11557. return 0;
  11558. sint32 min = lua_interface->GetSInt32Value(state);
  11559. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11560. lua_interface->ResetFunctionStack(state);
  11561. sint32 result = MakeRandomInt(min, max);
  11562. lua_interface->SetSInt32Value(state, result);
  11563. return 1;
  11564. }
  11565. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11566. if (!lua_interface)
  11567. return 0;
  11568. float min = lua_interface->GetFloatValue(state);
  11569. float max = lua_interface->GetFloatValue(state, 2);
  11570. lua_interface->ResetFunctionStack(state);
  11571. float result = MakeRandomFloat(min, max);
  11572. lua_interface->SetFloatValue(state, result);
  11573. return 1;
  11574. }
  11575. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11576. if (!lua_interface)
  11577. return 0;
  11578. Spawn* spawn = lua_interface->GetSpawn(state);
  11579. int32 value = lua_interface->GetInt32Value(state, 2);
  11580. lua_interface->ResetFunctionStack(state);
  11581. if(!spawn)
  11582. {
  11583. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11584. lua_interface->SetBooleanValue(state, false);
  11585. return 1;
  11586. }
  11587. spawn->AddIconValue(value);
  11588. lua_interface->SetBooleanValue(state, true);
  11589. return 1;
  11590. }
  11591. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11592. if (!lua_interface)
  11593. return 0;
  11594. Spawn* spawn = lua_interface->GetSpawn(state);
  11595. int32 value = lua_interface->GetInt32Value(state, 2);
  11596. lua_interface->ResetFunctionStack(state);
  11597. if(!spawn)
  11598. {
  11599. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11600. lua_interface->SetBooleanValue(state, false);
  11601. return 1;
  11602. }
  11603. spawn->RemoveIconValue(value);
  11604. lua_interface->SetBooleanValue(state, true);
  11605. return 1;
  11606. }
  11607. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11608. Spawn* npc = lua_interface->GetSpawn(state);
  11609. lua_interface->ResetFunctionStack(state);
  11610. if (npc && npc->IsNPC()) {
  11611. NPC* shard = (NPC*)npc;
  11612. int32 shardid = shard->GetShardID();
  11613. lua_interface->SetInt32Value(state, shardid);
  11614. return 1;
  11615. }
  11616. lua_interface->SetInt32Value(state, 0);
  11617. return 1;
  11618. }
  11619. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11620. Spawn* npc = lua_interface->GetSpawn(state);
  11621. lua_interface->ResetFunctionStack(state);
  11622. if (npc && npc->IsNPC()) {
  11623. NPC* shard = (NPC*)npc;
  11624. int32 charid = shard->GetShardCharID();
  11625. lua_interface->SetInt32Value(state, charid);
  11626. return 1;
  11627. }
  11628. lua_interface->SetInt32Value(state, 0);
  11629. return 1;
  11630. }
  11631. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11632. Spawn* npc = lua_interface->GetSpawn(state);
  11633. lua_interface->ResetFunctionStack(state);
  11634. if (npc && npc->IsNPC()) {
  11635. NPC* shard = (NPC*)npc;
  11636. int64 timestamp = shard->GetShardCreatedTimestamp();
  11637. lua_interface->SetSInt64Value(state, timestamp);
  11638. return 1;
  11639. }
  11640. lua_interface->SetSInt64Value(state, 0);
  11641. return 1;
  11642. }
  11643. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11644. if (!lua_interface)
  11645. return 0;
  11646. int32 shardid = lua_interface->GetInt32Value(state);
  11647. lua_interface->ResetFunctionStack(state);
  11648. if(shardid < 1)
  11649. lua_interface->SetBooleanValue(state, false);
  11650. else
  11651. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11652. return 1;
  11653. }
  11654. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11655. if (!lua_interface)
  11656. return 0;
  11657. Spawn* spawn = lua_interface->GetSpawn(state);
  11658. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11659. if (spawn) {
  11660. spawn->PauseMovement(delay_in_ms);
  11661. }
  11662. lua_interface->ResetFunctionStack(state);
  11663. return 0;
  11664. }
  11665. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11666. if (!lua_interface)
  11667. return 0;
  11668. Spawn* spawn = lua_interface->GetSpawn(state);
  11669. if (spawn) {
  11670. spawn->ResetMovement();
  11671. }
  11672. lua_interface->ResetFunctionStack(state);
  11673. return 0;
  11674. }
  11675. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11676. Player* player = (Player*)lua_interface->GetSpawn(state);
  11677. int8 level = lua_interface->GetInt8Value(state, 2);
  11678. lua_interface->ResetFunctionStack(state);
  11679. if (player && player->IsPlayer() && level > 0) {
  11680. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11681. return 1;
  11682. }
  11683. return 0;
  11684. }
  11685. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11686. Player* player = (Player*)lua_interface->GetSpawn(state);
  11687. int8 level = lua_interface->GetInt8Value(state, 2);
  11688. lua_interface->ResetFunctionStack(state);
  11689. if (player && player->IsPlayer() && level > 0) {
  11690. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11691. return 1;
  11692. }
  11693. return 0;
  11694. }
  11695. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11696. ZoneServer* zone = lua_interface->GetZone(state);
  11697. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11698. lua_interface->ResetFunctionStack(state);
  11699. if (zone) {
  11700. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11701. if (spawn) {
  11702. lua_interface->SetSpawnValue(state, spawn);
  11703. return 1;
  11704. }
  11705. }
  11706. return 0;
  11707. }
  11708. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11709. if (!lua_interface)
  11710. return 0;
  11711. Spawn* spawn = lua_interface->GetSpawn(state);
  11712. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11713. lua_interface->ResetFunctionStack(state);
  11714. bool res = false;
  11715. if(spawn && spawn->IsTransportSpawn())
  11716. {
  11717. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11718. spawn->SetRailID(rail_id);
  11719. res = true;
  11720. }
  11721. else if (!spawn) {
  11722. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11723. }
  11724. else if(!spawn->IsTransportSpawn()) {
  11725. 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());
  11726. }
  11727. lua_interface->SetBooleanValue(state, res);
  11728. return 1;
  11729. }
  11730. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11731. if (!lua_interface)
  11732. return 0;
  11733. ZoneServer* zone = lua_interface->GetZone(state);
  11734. lua_interface->ResetFunctionStack(state);
  11735. if (zone) {
  11736. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11737. return 1;
  11738. }
  11739. return 0;
  11740. }
  11741. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11742. if (!lua_interface)
  11743. return 0;
  11744. Spawn* spawn = lua_interface->GetSpawn(state);
  11745. lua_interface->ResetFunctionStack(state);
  11746. if (spawn) {
  11747. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11748. return 1;
  11749. }
  11750. return 0;
  11751. }
  11752. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11753. if (!lua_interface)
  11754. return 0;
  11755. Spawn* player = lua_interface->GetSpawn(state);
  11756. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11757. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11758. lua_interface->ResetFunctionStack(state);
  11759. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11760. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11761. }
  11762. else if(!zoneID) {
  11763. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11764. }
  11765. else
  11766. {
  11767. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11768. return 1;
  11769. }
  11770. return 0;
  11771. }
  11772. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11773. if (!lua_interface)
  11774. return 0;
  11775. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11776. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11777. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11778. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11779. lua_interface->ResetFunctionStack(state);
  11780. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11781. world.GetWorldTimeStruct()->year = newYear;
  11782. world.GetWorldTimeStruct()->month = newMonth;
  11783. world.GetWorldTimeStruct()->hour = newHour;
  11784. world.GetWorldTimeStruct()->minute = newMinute;
  11785. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11786. return 0;
  11787. }
  11788. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11789. if (!lua_interface)
  11790. return 0;
  11791. lua_interface->ResetFunctionStack(state);
  11792. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11793. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11794. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11795. return 1;
  11796. }
  11797. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11798. if (!lua_interface)
  11799. return 0;
  11800. lua_interface->ResetFunctionStack(state);
  11801. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11802. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11803. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11804. return 1;
  11805. }
  11806. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11807. if (!lua_interface)
  11808. return 0;
  11809. lua_interface->ResetFunctionStack(state);
  11810. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11811. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11812. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11813. return 1;
  11814. }
  11815. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11816. if (!lua_interface)
  11817. return 0;
  11818. lua_interface->ResetFunctionStack(state);
  11819. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11820. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11821. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11822. return 1;
  11823. }
  11824. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11825. if (!lua_interface)
  11826. return 0;
  11827. lua_interface->ResetFunctionStack(state);
  11828. world.SendTimeUpdate();
  11829. return 0;
  11830. }
  11831. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11832. bool update_result = false;
  11833. Faction* faction = 0;
  11834. Spawn* spawn = lua_interface->GetSpawn(state);
  11835. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11836. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11837. lua_interface->ResetFunctionStack(state);
  11838. if(!spawn || !spawn->IsPlayer()) {
  11839. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11840. return 0;
  11841. }
  11842. Player* player = (Player*)spawn;
  11843. Client* client = player->GetClient();
  11844. if (faction_id > 0) {
  11845. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11846. if(hasfaction == 0) {
  11847. //they do not have the faction. Lets get the default value and feed it in.
  11848. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11849. //add the default faction for the player.
  11850. player->SetFactionValue(faction_id, defaultfaction);
  11851. }
  11852. if(increase >= 0) {
  11853. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11854. faction = master_faction_list.GetFaction(faction_id);
  11855. if(faction && update_result)
  11856. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11857. else if(faction)
  11858. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11859. lua_interface->SetBooleanValue(state, true);
  11860. return 1;
  11861. }
  11862. if(increase < 0){
  11863. //change the negative to a positive, since thats how decreasefaction() likes it.
  11864. increase *= -1;
  11865. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11866. faction = master_faction_list.GetFaction(faction_id);
  11867. if(faction && update_result)
  11868. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11869. else if(faction)
  11870. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11871. lua_interface->SetBooleanValue(state, true);
  11872. return 1;
  11873. }
  11874. }
  11875. lua_interface->SetBooleanValue(state, false);
  11876. return 1;
  11877. }
  11878. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11879. bool hascoin = 0;
  11880. Player* player = (Player*)lua_interface->GetSpawn(state);
  11881. int32 coins = lua_interface->GetInt32Value(state, 2);
  11882. lua_interface->ResetFunctionStack(state);
  11883. if (player && player->IsPlayer()) {
  11884. hascoin = player->HasCoins(coins);
  11885. if(hascoin == 0) {
  11886. lua_interface->SetBooleanValue(state, false);
  11887. return 1;
  11888. }
  11889. if(hascoin == 1) {
  11890. lua_interface->SetBooleanValue(state, true);
  11891. return 1;
  11892. }
  11893. }
  11894. return 0;
  11895. }
  11896. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11897. int32 loot_tier = 0;
  11898. Spawn* spawn = lua_interface->GetSpawn(state);
  11899. lua_interface->ResetFunctionStack(state);
  11900. if (spawn) {
  11901. loot_tier = spawn->GetLootTier();
  11902. lua_interface->SetInt32Value(state, loot_tier);
  11903. return 1;
  11904. }
  11905. return 0;
  11906. }
  11907. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11908. if (!lua_interface)
  11909. return 0;
  11910. Spawn* spawn = lua_interface->GetSpawn(state);
  11911. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11912. lua_interface->ResetFunctionStack(state);
  11913. if (spawn) {
  11914. spawn->SetLootTier(loot_tier);
  11915. lua_interface->SetBooleanValue(state, true);
  11916. return 1;
  11917. }
  11918. lua_interface->SetBooleanValue(state, false);
  11919. return 1;
  11920. }
  11921. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11922. int32 loot_drop_type = 0;
  11923. Spawn* spawn = lua_interface->GetSpawn(state);
  11924. lua_interface->ResetFunctionStack(state);
  11925. if (spawn) {
  11926. loot_drop_type = spawn->GetLootDropType();
  11927. lua_interface->SetInt32Value(state, loot_drop_type);
  11928. return 1;
  11929. }
  11930. return 0;
  11931. }
  11932. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11933. if (!lua_interface)
  11934. return 0;
  11935. Spawn* spawn = lua_interface->GetSpawn(state);
  11936. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11937. lua_interface->ResetFunctionStack(state);
  11938. if (spawn) {
  11939. spawn->SetLootDropType(loot_drop_type);
  11940. lua_interface->SetBooleanValue(state, true);
  11941. return 1;
  11942. }
  11943. lua_interface->SetBooleanValue(state, false);
  11944. return 1;
  11945. }
  11946. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11947. if (!lua_interface)
  11948. return 0;
  11949. Spawn* spawn = lua_interface->GetSpawn(state);
  11950. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11951. if(damage_amount > 100) {
  11952. damage_amount = 100;
  11953. }
  11954. if (!spawn) {
  11955. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11956. lua_interface->ResetFunctionStack(state);
  11957. return 0;
  11958. }
  11959. lua_interface->ResetFunctionStack(state);
  11960. if (spawn->IsPlayer()) {
  11961. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11962. lua_interface->SetBooleanValue(state, true);
  11963. else
  11964. lua_interface->SetBooleanValue(state, false);
  11965. }
  11966. else {
  11967. lua_interface->SetBooleanValue(state, false);
  11968. }
  11969. return 1;
  11970. }
  11971. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11972. ZoneServer* zone = lua_interface->GetZone(state);
  11973. int32 version = lua_interface->GetInt32Value(state, 2);
  11974. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11975. if(region_map == nullptr) {
  11976. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11977. lua_interface->ResetFunctionStack(state);
  11978. return 0;
  11979. }
  11980. string region_name = lua_interface->GetStringValue(state, 3);
  11981. string env_name = lua_interface->GetStringValue(state, 4);
  11982. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11983. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11984. float dist = lua_interface->GetFloatValue(state, 7);
  11985. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11986. lua_interface->ResetFunctionStack(state);
  11987. lua_interface->SetBooleanValue(state, true);
  11988. return 1;
  11989. }
  11990. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11991. ZoneServer* zone = lua_interface->GetZone(state);
  11992. int32 version = lua_interface->GetInt32Value(state, 2);
  11993. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11994. if(region_map == nullptr) {
  11995. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11996. lua_interface->ResetFunctionStack(state);
  11997. return 0;
  11998. }
  11999. string region_name = lua_interface->GetStringValue(state, 3);
  12000. region_map->RemoveRegionNode(region_name);
  12001. lua_interface->ResetFunctionStack(state);
  12002. lua_interface->SetBooleanValue(state, true);
  12003. return 1;
  12004. }
  12005. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  12006. Client* client = nullptr;
  12007. Spawn* player = lua_interface->GetSpawn(state);
  12008. if (!player) {
  12009. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  12010. lua_interface->SetBooleanValue(state, false);
  12011. lua_interface->ResetFunctionStack(state);
  12012. return 1;
  12013. }
  12014. if (!player->IsPlayer()) {
  12015. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  12016. lua_interface->SetBooleanValue(state, false);
  12017. lua_interface->ResetFunctionStack(state);
  12018. return 1;
  12019. }
  12020. client = player->GetClient();
  12021. if (!client) {
  12022. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  12023. lua_interface->SetBooleanValue(state, false);
  12024. lua_interface->ResetFunctionStack(state);
  12025. return 1;
  12026. }
  12027. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  12028. bool success_sight = client->SetPlayerPOVGhost(spawn);
  12029. lua_interface->ResetFunctionStack(state);
  12030. lua_interface->SetBooleanValue(state, success_sight);
  12031. return 1;
  12032. }
  12033. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  12034. if (!lua_interface)
  12035. return 0;
  12036. bool result = false;
  12037. Spawn* spawn = lua_interface->GetSpawn(state);
  12038. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  12039. lua_interface->ResetFunctionStack(state);
  12040. if (!spawn)
  12041. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12042. else if (!spawn->IsNPC())
  12043. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12044. else
  12045. {
  12046. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  12047. result = true;
  12048. }
  12049. lua_interface->SetBooleanValue(state, result);
  12050. return 1;
  12051. }
  12052. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  12053. if (!lua_interface)
  12054. return 0;
  12055. bool result = false;
  12056. Spawn* spawn = lua_interface->GetSpawn(state);
  12057. lua_interface->ResetFunctionStack(state);
  12058. if (!spawn)
  12059. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12060. else if (!spawn->IsNPC())
  12061. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12062. else
  12063. {
  12064. if(((NPC*)spawn)->cast_on_aggro_completed)
  12065. result = true;
  12066. }
  12067. lua_interface->SetBooleanValue(state, result);
  12068. return 1;
  12069. }
  12070. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12071. Client* client = nullptr;
  12072. Spawn* player = lua_interface->GetSpawn(state);
  12073. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12074. lua_interface->ResetFunctionStack(state);
  12075. if (!player) {
  12076. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  12077. lua_interface->SetBooleanValue(state, false);
  12078. return 1;
  12079. }
  12080. if (!player->IsPlayer()) {
  12081. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  12082. lua_interface->SetBooleanValue(state, false);
  12083. return 1;
  12084. }
  12085. client = player->GetClient();
  12086. if (!client) {
  12087. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12088. lua_interface->SetBooleanValue(state, false);
  12089. return 1;
  12090. }
  12091. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12092. lua_interface->SetBooleanValue(state, result);
  12093. return 1;
  12094. }
  12095. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12096. Client* client = nullptr;
  12097. Spawn* player = lua_interface->GetSpawn(state);
  12098. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12099. lua_interface->ResetFunctionStack(state);
  12100. if (!player) {
  12101. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12102. lua_interface->SetBooleanValue(state, false);
  12103. return 1;
  12104. }
  12105. if (!player->IsPlayer()) {
  12106. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12107. lua_interface->SetBooleanValue(state, false);
  12108. return 1;
  12109. }
  12110. client = player->GetClient();
  12111. if (!client) {
  12112. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12113. lua_interface->SetBooleanValue(state, false);
  12114. return 1;
  12115. }
  12116. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12117. lua_interface->SetBooleanValue(state, result);
  12118. return 1;
  12119. }
  12120. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12121. Client* client = nullptr;
  12122. Spawn* player = lua_interface->GetSpawn(state);
  12123. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12124. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12125. // rest are all optional fields
  12126. float x = lua_interface->GetFloatValue(state, 4);
  12127. float y = lua_interface->GetFloatValue(state, 5);
  12128. float z = lua_interface->GetFloatValue(state, 6);
  12129. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12130. lua_interface->ResetFunctionStack(state);
  12131. if (!player) {
  12132. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12133. lua_interface->SetBooleanValue(state, false);
  12134. return 1;
  12135. }
  12136. if (!player->IsPlayer()) {
  12137. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12138. lua_interface->SetBooleanValue(state, false);
  12139. return 1;
  12140. }
  12141. if(!player->GetZone()) {
  12142. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12143. lua_interface->SetBooleanValue(state, false);
  12144. return 1;
  12145. }
  12146. client = player->GetClient();
  12147. if (!client) {
  12148. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12149. lua_interface->SetBooleanValue(state, false);
  12150. return 1;
  12151. }
  12152. if(!client->IsReadyForUpdates()) {
  12153. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12154. lua_interface->SetBooleanValue(state, false);
  12155. return 1;
  12156. }
  12157. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12158. lua_interface->SetBooleanValue(state, true);
  12159. return 1;
  12160. }
  12161. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12162. Client* client = nullptr;
  12163. Spawn* spawn = lua_interface->GetSpawn(state);
  12164. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12165. lua_interface->ResetFunctionStack(state);
  12166. if (!spawn) {
  12167. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12168. lua_interface->SetBooleanValue(state, false);
  12169. return 1;
  12170. }
  12171. if(!spawn->GetZone()) {
  12172. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12173. lua_interface->SetBooleanValue(state, false);
  12174. return 1;
  12175. }
  12176. spawn->AddIgnoredWidget(widget_id);
  12177. lua_interface->SetBooleanValue(state, true);
  12178. return 1;
  12179. }
  12180. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12181. ZoneServer* zone = lua_interface->GetZone(state);
  12182. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12183. lua_interface->ResetFunctionStack(state);
  12184. if(!zone) {
  12185. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12186. lua_interface->SetBooleanValue(state, false);
  12187. return 1;
  12188. }
  12189. if(!zone->IsLoading()) {
  12190. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12191. lua_interface->SetBooleanValue(state, false);
  12192. return 1;
  12193. }
  12194. zone->AddIgnoredWidget(widget_id);
  12195. lua_interface->SetBooleanValue(state, true);
  12196. return 1;
  12197. }
  12198. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12199. if (!lua_interface)
  12200. return 0;
  12201. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12202. Spawn* spawn = lua_interface->GetSpawn(state);
  12203. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12204. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12205. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12206. Spawn* target = lua_interface->GetSpawn(state, 5);
  12207. lua_interface->ResetFunctionStack(state);
  12208. if(spell && spawn && spawn->IsEntity()) {
  12209. ZoneServer* zone = spawn->GetZone();
  12210. if(zone) {
  12211. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12212. }
  12213. }
  12214. else if (spawn) {
  12215. if (spawn->IsPlayer()) {
  12216. Client* client = ((Player*)spawn)->GetClient();
  12217. if (client) {
  12218. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12219. }
  12220. }
  12221. }
  12222. return 0;
  12223. }
  12224. int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
  12225. if (!lua_interface)
  12226. return 0;
  12227. Spawn* player = lua_interface->GetSpawn(state);
  12228. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12229. lua_interface->ResetFunctionStack(state);
  12230. if (!player) {
  12231. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12232. return 0;
  12233. }
  12234. if (!player->IsPlayer()) {
  12235. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12236. return 0;
  12237. }
  12238. bool ret = ((Player*)player)->get_character_flag(flag_id);
  12239. lua_interface->SetBooleanValue(state, ret);
  12240. return 1;
  12241. }
  12242. int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
  12243. if (!lua_interface)
  12244. return 0;
  12245. Spawn* player = lua_interface->GetSpawn(state);
  12246. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12247. lua_interface->ResetFunctionStack(state);
  12248. if (!player) {
  12249. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12250. return 0;
  12251. }
  12252. if (!player->IsPlayer()) {
  12253. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12254. return 0;
  12255. }
  12256. ((Player*)player)->toggle_character_flag(flag_id);
  12257. return 0;
  12258. }
  12259. int EQ2Emu_lua_GetSpellInitialTarget(lua_State* state) {
  12260. LuaSpell* spell = lua_interface->GetSpell(state);
  12261. if(!spell) {
  12262. spell = lua_interface->GetCurrentSpell(state);
  12263. }
  12264. lua_interface->ResetFunctionStack(state);
  12265. if (spell) {
  12266. if(!spell->caster) {
  12267. lua_interface->LogError("%s: LUA GetSpellTarget command error, caster does not exist.", lua_interface->GetScriptName(state));
  12268. return 0;
  12269. }
  12270. if(!spell->caster->GetZone()) {
  12271. lua_interface->LogError("%s: LUA GetSpellTarget command error, zone does not exist.", lua_interface->GetScriptName(state));
  12272. return 0;
  12273. }
  12274. Spawn* spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  12275. if (spawn) {
  12276. lua_interface->SetSpawnValue(state, spawn);
  12277. return 1;
  12278. }
  12279. else {
  12280. lua_interface->LogError("%s: LUA GetSpellTarget command error, could not find initial target %u to map to spawn.", lua_interface->GetScriptName(state), spell->initial_target);
  12281. }
  12282. }
  12283. return 0;
  12284. }