LuaFunctions.cpp 422 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765
  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() > 546 )
  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. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  685. lua_interface->SetBooleanValue(state, true);
  686. return 1;
  687. }
  688. lua_interface->SetBooleanValue(state, false);
  689. return 1;
  690. }
  691. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  692. Spawn* spawn = lua_interface->GetSpawn(state);
  693. lua_interface->ResetFunctionStack(state);
  694. if (spawn) {
  695. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  701. Spawn* spawn = lua_interface->GetSpawn(state);
  702. lua_interface->ResetFunctionStack(state);
  703. if (spawn) {
  704. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  705. return 1;
  706. }
  707. return 0;
  708. }
  709. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  710. Player* player = (Player*)lua_interface->GetSpawn(state);
  711. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  712. lua_interface->ResetFunctionStack(state);
  713. if (player && player->IsPlayer() && faction_id > 0) {
  714. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  715. return 1;
  716. }
  717. return 0;
  718. }
  719. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  720. if (!lua_interface)
  721. return 0;
  722. Spawn* spawn = lua_interface->GetSpawn(state);
  723. int32 value = lua_interface->GetInt32Value(state, 2);
  724. lua_interface->ResetFunctionStack(state);
  725. if (spawn) {
  726. spawn->SetFactionID(value);
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  731. Spawn* spawn = lua_interface->GetSpawn(state);
  732. lua_interface->ResetFunctionStack(state);
  733. if (spawn) {
  734. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  735. return 1;
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_GetGender(lua_State* state) {
  740. Spawn* spawn = lua_interface->GetSpawn(state);
  741. lua_interface->ResetFunctionStack(state);
  742. if (spawn) {
  743. lua_interface->SetInt32Value(state, spawn->GetGender());
  744. return 1;
  745. }
  746. return 0;
  747. }
  748. int EQ2Emu_lua_GetTarget(lua_State* state) {
  749. Spawn* spawn = lua_interface->GetSpawn(state);
  750. lua_interface->ResetFunctionStack(state);
  751. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  752. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  753. return 1;
  754. }
  755. return 0;
  756. }
  757. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  758. if (!lua_interface)
  759. return 0;
  760. Spawn* spawn = lua_interface->GetSpawn(state);
  761. string mp3_string = lua_interface->GetStringValue(state, 2);
  762. int32 key1 = lua_interface->GetInt32Value(state, 3);
  763. int32 key2 = lua_interface->GetInt32Value(state, 4);
  764. Spawn* player = lua_interface->GetSpawn(state, 5);
  765. lua_interface->ResetFunctionStack(state);
  766. if (spawn && mp3_string.length() > 0) {
  767. Client* client = 0;
  768. if (player && player->IsPlayer())
  769. client = ((Player*)player)->GetClient();
  770. if (client) {
  771. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  772. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  773. }
  774. else
  775. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* spawn = lua_interface->GetSpawn(state);
  783. lua_interface->ResetFunctionStack(state);
  784. if (spawn) {
  785. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  786. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  788. return 3;
  789. }
  790. return 0;
  791. }
  792. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  793. if (!lua_interface)
  794. return 0;
  795. Spawn* spawn = lua_interface->GetSpawn(state);
  796. if (spawn) {
  797. int32 item_id = lua_interface->GetInt32Value(state, 2);
  798. lua_interface->ResetFunctionStack(state);
  799. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  800. return 1;
  801. }
  802. lua_interface->ResetFunctionStack(state);
  803. return 0;
  804. }
  805. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  806. if (!lua_interface)
  807. return 0;
  808. Spawn* spawn = lua_interface->GetSpawn(state);
  809. if (spawn && spawn->IsEntity()) {
  810. int32 item_id = lua_interface->GetInt32Value(state, 2);
  811. int16 charges = lua_interface->GetInt16Value(state, 3);
  812. if (charges == 0)
  813. charges = 1;
  814. ((Entity*)spawn)->AddLootItem(item_id, charges);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* spawn = lua_interface->GetSpawn(state);
  823. if (spawn && spawn->IsEntity()) {
  824. int32 item_id = lua_interface->GetInt32Value(state, 2);
  825. Item* item = spawn->LootItem(item_id);
  826. lua_interface->SetLuaUserDataStale(item);
  827. safe_delete(item);
  828. }
  829. lua_interface->ResetFunctionStack(state);
  830. return 0;
  831. }
  832. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  833. if (!lua_interface)
  834. return 0;
  835. Spawn* spawn = lua_interface->GetSpawn(state);
  836. if (spawn) {
  837. int32 val = lua_interface->GetInt32Value(state, 2);
  838. spawn->AddLootCoins(val);
  839. }
  840. lua_interface->ResetFunctionStack(state);
  841. return 0;
  842. }
  843. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  844. if (!lua_interface)
  845. return 0;
  846. Spawn* entity = lua_interface->GetSpawn(state);
  847. Spawn* player = lua_interface->GetSpawn(state, 2);
  848. if (entity && player && player->IsPlayer()) {
  849. int32 coins = lua_interface->GetInt32Value(state, 3);
  850. vector<Item*>* items = 0;
  851. int i = 0;
  852. int32 item_id = 0;
  853. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  854. if (items == 0)
  855. items = new vector<Item*>;
  856. if (master_item_list.GetItem(item_id))
  857. items->push_back(master_item_list.GetItem(item_id));
  858. i++;
  859. }
  860. Client* client = 0;
  861. client = ((Player*)player)->GetClient();
  862. if (client)
  863. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  864. if(coins > 0)
  865. entity->AddLootCoins(coins);
  866. safe_delete(items);
  867. }
  868. lua_interface->ResetFunctionStack(state);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* entity = lua_interface->GetSpawn(state);
  875. Spawn* player = lua_interface->GetSpawn(state, 2);
  876. int32 item_id = lua_interface->GetInt32Value(state, 3);
  877. lua_interface->ResetFunctionStack(state);
  878. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  879. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  880. return 1;
  881. }
  882. return 0;
  883. }
  884. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  885. if (!lua_interface)
  886. return 0;
  887. Spawn* entity = lua_interface->GetSpawn(state);
  888. Spawn* player = lua_interface->GetSpawn(state, 2);
  889. lua_interface->ResetFunctionStack(state);
  890. if (entity && player && player->IsPlayer()) {
  891. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  892. return 1;
  893. }
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  900. lua_interface->SetLuaUserDataStale(conversation);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = ((Player*)player)->GetClient();
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = ((Player*)player)->GetClient();
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = ((Player*)player)->GetClient();
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. lua_interface->SetLuaUserDataStale(conversation);
  994. safe_delete(conversation);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = ((Player*)player)->GetClient();
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. lua_interface->SetLuaUserDataStale(conversation);
  1020. safe_delete(conversation);
  1021. }
  1022. else
  1023. 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);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = ((Player*)player)->GetClient();
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = ((Player*)player)->GetClient();
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = ((Player*)player)->GetClient();
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = ((Player*)player)->GetClient();
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. lua_interface->ResetFunctionStack(state);
  1247. return 0;
  1248. }
  1249. Spawn* caster = luaspell->caster;
  1250. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1251. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1252. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1253. Spawn* target = lua_interface->GetSpawn(state, 4);
  1254. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1255. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1256. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1257. lua_interface->ResetFunctionStack(state);
  1258. boost::to_lower(heal_type);
  1259. if (caster && caster->IsEntity()) {
  1260. bool success = false;
  1261. luaspell->resisted = false;
  1262. if (target) {
  1263. float distance = caster->GetDistance(target, true);
  1264. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1265. success = true;
  1266. }
  1267. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1268. Spawn* target = 0;
  1269. ZoneServer* zone = luaspell->caster->GetZone();
  1270. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1271. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1272. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1273. float distance = caster->GetDistance(target, true);
  1274. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1275. }
  1276. }
  1277. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1278. success = true;
  1279. }
  1280. if (success) {
  1281. if (caster->GetZone())
  1282. caster->GetZone()->TriggerCharSheetTimer();
  1283. }
  1284. }
  1285. return 0;
  1286. }
  1287. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1288. if (!lua_interface)
  1289. return 0;
  1290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1291. if(!luaspell || luaspell->resisted) {
  1292. lua_interface->ResetFunctionStack(state);
  1293. return 0;
  1294. }
  1295. Spawn* caster = luaspell->caster;
  1296. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1297. float percentage = lua_interface->GetFloatValue(state, 2);
  1298. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1299. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1300. Spawn* target = lua_interface->GetSpawn(state, 5);
  1301. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1302. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1303. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1304. lua_interface->ResetFunctionStack(state);
  1305. boost::to_lower(heal_type);
  1306. int32 min_heal = 0, max_heal = 0;
  1307. if (caster && caster->IsEntity() && target) {
  1308. if(percentage <= 0.0f)
  1309. {
  1310. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1311. return 0;
  1312. }
  1313. if(heal_type == "power")
  1314. {
  1315. if(current_value)
  1316. {
  1317. if(caster_value)
  1318. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1319. else
  1320. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1321. }
  1322. else
  1323. {
  1324. if(caster_value)
  1325. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1326. else
  1327. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(current_value)
  1333. {
  1334. if(caster_value)
  1335. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1336. else
  1337. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1338. }
  1339. else
  1340. {
  1341. if(caster_value)
  1342. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1343. else
  1344. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1345. }
  1346. }
  1347. bool success = false;
  1348. luaspell->resisted = false;
  1349. if (target) {
  1350. float distance = caster->GetDistance(target, true);
  1351. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1352. success = true;
  1353. }
  1354. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1355. Spawn* target = 0;
  1356. ZoneServer* zone = luaspell->caster->GetZone();
  1357. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1358. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1359. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1360. float distance = caster->GetDistance(target, true);
  1361. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1362. }
  1363. }
  1364. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1365. success = true;
  1366. }
  1367. if (success) {
  1368. if (caster->GetZone())
  1369. caster->GetZone()->TriggerCharSheetTimer();
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. int EQ2Emu_lua_AddItem(lua_State* state) {
  1375. if (!lua_interface)
  1376. return 0;
  1377. Spawn* spawn = lua_interface->GetSpawn(state);
  1378. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1379. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1380. lua_interface->ResetFunctionStack(state);
  1381. // default of 1 quantity to add
  1382. if (quantity == 0)
  1383. quantity = 1;
  1384. if (spawn && spawn->IsPlayer()) {
  1385. Client* client = ((Player*)spawn)->GetClient();
  1386. if (client && item_id > 0) {
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1388. return 1;
  1389. }
  1390. }
  1391. lua_interface->SetBooleanValue(state, false);
  1392. return 1;
  1393. }
  1394. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1395. if (!lua_interface)
  1396. return 0;
  1397. Spawn* spawn = lua_interface->GetSpawn(state);
  1398. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1399. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1400. string location = lua_interface->GetStringValue(state, 4);
  1401. int16 item_count = lua_interface->GetInt16Value(state,5);
  1402. //devn00b: if we dont have a count, assume 1 item.
  1403. if(!item_count) {
  1404. item_count = 1;
  1405. }
  1406. lua_interface->ResetFunctionStack(state);
  1407. if (spawn && spawn->IsPlayer()) {
  1408. Client* client = ((Player*)spawn)->GetClient();
  1409. if (client && item_id > 0) {
  1410. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1411. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1412. else
  1413. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1414. if (send_messages) {
  1415. Item* item = master_item_list.GetItem(item_id);
  1416. if (item) {
  1417. if(item_count > 1) {
  1418. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1419. string popup_text1 = "You receive "+ item_count;
  1420. string popup_text2 = " " + item->name;
  1421. string popup_text = popup_text1 + popup_text2;
  1422. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1423. // return 1;
  1424. } else {
  1425. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1426. string popup_text = "You receive " + item->name;
  1427. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1428. }
  1429. }
  1430. }
  1431. return 1;
  1432. }
  1433. }
  1434. lua_interface->SetBooleanValue(state, false);
  1435. return 1;
  1436. }
  1437. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1438. Spawn* spawn = lua_interface->GetSpawn(state);
  1439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1440. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1441. lua_interface->ResetFunctionStack(state);
  1442. // default of 1 to remove
  1443. if (quantity == 0)
  1444. quantity = 1;
  1445. Client* client;
  1446. Item* item;
  1447. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1448. if ((client = ((Player*)spawn)->GetClient())) {
  1449. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1450. if (client->RemoveItem(item, quantity)) {
  1451. lua_interface->SetBooleanValue(state, true);
  1452. return 1;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. lua_interface->SetBooleanValue(state, false);
  1458. return 1;
  1459. }
  1460. int EQ2Emu_lua_HasItem(lua_State* state) {
  1461. Spawn* player = lua_interface->GetSpawn(state);
  1462. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1463. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1464. lua_interface->ResetFunctionStack(state);
  1465. if (player && player->IsPlayer()) {
  1466. bool hasItem = false;
  1467. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1468. if (!hasItem)
  1469. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1470. lua_interface->SetBooleanValue(state, hasItem);
  1471. return 1;
  1472. }
  1473. lua_interface->SetBooleanValue(state, false);
  1474. return 1;
  1475. }
  1476. int EQ2Emu_lua_Spawn(lua_State* state) {
  1477. if (!lua_interface)
  1478. return 0;
  1479. ZoneServer* zone = lua_interface->GetZone(state);
  1480. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1481. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1482. float x = lua_interface->GetFloatValue(state, 4);
  1483. float y = lua_interface->GetFloatValue(state, 5);
  1484. float z = lua_interface->GetFloatValue(state, 6);
  1485. float heading = lua_interface->GetFloatValue(state, 7);
  1486. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1487. Spawn* spawn = zone->GetSpawn(spawn_id);
  1488. if (!spawn)
  1489. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1490. else {
  1491. spawn->SetX(x);
  1492. spawn->SetZ(z);
  1493. spawn->SetY(y,true,true);
  1494. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1495. spawn->SetHeading(heading);
  1496. if (restricted_npc)
  1497. spawn->AddAllowAccessSpawn(spawn);
  1498. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1499. bool scriptActive = false;
  1500. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1501. scriptActive = true;
  1502. spawn->SetSpawnScript(string(spawn_script));
  1503. }
  1504. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1505. zone->AddSpawn(spawn);
  1506. if (scriptActive) {
  1507. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1508. }
  1509. lua_interface->ResetFunctionStack(state);
  1510. lua_interface->SetSpawnValue(state, spawn);
  1511. return 1;
  1512. }
  1513. }
  1514. else {
  1515. string output = "Invalid paramaters to LUA Spawn command: \n";
  1516. if (!zone)
  1517. output = output.append("\t").append("Missing zone reference. \n");
  1518. if (spawn_id == 0)
  1519. output = output.append("\t").append("Missing spawn_id.");
  1520. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1521. }
  1522. lua_interface->ResetFunctionStack(state);
  1523. return 0;
  1524. }
  1525. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1526. if (!lua_interface)
  1527. return 0;
  1528. ZoneServer* zone = lua_interface->GetZone(state);
  1529. lua_interface->ResetFunctionStack(state);
  1530. if (zone) {
  1531. lua_interface->SetStringValue(state, zone->GetZoneName());
  1532. return 1;
  1533. }
  1534. return 0;
  1535. }
  1536. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1537. if (!lua_interface)
  1538. return 0;
  1539. ZoneServer* zone = lua_interface->GetZone(state);
  1540. lua_interface->ResetFunctionStack(state);
  1541. if (zone) {
  1542. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1543. return 1;
  1544. }
  1545. return 0;
  1546. }
  1547. int EQ2Emu_lua_GetZone(lua_State* state) {
  1548. if (!lua_interface)
  1549. return 0;
  1550. int32 zone_id = lua_interface->GetInt32Value(state);
  1551. ZoneServer* zone = 0;
  1552. if (zone_id > 0)
  1553. zone = zone_list.Get(zone_id);
  1554. else {
  1555. string zone_name = lua_interface->GetStringValue(state);
  1556. if (zone_name.length() > 0) {
  1557. zone = zone_list.Get(zone_name.c_str());
  1558. }
  1559. else {
  1560. Spawn* spawn = lua_interface->GetSpawn(state);
  1561. if (spawn)
  1562. zone = spawn->GetZone();
  1563. }
  1564. }
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (zone) {
  1567. lua_interface->SetZoneValue(state, zone);
  1568. return 1;
  1569. }
  1570. return 0;
  1571. }
  1572. int EQ2Emu_lua_AddHate(lua_State* state) {
  1573. Spawn* entity = lua_interface->GetSpawn(state);
  1574. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1575. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1576. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1577. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1578. if(luaspell && luaspell->resisted) {
  1579. lua_interface->ResetFunctionStack(state);
  1580. return 0;
  1581. }
  1582. if (entity && entity->IsEntity() && amount != 0) {
  1583. if (luaspell) {
  1584. ZoneServer* zone = luaspell->caster->GetZone();
  1585. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1586. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1587. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1588. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1589. entity->CheckEncounterState((Entity*)spawn);
  1590. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1591. if (send_packet)
  1592. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1593. }
  1594. }
  1595. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1596. }
  1597. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1598. entity->CheckEncounterState((Entity*)npc);
  1599. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1600. }
  1601. }
  1602. lua_interface->ResetFunctionStack(state);
  1603. return 0;
  1604. }
  1605. int EQ2Emu_lua_Zone(lua_State* state) {
  1606. if (!lua_interface)
  1607. return 0;
  1608. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1609. ZoneServer* zone = lua_interface->GetZone(state);
  1610. Spawn* player = lua_interface->GetSpawn(state, 2);
  1611. Client* client = 0;
  1612. if (player && player->IsPlayer())
  1613. client = ((Player*)player)->GetClient();
  1614. float x = lua_interface->GetFloatValue(state, 3);
  1615. float y = lua_interface->GetFloatValue(state, 4);
  1616. float z = lua_interface->GetFloatValue(state, 5);
  1617. float heading = lua_interface->GetFloatValue(state, 6);
  1618. if (zone && client) {
  1619. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1620. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1621. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1622. {
  1623. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1624. return 0;
  1625. }
  1626. if (x != 0 || y != 0 || z != 0) {
  1627. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1628. player->SetX(x);
  1629. player->SetY(y);
  1630. player->SetZ(z);
  1631. player->SetHeading(heading);
  1632. client->Zone(zone->GetZoneName(), false);
  1633. }
  1634. else
  1635. client->Zone(zone->GetZoneName());
  1636. }
  1637. else
  1638. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1639. lua_interface->ResetFunctionStack(state);
  1640. return 0;
  1641. }
  1642. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1643. if (!lua_interface)
  1644. return 0;
  1645. Spawn* spawn = lua_interface->GetSpawn(state);
  1646. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1647. if (spawn && spawn2)
  1648. spawn->AddAllowAccessSpawn(spawn2);
  1649. lua_interface->ResetFunctionStack(state);
  1650. return 0;
  1651. }
  1652. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1653. if (!lua_interface)
  1654. return 0;
  1655. Spawn* target = lua_interface->GetSpawn(state);
  1656. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1657. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1658. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1659. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1660. lua_interface->ResetFunctionStack(state);
  1661. if (!target) {
  1662. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1663. return 0;
  1664. }
  1665. if (!target->IsEntity()) {
  1666. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1667. return 0;
  1668. }
  1669. if (spell_id <= 0) {
  1670. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1671. return 0;
  1672. }
  1673. if (caster && !caster->IsEntity()) {
  1674. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1675. return 0;
  1676. }
  1677. if (spell_tier == 0)
  1678. spell_tier = 1;
  1679. if (!caster)
  1680. caster = target;
  1681. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1682. return 0;
  1683. }
  1684. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1685. if (!lua_interface)
  1686. return 0;
  1687. Spawn* target = lua_interface->GetSpawn(state);
  1688. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1689. if(!luaspell || luaspell->resisted) {
  1690. lua_interface->ResetFunctionStack(state);
  1691. return 0;
  1692. }
  1693. Spawn* caster = luaspell->caster;
  1694. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1695. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1696. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1697. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1698. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1699. //lua_interface->ResetFunctionStack(state);
  1700. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1701. vector<int16> faction_req;
  1702. vector<int16> race_req;
  1703. int32 class_req = 0;
  1704. int32 i = 0;
  1705. int8 f = 0;
  1706. int8 r = 0;
  1707. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1708. if (class_id < 100) {
  1709. class_req += pow(2.0, double(class_id - 1));
  1710. }
  1711. else if (class_id > 100 && class_id < 1000) {
  1712. race_req.push_back(class_id);
  1713. r++;
  1714. }
  1715. else {
  1716. faction_req.push_back(class_id);
  1717. f++;
  1718. }
  1719. i++;
  1720. }
  1721. lua_interface->ResetFunctionStack(state);
  1722. if (caster && caster->IsEntity()) {
  1723. bool race_match = false;
  1724. bool success = false;
  1725. luaspell->resisted = false;
  1726. if (luaspell->targets.size() > 0) {
  1727. ZoneServer* zone = luaspell->caster->GetZone();
  1728. Spawn* target = 0;
  1729. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1730. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1731. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1732. if (race_req.size() > 0) {
  1733. for (int8 i = 0; i < race_req.size(); i++) {
  1734. if(race_req[i] == target->GetRace() ||
  1735. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1736. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1737. race_match = true;
  1738. }
  1739. }
  1740. }
  1741. else
  1742. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1743. if (race_match == true) {
  1744. float distance = caster->GetDistance(target, true);
  1745. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1746. }
  1747. }
  1748. }
  1749. success = true;
  1750. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1751. }
  1752. else if (target) {
  1753. //check class and race/faction here
  1754. if (race_req.size() > 0) {
  1755. for (int8 i = 0; i < race_req.size(); i++) {
  1756. if(race_req[i] == target->GetRace() ||
  1757. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1758. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1759. race_match = true;
  1760. }
  1761. }
  1762. }
  1763. else
  1764. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1765. if (race_match == true) {
  1766. float distance = caster->GetDistance(target, true);
  1767. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1768. success = true;
  1769. }
  1770. }
  1771. if (success) {
  1772. Spell* spell = luaspell->spell;
  1773. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1774. ((Player*)caster)->InCombat(true);
  1775. if (caster->GetZone())
  1776. caster->GetZone()->TriggerCharSheetTimer();
  1777. }
  1778. }
  1779. }
  1780. return 0;
  1781. }
  1782. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1783. if (!lua_interface)
  1784. return 0;
  1785. Spawn* spawn = lua_interface->GetSpawn(state);
  1786. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1787. lua_interface->ResetFunctionStack(state);
  1788. if (spawn && value != 0) {
  1789. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1790. spawn->SetPower(spawn->GetTotalPower());
  1791. else
  1792. spawn->SetPower(spawn->GetPower() + value);
  1793. }
  1794. return 0;
  1795. }
  1796. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1797. if (!lua_interface)
  1798. return 0;
  1799. Spawn* spawn = lua_interface->GetSpawn(state);
  1800. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1801. lua_interface->ResetFunctionStack(state);
  1802. if (spawn && value != 0) {
  1803. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1804. spawn->SetHP(spawn->GetTotalHP());
  1805. else
  1806. spawn->SetHP(spawn->GetHP() + value);
  1807. }
  1808. return 0;
  1809. }
  1810. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1811. if (!lua_interface)
  1812. return 0;
  1813. Spawn* spawn = lua_interface->GetSpawn(state);
  1814. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1815. lua_interface->ResetFunctionStack(state);
  1816. if (spawn && value != 0) {
  1817. spawn->SetPower(spawn->GetPower() + value);
  1818. if (value > spawn->GetTotalHPBase())
  1819. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1820. }
  1821. return 0;
  1822. }
  1823. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1824. if (!lua_interface)
  1825. return 0;
  1826. Spawn* spawn = lua_interface->GetSpawn(state);
  1827. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1828. lua_interface->ResetFunctionStack(state);
  1829. if (spawn && value != 0) {
  1830. spawn->SetHP(spawn->GetHP() + value);
  1831. if (value > spawn->GetTotalHPBase())
  1832. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1833. }
  1834. return 0;
  1835. }
  1836. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1837. if (!lua_interface)
  1838. return 0;
  1839. Spawn* spawn = lua_interface->GetSpawn(state);
  1840. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1841. lua_interface->ResetFunctionStack(state);
  1842. if (spawn) {
  1843. spawn->SetHP(value);
  1844. if (value > spawn->GetTotalHPBase())
  1845. spawn->SetTotalHP(value);
  1846. }
  1847. return 0;
  1848. }
  1849. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1850. if (!lua_interface)
  1851. return 0;
  1852. Spawn* spawn = lua_interface->GetSpawn(state);
  1853. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1854. float value = lua_interface->GetFloatValue(state, 2);
  1855. lua_interface->ResetFunctionStack(state);
  1856. if (spawn && spawn->IsEntity() && value > 0)
  1857. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1858. if (spawn && spawn->IsPlayer())
  1859. ((Player*)spawn)->SetCharSheetChanged(true);
  1860. return 0;
  1861. }
  1862. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1863. if (!lua_interface)
  1864. return 0;
  1865. Spawn* spawn = lua_interface->GetSpawn(state);
  1866. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1867. lua_interface->ResetFunctionStack(state);
  1868. if (spawn && spawn->IsEntity() && value > 0)
  1869. ((Entity*)spawn)->SetTotalHPBase(value);
  1870. return 0;
  1871. }
  1872. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1873. if (!lua_interface)
  1874. return 0;
  1875. Spawn* spawn = lua_interface->GetSpawn(state);
  1876. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1877. lua_interface->ResetFunctionStack(state);
  1878. if (spawn && value > 0) {
  1879. spawn->SetPower(value);
  1880. if (value > spawn->GetTotalPowerBase())
  1881. spawn->SetTotalPower(value);
  1882. }
  1883. return 0;
  1884. }
  1885. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1886. if (!lua_interface)
  1887. return 0;
  1888. Spawn* spawn = lua_interface->GetSpawn(state);
  1889. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1890. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1891. lua_interface->ResetFunctionStack(state);
  1892. if (spawn && spawn->IsEntity() && value > 0)
  1893. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1894. return 0;
  1895. }
  1896. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1897. if (!lua_interface)
  1898. return 0;
  1899. Spawn* spawn = lua_interface->GetSpawn(state);
  1900. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1901. lua_interface->ResetFunctionStack(state);
  1902. if (spawn && spawn->IsEntity() && value > 0)
  1903. ((Entity*)spawn)->SetTotalPowerBase(value);
  1904. return 0;
  1905. }
  1906. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1907. if (!lua_interface)
  1908. return 0;
  1909. Spawn* spawn = lua_interface->GetSpawn(state);
  1910. float x = lua_interface->GetFloatValue(state, 2);
  1911. float y = lua_interface->GetFloatValue(state, 3);
  1912. float z = lua_interface->GetFloatValue(state, 4);
  1913. float heading = lua_interface->GetFloatValue(state, 5);
  1914. lua_interface->ResetFunctionStack(state);
  1915. if (spawn) {
  1916. spawn->SetX(x);
  1917. spawn->SetY(y);
  1918. spawn->SetZ(z);
  1919. if (heading != 0)
  1920. spawn->SetHeading(heading);
  1921. spawn->SetSpawnOrigX(spawn->GetX());
  1922. spawn->SetSpawnOrigY(spawn->GetY());
  1923. spawn->SetSpawnOrigZ(spawn->GetZ());
  1924. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1925. if (spawn->IsPlayer()) {
  1926. Client* client = ((Player*)spawn)->GetClient();
  1927. if (client) {
  1928. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1929. client->QueuePacket(packet);
  1930. }
  1931. }
  1932. }
  1933. return 0;
  1934. }
  1935. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1936. if (!lua_interface)
  1937. return 0;
  1938. Spawn* spawn = lua_interface->GetSpawn(state);
  1939. float value = lua_interface->GetFloatValue(state, 2);
  1940. lua_interface->ResetFunctionStack(state);
  1941. if (spawn) {
  1942. spawn->SetHeading(value);
  1943. if (spawn->IsPlayer()) {
  1944. Client* client = ((Player*)spawn)->GetClient();
  1945. if (client) {
  1946. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1947. client->QueuePacket(packet);
  1948. }
  1949. }
  1950. }
  1951. return 0;
  1952. }
  1953. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1954. if (!lua_interface)
  1955. return 0;
  1956. Spawn* spawn = lua_interface->GetSpawn(state);
  1957. int16 value = lua_interface->GetInt16Value(state, 2);
  1958. lua_interface->ResetFunctionStack(state);
  1959. if (spawn)
  1960. spawn->SetModelType(value);
  1961. return 0;
  1962. }
  1963. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1964. if (!lua_interface)
  1965. return 0;
  1966. Spawn* spawn = lua_interface->GetSpawn(state);
  1967. int8 value = lua_interface->GetInt8Value(state, 2);
  1968. lua_interface->ResetFunctionStack(state);
  1969. if (spawn) {
  1970. if (spawn->IsPlayer())
  1971. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1972. else
  1973. spawn->SetAdventureClass(value);
  1974. }
  1975. return 0;
  1976. }
  1977. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1978. if (!lua_interface)
  1979. return 0;
  1980. Spawn* spawn = lua_interface->GetSpawn(state);
  1981. int8 value = lua_interface->GetInt8Value(state, 2);
  1982. lua_interface->ResetFunctionStack(state);
  1983. if (spawn) {
  1984. spawn->SetTradeskillClass(value);
  1985. if (spawn->IsEntity()) {
  1986. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1987. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1988. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1989. }
  1990. if (spawn->IsPlayer())
  1991. ((Player*)spawn)->SetCharSheetChanged(true);
  1992. }
  1993. return 0;
  1994. }
  1995. int EQ2Emu_lua_SetMount(lua_State* state) {
  1996. if (!lua_interface)
  1997. return 0;
  1998. Spawn* spawn = lua_interface->GetSpawn(state);
  1999. int16 value = lua_interface->GetInt16Value(state, 2);
  2000. if (spawn && spawn->IsEntity()) {
  2001. ((Entity*)spawn)->SetMount(value);
  2002. EQ2_Color color;
  2003. color.red = 255;
  2004. color.green = 255;
  2005. color.blue = 255;
  2006. ((Entity*)spawn)->SetMountColor(&color);
  2007. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2008. }
  2009. return 0;
  2010. }
  2011. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2012. if (!lua_interface)
  2013. return 0;
  2014. Spawn* spawn = lua_interface->GetSpawn(state);
  2015. EQ2_Color mount_color;
  2016. EQ2_Color saddle_color;
  2017. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2018. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2019. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2020. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2021. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2022. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2023. if (spawn && spawn->IsEntity()) {
  2024. ((Entity*)spawn)->SetMountColor(&mount_color);
  2025. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2026. }
  2027. return 0;
  2028. }
  2029. int EQ2Emu_lua_GetMount(lua_State* state) {
  2030. if (!lua_interface)
  2031. return 0;
  2032. Spawn* spawn = lua_interface->GetSpawn(state);
  2033. if (spawn && spawn->IsEntity()) {
  2034. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2035. return 1;
  2036. }
  2037. return 0;
  2038. }
  2039. int EQ2Emu_lua_GetRace(lua_State* state) {
  2040. if (!lua_interface)
  2041. return 0;
  2042. Spawn* spawn = lua_interface->GetSpawn(state);
  2043. if (spawn)
  2044. {
  2045. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2046. lua_interface->SetInt32Value(state, spawn->GetRace());
  2047. return 1;
  2048. }
  2049. return 0;
  2050. }
  2051. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2052. if (!lua_interface)
  2053. return 0;
  2054. Spawn* spawn = lua_interface->GetSpawn(state);
  2055. if (spawn) {
  2056. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2057. return 1;
  2058. }
  2059. return 0;
  2060. }
  2061. int EQ2Emu_lua_GetClass(lua_State* state) {
  2062. Spawn* spawn = lua_interface->GetSpawn(state);
  2063. if (spawn) {
  2064. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2065. return 1;
  2066. }
  2067. return 0;
  2068. }
  2069. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2070. Spawn* spawn = lua_interface->GetSpawn(state);
  2071. if (spawn) {
  2072. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2073. return 1;
  2074. }
  2075. return 0;
  2076. }
  2077. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2078. if (!lua_interface)
  2079. return 0;
  2080. Spawn* spawn = lua_interface->GetSpawn(state);
  2081. float value = lua_interface->GetFloatValue(state, 2);
  2082. lua_interface->ResetFunctionStack(state);
  2083. if (spawn) {
  2084. spawn->SetSpeed(value);
  2085. if(spawn->IsEntity())
  2086. ((Entity*)spawn)->SetSpeed(value);
  2087. if (spawn->IsPlayer()) {
  2088. Client* client = ((Player*)spawn)->GetClient();
  2089. if (client) {
  2090. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2091. if (packet) {
  2092. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2093. packet->setDataByName("speed", value);
  2094. packet->setDataByName("size", 0.51);
  2095. EQ2Packet* app = packet->serialize();
  2096. client->QueuePacket(app);
  2097. safe_delete(packet);
  2098. }
  2099. }
  2100. }
  2101. }
  2102. return 0;
  2103. }
  2104. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2105. if (!lua_interface)
  2106. return 0;
  2107. Spawn* spawn = lua_interface->GetSpawn(state);
  2108. const int16 type = lua_interface->GetInt16Value(state, 2);
  2109. const float value = lua_interface->GetFloatValue(state, 3);
  2110. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2111. if(!luaspell || luaspell->resisted) {
  2112. lua_interface->ResetFunctionStack(state);
  2113. return 0;
  2114. }
  2115. int64 class_req = 0;
  2116. int32 class_id = 0;
  2117. vector<int16> faction_req;
  2118. vector<int16> race_req;
  2119. int32 i = 0;
  2120. int8 f = 0;
  2121. int8 r = 0;
  2122. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2123. if (class_id < 100) {
  2124. class_req += pow(2.0, double(class_id - 1));
  2125. }
  2126. else if (class_id > 100 && class_id < 1000) {
  2127. race_req.push_back(class_id);
  2128. r++;
  2129. }
  2130. else {
  2131. faction_req.push_back(class_id);
  2132. f++;
  2133. }
  2134. i++;
  2135. }
  2136. if (value != 0 && type >= 0) {
  2137. if (luaspell && luaspell->spell && luaspell->caster) {
  2138. ZoneServer* zone = luaspell->caster->GetZone();
  2139. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2140. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2141. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2142. if (target) {
  2143. if (target->IsPlayer()) {
  2144. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2145. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2146. if (((Player*)target)->GetGroupMemberInfo())
  2147. ((Player*)target)->UpdateGroupMemberInfo();
  2148. ((Player*)target)->SetCharSheetChanged(true);
  2149. }
  2150. else if (target->IsNPC())
  2151. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2152. else
  2153. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2154. }
  2155. }
  2156. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2157. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2158. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2159. }
  2160. else if (spawn && spawn->IsEntity()) {
  2161. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2162. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2163. if (spawn->IsPlayer())
  2164. ((Player*)spawn)->SetCharSheetChanged(true);
  2165. }
  2166. else
  2167. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2168. }
  2169. else
  2170. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2171. return 0;
  2172. }
  2173. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2174. if (!lua_interface)
  2175. return 0;
  2176. Spawn* spawn = lua_interface->GetSpawn(state);
  2177. int16 type = lua_interface->GetInt16Value(state, 2);
  2178. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2179. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2180. if (!spawn) {
  2181. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2182. return 0;
  2183. }
  2184. if (!spawn->IsEntity()) {
  2185. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2186. return 0;
  2187. }
  2188. if (value == 0) {
  2189. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2190. return 0;
  2191. }
  2192. if (!luaspell || !luaspell->spell) {
  2193. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2194. return 0;
  2195. }
  2196. if(luaspell->resisted) {
  2197. lua_interface->ResetFunctionStack(state);
  2198. return 0;
  2199. }
  2200. int32 class_req = 0;
  2201. vector<int16> faction_req;
  2202. vector<int16> race_req;
  2203. int32 class_id = 0;
  2204. int32 i = 0;
  2205. int8 f = 0;
  2206. int8 r = 0;
  2207. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2208. if (class_id < 100) {
  2209. class_req += pow(2.0, double(class_id - 1));
  2210. }
  2211. else if (class_id > 100 && class_id < 1000) {
  2212. race_req.push_back(class_id);
  2213. r++;
  2214. }
  2215. else {
  2216. faction_req.push_back(class_id);
  2217. f++;
  2218. }
  2219. i++;
  2220. }
  2221. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2222. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2223. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2224. if (spawn->IsPlayer())
  2225. ((Player*)spawn)->SetCharSheetChanged(true);
  2226. return 0;
  2227. }
  2228. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2229. if (!lua_interface)
  2230. return 0;
  2231. Spawn* spawn = lua_interface->GetSpawn(state);
  2232. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2233. if (!spawn) {
  2234. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2235. return 0;
  2236. }
  2237. if (!spawn->IsEntity()) {
  2238. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2239. return 0;
  2240. }
  2241. if (!luaspell || !luaspell->spell) {
  2242. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2243. return 0;
  2244. }
  2245. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2246. if (spawn->IsPlayer())
  2247. ((Player*)spawn)->SetCharSheetChanged(true);
  2248. return 0;
  2249. }
  2250. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2251. if (!lua_interface)
  2252. return 0;
  2253. Spawn* spawn = lua_interface->GetSpawn(state);
  2254. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2255. if (luaspell && luaspell->spell) {
  2256. ZoneServer* zone = luaspell->caster->GetZone();
  2257. Spawn* target = 0;
  2258. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2259. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2260. target = zone->GetSpawnByID(luaspell->targets[i]);
  2261. if (target && target->IsEntity()) {
  2262. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2263. if (target->IsPlayer())
  2264. ((Player*)target)->SetCharSheetChanged(true);
  2265. }
  2266. }
  2267. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2268. }
  2269. else if (spawn && spawn->IsEntity()) {
  2270. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2271. if (spawn->IsPlayer())
  2272. ((Player*)spawn)->SetCharSheetChanged(true);
  2273. }
  2274. return 0;
  2275. }
  2276. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2277. if (!lua_interface)
  2278. return 0;
  2279. Spawn* spawn = lua_interface->GetSpawn(state);
  2280. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2281. float value = lua_interface->GetFloatValue(state, 3);
  2282. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2283. if (value != 0) {
  2284. int32 spell_id = 0;
  2285. if (luaspell && luaspell->spell && luaspell->caster) {
  2286. if(luaspell->resisted) {
  2287. lua_interface->ResetFunctionStack(state);
  2288. return 0;
  2289. }
  2290. spell_id = luaspell->spell->GetSpellID();
  2291. ZoneServer* zone = luaspell->caster->GetZone();
  2292. Spawn* target = 0;
  2293. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2294. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2295. target = zone->GetSpawnByID(luaspell->targets[i]);
  2296. if (target && target->Alive()) {
  2297. if (target->IsPlayer()) {
  2298. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2299. Client* client = ((Player*)target)->GetClient();
  2300. if (client) {
  2301. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2302. if (packet)
  2303. client->QueuePacket(packet);
  2304. }
  2305. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2306. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2307. }
  2308. else if (target->IsNPC()) {
  2309. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2310. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2311. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2312. }
  2313. else
  2314. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2315. }
  2316. }
  2317. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2318. }
  2319. else if (spawn) {
  2320. if (spawn->IsPlayer()) {
  2321. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2322. Client* client = ((Player*)spawn)->GetClient();
  2323. if (client) {
  2324. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2325. if (packet)
  2326. client->QueuePacket(packet);
  2327. }
  2328. }
  2329. else if (spawn->IsNPC())
  2330. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2331. else
  2332. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2333. }
  2334. }
  2335. else
  2336. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2337. return 0;
  2338. }
  2339. int EQ2Emu_lua_RemoveSkillBonus(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 && spawn->IsPlayer()) {
  2345. int32 spell_id = 0;
  2346. if (luaspell && luaspell->spell) {
  2347. if(luaspell->resisted) {
  2348. lua_interface->ResetFunctionStack(state);
  2349. return 0;
  2350. }
  2351. spell_id = luaspell->spell->GetSpellID();
  2352. ZoneServer* zone = luaspell->caster->GetZone();
  2353. Spawn* target = 0;
  2354. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2355. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2356. target = zone->GetSpawnByID(luaspell->targets[i]);
  2357. if (target) {
  2358. if (target->IsPlayer()) {
  2359. ((Player*)target)->RemoveSkillBonus(spell_id);
  2360. Client* client = ((Player*)target)->GetClient();
  2361. if (client) {
  2362. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2363. if (packet)
  2364. client->QueuePacket(packet);
  2365. }
  2366. }
  2367. else if (target->IsNPC())
  2368. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2369. else
  2370. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2371. }
  2372. }
  2373. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2374. }
  2375. else if (spawn) {
  2376. if (spawn->IsPlayer()) {
  2377. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2378. Client* client = ((Player*)spawn)->GetClient();
  2379. if (client) {
  2380. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2381. if (packet)
  2382. client->QueuePacket(packet);
  2383. }
  2384. }
  2385. else if (spawn->IsNPC())
  2386. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2387. else
  2388. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2389. }
  2390. }
  2391. return 0;
  2392. }
  2393. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2394. if (!lua_interface)
  2395. return 0;
  2396. Spawn* spawn = lua_interface->GetSpawn(state);
  2397. int8 type = lua_interface->GetInt32Value(state, 2);
  2398. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2399. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2400. if(luaspell && luaspell->resisted) {
  2401. lua_interface->ResetFunctionStack(state);
  2402. return 0;
  2403. }
  2404. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2405. ZoneServer* zone = luaspell->caster->GetZone();
  2406. Spawn* target = 0;
  2407. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2408. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2409. target = zone->GetSpawnByID(luaspell->targets[i]);
  2410. if (target && target->IsEntity()) {
  2411. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2412. ((Entity*)target)->AddMezSpell(luaspell);
  2413. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2414. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2415. if (target->IsNPC())
  2416. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2417. }
  2418. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2419. ((Entity*)target)->AddStifleSpell(luaspell);
  2420. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2421. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2422. if (target->IsNPC())
  2423. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2424. }
  2425. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2426. ((Entity*)target)->AddDazeSpell(luaspell);
  2427. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2428. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2429. if (target->IsNPC())
  2430. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2431. }
  2432. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2433. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2434. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2435. ((Entity*)target)->AddStunSpell(luaspell);
  2436. if (target->IsNPC())
  2437. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2438. }
  2439. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2440. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2441. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2442. ((Entity*)target)->AddRootSpell(luaspell);
  2443. if (target->IsNPC())
  2444. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2445. }
  2446. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2447. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2448. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2449. ((Entity*)target)->AddFearSpell(luaspell);
  2450. if (target->IsNPC())
  2451. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2452. }
  2453. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2454. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2455. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2456. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2457. }
  2458. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2459. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2460. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2461. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2462. }
  2463. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2464. ((Entity*)target)->AddSnareSpell(luaspell);
  2465. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2466. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2467. if (target->IsNPC())
  2468. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2469. }
  2470. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2471. ((Entity*)target)->AddFlightSpell(luaspell);
  2472. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2473. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2474. }
  2475. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2476. ((Entity*)target)->AddGlideSpell(luaspell);
  2477. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2478. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2479. }
  2480. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2481. ((Entity*)target)->AddSafefallSpell(luaspell);
  2482. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2483. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2484. }
  2485. else
  2486. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2487. }
  2488. else
  2489. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2490. }
  2491. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2492. }
  2493. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2494. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2495. ((Entity*)spawn)->AddMezSpell(luaspell);
  2496. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2497. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2498. }
  2499. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2500. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2501. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2502. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2503. }
  2504. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2505. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2506. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2507. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2508. }
  2509. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2510. ((Entity*)spawn)->AddStunSpell(luaspell);
  2511. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2512. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2513. }
  2514. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2515. ((Entity*)spawn)->AddRootSpell(luaspell);
  2516. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2517. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2518. }
  2519. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2520. ((Entity*)spawn)->AddFearSpell(luaspell);
  2521. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2522. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2523. }
  2524. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2525. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2526. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2527. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2528. }
  2529. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2530. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2531. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2532. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2533. }
  2534. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2535. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2536. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2537. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2538. }
  2539. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2540. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2541. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2542. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2543. }
  2544. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2545. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2546. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2547. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2548. }
  2549. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2550. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2551. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2552. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2553. }
  2554. else
  2555. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2556. }
  2557. else
  2558. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2559. return 0;
  2560. }
  2561. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2562. if (!lua_interface)
  2563. return 0;
  2564. Spawn* spawn = lua_interface->GetSpawn(state);
  2565. int8 type = lua_interface->GetInt8Value(state, 2);
  2566. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2567. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2568. if (spawn && spawn->IsEntity()) {
  2569. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2570. ZoneServer* zone = luaspell->caster->GetZone();
  2571. Spawn* target = 0;
  2572. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2573. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2574. target = zone->GetSpawnByID(luaspell->targets[i]);
  2575. if (target) {
  2576. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2577. ((Entity*)target)->RemoveMezSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2579. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2581. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2583. ((Entity*)target)->RemoveStunSpell(luaspell);
  2584. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2585. ((Entity*)target)->RemoveRootSpell(luaspell);
  2586. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2587. ((Entity*)target)->RemoveFearSpell(luaspell);
  2588. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2589. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2590. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2591. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2592. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2593. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2594. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2595. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2596. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2597. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2598. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2599. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2600. else
  2601. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2602. }
  2603. }
  2604. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2605. }
  2606. else if (only_remove_spawn) {
  2607. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2608. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2609. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2610. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2611. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2612. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2613. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2614. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2615. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2616. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2617. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2618. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2619. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2620. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2621. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2622. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2623. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2624. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2625. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2626. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2627. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2628. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2629. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2630. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2631. else
  2632. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2633. }
  2634. }
  2635. return 0;
  2636. }
  2637. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2638. if (!lua_interface)
  2639. return 0;
  2640. Spawn* spawn = lua_interface->GetSpawn(state);
  2641. int8 type = lua_interface->GetInt8Value(state, 2);
  2642. bool hasEffect = false;
  2643. if (!spawn)
  2644. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2645. else if (!spawn->IsEntity())
  2646. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2647. else if (type < CONTROL_MAX_EFFECTS)
  2648. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2649. else
  2650. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2651. lua_interface->SetBooleanValue(state, hasEffect);
  2652. return 1;
  2653. }
  2654. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2655. if (!lua_interface)
  2656. return 0;
  2657. Spawn* spawn = lua_interface->GetSpawn(state);
  2658. float distance = 0.0f;
  2659. if (!spawn)
  2660. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2661. else if (!spawn->IsNPC())
  2662. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2663. else
  2664. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2665. lua_interface->SetFloatValue(state, distance);
  2666. return 1;
  2667. }
  2668. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2669. if (!lua_interface)
  2670. return 0;
  2671. Spawn* spawn = lua_interface->GetSpawn(state);
  2672. float distance = 0.0f;
  2673. if (!spawn)
  2674. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2675. else if (!spawn->IsNPC())
  2676. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2677. else
  2678. distance = ((NPC*)spawn)->GetAggroRadius();
  2679. lua_interface->SetFloatValue(state, distance);
  2680. return 1;
  2681. }
  2682. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2683. if (!lua_interface)
  2684. return 0;
  2685. Spawn* spawn = lua_interface->GetSpawn(state);
  2686. float distance = lua_interface->GetFloatValue(state, 2);
  2687. bool override = lua_interface->GetBooleanValue(state, 3);
  2688. bool result = false;
  2689. lua_interface->ResetFunctionStack(state);
  2690. if (!spawn)
  2691. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2692. else if (!spawn->IsNPC())
  2693. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2694. else
  2695. {
  2696. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2697. result = true;
  2698. }
  2699. lua_interface->SetBooleanValue(state, result);
  2700. return 1;
  2701. }
  2702. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2703. if (!lua_interface)
  2704. return 0;
  2705. Spawn* spawn = lua_interface->GetSpawn(state);
  2706. int16 value = lua_interface->GetInt16Value(state, 2);
  2707. if (spawn && spawn->IsEntity()) {
  2708. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2709. if (spawn->IsPlayer())
  2710. ((Player*)spawn)->SetCharSheetChanged(true);
  2711. }
  2712. return 0;
  2713. }
  2714. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2715. if (!lua_interface)
  2716. return 0;
  2717. Spawn* spawn = lua_interface->GetSpawn(state);
  2718. int16 value = lua_interface->GetInt16Value(state, 2);
  2719. if (spawn && spawn->IsEntity()) {
  2720. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2721. if (spawn->IsPlayer())
  2722. ((Player*)spawn)->SetCharSheetChanged(true);
  2723. }
  2724. return 0;
  2725. }
  2726. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2727. if (!lua_interface)
  2728. return 0;
  2729. Spawn* spawn = lua_interface->GetSpawn(state);
  2730. int16 value = lua_interface->GetInt16Value(state, 2);
  2731. if (spawn && spawn->IsEntity()) {
  2732. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2733. if (spawn->IsPlayer())
  2734. ((Player*)spawn)->SetCharSheetChanged(true);
  2735. }
  2736. return 0;
  2737. }
  2738. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2739. if (!lua_interface)
  2740. return 0;
  2741. Spawn* spawn = lua_interface->GetSpawn(state);
  2742. int16 value = lua_interface->GetInt16Value(state, 2);
  2743. if (spawn && spawn->IsEntity()) {
  2744. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2745. if (spawn->IsPlayer())
  2746. ((Player*)spawn)->SetCharSheetChanged(true);
  2747. }
  2748. return 0;
  2749. }
  2750. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2751. if (!lua_interface)
  2752. return 0;
  2753. Spawn* spawn = lua_interface->GetSpawn(state);
  2754. int16 value = lua_interface->GetInt16Value(state, 2);
  2755. if (spawn && spawn->IsEntity()) {
  2756. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2757. if (spawn->IsPlayer())
  2758. ((Player*)spawn)->SetCharSheetChanged(true);
  2759. }
  2760. return 0;
  2761. }
  2762. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2763. if (!lua_interface)
  2764. return 0;
  2765. Spawn* spawn = lua_interface->GetSpawn(state);
  2766. int8 value = lua_interface->GetInt8Value(state, 2);
  2767. if (spawn && spawn->IsEntity()) {
  2768. ((Entity*)spawn)->SetDeity(value);
  2769. if (spawn->IsPlayer())
  2770. ((Player*)spawn)->SetCharSheetChanged(true);
  2771. }
  2772. lua_interface->ResetFunctionStack(state);
  2773. return 0;
  2774. }
  2775. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. if (spawn && spawn->IsEntity()) {
  2780. int8 deity = ((Entity*)spawn)->GetDeity();
  2781. lua_interface->SetInt32Value(state, deity);
  2782. return 1;
  2783. }
  2784. return 0;
  2785. }
  2786. int EQ2Emu_lua_SetInt(lua_State* state) {
  2787. if (!lua_interface)
  2788. return 0;
  2789. Spawn* spawn = lua_interface->GetSpawn(state);
  2790. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2791. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2792. if (spawn && spawn->IsEntity()) {
  2793. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2794. if (spawn->IsPlayer())
  2795. ((Player*)spawn)->SetCharSheetChanged(true);
  2796. }
  2797. return 0;
  2798. }
  2799. int EQ2Emu_lua_SetWis(lua_State* state) {
  2800. if (!lua_interface)
  2801. return 0;
  2802. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. float value = lua_interface->GetFloatValue(state, 2);
  2805. if (spawn && spawn->IsEntity()) {
  2806. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2807. if (spawn->IsPlayer())
  2808. ((Player*)spawn)->SetCharSheetChanged(true);
  2809. }
  2810. return 0;
  2811. }
  2812. int EQ2Emu_lua_SetSta(lua_State* state) {
  2813. if (!lua_interface)
  2814. return 0;
  2815. Spawn* spawn = lua_interface->GetSpawn(state);
  2816. float value = lua_interface->GetFloatValue(state, 2);
  2817. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2818. if (spawn && spawn->IsEntity()) {
  2819. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2820. if (spawn->IsPlayer())
  2821. ((Player*)spawn)->SetCharSheetChanged(true);
  2822. }
  2823. return 0;
  2824. }
  2825. int EQ2Emu_lua_SetStr(lua_State* state) {
  2826. if (!lua_interface)
  2827. return 0;
  2828. Spawn* spawn = lua_interface->GetSpawn(state);
  2829. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2830. float value = lua_interface->GetFloatValue(state, 2);
  2831. if (spawn && spawn->IsEntity()) {
  2832. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2833. if (spawn->IsPlayer())
  2834. ((Player*)spawn)->SetCharSheetChanged(true);
  2835. }
  2836. return 0;
  2837. }
  2838. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2839. if (!lua_interface)
  2840. return 0;
  2841. Spawn* spawn = lua_interface->GetSpawn(state);
  2842. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2843. float value = lua_interface->GetFloatValue(state, 2);
  2844. if (spawn && spawn->IsEntity()) {
  2845. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2846. if (spawn->IsPlayer())
  2847. ((Player*)spawn)->SetCharSheetChanged(true);
  2848. }
  2849. return 0;
  2850. }
  2851. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2852. if (!lua_interface)
  2853. return 0;
  2854. Spawn* spawn = lua_interface->GetSpawn(state);
  2855. if (spawn) {
  2856. lua_interface->SetInt32Value(state, spawn->GetHP());
  2857. return 1;
  2858. }
  2859. return 0;
  2860. }
  2861. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2862. if (!lua_interface)
  2863. return 0;
  2864. Spawn* spawn = lua_interface->GetSpawn(state);
  2865. if (spawn) {
  2866. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2867. return 1;
  2868. }
  2869. return 0;
  2870. }
  2871. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2872. if (!lua_interface)
  2873. return 0;
  2874. Spawn* spawn = lua_interface->GetSpawn(state);
  2875. if (spawn) {
  2876. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2877. return 1;
  2878. }
  2879. return 0;
  2880. }
  2881. int EQ2Emu_lua_GetName(lua_State* state) {
  2882. if (!lua_interface)
  2883. return 0;
  2884. Spawn* spawn = lua_interface->GetSpawn(state);
  2885. if (spawn) {
  2886. lua_interface->SetStringValue(state, spawn->GetName());
  2887. return 1;
  2888. }
  2889. return 0;
  2890. }
  2891. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2892. Spawn* spawn = lua_interface->GetSpawn(state);
  2893. if (spawn) {
  2894. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2895. return 1;
  2896. }
  2897. return 0;
  2898. }
  2899. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2900. if (!lua_interface)
  2901. return 0;
  2902. Spawn* spawn = lua_interface->GetSpawn(state);
  2903. if (spawn) {
  2904. lua_interface->SetInt32Value(state, spawn->GetPower());
  2905. return 1;
  2906. }
  2907. return 0;
  2908. }
  2909. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2910. if (!lua_interface)
  2911. return 0;
  2912. Spawn* spawn = lua_interface->GetSpawn(state);
  2913. if (spawn) {
  2914. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2915. return 1;
  2916. }
  2917. return 0;
  2918. }
  2919. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2920. if (!lua_interface)
  2921. return 0;
  2922. Spawn* spawn = lua_interface->GetSpawn(state);
  2923. if (spawn) {
  2924. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2925. return 1;
  2926. }
  2927. return 0;
  2928. }
  2929. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2930. if (!lua_interface)
  2931. return 0;
  2932. Spawn* spawn = lua_interface->GetSpawn(state);
  2933. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2934. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2935. if (spawn && spawn2) {
  2936. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2937. lua_interface->SetFloatValue(state, distance);
  2938. return 1;
  2939. }
  2940. return 0;
  2941. }
  2942. int EQ2Emu_lua_GetX(lua_State* state) {
  2943. if (!lua_interface)
  2944. return 0;
  2945. Spawn* spawn = lua_interface->GetSpawn(state);
  2946. if (spawn) {
  2947. lua_interface->SetFloatValue(state, spawn->GetX());
  2948. return 1;
  2949. }
  2950. return 0;
  2951. }
  2952. int EQ2Emu_lua_GetY(lua_State* state) {
  2953. if (!lua_interface)
  2954. return 0;
  2955. Spawn* spawn = lua_interface->GetSpawn(state);
  2956. if (spawn) {
  2957. lua_interface->SetFloatValue(state, spawn->GetY());
  2958. return 1;
  2959. }
  2960. return 0;
  2961. }
  2962. int EQ2Emu_lua_GetZ(lua_State* state) {
  2963. if (!lua_interface)
  2964. return 0;
  2965. Spawn* spawn = lua_interface->GetSpawn(state);
  2966. if (spawn) {
  2967. lua_interface->SetFloatValue(state, spawn->GetZ());
  2968. return 1;
  2969. }
  2970. return 0;
  2971. }
  2972. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2973. if (!lua_interface)
  2974. return 0;
  2975. Spawn* spawn = lua_interface->GetSpawn(state);
  2976. if (spawn) {
  2977. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_GetModelType(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->GetModelType());
  2988. return 1;
  2989. }
  2990. return 0;
  2991. }
  2992. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2993. if (!lua_interface)
  2994. return 0;
  2995. Spawn* spawn = lua_interface->GetSpawn(state);
  2996. if (spawn) {
  2997. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2998. return 1;
  2999. }
  3000. return 0;
  3001. }
  3002. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3003. if (!lua_interface)
  3004. return 0;
  3005. Spawn* spawn = lua_interface->GetSpawn(state);
  3006. if (spawn && spawn->IsEntity()) {
  3007. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3008. return 1;
  3009. }
  3010. return 0;
  3011. }
  3012. int EQ2Emu_lua_GetInt(lua_State* state) {
  3013. if (!lua_interface)
  3014. return 0;
  3015. Spawn* spawn = lua_interface->GetSpawn(state);
  3016. if (spawn && spawn->IsEntity()) {
  3017. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3018. return 1;
  3019. }
  3020. return 0;
  3021. }
  3022. int EQ2Emu_lua_GetWis(lua_State* state) {
  3023. if (!lua_interface)
  3024. return 0;
  3025. Spawn* spawn = lua_interface->GetSpawn(state);
  3026. if (spawn && spawn->IsEntity()) {
  3027. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3028. return 1;
  3029. }
  3030. return 0;
  3031. }
  3032. int EQ2Emu_lua_GetSta(lua_State* state) {
  3033. if (!lua_interface)
  3034. return 0;
  3035. Spawn* spawn = lua_interface->GetSpawn(state);
  3036. if (spawn && spawn->IsEntity()) {
  3037. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3038. return 1;
  3039. }
  3040. return 0;
  3041. }
  3042. int EQ2Emu_lua_GetStr(lua_State* state) {
  3043. if (!lua_interface)
  3044. return 0;
  3045. Spawn* spawn = lua_interface->GetSpawn(state);
  3046. if (spawn && spawn->IsEntity()) {
  3047. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3048. return 1;
  3049. }
  3050. return 0;
  3051. }
  3052. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3053. if (!lua_interface)
  3054. return 0;
  3055. Spawn* spawn = lua_interface->GetSpawn(state);
  3056. if (spawn && spawn->IsEntity()) {
  3057. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3058. return 1;
  3059. }
  3060. return 0;
  3061. }
  3062. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3063. if (!lua_interface)
  3064. return 0;
  3065. Spawn* spawn = lua_interface->GetSpawn(state);
  3066. if (spawn && spawn->IsEntity()) {
  3067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3068. return 1;
  3069. }
  3070. return 0;
  3071. }
  3072. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3073. if (!lua_interface)
  3074. return 0;
  3075. Spawn* spawn = lua_interface->GetSpawn(state);
  3076. if (spawn && spawn->IsEntity()) {
  3077. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3078. return 1;
  3079. }
  3080. return 0;
  3081. }
  3082. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3083. if (!lua_interface)
  3084. return 0;
  3085. Spawn* spawn = lua_interface->GetSpawn(state);
  3086. if (spawn && spawn->IsEntity()) {
  3087. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3088. return 1;
  3089. }
  3090. return 0;
  3091. }
  3092. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3093. if (!lua_interface)
  3094. return 0;
  3095. Spawn* spawn = lua_interface->GetSpawn(state);
  3096. if (spawn && spawn->IsEntity()) {
  3097. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3098. return 1;
  3099. }
  3100. return 0;
  3101. }
  3102. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3103. if (!lua_interface)
  3104. return 0;
  3105. Spawn* spawn = lua_interface->GetSpawn(state);
  3106. if (spawn && spawn->IsEntity()) {
  3107. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3108. return 1;
  3109. }
  3110. return 0;
  3111. }
  3112. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3113. if (!lua_interface)
  3114. return 0;
  3115. Spawn* player = lua_interface->GetSpawn(state);
  3116. if (!player || !player->IsPlayer()) {
  3117. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3118. return 0;
  3119. }
  3120. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3121. if (quest_id <= 0) {
  3122. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3123. return 0;
  3124. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3125. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3126. return 0;
  3127. }
  3128. int32 step = lua_interface->GetInt32Value(state, 3);
  3129. if (step > 0) {
  3130. Client* client = ((Player*)player)->GetClient();
  3131. if (client)
  3132. client->AddPendingQuestUpdate(quest_id, step);
  3133. } else {
  3134. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3135. }
  3136. return 0;
  3137. }
  3138. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3139. Spawn* player = lua_interface->GetSpawn(state);
  3140. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3141. int32 step = lua_interface->GetInt32Value(state, 3);
  3142. int32 progress = lua_interface->GetInt32Value(state, 4);
  3143. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3144. Client* client = ((Player*)player)->GetClient();
  3145. if (client)
  3146. client->AddPendingQuestUpdate(quest_id, step, progress);
  3147. }
  3148. return 0;
  3149. }
  3150. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3151. if (!lua_interface)
  3152. return 0;
  3153. Spawn* player = lua_interface->GetSpawn(state);
  3154. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3155. if (player && player->IsPlayer() && quest_id > 0) {
  3156. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3157. return 1;
  3158. }
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Spawn* player = lua_interface->GetSpawn(state);
  3165. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3166. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3167. if (player && player->IsPlayer() && quest_id > 0) {
  3168. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3169. return 1;
  3170. }
  3171. return 0;
  3172. }
  3173. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3174. if (!lua_interface)
  3175. return 0;
  3176. Spawn* player = lua_interface->GetSpawn(state);
  3177. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3178. if (player && player->IsPlayer() && quest_id > 0) {
  3179. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3180. return 1;
  3181. }
  3182. return 0;
  3183. }
  3184. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3185. if (!lua_interface)
  3186. return 0;
  3187. Quest* quest = lua_interface->GetQuest(state);
  3188. string name = lua_interface->GetStringValue(state, 2);
  3189. string type = lua_interface->GetStringValue(state, 3);
  3190. string zone = lua_interface->GetStringValue(state, 4);
  3191. int16 level = lua_interface->GetInt16Value(state, 5);
  3192. string description = lua_interface->GetStringValue(state, 6);
  3193. bool load = true;
  3194. if (!quest) {
  3195. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3196. load = false;
  3197. }
  3198. if (load && name.length() == 0) {
  3199. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3200. load = false;
  3201. }
  3202. if (load && type.length() == 0) {
  3203. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3204. load = false;
  3205. }
  3206. if (load && zone.length() == 0) {
  3207. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3208. load = false;
  3209. }
  3210. if (load && description.length() == 0) {
  3211. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3212. load = false;
  3213. }
  3214. if (load && level == 0) {
  3215. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3216. load = false;
  3217. }
  3218. if (load)
  3219. quest->RegisterQuest(name, type, zone, level, description);
  3220. return 0;
  3221. }
  3222. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3223. if (!lua_interface)
  3224. return 0;
  3225. Quest* quest = lua_interface->GetQuest(state);
  3226. if (quest) {
  3227. int8 level = lua_interface->GetInt16Value(state, 2);
  3228. quest->SetPrereqLevel(level);
  3229. }
  3230. return 0;
  3231. }
  3232. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3233. if (!lua_interface)
  3234. return 0;
  3235. Quest* quest = lua_interface->GetQuest(state);
  3236. if (quest) {
  3237. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3238. quest->AddPrereqQuest(quest_id);
  3239. }
  3240. return 0;
  3241. }
  3242. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3243. if (!lua_interface)
  3244. return 0;
  3245. Quest* quest = lua_interface->GetQuest(state);
  3246. if (quest) {
  3247. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3248. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3249. if (quantity == 0)
  3250. quantity = 1;
  3251. Item* master_item = master_item_list.GetItem(item_id);
  3252. if (master_item) {
  3253. Item* item = new Item(master_item);
  3254. item->details.count = quantity;
  3255. quest->AddPrereqItem(item);
  3256. }
  3257. }
  3258. return 0;
  3259. }
  3260. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3261. if (!lua_interface)
  3262. return 0;
  3263. Spawn* player = lua_interface->GetSpawn(state);
  3264. if(!player || !player->IsPlayer()) {
  3265. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3266. return 0;
  3267. }
  3268. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3269. if (quest_id > 0) {
  3270. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3271. return 1;
  3272. } else {
  3273. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3274. }
  3275. return 0;
  3276. }
  3277. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3278. if (!lua_interface)
  3279. return 0;
  3280. Quest* quest = lua_interface->GetQuest(state);
  3281. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3282. lua_interface->ResetFunctionStack(state);
  3283. if (quest && spawn_id > 0)
  3284. quest->SetQuestReturnNPC(spawn_id);
  3285. return 0;
  3286. }
  3287. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3288. if (!lua_interface)
  3289. return 0;
  3290. Spawn* spawn = lua_interface->GetSpawn(state);
  3291. int32 time = lua_interface->GetInt32Value(state, 2);
  3292. string function = lua_interface->GetStringValue(state, 3);
  3293. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3294. Spawn* player = lua_interface->GetSpawn(state, 5);
  3295. lua_interface->ResetFunctionStack(state);
  3296. if (!spawn) {
  3297. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3298. return 0;
  3299. }
  3300. if (time <= 0) {
  3301. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3302. return 0;
  3303. }
  3304. if (function.length() == 0) {
  3305. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3306. return 0;
  3307. }
  3308. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3309. if ( time < 10)
  3310. time = 10;
  3311. timer->timer = Timer::GetCurrentTime2() + time;
  3312. timer->function = function;
  3313. timer->spawn = spawn->GetID();
  3314. timer->player = player ? player->GetID() : 0;
  3315. if (max_count == 0)
  3316. max_count = 1;
  3317. timer->max_count = max_count;
  3318. timer->current_count = 0;
  3319. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3320. return 0;
  3321. }
  3322. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3323. if (!lua_interface)
  3324. return 0;
  3325. Spawn* spawn = lua_interface->GetSpawn(state);
  3326. string function = lua_interface->GetStringValue(state, 2);
  3327. lua_interface->ResetFunctionStack(state);
  3328. if (!spawn) {
  3329. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3330. return 0;
  3331. }
  3332. if(!spawn->GetZone()) {
  3333. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3334. return 0;
  3335. }
  3336. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3337. return 0;
  3338. }
  3339. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3340. if (!lua_interface)
  3341. return 0;
  3342. Spawn* player = lua_interface->GetSpawn(state);
  3343. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3344. lua_interface->ResetFunctionStack(state);
  3345. if (player && player->IsPlayer() && quest_id > 0) {
  3346. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3347. return 1;
  3348. }
  3349. return 0;
  3350. }
  3351. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3352. if (!lua_interface)
  3353. return 0;
  3354. Spawn* player = lua_interface->GetSpawn(state);
  3355. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3356. lua_interface->ResetFunctionStack(state);
  3357. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3358. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3359. if (quest)
  3360. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3361. return 1;
  3362. }
  3363. return 0;
  3364. }
  3365. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3366. if (!lua_interface)
  3367. return 0;
  3368. Spawn* player = lua_interface->GetSpawn(state);
  3369. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3370. lua_interface->ResetFunctionStack(state);
  3371. if (player && player->IsPlayer() && quest_id > 0) {
  3372. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3373. return 1;
  3374. }
  3375. return 0;
  3376. }
  3377. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3378. if (!lua_interface)
  3379. return 0;
  3380. Spawn* npc = lua_interface->GetSpawn(state);
  3381. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3382. lua_interface->ResetFunctionStack(state);
  3383. if (npc && !npc->IsPlayer() && quest_id > 0)
  3384. npc->AddProvidedQuest(quest_id);
  3385. return 0;
  3386. }
  3387. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3388. if (!lua_interface)
  3389. return 0;
  3390. Spawn* npc = lua_interface->GetSpawn(state);
  3391. Spawn* player = lua_interface->GetSpawn(state, 2);
  3392. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3393. bool forced = lua_interface->GetBooleanValue(state, 4);
  3394. lua_interface->ResetFunctionStack(state);
  3395. /* NPC is allowed to be null */
  3396. if (player && player->IsPlayer() && quest_id > 0) {
  3397. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3398. if (master_quest) {
  3399. Client* client = ((Player*)player)->GetClient();
  3400. if (!client) {
  3401. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3402. }
  3403. Quest* quest = new Quest(master_quest);
  3404. if (!quest) {
  3405. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3406. }
  3407. if (client && quest) {
  3408. if (npc)
  3409. quest->SetQuestGiver(npc->GetDatabaseID());
  3410. else
  3411. quest->SetQuestGiver(0);
  3412. client->AddPendingQuest(quest, forced);
  3413. }
  3414. }
  3415. else {
  3416. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3417. }
  3418. }
  3419. else {
  3420. 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);
  3421. }
  3422. return 0;
  3423. }
  3424. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3425. if (!lua_interface)
  3426. return 0;
  3427. Quest* quest = lua_interface->GetQuest(state);
  3428. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3429. lua_interface->ResetFunctionStack(state);
  3430. if (quest) {
  3431. quest->AddPrereqClass(class_id);
  3432. }
  3433. return 0;
  3434. }
  3435. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3436. if (!lua_interface)
  3437. return 0;
  3438. Quest* quest = lua_interface->GetQuest(state);
  3439. int8 race = lua_interface->GetInt8Value(state, 2);
  3440. lua_interface->ResetFunctionStack(state);
  3441. if (quest) {
  3442. quest->AddPrereqRace(race);
  3443. }
  3444. return 0;
  3445. }
  3446. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3447. if (!lua_interface)
  3448. return 0;
  3449. Quest* quest = lua_interface->GetQuest(state);
  3450. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3451. lua_interface->ResetFunctionStack(state);
  3452. if (quest) {
  3453. quest->AddPrereqModelType(model_type);
  3454. }
  3455. return 0;
  3456. }
  3457. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3458. if (!lua_interface)
  3459. return 0;
  3460. Quest* quest = lua_interface->GetQuest(state);
  3461. int8 level = lua_interface->GetInt8Value(state, 2);
  3462. lua_interface->ResetFunctionStack(state);
  3463. if (!quest) {
  3464. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3465. return 0;
  3466. }
  3467. quest->SetPrereqTSLevel(level);
  3468. return 0;
  3469. }
  3470. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3471. if (!lua_interface)
  3472. return 0;
  3473. Quest* quest = lua_interface->GetQuest(state);
  3474. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3475. lua_interface->ResetFunctionStack(state);
  3476. if (!quest) {
  3477. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3478. return 0;
  3479. }
  3480. quest->AddPrereqTradeskillClass(class_id);
  3481. return 0;
  3482. }
  3483. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3484. if (!lua_interface)
  3485. return 0;
  3486. Quest* quest = lua_interface->GetQuest(state);
  3487. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3488. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3489. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3490. lua_interface->ResetFunctionStack(state);
  3491. if (quest) {
  3492. quest->AddPrereqFaction(faction_id, min, max);
  3493. }
  3494. return 0;
  3495. }
  3496. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3497. if (!lua_interface)
  3498. return 0;
  3499. Quest* quest = lua_interface->GetQuest(state);
  3500. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3501. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3502. lua_interface->ResetFunctionStack(state);
  3503. if (quest) {
  3504. if (quantity == 0)
  3505. quantity = 1;
  3506. Item* master_item = master_item_list.GetItem(item_id);
  3507. if (master_item) {
  3508. Item* item = new Item(master_item);
  3509. item->details.count = quantity;
  3510. quest->AddSelectableRewardItem(item);
  3511. }
  3512. }
  3513. return 0;
  3514. }
  3515. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3516. if (!lua_interface)
  3517. return 0;
  3518. Quest* quest = lua_interface->GetQuest(state);
  3519. if (quest) {
  3520. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3521. vector<Item*>* items = quest->GetRewardItems();
  3522. if (items) {
  3523. vector<Item*>::iterator itr;
  3524. for (itr = items->begin(); itr != items->end(); itr++) {
  3525. if (*itr && (*itr)->details.item_id == item_id) {
  3526. lua_interface->SetBooleanValue(state, true);
  3527. return 1;
  3528. }
  3529. }
  3530. }
  3531. }
  3532. lua_interface->SetBooleanValue(state, false);
  3533. return 1;
  3534. }
  3535. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3536. if (!lua_interface)
  3537. return 0;
  3538. Quest* quest = lua_interface->GetQuest(state);
  3539. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3540. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3541. lua_interface->ResetFunctionStack(state);
  3542. if (quest) {
  3543. if (quantity == 0)
  3544. quantity = 1;
  3545. Item* master_item = master_item_list.GetItem(item_id);
  3546. if (master_item) {
  3547. Item* item = new Item(master_item);
  3548. item->details.count = quantity;
  3549. quest->AddRewardItem(item);
  3550. }
  3551. }
  3552. return 0;
  3553. }
  3554. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3555. if (!lua_interface)
  3556. return 0;
  3557. Quest* quest = lua_interface->GetQuest(state);
  3558. int32 copper = lua_interface->GetInt32Value(state, 2);
  3559. int32 silver = lua_interface->GetInt32Value(state, 3);
  3560. int32 gold = lua_interface->GetInt32Value(state, 4);
  3561. int32 plat = lua_interface->GetInt32Value(state, 5);
  3562. lua_interface->ResetFunctionStack(state);
  3563. if (quest) {
  3564. quest->AddRewardCoins(copper, silver, gold, plat);
  3565. }
  3566. return 0;
  3567. }
  3568. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3569. if (!lua_interface)
  3570. return 0;
  3571. Quest* quest = lua_interface->GetQuest(state);
  3572. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3573. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3574. lua_interface->ResetFunctionStack(state);
  3575. if (quest && faction_id > 0 && amount != 0)
  3576. quest->AddRewardFaction(faction_id, amount);
  3577. return 0;
  3578. }
  3579. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3580. if (!lua_interface)
  3581. return 0;
  3582. Quest* quest = lua_interface->GetQuest(state);
  3583. int32 status = lua_interface->GetInt32Value(state, 2);
  3584. lua_interface->ResetFunctionStack(state);
  3585. if (quest) {
  3586. quest->SetRewardStatus(status);
  3587. }
  3588. return 0;
  3589. }
  3590. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3591. if (!lua_interface)
  3592. return 0;
  3593. Quest* quest = lua_interface->GetQuest(state);
  3594. int32 status = lua_interface->GetInt32Value(state, 2);
  3595. lua_interface->ResetFunctionStack(state);
  3596. if (quest) {
  3597. quest->SetStatusTmpReward(status);
  3598. }
  3599. return 0;
  3600. }
  3601. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3602. if (!lua_interface)
  3603. return 0;
  3604. Quest* quest = lua_interface->GetQuest(state);
  3605. int64 coins = lua_interface->GetInt64Value(state, 2);
  3606. lua_interface->ResetFunctionStack(state);
  3607. if (quest) {
  3608. quest->SetCoinTmpReward(coins);
  3609. }
  3610. return 0;
  3611. }
  3612. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3613. if (!lua_interface)
  3614. return 0;
  3615. Quest* quest = lua_interface->GetQuest(state);
  3616. string comment = lua_interface->GetStringValue(state, 2);
  3617. lua_interface->ResetFunctionStack(state);
  3618. if (quest) {
  3619. quest->SetRewardComment(comment);
  3620. }
  3621. return 0;
  3622. }
  3623. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3624. if (!lua_interface)
  3625. return 0;
  3626. Quest* quest = lua_interface->GetQuest(state);
  3627. int32 exp = lua_interface->GetInt32Value(state, 2);
  3628. lua_interface->ResetFunctionStack(state);
  3629. if (quest) {
  3630. quest->SetRewardXP(exp);
  3631. }
  3632. return 0;
  3633. }
  3634. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3635. Quest* quest = lua_interface->GetQuest(state);
  3636. int32 step = lua_interface->GetInt32Value(state, 2);
  3637. string description = lua_interface->GetStringValue(state, 3);
  3638. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3639. float percentage = lua_interface->GetFloatValue(state, 5);
  3640. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3641. int16 icon = lua_interface->GetInt16Value(state, 7);
  3642. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3643. if (quest) {
  3644. const char* taskgroup = 0;
  3645. if (str_taskgroup.length() > 0)
  3646. taskgroup = str_taskgroup.c_str();
  3647. int32 id = 0;
  3648. vector<int32>* ids = 0;
  3649. int i = 0;
  3650. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3651. if (ids == 0)
  3652. ids = new vector<int32>;
  3653. ids->push_back(id);
  3654. i++;
  3655. }
  3656. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3657. if (quest_step && icon && quantity > 0)
  3658. quest_step->SetIcon(icon);
  3659. if (quest->GetPlayer()) {
  3660. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3661. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3662. }
  3663. }
  3664. lua_interface->ResetFunctionStack(state);
  3665. return 0;
  3666. }
  3667. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3668. {
  3669. if (!lua_interface)
  3670. return 0;
  3671. Quest* quest = lua_interface->GetQuest(state);
  3672. int32 step = lua_interface->GetInt32Value(state, 2);
  3673. string description = lua_interface->GetStringValue(state, 3);
  3674. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3675. float percentage = lua_interface->GetFloatValue(state, 5);
  3676. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3677. int16 icon = lua_interface->GetInt16Value(state, 7);
  3678. if (quest) {
  3679. const char* taskgroup = 0;
  3680. if (str_taskgroup.length() > 0)
  3681. taskgroup = str_taskgroup.c_str();
  3682. int32 id = 0;
  3683. vector<int32>* ids = 0;
  3684. int i = 0;
  3685. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3686. if (ids == 0)
  3687. ids = new vector<int32>;
  3688. ids->push_back(id);
  3689. i++;
  3690. }
  3691. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3692. if (quest_step && icon > 0 && quantity > 0)
  3693. quest_step->SetIcon(icon);
  3694. if (quest->GetPlayer()) {
  3695. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3696. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3697. }
  3698. safe_delete(ids);
  3699. }
  3700. lua_interface->ResetFunctionStack(state);
  3701. return 0;
  3702. }
  3703. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3704. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3705. }
  3706. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3707. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3708. }
  3709. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3710. if (!lua_interface)
  3711. return 0;
  3712. Quest* quest = lua_interface->GetQuest(state);
  3713. int32 step = lua_interface->GetInt32Value(state, 2);
  3714. string description = lua_interface->GetStringValue(state, 3);
  3715. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3716. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3717. int16 icon = lua_interface->GetInt16Value(state, 6);
  3718. if (quest) {
  3719. const char* taskgroup = 0;
  3720. if (str_taskgroup.length() > 0)
  3721. taskgroup = str_taskgroup.c_str();
  3722. int32 npc_id = 0;
  3723. vector<int32>* ids = 0;
  3724. int i = 0;
  3725. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3726. if (ids == 0)
  3727. ids = new vector<int32>;
  3728. ids->push_back(npc_id);
  3729. i++;
  3730. }
  3731. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3732. if (quest_step && icon > 0)
  3733. quest_step->SetIcon(icon);
  3734. if (quest->GetPlayer()) {
  3735. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3736. if(client)
  3737. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3738. }
  3739. safe_delete(ids);
  3740. }
  3741. lua_interface->ResetFunctionStack(state);
  3742. return 0;
  3743. }
  3744. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3745. if (!lua_interface)
  3746. return 0;
  3747. Quest* quest = lua_interface->GetQuest(state);
  3748. int32 step = lua_interface->GetInt32Value(state, 2);
  3749. string description = lua_interface->GetStringValue(state, 3);
  3750. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3751. float percentage = lua_interface->GetFloatValue(state, 5);
  3752. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3753. int16 icon = lua_interface->GetInt16Value(state, 7);
  3754. if (quest) {
  3755. const char* taskgroup = 0;
  3756. if (str_taskgroup.length() > 0)
  3757. taskgroup = str_taskgroup.c_str();
  3758. int32 item_id = 0;
  3759. vector<int32>* ids = 0;
  3760. int i = 0;
  3761. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3762. if (ids == 0)
  3763. ids = new vector<int32>;
  3764. ids->push_back(item_id);
  3765. i++;
  3766. }
  3767. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3768. if (quest_step && icon > 0 && quantity > 0)
  3769. quest_step->SetIcon(icon);
  3770. if (quest->GetPlayer()) {
  3771. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3772. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3773. }
  3774. safe_delete(ids);
  3775. }
  3776. lua_interface->ResetFunctionStack(state);
  3777. return 0;
  3778. }
  3779. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3780. if (!lua_interface)
  3781. return 0;
  3782. Quest* quest = lua_interface->GetQuest(state);
  3783. int32 step = lua_interface->GetInt32Value(state, 2);
  3784. string description = lua_interface->GetStringValue(state, 3);
  3785. float max_variation = lua_interface->GetFloatValue(state, 4);
  3786. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3787. int16 icon = lua_interface->GetInt16Value(state, 6);
  3788. if (quest) {
  3789. const char* taskgroup = 0;
  3790. if (str_taskgroup.length() > 0)
  3791. taskgroup = str_taskgroup.c_str();
  3792. vector<Location>* locations = 0;
  3793. int8 i = 7;
  3794. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3795. while (true) {
  3796. Location loc;
  3797. loc.x = lua_interface->GetFloatValue(state, i);
  3798. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3799. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3800. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3801. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3802. break;
  3803. if (locations == 0)
  3804. locations = new vector<Location>;
  3805. locations->push_back(loc);
  3806. i += 4;
  3807. }
  3808. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3809. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3810. if (quest_step && icon > 0)
  3811. quest_step->SetIcon(icon);
  3812. if (quest->GetPlayer()) {
  3813. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3814. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3815. }
  3816. }
  3817. lua_interface->ResetFunctionStack(state);
  3818. return 0;
  3819. }
  3820. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3821. if (!lua_interface)
  3822. return 0;
  3823. Quest* quest = lua_interface->GetQuest(state);
  3824. int32 step = lua_interface->GetInt32Value(state, 2);
  3825. string description = lua_interface->GetStringValue(state, 3);
  3826. float max_variation = lua_interface->GetFloatValue(state, 4);
  3827. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3828. int16 icon = lua_interface->GetInt16Value(state, 6);
  3829. if (quest) {
  3830. const char* taskgroup = 0;
  3831. if (str_taskgroup.length() > 0)
  3832. taskgroup = str_taskgroup.c_str();
  3833. vector<Location>* locations = 0;
  3834. int8 i = 7;
  3835. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3836. while (true) {
  3837. Location loc;
  3838. loc.x = lua_interface->GetFloatValue(state, i);
  3839. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3840. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3841. loc.zone_id = 0;
  3842. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3843. break;
  3844. if (locations == 0)
  3845. locations = new vector<Location>;
  3846. locations->push_back(loc);
  3847. i += 3;
  3848. }
  3849. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3850. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3851. if (quest_step && icon > 0)
  3852. quest_step->SetIcon(icon);
  3853. if (quest->GetPlayer()) {
  3854. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3855. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3856. }
  3857. }
  3858. lua_interface->ResetFunctionStack(state);
  3859. return 0;
  3860. }
  3861. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3862. if (!lua_interface)
  3863. return 0;
  3864. Quest* quest = lua_interface->GetQuest(state);
  3865. int32 step = lua_interface->GetInt32Value(state, 2);
  3866. string description = lua_interface->GetStringValue(state, 3);
  3867. float max_variation = lua_interface->GetFloatValue(state, 4);
  3868. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3869. int16 icon = lua_interface->GetInt16Value(state, 6);
  3870. if (quest) {
  3871. const char* taskgroup = 0;
  3872. if (str_taskgroup.length() > 0)
  3873. taskgroup = str_taskgroup.c_str();
  3874. vector<Location>* locations = 0;
  3875. int i = 7;
  3876. while (true) {
  3877. Location loc;
  3878. loc.x = lua_interface->GetFloatValue(state, i);
  3879. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3880. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3881. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3882. break;
  3883. if (locations == 0)
  3884. locations = new vector<Location>;
  3885. locations->push_back(loc);
  3886. i += 3;
  3887. }
  3888. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3889. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3890. if (quest_step && icon > 0)
  3891. quest_step->SetIcon(icon);
  3892. if (quest->GetPlayer()) {
  3893. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3894. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3895. }
  3896. }
  3897. lua_interface->ResetFunctionStack(state);
  3898. return 0;
  3899. }
  3900. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3901. Quest* quest = lua_interface->GetQuest(state);
  3902. int32 step = lua_interface->GetInt32Value(state, 2);
  3903. string description = lua_interface->GetStringValue(state, 3);
  3904. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3905. float percentage = lua_interface->GetFloatValue(state, 5);
  3906. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3907. int16 icon = lua_interface->GetInt16Value(state, 7);
  3908. if (quest) {
  3909. const char* taskgroup = 0;
  3910. if (str_taskgroup.length() > 0)
  3911. taskgroup = str_taskgroup.c_str();
  3912. int32 spell_id = 0;
  3913. vector<int32>* ids = 0;
  3914. int i = 0;
  3915. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3916. if (ids == 0)
  3917. ids = new vector<int32>;
  3918. ids->push_back(spell_id);
  3919. i++;
  3920. }
  3921. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3922. if (quest_step && icon > 0 && quantity > 0)
  3923. quest_step->SetIcon(icon);
  3924. if (quest->GetPlayer()) {
  3925. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3926. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3927. }
  3928. safe_delete(ids);
  3929. }
  3930. lua_interface->ResetFunctionStack(state);
  3931. return 0;
  3932. }
  3933. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3934. if (!lua_interface)
  3935. return 0;
  3936. Quest* quest = lua_interface->GetQuest(state);
  3937. int32 step = lua_interface->GetInt32Value(state, 2);
  3938. string description = lua_interface->GetStringValue(state, 3);
  3939. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3940. float percentage = lua_interface->GetFloatValue(state, 5);
  3941. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3942. int16 icon = lua_interface->GetInt16Value(state, 7);
  3943. if (quest) {
  3944. const char* taskgroup = 0;
  3945. if (str_taskgroup.length() > 0)
  3946. taskgroup = str_taskgroup.c_str();
  3947. int32 item_id = 0;
  3948. vector<int32>* ids = 0;
  3949. int i = 0;
  3950. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3951. if (ids == 0)
  3952. ids = new vector<int32>;
  3953. ids->push_back(item_id);
  3954. i++;
  3955. }
  3956. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3957. if (quest_step && icon > 0 && quantity > 0)
  3958. quest_step->SetIcon(icon);
  3959. if (quest->GetPlayer()) {
  3960. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3961. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3962. }
  3963. safe_delete(ids);
  3964. }
  3965. lua_interface->ResetFunctionStack(state);
  3966. return 0;
  3967. }
  3968. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3969. if (!lua_interface)
  3970. return 0;
  3971. Quest* quest = lua_interface->GetQuest(state);
  3972. int32 step = lua_interface->GetInt32Value(state, 2);
  3973. string description = lua_interface->GetStringValue(state, 3);
  3974. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3975. float percentage = lua_interface->GetFloatValue(state, 5);
  3976. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3977. int16 icon = lua_interface->GetInt16Value(state, 7);
  3978. if (quest) {
  3979. const char* taskgroup = 0;
  3980. if (str_taskgroup.length() > 0)
  3981. taskgroup = str_taskgroup.c_str();
  3982. int32 item_id = 0;
  3983. vector<int32>* ids = 0;
  3984. int i = 0;
  3985. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3986. if (ids == 0)
  3987. ids = new vector<int32>;
  3988. ids->push_back(item_id);
  3989. i++;
  3990. }
  3991. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3992. if (quest_step && icon > 0 && quantity > 0)
  3993. quest_step->SetIcon(icon);
  3994. if (quest->GetPlayer()) {
  3995. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3996. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3997. }
  3998. safe_delete(ids);
  3999. }
  4000. lua_interface->ResetFunctionStack(state);
  4001. return 0;
  4002. }
  4003. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4004. if (!lua_interface)
  4005. return 0;
  4006. Quest* quest = lua_interface->GetQuest(state);
  4007. string action = lua_interface->GetStringValue(state, 2);
  4008. lua_interface->ResetFunctionStack(state);
  4009. if (quest) {
  4010. if (action.length() > 0)
  4011. quest->SetCompleteAction(action);
  4012. }
  4013. return 0;
  4014. }
  4015. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4016. if (!lua_interface)
  4017. return 0;
  4018. Quest* quest = lua_interface->GetQuest(state);
  4019. int32 step = lua_interface->GetInt32Value(state, 2);
  4020. string action = lua_interface->GetStringValue(state, 3);
  4021. lua_interface->ResetFunctionStack(state);
  4022. if (quest) {
  4023. if (step > 0 && action.length() > 0)
  4024. quest->AddCompleteAction(step, action);
  4025. }
  4026. return 0;
  4027. }
  4028. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4029. if (!lua_interface)
  4030. return 0;
  4031. Quest* quest = lua_interface->GetQuest(state);
  4032. int32 step = lua_interface->GetInt32Value(state, 2);
  4033. string action = lua_interface->GetStringValue(state, 3);
  4034. lua_interface->ResetFunctionStack(state);
  4035. if (quest) {
  4036. if (step > 0 && action.length() > 0)
  4037. quest->AddProgressAction(step, action);
  4038. }
  4039. return 0;
  4040. }
  4041. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4042. if (!lua_interface)
  4043. return 0;
  4044. Quest* quest = lua_interface->GetQuest(state);
  4045. string description = lua_interface->GetStringValue(state, 2);
  4046. lua_interface->ResetFunctionStack(state);
  4047. if (quest && description.length() > 0)
  4048. quest->SetDescription(description);
  4049. return 0;
  4050. }
  4051. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4052. if (!lua_interface)
  4053. return 0;
  4054. Quest* quest = lua_interface->GetQuest(state);
  4055. string description = lua_interface->GetStringValue(state, 2);
  4056. lua_interface->ResetFunctionStack(state);
  4057. if (quest && description.length() > 0)
  4058. quest->SetCompletedDescription(description);
  4059. return 0;
  4060. }
  4061. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4062. if (!lua_interface)
  4063. return 0;
  4064. Quest* quest = lua_interface->GetQuest(state);
  4065. int32 step = lua_interface->GetInt32Value(state, 2);
  4066. string description = lua_interface->GetStringValue(state, 3);
  4067. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4068. lua_interface->ResetFunctionStack(state);
  4069. if (quest && step > 0 && description.length() > 0) {
  4070. quest->SetTaskGroupDescription(step, description, display_bullets);
  4071. /* if (quest->GetPlayer()) {
  4072. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4073. if (client)
  4074. client->SendQuestUpdateStep(quest, step, false);
  4075. }*/
  4076. }
  4077. return 0;
  4078. }
  4079. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4080. if (!lua_interface)
  4081. return 0;
  4082. Quest* quest = lua_interface->GetQuest(state);
  4083. int32 step = lua_interface->GetInt32Value(state, 2);
  4084. string description = lua_interface->GetStringValue(state, 3);
  4085. lua_interface->ResetFunctionStack(state);
  4086. if (quest && step > 0 && description.length() > 0) {
  4087. quest->SetStepDescription(step, description);
  4088. /*if (quest->GetPlayer()) {
  4089. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4090. if (client)
  4091. client->SendQuestUpdateStepImmediately(quest, step);
  4092. }*/
  4093. }
  4094. return 0;
  4095. }
  4096. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4097. Quest* quest = lua_interface->GetQuest(state);
  4098. string zone = lua_interface->GetStringValue(state, 2);
  4099. lua_interface->ResetFunctionStack(state);
  4100. if (quest && zone.length() > 0)
  4101. quest->SetZone(zone);
  4102. return 0;
  4103. }
  4104. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4105. if (!lua_interface)
  4106. return 0;
  4107. Quest* quest = lua_interface->GetQuest(state);
  4108. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4109. lua_interface->ResetFunctionStack(state);
  4110. if (quest && spawn) {
  4111. if (spawn->IsPlayer()) {
  4112. Client* client = ((Player*)spawn)->GetClient();
  4113. if (client) {
  4114. client->AddPendingQuestReward(quest);
  4115. }
  4116. }
  4117. }
  4118. return 0;
  4119. }
  4120. int EQ2Emu_lua_Harvest(lua_State* state) {
  4121. if (!lua_interface)
  4122. return 0;
  4123. Spawn* player = lua_interface->GetSpawn(state);
  4124. Spawn* node = lua_interface->GetSpawn(state, 2);
  4125. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4126. Client* client = ((Player*)player)->GetClient();
  4127. if (client) {
  4128. ((GroundSpawn*)node)->ProcessHarvest(client);
  4129. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4130. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4131. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4132. }
  4133. }
  4134. }
  4135. else if (player && player->IsPlayer()) {
  4136. Client* client = ((Player*)player)->GetClient();
  4137. if (client)
  4138. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4139. }
  4140. lua_interface->ResetFunctionStack(state);
  4141. return 0;
  4142. }
  4143. int EQ2Emu_lua_Bind(lua_State* state) {
  4144. if (!lua_interface)
  4145. return 0;
  4146. Spawn* spawn = lua_interface->GetSpawn(state);
  4147. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4148. float x = lua_interface->GetFloatValue(state, 3);
  4149. float y = lua_interface->GetFloatValue(state, 4);
  4150. float z = lua_interface->GetFloatValue(state, 5);
  4151. float h = lua_interface->GetFloatValue(state, 6);
  4152. lua_interface->ResetFunctionStack(state);
  4153. if (!spawn) {
  4154. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4155. return 0;
  4156. }
  4157. if (!spawn->IsPlayer()) {
  4158. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4159. return 0;
  4160. }
  4161. if (zone_id == 0) {
  4162. Client* client = ((Player*)spawn)->GetClient();
  4163. if (!client) {
  4164. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4165. return 0;
  4166. }
  4167. if (!client->Bind())
  4168. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4169. }
  4170. else {
  4171. Player* player = (Player*)spawn;
  4172. player->GetPlayerInfo()->SetBindZone(zone_id);
  4173. player->GetPlayerInfo()->SetBindX(x);
  4174. player->GetPlayerInfo()->SetBindY(y);
  4175. player->GetPlayerInfo()->SetBindZ(z);
  4176. player->GetPlayerInfo()->SetBindHeading(h);
  4177. }
  4178. return 0;
  4179. }
  4180. int EQ2Emu_lua_Gate(lua_State* state) {
  4181. if (!lua_interface)
  4182. return 0;
  4183. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4184. Spawn* spawn = lua_interface->GetSpawn(state);
  4185. lua_interface->ResetFunctionStack(state);
  4186. if (spawn) {
  4187. if (spawn->IsPlayer()) {
  4188. Client* client = ((Player*)spawn)->GetClient();
  4189. if (client) {
  4190. if (!client->Gate((spell != nullptr) ? true : false))
  4191. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4192. }
  4193. }
  4194. }
  4195. return 0;
  4196. }
  4197. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4198. if (!lua_interface)
  4199. return 0;
  4200. bool ret = false;
  4201. Spawn* spawn = lua_interface->GetSpawn(state);
  4202. lua_interface->ResetFunctionStack(state);
  4203. if (spawn) {
  4204. if (spawn->IsPlayer()) {
  4205. Client* client = ((Player*)spawn)->GetClient();
  4206. if (client)
  4207. ret = client->BindAllowed();
  4208. }
  4209. }
  4210. lua_interface->SetBooleanValue(state, ret);
  4211. return 1;
  4212. }
  4213. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4214. if (!lua_interface)
  4215. return 0;
  4216. bool ret = false;
  4217. Spawn* spawn = lua_interface->GetSpawn(state);
  4218. lua_interface->ResetFunctionStack(state);
  4219. if (spawn) {
  4220. if (spawn->IsPlayer()) {
  4221. Client* client = ((Player*)spawn)->GetClient();
  4222. ZoneServer* zone = lua_interface->GetZone(state);
  4223. if (client && zone){
  4224. ret = zone->GetCanGate();
  4225. }
  4226. }
  4227. }
  4228. lua_interface->SetBooleanValue(state, ret);
  4229. return 1;
  4230. }
  4231. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4232. Spawn* spawn = lua_interface->GetSpawn(state);
  4233. lua_interface->ResetFunctionStack(state);
  4234. if (spawn) {
  4235. lua_interface->SetBooleanValue(state, spawn->Alive());
  4236. return 1;
  4237. }
  4238. return 0;
  4239. }
  4240. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4241. if (!lua_interface)
  4242. return 0;
  4243. Spawn* spawn = lua_interface->GetSpawn(state);
  4244. lua_interface->ResetFunctionStack(state);
  4245. if (spawn && spawn->IsEntity()) {
  4246. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4247. return 1;
  4248. }
  4249. return 0;
  4250. }
  4251. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4252. Spawn* spawn = lua_interface->GetSpawn(state);
  4253. string message = lua_interface->GetStringValue(state, 2);
  4254. string color_str = lua_interface->GetStringValue(state, 3);
  4255. lua_interface->ResetFunctionStack(state);
  4256. int8 color = CHANNEL_NARRATIVE;
  4257. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4258. Client* client = ((Player*)spawn)->GetClient();
  4259. if (client) {
  4260. if (color_str.length() > 0) {
  4261. // leave for backwards compat, but all future should just use the number
  4262. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4263. color = CHANNEL_COLOR_RED;
  4264. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4265. color = CHANNEL_COLOR_YELLOW;
  4266. else
  4267. {
  4268. // use a number to specify the channel as per Commands/Commands.h defines
  4269. color = (int8)atoul(color_str.c_str());
  4270. }
  4271. }
  4272. client->SimpleMessage(color, message.c_str());
  4273. }
  4274. }
  4275. return 0;
  4276. }
  4277. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4278. Spawn* spawn = lua_interface->GetSpawn(state);
  4279. string message = lua_interface->GetStringValue(state, 2);
  4280. int8 red = lua_interface->GetInt8Value(state, 3);
  4281. int8 green = lua_interface->GetInt8Value(state, 4);
  4282. int8 blue = lua_interface->GetInt8Value(state, 5);
  4283. lua_interface->ResetFunctionStack(state);
  4284. if (!spawn) {
  4285. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4286. return 0;
  4287. }
  4288. if (!spawn->IsPlayer()) {
  4289. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4290. return 0;
  4291. }
  4292. int32 words = ::CountWordsInString(message.c_str());
  4293. if (words < 5)
  4294. words = 5;
  4295. Client* client = ((Player*)spawn)->GetClient();
  4296. if (client)
  4297. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4298. return 0;
  4299. }
  4300. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4301. Spawn* spawn = lua_interface->GetSpawn(state);
  4302. int8 param = lua_interface->GetInt8Value(state, 2);
  4303. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4304. int8 value = lua_interface->GetInt8Value(state, 4);
  4305. lua_interface->ResetFunctionStack(state);
  4306. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4307. Client* client = ((Player*)spawn)->GetClient();
  4308. if (client) {
  4309. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4310. switch (param) {
  4311. case 1: {
  4312. packet->setDataByName("parameter1", param_value);
  4313. break;
  4314. }
  4315. case 2: {
  4316. packet->setDataByName("parameter2", param_value);
  4317. break;
  4318. }
  4319. case 3: {
  4320. packet->setDataByName("parameter3", param_value);
  4321. break;
  4322. }
  4323. case 4: {
  4324. packet->setDataByName("parameter4", param_value);
  4325. break;
  4326. }
  4327. case 5: {
  4328. packet->setDataByName("parameter5", param_value);
  4329. break;
  4330. }
  4331. }
  4332. packet->setDataByName("value", value);
  4333. client->QueuePacket(packet->serialize());
  4334. safe_delete(packet);
  4335. }
  4336. }
  4337. return 0;
  4338. }
  4339. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4340. Spawn* spawn = lua_interface->GetSpawn(state);
  4341. lua_interface->ResetFunctionStack(state);
  4342. if (spawn && spawn->IsPlayer()) {
  4343. if (((Player*)spawn)->GetIsTracking())
  4344. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4345. else
  4346. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4347. }
  4348. return 0;
  4349. }
  4350. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4351. Spawn* player = lua_interface->GetSpawn(state);
  4352. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4353. string name = lua_interface->GetStringValue(state, 3);
  4354. float distance = lua_interface->GetFloatValue(state, 4);
  4355. string command = lua_interface->GetStringValue(state, 5);
  4356. string error_text = lua_interface->GetStringValue(state, 6);
  4357. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4358. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4359. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4360. lua_interface->ResetFunctionStack(state);
  4361. if (spawn) {
  4362. if (distance == 0)
  4363. distance = 10.0f;
  4364. if (command.length() == 0)
  4365. command = name;
  4366. if (command.length() < 1 && name.length() < 1)
  4367. {
  4368. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4369. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4370. spawn->RemovePrimaryCommands();
  4371. }
  4372. else
  4373. {
  4374. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4375. }
  4376. }
  4377. return 0;
  4378. }
  4379. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4380. if (!lua_interface)
  4381. return 0;
  4382. Spawn* player = lua_interface->GetSpawn(state);
  4383. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4384. int16 tier = lua_interface->GetInt16Value(state, 3);
  4385. lua_interface->ResetFunctionStack(state);
  4386. if (player && player->IsPlayer()) {
  4387. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4388. return 1;
  4389. }
  4390. return 0;
  4391. }
  4392. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4393. if (!lua_interface)
  4394. return 0;
  4395. Spawn* player = lua_interface->GetSpawn(state);
  4396. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4397. int16 tier = lua_interface->GetInt16Value(state, 3);
  4398. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4399. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4400. bool add_to_hotbar = true;
  4401. if (num_args > 4) {
  4402. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4403. }
  4404. lua_interface->ResetFunctionStack(state);
  4405. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4406. if (player && spell && player->IsPlayer()) {
  4407. Client* client = player->GetClient();
  4408. if (client) {
  4409. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4410. {
  4411. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4412. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4413. client->GetPlayer()->UnlockSpell(spell);
  4414. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4415. }
  4416. else
  4417. {
  4418. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4419. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4420. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4421. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4422. client->GetPlayer()->UnlockSpell(spell);
  4423. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4424. }
  4425. //if (client ) {
  4426. // ((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);
  4427. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4428. if (outapp)
  4429. client->QueuePacket(outapp);
  4430. }
  4431. }
  4432. return 0;
  4433. }
  4434. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4435. if (!lua_interface)
  4436. return 0;
  4437. Spawn* player = lua_interface->GetSpawn(state);
  4438. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4439. lua_interface->ResetFunctionStack(state);
  4440. if (player && player->IsPlayer()) {
  4441. Client* client = player->GetClient();
  4442. if (client) {
  4443. ((Player*)player)->DeleteSpellBook(type_selection);
  4444. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4445. if (outapp)
  4446. client->QueuePacket(outapp);
  4447. }
  4448. }
  4449. return 0;
  4450. }
  4451. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4452. if (!lua_interface)
  4453. return 0;
  4454. Spawn* player = lua_interface->GetSpawn(state);
  4455. lua_interface->ResetFunctionStack(state);
  4456. if (player && player->IsPlayer()) {
  4457. Client* client = player->GetClient();
  4458. if (client) {
  4459. client->SendNewAdventureSpells();
  4460. }
  4461. }
  4462. return 0;
  4463. }
  4464. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4465. if (!lua_interface)
  4466. return 0;
  4467. Spawn* player = lua_interface->GetSpawn(state);
  4468. lua_interface->ResetFunctionStack(state);
  4469. if (player && player->IsPlayer()) {
  4470. Client* client = player->GetClient();
  4471. if (client) {
  4472. client->SendNewTradeskillSpells();
  4473. }
  4474. }
  4475. return 0;
  4476. }
  4477. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4478. if (!lua_interface)
  4479. return 0;
  4480. Spawn* player = lua_interface->GetSpawn(state);
  4481. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4482. lua_interface->ResetFunctionStack(state);
  4483. if (player && player->IsPlayer()) {
  4484. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4485. Client* client = player->GetClient();
  4486. if (sbe && client) {
  4487. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4488. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4489. if (outapp)
  4490. client->QueuePacket(outapp);
  4491. }
  4492. }
  4493. return 0;
  4494. }
  4495. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4496. if (!lua_interface)
  4497. return 0;
  4498. Spawn* player = lua_interface->GetSpawn(state);
  4499. lua_interface->ResetFunctionStack(state);
  4500. if (player && player->IsPlayer()) {
  4501. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4502. return 1;
  4503. }
  4504. return 0;
  4505. }
  4506. int EQ2Emu_lua_Attack(lua_State* state) {
  4507. if (lua_interface) {
  4508. Spawn* npc = lua_interface->GetSpawn(state);
  4509. Spawn* player = lua_interface->GetSpawn(state, 2);
  4510. lua_interface->ResetFunctionStack(state);
  4511. if (npc && player && npc->IsNPC() && player->IsEntity())
  4512. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4513. }
  4514. return 0;
  4515. }
  4516. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4517. if (lua_interface) {
  4518. Spawn* target = lua_interface->GetSpawn(state);
  4519. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4520. lua_interface->ResetFunctionStack(state);
  4521. if (target && target->GetZone())
  4522. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4523. }
  4524. return 0;
  4525. }
  4526. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4527. Spawn* player;
  4528. if (lua_interface) {
  4529. player = lua_interface->GetSpawn(state);
  4530. lua_interface->ResetFunctionStack(state);
  4531. if (player && player->IsPlayer()) {
  4532. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4533. return 1;
  4534. }
  4535. }
  4536. return 0;
  4537. }
  4538. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4539. Spawn* player;
  4540. Client* client;
  4541. if (lua_interface) {
  4542. player = lua_interface->GetSpawn(state);
  4543. lua_interface->ResetFunctionStack(state);
  4544. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4545. if ((client = ((Player*)player)->GetClient()))
  4546. client->HandInCollections();
  4547. }
  4548. return 0;
  4549. }
  4550. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4551. Spawn* widget;
  4552. if (lua_interface) {
  4553. widget = lua_interface->GetSpawn(state);
  4554. lua_interface->ResetFunctionStack(state);
  4555. if (widget && widget->IsWidget())
  4556. ((Widget*)widget)->HandleUse(nullptr, "");
  4557. }
  4558. return 0;
  4559. }
  4560. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4561. Spawn* spawn = 0;
  4562. int32 primary_list = 0;
  4563. int32 secondary_list = 0;
  4564. if (lua_interface) {
  4565. spawn = lua_interface->GetSpawn(state);
  4566. primary_list = lua_interface->GetInt32Value(state, 2);
  4567. secondary_list = lua_interface->GetInt32Value(state, 3);
  4568. lua_interface->ResetFunctionStack(state);
  4569. if (!spawn->IsNPC()) {
  4570. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4571. return 0;
  4572. }
  4573. NPC* npc = (NPC*)spawn;
  4574. npc->SetPrimarySpellList(primary_list);
  4575. npc->SetSecondarySpellList(secondary_list);
  4576. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4577. }
  4578. return 0;
  4579. }
  4580. int EQ2Emu_lua_GetPet(lua_State* state) {
  4581. if (!lua_interface)
  4582. return 0;
  4583. Spawn* spawn = lua_interface->GetSpawn(state);
  4584. lua_interface->ResetFunctionStack(state);
  4585. if (spawn) {
  4586. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4587. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4588. return 1;
  4589. }
  4590. }
  4591. return 0;
  4592. }
  4593. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4594. if (!lua_interface)
  4595. return 0;
  4596. Spawn* spawn = lua_interface->GetSpawn(state);
  4597. lua_interface->ResetFunctionStack(state);
  4598. if (spawn) {
  4599. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4600. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4601. return 1;
  4602. }
  4603. }
  4604. return 0;
  4605. }
  4606. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4607. if (!lua_interface)
  4608. return 0;
  4609. Spawn* spawn = lua_interface->GetSpawn(state);
  4610. lua_interface->ResetFunctionStack(state);
  4611. if (spawn) {
  4612. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4613. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4614. return 1;
  4615. }
  4616. }
  4617. return 0;
  4618. }
  4619. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4620. if (!lua_interface)
  4621. return 0;
  4622. Spawn* spawn = lua_interface->GetSpawn(state);
  4623. lua_interface->ResetFunctionStack(state);
  4624. if (spawn) {
  4625. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4626. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4627. return 1;
  4628. }
  4629. }
  4630. return 0;
  4631. }
  4632. int EQ2Emu_lua_Charm(lua_State* state) {
  4633. if (!lua_interface)
  4634. return 0;
  4635. Spawn* owner = lua_interface->GetSpawn(state);
  4636. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4637. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4638. lua_interface->ResetFunctionStack(state);
  4639. if (!luaspell) {
  4640. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4641. return 0;
  4642. }
  4643. if(luaspell->resisted) {
  4644. return 0;
  4645. }
  4646. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4647. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4648. pet->SetPet(true);
  4649. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4650. ((NPC*)pet)->SetOwner((Entity*)owner);
  4651. // If owner is player and player does not have a summoned pet set the players charsheet
  4652. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4653. Player* player = (Player*)owner;
  4654. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4655. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4656. player->GetInfoStruct()->set_pet_movement(2);
  4657. player->GetInfoStruct()->set_pet_behavior(3);
  4658. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4659. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4660. // Make sure the values get sent to the client
  4661. player->SetCharSheetChanged(true);
  4662. }
  4663. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4664. pet->SetSpawnScript("");
  4665. // Set faction to the same as the owner
  4666. pet->SetFactionID(owner->GetFactionID());
  4667. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4668. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4669. // Clear hate list
  4670. ((NPC*)pet)->Brain()->ClearHate();
  4671. // Set the brain to a pet brain
  4672. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4673. }
  4674. return 0;
  4675. }
  4676. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4677. if (!lua_interface)
  4678. return 0;
  4679. Spawn* spawn = lua_interface->GetSpawn(state);
  4680. lua_interface->ResetFunctionStack(state);
  4681. if (!spawn) {
  4682. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4683. return 0;
  4684. }
  4685. vector<Spawn*> groupMembers;
  4686. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4687. groupMembers = *spawn->GetSpawnGroup();
  4688. }
  4689. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4690. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4691. deque<GroupMemberInfo*>::iterator itr;
  4692. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4693. if (group)
  4694. {
  4695. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4696. deque<GroupMemberInfo*>* members = group->GetMembers();
  4697. GroupMemberInfo* info = 0;
  4698. for (itr = members->begin(); itr != members->end(); itr++) {
  4699. info = *itr;
  4700. if (info->client)
  4701. groupMembers.push_back(info->client->GetPlayer());
  4702. }
  4703. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4704. }
  4705. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4706. }
  4707. else
  4708. return 0;
  4709. lua_createtable(state, groupMembers.size(), 0);
  4710. int newTable = lua_gettop(state);
  4711. for (int32 i = 0; i < groupMembers.size(); i++) {
  4712. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4713. lua_rawseti(state, newTable, i + 1);
  4714. }
  4715. return 1;
  4716. }
  4717. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4718. if (!lua_interface)
  4719. return 0;
  4720. lua_interface->ResetFunctionStack(state);
  4721. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4722. lua_interface->SetOptionWindowValue(state, option_window);
  4723. return 1;
  4724. }
  4725. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4726. if (!lua_interface)
  4727. return 0;
  4728. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4729. if (option_window) {
  4730. OptionWindowOption option_window_option;
  4731. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4732. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4733. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4734. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4735. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4736. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4737. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4738. option_window->push_back(option_window_option);
  4739. }
  4740. lua_interface->ResetFunctionStack(state);
  4741. return 0;
  4742. }
  4743. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4744. if (!lua_interface)
  4745. return 0;
  4746. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4747. Spawn* player = lua_interface->GetSpawn(state, 2);
  4748. string window_title = lua_interface->GetStringValue(state, 3);
  4749. string cancel_command = lua_interface->GetStringValue(state, 4);
  4750. lua_interface->ResetFunctionStack(state);
  4751. if (!player->IsPlayer()) {
  4752. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4753. return 0;
  4754. }
  4755. Client* client = ((Player*)player)->GetClient();
  4756. if (option_window && window_title.length() > 0 && client) {
  4757. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4758. if (!packet)
  4759. return 0;
  4760. packet->setDataByName("title_text", window_title.c_str());
  4761. if (cancel_command.length() > 0)
  4762. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4763. packet->setArrayLengthByName("num_selections", option_window->size());
  4764. vector<OptionWindowOption>::iterator itr;
  4765. int8 i = 0;
  4766. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4767. OptionWindowOption opt = *itr;
  4768. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4769. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4770. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4771. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4772. if (opt.optionCommand.length() > 0)
  4773. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4774. if (opt.optionConfirmTitle.length() > 0)
  4775. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4776. i++;
  4777. }
  4778. client->QueuePacket(packet->serialize());
  4779. lua_interface->SetLuaUserDataStale(option_window);
  4780. safe_delete(option_window);
  4781. safe_delete(packet);
  4782. }
  4783. return 0;
  4784. }
  4785. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4786. if (!lua_interface)
  4787. return 0;
  4788. Spawn* spawn = lua_interface->GetSpawn(state);
  4789. lua_interface->ResetFunctionStack(state);
  4790. if (spawn) {
  4791. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4792. return 1;
  4793. }
  4794. else
  4795. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4796. return 0;
  4797. }
  4798. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4799. if (!lua_interface)
  4800. return 0;
  4801. Spawn* spawn = lua_interface->GetSpawn(state);
  4802. lua_interface->ResetFunctionStack(state);
  4803. if (spawn) {
  4804. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4805. return 1;
  4806. }
  4807. else
  4808. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4809. return 0;
  4810. }
  4811. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4812. if (!lua_interface)
  4813. return 0;
  4814. Spawn* spawn = lua_interface->GetSpawn(state);
  4815. lua_interface->ResetFunctionStack(state);
  4816. if (spawn) {
  4817. int8 class_id = spawn->GetTradeskillClass();
  4818. // Need to add 42 for the offset in the array
  4819. class_id += 44;
  4820. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4821. return 1;
  4822. }
  4823. else
  4824. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4825. return 0;
  4826. }
  4827. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4828. if (!lua_interface)
  4829. return 0;
  4830. Spawn* spawn = lua_interface->GetSpawn(state);
  4831. int16 level = lua_interface->GetInt8Value(state, 2);
  4832. lua_interface->ResetFunctionStack(state);
  4833. if (spawn) {
  4834. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4835. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4836. else
  4837. spawn->SetTSLevel(level);
  4838. }
  4839. else
  4840. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4841. return 0;
  4842. }
  4843. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4844. if (!lua_interface)
  4845. return 0;
  4846. Spawn* spawn = lua_interface->GetSpawn(state);
  4847. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4848. lua_interface->ResetFunctionStack(state);
  4849. if (spawn) {
  4850. spawn->SetAttackable(attackable);
  4851. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4852. }
  4853. return 0;
  4854. }
  4855. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4856. // Check to see if we have a valid lua_interface
  4857. if (!lua_interface)
  4858. return 0;
  4859. // Get the spawn that is getting the pet
  4860. Spawn* spawn = lua_interface->GetSpawn(state);
  4861. // Get the DB ID of the pet
  4862. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4863. // The max level the pet can gain
  4864. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4865. // Get the spell that this command was called from
  4866. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4867. lua_interface->ResetFunctionStack(state);
  4868. // Check to make sure the spawn pointer is valid
  4869. if (!spawn) {
  4870. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4871. return 0;
  4872. }
  4873. // Check to make sure the spawn is an entity
  4874. if (!spawn->IsEntity()) {
  4875. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4876. return 0;
  4877. }
  4878. // Check to make sure the spawn doesn't already have a pet of this type
  4879. if (((Entity*)spawn)->GetPet()) {
  4880. if (spawn->IsPlayer()) {
  4881. Client* client = ((Player*)spawn)->GetClient();
  4882. if (client)
  4883. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4884. }
  4885. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4886. return 0;
  4887. }
  4888. // Check to see if the DB ID for the pet is set
  4889. if (pet_id == 0) {
  4890. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4891. return 0;
  4892. }
  4893. // Check to see if the pointer to the spell is valid
  4894. if (!luaspell) {
  4895. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4896. return 0;
  4897. }
  4898. if(luaspell->resisted) {
  4899. return 0;
  4900. }
  4901. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4902. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4903. if (!pet) {
  4904. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4905. return 0;
  4906. }
  4907. // Check to make sure the pet is an npc
  4908. if (!pet->IsNPC()) {
  4909. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4910. return 0;
  4911. }
  4912. // Spawn the pet at the same location as the owner
  4913. pet->SetX(spawn->GetX());
  4914. pet->SetY(spawn->GetY());
  4915. pet->SetZ(spawn->GetZ());
  4916. pet->SetLocation(spawn->GetLocation());
  4917. pet->SetHeading(spawn->GetHeading());
  4918. std::string petName = std::string("");
  4919. if(spawn->IsEntity()) {
  4920. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  4921. }
  4922. if(petName.size() < 1) {
  4923. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4924. petName = spawn->GetZone()->pet_names.at(rand_index);
  4925. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  4926. }
  4927. // If player set various values for the char sheet (pet window)
  4928. if (spawn->IsPlayer()) {
  4929. Player* player = (Player*)spawn;
  4930. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4931. player->GetInfoStruct()->set_pet_name(petName);
  4932. player->GetInfoStruct()->set_pet_movement(2);
  4933. player->GetInfoStruct()->set_pet_behavior(3);
  4934. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4935. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4936. // Make sure the values get sent to the client
  4937. player->SetCharSheetChanged(true);
  4938. }
  4939. // Set the pets name
  4940. pet->SetName(petName.c_str());
  4941. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4942. if (max_level > 0)
  4943. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4944. else
  4945. pet->SetLevel(spawn->GetLevel());
  4946. // Set the max level this pet can reach
  4947. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4948. ((NPC*)pet)->UpdateWeapons();
  4949. // Set the faction of the pet to the same faction as the owner
  4950. pet->SetFactionID(spawn->GetFactionID());
  4951. // Set the spawn as a pet
  4952. pet->SetPet(true);
  4953. // Give a pointer of the owner to the pet
  4954. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4955. // Give a pointer of the pet to the owner
  4956. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4957. // Set the pet type
  4958. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4959. // Set the spell id used to create this pet
  4960. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4961. // Set the spell tier used to create this pet
  4962. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4963. // Set the pets spawn type to 6
  4964. pet->SetSpawnType(6);
  4965. // Set the pets brain
  4966. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4967. // Check to see if the pet has a subtitle
  4968. if (strlen(pet->GetSubTitle()) > 0) {
  4969. // Add the players name to the front of the sub title
  4970. string pet_subtitle;
  4971. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4972. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4973. // Set the pets subtitle to the new one
  4974. pet->SetSubTitle(pet_subtitle.c_str());
  4975. }
  4976. // Add the "Pet Options" entity command to the pet
  4977. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4978. const char* spawn_script = world.GetSpawnScript(pet_id);
  4979. bool runScript = false;
  4980. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4981. runScript = true;
  4982. pet->SetSpawnScript(string(spawn_script));
  4983. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  4984. }
  4985. spawn->GetZone()->AddSpawn(pet);
  4986. if(runScript){
  4987. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  4988. }
  4989. // Set the pet as the return value for this function
  4990. lua_interface->SetSpawnValue(state, pet);
  4991. return 1;
  4992. }
  4993. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4994. if (!lua_interface)
  4995. return 0;
  4996. Spawn* spawn = lua_interface->GetSpawn(state);
  4997. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4998. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4999. lua_interface->ResetFunctionStack(state);
  5000. if (!spawn) {
  5001. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5002. return 0;
  5003. }
  5004. if (!spawn->IsEntity()) {
  5005. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5006. return 0;
  5007. }
  5008. if (((Entity*)spawn)->GetDeityPet()) {
  5009. if (spawn->IsPlayer()) {
  5010. Client* client = ((Player*)spawn)->GetClient();
  5011. if (client)
  5012. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5013. }
  5014. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5015. return 0;
  5016. }
  5017. if (pet_id == 0) {
  5018. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5019. return 0;
  5020. }
  5021. if (!luaspell) {
  5022. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. if(luaspell->resisted) {
  5026. return 0;
  5027. }
  5028. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5029. if (!pet) {
  5030. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5031. return 0;
  5032. }
  5033. if (!pet->IsNPC()) {
  5034. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5035. return 0;
  5036. }
  5037. pet->SetX(spawn->GetX());
  5038. pet->SetY(spawn->GetY());
  5039. pet->SetZ(spawn->GetZ());
  5040. pet->SetLocation(spawn->GetLocation());
  5041. pet->SetHeading(spawn->GetHeading());
  5042. spawn->GetZone()->AddSpawn(pet);
  5043. string random_pet_name;
  5044. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5045. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5046. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5047. pet->SetName(random_pet_name.c_str());
  5048. pet->SetLevel(spawn->GetLevel());
  5049. pet->SetFactionID(spawn->GetFactionID());
  5050. pet->SetPet(true);
  5051. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5052. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5053. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5054. pet->SetSpawnType(6);
  5055. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5056. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5057. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5058. if (strlen(pet->GetSubTitle()) > 0) {
  5059. string pet_subtitle;
  5060. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5061. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5062. pet->SetSubTitle(pet_subtitle.c_str());
  5063. }
  5064. // deity and cosmetic pets are not attackable
  5065. pet->SetAttackable(false);
  5066. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5067. lua_interface->SetSpawnValue(state, pet);
  5068. return 1;
  5069. }
  5070. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5071. if (!lua_interface)
  5072. return 0;
  5073. Spawn* spawn = lua_interface->GetSpawn(state);
  5074. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5075. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5076. lua_interface->ResetFunctionStack(state);
  5077. if (!spawn) {
  5078. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5079. return 0;
  5080. }
  5081. if (!spawn->IsEntity()) {
  5082. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5083. return 0;
  5084. }
  5085. if (((Entity*)spawn)->GetCosmeticPet()) {
  5086. if (spawn->IsPlayer()) {
  5087. Client* client = ((Player*)spawn)->GetClient();
  5088. if (client)
  5089. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5090. }
  5091. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5092. return 0;
  5093. }
  5094. if (pet_id == 0) {
  5095. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5096. return 0;
  5097. }
  5098. if (!luaspell) {
  5099. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5100. return 0;
  5101. }
  5102. if(luaspell->resisted) {
  5103. return 0;
  5104. }
  5105. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5106. if (!pet) {
  5107. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5108. return 0;
  5109. }
  5110. if (!pet->IsNPC()) {
  5111. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5112. return 0;
  5113. }
  5114. pet->SetX(spawn->GetX());
  5115. pet->SetY(spawn->GetY());
  5116. pet->SetZ(spawn->GetZ());
  5117. pet->SetLocation(spawn->GetLocation());
  5118. pet->SetHeading(spawn->GetHeading());
  5119. spawn->GetZone()->AddSpawn(pet);
  5120. string random_pet_name;
  5121. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5122. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5123. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5124. pet->SetName(random_pet_name.c_str());
  5125. pet->SetLevel(spawn->GetLevel());
  5126. pet->SetFactionID(spawn->GetFactionID());
  5127. pet->SetPet(true);
  5128. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5129. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5130. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5131. pet->SetSpawnType(6);
  5132. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5133. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5134. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5135. if (strlen(pet->GetSubTitle()) > 0) {
  5136. string pet_subtitle;
  5137. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5138. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5139. pet->SetSubTitle(pet_subtitle.c_str());
  5140. }
  5141. pet->SetAttackable(false);
  5142. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5143. lua_interface->SetSpawnValue(state, pet);
  5144. return 1;
  5145. }
  5146. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5147. if (!lua_interface)
  5148. return 0;
  5149. Spawn* spawn = lua_interface->GetSpawn(state);
  5150. lua_interface->ResetFunctionStack(state);
  5151. if (!spawn) {
  5152. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5153. return 0;
  5154. }
  5155. if (!spawn->IsPet()) {
  5156. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5157. return 0;
  5158. }
  5159. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5160. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5161. return 0;
  5162. }
  5163. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5164. if (!lua_interface)
  5165. return 0;
  5166. Quest* quest = lua_interface->GetQuest(state);
  5167. if (!quest) {
  5168. 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));
  5169. lua_interface->ResetFunctionStack(state);
  5170. return 0;
  5171. }
  5172. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5173. lua_interface->ResetFunctionStack(state);
  5174. if (feather_color > 0)
  5175. quest->SetFeatherColor(feather_color);
  5176. return 0;
  5177. }
  5178. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5179. if (!lua_interface)
  5180. return 0;
  5181. Spawn* spawn = lua_interface->GetSpawn(state);
  5182. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5183. lua_interface->ResetFunctionStack(state);
  5184. if (!spawn) {
  5185. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5186. return 0;
  5187. }
  5188. if (!spawn2) {
  5189. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5190. return 0;
  5191. }
  5192. spawn->RemoveSpawnAccess(spawn2);
  5193. return 0;
  5194. }
  5195. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5196. if (!lua_interface)
  5197. return 0;
  5198. ZoneServer* zone = lua_interface->GetZone(state);
  5199. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5200. lua_interface->ResetFunctionStack(state);
  5201. if (!zone) {
  5202. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5203. return 0;
  5204. }
  5205. if (location_id == 0) {
  5206. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5207. return 0;
  5208. }
  5209. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5210. if (!location) {
  5211. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5212. return 0;
  5213. }
  5214. Spawn* spawn = 0;
  5215. if (location->entities[0]) {
  5216. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5217. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5218. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5219. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5220. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5221. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5222. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5223. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5224. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5225. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5226. if(spawn && spawn->IsOmittedByDBFlag())
  5227. {
  5228. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5229. safe_delete(spawn);
  5230. spawn = 0;
  5231. return 0;
  5232. }
  5233. if (spawn) {
  5234. const char* script = 0;
  5235. for (int x = 0; x < 3; x++) {
  5236. switch (x) {
  5237. case 0:
  5238. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5239. break;
  5240. case 1:
  5241. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5242. break;
  5243. case 2:
  5244. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5245. break;
  5246. }
  5247. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5248. spawn->SetSpawnScript(string(script));
  5249. break;
  5250. }
  5251. }
  5252. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5253. lua_interface->SetSpawnValue(state, spawn);
  5254. return 1;
  5255. }
  5256. else {
  5257. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5258. safe_delete(spawn);
  5259. }
  5260. }
  5261. return 0;
  5262. }
  5263. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5264. if (!lua_interface)
  5265. return 0;
  5266. Spawn* caster = lua_interface->GetSpawn(state);
  5267. Spawn* target = lua_interface->GetSpawn(state, 2);
  5268. int32 id = lua_interface->GetInt32Value(state, 3);
  5269. string command = lua_interface->GetStringValue(state, 4);
  5270. lua_interface->ResetFunctionStack(state);
  5271. if (!caster) {
  5272. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5273. return 0;
  5274. }
  5275. if (!target) {
  5276. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5277. return 0;
  5278. }
  5279. if (!caster->IsPlayer()) {
  5280. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5281. return 0;
  5282. }
  5283. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5284. if (!entity_command) {
  5285. 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());
  5286. return 0;
  5287. }
  5288. Client* client = ((Player*)caster)->GetClient();
  5289. if (!client) {
  5290. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5291. return 0;
  5292. }
  5293. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5294. return 0;
  5295. }
  5296. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5297. if (!lua_interface)
  5298. return 0;
  5299. Spawn* spawn = lua_interface->GetSpawn(state);
  5300. lua_interface->ResetFunctionStack(state);
  5301. if (!spawn) {
  5302. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5303. return 0;
  5304. }
  5305. if (!spawn->IsNPC()) {
  5306. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5307. return 0;
  5308. }
  5309. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5310. return 0;
  5311. }
  5312. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5313. if (!lua_interface)
  5314. return 0;
  5315. Spawn* spawn = lua_interface->GetSpawn(state);
  5316. int16 tick = lua_interface->GetInt16Value(state, 2);
  5317. lua_interface->ResetFunctionStack(state);
  5318. if (!spawn) {
  5319. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5320. return 0;
  5321. }
  5322. if (!spawn->IsNPC()) {
  5323. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5324. return 0;
  5325. }
  5326. if (tick < 20) {
  5327. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5328. return 0;
  5329. }
  5330. ((NPC*)spawn)->Brain()->SetTick(tick);
  5331. return 0;
  5332. }
  5333. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5334. if (!lua_interface)
  5335. return 0;
  5336. Spawn* spawn = lua_interface->GetSpawn(state);
  5337. Spawn* target = lua_interface->GetSpawn(state, 2);
  5338. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5339. lua_interface->ResetFunctionStack(state);
  5340. if (!spawn) {
  5341. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5342. return 0;
  5343. }
  5344. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5345. spawn->SetFollowTarget(target, follow_distance);
  5346. return 0;
  5347. }
  5348. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5349. if (!lua_interface)
  5350. return 0;
  5351. Spawn* spawn = lua_interface->GetSpawn(state);
  5352. lua_interface->ResetFunctionStack(state);
  5353. if (!spawn) {
  5354. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5355. return 0;
  5356. }
  5357. Spawn* target = spawn->GetFollowTarget();
  5358. if (target) {
  5359. lua_interface->SetSpawnValue(state, target);
  5360. return 1;
  5361. }
  5362. return 0;
  5363. }
  5364. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5365. if (!lua_interface)
  5366. return 0;
  5367. Spawn* spawn = lua_interface->GetSpawn(state);
  5368. lua_interface->ResetFunctionStack(state);
  5369. if (!spawn) {
  5370. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5371. return 0;
  5372. }
  5373. if (spawn->following)
  5374. spawn->following = false;
  5375. else
  5376. spawn->following = true;
  5377. return 0;
  5378. }
  5379. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5380. if (!lua_interface)
  5381. return 0;
  5382. Spawn* spawn = lua_interface->GetSpawn(state);
  5383. lua_interface->ResetFunctionStack(state);
  5384. if (!spawn) {
  5385. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5386. return 0;
  5387. }
  5388. lua_interface->SetBooleanValue(state, spawn->following);
  5389. return 1;
  5390. }
  5391. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5392. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5393. // I will attempt to explain how this function works for future refrence
  5394. // Fist lets make sure lua_interface is valid, if not return out
  5395. if (!lua_interface)
  5396. return 0;
  5397. // Next we grab the first 2 params same as we usually would
  5398. Spawn* spawn = lua_interface->GetSpawn(state);
  5399. string var = lua_interface->GetStringValue(state, 2);
  5400. // 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
  5401. // 1 = Spawn
  5402. // 2 = Zone
  5403. // 3 = Item
  5404. // 4 = Quest
  5405. // 5 = String
  5406. // 6 = nil (null)
  5407. int8 dataType = 0;
  5408. // Define pointers for each potential type
  5409. Spawn* spawnVal = 0;
  5410. ZoneServer* zone = 0;
  5411. Item* item = 0;
  5412. Quest* quest = 0;
  5413. string val;
  5414. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5415. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5416. // options window are also light user data be we do not handle those.
  5417. // We check with lua_islightuserdata(lua_State*, index)
  5418. if (lua_islightuserdata(state, 3)) {
  5419. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5420. // and convert it to LUAUserData*
  5421. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5422. // Check to make sure the data we got is valid, if not give an error
  5423. if (!data || !data->IsCorrectlyInitialized()) {
  5424. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5425. }
  5426. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5427. else if (data->IsSpawn()) {
  5428. spawnVal = data->spawn;
  5429. dataType = 1;
  5430. }
  5431. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5432. else if (data->IsZone()) {
  5433. zone = data->zone;
  5434. dataType = 2;
  5435. }
  5436. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5437. else if (data->IsItem()) {
  5438. item = data->item;
  5439. dataType = 3;
  5440. }
  5441. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5442. else if (data->IsQuest()) {
  5443. quest = data->quest;
  5444. dataType = 4;
  5445. }
  5446. }
  5447. // Wasn't light user data, check if it is nil(null)
  5448. else if (lua_isnil(state, 3)) {
  5449. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5450. dataType = 6;
  5451. }
  5452. // Wasn't light user data or nil (null), must be a string
  5453. else {
  5454. // Set the string and dataType variable
  5455. val = lua_interface->GetStringValue(state, 3);
  5456. dataType = 5;
  5457. }
  5458. lua_interface->ResetFunctionStack(state);
  5459. // We now have all the params, lets check to make sure they are valid
  5460. if (!spawn) {
  5461. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5462. return 0;
  5463. }
  5464. if (var.length() == 0) {
  5465. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5466. return 0;
  5467. }
  5468. if (dataType == 0) {
  5469. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5470. return 0;
  5471. }
  5472. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5473. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5474. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5475. switch (dataType) {
  5476. case 1:
  5477. // 1 = Spawn
  5478. spawn->AddTempVariable(var, spawnVal);
  5479. break;
  5480. case 2:
  5481. // 2 = Zone
  5482. spawn->AddTempVariable(var, zone);
  5483. break;
  5484. case 3:
  5485. // 3 = Item
  5486. spawn->AddTempVariable(var, item);
  5487. break;
  5488. case 4:
  5489. // 4 = Quest
  5490. spawn->AddTempVariable(var, quest);
  5491. break;
  5492. case 5:
  5493. // 5 = String
  5494. spawn->AddTempVariable(var, val);
  5495. break;
  5496. case 6:
  5497. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5498. spawn->DeleteTempVariable(var);
  5499. break;
  5500. }
  5501. // And we are done so return out
  5502. return 0;
  5503. }
  5504. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5505. if (!lua_interface)
  5506. return 0;
  5507. Spawn* spawn = lua_interface->GetSpawn(state);
  5508. string var = lua_interface->GetStringValue(state, 2);
  5509. lua_interface->ResetFunctionStack(state);
  5510. if (!spawn) {
  5511. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5512. return 0;
  5513. }
  5514. if (var.length() == 0) {
  5515. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5516. return 0;
  5517. }
  5518. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5519. int8 type = spawn->GetTempVariableType(var);
  5520. Spawn* spawn2 = 0;
  5521. ZoneServer* zone = 0;
  5522. Item* item = 0;
  5523. Quest* quest = 0;
  5524. // Set the lua function return value based on the type of data the variable contains
  5525. switch (type) {
  5526. case 1:
  5527. spawn2 = spawn->GetTempVariableSpawn(var);
  5528. if (!spawn2)
  5529. return 0;
  5530. lua_interface->SetSpawnValue(state, spawn2);
  5531. break;
  5532. case 2:
  5533. zone = spawn->GetTempVariableZone(var);
  5534. if (!zone)
  5535. return 0;
  5536. lua_interface->SetZoneValue(state, zone);
  5537. break;
  5538. case 3:
  5539. item = spawn->GetTempVariableItem(var);
  5540. if (!item)
  5541. return 0;
  5542. lua_interface->SetItemValue(state, item);
  5543. break;
  5544. case 4:
  5545. quest = spawn->GetTempVariableQuest(var);
  5546. if (!quest)
  5547. return 0;
  5548. lua_interface->SetQuestValue(state, quest);
  5549. break;
  5550. case 5:
  5551. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5552. break;
  5553. default:
  5554. // Not a valid type then the variable was not set so return out
  5555. return 0;
  5556. }
  5557. // Return value was set so return out
  5558. return 1;
  5559. }
  5560. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5561. {
  5562. if (!lua_interface)
  5563. return 0;
  5564. Quest* quest = lua_interface->GetQuest(state);
  5565. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5566. string description = lua_interface->GetStringValue(state, 3);
  5567. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5568. if (!quest) {
  5569. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5570. lua_interface->ResetFunctionStack(state);
  5571. lua_interface->SetBooleanValue(state, false);
  5572. return 1;
  5573. }
  5574. if (!spawn) {
  5575. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5576. lua_interface->ResetFunctionStack(state);
  5577. lua_interface->SetBooleanValue(state, false);
  5578. return 1;
  5579. }
  5580. if (!spawn->IsPlayer()) {
  5581. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5582. lua_interface->ResetFunctionStack(state);
  5583. lua_interface->SetBooleanValue(state, false);
  5584. return 1;
  5585. }
  5586. if (item_id == 0) {
  5587. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5588. lua_interface->ResetFunctionStack(state);
  5589. lua_interface->SetBooleanValue(state, false);
  5590. return 1;
  5591. }
  5592. Client* client = ((Player*)spawn)->GetClient();
  5593. if (!client) {
  5594. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5595. lua_interface->ResetFunctionStack(state);
  5596. lua_interface->SetBooleanValue(state, false);
  5597. return 1;
  5598. }
  5599. Item* item = master_item_list.GetItem(item_id);
  5600. if (!item) {
  5601. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5602. lua_interface->ResetFunctionStack(state);
  5603. lua_interface->SetBooleanValue(state, false);
  5604. return 1;
  5605. }
  5606. Item* firstItem = new Item(item);
  5607. quest->AddTmpRewardItem(firstItem);
  5608. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5609. bool itemsAddedSuccessfully = true;
  5610. if(num_args > 4)
  5611. {
  5612. for(int8 n=5;n<num_args+1;n++)
  5613. {
  5614. int32 new_item = lua_interface->GetInt32Value(state, n);
  5615. Item* tmpItem = master_item_list.GetItem(new_item);
  5616. if(tmpItem)
  5617. {
  5618. Item* newTmpItem = new Item(tmpItem);
  5619. quest->AddTmpRewardItem(newTmpItem);
  5620. }
  5621. else
  5622. itemsAddedSuccessfully = false;
  5623. }
  5624. }
  5625. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5626. lua_interface->ResetFunctionStack(state);
  5627. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5628. return 1;
  5629. }
  5630. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5631. if (!lua_interface)
  5632. return 0;
  5633. Quest* quest = lua_interface->GetQuest(state);
  5634. lua_interface->ResetFunctionStack(state);
  5635. if (!quest) {
  5636. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5637. return 0;
  5638. }
  5639. quest->SetRepeatable(true);
  5640. return 0;
  5641. }
  5642. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5643. if (!lua_interface)
  5644. return 0;
  5645. Spawn* spawn = lua_interface->GetSpawn(state);
  5646. lua_interface->ResetFunctionStack(state);
  5647. if (!spawn) {
  5648. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5649. return 0;
  5650. }
  5651. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5652. string ret = classes.GetClassNameCase(base_class);
  5653. if (ret.length() > 0) {
  5654. lua_interface->SetStringValue(state, ret.c_str());
  5655. return 1;
  5656. }
  5657. return 0;
  5658. }
  5659. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5660. if (!lua_interface)
  5661. return 0;
  5662. Spawn* player = lua_interface->GetSpawn(state);
  5663. lua_interface->ResetFunctionStack(state);
  5664. if (player && player->IsPlayer()) {
  5665. Client* client = player->GetClient();
  5666. if (client)
  5667. client->SendWaypoints();
  5668. }
  5669. return 0;
  5670. }
  5671. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5672. if (!lua_interface)
  5673. return 0;
  5674. Spawn* player = lua_interface->GetSpawn(state);
  5675. string name = lua_interface->GetStringValue(state, 2);
  5676. int32 type = lua_interface->GetInt32Value(state, 3);
  5677. lua_interface->ResetFunctionStack(state);
  5678. if (type == 0)
  5679. type = 2;
  5680. if (name.length() > 0) {
  5681. if (player && player->IsPlayer()) {
  5682. Client* client = player->GetClient();
  5683. if (client)
  5684. client->AddWaypoint(name, type);
  5685. }
  5686. }
  5687. return 0;
  5688. }
  5689. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5690. if (!lua_interface)
  5691. return 0;
  5692. Spawn* player = lua_interface->GetSpawn(state);
  5693. string name = lua_interface->GetStringValue(state, 2);
  5694. lua_interface->ResetFunctionStack(state);
  5695. if (name.length() > 0) {
  5696. if (player && player->IsPlayer()) {
  5697. Client* client = player->GetClient();
  5698. if (client)
  5699. client->RemoveWaypoint(name);
  5700. }
  5701. }
  5702. return 0;
  5703. }
  5704. int EQ2Emu_lua_AddWard(lua_State* state) {
  5705. if (!lua_interface)
  5706. return 0;
  5707. int32 damage = lua_interface->GetInt32Value(state);
  5708. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5709. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5710. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5711. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5712. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5713. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5714. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5715. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5716. lua_interface->ResetFunctionStack(state);
  5717. if(!spell || spell->resisted) {
  5718. return 0;
  5719. }
  5720. bool ward_was_added = false;
  5721. ZoneServer* zone = spell->caster->GetZone();
  5722. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5723. for (int32 i = 0; i < spell->targets.size(); i++) {
  5724. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5725. if (!target)
  5726. continue;
  5727. if (target->IsEntity()) {
  5728. // If the ward is already active remove it
  5729. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5730. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5731. // Create new ward info
  5732. WardInfo* ward = new WardInfo;
  5733. ward->Spell = spell;
  5734. ward->BaseDamage = damage;
  5735. ward->DamageLeft = damage;
  5736. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5737. ward->keepWard = keepWard;
  5738. ward->WardType = wardType;
  5739. if (damageAbsorptionPercent > 100)
  5740. damageAbsorptionPercent = 100;
  5741. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5742. if (damageAbsorptionMaxHealthPercent > 100)
  5743. damageAbsorptionMaxHealthPercent = 100;
  5744. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5745. ward->RedirectDamagePercent = redirectDamagePercent;
  5746. ward->LastRedirectDamage = 0;
  5747. ward->LastAbsorbedDamage = 0;
  5748. ward->HitCount = 0;
  5749. spell->num_triggers = maxHitCount;
  5750. spell->had_triggers = true;
  5751. spell->cancel_after_all_triggers = false;
  5752. ward->MaxHitCount = maxHitCount;
  5753. ward->RoundTriggered = false;
  5754. if (wardType == WARD_TYPE_MAGICAL)
  5755. ward->DamageType = damageTypes;
  5756. // Add the ward to the entity
  5757. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5758. ward_was_added = true;
  5759. }
  5760. }
  5761. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5762. if (ward_was_added && spell->caster->IsPlayer()) {
  5763. spell->had_dmg_remaining = true;
  5764. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5765. }
  5766. return 0;
  5767. }
  5768. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5769. if (!lua_interface)
  5770. return 0;
  5771. int32 amount = lua_interface->GetInt32Value(state);
  5772. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5773. lua_interface->ResetFunctionStack(state);
  5774. WardInfo* ward = 0;
  5775. if(!spell || spell->resisted) {
  5776. return 0;
  5777. }
  5778. ZoneServer* zone = spell->caster->GetZone();
  5779. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5780. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5781. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5782. ward = target->GetWard(spell->spell->GetSpellID());
  5783. if (target && ward) {
  5784. ward->DamageLeft += amount;
  5785. if (ward->DamageLeft > ward->BaseDamage)
  5786. ward->DamageLeft = ward->BaseDamage;
  5787. for (int32 i = 0; i < spell->targets.size(); i++) {
  5788. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5789. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5790. }
  5791. }
  5792. }
  5793. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5794. if (ward && spell->caster->IsPlayer())
  5795. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5796. return 0;
  5797. }
  5798. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5799. if (!lua_interface)
  5800. return 0;
  5801. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5802. lua_interface->ResetFunctionStack(state);
  5803. if (!spell) {
  5804. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5805. return 0;
  5806. }
  5807. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5808. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5809. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5810. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5811. if (ward) {
  5812. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5813. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5814. return 1;
  5815. }
  5816. }
  5817. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5818. return 0;
  5819. }
  5820. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5821. if (!lua_interface)
  5822. return 0;
  5823. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5824. if (!spell) {
  5825. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5826. lua_interface->ResetFunctionStack(state);
  5827. return 0;
  5828. }
  5829. string type = lua_interface->GetStringValue(state, 2);
  5830. lua_interface->ResetFunctionStack(state);
  5831. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5832. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5833. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5834. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5835. if (ward) {
  5836. if (boost::iequals(type, "damageleft"))
  5837. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5838. else if (boost::iequals(type, "basedamage"))
  5839. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5840. else if (boost::iequals(type, "keepward"))
  5841. lua_interface->SetBooleanValue(state, ward->keepWard);
  5842. else if (boost::iequals(type, "wardtype"))
  5843. lua_interface->SetInt32Value(state, ward->WardType);
  5844. else if (boost::iequals(type, "dmgabsorptionpct"))
  5845. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5846. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5847. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5848. else if (boost::iequals(type, "redirectdamagepercent"))
  5849. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5850. else if (boost::iequals(type, "lastredirectdamage"))
  5851. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5852. else if (boost::iequals(type, "lastabsorbeddamage"))
  5853. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5854. else if (boost::iequals(type, "hitcount"))
  5855. lua_interface->SetInt32Value(state, ward->HitCount);
  5856. else if (boost::iequals(type, "maxhitcount"))
  5857. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5858. else
  5859. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5860. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5861. return 1;
  5862. }
  5863. }
  5864. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5865. return 0;
  5866. }
  5867. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5868. if (!lua_interface)
  5869. return 0;
  5870. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5871. lua_interface->ResetFunctionStack(state);
  5872. if(!spell) {
  5873. return 0;
  5874. }
  5875. ZoneServer* zone = spell->caster->GetZone();
  5876. Spawn* target = 0;
  5877. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5878. for (int32 i = 0; i < spell->targets.size(); i++) {
  5879. target = zone->GetSpawnByID(spell->targets.at(i));
  5880. if (target && target->IsEntity()) {
  5881. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5882. }
  5883. }
  5884. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5885. return 0;
  5886. }
  5887. int EQ2Emu_lua_Interrupt(lua_State* state)
  5888. {
  5889. if (!lua_interface)
  5890. return 0;
  5891. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5892. Spawn* target = lua_interface->GetSpawn(state, 2);
  5893. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5894. lua_interface->ResetFunctionStack(state);
  5895. if (!caster)
  5896. {
  5897. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5898. return 0;
  5899. }
  5900. if (!target)
  5901. {
  5902. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5903. return 0;
  5904. }
  5905. if (!spell) {
  5906. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5907. return 0;
  5908. }
  5909. if (!target->IsEntity() && !spell)
  5910. {
  5911. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5912. return 0;
  5913. }
  5914. if (!target && spell) {
  5915. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5916. for (int8 i = 0; i < spell->targets.size(); i++) {
  5917. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5918. if (!target || !target->IsEntity())
  5919. continue;
  5920. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5921. }
  5922. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5923. }
  5924. else
  5925. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5926. return 0;
  5927. }
  5928. int EQ2Emu_lua_Stealth(lua_State* state) {
  5929. if (!lua_interface)
  5930. return 0;
  5931. int8 type = lua_interface->GetInt8Value(state);
  5932. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5933. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5934. lua_interface->ResetFunctionStack(state);
  5935. if (!spell) {
  5936. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5937. return 0;
  5938. }
  5939. ZoneServer* zone = spell->caster->GetZone();
  5940. if (spawn) {
  5941. if (spawn->IsEntity()) {
  5942. if (type == 1) {
  5943. ((Entity*)spawn)->AddStealthSpell(spell);
  5944. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5945. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5946. }
  5947. else if (type == 2) {
  5948. ((Entity*)spawn)->AddInvisSpell(spell);
  5949. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5950. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5951. }
  5952. return 0;
  5953. }
  5954. else {
  5955. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5956. return 0;
  5957. }
  5958. }
  5959. else {
  5960. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5961. for (int32 i = 0; i < spell->targets.size(); i++) {
  5962. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5963. if (!spawn || !spawn->IsEntity())
  5964. continue;
  5965. if (type == 1) {
  5966. ((Entity*)spawn)->AddStealthSpell(spell);
  5967. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5968. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5969. }
  5970. else if (type == 2) {
  5971. ((Entity*)spawn)->AddInvisSpell(spell);
  5972. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5973. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5974. }
  5975. else {
  5976. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5977. break;
  5978. }
  5979. }
  5980. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5981. }
  5982. return 0;
  5983. }
  5984. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5985. if (!lua_interface)
  5986. return 0;
  5987. Spawn* spawn = lua_interface->GetSpawn(state);
  5988. lua_interface->ResetFunctionStack(state);
  5989. if (!spawn) {
  5990. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5991. return 0;
  5992. }
  5993. if (spawn->IsEntity()) {
  5994. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5995. return 1;
  5996. }
  5997. else
  5998. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6002. if (!lua_interface)
  6003. return 0;
  6004. Spawn* spawn = lua_interface->GetSpawn(state);
  6005. lua_interface->ResetFunctionStack(state);
  6006. if (!spawn) {
  6007. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6008. return 0;
  6009. }
  6010. if (spawn->IsEntity()) {
  6011. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6012. return 1;
  6013. }
  6014. else
  6015. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6016. return 0;
  6017. }
  6018. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6019. if (!lua_interface)
  6020. return 0;
  6021. Spawn* player = lua_interface->GetSpawn(state);
  6022. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6023. lua_interface->ResetFunctionStack(state);
  6024. if (!player->IsPlayer()) {
  6025. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6026. return 0;
  6027. }
  6028. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6029. return 1;
  6030. }
  6031. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6032. if (!lua_interface)
  6033. return 0;
  6034. Spawn* spawn = lua_interface->GetSpawn(state);
  6035. int8 slot = lua_interface->GetInt8Value(state, 2);
  6036. lua_interface->ResetFunctionStack(state);
  6037. if (!spawn) {
  6038. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6039. return 0;
  6040. }
  6041. if (!spawn->IsEntity()) {
  6042. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6043. return 0;
  6044. }
  6045. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6046. if (!item) {
  6047. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6048. return 0;
  6049. }
  6050. lua_interface->SetItemValue(state, item);
  6051. return 1;
  6052. }
  6053. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6054. if (!lua_interface)
  6055. return 0;
  6056. Spawn* player = lua_interface->GetSpawn(state);
  6057. int32 id = lua_interface->GetInt32Value(state, 2);
  6058. lua_interface->ResetFunctionStack(state);
  6059. if (!player) {
  6060. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6061. return 0;
  6062. }
  6063. if (!player->IsPlayer()) {
  6064. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6065. return 0;
  6066. }
  6067. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6068. if (!item) {
  6069. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6070. return 0;
  6071. }
  6072. lua_interface->SetItemValue(state, item);
  6073. return 1;
  6074. }
  6075. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6076. if (!lua_interface)
  6077. return 0;
  6078. Spawn* spawn = lua_interface->GetSpawn(state);
  6079. int8 slot = lua_interface->GetInt8Value(state, 2);
  6080. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6081. lua_interface->ResetFunctionStack(state);
  6082. if (!spawn) {
  6083. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6084. return 0;
  6085. }
  6086. if (!spawn->IsEntity()) {
  6087. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6088. return 0;
  6089. }
  6090. Item* item = master_item_list.GetItem(item_id);
  6091. if (!item) {
  6092. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6093. return 0;
  6094. }
  6095. Item* copy = new Item(item);
  6096. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6097. if(result)
  6098. {
  6099. ((Entity*)spawn)->SetEquipment(copy, slot);
  6100. spawn->vis_changed = true;
  6101. if(spawn->IsPlayer())
  6102. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6103. }
  6104. else
  6105. {
  6106. safe_delete(copy);
  6107. }
  6108. lua_interface->SetBooleanValue(state, result);
  6109. return 1;
  6110. }
  6111. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6112. if (!lua_interface)
  6113. return 0;
  6114. Spawn* spawn = lua_interface->GetSpawn(state);
  6115. int8 slot = lua_interface->GetInt8Value(state, 2);
  6116. Item* item = lua_interface->GetItem(state, 3);
  6117. lua_interface->ResetFunctionStack(state);
  6118. if (!spawn) {
  6119. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6120. return 0;
  6121. }
  6122. if (!spawn->IsEntity()) {
  6123. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6124. return 0;
  6125. }
  6126. if (!item) {
  6127. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6128. return 0;
  6129. }
  6130. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6131. if(result)
  6132. {
  6133. ((Entity*)spawn)->SetEquipment(item, slot);
  6134. spawn->vis_changed = true;
  6135. if(spawn->IsPlayer())
  6136. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6137. }
  6138. lua_interface->SetBooleanValue(state, result);
  6139. return 1;
  6140. }
  6141. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6142. if (!lua_interface)
  6143. return 0;
  6144. Spawn* spawn = lua_interface->GetSpawn(state);
  6145. int8 slot = lua_interface->GetInt8Value(state, 2);
  6146. 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
  6147. lua_interface->ResetFunctionStack(state);
  6148. if (!spawn) {
  6149. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6150. return 0;
  6151. }
  6152. if (!spawn->IsEntity()) {
  6153. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6154. return 0;
  6155. }
  6156. if(slot >= NUM_SLOTS) {
  6157. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6158. return 0;
  6159. }
  6160. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6161. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6162. if(item) {
  6163. item->save_needed = true;
  6164. if(no_delete_item) {
  6165. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6166. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6167. }
  6168. else{
  6169. Client* client = ((Player*)spawn)->GetClient();
  6170. client->UnequipItem(item->details.index);
  6171. }
  6172. }
  6173. }
  6174. else
  6175. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6176. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6177. spawn->vis_changed = true;
  6178. if(spawn->IsPlayer())
  6179. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6180. lua_interface->SetBooleanValue(state, true);
  6181. return 1;
  6182. }
  6183. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6184. if (!lua_interface)
  6185. return 0;
  6186. Spawn* spawn = lua_interface->GetSpawn(state);
  6187. int8 slot = lua_interface->GetInt8Value(state, 2);
  6188. int16 type = lua_interface->GetInt16Value(state, 3);
  6189. int8 r = lua_interface->GetInt8Value(state, 4);
  6190. int8 g = lua_interface->GetInt8Value(state, 5);
  6191. int8 b = lua_interface->GetInt8Value(state, 6);
  6192. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6193. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6194. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6195. lua_interface->ResetFunctionStack(state);
  6196. if (!spawn) {
  6197. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6198. return 0;
  6199. }
  6200. if (!spawn->IsEntity()) {
  6201. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6202. return 0;
  6203. }
  6204. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6205. spawn->vis_changed = true;
  6206. lua_interface->SetBooleanValue(state, true);
  6207. return 1;
  6208. }
  6209. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6210. if (!lua_interface)
  6211. return 0;
  6212. Spawn* player = lua_interface->GetSpawn(state);
  6213. int32 id = lua_interface->GetInt32Value(state, 2);
  6214. int8 count = lua_interface->GetInt8Value(state, 3);
  6215. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6216. lua_interface->ResetFunctionStack(state);
  6217. if (!player) {
  6218. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6219. return 0;
  6220. }
  6221. if (!player->IsPlayer()) {
  6222. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6223. return 0;
  6224. }
  6225. if (!count)
  6226. count = 1;
  6227. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6228. if (!item) {
  6229. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6230. return 0;
  6231. }
  6232. lua_interface->SetItemValue(state, item);
  6233. return 1;
  6234. }
  6235. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6236. if (!lua_interface)
  6237. return 0;
  6238. Spawn* spawn = lua_interface->GetSpawn(state);
  6239. int32 anim = lua_interface->GetInt32Value(state, 2);
  6240. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6241. int8 type = lua_interface->GetInt8Value(state, 4);
  6242. lua_interface->ResetFunctionStack(state);
  6243. if (!spawn) {
  6244. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6245. return 0;
  6246. }
  6247. if (spawn2) {
  6248. if (spawn2->IsPlayer()) {
  6249. if (type != 1 && type != 2)
  6250. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6251. else
  6252. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6253. return 0;
  6254. }
  6255. else {
  6256. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6257. return 0;
  6258. }
  6259. }
  6260. else
  6261. spawn->GetZone()->PlayAnimation(spawn, anim);
  6262. return 0;
  6263. }
  6264. int EQ2Emu_lua_IsPet(lua_State* state) {
  6265. if (!lua_interface)
  6266. return 0;
  6267. Spawn* spawn = lua_interface->GetSpawn(state);
  6268. lua_interface->ResetFunctionStack(state);
  6269. if (!spawn) {
  6270. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6271. return 0;
  6272. }
  6273. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6274. return 1;
  6275. }
  6276. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6277. if (!lua_interface)
  6278. return 0;
  6279. Spawn* spawn = lua_interface->GetSpawn(state);
  6280. lua_interface->ResetFunctionStack(state);
  6281. if (!spawn) {
  6282. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6283. return 0;
  6284. }
  6285. if (!spawn->IsNPC()) {
  6286. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6287. return 0;
  6288. }
  6289. if (((NPC*)spawn)->GetOwner()) {
  6290. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6291. return 1;
  6292. }
  6293. return 0;
  6294. }
  6295. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6296. if (!lua_interface)
  6297. return 0;
  6298. Spawn* spawn = lua_interface->GetSpawn(state);
  6299. Spawn* target = lua_interface->GetSpawn(state, 2);
  6300. lua_interface->ResetFunctionStack(state);
  6301. if (!spawn) {
  6302. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6303. return 0;
  6304. }
  6305. if (!spawn) {
  6306. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6307. return 0;
  6308. }
  6309. spawn->SetTarget(target);
  6310. return 0;
  6311. }
  6312. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6313. if (!lua_interface)
  6314. return 0;
  6315. Spawn* spawn = lua_interface->GetSpawn(state);
  6316. bool val = lua_interface->GetBooleanValue(state, 2);
  6317. lua_interface->ResetFunctionStack(state);
  6318. if (!spawn) {
  6319. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6320. return 0;
  6321. }
  6322. if (!spawn->IsEntity()) {
  6323. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6324. return 0;
  6325. }
  6326. ((Entity*)spawn)->InCombat(val);
  6327. if (val) {
  6328. spawn->ClearRunningLocations();
  6329. spawn->CalculateRunningLocation(true);
  6330. }
  6331. return 0;
  6332. }
  6333. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6334. if (!lua_interface)
  6335. return 0;
  6336. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6337. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6338. lua_interface->ResetFunctionStack(state);
  6339. if (!spawn1) {
  6340. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6341. return 0;
  6342. }
  6343. if (!spawn2) {
  6344. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6345. return 0;
  6346. }
  6347. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6348. return 1;
  6349. }
  6350. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6351. if (!lua_interface)
  6352. return 0;
  6353. Spawn* spawn = lua_interface->GetSpawn(state);
  6354. lua_interface->ResetFunctionStack(state);
  6355. if (!spawn) {
  6356. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6357. return 0;
  6358. }
  6359. if (!spawn->IsNPC()) {
  6360. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6361. return 0;
  6362. }
  6363. ((NPC*)spawn)->ClearRunback();
  6364. return 0;
  6365. }
  6366. int EQ2Emu_lua_Runback(lua_State* state) {
  6367. if (!lua_interface)
  6368. return 0;
  6369. Spawn* spawn = lua_interface->GetSpawn(state);
  6370. lua_interface->ResetFunctionStack(state);
  6371. if (!spawn) {
  6372. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6373. return 0;
  6374. }
  6375. if (!spawn->IsNPC()) {
  6376. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6377. return 0;
  6378. }
  6379. ((NPC*)spawn)->Runback();
  6380. return 0;
  6381. }
  6382. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6383. if (!lua_interface)
  6384. return 0;
  6385. Spawn* spawn = lua_interface->GetSpawn(state);
  6386. lua_interface->ResetFunctionStack(state);
  6387. if (!spawn) {
  6388. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6389. return 0;
  6390. }
  6391. if (!spawn->IsNPC()) {
  6392. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6393. return 0;
  6394. }
  6395. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6396. return 1;
  6397. }
  6398. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6399. if (!lua_interface)
  6400. return 0;
  6401. Spawn* spawn = lua_interface->GetSpawn(state);
  6402. lua_interface->ResetFunctionStack(state);
  6403. if (!spawn) {
  6404. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6405. return 0;
  6406. }
  6407. if (!spawn->IsEntity()) {
  6408. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6409. return 0;
  6410. }
  6411. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6412. return 1;
  6413. }
  6414. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6415. if (!lua_interface)
  6416. return 0;
  6417. Spawn* spawn = lua_interface->GetSpawn(state);
  6418. lua_interface->ResetFunctionStack(state);
  6419. if (!spawn) {
  6420. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6421. return 0;
  6422. }
  6423. if (!spawn->IsEntity()) {
  6424. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6425. return 0;
  6426. }
  6427. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6428. return 1;
  6429. }
  6430. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6431. if (!lua_interface)
  6432. return 0;
  6433. Spawn* spawn = lua_interface->GetSpawn(state);
  6434. lua_interface->ResetFunctionStack(state);
  6435. if (!spawn) {
  6436. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6437. return 0;
  6438. }
  6439. if (!spawn->IsEntity()) {
  6440. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6441. return 0;
  6442. }
  6443. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6444. return 1;
  6445. }
  6446. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6447. if (!lua_interface)
  6448. return 0;
  6449. Spawn* spawn = lua_interface->GetSpawn(state);
  6450. lua_interface->ResetFunctionStack(state);
  6451. if (!spawn) {
  6452. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6453. return 0;
  6454. }
  6455. if (!spawn->IsEntity()) {
  6456. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6457. return 0;
  6458. }
  6459. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6460. return 1;
  6461. }
  6462. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6463. if (!lua_interface)
  6464. return 0;
  6465. Spawn* spawn = lua_interface->GetSpawn(state);
  6466. Spawn* target = lua_interface->GetSpawn(state, 2);
  6467. float distance = lua_interface->GetFloatValue(state, 3);
  6468. lua_interface->ResetFunctionStack(state);
  6469. if (!spawn) {
  6470. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6471. return 0;
  6472. }
  6473. if (!target) {
  6474. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6475. return 0;
  6476. }
  6477. if (!spawn->IsNPC()) {
  6478. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6479. return 0;
  6480. }
  6481. if (!target->IsEntity()) {
  6482. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6483. return 0;
  6484. }
  6485. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6486. return 1;
  6487. }
  6488. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6489. if (!lua_interface)
  6490. return 0;
  6491. Spawn* spawn = lua_interface->GetSpawn(state);
  6492. Spawn* target = lua_interface->GetSpawn(state, 2);
  6493. float distance = lua_interface->GetFloatValue(state, 3);
  6494. lua_interface->ResetFunctionStack(state);
  6495. if (!spawn) {
  6496. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6497. return 0;
  6498. }
  6499. if (!target) {
  6500. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6501. return 0;
  6502. }
  6503. if (!spawn->IsNPC()) {
  6504. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6505. return 0;
  6506. }
  6507. if (!target->IsEntity()) {
  6508. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6509. return 0;
  6510. }
  6511. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6512. return 0;
  6513. }
  6514. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6515. if (!lua_interface)
  6516. return 0;
  6517. Spawn* spawn = lua_interface->GetSpawn(state);
  6518. lua_interface->ResetFunctionStack(state);
  6519. if (!spawn) {
  6520. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6521. return 0;
  6522. }
  6523. if (!spawn->IsNPC()) {
  6524. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6525. return 0;
  6526. }
  6527. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6528. return 1;
  6529. }
  6530. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6531. if (!lua_interface)
  6532. return 0;
  6533. Spawn* spawn = lua_interface->GetSpawn(state);
  6534. lua_interface->ResetFunctionStack(state);
  6535. if (!spawn) {
  6536. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6537. return 0;
  6538. }
  6539. if (!spawn->IsNPC()) {
  6540. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6541. return 0;
  6542. }
  6543. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6544. return 1;
  6545. }
  6546. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6547. if (!lua_interface)
  6548. return 0;
  6549. Spawn* spawn = lua_interface->GetSpawn(state);
  6550. lua_interface->ResetFunctionStack(state);
  6551. if (!spawn) {
  6552. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6553. return 0;
  6554. }
  6555. if (!spawn->IsNPC()) {
  6556. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6557. return 0;
  6558. }
  6559. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6560. if (hated) {
  6561. lua_interface->SetSpawnValue(state, hated);
  6562. return 1;
  6563. }
  6564. return 0;
  6565. }
  6566. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6567. if (!lua_interface)
  6568. return 0;
  6569. Spawn* spawn = lua_interface->GetSpawn(state);
  6570. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6571. lua_interface->ResetFunctionStack(state);
  6572. if (!spawn) {
  6573. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6574. return 0;
  6575. }
  6576. if (!spawn->IsNPC()) {
  6577. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6578. return 0;
  6579. }
  6580. if (!hated) {
  6581. ((NPC*)spawn)->Brain()->ClearHate();
  6582. return 0;
  6583. }
  6584. else
  6585. {
  6586. if (!hated->IsEntity()) {
  6587. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6588. return 0;
  6589. }
  6590. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6591. return 0;
  6592. }
  6593. return 0;
  6594. }
  6595. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6596. if (!lua_interface)
  6597. return 0;
  6598. Spawn* spawn = lua_interface->GetSpawn(state);
  6599. lua_interface->ResetFunctionStack(state);
  6600. if (!spawn) {
  6601. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6602. return 0;
  6603. }
  6604. if (!spawn->IsNPC()) {
  6605. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6606. return 0;
  6607. }
  6608. ((NPC*)spawn)->Brain()->ClearEncounter();
  6609. return 0;
  6610. }
  6611. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6612. if (!lua_interface)
  6613. return 0;
  6614. Spawn* spawn = lua_interface->GetSpawn(state);
  6615. lua_interface->ResetFunctionStack(state);
  6616. if (!spawn) {
  6617. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6618. return 0;
  6619. }
  6620. if (!spawn->IsNPC()) {
  6621. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6622. return 0;
  6623. }
  6624. // Temp list to store hate list
  6625. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6626. if (encounterList->size() == 0) {
  6627. safe_delete(encounterList);
  6628. return 0;
  6629. }
  6630. lua_createtable(state, encounterList->size(), 0);
  6631. int newTable = lua_gettop(state);
  6632. for (int32 i = 0; i < encounterList->size(); i++) {
  6633. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6634. if (temp)
  6635. lua_interface->SetSpawnValue(state, temp);
  6636. lua_rawseti(state, newTable, i + 1);
  6637. }
  6638. safe_delete(encounterList);
  6639. return 1;
  6640. }
  6641. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6642. if (!lua_interface)
  6643. return 0;
  6644. Spawn* spawn = lua_interface->GetSpawn(state);
  6645. lua_interface->ResetFunctionStack(state);
  6646. if (!spawn) {
  6647. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6648. return 0;
  6649. }
  6650. if (!spawn->IsNPC()) {
  6651. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6652. return 0;
  6653. }
  6654. // Temp list to store hate list
  6655. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6656. if (hateList->size() == 0) {
  6657. safe_delete(hateList);
  6658. return 0;
  6659. }
  6660. lua_createtable(state, hateList->size(), 0);
  6661. int newTable = lua_gettop(state);
  6662. for (int32 i = 0; i < hateList->size(); i++) {
  6663. lua_interface->SetSpawnValue(state, hateList->at(i));
  6664. lua_rawseti(state, newTable, i + 1);
  6665. }
  6666. safe_delete(hateList);
  6667. return 1;
  6668. }
  6669. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6670. if (!lua_interface)
  6671. return 0;
  6672. Spawn* spawn = lua_interface->GetSpawn(state);
  6673. lua_interface->ResetFunctionStack(state);
  6674. if (!spawn) {
  6675. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6676. return 0;
  6677. }
  6678. if (spawn->IsPlayer()) {
  6679. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6680. lua_interface->SetBooleanValue(state, true);
  6681. else
  6682. lua_interface->SetBooleanValue(state, false);
  6683. return 1;
  6684. }
  6685. else {
  6686. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6687. return 1;
  6688. }
  6689. }
  6690. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6691. if (!lua_interface)
  6692. return 0;
  6693. Quest* quest = lua_interface->GetQuest(state);
  6694. lua_interface->ResetFunctionStack(state);
  6695. if (!quest) {
  6696. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6697. return 0;
  6698. }
  6699. quest->SetCompletedFlag(true);
  6700. return 0;
  6701. }
  6702. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6703. if (!lua_interface)
  6704. return 0;
  6705. Spawn* spawn = lua_interface->GetSpawn(state);
  6706. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6707. int8 tier = lua_interface->GetInt8Value(state, 3);
  6708. lua_interface->ResetFunctionStack(state);
  6709. if (!spawn) {
  6710. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6711. return 0;
  6712. }
  6713. if (!spawn->IsEntity()) {
  6714. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6715. return 0;
  6716. }
  6717. if (spellID == 0) {
  6718. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6719. return 0;
  6720. }
  6721. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6722. if (effect) {
  6723. if (tier > 0) {
  6724. // If a tier was passed chec to see if it is the same as the effect
  6725. if (tier == effect->tier)
  6726. lua_interface->SetBooleanValue(state, true);
  6727. else
  6728. lua_interface->SetBooleanValue(state, false);
  6729. return 1;
  6730. }
  6731. else {
  6732. // Have an effect but no tier was passed so return true
  6733. lua_interface->SetBooleanValue(state, true);
  6734. }
  6735. return 1;
  6736. }
  6737. // no effect so return false
  6738. lua_interface->SetBooleanValue(state, false);
  6739. return 1;
  6740. }
  6741. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6742. if (!lua_interface)
  6743. return 0;
  6744. Spawn* spawn = lua_interface->GetSpawn(state);
  6745. int32 id = lua_interface->GetInt32Value(state, 2);
  6746. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6747. lua_interface->ResetFunctionStack(state);
  6748. Spawn* spawn2 = 0;
  6749. vector<Spawn*> list;
  6750. if (!spawn) {
  6751. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6752. return 0;
  6753. }
  6754. //If zone not provided, use spawn's zone
  6755. if (!zone)
  6756. zone = spawn->GetZone();
  6757. list = zone->GetSpawnsByID(id);
  6758. if (list.size() == 0) {
  6759. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6760. return 0;
  6761. }
  6762. vector<Spawn*>::iterator itr = list.begin();
  6763. for (int8 i = 0; i < list.size(); i++) {
  6764. spawn2 = itr[i];
  6765. if (spawn2)
  6766. spawn2->AddAllowAccessSpawn(spawn);
  6767. }
  6768. return 0;
  6769. }
  6770. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6771. if (!lua_interface)
  6772. return 0;
  6773. Spawn* spawn = lua_interface->GetSpawn(state);
  6774. int32 id = lua_interface->GetInt32Value(state, 2);
  6775. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6776. lua_interface->ResetFunctionStack(state);
  6777. Spawn* spawn2 = 0;
  6778. if (!spawn) {
  6779. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6780. return 0;
  6781. }
  6782. //If zone not provided, use spawn's zone
  6783. if (!zone)
  6784. zone = spawn->GetZone();
  6785. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6786. vector<Spawn*>::iterator itr = list.begin();
  6787. if (list.size() == 0) {
  6788. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6789. return 0;
  6790. }
  6791. for (int8 i = 0; i < list.size(); i++) {
  6792. spawn2 = itr[i];
  6793. if (spawn2)
  6794. spawn2->RemoveSpawnAccess(spawn);
  6795. }
  6796. return 0;
  6797. }
  6798. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6799. if (!lua_interface)
  6800. return 0;
  6801. Quest* quest = lua_interface->GetQuest(state);
  6802. lua_interface->ResetFunctionStack(state);
  6803. if (!quest) {
  6804. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6805. return 0;
  6806. }
  6807. quest->SetYellowName(true);
  6808. return 0;
  6809. }
  6810. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6811. if (!lua_interface)
  6812. return 0;
  6813. Spawn* spawn = lua_interface->GetSpawn(state);
  6814. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6815. lua_interface->ResetFunctionStack(state);
  6816. if (!spawn) {
  6817. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6818. return 0;
  6819. }
  6820. if (!spawn->IsPlayer()) {
  6821. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6822. return 0;
  6823. }
  6824. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6825. return 1;
  6826. }
  6827. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6828. if (!lua_interface)
  6829. return 0;
  6830. Spawn* spawn = lua_interface->GetSpawn(state);
  6831. lua_interface->ResetFunctionStack(state);
  6832. if (!spawn) {
  6833. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6834. return 0;
  6835. }
  6836. if (!spawn->IsPlayer()) {
  6837. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. ZoneServer* zone = spawn->GetZone();
  6841. if (!zone) {
  6842. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6843. return 0;
  6844. }
  6845. Instance_Type iType = zone->GetInstanceType();
  6846. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6847. iType == GROUP_LOCKOUT_INSTANCE ||
  6848. iType == RAID_LOCKOUT_INSTANCE ||
  6849. iType == SOLO_PERSIST_INSTANCE ||
  6850. iType == GROUP_PERSIST_INSTANCE ||
  6851. iType == RAID_PERSIST_INSTANCE) {
  6852. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6853. if (data) {
  6854. // Check to see if the timer has already been set, if it has return out.
  6855. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6856. return 0;
  6857. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6858. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6859. if(spawn->IsPlayer()) {
  6860. Client* client = ((Player*)spawn)->GetClient();
  6861. if (client) {
  6862. string time_msg = "";
  6863. int32 time = data->success_lockout_time;
  6864. int16 hour;
  6865. int8 min;
  6866. int8 sec;
  6867. hour = time / 3600;
  6868. time = time % 3600;
  6869. min = time / 60;
  6870. time = time % 60;
  6871. sec = time;
  6872. if (hour > 0) {
  6873. char temp[10];
  6874. sprintf(temp, " %i", hour);
  6875. time_msg.append(temp);
  6876. time_msg.append(" hour");
  6877. time_msg.append((hour > 1) ? "s" : "");
  6878. }
  6879. if (min > 0) {
  6880. char temp[5];
  6881. sprintf(temp, " %i", min);
  6882. time_msg.append(temp);
  6883. time_msg.append(" minute");
  6884. time_msg.append((min > 1) ? "s" : "");
  6885. }
  6886. // Only add seconds if minutes and hours are 0
  6887. if (hour == 0 && min == 0 && sec > 0) {
  6888. char temp[5];
  6889. sprintf(temp, " %i", sec);
  6890. time_msg.append(temp);
  6891. time_msg.append(" second");
  6892. time_msg.append((sec > 1) ? "s" : "");
  6893. }
  6894. 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());
  6895. }
  6896. else {
  6897. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6898. }
  6899. }
  6900. }
  6901. else
  6902. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6903. }
  6904. else
  6905. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6906. return 0;
  6907. }
  6908. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6909. if (!lua_interface)
  6910. return 0;
  6911. Spawn* spawn = lua_interface->GetSpawn(state);
  6912. lua_interface->ResetFunctionStack(state);
  6913. if (!spawn) {
  6914. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6915. return 0;
  6916. }
  6917. if (!spawn->IsPlayer()) {
  6918. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6919. return 0;
  6920. }
  6921. ZoneServer* zone = spawn->GetZone();
  6922. if (!zone) {
  6923. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6924. return 0;
  6925. }
  6926. Instance_Type iType = zone->GetInstanceType();
  6927. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6928. iType == GROUP_LOCKOUT_INSTANCE ||
  6929. iType == RAID_LOCKOUT_INSTANCE ||
  6930. iType == SOLO_PERSIST_INSTANCE ||
  6931. iType == GROUP_PERSIST_INSTANCE ||
  6932. iType == RAID_PERSIST_INSTANCE) {
  6933. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6934. if (data) {
  6935. // Check to see if the timer has already been set, if it has return out.
  6936. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6937. return 0;
  6938. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6939. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6940. if(spawn->IsPlayer()) {
  6941. Client* client = ((Player*)spawn)->GetClient();
  6942. if (client) {
  6943. string time_msg = "";
  6944. int32 time = data->failure_lockout_time;
  6945. int16 hour;
  6946. int8 min;
  6947. int8 sec;
  6948. hour = time / 3600;
  6949. time = time % 3600;
  6950. min = time / 60;
  6951. time = time % 60;
  6952. sec = time;
  6953. if (hour > 0) {
  6954. char temp[10];
  6955. sprintf(temp, " %i", hour);
  6956. time_msg.append(temp);
  6957. time_msg.append(" hour");
  6958. time_msg.append((hour > 1) ? "s" : "");
  6959. }
  6960. if (min > 0) {
  6961. char temp[5];
  6962. sprintf(temp, " %i", min);
  6963. time_msg.append(temp);
  6964. time_msg.append(" minute");
  6965. time_msg.append((min > 1) ? "s" : "");
  6966. }
  6967. // Only add seconds if minutes and hours are 0
  6968. if (hour == 0 && min == 0 && sec > 0) {
  6969. char temp[5];
  6970. sprintf(temp, " %i", sec);
  6971. time_msg.append(temp);
  6972. time_msg.append(" second");
  6973. time_msg.append((sec > 1) ? "s" : "");
  6974. }
  6975. 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());
  6976. }
  6977. }
  6978. else {
  6979. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6980. }
  6981. }
  6982. else
  6983. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6984. }
  6985. else
  6986. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6987. return 0;
  6988. }
  6989. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6990. if (!lua_interface)
  6991. return 0;
  6992. Spawn* spawn = lua_interface->GetSpawn(state);
  6993. lua_interface->ResetFunctionStack(state);
  6994. if (!spawn) {
  6995. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6996. return 0;
  6997. }
  6998. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6999. return 1;
  7000. }
  7001. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7002. if (!lua_interface)
  7003. return 0;
  7004. Spawn* player = lua_interface->GetSpawn(state);
  7005. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7006. if (!player) {
  7007. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7008. lua_interface->ResetFunctionStack(state);
  7009. return 0;
  7010. }
  7011. if (!player->IsPlayer()) {
  7012. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7013. lua_interface->ResetFunctionStack(state);
  7014. return 0;
  7015. }
  7016. if (!ground) {
  7017. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7018. lua_interface->ResetFunctionStack(state);
  7019. return 0;
  7020. }
  7021. if (!ground->IsGroundSpawn()) {
  7022. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7023. lua_interface->ResetFunctionStack(state);
  7024. return 0;
  7025. }
  7026. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7027. if (!groundspawn_entries) {
  7028. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7029. lua_interface->ResetFunctionStack(state);
  7030. return 0;
  7031. }
  7032. Skill* skill = 0;
  7033. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7034. if (collection_skill == "Collecting")
  7035. skill = ((Player*)player)->GetSkillByName("Gathering");
  7036. else
  7037. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7038. if (!skill) {
  7039. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7040. lua_interface->ResetFunctionStack(state);
  7041. return 0;
  7042. }
  7043. vector<GroundSpawnEntry*>::iterator itr;
  7044. GroundSpawnEntry* entry = 0;
  7045. bool can_harvest = false;
  7046. sint32 min_skill = -1;
  7047. int16 totalSkill = skill->current_val;
  7048. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7049. if(skillID != 0xFFFFFFFF)
  7050. {
  7051. ((Entity*)player)->MStats.lock();
  7052. totalSkill += ((Entity*)player)->stats[skillID];
  7053. ((Entity*)player)->MStats.unlock();
  7054. }
  7055. // first, iterate through groundspawn_entries, discard tables player cannot use
  7056. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7057. {
  7058. entry = *itr;
  7059. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7060. min_skill = entry->min_skill_level;
  7061. // if player lacks skill, skip table
  7062. if (entry->min_skill_level > totalSkill)
  7063. continue;
  7064. // if bonus, but player lacks level, skip table
  7065. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7066. continue;
  7067. can_harvest = true;
  7068. break;
  7069. }
  7070. lua_interface->SetBooleanValue(state, can_harvest);
  7071. // If false, send the message to the client
  7072. if (!can_harvest) {
  7073. Client* client = ((Player*)player)->GetClient();
  7074. if (client) {
  7075. string msg = "You do not have enough skill to ";
  7076. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7077. msg.append("gather");
  7078. else if (collection_skill == "Mining")
  7079. msg.append("mine");
  7080. else if (collection_skill == "Trapping")
  7081. msg.append("trap");
  7082. else if (collection_skill == "Foresting")
  7083. msg.append("forest");
  7084. else if (collection_skill == "Fishing")
  7085. msg.append("catch");
  7086. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7087. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7088. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7089. }
  7090. }
  7091. lua_interface->ResetFunctionStack(state);
  7092. return 1;
  7093. }
  7094. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7095. if (!lua_interface)
  7096. return 0;
  7097. Spawn* player = lua_interface->GetSpawn(state);
  7098. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7099. lua_interface->ResetFunctionStack(state);
  7100. if (!player) {
  7101. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7102. return 0;
  7103. }
  7104. if (!player->IsPlayer()) {
  7105. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7106. return 0;
  7107. }
  7108. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7109. lua_interface->SetBooleanValue(state, ret);
  7110. return 1;
  7111. }
  7112. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7113. // Check to see if we have a valid lua_interface
  7114. if (!lua_interface)
  7115. return 0;
  7116. // Get the spawn that is getting the pet
  7117. Spawn* spawn = lua_interface->GetSpawn(state);
  7118. Spawn* target = lua_interface->GetSpawn(state, 2);
  7119. // Get the DB ID of the pet
  7120. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7121. float x = lua_interface->GetFloatValue(state, 4);
  7122. float y = lua_interface->GetFloatValue(state, 5);
  7123. float z = lua_interface->GetFloatValue(state, 6);
  7124. // Get the spell that this command was called from
  7125. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7126. lua_interface->ResetFunctionStack(state);
  7127. // Check to make sure the spawn pointer is valid
  7128. if (!spawn) {
  7129. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7130. return 0;
  7131. }
  7132. // Check to make sure the spawn is an entity
  7133. if (!spawn->IsEntity()) {
  7134. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7135. return 0;
  7136. }
  7137. if (!target) {
  7138. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7139. return 0;
  7140. }
  7141. if (!target->IsEntity()) {
  7142. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7143. return 0;
  7144. }
  7145. // Check to see if the DB ID for the pet is set
  7146. if (pet_id == 0) {
  7147. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7148. return 0;
  7149. }
  7150. // Check to see if the pointer to the spell is valid
  7151. if (!luaspell) {
  7152. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7153. return 0;
  7154. }
  7155. if(luaspell->resisted) {
  7156. return 0;
  7157. }
  7158. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7159. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7160. if (!pet) {
  7161. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7162. return 0;
  7163. }
  7164. // Check to make sure the pet is an npc
  7165. if (!pet->IsNPC()) {
  7166. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7167. return 0;
  7168. }
  7169. if (x == 0)
  7170. x = spawn->GetX();
  7171. if (y == 0)
  7172. y = spawn->GetY();
  7173. if (z == 0)
  7174. z = spawn->GetZ();
  7175. // Spawn the pet at the same location as the owner
  7176. pet->SetX(x);
  7177. pet->SetY(y);
  7178. pet->SetZ(z);
  7179. pet->SetLocation(spawn->GetLocation());
  7180. pet->SetHeading(spawn->GetHeading());
  7181. spawn->GetZone()->AddSpawn(pet);
  7182. const char* spawn_script = world.GetSpawnScript(pet_id);
  7183. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7184. spawn->SetSpawnScript(string(spawn_script));
  7185. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7186. }
  7187. std::string petName = std::string("");
  7188. if(spawn->IsEntity()) {
  7189. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7190. }
  7191. if(petName.size() < 1) {
  7192. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7193. petName = spawn->GetZone()->pet_names.at(rand_index);
  7194. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7195. }
  7196. // Set the pets name
  7197. pet->SetName(petName.c_str());
  7198. // Set the level of the pet to the owners level
  7199. pet->SetLevel(spawn->GetLevel());
  7200. // Set the faction of the pet to the same faction as the owner
  7201. pet->SetFactionID(spawn->GetFactionID());
  7202. // Set the spawn as a pet
  7203. pet->SetPet(true);
  7204. // Give a pointer of the owner to the pet
  7205. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7206. // Set the pet type
  7207. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7208. // Set the spell id used to create this pet
  7209. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7210. // Set the spell tier used to create this pet
  7211. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7212. // Set the pets spawn type to 6
  7213. pet->SetSpawnType(6);
  7214. // Set the pets brain
  7215. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7216. // Check to see if the pet has a subtitle
  7217. if (strlen(pet->GetSubTitle()) > 0) {
  7218. // Add the players name to the front of the sub title
  7219. string pet_subtitle;
  7220. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7221. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7222. // Set the pets subtitle to the new one
  7223. pet->SetSubTitle(pet_subtitle.c_str());
  7224. }
  7225. // Set the pet as the return value for this function
  7226. lua_interface->SetSpawnValue(state, pet);
  7227. return 1;
  7228. }
  7229. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7230. if (!lua_interface)
  7231. return 0;
  7232. Spawn* spawn = lua_interface->GetSpawn(state);
  7233. Spawn* player = lua_interface->GetSpawn(state, 2);
  7234. float max_distance = lua_interface->GetFloatValue(state, 3);
  7235. string type = lua_interface->GetStringValue(state, 4);
  7236. lua_interface->ResetFunctionStack(state);
  7237. if (!spawn || (spawn && spawn->IsPlayer())) {
  7238. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7239. return 0;
  7240. }
  7241. if (!player || !player->IsPlayer()) {
  7242. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7243. return 0;
  7244. }
  7245. Client* client = ((Player*)player)->GetClient();
  7246. if (!client) {
  7247. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7248. return 0;
  7249. }
  7250. //Set max_distance to default if not set or not proper value
  7251. if (max_distance <= 0)
  7252. max_distance = 500;
  7253. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7254. if (packet) {
  7255. float unknown2_3 = 0;
  7256. int8 placement_mode = 0;
  7257. if (type == "wall") {
  7258. placement_mode = 2;
  7259. unknown2_3 = 150;
  7260. }
  7261. else if (type == "ceiling")
  7262. placement_mode = 1;
  7263. packet->setDataByName("placement_mode", placement_mode);
  7264. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7265. packet->setDataByName("model_type", spawn->GetModelType());
  7266. packet->setDataByName("unknown", 1); //size
  7267. packet->setDataByName("unknown2", 1); //size 2
  7268. packet->setDataByName("unknown2", .5, 1); //size 3
  7269. packet->setDataByName("unknown2", 3, 2);
  7270. packet->setDataByName("unknown2", unknown2_3, 3);
  7271. packet->setDataByName("max_distance", max_distance);
  7272. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7273. client->QueuePacket(packet->serialize());
  7274. safe_delete(packet);
  7275. }
  7276. return 0;
  7277. }
  7278. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7279. if (!lua_interface)
  7280. return 0;
  7281. Item* item = lua_interface->GetItem(state);
  7282. lua_interface->ResetFunctionStack(state);
  7283. if (!item) {
  7284. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7285. return 0;
  7286. }
  7287. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7288. return 1;
  7289. }
  7290. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7291. if (!lua_interface)
  7292. return 0;
  7293. Item* item = lua_interface->GetItem(state);
  7294. lua_interface->ResetFunctionStack(state);
  7295. if (!item) {
  7296. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7297. return 0;
  7298. }
  7299. lua_interface->SetInt32Value(state, item->effect_type);
  7300. return 1;
  7301. }
  7302. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7303. if (!lua_interface)
  7304. return 0;
  7305. Spawn* spawn = lua_interface->GetSpawn(state);
  7306. lua_interface->ResetFunctionStack(state);
  7307. if (!spawn) {
  7308. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7309. return 0;
  7310. }
  7311. if (spawn->GetZone())
  7312. spawn->GetZone()->AddTransportSpawn(spawn);
  7313. return 0;
  7314. }
  7315. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7316. if (!lua_interface)
  7317. return 0;
  7318. Spawn* spawn = lua_interface->GetSpawn(state);
  7319. lua_interface->ResetFunctionStack(state);
  7320. if (!spawn) {
  7321. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7322. return 0;
  7323. }
  7324. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7325. return 1;
  7326. }
  7327. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7328. if (!lua_interface)
  7329. return 0;
  7330. Skill* skill = lua_interface->GetSkill(state);
  7331. lua_interface->ResetFunctionStack(state);
  7332. if (!skill) {
  7333. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7334. return 0;
  7335. }
  7336. lua_interface->SetInt32Value(state, skill->current_val);
  7337. return 1;
  7338. }
  7339. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7340. if (!lua_interface)
  7341. return 0;
  7342. Skill* skill = lua_interface->GetSkill(state);
  7343. lua_interface->ResetFunctionStack(state);
  7344. if (!skill) {
  7345. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7346. return 0;
  7347. }
  7348. lua_interface->SetInt32Value(state, skill->max_val);
  7349. return 1;
  7350. }
  7351. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7352. if (!lua_interface)
  7353. return 0;
  7354. Skill* skill = lua_interface->GetSkill(state);
  7355. lua_interface->ResetFunctionStack(state);
  7356. if (!skill) {
  7357. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7358. return 0;
  7359. }
  7360. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7361. return 1;
  7362. }
  7363. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7364. if (!lua_interface)
  7365. return 0;
  7366. Skill* skill = lua_interface->GetSkill(state);
  7367. int16 value = lua_interface->GetInt16Value(state, 2);
  7368. lua_interface->ResetFunctionStack(state);
  7369. if (!skill) {
  7370. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7371. return 0;
  7372. }
  7373. skill->max_val = value;
  7374. if (skill->max_val < skill->current_val)
  7375. skill->current_val = skill->max_val;
  7376. return 0;
  7377. }
  7378. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7379. if (!lua_interface)
  7380. return 0;
  7381. Skill* skill = lua_interface->GetSkill(state);
  7382. int16 value = lua_interface->GetInt16Value(state, 2);
  7383. lua_interface->ResetFunctionStack(state);
  7384. if (!skill) {
  7385. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7386. return 0;
  7387. }
  7388. if (value > skill->max_val)
  7389. skill->current_val = skill->max_val;
  7390. else
  7391. skill->current_val = value;
  7392. return 0;
  7393. }
  7394. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7395. if (!lua_interface)
  7396. return 0;
  7397. Spawn* player = lua_interface->GetSpawn(state);
  7398. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7399. lua_interface->ResetFunctionStack(state);
  7400. if (skill_id > 0 && player && player->IsPlayer()) {
  7401. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7402. return 1;
  7403. }
  7404. return 0;
  7405. }
  7406. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7407. if (!lua_interface)
  7408. return 0;
  7409. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7410. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7411. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7412. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7413. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7414. lua_interface->ResetFunctionStack(state);
  7415. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7416. if (player_spawn && player_spawn->IsPlayer()) {
  7417. Player* player = (Player*)player_spawn;
  7418. bool added = false;
  7419. if (!player->skill_list.HasSkill(skill_id)) {
  7420. player->AddSkill(skill_id, current_val, max_val, true);
  7421. added = true;
  7422. }
  7423. 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
  7424. Client* client = player->GetClient();
  7425. if (client) {
  7426. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7427. if (packet)
  7428. client->QueuePacket(packet);
  7429. }
  7430. }
  7431. if (added) {
  7432. lua_interface->SetBooleanValue(state, true);
  7433. return 1;
  7434. }
  7435. }
  7436. else {
  7437. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7438. }
  7439. }
  7440. else {
  7441. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7442. }
  7443. lua_interface->SetBooleanValue(state, false);
  7444. return 1;
  7445. }
  7446. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7447. if (!lua_interface)
  7448. return 0;
  7449. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7450. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7451. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7452. lua_interface->ResetFunctionStack(state);
  7453. if (skill_id > 0) {
  7454. if (player_spawn && player_spawn->IsPlayer()) {
  7455. Player* player = (Player*)player_spawn;
  7456. if (player->skill_list.HasSkill(skill_id)) {
  7457. player->RemovePlayerSkill(skill_id);
  7458. if (!more_to_remove) {
  7459. Client* client = player->GetClient();
  7460. if (client) {
  7461. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7462. if (packet)
  7463. client->QueuePacket(packet);
  7464. }
  7465. }
  7466. }
  7467. }
  7468. else {
  7469. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7470. }
  7471. }
  7472. else {
  7473. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7474. }
  7475. return 0;
  7476. }
  7477. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7478. if (!lua_interface)
  7479. return 0;
  7480. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7481. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7482. int16 amount = lua_interface->GetInt8Value(state, 3);
  7483. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7484. lua_interface->ResetFunctionStack(state);
  7485. if (amount > 0 && skill_type < 100) {
  7486. if (player_spawn && player_spawn->IsPlayer()) {
  7487. Player* player = (Player*)player_spawn;
  7488. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7489. if (!more_to_increase) {
  7490. Client* client = player->GetClient();
  7491. if (client) {
  7492. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7493. if (packet)
  7494. client->QueuePacket(packet);
  7495. }
  7496. }
  7497. }
  7498. else {
  7499. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7500. }
  7501. }
  7502. else {
  7503. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7504. }
  7505. return 0;
  7506. }
  7507. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7508. if (!lua_interface)
  7509. return 0;
  7510. Spawn* spawn = lua_interface->GetSpawn(state);
  7511. string name = lua_interface->GetStringValue(state, 2);
  7512. lua_interface->ResetFunctionStack(state);
  7513. if (!spawn) {
  7514. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7515. return 0;
  7516. }
  7517. if (!spawn->IsEntity()) {
  7518. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7519. return 0;
  7520. }
  7521. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7522. if (skill) {
  7523. lua_interface->SetSkillValue(state, skill);
  7524. return 1;
  7525. }
  7526. return 0;
  7527. }
  7528. int EQ2Emu_lua_AddProc(lua_State* state) {
  7529. if (!lua_interface)
  7530. return 0;
  7531. Spawn* spawn = lua_interface->GetSpawn(state);
  7532. int8 type = lua_interface->GetInt8Value(state, 2);
  7533. float chance = lua_interface->GetFloatValue(state, 3);
  7534. Item* item = lua_interface->GetItem(state, 4);
  7535. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7536. LuaSpell* spell = 0;
  7537. if (!spawn && (!spell || !use_all_spelltargets)) {
  7538. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7539. return 0;
  7540. }
  7541. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7542. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7543. return 0;
  7544. }
  7545. if (!item)
  7546. spell = lua_interface->GetCurrentSpell(state);
  7547. if (!item && !spell) {
  7548. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7549. return 0;
  7550. }
  7551. if(spell && spell->resisted) {
  7552. return 0;
  7553. }
  7554. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7555. Spawn* target;
  7556. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7557. for (int8 i = 0; i < spell->targets.size(); i++) {
  7558. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7559. if (!target || !target->IsEntity())
  7560. continue;
  7561. ((Entity*)target)->AddProc(type, chance, item, spell);
  7562. }
  7563. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7564. }
  7565. else
  7566. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7567. return 0;
  7568. }
  7569. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7570. if (!lua_interface)
  7571. return 0;
  7572. Spawn* spawn = lua_interface->GetSpawn(state);
  7573. Item* item = lua_interface->GetItem(state, 2);
  7574. LuaSpell* spell = 0;
  7575. if (!spawn) {
  7576. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7577. lua_interface->ResetFunctionStack(state);
  7578. return 0;
  7579. }
  7580. if (!spawn->IsEntity()) {
  7581. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7582. lua_interface->ResetFunctionStack(state);
  7583. return 0;
  7584. }
  7585. if (!item)
  7586. spell = lua_interface->GetCurrentSpell(state);
  7587. lua_interface->ResetFunctionStack(state);
  7588. if (!item && !spell) {
  7589. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7590. return 0;
  7591. }
  7592. if (spell && spell->caster && spell->caster->GetZone()) {
  7593. Spawn* target;
  7594. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7595. for (int8 i = 0; i < spell->targets.size(); i++) {
  7596. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7597. if (!target || !target->IsEntity())
  7598. continue;
  7599. ((Entity*)target)->RemoveProc(item, spell);
  7600. }
  7601. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7602. spell->caster->RemoveProc(item, spell);
  7603. }
  7604. else
  7605. ((Entity*)spawn)->RemoveProc(item, spell);
  7606. return 0;
  7607. }
  7608. int EQ2Emu_lua_Knockback(lua_State* state) {
  7609. if (!lua_interface)
  7610. return 0;
  7611. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7612. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7613. int32 duration = lua_interface->GetInt32Value(state, 3);
  7614. float vertical = lua_interface->GetFloatValue(state, 4);
  7615. float horizontal = lua_interface->GetFloatValue(state, 5);
  7616. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7617. lua_interface->ResetFunctionStack(state);
  7618. if (!target_spawn) {
  7619. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7620. return 0;
  7621. }
  7622. if (!spawn) {
  7623. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7624. return 0;
  7625. }
  7626. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7627. Client* client = ((Player*)spawn)->GetClient();
  7628. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7629. if (packet) {
  7630. packet->setDataByName("target_x", target_spawn->GetX());
  7631. packet->setDataByName("target_y", target_spawn->GetY());
  7632. packet->setDataByName("target_z", target_spawn->GetZ());
  7633. packet->setDataByName("vertical_movement", vertical);
  7634. packet->setDataByName("horizontal_movement", horizontal);
  7635. if (use_heading)
  7636. packet->setDataByName("use_player_heading", 1);
  7637. client->QueuePacket(packet->serialize());
  7638. }
  7639. safe_delete(packet);
  7640. }
  7641. return 0;
  7642. }
  7643. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7644. if (!lua_interface)
  7645. return 0;
  7646. Spawn* spawn = lua_interface->GetSpawn(state);
  7647. lua_interface->ResetFunctionStack(state);
  7648. if (!spawn) {
  7649. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7650. return 0;
  7651. }
  7652. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7653. return 1;
  7654. }
  7655. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7656. if (!lua_interface)
  7657. return 0;
  7658. Spawn* caster = lua_interface->GetSpawn(state);
  7659. Spawn* target = lua_interface->GetSpawn(state, 2);
  7660. string name = lua_interface->GetStringValue(state, 3);
  7661. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7662. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7663. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7664. string success_msg = lua_interface->GetStringValue(state, 7);
  7665. string effect_msg = lua_interface->GetStringValue(state, 8);
  7666. lua_interface->ResetFunctionStack(state);
  7667. if (!caster) {
  7668. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7669. return 0;
  7670. }
  7671. if (!caster->IsEntity()) {
  7672. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7673. return 0;
  7674. }
  7675. if (!target) {
  7676. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7677. return 0;
  7678. }
  7679. if (!target->IsEntity()) {
  7680. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7681. return 0;
  7682. }
  7683. if (name.length() == 0) {
  7684. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7685. return 0;
  7686. }
  7687. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7688. return 0;
  7689. }
  7690. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7691. if (!lua_interface)
  7692. return 0;
  7693. string name = lua_interface->GetStringValue(state);
  7694. lua_interface->ResetFunctionStack(state);
  7695. if (name.length() == 0) {
  7696. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7697. return 0;
  7698. }
  7699. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7700. if (!skill) {
  7701. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7702. return 0;
  7703. }
  7704. lua_interface->SetInt32Value(state, skill->skill_id);
  7705. return 1;
  7706. }
  7707. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7708. if (!lua_interface)
  7709. return 0;
  7710. Spawn* spawn = lua_interface->GetSpawn(state);
  7711. lua_interface->ResetFunctionStack(state);
  7712. if (!spawn) {
  7713. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7714. return 0;
  7715. }
  7716. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7717. return 1;
  7718. }
  7719. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7720. if (!lua_interface)
  7721. return 0;
  7722. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7723. lua_interface->ResetFunctionStack(state);
  7724. if (!luaspell) {
  7725. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7726. return 0;
  7727. }
  7728. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7729. return 1;
  7730. }
  7731. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7732. if (!lua_interface)
  7733. return 0;
  7734. Spawn* spawn = lua_interface->GetSpawn(state);
  7735. Spawn* target = lua_interface->GetSpawn(state, 2);
  7736. lua_interface->ResetFunctionStack(state);
  7737. if (!spawn) {
  7738. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7739. return 0;
  7740. }
  7741. if (!spawn->IsEntity()) {
  7742. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7743. return 0;
  7744. }
  7745. if (!target) {
  7746. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7747. return 0;
  7748. }
  7749. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7750. return 1;
  7751. }
  7752. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7753. if (!lua_interface)
  7754. return 0;
  7755. Spawn* spawn = lua_interface->GetSpawn(state);
  7756. Spawn* target = lua_interface->GetSpawn(state, 2);
  7757. lua_interface->ResetFunctionStack(state);
  7758. if (!spawn) {
  7759. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7760. return 0;
  7761. }
  7762. if (!spawn->IsEntity()) {
  7763. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7764. return 0;
  7765. }
  7766. if (!target) {
  7767. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7768. return 0;
  7769. }
  7770. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7771. return 1;
  7772. }
  7773. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7774. if (!lua_interface)
  7775. return 0;
  7776. Item* item = lua_interface->GetItem(state);
  7777. lua_interface->ResetFunctionStack(state);
  7778. if (!item) {
  7779. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7780. return 0;
  7781. }
  7782. lua_interface->SetInt32Value(state, item->details.count);
  7783. return 1;
  7784. }
  7785. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7786. if (!lua_interface)
  7787. return 0;
  7788. Item* item = lua_interface->GetItem(state);
  7789. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7790. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7791. lua_interface->ResetFunctionStack(state);
  7792. if (!item) {
  7793. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7794. return 0;
  7795. }
  7796. if (!owner) {
  7797. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7798. return 0;
  7799. }
  7800. if (!owner->IsPlayer()) {
  7801. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7802. return 0;
  7803. }
  7804. if (item->stack_count < new_count) {
  7805. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7806. return 0;
  7807. }
  7808. if (new_count > 0) {
  7809. item->details.count = new_count;
  7810. item->save_needed = true;
  7811. }
  7812. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7813. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7814. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7815. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7816. else
  7817. {
  7818. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7819. return 0;
  7820. }
  7821. Client* client = ((Player*)owner)->GetClient();
  7822. if (!client)
  7823. return 0;
  7824. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7825. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7826. if (app)
  7827. client->QueuePacket(app);
  7828. return 0;
  7829. }
  7830. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7831. if (!lua_interface)
  7832. return 0;
  7833. int32 time = lua_interface->GetInt32Value(state);
  7834. string function = lua_interface->GetStringValue(state, 2);
  7835. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7836. Spawn* target = lua_interface->GetSpawn(state, 4);
  7837. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7838. lua_interface->ResetFunctionStack(state);
  7839. if (time == 0) {
  7840. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7841. return 0;
  7842. }
  7843. if (function.length() == 0) {
  7844. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7845. return 0;
  7846. }
  7847. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  7848. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7849. return 0;
  7850. }
  7851. SpellScriptTimer* timer = new SpellScriptTimer;
  7852. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7853. #ifdef WIN32
  7854. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7855. #else
  7856. bzero(timer, sizeof(SpellScriptTimer));
  7857. #endif*/
  7858. timer->caster = 0;
  7859. timer->deleteWhenDone = false;
  7860. timer->target = 0;
  7861. timer->time = Timer::GetCurrentTime2() + time;
  7862. timer->customFunction = function;
  7863. timer->spell = spell;
  7864. if (caster)
  7865. timer->caster = caster->GetID();
  7866. if (target)
  7867. timer->target = target->GetID();
  7868. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7869. return 0;
  7870. }
  7871. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7872. if (!lua_interface)
  7873. return 0;
  7874. float hp_perc = lua_interface->GetFloatValue(state);
  7875. float power_perc = lua_interface->GetFloatValue(state, 2);
  7876. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7877. Spawn* target = lua_interface->GetSpawn(state, 4);
  7878. string heal_name = lua_interface->GetStringValue(state, 5);
  7879. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7880. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7881. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7882. lua_interface->ResetFunctionStack(state);
  7883. if (!spell) {
  7884. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7885. return 0;
  7886. }
  7887. Entity* caster = spell->caster;
  7888. if (!caster) {
  7889. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7890. return 0;
  7891. }
  7892. Client* client = 0;
  7893. PendingResurrection* rez = 0;
  7894. ZoneServer* zone = spell->caster->GetZone();
  7895. if (!target) {
  7896. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7897. if (spell->targets.size() > 0) {
  7898. vector<int32> spell_targets = spell->targets;
  7899. for (int8 i = 0; i < spell_targets.size(); i++) {
  7900. target = zone->GetSpawnByID(spell_targets.at(i));
  7901. if (!target)
  7902. continue;
  7903. if (!target->IsPlayer())
  7904. continue;
  7905. client = ((Player*)target)->GetClient();
  7906. if (!client)
  7907. continue;
  7908. rez = client->GetCurrentRez();
  7909. if (rez->active)
  7910. continue;
  7911. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7912. rez->active = true;
  7913. rez->caster = caster;
  7914. rez->expire_timer = new Timer;
  7915. int32 duration = spell->spell->GetSpellDuration();
  7916. rez->expire_timer->Start(duration * 100);
  7917. rez->hp_perc = hp_perc;
  7918. rez->mp_perc = power_perc;
  7919. rez->range = spell->spell->GetSpellData()->range;
  7920. rez->spell_name = spell->spell->GetName();
  7921. if (heal_name.length() > 0)
  7922. rez->heal_name = heal_name;
  7923. else
  7924. rez->heal_name = rez->spell_name;
  7925. rez->no_calcs = no_calcs;
  7926. rez->crit_mod = crit_mod;
  7927. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7928. if (send_window)
  7929. client->SendResurrectionWindow();
  7930. else {
  7931. target->GetZone()->ResurrectSpawn(target, client);
  7932. rez->should_delete = true;
  7933. }
  7934. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7935. }
  7936. }
  7937. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7938. }
  7939. else {
  7940. if(!target->IsPlayer())
  7941. return 0;
  7942. client = ((Player*)target)->GetClient();
  7943. if (!client)
  7944. return 0;
  7945. rez = client->GetCurrentRez();
  7946. if (rez->active)
  7947. return 0;
  7948. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7949. rez->active = true;
  7950. rez->caster = caster;
  7951. rez->expire_timer = new Timer;
  7952. int32 duration = spell->spell->GetSpellDuration();
  7953. rez->expire_timer->Start(duration * 100);
  7954. rez->hp_perc = hp_perc;
  7955. rez->mp_perc = power_perc;
  7956. rez->range = spell->spell->GetSpellData()->range;
  7957. rez->spell_name = spell->spell->GetName();
  7958. if (heal_name.length() > 0)
  7959. rez->heal_name = heal_name;
  7960. else
  7961. rez->heal_name = rez->spell_name;
  7962. rez->no_calcs = no_calcs;
  7963. rez->crit_mod = crit_mod;
  7964. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7965. if (send_window)
  7966. client->SendResurrectionWindow();
  7967. else {
  7968. target->GetZone()->ResurrectSpawn(target, client);
  7969. rez->should_delete = true;
  7970. }
  7971. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7972. }
  7973. return 0;
  7974. }
  7975. int EQ2Emu_lua_SetVision(lua_State* state) {
  7976. if (!lua_interface)
  7977. return 0;
  7978. Spawn* spawn = lua_interface->GetSpawn(state);
  7979. int32 vision = lua_interface->GetInt32Value(state, 2);
  7980. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7981. lua_interface->ResetFunctionStack(state);
  7982. if (!spawn) {
  7983. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7984. return 0;
  7985. }
  7986. if (!spawn->IsEntity()) {
  7987. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7988. return 0;
  7989. }
  7990. if (spell && spell->targets.size() > 0) {
  7991. ZoneServer* zone = spell->caster->GetZone();
  7992. for (int8 i = 0; i < spell->targets.size(); i++) {
  7993. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7994. if (target && target->IsEntity()) {
  7995. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7996. if (target->IsPlayer())
  7997. ((Player*)target)->SetCharSheetChanged(true);
  7998. }
  7999. }
  8000. }
  8001. else {
  8002. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8003. if (spawn->IsPlayer())
  8004. ((Player*)spawn)->SetCharSheetChanged(true);
  8005. }
  8006. return 0;
  8007. }
  8008. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8009. if (!lua_interface)
  8010. return 0;
  8011. Spawn* spawn = lua_interface->GetSpawn(state);
  8012. float intensity = lua_interface->GetFloatValue(state, 2);
  8013. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8014. lua_interface->ResetFunctionStack(state);
  8015. if (!spawn) {
  8016. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8017. return 0;
  8018. }
  8019. if (!spawn->IsEntity()) {
  8020. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8021. return 0;
  8022. }
  8023. if (spell && spell->targets.size() > 0) {
  8024. ZoneServer* zone = spell->caster->GetZone();
  8025. for (int8 i = 0; i < spell->targets.size(); i++) {
  8026. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8027. if (target && target->IsEntity()) {
  8028. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8029. if (target->IsPlayer())
  8030. ((Player*)target)->SetCharSheetChanged(true);
  8031. }
  8032. }
  8033. }
  8034. else {
  8035. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8036. if (spawn->IsPlayer())
  8037. ((Player*)spawn)->SetCharSheetChanged(true);
  8038. }
  8039. return 0;
  8040. }
  8041. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8042. if (!lua_interface)
  8043. return 0;
  8044. Spawn* spawn = lua_interface->GetSpawn(state);
  8045. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8046. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8047. lua_interface->ResetFunctionStack(state);
  8048. if (!spawn) {
  8049. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8050. return 0;
  8051. }
  8052. if (!spawn->IsEntity()) {
  8053. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8054. return 0;
  8055. }
  8056. if (spell && spell->targets.size() > 0) {
  8057. ZoneServer* zone = spell->caster->GetZone();
  8058. for (int8 i = 0; i < spell->targets.size(); i++) {
  8059. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8060. if (target && target->IsEntity()) {
  8061. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8062. if (target->IsPlayer())
  8063. ((Player*)target)->SetCharSheetChanged(true);
  8064. }
  8065. }
  8066. }
  8067. else {
  8068. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8069. if (spawn->IsPlayer())
  8070. ((Player*)spawn)->SetCharSheetChanged(true);
  8071. }
  8072. return 0;
  8073. }
  8074. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8075. if (!lua_interface)
  8076. return 0;
  8077. Item* item = lua_interface->GetItem(state);
  8078. int8 type = lua_interface->GetInt32Value(state, 2);
  8079. lua_interface->ResetFunctionStack(state);
  8080. if (!item) {
  8081. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8082. return 0;
  8083. }
  8084. if (type == 1)
  8085. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8086. else if (type == 2)
  8087. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8088. return 1;
  8089. }
  8090. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8091. if (!lua_interface)
  8092. return 0;
  8093. Spawn* target = lua_interface->GetSpawn(state);
  8094. float val = lua_interface->GetFloatValue(state, 2);
  8095. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8096. lua_interface->ResetFunctionStack(state);
  8097. // Added from Gangrenous post
  8098. if (spell && spell->resisted)
  8099. return 0;
  8100. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8101. if (val > 1.0f)
  8102. val = 1.0f - (val / 100.0f);
  8103. if (spell && spell->spell && spell->targets.size() > 0) {
  8104. ZoneServer* zone = spell->caster->GetZone();
  8105. for (int32 i = 0; i != spell->targets.size(); i++) {
  8106. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8107. if (spawn && spawn->IsEntity()) {
  8108. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8109. if (spawn->IsPlayer())
  8110. ((Player*)spawn)->SetCharSheetChanged(true);
  8111. }
  8112. }
  8113. }
  8114. else {
  8115. if (target && target->IsEntity()) {
  8116. ((Entity*)target)->SetSpeedMultiplier(val);
  8117. if (target->IsPlayer())
  8118. ((Player*)target)->SetCharSheetChanged(true);
  8119. }
  8120. }
  8121. return 0;
  8122. }
  8123. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8124. if (!lua_interface)
  8125. return 0;
  8126. Spawn* spawn = lua_interface->GetSpawn(state);
  8127. int16 model = lua_interface->GetInt16Value(state, 2);
  8128. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8129. lua_interface->ResetFunctionStack(state);
  8130. if (spell && spell->spell && spell->targets.size() > 0) {
  8131. ZoneServer* zone = spell->caster->GetZone();
  8132. for (int32 i = 0; i < spell->targets.size(); i++) {
  8133. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8134. if (target)
  8135. target->SetIllusionModel(model);
  8136. }
  8137. }
  8138. else {
  8139. if (!spawn) {
  8140. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8141. return 0;
  8142. }
  8143. spawn->SetIllusionModel(model);
  8144. }
  8145. return 0;
  8146. }
  8147. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8148. if (!lua_interface)
  8149. return 0;
  8150. Spawn* spawn = lua_interface->GetSpawn(state);
  8151. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8152. lua_interface->ResetFunctionStack(state);
  8153. if (spell && spell->spell && spell->targets.size() > 0) {
  8154. ZoneServer* zone = spell->caster->GetZone();
  8155. for (int32 i = 0; i < spell->targets.size(); i++) {
  8156. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8157. if (target)
  8158. target->SetIllusionModel(0);
  8159. }
  8160. }
  8161. else {
  8162. if (!spawn) {
  8163. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8164. return 0;
  8165. }
  8166. spawn->SetIllusionModel(0);
  8167. }
  8168. return 0;
  8169. }
  8170. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8171. if (!lua_interface)
  8172. return 0;
  8173. Spawn* caster = lua_interface->GetSpawn(state);
  8174. Spawn* target = lua_interface->GetSpawn(state, 2);
  8175. float chance = lua_interface->GetFloatValue(state, 3);
  8176. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8177. lua_interface->ResetFunctionStack(state);
  8178. if (!caster) {
  8179. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8180. return 0;
  8181. }
  8182. if (!caster->IsEntity()) {
  8183. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8184. return 0;
  8185. }
  8186. if (!target) {
  8187. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8188. return 0;
  8189. }
  8190. if (!target->IsEntity()) {
  8191. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8192. return 0;
  8193. }
  8194. if (chance <= 0) {
  8195. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8196. return 0;
  8197. }
  8198. if (!spell) {
  8199. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8200. return 0;
  8201. }
  8202. if(spell->resisted) {
  8203. return 0;
  8204. }
  8205. if (((Entity*)caster)->GetThreatTransfer()) {
  8206. return 0;
  8207. }
  8208. ThreatTransfer* transfer = new ThreatTransfer;
  8209. transfer->Target = target->GetID();
  8210. transfer->Amount = chance;
  8211. transfer->Spell = spell;
  8212. ((Entity*)caster)->SetThreatTransfer(transfer);
  8213. return 0;
  8214. }
  8215. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8216. if (!lua_interface)
  8217. return 0;
  8218. Spawn* spawn = lua_interface->GetSpawn(state);
  8219. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8220. lua_interface->ResetFunctionStack(state);
  8221. if (!spawn) {
  8222. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8223. return 0;
  8224. }
  8225. if (!spell) {
  8226. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8227. return 0;
  8228. }
  8229. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8230. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8231. if(transfer && transfer->Spell != spell) {
  8232. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8233. return 0;
  8234. }
  8235. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8236. }
  8237. return 0;
  8238. }
  8239. int EQ2Emu_lua_CureByType(lua_State* state) {
  8240. if (!lua_interface)
  8241. return 0;
  8242. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8243. int8 cure_count = lua_interface->GetInt8Value(state);
  8244. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8245. string cure_name = lua_interface->GetStringValue(state, 3);
  8246. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8247. Spawn* target = lua_interface->GetSpawn(state, 5);
  8248. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8249. lua_interface->ResetFunctionStack(state);
  8250. if(spell && spell->resisted) {
  8251. return 0;
  8252. }
  8253. if (target) {
  8254. if (!target->IsEntity()) {
  8255. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8256. return 0;
  8257. }
  8258. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8259. std::string alternate_name = "item";
  8260. if(spell)
  8261. alternate_name = std::string(spell->spell->GetName());
  8262. if(!caster && spell)
  8263. caster = (Spawn*)spell->caster;
  8264. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8265. }
  8266. }
  8267. else {
  8268. ZoneServer* zone = spell->caster->GetZone();
  8269. vector<int32> targets = spell->targets;
  8270. vector<Entity*> targets_to_cure;
  8271. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8272. for (int8 i = 0; i < targets.size(); i++) {
  8273. target = zone->GetSpawnByID(targets.at(i));
  8274. if (!target || !target->IsEntity())
  8275. continue;
  8276. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8277. targets_to_cure.push_back((Entity*)target);
  8278. }
  8279. }
  8280. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8281. vector<Entity*>::iterator itr;
  8282. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8283. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8284. }
  8285. }
  8286. return 0;
  8287. }
  8288. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8289. if (!lua_interface)
  8290. return 0;
  8291. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8292. if (!spell) {
  8293. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8294. lua_interface->ResetFunctionStack(state);
  8295. return 0;
  8296. }
  8297. if(spell->resisted) {
  8298. lua_interface->ResetFunctionStack(state);
  8299. return 0;
  8300. }
  8301. int8 cure_count = lua_interface->GetInt8Value(state);
  8302. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8303. string cure_name = lua_interface->GetStringValue(state, 3);
  8304. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8305. Spawn* target = lua_interface->GetSpawn(state, 5);
  8306. lua_interface->ResetFunctionStack(state);
  8307. if (target) {
  8308. if (!target->IsEntity()) {
  8309. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8310. return 0;
  8311. }
  8312. if (((Entity*)target)->GetDetCount() > 0)
  8313. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8314. }
  8315. else {
  8316. ZoneServer* zone = spell->caster->GetZone();
  8317. vector<int32> targets = spell->targets;
  8318. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8319. for (int8 i = 0; i < targets.size(); i++) {
  8320. target = zone->GetSpawnByID(targets.at(i));
  8321. if (!target || !target->IsEntity())
  8322. continue;
  8323. if (((Entity*)target)->GetDetCount() > 0)
  8324. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8325. }
  8326. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8327. }
  8328. return 0;
  8329. }
  8330. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8331. if (!lua_interface)
  8332. return 0;
  8333. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8334. lua_interface->ResetFunctionStack(state);
  8335. if (!spell) {
  8336. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8337. return 0;
  8338. }
  8339. if (!spell->caster) {
  8340. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8341. return 0;
  8342. }
  8343. if (!spell->caster->GetZone()) {
  8344. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8345. return 0;
  8346. }
  8347. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8348. return 0;
  8349. }
  8350. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8351. if (!lua_interface)
  8352. return 0;
  8353. Spawn* spawn = lua_interface->GetSpawn(state);
  8354. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8355. lua_interface->ResetFunctionStack(state);
  8356. if (!spell) {
  8357. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8358. return 0;
  8359. }
  8360. if (spawn && spawn->IsEntity())
  8361. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8362. else {
  8363. ZoneServer* zone = spell->caster->GetZone();
  8364. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8365. for (int32 i = 0; i < spell->targets.size(); i++) {
  8366. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8367. if (!spawn || !spawn->IsEntity())
  8368. continue;
  8369. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8370. }
  8371. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8372. }
  8373. return 0;
  8374. }
  8375. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8376. if (!lua_interface)
  8377. return 0;
  8378. Spawn* spawn = lua_interface->GetSpawn(state);
  8379. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8380. lua_interface->ResetFunctionStack(state);
  8381. if (!spell) {
  8382. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8383. return 0;
  8384. }
  8385. if (spawn && spawn->IsEntity())
  8386. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8387. else {
  8388. ZoneServer* zone = spell->caster->GetZone();
  8389. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8390. for (int32 i = 0; i < spell->targets.size(); i++) {
  8391. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8392. if (!spawn || !spawn->IsEntity())
  8393. continue;
  8394. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8395. }
  8396. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8397. }
  8398. return 0;
  8399. }
  8400. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8401. if (!lua_interface)
  8402. return 0;
  8403. Spawn* caster = lua_interface->GetSpawn(state);
  8404. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8405. lua_interface->ResetFunctionStack(state);
  8406. if (!caster) {
  8407. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8408. return 0;
  8409. }
  8410. if (!caster->IsPlayer()) {
  8411. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8412. return 0;
  8413. }
  8414. Spawn* target = caster->GetTarget();
  8415. if (!target) {
  8416. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8417. return 0;
  8418. }
  8419. Client* client = ((Player*)caster)->GetClient();
  8420. if (!client) {
  8421. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8422. return 0;
  8423. }
  8424. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8425. if (ho) {
  8426. ho->SetTarget(target->GetID());
  8427. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8428. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8429. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8430. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8431. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8432. deque<GroupMemberInfo*>::iterator itr;
  8433. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8434. if (group)
  8435. {
  8436. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8437. deque<GroupMemberInfo*>* members = group->GetMembers();
  8438. for (itr = members->begin(); itr != members->end(); itr++) {
  8439. if ((*itr)->client)
  8440. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8441. }
  8442. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8443. }
  8444. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8445. }
  8446. else
  8447. safe_delete(ho);
  8448. }
  8449. else {
  8450. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8451. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8452. }
  8453. else
  8454. safe_delete(ho);
  8455. }
  8456. }
  8457. return 0;
  8458. }
  8459. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8460. if (!lua_interface)
  8461. return 0;
  8462. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8463. if (!spell) {
  8464. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8465. return 0;
  8466. }
  8467. int16 triggerCount = lua_interface->GetInt16Value(state);
  8468. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8469. if (!triggerCount) {
  8470. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8471. return 0;
  8472. }
  8473. spell->num_triggers = triggerCount;
  8474. spell->had_triggers = true;
  8475. spell->cancel_after_all_triggers = cancel_after_triggers;
  8476. return 0;
  8477. }
  8478. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8479. if (!lua_interface)
  8480. return 0;
  8481. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8482. lua_interface->ResetFunctionStack(state);
  8483. if (!spell) {
  8484. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8485. return 0;
  8486. }
  8487. lua_interface->SetInt32Value(state, spell->num_triggers);
  8488. return 1;
  8489. }
  8490. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8491. if (!lua_interface)
  8492. return 0;
  8493. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8494. if (!spell) {
  8495. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8496. lua_interface->ResetFunctionStack(state);
  8497. return 0;
  8498. }
  8499. if (!spell->caster || !spell->caster->GetZone()) {
  8500. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8501. lua_interface->ResetFunctionStack(state);
  8502. return 0;
  8503. }
  8504. int16 remove_count = lua_interface->GetInt16Value(state);
  8505. lua_interface->ResetFunctionStack(state);
  8506. if (!remove_count)
  8507. remove_count = 1;
  8508. if (remove_count >= spell->num_triggers) {
  8509. spell->num_triggers = 0;
  8510. if (spell->cancel_after_all_triggers)
  8511. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8512. }
  8513. else {
  8514. spell->num_triggers -= remove_count;
  8515. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8516. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8517. }
  8518. return 0;
  8519. }
  8520. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8521. if (!lua_interface)
  8522. return 0;
  8523. Spawn* spawn = lua_interface->GetSpawn(state);
  8524. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8525. lua_interface->ResetFunctionStack(state);
  8526. if (!spawn) {
  8527. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8528. return 0;
  8529. }
  8530. if (!copy_spawn) {
  8531. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8532. return 0;
  8533. }
  8534. spawn->CopySpawnAppearance(copy_spawn);
  8535. return 0;
  8536. }
  8537. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8538. Spawn* spawn = lua_interface->GetSpawn(state);
  8539. int8 type = lua_interface->GetInt8Value(state, 2);
  8540. lua_interface->ResetFunctionStack(state);
  8541. if (!spawn) {
  8542. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8543. return 0;
  8544. }
  8545. else if (!spawn->IsEntity()) {
  8546. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8547. return 0;
  8548. }
  8549. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8550. return 1;
  8551. }
  8552. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8553. if (!lua_interface)
  8554. return 0;
  8555. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8556. int8 type = lua_interface->GetInt8Value(state);
  8557. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8558. lua_interface->ResetFunctionStack(state);
  8559. if (!spell) {
  8560. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8561. return 0;
  8562. }
  8563. if(spell->resisted) {
  8564. return 0;
  8565. }
  8566. if (spawn) {
  8567. if (!spawn->IsEntity()) {
  8568. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8569. return 0;
  8570. }
  8571. Entity* entity = ((Entity*)spawn);
  8572. entity->AddImmunity(spell, type);
  8573. }
  8574. else if(spell->caster && spell->caster->GetZone()) {
  8575. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8576. for (int8 i = 0; i < spell->targets.size(); i++) {
  8577. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8578. if (!spawn || !spawn->IsEntity())
  8579. continue;
  8580. Entity* entity = ((Entity*)spawn);
  8581. entity->AddImmunity(spell, type);
  8582. }
  8583. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8584. }
  8585. return 0;
  8586. }
  8587. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8588. if (!lua_interface)
  8589. return 0;
  8590. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8591. int8 type = lua_interface->GetInt8Value(state);
  8592. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8593. lua_interface->ResetFunctionStack(state);
  8594. if (!spell) {
  8595. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8596. return 0;
  8597. }
  8598. if (spawn) {
  8599. if (!spawn->IsEntity()) {
  8600. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8601. return 0;
  8602. }
  8603. Entity* entity = ((Entity*)spawn);
  8604. entity->RemoveImmunity(spell, type);
  8605. }
  8606. else if(spell->caster && spell->caster->GetZone()) {
  8607. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8608. for (int8 i = 0; i < spell->targets.size(); i++) {
  8609. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8610. if (!spawn || !spawn->IsEntity())
  8611. continue;
  8612. Entity* entity = ((Entity*)spawn);
  8613. entity->RemoveImmunity(spell, type);
  8614. }
  8615. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8616. }
  8617. return 0;
  8618. }
  8619. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8620. if (!lua_interface)
  8621. return 0;
  8622. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8623. if (!spell) {
  8624. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8625. lua_interface->ResetFunctionStack(state);
  8626. return 0;
  8627. }
  8628. if(spell->resisted) {
  8629. lua_interface->ResetFunctionStack(state);
  8630. return 0;
  8631. }
  8632. float snare = lua_interface->GetFloatValue(state);
  8633. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8634. lua_interface->ResetFunctionStack(state);
  8635. // convert the val to the speed multipler value (100 - val)
  8636. float val = 100.0 - snare;
  8637. val /= 100.0;
  8638. if (spawn) {
  8639. if (!spawn->IsEntity()) {
  8640. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8641. return 0;
  8642. }
  8643. ((Entity*)spawn)->SetSnareValue(spell, val);
  8644. }
  8645. else if(spell->caster && spell->caster->GetZone()) {
  8646. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8647. for (int8 i = 0; i < spell->targets.size(); i++) {
  8648. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8649. if (!spawn || !spawn->IsEntity())
  8650. continue;
  8651. ((Entity*)spawn)->SetSnareValue(spell, val);
  8652. }
  8653. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8654. }
  8655. return 0;
  8656. }
  8657. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8658. if (!lua_interface)
  8659. return 0;
  8660. Spawn* spawn = lua_interface->GetSpawn(state);
  8661. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8662. lua_interface->ResetFunctionStack(state);
  8663. if (!spawn) {
  8664. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8665. return 0;
  8666. }
  8667. if (race_id == 0) {
  8668. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8669. return 0;
  8670. }
  8671. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8672. return 1;
  8673. }
  8674. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8675. if (!lua_interface)
  8676. return 0;
  8677. Spawn* spawn = lua_interface->GetSpawn(state);
  8678. lua_interface->ResetFunctionStack(state);
  8679. if (!spawn) {
  8680. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8681. return 0;
  8682. }
  8683. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8684. return 1;
  8685. }
  8686. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8687. if (!lua_interface)
  8688. return 0;
  8689. Spawn* spawn = lua_interface->GetSpawn(state);
  8690. lua_interface->ResetFunctionStack(state);
  8691. if (!spawn) {
  8692. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8693. return 0;
  8694. }
  8695. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8696. return 1;
  8697. }
  8698. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8699. if (!lua_interface)
  8700. return 0;
  8701. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8702. lua_interface->ResetFunctionStack(state);
  8703. if (!spell) {
  8704. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8705. return 0;
  8706. }
  8707. lua_interface->SetStringValue(state, spell->spell->GetName());
  8708. return 1;
  8709. }
  8710. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8711. if (!lua_interface)
  8712. return 0;
  8713. Quest* quest = lua_interface->GetQuest(state);
  8714. lua_interface->ResetFunctionStack(state);
  8715. if (!quest) {
  8716. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8717. return 0;
  8718. }
  8719. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8720. return 1;
  8721. }
  8722. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8723. if (!lua_interface)
  8724. return 0;
  8725. Quest* quest = lua_interface->GetQuest(state);
  8726. int32 flags = lua_interface->GetInt32Value(state, 2);
  8727. lua_interface->ResetFunctionStack(state);
  8728. if (!quest) {
  8729. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8730. return 0;
  8731. }
  8732. quest->SetQuestFlags(flags);
  8733. return 0;
  8734. }
  8735. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8736. if (!lua_interface)
  8737. return 0;
  8738. Quest* quest = lua_interface->GetQuest(state);
  8739. Spawn* player = lua_interface->GetSpawn(state, 2);
  8740. int32 step = lua_interface->GetInt32Value(state, 3);
  8741. int32 duration = lua_interface->GetInt32Value(state, 4);
  8742. string action = lua_interface->GetStringValue(state, 5);
  8743. lua_interface->ResetFunctionStack(state);
  8744. if (!quest) {
  8745. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8746. return 0;
  8747. }
  8748. if (!player) {
  8749. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8750. return 0;
  8751. }
  8752. if (!player->IsPlayer()) {
  8753. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8754. return 0;
  8755. }
  8756. if (step == 0) {
  8757. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8758. return 0;
  8759. }
  8760. if (duration == 0) {
  8761. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8762. return 0;
  8763. }
  8764. if (action.length() == 0) {
  8765. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8766. return 0;
  8767. }
  8768. Client* client = ((Player*)player)->GetClient();
  8769. if (!client) {
  8770. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8771. return 0;
  8772. }
  8773. quest->SetTimerStep(step);
  8774. quest->AddFailedAction(step, action);
  8775. quest->SetStepTimer(duration);
  8776. client->AddQuestTimer(quest->GetQuestID());
  8777. return 0;
  8778. }
  8779. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8780. if (!lua_interface)
  8781. return 0;
  8782. Quest* quest = lua_interface->GetQuest(state);
  8783. Spawn* player = lua_interface->GetSpawn(state, 2);
  8784. lua_interface->ResetFunctionStack(state);
  8785. if (!quest) {
  8786. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8787. return 0;
  8788. }
  8789. if (!player) {
  8790. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8791. return 0;
  8792. }
  8793. if (!player->IsPlayer()) {
  8794. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8795. return 0;
  8796. }
  8797. Client* client = ((Player*)player)->GetClient();
  8798. if (!client) {
  8799. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8800. return 0;
  8801. }
  8802. quest->SetTimerStep(0);
  8803. quest->SetStepTimer(0);
  8804. client->RemoveQuestTimer(quest->GetQuestID());
  8805. return 0;
  8806. }
  8807. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8808. if (!lua_interface)
  8809. return 0;
  8810. Spawn* player = lua_interface->GetSpawn(state);
  8811. Quest* quest = lua_interface->GetQuest(state, 2);
  8812. int32 step = lua_interface->GetInt32Value(state, 3);
  8813. lua_interface->ResetFunctionStack(state);
  8814. if (!player) {
  8815. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8816. return 0;
  8817. }
  8818. if (!player->IsPlayer()) {
  8819. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8820. return 0;
  8821. }
  8822. if (!quest) {
  8823. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8824. return 0;
  8825. }
  8826. if (step == 0) {
  8827. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8828. return 0;
  8829. }
  8830. Client* client = ((Player*)player)->GetClient();
  8831. if (!client) {
  8832. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8833. return 0;
  8834. }
  8835. if (quest->RemoveQuestStep(step, client)) {
  8836. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8837. client->GetCurrentZone()->SendQuestUpdates(client);
  8838. }
  8839. else
  8840. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8841. return 0;
  8842. }
  8843. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8844. if (!lua_interface)
  8845. return 0;
  8846. Quest* quest = lua_interface->GetQuest(state, 1);
  8847. int32 step = lua_interface->GetInt32Value(state, 2);
  8848. string desc = lua_interface->GetStringValue(state, 3);
  8849. string task_group = lua_interface->GetStringValue(state, 4);
  8850. lua_interface->ResetFunctionStack(state);
  8851. if (!quest) {
  8852. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8853. return 0;
  8854. }
  8855. if (step == 0) {
  8856. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8857. return 0;
  8858. }
  8859. QuestStep* quest_step = quest->GetQuestStep(step);
  8860. if (!quest_step) {
  8861. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8862. return 0;
  8863. }
  8864. quest_step->SetStepProgress(0);
  8865. quest_step->SetTaskGroup(task_group);
  8866. quest_step->SetDescription(desc);
  8867. return 0;
  8868. }
  8869. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8870. if (!lua_interface)
  8871. return 0;
  8872. Quest* quest = lua_interface->GetQuest(state);
  8873. int32 step = lua_interface->GetInt32Value(state, 2);
  8874. string action = lua_interface->GetStringValue(state, 3);
  8875. lua_interface->ResetFunctionStack(state);
  8876. if (!quest) {
  8877. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8878. return 0;
  8879. }
  8880. if (step == 0) {
  8881. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8882. return 0;
  8883. }
  8884. if (action.length() == 0) {
  8885. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8886. return 0;
  8887. }
  8888. quest->AddFailedAction(step, action);
  8889. return 0;
  8890. }
  8891. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8892. if (!lua_interface)
  8893. return 0;
  8894. Spawn* player = lua_interface->GetSpawn(state);
  8895. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8896. int32 step = lua_interface->GetInt32Value(state, 3);
  8897. lua_interface->ResetFunctionStack(state);
  8898. if (!player) {
  8899. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8900. return 0;
  8901. }
  8902. if (!player->IsPlayer()) {
  8903. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8904. return 0;
  8905. }
  8906. if (quest_id == 0) {
  8907. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8908. return 0;
  8909. }
  8910. if (step == 0) {
  8911. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8912. return 0;
  8913. }
  8914. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8915. if (!quest) {
  8916. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8917. return 0;
  8918. }
  8919. quest->StepFailed(step);
  8920. return 0;
  8921. }
  8922. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8923. if (!lua_interface)
  8924. return 0;
  8925. Spawn* player = lua_interface->GetSpawn(state);
  8926. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8927. lua_interface->ResetFunctionStack(state);
  8928. if (!player) {
  8929. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8930. return 0;
  8931. }
  8932. if (!player->IsPlayer()) {
  8933. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8934. return 0;
  8935. }
  8936. if (quest_id == 0) {
  8937. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8938. return 0;
  8939. }
  8940. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  8941. return 1;
  8942. }
  8943. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8944. if (!lua_interface)
  8945. return 0;
  8946. string name = lua_interface->GetStringValue(state);
  8947. string value = lua_interface->GetStringValue(state, 2);
  8948. string comment = lua_interface->GetStringValue(state, 3);
  8949. lua_interface->ResetFunctionStack(state);
  8950. if (name.length() == 0) {
  8951. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8952. return 0;
  8953. }
  8954. if (value.length() == 0) {
  8955. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8956. return 0;
  8957. }
  8958. string varname = string("lua_").append(name);
  8959. Variable* var = variables.FindVariable(varname);
  8960. if (var)
  8961. var->SetValue(value.c_str());
  8962. else {
  8963. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8964. variables.AddVariable(var);
  8965. }
  8966. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8967. return 0;
  8968. }
  8969. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8970. if (!lua_interface)
  8971. return 0;
  8972. string name = lua_interface->GetStringValue(state);
  8973. lua_interface->ResetFunctionStack(state);
  8974. if (name.length() == 0) {
  8975. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8976. return 0;
  8977. }
  8978. string varname = string("lua_").append(name);
  8979. Variable* var = variables.FindVariable(varname);
  8980. if (var)
  8981. lua_interface->SetStringValue(state, var->GetValue());
  8982. else
  8983. lua_interface->SetStringValue(state, "NULL");
  8984. return 1;
  8985. }
  8986. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8987. if (!lua_interface)
  8988. return 0;
  8989. Spawn* player = lua_interface->GetSpawn(state);
  8990. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8991. lua_interface->ResetFunctionStack(state);
  8992. if (!player) {
  8993. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8994. return 0;
  8995. }
  8996. if (!player->IsPlayer()) {
  8997. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8998. return 0;
  8999. }
  9000. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9001. return 1;
  9002. }
  9003. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9004. if (!lua_interface)
  9005. return 0;
  9006. Spawn* player = lua_interface->GetSpawn(state);
  9007. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9008. lua_interface->ResetFunctionStack(state);
  9009. if (!player) {
  9010. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9011. return 0;
  9012. }
  9013. if (!player->IsPlayer()) {
  9014. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9015. return 0;
  9016. }
  9017. Language* language = master_languages_list.GetLanguage(language_id);
  9018. if (language)
  9019. {
  9020. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9021. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9022. }
  9023. return 0;
  9024. }
  9025. int EQ2Emu_lua_IsNight(lua_State* state) {
  9026. if (!lua_interface)
  9027. return 0;
  9028. ZoneServer* zone = lua_interface->GetZone(state);
  9029. lua_interface->ResetFunctionStack(state);
  9030. if (!zone) {
  9031. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9032. return 0;
  9033. }
  9034. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9035. return 1;
  9036. }
  9037. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9038. if (!lua_interface)
  9039. return 0;
  9040. Spawn* spawn = lua_interface->GetSpawn(state);
  9041. lua_interface->ResetFunctionStack(state);
  9042. if (!spawn) {
  9043. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9044. return 0;
  9045. }
  9046. if (!spawn->IsWidget()) {
  9047. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9048. return 0;
  9049. }
  9050. ((Widget*)spawn)->SetMultiFloorLift(true);
  9051. if (spawn->GetZone())
  9052. spawn->GetZone()->AddTransportSpawn(spawn);
  9053. return 0;
  9054. }
  9055. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9056. if (!lua_interface)
  9057. return 0;
  9058. Spawn* player = lua_interface->GetSpawn(state);
  9059. int32 path = lua_interface->GetInt32Value(state, 2);
  9060. lua_interface->ResetFunctionStack(state);
  9061. if (!player) {
  9062. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9063. return 0;
  9064. }
  9065. if (!player->IsPlayer()) {
  9066. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9067. return 0;
  9068. }
  9069. if (path == 0) {
  9070. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9071. return 0;
  9072. }
  9073. Client* client = ((Player*)player)->GetClient();
  9074. if (!client) {
  9075. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9076. return 0;
  9077. }
  9078. client->SendFlightAutoMount(path);
  9079. return 0;
  9080. }
  9081. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9082. if (!lua_interface)
  9083. return 0;
  9084. Spawn* player = lua_interface->GetSpawn(state);
  9085. if (!player) {
  9086. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9087. return 0;
  9088. }
  9089. if (!player->IsPlayer()) {
  9090. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9091. return 0;
  9092. }
  9093. Client* client = ((Player*)player)->GetClient();
  9094. if (!client) {
  9095. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9096. return 0;
  9097. }
  9098. client->EndAutoMount();
  9099. return 0;
  9100. }
  9101. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9102. if (!lua_interface)
  9103. return 0;
  9104. Spawn* player = lua_interface->GetSpawn(state);
  9105. lua_interface->ResetFunctionStack(state);
  9106. if (!player) {
  9107. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9108. return 0;
  9109. }
  9110. if (!player->IsPlayer()) {
  9111. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9112. return 0;
  9113. }
  9114. Client* client = ((Player*)player)->GetClient();
  9115. if (!client) {
  9116. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9117. return 0;
  9118. }
  9119. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9120. return 1;
  9121. }
  9122. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9123. if (!lua_interface)
  9124. return 0;
  9125. Spawn* player = lua_interface->GetSpawn(state);
  9126. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9127. int32 value = lua_interface->GetInt32Value(state, 3);
  9128. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9129. lua_interface->ResetFunctionStack(state);
  9130. if (!player) {
  9131. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9132. return 0;
  9133. }
  9134. if (!player->IsPlayer()) {
  9135. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9136. return 0;
  9137. }
  9138. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9139. return 0;
  9140. }
  9141. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9142. if (!lua_interface)
  9143. return 0;
  9144. Spawn* player = lua_interface->GetSpawn(state);
  9145. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9146. lua_interface->ResetFunctionStack(state);
  9147. if (!player) {
  9148. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9149. return 0;
  9150. }
  9151. if (!player->IsPlayer()) {
  9152. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9153. return 0;
  9154. }
  9155. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9156. if (!hd)
  9157. return 0;
  9158. lua_interface->SetInt32Value(state, hd->Value);
  9159. lua_interface->SetInt32Value(state, hd->Value2);
  9160. return 2;
  9161. }
  9162. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9163. if (!lua_interface)
  9164. return 0;
  9165. Spawn* spawn = lua_interface->GetSpawn(state);
  9166. int32 grid = lua_interface->GetInt32Value(state, 2);
  9167. lua_interface->ResetFunctionStack(state);
  9168. if (!spawn) {
  9169. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9170. return 0;
  9171. }
  9172. if (grid == 0) {
  9173. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9174. return 0;
  9175. }
  9176. spawn->SetLocation(grid);
  9177. return 0;
  9178. }
  9179. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9180. if (!lua_interface)
  9181. return 0;
  9182. Spawn* spawn = lua_interface->GetSpawn(state);
  9183. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9184. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9185. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9186. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9187. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9188. lua_interface->ResetFunctionStack(state);
  9189. if (!spawn) {
  9190. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9191. return 0;
  9192. }
  9193. //Add this quest to the list of required quests for this spawn
  9194. spawn->SetRequiredHistory(event_id, value1, value2);
  9195. //If private spawn value set
  9196. if (private_spawn) {
  9197. //Set the spawn to be private when not granted access via history
  9198. spawn->AddAllowAccessSpawn(spawn);
  9199. spawn->SetPrivateQuestSpawn(true);
  9200. }
  9201. //This value will override vis_flags in the vis packet
  9202. if (flag_override > 0)
  9203. spawn->SetQuestsRequiredOverride(flag_override);
  9204. return 0;
  9205. }
  9206. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9207. if (!lua_interface)
  9208. return 0;
  9209. Spawn* player = lua_interface->GetSpawn(state);
  9210. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9211. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9212. lua_interface->ResetFunctionStack(state);
  9213. if (!player) {
  9214. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9215. return 0;
  9216. }
  9217. if (!player->IsPlayer()) {
  9218. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9219. return 0;
  9220. }
  9221. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9222. return 1;
  9223. }
  9224. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9225. if (!lua_interface)
  9226. return 0;
  9227. Spawn* player = lua_interface->GetSpawn(state);
  9228. int8 level = lua_interface->GetInt8Value(state, 2);
  9229. lua_interface->ResetFunctionStack(state);
  9230. if (!player) {
  9231. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9232. return 0;
  9233. }
  9234. if (!player->IsPlayer()) {
  9235. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9236. return 0;
  9237. }
  9238. if (level == 0) {
  9239. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9240. return 0;
  9241. }
  9242. Client* client = ((Player*)player)->GetClient();
  9243. if (!client) {
  9244. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9245. return 0;
  9246. }
  9247. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9248. return 0;
  9249. }
  9250. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9251. if (!lua_interface)
  9252. return 0;
  9253. Spawn* player = lua_interface->GetSpawn(state);
  9254. int32 amount = lua_interface->GetInt32Value(state, 2);
  9255. lua_interface->ResetFunctionStack(state);
  9256. if (!player) {
  9257. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9258. return 0;
  9259. }
  9260. if (!player->IsPlayer()) {
  9261. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9262. return 0;
  9263. }
  9264. if (amount == 0) {
  9265. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9266. return 0;
  9267. }
  9268. ((Player*)player)->AddCoins(amount);
  9269. return 0;
  9270. }
  9271. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9272. if (!lua_interface)
  9273. return 0;
  9274. Spawn* player = lua_interface->GetSpawn(state);
  9275. int32 amount = lua_interface->GetInt32Value(state, 2);
  9276. lua_interface->ResetFunctionStack(state);
  9277. if (!player) {
  9278. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9279. return 0;
  9280. }
  9281. if (!player->IsPlayer()) {
  9282. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9283. return 0;
  9284. }
  9285. if (amount == 0) {
  9286. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9287. return 0;
  9288. }
  9289. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9290. return 1;
  9291. }
  9292. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9293. if (!lua_interface)
  9294. return 0;
  9295. ZoneServer* zone = lua_interface->GetZone(state);
  9296. lua_interface->ResetFunctionStack(state);
  9297. if (!zone) {
  9298. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9299. return 0;
  9300. }
  9301. vector<Entity*> players = zone->GetPlayers();
  9302. if (players.size() == 0)
  9303. return 0;
  9304. lua_createtable(state, players.size(), 0);
  9305. int newTable = lua_gettop(state);
  9306. for (int32 i = 0; i < players.size(); i++) {
  9307. lua_interface->SetSpawnValue(state, players.at(i));
  9308. lua_rawseti(state, newTable, i + 1);
  9309. }
  9310. return 1;
  9311. }
  9312. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9313. if (!lua_interface)
  9314. return 0;
  9315. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9316. if (!zone) {
  9317. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9318. return 0;
  9319. }
  9320. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9321. lua_interface->ResetFunctionStack(state);
  9322. //Map of <placement_id, location_id>
  9323. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9324. map<int32, int32>::iterator itr;
  9325. vector<Spawn*> group;
  9326. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9327. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9328. if (!location) {
  9329. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9330. return 0;
  9331. }
  9332. Spawn* spawn = 0;
  9333. if (location->entities[0]) {
  9334. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9335. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9336. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9337. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9338. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9339. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9340. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9341. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9342. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9343. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9344. if(spawn && spawn->IsOmittedByDBFlag())
  9345. {
  9346. 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);
  9347. safe_delete(spawn);
  9348. continue;
  9349. }
  9350. if (spawn) {
  9351. const char* script = 0;
  9352. for (int x = 0; x < 3; x++) {
  9353. switch (x) {
  9354. case 0:
  9355. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9356. break;
  9357. case 1:
  9358. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9359. break;
  9360. case 2:
  9361. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9362. break;
  9363. }
  9364. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9365. spawn->SetSpawnScript(string(script));
  9366. break;
  9367. }
  9368. }
  9369. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9370. lua_interface->SetSpawnValue(state, spawn);
  9371. group.push_back(spawn);
  9372. }
  9373. else {
  9374. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9375. safe_delete(spawn);
  9376. }
  9377. }
  9378. }
  9379. if (!group.empty()) {
  9380. lua_createtable(state, group.size(), 0);
  9381. int newTable = lua_gettop(state);
  9382. for (int32 i = 0; i < group.size(); i++) {
  9383. lua_interface->SetSpawnValue(state, group[i]);
  9384. lua_rawseti(state, newTable, i + 1);
  9385. }
  9386. }
  9387. else
  9388. lua_pushnil(state);
  9389. return 1;
  9390. }
  9391. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9392. if (!lua_interface)
  9393. return 0;
  9394. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9395. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9396. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9397. lua_interface->ResetFunctionStack(state);
  9398. if (!spawn) {
  9399. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9400. return 0;
  9401. }
  9402. if (anim_id == 0) {
  9403. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9404. return 0;
  9405. }
  9406. if (leeway == 0)
  9407. leeway = 5000;
  9408. spawn->SetSpawnAnim(anim_id);
  9409. spawn->SetSpawnAnimLeeway(leeway);
  9410. return 0;
  9411. }
  9412. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9413. if (!lua_interface)
  9414. return 0;
  9415. Spawn* player = lua_interface->GetSpawn(state);
  9416. lua_interface->ResetFunctionStack(state);
  9417. if (!player || !player->IsPlayer()) {
  9418. return 0;
  9419. }
  9420. Client* client = ((Player*)player)->GetClient();
  9421. if (!client) {
  9422. return 0;
  9423. }
  9424. lua_interface->SetInt32Value(state, client->GetVersion());
  9425. return 1;
  9426. }
  9427. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9428. if (!lua_interface)
  9429. return 0;
  9430. Item* item = lua_interface->GetItem(state);
  9431. lua_interface->ResetFunctionStack(state);
  9432. if (!item) {
  9433. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9434. return 0;
  9435. }
  9436. lua_interface->SetInt32Value(state, item->details.item_id);
  9437. return 1;
  9438. }
  9439. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9440. if (!lua_interface)
  9441. return 0;
  9442. Spawn* spawn = lua_interface->GetSpawn(state);
  9443. lua_interface->ResetFunctionStack(state);
  9444. if (!spawn) {
  9445. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9446. return 0;
  9447. }
  9448. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9449. return 1;
  9450. }
  9451. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9452. if (!lua_interface)
  9453. return 0;
  9454. Spawn* spawn = lua_interface->GetSpawn(state);
  9455. lua_interface->ResetFunctionStack(state);
  9456. if (!spawn) {
  9457. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9458. return 0;
  9459. }
  9460. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9461. return 1;
  9462. }
  9463. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9464. if (!lua_interface)
  9465. return 0;
  9466. Spawn* spawn = lua_interface->GetSpawn(state);
  9467. lua_interface->ResetFunctionStack(state);
  9468. if (!spawn) {
  9469. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9470. return 0;
  9471. }
  9472. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9473. return 1;
  9474. }
  9475. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9476. if (!lua_interface)
  9477. return 0;
  9478. Spawn* spawn = lua_interface->GetSpawn(state);
  9479. lua_interface->ResetFunctionStack(state);
  9480. if (!spawn) {
  9481. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9482. return 0;
  9483. }
  9484. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9485. return 1;
  9486. }
  9487. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9488. if (!lua_interface)
  9489. return 0;
  9490. Spawn* spawn = lua_interface->GetSpawn(state);
  9491. float pct = lua_interface->GetFloatValue(state, 2);
  9492. lua_interface->ResetFunctionStack(state);
  9493. if (!spawn) {
  9494. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9495. return 0;
  9496. }
  9497. if (pct == 0) {
  9498. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9499. return 0;
  9500. }
  9501. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9502. lua_interface->SetInt32Value(state, amount);
  9503. return 1;
  9504. }
  9505. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9506. if (!lua_interface)
  9507. return 0;
  9508. Spawn* spawn = lua_interface->GetSpawn(state);
  9509. float pct = lua_interface->GetFloatValue(state, 2);
  9510. lua_interface->ResetFunctionStack(state);
  9511. if (!spawn) {
  9512. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9513. return 0;
  9514. }
  9515. if (pct == 0) {
  9516. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9517. return 0;
  9518. }
  9519. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9520. lua_interface->SetInt32Value(state, amount);
  9521. return 1;
  9522. }
  9523. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9524. if (!lua_interface)
  9525. return 0;
  9526. Spawn* spawn = lua_interface->GetSpawn(state);
  9527. lua_interface->ResetFunctionStack(state);
  9528. if (!spawn) {
  9529. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9530. return 0;
  9531. }
  9532. if (!spawn->IsPlayer()) {
  9533. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9534. return 0;
  9535. }
  9536. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9537. return 1;
  9538. }
  9539. int EQ2Emu_lua_Evac(lua_State* state) {
  9540. if (!lua_interface)
  9541. return 0;
  9542. Spawn* target = lua_interface->GetSpawn(state);
  9543. if (target) {
  9544. float x = target->GetZone()->GetSafeX();
  9545. float y = target->GetZone()->GetSafeY();
  9546. float z = target->GetZone()->GetSafeZ();
  9547. float h = target->GetZone()->GetSafeHeading();
  9548. target->SetX(x);
  9549. target->SetY(y);
  9550. target->SetZ(z);
  9551. target->SetHeading(h);
  9552. target->SetSpawnOrigX(x);
  9553. target->SetSpawnOrigY(y);
  9554. target->SetSpawnOrigZ(z);
  9555. target->SetSpawnOrigHeading(h);
  9556. if (target->IsPlayer()) {
  9557. Client* client = ((Player*)target)->GetClient();
  9558. if (client) {
  9559. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9560. int numargs = lua_interface->GetNumberOfArgs(state);
  9561. if(numargs == 4) {
  9562. x = lua_interface->GetFloatValue(state,1);
  9563. y = lua_interface->GetFloatValue(state,2);
  9564. z = lua_interface->GetFloatValue(state,3);
  9565. h = lua_interface->GetFloatValue(state,4);
  9566. }
  9567. client->SetReloadingZone(true);
  9568. target->SetX(x);
  9569. target->SetY(y);
  9570. target->SetZ(z);
  9571. target->SetHeading(h);
  9572. target->SetSpawnOrigX(x);
  9573. target->SetSpawnOrigY(y);
  9574. target->SetSpawnOrigZ(z);
  9575. target->SetSpawnOrigHeading(h);
  9576. target->SetAppearancePosition(x,y,z);
  9577. client->SetZoningCoords(x,y,z,h);
  9578. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9579. if (packet)
  9580. {
  9581. packet->setDataByName("x", x);
  9582. packet->setDataByName("y", y);
  9583. packet->setDataByName("z", z);
  9584. client->QueuePacket(packet->serialize());
  9585. safe_delete(packet);
  9586. }
  9587. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9588. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9589. }
  9590. }
  9591. lua_interface->ResetFunctionStack(state);
  9592. }
  9593. else {
  9594. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9595. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9596. lua_interface->ResetFunctionStack(state);
  9597. return 0;
  9598. }
  9599. ZoneServer* zone = spell->caster->GetZone();
  9600. float x = spell->caster->GetZone()->GetSafeX();
  9601. float y = spell->caster->GetZone()->GetSafeY();
  9602. float z = spell->caster->GetZone()->GetSafeZ();
  9603. float h = spell->caster->GetZone()->GetSafeHeading();
  9604. int numargs = lua_interface->GetNumberOfArgs(state);
  9605. if(numargs == 4) {
  9606. x = lua_interface->GetFloatValue(state,1);
  9607. y = lua_interface->GetFloatValue(state,2);
  9608. z = lua_interface->GetFloatValue(state,3);
  9609. h = lua_interface->GetFloatValue(state,4);
  9610. }
  9611. lua_interface->ResetFunctionStack(state);
  9612. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9613. for (int32 i = 0; i < spell->targets.size(); i++) {
  9614. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9615. if (!target2)
  9616. continue;
  9617. if (target2->IsPlayer()) {
  9618. Client* client = ((Player*)target2)->GetClient();
  9619. if (client) {
  9620. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9621. client->SetReloadingZone(true);
  9622. target2->SetX(x);
  9623. target2->SetY(y);
  9624. target2->SetZ(z);
  9625. target2->SetHeading(h);
  9626. target2->SetSpawnOrigX(x);
  9627. target2->SetSpawnOrigY(y);
  9628. target2->SetSpawnOrigZ(z);
  9629. target2->SetSpawnOrigHeading(h);
  9630. target2->SetAppearancePosition(x,y,z);
  9631. client->SetZoningCoords(x,y,z,h);
  9632. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9633. if (packet)
  9634. {
  9635. packet->setDataByName("x", x);
  9636. packet->setDataByName("y", y);
  9637. packet->setDataByName("z", z);
  9638. client->QueuePacket(packet->serialize());
  9639. safe_delete(packet);
  9640. }
  9641. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9642. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9643. }
  9644. }
  9645. }
  9646. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9647. }
  9648. return 0;
  9649. }
  9650. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9651. if (!lua_interface)
  9652. return 0;
  9653. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9654. lua_interface->ResetFunctionStack(state);
  9655. if (!luaspell) {
  9656. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9657. return 0;
  9658. }
  9659. int8 tier = luaspell->spell->GetSpellTier();
  9660. lua_interface->SetInt32Value(state, tier);
  9661. return 1;
  9662. }
  9663. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9664. if (!lua_interface)
  9665. return 0;
  9666. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9667. lua_interface->ResetFunctionStack(state);
  9668. if (!luaspell) {
  9669. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9670. return 0;
  9671. }
  9672. int32 spell_id = luaspell->spell->GetSpellID();
  9673. lua_interface->SetInt32Value(state, spell_id);
  9674. return 1;
  9675. }
  9676. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9677. if (!lua_interface)
  9678. return 0;
  9679. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9680. lua_interface->ResetFunctionStack(state);
  9681. if (!spawn) {
  9682. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9683. return 0;
  9684. }
  9685. if (!spawn->IsPlayer()) {
  9686. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9687. return 0;
  9688. }
  9689. ZoneServer* zone = spawn->GetZone();
  9690. if (!zone) {
  9691. return 0;
  9692. }
  9693. Client* client = ((Player*)spawn)->GetClient();
  9694. if (!client) {
  9695. return 0;
  9696. }
  9697. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9698. return 0;
  9699. }
  9700. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9701. if (!lua_interface)
  9702. return 0;
  9703. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9704. lua_interface->ResetFunctionStack(state);
  9705. if (!spawn) {
  9706. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9707. return 0;
  9708. }
  9709. if (!spawn->IsPlayer()) {
  9710. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9711. return 0;
  9712. }
  9713. ZoneServer* zone = spawn->GetZone();
  9714. if (!zone) {
  9715. return 0;
  9716. }
  9717. Client* client = ((Player*)spawn)->GetClient();
  9718. if (!client) {
  9719. return 0;
  9720. }
  9721. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9722. return 0;
  9723. }
  9724. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9725. if (!lua_interface)
  9726. return 0;
  9727. Spawn* caster = lua_interface->GetSpawn(state);
  9728. Spawn* target = lua_interface->GetSpawn(state, 2);
  9729. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9730. string spell_name = lua_interface->GetStringValue(state, 4);
  9731. lua_interface->ResetFunctionStack(state);
  9732. if (!caster) {
  9733. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9734. return 0;
  9735. }
  9736. if (!caster->IsEntity()) {
  9737. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9738. return 0;
  9739. }
  9740. if (!target) {
  9741. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9742. return 0;
  9743. }
  9744. if (!target->IsEntity()) {
  9745. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9746. return 0;
  9747. }
  9748. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9749. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9750. return 0;
  9751. }
  9752. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9753. if (!lua_interface)
  9754. return 0;
  9755. Spawn* player = lua_interface->GetSpawn(state);
  9756. int32 amount = lua_interface->GetInt32Value(state, 2);
  9757. lua_interface->ResetFunctionStack(state);
  9758. if (player && player->IsPlayer() && amount > 0) {
  9759. ((Player*)player)->AddXP(amount);
  9760. }
  9761. return 0;
  9762. }
  9763. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9764. if (!lua_interface)
  9765. return 0;
  9766. Spawn* player = lua_interface->GetSpawn(state);
  9767. int8 type = lua_interface->GetInt8Value(state, 2);
  9768. string text = lua_interface->GetStringValue(state, 3);
  9769. lua_interface->ResetFunctionStack(state);
  9770. Client* client = 0;
  9771. if (player && player->IsPlayer())
  9772. client = ((Player*)player)->GetClient();
  9773. if (!client || text.length() == 0) {
  9774. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9775. return 0;
  9776. }
  9777. client->SimpleMessage(type, text.c_str());
  9778. return 0;
  9779. }
  9780. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9781. if (!lua_interface)
  9782. return 0;
  9783. Spawn* player = lua_interface->GetSpawn(state);
  9784. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9785. lua_interface->ResetFunctionStack(state);
  9786. Client* client = 0;
  9787. if (player && player->IsPlayer())
  9788. client = ((Player*)player)->GetClient();
  9789. if (!client || !spawn) {
  9790. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9791. return 0;
  9792. }
  9793. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9794. if (!items) {
  9795. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9796. return 0;
  9797. }
  9798. client->Loot(spawn->GetLootCoins(), items, spawn);
  9799. return 0;
  9800. }
  9801. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9802. if (!lua_interface)
  9803. return 0;
  9804. Spawn* spawnref = lua_interface->GetSpawn(state);
  9805. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9806. lua_interface->ResetFunctionStack(state);
  9807. if (spawn_id > 0 && spawnref) {
  9808. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9809. if (spawns.size() == 0) {
  9810. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9811. return 0;
  9812. }
  9813. Spawn* spawn = 0;
  9814. int16 index = MakeRandomInt(0, spawns.size());
  9815. if (index >= spawns.size() || index < 0)
  9816. index = 0;
  9817. spawn = spawns[index];
  9818. lua_interface->SetSpawnValue(state, spawn);
  9819. return 1;
  9820. }
  9821. else {
  9822. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9823. }
  9824. return 0;
  9825. }
  9826. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9827. Spawn* player = lua_interface->GetSpawn(state);
  9828. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9829. string name = lua_interface->GetStringValue(state, 3);
  9830. float distance = lua_interface->GetFloatValue(state, 4);
  9831. string command = lua_interface->GetStringValue(state, 5);
  9832. string error_text = lua_interface->GetStringValue(state, 6);
  9833. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9834. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9835. lua_interface->ResetFunctionStack(state);
  9836. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9837. if (distance == 0)
  9838. distance = 10.0f;
  9839. if (command.length() == 0)
  9840. command = name;
  9841. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9842. if (spawns.size() == 0) {
  9843. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9844. return 0;
  9845. }
  9846. Spawn* spawn = 0;
  9847. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9848. spawn = *itr;
  9849. if (spawn) {
  9850. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9851. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9852. }
  9853. }
  9854. }
  9855. return 0;
  9856. }
  9857. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9858. if (!lua_interface)
  9859. return 0;
  9860. Client* client = 0;
  9861. Spawn* player = lua_interface->GetSpawn(state);
  9862. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9863. lua_interface->ResetFunctionStack(state);
  9864. if (player && player->IsPlayer() && player->GetZone())
  9865. client = ((Player*)player)->GetClient();
  9866. else{
  9867. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9868. return 0;
  9869. }
  9870. if (client) {
  9871. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9872. if (packet) {
  9873. packet->setDataByName("goal_num", goal_num);
  9874. client->QueuePacket(packet->serialize());
  9875. safe_delete(packet);
  9876. }
  9877. }
  9878. return 0;
  9879. }
  9880. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9881. if (!lua_interface)
  9882. return 0;
  9883. Client* client = 0;
  9884. Spawn* player = lua_interface->GetSpawn(state);
  9885. lua_interface->ResetFunctionStack(state);
  9886. if (player && player->IsPlayer() && player->GetZone())
  9887. client = ((Player*)player)->GetClient();
  9888. else {
  9889. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9890. return 0;
  9891. }
  9892. if (client) {
  9893. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9894. }
  9895. return 0;
  9896. }
  9897. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9898. if (!lua_interface)
  9899. return 0;
  9900. Client* client = 0;
  9901. Spawn* player = lua_interface->GetSpawn(state);
  9902. float duration = lua_interface->GetFloatValue(state, 2);
  9903. string text = lua_interface->GetStringValue(state, 3);
  9904. string voice = lua_interface->GetStringValue(state, 4);
  9905. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9906. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9907. string signal = lua_interface->GetStringValue(state, 7);
  9908. string goal1 = lua_interface->GetStringValue(state, 8);
  9909. string task1 = lua_interface->GetStringValue(state, 9);
  9910. string goal2 = lua_interface->GetStringValue(state, 10);
  9911. string task2 = lua_interface->GetStringValue(state, 11);
  9912. string goal3 = lua_interface->GetStringValue(state, 12);
  9913. string task3 = lua_interface->GetStringValue(state, 13);
  9914. string goal4 = lua_interface->GetStringValue(state, 14);
  9915. string task4 = lua_interface->GetStringValue(state, 15);
  9916. lua_interface->ResetFunctionStack(state);
  9917. if (!player) {
  9918. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9919. return 0;
  9920. }
  9921. if (!player->IsPlayer()) {
  9922. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9923. return 0;
  9924. }
  9925. else
  9926. client = ((Player*)player)->GetClient();
  9927. if (!client) {
  9928. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9929. return 0;
  9930. }
  9931. if (text.length() == 0) {
  9932. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9933. return 0;
  9934. }
  9935. if (duration >= 0 && duration < 2)
  9936. duration = 2;
  9937. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9938. if (packet) {
  9939. packet->setDataByName("open_seconds_max", duration);
  9940. packet->setDataByName("text", text.c_str());
  9941. packet->setDataByName("voice", voice.c_str());
  9942. int8 num_goals = 1;
  9943. if (task2.length() > 0)
  9944. num_goals++;
  9945. if (task3.length() > 0)
  9946. num_goals++;
  9947. if (task4.length() > 0)
  9948. num_goals++;
  9949. packet->setArrayLengthByName("num_goals", num_goals);
  9950. for (int8 i = 0; i < num_goals; i++) {
  9951. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9952. }
  9953. if (goal1.length() > 0)
  9954. packet->setArrayDataByName("goal_text", goal1.c_str());
  9955. if (goal2.length() > 0)
  9956. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9957. if (goal3.length() > 0)
  9958. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9959. if (goal4.length() > 0)
  9960. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9961. packet->setSubArrayDataByName("task_text", task1.c_str());
  9962. if (task2.length() > 0)
  9963. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9964. if (task3.length() > 0)
  9965. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9966. if (task4.length() > 0)
  9967. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9968. packet->setDataByName("complete_sound", "click");
  9969. packet->setDataByName("signal", signal.c_str());
  9970. packet->setDataByName("voice_key1", voice_key1);
  9971. packet->setDataByName("voice_key2", voice_key2);
  9972. client->QueuePacket(packet->serialize());
  9973. safe_delete(packet);
  9974. }
  9975. return 0;
  9976. }
  9977. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9978. if (!lua_interface)
  9979. return 0;
  9980. Client* client = 0;
  9981. Spawn* player = lua_interface->GetSpawn(state);
  9982. string window = lua_interface->GetStringValue(state, 2);
  9983. int8 show = lua_interface->GetInt8Value(state, 3);
  9984. lua_interface->ResetFunctionStack(state);
  9985. if (!player) {
  9986. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9987. return 0;
  9988. }
  9989. if (!player->IsPlayer()) {
  9990. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9991. return 0;
  9992. }
  9993. else
  9994. client = ((Player*)player)->GetClient();
  9995. if (!client) {
  9996. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9997. return 0;
  9998. }
  9999. if (window.length() == 0) {
  10000. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10001. return 0;
  10002. }
  10003. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10004. if (packet) {
  10005. packet->setDataByName("window", window.c_str());
  10006. packet->setDataByName("show", show);
  10007. client->QueuePacket(packet->serialize());
  10008. safe_delete(packet);
  10009. }
  10010. return 0;
  10011. }
  10012. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10013. //See GameEvents.txt for options that can be used for this function
  10014. if (!lua_interface)
  10015. return 0;
  10016. Client* client = 0;
  10017. Spawn* player = lua_interface->GetSpawn(state);
  10018. string event_name = lua_interface->GetStringValue(state, 2);
  10019. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10020. lua_interface->ResetFunctionStack(state);
  10021. if (!player || !player->IsPlayer()) {
  10022. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10023. return 0;
  10024. }
  10025. client = ((Player*)player)->GetClient();
  10026. if (!client) {
  10027. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10028. return 0;
  10029. }
  10030. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10031. if (packet) {
  10032. packet->setDataByName("event_name", event_name.c_str());
  10033. packet->setDataByName("enabled", enabled);
  10034. client->QueuePacket(packet->serialize());
  10035. safe_delete(packet);
  10036. }
  10037. return 0;
  10038. }
  10039. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10040. if (!lua_interface)
  10041. return 0;
  10042. Spawn* player = lua_interface->GetSpawn(state);
  10043. lua_interface->ResetFunctionStack(state);
  10044. if (player && player->IsPlayer()) {
  10045. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10046. return 1;
  10047. }
  10048. return 0;
  10049. }
  10050. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10051. if (!lua_interface)
  10052. return 0;
  10053. Spawn* player = lua_interface->GetSpawn(state);
  10054. int8 step = lua_interface->GetInt8Value(state, 2);
  10055. lua_interface->ResetFunctionStack(state);
  10056. if (player && player->IsPlayer() && step > 0) {
  10057. ((Player*)player)->SetTutorialStep(step);
  10058. }
  10059. return 0;
  10060. }
  10061. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10062. if (!lua_interface)
  10063. return 0;
  10064. Client* client = 0;
  10065. Spawn* player = lua_interface->GetSpawn(state);
  10066. string window = lua_interface->GetStringValue(state, 2);
  10067. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10068. lua_interface->ResetFunctionStack(state);
  10069. if (!player) {
  10070. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10071. return 0;
  10072. }
  10073. if (!player->IsPlayer()) {
  10074. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10075. return 0;
  10076. }
  10077. else
  10078. client = ((Player*)player)->GetClient();
  10079. if (!client) {
  10080. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10081. return 0;
  10082. }
  10083. if (window.length() == 0) {
  10084. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10085. return 0;
  10086. }
  10087. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10088. if (packet) {
  10089. packet->setDataByName("window", window.c_str());
  10090. packet->setDataByName("flash_seconds", flash_seconds);
  10091. client->QueuePacket(packet->serialize());
  10092. safe_delete(packet);
  10093. }
  10094. return 0;
  10095. }
  10096. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10097. if (!lua_interface)
  10098. return 0;
  10099. Spawn* spawn = lua_interface->GetSpawn(state);
  10100. Spawn* target = lua_interface->GetSpawn(state, 2);
  10101. lua_interface->ResetFunctionStack(state);
  10102. if (spawn && target)
  10103. return spawn->CheckLoS(target);
  10104. return 0;
  10105. }
  10106. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10107. if (!lua_interface)
  10108. return 0;
  10109. Spawn* spawn = lua_interface->GetSpawn(state);
  10110. float x = lua_interface->GetFloatValue(state, 2);
  10111. float y = lua_interface->GetFloatValue(state, 3);
  10112. float z = lua_interface->GetFloatValue(state, 4);
  10113. lua_interface->ResetFunctionStack(state);
  10114. if (spawn)
  10115. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10116. return 0;
  10117. }
  10118. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10119. if (!lua_interface)
  10120. return 0;
  10121. ZoneServer* zone = lua_interface->GetZone(state);
  10122. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10123. lua_interface->ResetFunctionStack(state);
  10124. if (zone)
  10125. zone->SetExpansionFlag(xpackFlag);
  10126. return 0;
  10127. }
  10128. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10129. if (!lua_interface)
  10130. return 0;
  10131. ZoneServer* zone = lua_interface->GetZone(state);
  10132. lua_interface->ResetFunctionStack(state);
  10133. if (zone) {
  10134. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10135. return 1;
  10136. }
  10137. return 0;
  10138. }
  10139. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10140. if (!lua_interface)
  10141. return 0;
  10142. ZoneServer* zone = lua_interface->GetZone(state);
  10143. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10144. lua_interface->ResetFunctionStack(state);
  10145. if (zone)
  10146. zone->SetHolidayFlag(holidayFlag);
  10147. return 0;
  10148. }
  10149. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10150. if (!lua_interface)
  10151. return 0;
  10152. ZoneServer* zone = lua_interface->GetZone(state);
  10153. lua_interface->ResetFunctionStack(state);
  10154. if (zone) {
  10155. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10156. return 1;
  10157. }
  10158. return 0;
  10159. }
  10160. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10161. if (!lua_interface)
  10162. return 0;
  10163. Spawn* player = lua_interface->GetSpawn(state);
  10164. ZoneServer* zone = player->GetZone();
  10165. bool canbind = lua_interface->GetInt32Value(state, 2);
  10166. lua_interface->ResetFunctionStack(state);
  10167. if (zone)
  10168. zone->SetCanBind(canbind);
  10169. return 0;
  10170. }
  10171. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10172. if (!lua_interface)
  10173. return 0;
  10174. Spawn* player = lua_interface->GetSpawn(state);
  10175. ZoneServer* zone = player->GetZone();
  10176. lua_interface->ResetFunctionStack(state);
  10177. if (zone) {
  10178. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10179. return 1;
  10180. }
  10181. return 0;
  10182. }
  10183. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10184. if (!lua_interface)
  10185. return 0;
  10186. Spawn* player = lua_interface->GetSpawn(state);
  10187. ZoneServer* zone = player->GetZone();
  10188. bool cangate = lua_interface->GetInt32Value(state, 2);
  10189. lua_interface->ResetFunctionStack(state);
  10190. if (zone)
  10191. zone->SetCanGate(cangate);
  10192. return 0;
  10193. }
  10194. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10195. if (!lua_interface)
  10196. return 0;
  10197. Spawn* player = lua_interface->GetSpawn(state);
  10198. ZoneServer* zone = player->GetZone();
  10199. lua_interface->ResetFunctionStack(state);
  10200. if (zone) {
  10201. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10202. return 1;
  10203. }
  10204. return 0;
  10205. }
  10206. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10207. if (!lua_interface)
  10208. return 0;
  10209. Spawn* spawn = lua_interface->GetSpawn(state);
  10210. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10211. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10212. float distance = lua_interface->GetFloatValue(state, 4);
  10213. string in_range_function = lua_interface->GetStringValue(state, 5);
  10214. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10215. lua_interface->ResetFunctionStack(state);
  10216. if (spawn && distance > 0 && in_range_function.length() > 0)
  10217. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10218. return 0;
  10219. }
  10220. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10221. if (!lua_interface)
  10222. return 0;
  10223. Spawn* spawn = lua_interface->GetSpawn(state);
  10224. Spawn* target = lua_interface->GetSpawn(state, 2);
  10225. lua_interface->ResetFunctionStack(state);
  10226. if (spawn && target)
  10227. {
  10228. if (spawn->IsPlayer() && target->IsEntity())
  10229. {
  10230. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10231. return 1;
  10232. }
  10233. else if (spawn->IsEntity() && target->IsEntity())
  10234. {
  10235. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10236. return 1;
  10237. }
  10238. }
  10239. return 0;
  10240. }
  10241. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10242. if (!lua_interface)
  10243. return 0;
  10244. Spawn* spawn = lua_interface->GetSpawn(state);
  10245. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10246. lua_interface->ResetFunctionStack(state);
  10247. if (spawn && spawn->IsEntity())
  10248. {
  10249. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10250. if (spawn->IsPlayer())
  10251. {
  10252. Client* client = ((Player*)spawn)->GetClient();
  10253. if (client)
  10254. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10255. }
  10256. }
  10257. return 0;
  10258. }
  10259. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10260. if (!lua_interface)
  10261. return 0;
  10262. Spawn* spawn = lua_interface->GetSpawn(state);
  10263. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10264. lua_interface->ResetFunctionStack(state);
  10265. if (spawn && spawn->IsEntity())
  10266. {
  10267. ((Entity*)spawn)->SetSeeHideSpell(val);
  10268. if (spawn->IsPlayer())
  10269. {
  10270. Client* client = ((Player*)spawn)->GetClient();
  10271. if (client)
  10272. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10273. }
  10274. }
  10275. return 0;
  10276. }
  10277. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10278. {
  10279. if (!lua_interface)
  10280. return 0;
  10281. Spawn* player = lua_interface->GetSpawn(state);
  10282. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10283. string command = lua_interface->GetStringValue(state, 3);
  10284. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10285. lua_interface->ResetFunctionStack(state);
  10286. if (spawn && player && player->IsPlayer())
  10287. {
  10288. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10289. bool res = false;
  10290. if (cmd)
  10291. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10292. lua_interface->SetBooleanValue(state, res);
  10293. return 1;
  10294. }
  10295. return 0;
  10296. }
  10297. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10298. {
  10299. if (!lua_interface)
  10300. return 0;
  10301. Spawn* spawn = lua_interface->GetSpawn(state);
  10302. int32 charID = lua_interface->GetInt32Value(state, 2);
  10303. string command = lua_interface->GetStringValue(state, 3);
  10304. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10305. lua_interface->ResetFunctionStack(state);
  10306. if (spawn && charID)
  10307. {
  10308. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10309. bool res = false;
  10310. if (cmd)
  10311. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10312. lua_interface->SetBooleanValue(state, res);
  10313. return 1;
  10314. }
  10315. return 0;
  10316. }
  10317. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10318. {
  10319. if (!lua_interface)
  10320. return 0;
  10321. Spawn* spawn = lua_interface->GetSpawn(state);
  10322. string command = lua_interface->GetStringValue(state, 2);
  10323. lua_interface->ResetFunctionStack(state);
  10324. if (spawn && command.length() > 0)
  10325. spawn->RemovePrimaryEntityCommand(command.c_str());
  10326. return 0;
  10327. }
  10328. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10329. if (!lua_interface)
  10330. return 0;
  10331. Spawn* spawn = lua_interface->GetSpawn(state);
  10332. float distance = lua_interface->GetFloatValue(state, 2);
  10333. string command = lua_interface->GetStringValue(state, 3);
  10334. Spawn* player = lua_interface->GetSpawn(state, 4);
  10335. lua_interface->ResetFunctionStack(state);
  10336. if (spawn) {
  10337. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10338. }
  10339. return 0;
  10340. }
  10341. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10342. if (!lua_interface)
  10343. return 0;
  10344. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10345. Spawn* spawn = lua_interface->GetSpawn(state);
  10346. Spawn* player = lua_interface->GetSpawn(state, 2);
  10347. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10348. lua_interface->ResetFunctionStack(state);
  10349. if (spawn && player && transport_id && player->IsPlayer()) {
  10350. Client* client = 0;
  10351. if (player && player->IsPlayer())
  10352. client = ((Player*)player)->GetClient();
  10353. if (!client)
  10354. return 0;
  10355. vector<TransportDestination*> destinations;
  10356. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10357. if (destinations.size())
  10358. {
  10359. client->SetTemporaryTransportID(transport_id);
  10360. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10361. }
  10362. else
  10363. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10364. }
  10365. return 0;
  10366. }
  10367. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10368. if (!lua_interface)
  10369. return 0;
  10370. Spawn* player = lua_interface->GetSpawn(state);
  10371. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10372. lua_interface->ResetFunctionStack(state);
  10373. if (player && player->IsPlayer()) {
  10374. Client* client = 0;
  10375. if (player && player->IsPlayer())
  10376. client = ((Player*)player)->GetClient();
  10377. if (!client)
  10378. return 0;
  10379. client->SetTemporaryTransportID(transport_id);
  10380. }
  10381. return 0;
  10382. }
  10383. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10384. if (!lua_interface)
  10385. return 0;
  10386. Spawn* player = lua_interface->GetSpawn(state);
  10387. lua_interface->ResetFunctionStack(state);
  10388. if (player && player->IsPlayer()) {
  10389. Client* client = 0;
  10390. if (player && player->IsPlayer())
  10391. client = ((Player*)player)->GetClient();
  10392. if (!client)
  10393. return 0;
  10394. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10395. return 1;
  10396. }
  10397. return 0;
  10398. }
  10399. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10400. if (!lua_interface)
  10401. return 0;
  10402. Spawn* spawn = lua_interface->GetSpawn(state);
  10403. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10404. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10405. if (!spawn) {
  10406. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10407. return 0;
  10408. }
  10409. if (!spawn->IsEntity()) {
  10410. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10411. return 0;
  10412. }
  10413. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10414. {
  10415. 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);
  10416. return 0;
  10417. }
  10418. lua_interface->ResetFunctionStack(state);
  10419. if (spell && spell->targets.size() > 0) {
  10420. ZoneServer* zone = spell->caster->GetZone();
  10421. for (int8 i = 0; i < spell->targets.size(); i++) {
  10422. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10423. if (target && target->IsEntity()) {
  10424. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10425. if (target->IsPlayer())
  10426. ((Player*)target)->SetCharSheetChanged(true);
  10427. }
  10428. }
  10429. }
  10430. else {
  10431. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10432. if (spawn->IsPlayer())
  10433. ((Player*)spawn)->SetCharSheetChanged(true);
  10434. }
  10435. return 0;
  10436. }
  10437. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10438. if (!lua_interface)
  10439. return 0;
  10440. Spawn* spawn = lua_interface->GetSpawn(state);
  10441. lua_interface->ResetFunctionStack(state);
  10442. if (!spawn) {
  10443. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10444. return 0;
  10445. }
  10446. if (!spawn->IsEntity()) {
  10447. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10448. return 0;
  10449. }
  10450. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10451. return 1;
  10452. }
  10453. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10454. if (!lua_interface)
  10455. return 0;
  10456. int32 spell_id = lua_interface->GetInt32Value(state);
  10457. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10458. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10459. if (spell_id > 0) {
  10460. if (spell_tier == 0)
  10461. spell_tier = 1;
  10462. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10463. if(!spell) {
  10464. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10465. lua_interface->ResetFunctionStack(state);
  10466. return 0;
  10467. }
  10468. LuaSpell* lua_spell = 0;
  10469. if(custom_lua_script.size() > 0)
  10470. {
  10471. // attempt to load the custom script since it isn't already loaded
  10472. // we will re-obtain the lua_spell further below
  10473. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10474. {
  10475. 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());
  10476. lua_interface->LoadLuaSpell(custom_lua_script);
  10477. }
  10478. }
  10479. else
  10480. custom_lua_script = spell->GetSpellData()->lua_script;
  10481. if (!lua_spell && lua_interface)
  10482. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10483. lua_interface->ResetFunctionStack(state);
  10484. if (!lua_spell)
  10485. {
  10486. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10487. return 0;
  10488. }
  10489. lua_spell->spell = new Spell(spell);
  10490. lua_interface->AddCustomSpell(lua_spell);
  10491. lua_interface->SetSpellValue(state, lua_spell);
  10492. return 1;
  10493. }
  10494. return 0;
  10495. }
  10496. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10497. if (!lua_interface)
  10498. return 0;
  10499. LuaSpell* spell = lua_interface->GetSpell(state);
  10500. string field = lua_interface->GetStringValue(state, 2);
  10501. lua_interface->ResetFunctionStack(state);
  10502. if (!spell) {
  10503. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10504. return 0;
  10505. }
  10506. if (!spell->spell || !spell->spell->GetSpellData()) {
  10507. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10508. return 0;
  10509. }
  10510. boost::to_lower(field);
  10511. return spell->spell->GetSpellData(state, field);
  10512. }
  10513. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10514. if (!lua_interface)
  10515. return 0;
  10516. LuaSpell* spell = lua_interface->GetSpell(state);
  10517. string field = lua_interface->GetStringValue(state, 2);
  10518. lua_interface->ResetFunctionStack(state);
  10519. int8 fieldArg = 3; // field value after the initial set
  10520. if (!spell) {
  10521. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10522. return 0;
  10523. }
  10524. if (!spell->spell || !spell->spell->GetSpellData()) {
  10525. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10526. return 0;
  10527. }
  10528. boost::to_lower(field);
  10529. bool valSet = false;
  10530. spell->spell->SetSpellData(state, field, fieldArg);
  10531. return valSet;
  10532. }
  10533. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10534. if (!lua_interface)
  10535. return 0;
  10536. LuaSpell* spell = lua_interface->GetSpell(state);
  10537. int8 idx = lua_interface->GetInt32Value(state, 2);
  10538. if (!spell) {
  10539. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10540. return 0;
  10541. }
  10542. if (!spell->spell || !spell->spell->GetSpellData()) {
  10543. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10544. return 0;
  10545. }
  10546. if (spell->spell->lua_data.size() <= idx)
  10547. {
  10548. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10549. return 0;
  10550. }
  10551. bool setVal = true;
  10552. LUAData* data = spell->spell->lua_data[idx];
  10553. switch (data->type)
  10554. {
  10555. case 0:
  10556. {
  10557. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10558. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10559. data->int_value = value;
  10560. data->int_value2 = value2;
  10561. break;
  10562. }
  10563. case 1:
  10564. {
  10565. float value = lua_interface->GetFloatValue(state, 3);
  10566. float value2 = lua_interface->GetFloatValue(state, 4);
  10567. data->float_value = value;
  10568. data->float_value2 = value2;
  10569. break;
  10570. }
  10571. case 2:
  10572. {
  10573. bool value = lua_interface->GetBooleanValue(state, 3);
  10574. data->bool_value = value;
  10575. break;
  10576. }
  10577. case 3:
  10578. {
  10579. string value = lua_interface->GetStringValue(state, 3);
  10580. string value2 = lua_interface->GetStringValue(state, 4);
  10581. data->string_value = value;
  10582. data->string_value2 = value2;
  10583. break;
  10584. }
  10585. default:
  10586. setVal = false;
  10587. }
  10588. lua_interface->ResetFunctionStack(state);
  10589. return setVal;
  10590. }
  10591. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10592. if (!lua_interface)
  10593. return 0;
  10594. LuaSpell* spell = lua_interface->GetSpell(state);
  10595. int8 idx = lua_interface->GetInt32Value(state, 2);
  10596. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10597. lua_interface->ResetFunctionStack(state);
  10598. if (!spell) {
  10599. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10600. return 0;
  10601. }
  10602. if (!spell->spell || !spell->spell->GetSpellData()) {
  10603. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10604. return 0;
  10605. }
  10606. if (spell->spell->lua_data.size() <= idx)
  10607. {
  10608. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10609. return 0;
  10610. }
  10611. bool setVal = true;
  10612. LUAData* data = spell->spell->lua_data[idx];
  10613. switch (data->type)
  10614. {
  10615. case 0:
  10616. {
  10617. if(!secondfield)
  10618. lua_interface->SetSInt32Value(state, data->int_value);
  10619. else
  10620. lua_interface->SetSInt32Value(state, data->int_value2);
  10621. break;
  10622. }
  10623. case 1:
  10624. {
  10625. if (!secondfield)
  10626. lua_interface->SetFloatValue(state, data->float_value);
  10627. else
  10628. lua_interface->SetFloatValue(state, data->float_value2);
  10629. break;
  10630. }
  10631. case 2:
  10632. {
  10633. lua_interface->SetBooleanValue(state, data->bool_value);
  10634. break;
  10635. }
  10636. case 3:
  10637. {
  10638. if (!secondfield)
  10639. lua_interface->SetStringValue(state, data->string_value.c_str());
  10640. else
  10641. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10642. break;
  10643. }
  10644. default:
  10645. setVal = false;
  10646. }
  10647. return setVal;
  10648. }
  10649. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10650. if (!lua_interface)
  10651. return 0;
  10652. LuaSpell* spell = lua_interface->GetSpell(state);
  10653. int8 idx = lua_interface->GetInt32Value(state, 2);
  10654. string field = lua_interface->GetStringValue(state, 3);
  10655. boost::to_lower(field);
  10656. if (!spell) {
  10657. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10658. lua_interface->ResetFunctionStack(state);
  10659. return 0;
  10660. }
  10661. if (!spell->spell || !spell->spell->GetSpellData()) {
  10662. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10663. lua_interface->ResetFunctionStack(state);
  10664. return 0;
  10665. }
  10666. if (spell->spell->effects.size() <= idx)
  10667. {
  10668. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10669. lua_interface->ResetFunctionStack(state);
  10670. return 0;
  10671. }
  10672. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10673. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10674. if (field == "description")
  10675. effect->description = string(lua_interface->GetStringValue(state, 4));
  10676. else if (field == "bullet")
  10677. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10678. else if (field == "percentage")
  10679. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10680. else { // no match
  10681. lua_interface->ResetFunctionStack(state);
  10682. return 0;
  10683. }
  10684. lua_interface->ResetFunctionStack(state);
  10685. return 1;
  10686. }
  10687. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10688. if (!lua_interface)
  10689. return 0;
  10690. LuaSpell* spell = lua_interface->GetSpell(state);
  10691. int8 idx = lua_interface->GetInt32Value(state, 2);
  10692. string field = lua_interface->GetStringValue(state, 3);
  10693. lua_interface->ResetFunctionStack(state);
  10694. boost::to_lower(field);
  10695. if (!spell) {
  10696. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10697. return 0;
  10698. }
  10699. if (!spell->spell || !spell->spell->GetSpellData()) {
  10700. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10701. return 0;
  10702. }
  10703. if (spell->spell->effects.size() <= idx)
  10704. {
  10705. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10706. return 0;
  10707. }
  10708. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10709. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10710. if (field == "description")
  10711. lua_interface->SetStringValue(state, effect->description.c_str());
  10712. else if (field == "bullet")
  10713. lua_interface->SetInt32Value(state, effect->subbullet);
  10714. else if (field == "percentage")
  10715. lua_interface->SetInt32Value(state, effect->percentage);
  10716. else // no match
  10717. return 0;
  10718. return 1;
  10719. }
  10720. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10721. if (!lua_interface)
  10722. return 0;
  10723. LuaSpell* spell = lua_interface->GetSpell(state);
  10724. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10725. Spawn* target = lua_interface->GetSpawn(state, 3);
  10726. lua_interface->ResetFunctionStack(state);
  10727. if (!target) {
  10728. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10729. return 0;
  10730. }
  10731. if (!target->IsEntity()) {
  10732. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10733. return 0;
  10734. }
  10735. if (!spell) {
  10736. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10737. return 0;
  10738. }
  10739. if (caster && !caster->IsEntity()) {
  10740. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10741. return 0;
  10742. }
  10743. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10744. return 0;
  10745. }
  10746. int EQ2Emu_lua_InWater(lua_State* state) {
  10747. if (!lua_interface)
  10748. return 0;
  10749. Spawn* spawn = lua_interface->GetSpawn(state);
  10750. lua_interface->ResetFunctionStack(state);
  10751. if (spawn) {
  10752. lua_interface->SetBooleanValue(state, spawn->InWater());
  10753. return 1;
  10754. }
  10755. return 0;
  10756. }
  10757. int EQ2Emu_lua_InLava(lua_State* state) {
  10758. if (!lua_interface)
  10759. return 0;
  10760. Spawn* spawn = lua_interface->GetSpawn(state);
  10761. lua_interface->ResetFunctionStack(state);
  10762. if (spawn) {
  10763. lua_interface->SetBooleanValue(state, spawn->InLava());
  10764. return 1;
  10765. }
  10766. return 0;
  10767. }
  10768. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10769. if (!lua_interface)
  10770. return 0;
  10771. Spawn* attacker = lua_interface->GetSpawn(state);
  10772. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10773. int8 type = lua_interface->GetInt8Value(state, 3);
  10774. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10775. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10776. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10777. string spell_name = lua_interface->GetStringValue(state, 7);
  10778. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10779. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10780. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10781. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10782. lua_interface->ResetFunctionStack(state);
  10783. if (!attacker) {
  10784. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10785. return 0;
  10786. }
  10787. if (!attacker->IsEntity()) {
  10788. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10789. return 0;
  10790. }
  10791. if (!victim) {
  10792. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10793. return 0;
  10794. }
  10795. if (!victim->IsEntity()) {
  10796. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10797. return 0;
  10798. }
  10799. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10800. return 0;
  10801. }
  10802. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10803. if (!lua_interface)
  10804. return 0;
  10805. Spawn* spawn = lua_interface->GetSpawn(state);
  10806. lua_interface->ResetFunctionStack(state);
  10807. if (spawn) {
  10808. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10809. return 1;
  10810. }
  10811. return 0;
  10812. }
  10813. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10814. if (!lua_interface)
  10815. return 0;
  10816. Spawn* spawn = lua_interface->GetSpawn(state);
  10817. bool invul = lua_interface->GetBooleanValue(state, 2);
  10818. lua_interface->ResetFunctionStack(state);
  10819. if (spawn) {
  10820. spawn->SetInvulnerable(invul);
  10821. }
  10822. return 0;
  10823. }
  10824. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10825. if (!lua_interface)
  10826. return 0;
  10827. string category = lua_interface->GetStringValue(state);
  10828. string name = lua_interface->GetStringValue(state, 2);
  10829. lua_interface->ResetFunctionStack(state);
  10830. Rule *ret = 0;
  10831. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10832. lua_interface->SetBooleanValue(state, ret->GetBool());
  10833. return 1;
  10834. }
  10835. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10836. return 0;
  10837. }
  10838. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10839. if (!lua_interface)
  10840. return 0;
  10841. string category = lua_interface->GetStringValue(state);
  10842. string name = lua_interface->GetStringValue(state, 2);
  10843. lua_interface->ResetFunctionStack(state);
  10844. Rule *ret = 0;
  10845. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10846. lua_interface->SetInt32Value(state, ret->GetInt32());
  10847. return 1;
  10848. }
  10849. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10850. return 0;
  10851. }
  10852. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10853. if (!lua_interface)
  10854. return 0;
  10855. string category = lua_interface->GetStringValue(state);
  10856. string name = lua_interface->GetStringValue(state, 2);
  10857. lua_interface->ResetFunctionStack(state);
  10858. Rule *ret = 0;
  10859. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10860. lua_interface->SetFloatValue(state, ret->GetFloat());
  10861. return 1;
  10862. }
  10863. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10864. return 0;
  10865. }
  10866. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10867. if (!lua_interface)
  10868. return 0;
  10869. Spawn* spawn = lua_interface->GetSpawn(state);
  10870. string type = lua_interface->GetStringValue(state, 2);
  10871. lua_interface->ResetFunctionStack(state);
  10872. if (spawn) {
  10873. int res = 1;
  10874. boost::to_lower(type);
  10875. if(type == "assigned_aa")
  10876. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10877. else if ( type == "unassigned_aa")
  10878. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10879. else if ( type == "assigned_tradeskill_aa")
  10880. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10881. else if ( type == "unassigned_tradeskill_aa")
  10882. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10883. else if ( type == "assigned_prestige_aa")
  10884. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10885. else if ( type == "unassigned_prestige_aa")
  10886. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10887. else if ( type == "assigned_tradeskill_prestige_aa")
  10888. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10889. else if ( type == "unassigned_tradeskill_prestige_aa")
  10890. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10891. else
  10892. res = 0;
  10893. return res;
  10894. }
  10895. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10896. return 0;
  10897. }
  10898. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10899. if (!lua_interface)
  10900. return 0;
  10901. Spawn* spawn = lua_interface->GetSpawn(state);
  10902. string type = lua_interface->GetStringValue(state, 2);
  10903. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10904. lua_interface->ResetFunctionStack(state);
  10905. if (spawn) {
  10906. boost::to_lower(type);
  10907. if(type == "assigned_aa")
  10908. spawn->SetAssignedAA((sint16)value);
  10909. else if ( type == "unassigned_aa")
  10910. spawn->SetUnassignedAA((sint16)value);
  10911. else if ( type == "assigned_tradeskill_aa")
  10912. spawn->SetTradeskillAA((sint16)value);
  10913. else if ( type == "unassigned_tradeskill_aa")
  10914. spawn->SetUnassignedTradeskillAA((sint16)value);
  10915. else if ( type == "assigned_prestige_aa")
  10916. spawn->SetPrestigeAA((sint16)value);
  10917. else if ( type == "unassigned_prestige_aa")
  10918. spawn->SetUnassignedPrestigeAA((sint16)value);
  10919. else if ( type == "assigned_tradeskill_prestige_aa")
  10920. spawn->SetTradeskillPrestigeAA((sint16)value);
  10921. else if ( type == "unassigned_tradeskill_prestige_aa")
  10922. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10923. if(spawn->IsPlayer())
  10924. ((Player*)spawn)->SetCharSheetChanged(true);
  10925. }
  10926. return 0;
  10927. }
  10928. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10929. if (!lua_interface)
  10930. return 0;
  10931. string titleName = lua_interface->GetStringValue(state);
  10932. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10933. lua_interface->ResetFunctionStack(state);
  10934. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10935. lua_interface->SetSInt32Value(state, index);
  10936. return 1;
  10937. }
  10938. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10939. if (!lua_interface)
  10940. return 0;
  10941. Spawn* spawn = lua_interface->GetSpawn(state);
  10942. string titleName = lua_interface->GetStringValue(state, 2);
  10943. lua_interface->ResetFunctionStack(state);
  10944. if(!spawn->IsPlayer())
  10945. {
  10946. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10947. lua_interface->SetSInt32Value(state, -1);
  10948. return 1;
  10949. }
  10950. Player* player = (Player*)spawn;
  10951. // check if player already has the title, don't need to add twice
  10952. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10953. if ( playerHasTitle)
  10954. {
  10955. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10956. return 1;
  10957. }
  10958. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10959. if(!title)
  10960. {
  10961. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10962. lua_interface->SetSInt32Value(state, -1);
  10963. return 1;
  10964. }
  10965. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10966. if(returnIdx < 0)
  10967. {
  10968. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10969. }
  10970. lua_interface->SetSInt32Value(state, returnIdx);
  10971. player->GetClient()->SendTitleUpdate();
  10972. return 1;
  10973. }
  10974. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10975. if (!lua_interface)
  10976. return 0;
  10977. Spawn* spawn = lua_interface->GetSpawn(state);
  10978. string titleName = lua_interface->GetStringValue(state, 2);
  10979. lua_interface->ResetFunctionStack(state);
  10980. if(!spawn->IsPlayer())
  10981. {
  10982. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10983. return 0;
  10984. }
  10985. Player* player = (Player*)spawn;
  10986. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10987. if(!title)
  10988. {
  10989. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10990. return 0;
  10991. }
  10992. if(title->GetPrefix())
  10993. {
  10994. 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());
  10995. return 0;
  10996. }
  10997. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10998. player->GetClient()->SendTitleUpdate();
  10999. return 1;
  11000. }
  11001. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11002. if (!lua_interface)
  11003. return 0;
  11004. Spawn* spawn = lua_interface->GetSpawn(state);
  11005. string titleName = lua_interface->GetStringValue(state, 2);
  11006. lua_interface->ResetFunctionStack(state);
  11007. if(!spawn->IsPlayer())
  11008. {
  11009. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11010. return 0;
  11011. }
  11012. Player* player = (Player*)spawn;
  11013. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11014. if(!title)
  11015. {
  11016. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11017. return 0;
  11018. }
  11019. if(!title->GetPrefix())
  11020. {
  11021. 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());
  11022. return 0;
  11023. }
  11024. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11025. player->GetClient()->SendTitleUpdate();
  11026. return 1;
  11027. }
  11028. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11029. if (!lua_interface)
  11030. return 0;
  11031. Spawn* spawn = lua_interface->GetSpawn(state);
  11032. lua_interface->ResetFunctionStack(state);
  11033. if(!spawn->IsPlayer())
  11034. {
  11035. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11036. return 0;
  11037. }
  11038. Player* player = (Player*)spawn;
  11039. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11040. player->GetClient()->SendTitleUpdate();
  11041. return 1;
  11042. }
  11043. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11044. if (!lua_interface)
  11045. return 0;
  11046. Spawn* spawn = lua_interface->GetSpawn(state);
  11047. lua_interface->ResetFunctionStack(state);
  11048. if(!spawn->IsPlayer())
  11049. {
  11050. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11051. return 0;
  11052. }
  11053. Player* player = (Player*)spawn;
  11054. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11055. player->GetClient()->SendTitleUpdate();
  11056. return 1;
  11057. }
  11058. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11059. if (!lua_interface)
  11060. return 0;
  11061. Spawn* spawn = lua_interface->GetSpawn(state);
  11062. string field = lua_interface->GetStringValue(state, 2);
  11063. lua_interface->ResetFunctionStack(state);
  11064. if(!spawn || !spawn->IsEntity())
  11065. {
  11066. 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));
  11067. return 0;
  11068. }
  11069. Entity* ent = (Entity*)spawn;
  11070. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11071. return 1;
  11072. }
  11073. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11074. if (!lua_interface)
  11075. return 0;
  11076. Spawn* spawn = lua_interface->GetSpawn(state);
  11077. string field = lua_interface->GetStringValue(state, 2);
  11078. lua_interface->ResetFunctionStack(state);
  11079. if(!spawn || !spawn->IsEntity())
  11080. {
  11081. 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));
  11082. return 0;
  11083. }
  11084. Entity* ent = (Entity*)spawn;
  11085. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11086. return 1;
  11087. }
  11088. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11089. if (!lua_interface)
  11090. return 0;
  11091. Spawn* spawn = lua_interface->GetSpawn(state);
  11092. string field = lua_interface->GetStringValue(state, 2);
  11093. lua_interface->ResetFunctionStack(state);
  11094. if(!spawn || !spawn->IsEntity())
  11095. {
  11096. 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));
  11097. return 0;
  11098. }
  11099. Entity* ent = (Entity*)spawn;
  11100. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11101. return 1;
  11102. }
  11103. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11104. if (!lua_interface)
  11105. return 0;
  11106. Spawn* spawn = lua_interface->GetSpawn(state);
  11107. string field = lua_interface->GetStringValue(state, 2);
  11108. lua_interface->ResetFunctionStack(state);
  11109. if(!spawn || !spawn->IsEntity())
  11110. {
  11111. 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));
  11112. return 0;
  11113. }
  11114. Entity* ent = (Entity*)spawn;
  11115. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11116. return 1;
  11117. }
  11118. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11119. if (!lua_interface)
  11120. return 0;
  11121. Spawn* spawn = lua_interface->GetSpawn(state);
  11122. string field = lua_interface->GetStringValue(state, 2);
  11123. string value = lua_interface->GetStringValue(state, 3);
  11124. lua_interface->ResetFunctionStack(state);
  11125. if(!spawn || !spawn->IsEntity())
  11126. {
  11127. 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));
  11128. return 0;
  11129. }
  11130. Entity* ent = (Entity*)spawn;
  11131. bool set_ = ent->SetInfoStructString(field, value);
  11132. lua_interface->SetBooleanValue(state, set_);
  11133. return 1;
  11134. }
  11135. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11136. if (!lua_interface)
  11137. return 0;
  11138. Spawn* spawn = lua_interface->GetSpawn(state);
  11139. string field = lua_interface->GetStringValue(state, 2);
  11140. int64 value = lua_interface->GetInt64Value(state, 3);
  11141. lua_interface->ResetFunctionStack(state);
  11142. if(!spawn || !spawn->IsEntity())
  11143. {
  11144. 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));
  11145. return 0;
  11146. }
  11147. Entity* ent = (Entity*)spawn;
  11148. bool set_ = ent->SetInfoStructUInt(field, value);
  11149. lua_interface->SetBooleanValue(state, set_);
  11150. return 1;
  11151. }
  11152. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11153. if (!lua_interface)
  11154. return 0;
  11155. Spawn* spawn = lua_interface->GetSpawn(state);
  11156. string field = lua_interface->GetStringValue(state, 2);
  11157. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11158. lua_interface->ResetFunctionStack(state);
  11159. if(!spawn || !spawn->IsEntity())
  11160. {
  11161. 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));
  11162. return 0;
  11163. }
  11164. Entity* ent = (Entity*)spawn;
  11165. bool set_ = ent->SetInfoStructSInt(field, value);
  11166. lua_interface->SetBooleanValue(state, set_);
  11167. return 1;
  11168. }
  11169. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11170. if (!lua_interface)
  11171. return 0;
  11172. Spawn* spawn = lua_interface->GetSpawn(state);
  11173. string field = lua_interface->GetStringValue(state, 2);
  11174. float value = lua_interface->GetFloatValue(state, 3);
  11175. lua_interface->ResetFunctionStack(state);
  11176. if(!spawn || !spawn->IsEntity())
  11177. {
  11178. 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));
  11179. return 0;
  11180. }
  11181. Entity* ent = (Entity*)spawn;
  11182. bool set_ = ent->SetInfoStructFloat(field, value);
  11183. lua_interface->SetBooleanValue(state, set_);
  11184. return 1;
  11185. }
  11186. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11187. if (!lua_interface)
  11188. return 0;
  11189. Spawn* spawn = lua_interface->GetSpawn(state);
  11190. bool value = lua_interface->GetBooleanValue(state, 2);
  11191. lua_interface->ResetFunctionStack(state);
  11192. if(!spawn || !spawn->IsPlayer())
  11193. {
  11194. 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));
  11195. return 0;
  11196. }
  11197. ((Player*)spawn)->SetCharSheetChanged(value);
  11198. return 0;
  11199. }
  11200. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11201. if (!lua_interface)
  11202. return 0;
  11203. Spawn* spawn = lua_interface->GetSpawn(state);
  11204. std::string fromName = lua_interface->GetStringValue(state, 2);
  11205. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11206. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11207. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11208. int32 copper = lua_interface->GetInt32Value(state, 6);
  11209. int32 silver = lua_interface->GetInt32Value(state, 7);
  11210. int32 gold = lua_interface->GetInt32Value(state, 8);
  11211. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11212. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11213. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11214. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11215. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11216. lua_interface->ResetFunctionStack(state);
  11217. if(!spawn || !spawn->IsPlayer())
  11218. {
  11219. 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));
  11220. lua_interface->SetBooleanValue(state, false);
  11221. return 1;
  11222. }
  11223. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11224. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11225. lua_interface->SetBooleanValue(state, true);
  11226. return 1;
  11227. }
  11228. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11229. if (!lua_interface)
  11230. return 0;
  11231. int32 char_id = lua_interface->GetInt32Value(state);
  11232. std::string fromName = lua_interface->GetStringValue(state, 2);
  11233. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11234. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11235. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11236. int32 copper = lua_interface->GetInt32Value(state, 6);
  11237. int32 silver = lua_interface->GetInt32Value(state, 7);
  11238. int32 gold = lua_interface->GetInt32Value(state, 8);
  11239. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11240. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11241. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11242. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11243. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11244. lua_interface->ResetFunctionStack(state);
  11245. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11246. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11247. lua_interface->SetBooleanValue(state, true);
  11248. return 1;
  11249. }
  11250. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11251. Spawn* widget;
  11252. if (lua_interface) {
  11253. widget = lua_interface->GetSpawn(state);
  11254. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11255. lua_interface->ResetFunctionStack(state);
  11256. if (widget && widget->IsWidget())
  11257. {
  11258. ((Widget*)widget)->OpenDoor();
  11259. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11260. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11261. }
  11262. else
  11263. 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));
  11264. }
  11265. return 0;
  11266. }
  11267. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11268. Spawn* widget;
  11269. if (lua_interface) {
  11270. widget = lua_interface->GetSpawn(state);
  11271. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11272. lua_interface->ResetFunctionStack(state);
  11273. if (widget && widget->IsWidget())
  11274. {
  11275. ((Widget*)widget)->CloseDoor();
  11276. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11277. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11278. }
  11279. else
  11280. 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));
  11281. }
  11282. return 0;
  11283. }
  11284. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11285. if (!lua_interface)
  11286. return 0;
  11287. Spawn* widget = lua_interface->GetSpawn(state);
  11288. lua_interface->ResetFunctionStack(state);
  11289. if (widget && widget->IsWidget())
  11290. {
  11291. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11292. return 1;
  11293. }
  11294. return 0;
  11295. }
  11296. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11297. if (!lua_interface)
  11298. return 0;
  11299. sint32 min = lua_interface->GetSInt32Value(state);
  11300. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11301. lua_interface->ResetFunctionStack(state);
  11302. sint32 result = MakeRandomInt(min, max);
  11303. lua_interface->SetSInt32Value(state, result);
  11304. return 1;
  11305. }
  11306. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11307. if (!lua_interface)
  11308. return 0;
  11309. float min = lua_interface->GetFloatValue(state);
  11310. float max = lua_interface->GetFloatValue(state, 2);
  11311. lua_interface->ResetFunctionStack(state);
  11312. float result = MakeRandomFloat(min, max);
  11313. lua_interface->SetFloatValue(state, result);
  11314. return 1;
  11315. }
  11316. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11317. if (!lua_interface)
  11318. return 0;
  11319. Spawn* spawn = lua_interface->GetSpawn(state);
  11320. int32 value = lua_interface->GetInt32Value(state, 2);
  11321. lua_interface->ResetFunctionStack(state);
  11322. if(!spawn)
  11323. {
  11324. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11325. lua_interface->SetBooleanValue(state, false);
  11326. return 1;
  11327. }
  11328. spawn->AddIconValue(value);
  11329. lua_interface->SetBooleanValue(state, true);
  11330. return 1;
  11331. }
  11332. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11333. if (!lua_interface)
  11334. return 0;
  11335. Spawn* spawn = lua_interface->GetSpawn(state);
  11336. int32 value = lua_interface->GetInt32Value(state, 2);
  11337. lua_interface->ResetFunctionStack(state);
  11338. if(!spawn)
  11339. {
  11340. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11341. lua_interface->SetBooleanValue(state, false);
  11342. return 1;
  11343. }
  11344. spawn->RemoveIconValue(value);
  11345. lua_interface->SetBooleanValue(state, true);
  11346. return 1;
  11347. }
  11348. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11349. Spawn* npc = lua_interface->GetSpawn(state);
  11350. lua_interface->ResetFunctionStack(state);
  11351. if (npc && npc->IsNPC()) {
  11352. NPC* shard = (NPC*)npc;
  11353. int32 shardid = shard->GetShardID();
  11354. lua_interface->SetInt32Value(state, shardid);
  11355. return 1;
  11356. }
  11357. lua_interface->SetInt32Value(state, 0);
  11358. return 1;
  11359. }
  11360. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11361. Spawn* npc = lua_interface->GetSpawn(state);
  11362. lua_interface->ResetFunctionStack(state);
  11363. if (npc && npc->IsNPC()) {
  11364. NPC* shard = (NPC*)npc;
  11365. int32 charid = shard->GetShardCharID();
  11366. lua_interface->SetInt32Value(state, charid);
  11367. return 1;
  11368. }
  11369. lua_interface->SetInt32Value(state, 0);
  11370. return 1;
  11371. }
  11372. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11373. Spawn* npc = lua_interface->GetSpawn(state);
  11374. lua_interface->ResetFunctionStack(state);
  11375. if (npc && npc->IsNPC()) {
  11376. NPC* shard = (NPC*)npc;
  11377. int64 timestamp = shard->GetShardCreatedTimestamp();
  11378. lua_interface->SetSInt64Value(state, timestamp);
  11379. return 1;
  11380. }
  11381. lua_interface->SetSInt64Value(state, 0);
  11382. return 1;
  11383. }
  11384. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11385. if (!lua_interface)
  11386. return 0;
  11387. int32 shardid = lua_interface->GetInt32Value(state);
  11388. lua_interface->ResetFunctionStack(state);
  11389. if(shardid < 1)
  11390. lua_interface->SetBooleanValue(state, false);
  11391. else
  11392. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11393. return 1;
  11394. }
  11395. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11396. if (!lua_interface)
  11397. return 0;
  11398. Spawn* spawn = lua_interface->GetSpawn(state);
  11399. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11400. if (spawn) {
  11401. spawn->PauseMovement(delay_in_ms);
  11402. }
  11403. lua_interface->ResetFunctionStack(state);
  11404. return 0;
  11405. }
  11406. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11407. if (!lua_interface)
  11408. return 0;
  11409. Spawn* spawn = lua_interface->GetSpawn(state);
  11410. if (spawn) {
  11411. spawn->StopMovement();
  11412. }
  11413. lua_interface->ResetFunctionStack(state);
  11414. return 0;
  11415. }
  11416. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11417. Player* player = (Player*)lua_interface->GetSpawn(state);
  11418. int8 level = lua_interface->GetInt8Value(state, 2);
  11419. lua_interface->ResetFunctionStack(state);
  11420. if (player && player->IsPlayer() && level > 0) {
  11421. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11422. return 1;
  11423. }
  11424. return 0;
  11425. }
  11426. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11427. Player* player = (Player*)lua_interface->GetSpawn(state);
  11428. int8 level = lua_interface->GetInt8Value(state, 2);
  11429. lua_interface->ResetFunctionStack(state);
  11430. if (player && player->IsPlayer() && level > 0) {
  11431. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11432. return 1;
  11433. }
  11434. return 0;
  11435. }
  11436. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11437. ZoneServer* zone = lua_interface->GetZone(state);
  11438. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11439. lua_interface->ResetFunctionStack(state);
  11440. if (zone) {
  11441. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11442. if (spawn) {
  11443. lua_interface->SetSpawnValue(state, spawn);
  11444. return 1;
  11445. }
  11446. }
  11447. return 0;
  11448. }
  11449. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11450. if (!lua_interface)
  11451. return 0;
  11452. Spawn* spawn = lua_interface->GetSpawn(state);
  11453. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11454. lua_interface->ResetFunctionStack(state);
  11455. bool res = false;
  11456. if(spawn && spawn->IsTransportSpawn())
  11457. {
  11458. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11459. spawn->SetRailID(rail_id);
  11460. res = true;
  11461. }
  11462. else if (!spawn) {
  11463. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11464. }
  11465. else if(!spawn->IsTransportSpawn()) {
  11466. 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());
  11467. }
  11468. lua_interface->SetBooleanValue(state, res);
  11469. return 1;
  11470. }
  11471. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11472. if (!lua_interface)
  11473. return 0;
  11474. ZoneServer* zone = lua_interface->GetZone(state);
  11475. lua_interface->ResetFunctionStack(state);
  11476. if (zone) {
  11477. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11478. return 1;
  11479. }
  11480. return 0;
  11481. }
  11482. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11483. if (!lua_interface)
  11484. return 0;
  11485. Spawn* spawn = lua_interface->GetSpawn(state);
  11486. lua_interface->ResetFunctionStack(state);
  11487. if (spawn) {
  11488. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11489. return 1;
  11490. }
  11491. return 0;
  11492. }
  11493. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11494. if (!lua_interface)
  11495. return 0;
  11496. Spawn* player = lua_interface->GetSpawn(state);
  11497. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11498. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11499. lua_interface->ResetFunctionStack(state);
  11500. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11501. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11502. }
  11503. else if(!zoneID) {
  11504. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11505. }
  11506. else
  11507. {
  11508. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11509. return 1;
  11510. }
  11511. return 0;
  11512. }
  11513. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11514. if (!lua_interface)
  11515. return 0;
  11516. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11517. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11518. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11519. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11520. lua_interface->ResetFunctionStack(state);
  11521. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11522. world.GetWorldTimeStruct()->year = newYear;
  11523. world.GetWorldTimeStruct()->month = newMonth;
  11524. world.GetWorldTimeStruct()->hour = newHour;
  11525. world.GetWorldTimeStruct()->minute = newMinute;
  11526. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11527. return 0;
  11528. }
  11529. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11530. if (!lua_interface)
  11531. return 0;
  11532. lua_interface->ResetFunctionStack(state);
  11533. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11534. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11535. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11536. return 1;
  11537. }
  11538. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11539. if (!lua_interface)
  11540. return 0;
  11541. lua_interface->ResetFunctionStack(state);
  11542. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11543. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11544. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11545. return 1;
  11546. }
  11547. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11548. if (!lua_interface)
  11549. return 0;
  11550. lua_interface->ResetFunctionStack(state);
  11551. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11552. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11553. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11554. return 1;
  11555. }
  11556. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11557. if (!lua_interface)
  11558. return 0;
  11559. lua_interface->ResetFunctionStack(state);
  11560. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11561. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11562. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11563. return 1;
  11564. }
  11565. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11566. if (!lua_interface)
  11567. return 0;
  11568. lua_interface->ResetFunctionStack(state);
  11569. world.SendTimeUpdate();
  11570. return 0;
  11571. }
  11572. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11573. bool update_result = false;
  11574. Faction* faction = 0;
  11575. Spawn* spawn = lua_interface->GetSpawn(state);
  11576. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11577. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11578. lua_interface->ResetFunctionStack(state);
  11579. if(!spawn || !spawn->IsPlayer()) {
  11580. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11581. return 0;
  11582. }
  11583. Player* player = (Player*)spawn;
  11584. Client* client = player->GetClient();
  11585. if (faction_id > 0) {
  11586. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11587. if(hasfaction == 0) {
  11588. //they do not have the faction. Lets get the default value and feed it in.
  11589. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11590. //add the default faction for the player.
  11591. player->SetFactionValue(faction_id, defaultfaction);
  11592. }
  11593. if(increase >= 0) {
  11594. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11595. faction = master_faction_list.GetFaction(faction_id);
  11596. if(faction && update_result)
  11597. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11598. else if(faction)
  11599. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11600. lua_interface->SetBooleanValue(state, true);
  11601. return 1;
  11602. }
  11603. if(increase < 0){
  11604. //change the negative to a positive, since thats how decreasefaction() likes it.
  11605. increase *= -1;
  11606. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11607. faction = master_faction_list.GetFaction(faction_id);
  11608. if(faction && update_result)
  11609. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11610. else if(faction)
  11611. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11612. lua_interface->SetBooleanValue(state, true);
  11613. return 1;
  11614. }
  11615. }
  11616. lua_interface->SetBooleanValue(state, false);
  11617. return 1;
  11618. }
  11619. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11620. bool hascoin = 0;
  11621. Player* player = (Player*)lua_interface->GetSpawn(state);
  11622. int32 coins = lua_interface->GetInt32Value(state, 2);
  11623. lua_interface->ResetFunctionStack(state);
  11624. if (player && player->IsPlayer()) {
  11625. hascoin = player->HasCoins(coins);
  11626. if(hascoin == 0) {
  11627. lua_interface->SetBooleanValue(state, false);
  11628. return 1;
  11629. }
  11630. if(hascoin == 1) {
  11631. lua_interface->SetBooleanValue(state, true);
  11632. return 1;
  11633. }
  11634. }
  11635. return 0;
  11636. }
  11637. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11638. int32 loot_tier = 0;
  11639. Spawn* spawn = lua_interface->GetSpawn(state);
  11640. lua_interface->ResetFunctionStack(state);
  11641. if (spawn) {
  11642. loot_tier = spawn->GetLootTier();
  11643. lua_interface->SetInt32Value(state, loot_tier);
  11644. return 1;
  11645. }
  11646. return 0;
  11647. }
  11648. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11649. if (!lua_interface)
  11650. return 0;
  11651. Spawn* spawn = lua_interface->GetSpawn(state);
  11652. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11653. lua_interface->ResetFunctionStack(state);
  11654. if (spawn) {
  11655. spawn->SetLootTier(loot_tier);
  11656. lua_interface->SetBooleanValue(state, true);
  11657. return 1;
  11658. }
  11659. lua_interface->SetBooleanValue(state, false);
  11660. return 1;
  11661. }
  11662. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11663. int32 loot_drop_type = 0;
  11664. Spawn* spawn = lua_interface->GetSpawn(state);
  11665. lua_interface->ResetFunctionStack(state);
  11666. if (spawn) {
  11667. loot_drop_type = spawn->GetLootDropType();
  11668. lua_interface->SetInt32Value(state, loot_drop_type);
  11669. return 1;
  11670. }
  11671. return 0;
  11672. }
  11673. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11674. if (!lua_interface)
  11675. return 0;
  11676. Spawn* spawn = lua_interface->GetSpawn(state);
  11677. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11678. lua_interface->ResetFunctionStack(state);
  11679. if (spawn) {
  11680. spawn->SetLootDropType(loot_drop_type);
  11681. lua_interface->SetBooleanValue(state, true);
  11682. return 1;
  11683. }
  11684. lua_interface->SetBooleanValue(state, false);
  11685. return 1;
  11686. }
  11687. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11688. if (!lua_interface)
  11689. return 0;
  11690. Spawn* spawn = lua_interface->GetSpawn(state);
  11691. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11692. if(damage_amount > 100) {
  11693. damage_amount = 100;
  11694. }
  11695. if (!spawn) {
  11696. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11697. lua_interface->ResetFunctionStack(state);
  11698. return 0;
  11699. }
  11700. lua_interface->ResetFunctionStack(state);
  11701. if (spawn->IsPlayer()) {
  11702. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11703. lua_interface->SetBooleanValue(state, true);
  11704. else
  11705. lua_interface->SetBooleanValue(state, false);
  11706. }
  11707. else {
  11708. lua_interface->SetBooleanValue(state, false);
  11709. }
  11710. return 1;
  11711. }
  11712. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11713. ZoneServer* zone = lua_interface->GetZone(state);
  11714. int32 version = lua_interface->GetInt32Value(state, 2);
  11715. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11716. if(region_map == nullptr) {
  11717. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11718. lua_interface->ResetFunctionStack(state);
  11719. return 0;
  11720. }
  11721. string region_name = lua_interface->GetStringValue(state, 3);
  11722. string env_name = lua_interface->GetStringValue(state, 4);
  11723. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11724. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11725. float dist = lua_interface->GetFloatValue(state, 7);
  11726. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11727. lua_interface->ResetFunctionStack(state);
  11728. lua_interface->SetBooleanValue(state, true);
  11729. return 1;
  11730. }
  11731. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11732. ZoneServer* zone = lua_interface->GetZone(state);
  11733. int32 version = lua_interface->GetInt32Value(state, 2);
  11734. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11735. if(region_map == nullptr) {
  11736. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11737. lua_interface->ResetFunctionStack(state);
  11738. return 0;
  11739. }
  11740. string region_name = lua_interface->GetStringValue(state, 3);
  11741. region_map->RemoveRegionNode(region_name);
  11742. lua_interface->ResetFunctionStack(state);
  11743. lua_interface->SetBooleanValue(state, true);
  11744. return 1;
  11745. }
  11746. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11747. Client* client = nullptr;
  11748. Spawn* player = lua_interface->GetSpawn(state);
  11749. if (!player) {
  11750. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11751. lua_interface->SetBooleanValue(state, false);
  11752. lua_interface->ResetFunctionStack(state);
  11753. return 1;
  11754. }
  11755. if (!player->IsPlayer()) {
  11756. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11757. lua_interface->SetBooleanValue(state, false);
  11758. lua_interface->ResetFunctionStack(state);
  11759. return 1;
  11760. }
  11761. client = player->GetClient();
  11762. if (!client) {
  11763. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11764. lua_interface->SetBooleanValue(state, false);
  11765. lua_interface->ResetFunctionStack(state);
  11766. return 1;
  11767. }
  11768. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11769. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11770. lua_interface->ResetFunctionStack(state);
  11771. lua_interface->SetBooleanValue(state, success_sight);
  11772. return 1;
  11773. }
  11774. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11775. if (!lua_interface)
  11776. return 0;
  11777. bool result = false;
  11778. Spawn* spawn = lua_interface->GetSpawn(state);
  11779. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11780. lua_interface->ResetFunctionStack(state);
  11781. if (!spawn)
  11782. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11783. else if (!spawn->IsNPC())
  11784. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11785. else
  11786. {
  11787. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11788. result = true;
  11789. }
  11790. lua_interface->SetBooleanValue(state, result);
  11791. return 1;
  11792. }
  11793. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11794. if (!lua_interface)
  11795. return 0;
  11796. bool result = false;
  11797. Spawn* spawn = lua_interface->GetSpawn(state);
  11798. lua_interface->ResetFunctionStack(state);
  11799. if (!spawn)
  11800. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11801. else if (!spawn->IsNPC())
  11802. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11803. else
  11804. {
  11805. if(((NPC*)spawn)->cast_on_aggro_completed)
  11806. result = true;
  11807. }
  11808. lua_interface->SetBooleanValue(state, result);
  11809. return 1;
  11810. }
  11811. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  11812. Client* client = nullptr;
  11813. Spawn* player = lua_interface->GetSpawn(state);
  11814. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  11815. lua_interface->ResetFunctionStack(state);
  11816. if (!player) {
  11817. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  11818. lua_interface->SetBooleanValue(state, false);
  11819. return 1;
  11820. }
  11821. if (!player->IsPlayer()) {
  11822. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  11823. lua_interface->SetBooleanValue(state, false);
  11824. return 1;
  11825. }
  11826. client = player->GetClient();
  11827. if (!client) {
  11828. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  11829. lua_interface->SetBooleanValue(state, false);
  11830. return 1;
  11831. }
  11832. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  11833. lua_interface->SetBooleanValue(state, result);
  11834. return 1;
  11835. }
  11836. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  11837. Client* client = nullptr;
  11838. Spawn* player = lua_interface->GetSpawn(state);
  11839. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  11840. lua_interface->ResetFunctionStack(state);
  11841. if (!player) {
  11842. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  11843. lua_interface->SetBooleanValue(state, false);
  11844. return 1;
  11845. }
  11846. if (!player->IsPlayer()) {
  11847. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  11848. lua_interface->SetBooleanValue(state, false);
  11849. return 1;
  11850. }
  11851. client = player->GetClient();
  11852. if (!client) {
  11853. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  11854. lua_interface->SetBooleanValue(state, false);
  11855. return 1;
  11856. }
  11857. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  11858. lua_interface->SetBooleanValue(state, result);
  11859. return 1;
  11860. }
  11861. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  11862. Client* client = nullptr;
  11863. Spawn* player = lua_interface->GetSpawn(state);
  11864. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  11865. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  11866. // rest are all optional fields
  11867. float x = lua_interface->GetFloatValue(state, 4);
  11868. float y = lua_interface->GetFloatValue(state, 5);
  11869. float z = lua_interface->GetFloatValue(state, 6);
  11870. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  11871. lua_interface->ResetFunctionStack(state);
  11872. if (!player) {
  11873. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  11874. lua_interface->SetBooleanValue(state, false);
  11875. return 1;
  11876. }
  11877. if (!player->IsPlayer()) {
  11878. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  11879. lua_interface->SetBooleanValue(state, false);
  11880. return 1;
  11881. }
  11882. if(!player->GetZone()) {
  11883. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  11884. lua_interface->SetBooleanValue(state, false);
  11885. return 1;
  11886. }
  11887. client = player->GetClient();
  11888. if (!client) {
  11889. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  11890. lua_interface->SetBooleanValue(state, false);
  11891. return 1;
  11892. }
  11893. if(!client->IsReadyForUpdates()) {
  11894. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  11895. lua_interface->SetBooleanValue(state, false);
  11896. return 1;
  11897. }
  11898. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  11899. lua_interface->SetBooleanValue(state, true);
  11900. return 1;
  11901. }
  11902. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  11903. Client* client = nullptr;
  11904. Spawn* spawn = lua_interface->GetSpawn(state);
  11905. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  11906. lua_interface->ResetFunctionStack(state);
  11907. if (!spawn) {
  11908. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  11909. lua_interface->SetBooleanValue(state, false);
  11910. return 1;
  11911. }
  11912. if(!spawn->GetZone()) {
  11913. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  11914. lua_interface->SetBooleanValue(state, false);
  11915. return 1;
  11916. }
  11917. spawn->AddIgnoredWidget(widget_id);
  11918. lua_interface->SetBooleanValue(state, true);
  11919. return 1;
  11920. }
  11921. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  11922. ZoneServer* zone = lua_interface->GetZone(state);
  11923. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  11924. lua_interface->ResetFunctionStack(state);
  11925. if(!zone) {
  11926. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  11927. lua_interface->SetBooleanValue(state, false);
  11928. return 1;
  11929. }
  11930. if(!zone->IsLoading()) {
  11931. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  11932. lua_interface->SetBooleanValue(state, false);
  11933. return 1;
  11934. }
  11935. zone->AddIgnoredWidget(widget_id);
  11936. lua_interface->SetBooleanValue(state, true);
  11937. return 1;
  11938. }