LuaFunctions.cpp 394 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895
  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 = spawn->GetZone()->GetClientBySpawn(player);
  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_PlaySound(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. string sound_string = lua_interface->GetStringValue(state, 2);
  183. float x = lua_interface->GetFloatValue(state, 3);
  184. float y = lua_interface->GetFloatValue(state, 4);
  185. float z = lua_interface->GetFloatValue(state, 5);
  186. Spawn* player = lua_interface->GetSpawn(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn && sound_string.length() > 0) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = spawn->GetZone()->GetClientBySpawn(player);
  192. if (client)
  193. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  194. else
  195. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  196. }
  197. return 0;
  198. }
  199. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  200. if (!lua_interface)
  201. return 0;
  202. Spawn* spawn = lua_interface->GetSpawn(state);
  203. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  204. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  205. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  206. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  207. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  208. lua_interface->ResetFunctionStack(state);
  209. if (!spawn) {
  210. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  211. return 0;
  212. }
  213. if (quest_id > 0) {
  214. //Add this quest to the list of required quests for this spawn
  215. spawn->SetQuestsRequired(quest_id, quest_step);
  216. //If private spawn value set
  217. if (private_spawn) {
  218. //Set the spawn to be private when not granted access through this quest
  219. spawn->AddAllowAccessSpawn(spawn);
  220. spawn->SetPrivateQuestSpawn(true);
  221. }
  222. //This value allows access after a quest step, or the whole quest has been completed
  223. if (continued_access)
  224. spawn->SetQuestsRequiredContinuedAccess(true);
  225. //This value will override vis_flags in the vis packet
  226. if (flag_override > 0)
  227. spawn->SetQuestsRequiredOverride(flag_override);
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. Spawn* spawn = lua_interface->GetSpawn(state);
  235. float max_distance = lua_interface->GetFloatValue(state, 2);
  236. string variable = lua_interface->GetStringValue(state, 3);
  237. string value = lua_interface->GetStringValue(state, 4);
  238. lua_interface->ResetFunctionStack(state);
  239. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  240. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  241. return 0;
  242. }
  243. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  244. if (!lua_interface)
  245. return 0;
  246. Client* client = 0;
  247. Spawn* player = lua_interface->GetSpawn(state);
  248. if (!player) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  250. return 0;
  251. }
  252. if (!player->IsPlayer()) {
  253. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  254. return 0;
  255. }
  256. if (player->GetZone())
  257. client = player->GetZone()->GetClientBySpawn(player);
  258. if (!client) {
  259. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  260. return 0;
  261. }
  262. float intensity = lua_interface->GetFloatValue(state, 2);
  263. int8 direction = lua_interface->GetInt8Value(state, 3);
  264. lua_interface->ResetFunctionStack(state);
  265. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  266. if (packet) {
  267. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  268. v1 = *(float *)(a1 + 4);
  269. if ( v1 > 0.0 )
  270. v2 = fminf(v1, 1.0);
  271. else
  272. v2 = 0.1;
  273. */
  274. packet->setDataByName("intensity", intensity);
  275. if ( client->GetVersion() > 546 )
  276. packet->setDataByName("direction", direction);
  277. client->QueuePacket(packet->serialize());
  278. safe_delete(packet);
  279. }
  280. return 0;
  281. }
  282. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  283. if (!lua_interface)
  284. return 0;
  285. Spawn* dead = lua_interface->GetSpawn(state);
  286. Spawn* killer = lua_interface->GetSpawn(state, 2);
  287. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  288. lua_interface->ResetFunctionStack(state);
  289. if (dead && dead->Alive() && dead->GetZone())
  290. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  291. return 0;
  292. }
  293. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  294. if (!lua_interface)
  295. return 0;
  296. Spawn* spawn = lua_interface->GetSpawn(state);
  297. float max_distance = lua_interface->GetFloatValue(state, 2);
  298. bool include_players = lua_interface->GetInt8Value(state, 3);
  299. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  300. lua_interface->ResetFunctionStack(state);
  301. if (max_distance > 0 && spawn && spawn->GetZone())
  302. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  303. return 0;
  304. }
  305. int EQ2Emu_lua_Despawn(lua_State* state) {
  306. if (!lua_interface)
  307. return 0;
  308. Spawn* spawn = lua_interface->GetSpawn(state);
  309. int32 delay = lua_interface->GetInt32Value(state, 2);
  310. lua_interface->ResetFunctionStack(state);
  311. if (spawn && spawn->GetZone())
  312. spawn->GetZone()->Despawn(spawn, delay);
  313. return 0;
  314. }
  315. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  316. if (!lua_interface)
  317. return 0;
  318. Spawn* spawn = lua_interface->GetSpawn(state);
  319. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  320. lua_interface->ResetFunctionStack(state);
  321. if (spawn) {
  322. spawn->info_changed = true;
  323. spawn->SetShowHandIcon(displayHandIcon);
  324. }
  325. return 0;
  326. }
  327. //this function is used to force an update packet to be sent.
  328. //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
  329. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  330. if (!lua_interface)
  331. return 0;
  332. Spawn* spawn = lua_interface->GetSpawn(state);
  333. lua_interface->ResetFunctionStack(state);
  334. if (spawn) {
  335. spawn->vis_changed = true;
  336. spawn->GetZone()->AddChangedSpawn(spawn);
  337. }
  338. return 0;
  339. }
  340. //this function is used to force an update packet to be sent.
  341. //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
  342. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. lua_interface->ResetFunctionStack(state);
  347. if (spawn) {
  348. spawn->info_changed = true;
  349. spawn->GetZone()->AddChangedSpawn(spawn);
  350. }
  351. return 0;
  352. }
  353. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  354. if (!lua_interface)
  355. return 0;
  356. Spawn* spawn = lua_interface->GetSpawn(state);
  357. int32 new_state = lua_interface->GetInt32Value(state, 2);
  358. Spawn* player = lua_interface->GetSpawn(state, 3);
  359. lua_interface->ResetFunctionStack(state);
  360. if (spawn) {
  361. if(player)
  362. {
  363. if(player->IsPlayer())
  364. {
  365. Client* client = ((Player*)player)->GetClient();
  366. if(client)
  367. {
  368. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  369. lua_interface->SetBooleanValue(state, true);
  370. return 1;
  371. }
  372. else
  373. 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());
  374. }
  375. else
  376. 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());
  377. }
  378. else
  379. {
  380. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  381. lua_interface->SetBooleanValue(state, true);
  382. return 1;
  383. }
  384. }
  385. lua_interface->SetBooleanValue(state, false);
  386. return 1;
  387. }
  388. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  389. if (!lua_interface)
  390. return 0;
  391. Spawn* spawn = lua_interface->GetSpawn(state);
  392. string variable = lua_interface->GetStringValue(state, 2);
  393. string value = lua_interface->GetStringValue(state, 3);
  394. 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.
  395. bool temporary_flag = true;
  396. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  397. int8 index = 0;
  398. if(num_args >= 5)
  399. {
  400. 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
  401. index = lua_interface->GetInt8Value(state, 6);
  402. }
  403. lua_interface->ResetFunctionStack(state);
  404. int32 type = commands.GetSpawnSetType(variable);
  405. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  406. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  407. return 0;
  408. }
  409. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  410. if (!lua_interface)
  411. return 0;
  412. Spawn* spawn = lua_interface->GetSpawn(state);
  413. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  414. lua_interface->ResetFunctionStack(state);
  415. if (spawn && spawn_id > 0) {
  416. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  417. if (closest_spawn) {
  418. lua_interface->SetSpawnValue(state, closest_spawn);
  419. return 1;
  420. }
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. int32 position = lua_interface->GetInt32Value(state, 2);
  429. lua_interface->ResetFunctionStack(state);
  430. if (spawnList) {
  431. if (spawnList->size() > position) {
  432. lua_interface->SetSpawnValue(state, spawnList->at(position));
  433. return 1;
  434. }
  435. else {
  436. return 0;
  437. }
  438. return spawnList->size();
  439. }
  440. return 0;
  441. }
  442. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  443. if (!lua_interface)
  444. return 0;
  445. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  446. lua_interface->ResetFunctionStack(state);
  447. if (spawnList) {
  448. return spawnList->size();
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = new vector<Spawn*>();
  456. lua_interface->SetSpawnListValue(state, spawnList);
  457. return 1;
  458. }
  459. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  460. if (!lua_interface)
  461. return 0;
  462. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  463. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  464. lua_interface->ResetFunctionStack(state);
  465. if (spawnList) {
  466. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  467. if (it == spawnList->end())
  468. spawnList->push_back(spawn);
  469. }
  470. return 0;
  471. }
  472. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  473. if (!lua_interface)
  474. return 0;
  475. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  476. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  477. lua_interface->ResetFunctionStack(state);
  478. if (spawnList) {
  479. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  480. if(it != spawnList->end())
  481. spawnList->erase(it);
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* spawn = lua_interface->GetSpawn(state);
  489. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  490. lua_interface->ResetFunctionStack(state);
  491. if (spawn) {
  492. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  493. if (spawns.size() > 0) {
  494. vector<Spawn*>* spawnList = new vector<Spawn*>();
  495. vector<Spawn*>::iterator itr;
  496. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  497. spawnList->push_back(*itr);
  498. }
  499. lua_interface->SetSpawnListValue(state, spawnList);
  500. return 1;
  501. }
  502. }
  503. return 0;
  504. }
  505. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. Spawn* spawn = lua_interface->GetSpawn(state);
  509. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  510. lua_interface->ResetFunctionStack(state);
  511. if (spawn) {
  512. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  513. if (spawns.size() > 0) {
  514. vector<Spawn*>* spawnList = new vector<Spawn*>();
  515. vector<Spawn*>::iterator itr;
  516. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  517. spawnList->push_back(*itr);
  518. }
  519. lua_interface->SetSpawnListValue(state, spawnList);
  520. return 1;
  521. }
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  526. if (!lua_interface)
  527. return 0;
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. lua_interface->ResetFunctionStack(state);
  530. if (spawn) {
  531. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  532. if (spawns.size() > 0) {
  533. lua_createtable(state, spawns.size(), 0);
  534. int newTable = lua_gettop(state);
  535. for (int32 i = 0; i < spawns.size(); i++) {
  536. lua_interface->SetSpawnValue(state, spawns.at(i));
  537. lua_rawseti(state, newTable, i + 1);
  538. }
  539. return 1;
  540. }
  541. }
  542. return 0;
  543. }
  544. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  545. if (!lua_interface)
  546. return 0;
  547. string variable_name = lua_interface->GetStringValue(state);
  548. lua_interface->ResetFunctionStack(state);
  549. Variable* var = variables.FindVariable(variable_name);
  550. if (var) {
  551. lua_interface->SetStringValue(state, var->GetValue());
  552. return 1;
  553. }
  554. return 0;
  555. }
  556. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  557. if (!lua_interface)
  558. return 0;
  559. int32 total_coins = lua_interface->GetInt32Value(state);
  560. lua_interface->ResetFunctionStack(state);
  561. if (total_coins == 0) {
  562. lua_interface->SetStringValue(state, "0 copper");
  563. return 1;
  564. }
  565. char tmp[64] = { 0 };
  566. string message = "";
  567. int32 val = 0;
  568. if (total_coins >= 1000000) {
  569. val = total_coins / 1000000;
  570. total_coins -= 1000000 * val;
  571. sprintf(tmp, " %u Platinum", val);
  572. message.append(tmp);
  573. memset(tmp, 0, 64);
  574. }
  575. if (total_coins >= 10000) {
  576. val = total_coins / 10000;
  577. total_coins -= 10000 * val;
  578. sprintf(tmp, " %u Gold", val);
  579. message.append(tmp);
  580. memset(tmp, 0, 64);
  581. }
  582. if (total_coins >= 100) {
  583. val = total_coins / 100;
  584. total_coins -= 100 * val;
  585. sprintf(tmp, " %u Silver", val);
  586. message.append(tmp);
  587. memset(tmp, 0, 64);
  588. }
  589. if (total_coins > 0) {
  590. sprintf(tmp, " %u Copper", (int32)total_coins);
  591. message.append(tmp);
  592. }
  593. lua_interface->SetStringValue(state, message.c_str());
  594. return 1;
  595. }
  596. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  597. ZoneServer* zone = lua_interface->GetZone(state);
  598. int32 group_id = lua_interface->GetInt32Value(state, 2);
  599. lua_interface->ResetFunctionStack(state);
  600. if (zone) {
  601. Spawn* spawn = zone->GetSpawnGroup(group_id);
  602. if (spawn) {
  603. lua_interface->SetSpawnValue(state, spawn);
  604. return 1;
  605. }
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  610. ZoneServer* zone = lua_interface->GetZone(state);
  611. int32 location_id = lua_interface->GetInt32Value(state, 2);
  612. lua_interface->ResetFunctionStack(state);
  613. if (zone) {
  614. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  615. if (spawn) {
  616. lua_interface->SetSpawnValue(state, spawn);
  617. return 1;
  618. }
  619. }
  620. return 0;
  621. }
  622. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. lua_interface->ResetFunctionStack(state);
  625. if (spawn) {
  626. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  627. return 1;
  628. }
  629. return 0;
  630. }
  631. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  632. Spawn* spawn = lua_interface->GetSpawn(state);
  633. lua_interface->ResetFunctionStack(state);
  634. if (spawn) {
  635. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  636. return 1;
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  645. lua_interface->ResetFunctionStack(state);
  646. if (spawn) {
  647. spawn->SetSpawnGroupID(new_group_id);
  648. lua_interface->SetBooleanValue(state, true);
  649. return 1;
  650. }
  651. lua_interface->SetBooleanValue(state, false);
  652. return 1;
  653. }
  654. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  659. lua_interface->ResetFunctionStack(state);
  660. if (spawn) {
  661. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  662. lua_interface->SetBooleanValue(state, true);
  663. return 1;
  664. }
  665. lua_interface->SetBooleanValue(state, false);
  666. return 1;
  667. }
  668. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  669. Spawn* spawn = lua_interface->GetSpawn(state);
  670. lua_interface->ResetFunctionStack(state);
  671. if (spawn) {
  672. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  673. return 1;
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  678. Spawn* spawn = lua_interface->GetSpawn(state);
  679. lua_interface->ResetFunctionStack(state);
  680. if (spawn) {
  681. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  682. return 1;
  683. }
  684. return 0;
  685. }
  686. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  687. Player* player = (Player*)lua_interface->GetSpawn(state);
  688. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  689. lua_interface->ResetFunctionStack(state);
  690. if (player && player->IsPlayer() && faction_id > 0) {
  691. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  692. return 1;
  693. }
  694. return 0;
  695. }
  696. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  697. if (!lua_interface)
  698. return 0;
  699. Spawn* spawn = lua_interface->GetSpawn(state);
  700. int32 value = lua_interface->GetInt32Value(state, 2);
  701. lua_interface->ResetFunctionStack(state);
  702. if (spawn) {
  703. spawn->SetFactionID(value);
  704. }
  705. return 0;
  706. }
  707. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  708. Spawn* spawn = lua_interface->GetSpawn(state);
  709. lua_interface->ResetFunctionStack(state);
  710. if (spawn) {
  711. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. int EQ2Emu_lua_GetGender(lua_State* state) {
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. lua_interface->ResetFunctionStack(state);
  719. if (spawn) {
  720. lua_interface->SetInt32Value(state, spawn->GetGender());
  721. return 1;
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_GetTarget(lua_State* state) {
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. lua_interface->ResetFunctionStack(state);
  728. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  730. return 1;
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. Spawn* spawn = lua_interface->GetSpawn(state);
  738. string mp3_string = lua_interface->GetStringValue(state, 2);
  739. int32 key1 = lua_interface->GetInt32Value(state, 3);
  740. int32 key2 = lua_interface->GetInt32Value(state, 4);
  741. Spawn* player = lua_interface->GetSpawn(state, 5);
  742. lua_interface->ResetFunctionStack(state);
  743. if (spawn && mp3_string.length() > 0) {
  744. Client* client = 0;
  745. if (player && player->IsPlayer())
  746. client = spawn->GetZone()->GetClientBySpawn(player);
  747. if (client) {
  748. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  749. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  750. }
  751. else
  752. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  753. }
  754. return 0;
  755. }
  756. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  757. if (!lua_interface)
  758. return 0;
  759. Spawn* spawn = lua_interface->GetSpawn(state);
  760. lua_interface->ResetFunctionStack(state);
  761. if (spawn) {
  762. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  763. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  764. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  765. return 3;
  766. }
  767. return 0;
  768. }
  769. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. if (spawn) {
  774. int32 item_id = lua_interface->GetInt32Value(state, 2);
  775. lua_interface->ResetFunctionStack(state);
  776. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  777. return 1;
  778. }
  779. lua_interface->ResetFunctionStack(state);
  780. return 0;
  781. }
  782. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  783. if (!lua_interface)
  784. return 0;
  785. Spawn* spawn = lua_interface->GetSpawn(state);
  786. if (spawn && spawn->IsEntity()) {
  787. int32 item_id = lua_interface->GetInt32Value(state, 2);
  788. int16 charges = lua_interface->GetInt16Value(state, 3);
  789. if (charges == 0)
  790. charges = 1;
  791. ((Entity*)spawn)->AddLootItem(item_id, charges);
  792. }
  793. lua_interface->ResetFunctionStack(state);
  794. return 0;
  795. }
  796. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn && spawn->IsEntity()) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. Item* item = spawn->LootItem(item_id);
  803. safe_delete(item);
  804. }
  805. lua_interface->ResetFunctionStack(state);
  806. return 0;
  807. }
  808. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  809. if (!lua_interface)
  810. return 0;
  811. Spawn* spawn = lua_interface->GetSpawn(state);
  812. if (spawn) {
  813. int32 val = lua_interface->GetInt32Value(state, 2);
  814. spawn->AddLootCoins(val);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* entity = lua_interface->GetSpawn(state);
  823. Spawn* player = lua_interface->GetSpawn(state, 2);
  824. if (entity && player && player->IsPlayer()) {
  825. int32 coins = lua_interface->GetInt32Value(state, 3);
  826. vector<Item*>* items = 0;
  827. int i = 0;
  828. int32 item_id = 0;
  829. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  830. if (items == 0)
  831. items = new vector<Item*>;
  832. if (master_item_list.GetItem(item_id))
  833. items->push_back(master_item_list.GetItem(item_id));
  834. i++;
  835. }
  836. Client* client = 0;
  837. client = player->GetZone()->GetClientBySpawn(player);
  838. if (client)
  839. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  840. if(coins > 0)
  841. entity->AddLootCoins(coins);
  842. safe_delete(items);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. int32 item_id = lua_interface->GetInt32Value(state, 3);
  853. lua_interface->ResetFunctionStack(state);
  854. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  855. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  856. return 1;
  857. }
  858. return 0;
  859. }
  860. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  861. if (!lua_interface)
  862. return 0;
  863. Spawn* entity = lua_interface->GetSpawn(state);
  864. Spawn* player = lua_interface->GetSpawn(state, 2);
  865. lua_interface->ResetFunctionStack(state);
  866. if (entity && player && player->IsPlayer()) {
  867. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  868. return 1;
  869. }
  870. return 0;
  871. }
  872. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  873. if (!lua_interface)
  874. return 0;
  875. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  876. safe_delete(conversation);
  877. lua_interface->ResetFunctionStack(state);
  878. conversation = new vector<ConversationOption>();
  879. lua_interface->SetConversationValue(state, conversation);
  880. return 1;
  881. }
  882. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  883. if (!lua_interface)
  884. return 0;
  885. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  886. if (conversation) {
  887. ConversationOption conv_option;
  888. conv_option.option = lua_interface->GetStringValue(state, 2);
  889. conv_option.function = lua_interface->GetStringValue(state, 3);
  890. if (conv_option.option.length() > 0)
  891. conversation->push_back(conv_option);
  892. }
  893. lua_interface->ResetFunctionStack(state);
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. Spawn* npc = lua_interface->GetSpawn(state);
  900. Spawn* player = lua_interface->GetSpawn(state, 2);
  901. lua_interface->ResetFunctionStack(state);
  902. if (npc && player && player->IsPlayer() && player->GetZone()) {
  903. Client* client = player->GetZone()->GetClientBySpawn(player);
  904. if (client) {
  905. int32 conversation_id = client->GetConversationID(npc, 0);
  906. client->CloseDialog(conversation_id);
  907. }
  908. }
  909. return 0;
  910. }
  911. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. Item* item = lua_interface->GetItem(state);
  915. Spawn* player = lua_interface->GetSpawn(state, 2);
  916. lua_interface->ResetFunctionStack(state);
  917. if (item && player && player->IsPlayer() && player->GetZone()) {
  918. Client* client = player->GetZone()->GetClientBySpawn(player);
  919. if (client) {
  920. int32 conversation_id = client->GetConversationID(0, item);
  921. client->CloseDialog(conversation_id);
  922. }
  923. }
  924. return 0;
  925. }
  926. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  927. if (!lua_interface)
  928. return 0;
  929. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  930. Spawn* spawn = 0;
  931. Item* item = 0;
  932. int8 type = lua_interface->GetInt8Value(state, 2);
  933. if (type == 1 || type == 3)
  934. spawn = lua_interface->GetSpawn(state, 3);
  935. else if (type == 2 || type == 4)
  936. item = lua_interface->GetItem(state, 3);
  937. Spawn* player = lua_interface->GetSpawn(state, 4);
  938. string text = lua_interface->GetStringValue(state, 5);
  939. string mp3 = lua_interface->GetStringValue(state, 6);
  940. int32 key1 = lua_interface->GetInt32Value(state, 7);
  941. int32 key2 = lua_interface->GetInt32Value(state, 8);
  942. lua_interface->ResetFunctionStack(state);
  943. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  944. Client* client = player->GetZone()->GetClientBySpawn(player);
  945. if (client) {
  946. if (spawn) {
  947. // Need to do this so the function works the same as it did before
  948. if (type == 1)
  949. type++;
  950. if (mp3.length() > 0)
  951. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  952. else
  953. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  954. }
  955. else {
  956. if (mp3.length() > 0)
  957. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  958. else
  959. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  960. }
  961. }
  962. }
  963. safe_delete(conversation);
  964. lua_interface->SetConversationValue(state, NULL);
  965. return 0;
  966. }
  967. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  968. if(!lua_interface)
  969. return 0;
  970. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  971. Item* item = lua_interface->GetItem(state, 2);
  972. Spawn* player = lua_interface->GetSpawn(state, 3);
  973. string text = lua_interface->GetStringValue(state, 4);
  974. string mp3 = lua_interface->GetStringValue(state, 5);
  975. int32 key1 = lua_interface->GetInt32Value(state, 6);
  976. int32 key2 = lua_interface->GetInt32Value(state, 7);
  977. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  978. Client* client = player->GetZone()->GetClientBySpawn(player);
  979. if(client){
  980. if(mp3.length() > 0)
  981. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  982. else
  983. client->DisplayConversation(item, conversation, (char*)text.c_str());
  984. }
  985. safe_delete(conversation);
  986. }
  987. return 0;
  988. }*/
  989. int EQ2Emu_lua_StartConversation(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  993. Spawn* source = lua_interface->GetSpawn(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. string text = lua_interface->GetStringValue(state, 4);
  996. string mp3 = lua_interface->GetStringValue(state, 5);
  997. int32 key1 = lua_interface->GetInt32Value(state, 6);
  998. int32 key2 = lua_interface->GetInt32Value(state, 7);
  999. lua_interface->ResetFunctionStack(state);
  1000. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1001. Client* client = source->GetZone()->GetClientBySpawn(player);
  1002. if (mp3.length() > 0)
  1003. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  1004. else
  1005. client->DisplayConversation(source, 1, conversation, text.c_str());
  1006. safe_delete(conversation);
  1007. lua_interface->SetConversationValue(state, NULL);
  1008. }
  1009. else
  1010. 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);
  1011. return 0;
  1012. }
  1013. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1014. if (!lua_interface)
  1015. return 0;
  1016. Spawn* spawn = lua_interface->GetSpawn(state);
  1017. float distance = lua_interface->GetFloatValue(state, 2);
  1018. string in_range_function = lua_interface->GetStringValue(state, 3);
  1019. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1020. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1021. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1022. return 0;
  1023. }
  1024. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1025. ZoneServer* zone = lua_interface->GetZone(state);
  1026. float x = lua_interface->GetFloatValue(state, 2);
  1027. float y = lua_interface->GetFloatValue(state, 3);
  1028. float z = lua_interface->GetFloatValue(state, 4);
  1029. float max_variation = lua_interface->GetFloatValue(state, 5);
  1030. string in_range_function = lua_interface->GetStringValue(state, 6);
  1031. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1032. lua_interface->ResetFunctionStack(state);
  1033. if (zone && in_range_function.length() > 0)
  1034. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1038. if (!lua_interface)
  1039. return 0;
  1040. Spawn* spawn = lua_interface->GetSpawn(state);
  1041. if (spawn && spawn->IsEntity()) {
  1042. int32 val = lua_interface->GetInt32Value(state, 2);
  1043. ((Entity*)spawn)->SetLootCoins(val);
  1044. }
  1045. lua_interface->ResetFunctionStack(state);
  1046. return 0;
  1047. }
  1048. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1049. if (!lua_interface)
  1050. return 0;
  1051. Spawn* spawn = lua_interface->GetSpawn(state);
  1052. lua_interface->ResetFunctionStack(state);
  1053. if (spawn && spawn->IsEntity()) {
  1054. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1060. if (!lua_interface)
  1061. return 0;
  1062. Spawn* spawn = lua_interface->GetSpawn(state);
  1063. float x = lua_interface->GetFloatValue(state, 2);
  1064. float y = lua_interface->GetFloatValue(state, 3);
  1065. float z = lua_interface->GetFloatValue(state, 4);
  1066. float speed = lua_interface->GetFloatValue(state, 5);
  1067. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1068. string function = lua_interface->GetStringValue(state, 7);
  1069. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1070. float heading = lua_interface->GetFloatValue(state, 8);
  1071. if (spawn) {
  1072. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1073. spawn->GetZone()->AddMovementNPC(spawn);
  1074. }
  1075. lua_interface->ResetFunctionStack(state);
  1076. return 0;
  1077. }
  1078. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1079. if (!lua_interface)
  1080. return 0;
  1081. Spawn* spawn = lua_interface->GetSpawn(state);
  1082. lua_interface->ResetFunctionStack(state);
  1083. if (spawn) {
  1084. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1085. return 1;
  1086. }
  1087. return 0;
  1088. }
  1089. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1090. if (!lua_interface)
  1091. return 0;
  1092. Spawn* spawn = lua_interface->GetSpawn(state);
  1093. lua_interface->ResetFunctionStack(state);
  1094. if (spawn && spawn->IsPlayer()) {
  1095. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1096. return 1;
  1097. }
  1098. lua_interface->SetInt32Value(state, 0);
  1099. return 1;
  1100. }
  1101. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1102. if (!lua_interface)
  1103. return 0;
  1104. Spawn* spawn = lua_interface->GetSpawn(state);
  1105. Spawn* target = lua_interface->GetSpawn(state, 2);
  1106. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1107. bool reset_action_state = true;
  1108. if(num_args > 2)
  1109. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1110. if (spawn && target) {
  1111. if (spawn->IsEntity())
  1112. // ((Entity*)spawn)->FaceTarget(target);
  1113. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1114. }
  1115. lua_interface->ResetFunctionStack(state);
  1116. return 0;
  1117. }
  1118. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. float x = lua_interface->GetFloatValue(state, 2);
  1123. float y = lua_interface->GetFloatValue(state, 3);
  1124. float z = lua_interface->GetFloatValue(state, 4);
  1125. float speed = lua_interface->GetFloatValue(state, 5);
  1126. string lua_function = lua_interface->GetStringValue(state, 6);
  1127. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1128. if (spawn) {
  1129. if (speed == 0)
  1130. speed = spawn->GetSpeed();
  1131. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1132. }
  1133. lua_interface->ResetFunctionStack(state);
  1134. return 0;
  1135. }
  1136. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1137. if (!lua_interface)
  1138. return 0;
  1139. Spawn* spawn = lua_interface->GetSpawn(state);
  1140. lua_interface->ResetFunctionStack(state);
  1141. if (spawn) {
  1142. spawn->ClearRunningLocations();
  1143. }
  1144. return 0;
  1145. }
  1146. int EQ2Emu_lua_Say(lua_State* state) {
  1147. if (!lua_interface)
  1148. return 0;
  1149. Spawn* spawn = lua_interface->GetSpawn(state);
  1150. string message = lua_interface->GetStringValue(state, 2);
  1151. Spawn* player = lua_interface->GetSpawn(state, 3);
  1152. int32 language = lua_interface->GetInt32Value(state, 4);
  1153. if (spawn && message.length() > 0) {
  1154. Client* client = 0;
  1155. if (player && player->IsPlayer())
  1156. client = spawn->GetZone()->GetClientBySpawn(player);
  1157. if (client)
  1158. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1159. else
  1160. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1161. }
  1162. lua_interface->ResetFunctionStack(state);
  1163. return 0;
  1164. }
  1165. int EQ2Emu_lua_Shout(lua_State* state) {
  1166. if (!lua_interface)
  1167. return 0;
  1168. Spawn* spawn = lua_interface->GetSpawn(state);
  1169. string message = lua_interface->GetStringValue(state, 2);
  1170. Spawn* player = lua_interface->GetSpawn(state, 3);
  1171. float dist = lua_interface->GetFloatValue(state, 4);
  1172. if (spawn && message.length() > 0) {
  1173. Client* client = 0;
  1174. if (player && player->IsPlayer())
  1175. client = spawn->GetZone()->GetClientBySpawn(player);
  1176. if (client)
  1177. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1178. else
  1179. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1180. }
  1181. lua_interface->ResetFunctionStack(state);
  1182. return 0;
  1183. }
  1184. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1185. if (!lua_interface)
  1186. return 0;
  1187. Spawn* spawn = lua_interface->GetSpawn(state);
  1188. string message = lua_interface->GetStringValue(state, 2);
  1189. Spawn* player = lua_interface->GetSpawn(state, 3);
  1190. if (spawn && message.length() > 0) {
  1191. Client* client = 0;
  1192. if (player && player->IsPlayer())
  1193. client = spawn->GetZone()->GetClientBySpawn(player);
  1194. if (client)
  1195. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1196. else
  1197. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1198. }
  1199. lua_interface->ResetFunctionStack(state);
  1200. return 0;
  1201. }
  1202. int EQ2Emu_lua_Emote(lua_State* state) {
  1203. if (!lua_interface)
  1204. return 0;
  1205. Spawn* spawn = lua_interface->GetSpawn(state);
  1206. string message = lua_interface->GetStringValue(state, 2);
  1207. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1208. Spawn* player = lua_interface->GetSpawn(state, 4);
  1209. char* to = 0;
  1210. if (spawn2)
  1211. to = spawn2->GetName();
  1212. if (spawn && message.length() > 0) {
  1213. Client* client = 0;
  1214. if (player && player->IsPlayer())
  1215. client = spawn->GetZone()->GetClientBySpawn(player);
  1216. if (client)
  1217. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1218. else
  1219. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1220. }
  1221. lua_interface->ResetFunctionStack(state);
  1222. return 0;
  1223. }
  1224. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1225. if (!lua_interface)
  1226. return 0;
  1227. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1228. if (!luaspell)
  1229. return 0;
  1230. Spawn* caster = luaspell->caster;
  1231. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1232. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1233. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1234. Spawn* target = lua_interface->GetSpawn(state, 4);
  1235. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1236. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1237. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1238. lua_interface->ResetFunctionStack(state);
  1239. boost::to_lower(heal_type);
  1240. if (caster && caster->IsEntity()) {
  1241. bool success = false;
  1242. luaspell->resisted = false;
  1243. if (target) {
  1244. float distance = caster->GetDistance(target, true);
  1245. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1246. success = true;
  1247. }
  1248. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1249. Spawn* target = 0;
  1250. ZoneServer* zone = luaspell->caster->GetZone();
  1251. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1252. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1253. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1254. float distance = caster->GetDistance(target, true);
  1255. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1256. }
  1257. }
  1258. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1259. success = true;
  1260. }
  1261. if (success) {
  1262. if (caster->GetZone())
  1263. caster->GetZone()->TriggerCharSheetTimer();
  1264. }
  1265. }
  1266. return 0;
  1267. }
  1268. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1269. if (!lua_interface)
  1270. return 0;
  1271. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1272. if (!luaspell)
  1273. return 0;
  1274. Spawn* caster = luaspell->caster;
  1275. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1276. float percentage = lua_interface->GetFloatValue(state, 2);
  1277. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1278. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1279. Spawn* target = lua_interface->GetSpawn(state, 5);
  1280. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1281. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1282. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1283. lua_interface->ResetFunctionStack(state);
  1284. boost::to_lower(heal_type);
  1285. int32 min_heal = 0, max_heal = 0;
  1286. if (caster && caster->IsEntity() && target) {
  1287. if(percentage <= 0.0f)
  1288. {
  1289. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1290. return 0;
  1291. }
  1292. if(heal_type == "power")
  1293. {
  1294. if(current_value)
  1295. {
  1296. if(caster_value)
  1297. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1298. else
  1299. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1300. }
  1301. else
  1302. {
  1303. if(caster_value)
  1304. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1305. else
  1306. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1307. }
  1308. }
  1309. else
  1310. {
  1311. if(current_value)
  1312. {
  1313. if(caster_value)
  1314. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1315. else
  1316. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1317. }
  1318. else
  1319. {
  1320. if(caster_value)
  1321. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1322. else
  1323. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1324. }
  1325. }
  1326. bool success = false;
  1327. luaspell->resisted = false;
  1328. if (target) {
  1329. float distance = caster->GetDistance(target, true);
  1330. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1331. success = true;
  1332. }
  1333. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1334. Spawn* target = 0;
  1335. ZoneServer* zone = luaspell->caster->GetZone();
  1336. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1337. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1338. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1339. float distance = caster->GetDistance(target, true);
  1340. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1341. }
  1342. }
  1343. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1344. success = true;
  1345. }
  1346. if (success) {
  1347. if (caster->GetZone())
  1348. caster->GetZone()->TriggerCharSheetTimer();
  1349. }
  1350. }
  1351. return 0;
  1352. }
  1353. int EQ2Emu_lua_AddItem(lua_State* state) {
  1354. if (!lua_interface)
  1355. return 0;
  1356. Spawn* spawn = lua_interface->GetSpawn(state);
  1357. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1358. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1359. lua_interface->ResetFunctionStack(state);
  1360. // default of 1 quantity to add
  1361. if (quantity == 0)
  1362. quantity = 1;
  1363. if (spawn && spawn->IsPlayer()) {
  1364. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1365. if (client && item_id > 0) {
  1366. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1367. return 1;
  1368. }
  1369. }
  1370. lua_interface->SetBooleanValue(state, false);
  1371. return 1;
  1372. }
  1373. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1374. if (!lua_interface)
  1375. return 0;
  1376. Spawn* spawn = lua_interface->GetSpawn(state);
  1377. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1378. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1379. string location = lua_interface->GetStringValue(state, 4);
  1380. int16 item_count = lua_interface->GetInt16Value(state,5);
  1381. //devn00b: if we dont have a count, assume 1 item.
  1382. if(!item_count) {
  1383. item_count = 1;
  1384. }
  1385. lua_interface->ResetFunctionStack(state);
  1386. if (spawn && spawn->IsPlayer()) {
  1387. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1388. if (client && item_id > 0) {
  1389. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1390. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1391. else
  1392. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1393. if (send_messages) {
  1394. Item* item = master_item_list.GetItem(item_id);
  1395. if (item) {
  1396. if(item_count > 1) {
  1397. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1398. string popup_text1 = "You receive "+ item_count;
  1399. string popup_text2 = " " + item->name;
  1400. string popup_text = popup_text1 + popup_text2;
  1401. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1402. // return 1;
  1403. } else {
  1404. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1405. string popup_text = "You receive " + item->name;
  1406. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1407. }
  1408. }
  1409. }
  1410. return 1;
  1411. }
  1412. }
  1413. lua_interface->SetBooleanValue(state, false);
  1414. return 1;
  1415. }
  1416. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1417. Spawn* spawn = lua_interface->GetSpawn(state);
  1418. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1419. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1420. lua_interface->ResetFunctionStack(state);
  1421. // default of 1 to remove
  1422. if (quantity == 0)
  1423. quantity = 1;
  1424. Client* client;
  1425. Item* item;
  1426. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1427. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1428. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1429. if (client->RemoveItem(item, quantity)) {
  1430. lua_interface->SetBooleanValue(state, true);
  1431. return 1;
  1432. }
  1433. }
  1434. }
  1435. }
  1436. lua_interface->SetBooleanValue(state, false);
  1437. return 1;
  1438. }
  1439. int EQ2Emu_lua_HasItem(lua_State* state) {
  1440. Spawn* player = lua_interface->GetSpawn(state);
  1441. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1442. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1443. lua_interface->ResetFunctionStack(state);
  1444. if (player && player->IsPlayer()) {
  1445. bool hasItem = false;
  1446. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1447. if (!hasItem)
  1448. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1449. lua_interface->SetBooleanValue(state, hasItem);
  1450. return 1;
  1451. }
  1452. lua_interface->SetBooleanValue(state, false);
  1453. return 1;
  1454. }
  1455. int EQ2Emu_lua_Spawn(lua_State* state) {
  1456. if (!lua_interface)
  1457. return 0;
  1458. ZoneServer* zone = lua_interface->GetZone(state);
  1459. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1460. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1461. float x = lua_interface->GetFloatValue(state, 4);
  1462. float y = lua_interface->GetFloatValue(state, 5);
  1463. float z = lua_interface->GetFloatValue(state, 6);
  1464. float heading = lua_interface->GetFloatValue(state, 7);
  1465. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1466. Spawn* spawn = zone->GetSpawn(spawn_id);
  1467. if (!spawn)
  1468. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1469. else {
  1470. spawn->SetX(x);
  1471. spawn->SetZ(z);
  1472. spawn->SetY(y,true,true);
  1473. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1474. spawn->SetHeading(heading);
  1475. if (restricted_npc)
  1476. spawn->AddAllowAccessSpawn(spawn);
  1477. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1478. bool scriptActive = false;
  1479. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1480. scriptActive = true;
  1481. spawn->SetSpawnScript(string(spawn_script));
  1482. }
  1483. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1484. zone->AddSpawn(spawn);
  1485. if (scriptActive) {
  1486. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1487. }
  1488. lua_interface->ResetFunctionStack(state);
  1489. lua_interface->SetSpawnValue(state, spawn);
  1490. return 1;
  1491. }
  1492. }
  1493. else {
  1494. string output = "Invalid paramaters to LUA Spawn command: \n";
  1495. if (!zone)
  1496. output = output.append("\t").append("Missing zone reference. \n");
  1497. if (spawn_id == 0)
  1498. output = output.append("\t").append("Missing spawn_id.");
  1499. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1500. }
  1501. lua_interface->ResetFunctionStack(state);
  1502. return 0;
  1503. }
  1504. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1505. if (!lua_interface)
  1506. return 0;
  1507. ZoneServer* zone = lua_interface->GetZone(state);
  1508. lua_interface->ResetFunctionStack(state);
  1509. if (zone) {
  1510. lua_interface->SetStringValue(state, zone->GetZoneName());
  1511. return 1;
  1512. }
  1513. return 0;
  1514. }
  1515. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1516. if (!lua_interface)
  1517. return 0;
  1518. ZoneServer* zone = lua_interface->GetZone(state);
  1519. lua_interface->ResetFunctionStack(state);
  1520. if (zone) {
  1521. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1522. return 1;
  1523. }
  1524. return 0;
  1525. }
  1526. int EQ2Emu_lua_GetZone(lua_State* state) {
  1527. if (!lua_interface)
  1528. return 0;
  1529. int32 zone_id = lua_interface->GetInt32Value(state);
  1530. ZoneServer* zone = 0;
  1531. if (zone_id > 0)
  1532. zone = zone_list.Get(zone_id);
  1533. else {
  1534. string zone_name = lua_interface->GetStringValue(state);
  1535. if (zone_name.length() > 0) {
  1536. zone = zone_list.Get(zone_name.c_str());
  1537. }
  1538. else {
  1539. Spawn* spawn = lua_interface->GetSpawn(state);
  1540. if (spawn)
  1541. zone = spawn->GetZone();
  1542. }
  1543. }
  1544. lua_interface->ResetFunctionStack(state);
  1545. if (zone) {
  1546. lua_interface->SetZoneValue(state, zone);
  1547. return 1;
  1548. }
  1549. return 0;
  1550. }
  1551. int EQ2Emu_lua_AddHate(lua_State* state) {
  1552. Spawn* entity = lua_interface->GetSpawn(state);
  1553. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1554. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1555. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1556. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1557. if (entity && entity->IsEntity() && amount != 0) {
  1558. if (luaspell) {
  1559. ZoneServer* zone = luaspell->caster->GetZone();
  1560. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1561. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1562. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1563. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1564. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1565. if (send_packet)
  1566. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1567. }
  1568. }
  1569. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1570. }
  1571. else if (npc && npc->IsNPC() && npc->GetZone())
  1572. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1573. }
  1574. lua_interface->ResetFunctionStack(state);
  1575. return 0;
  1576. }
  1577. int EQ2Emu_lua_Zone(lua_State* state) {
  1578. if (!lua_interface)
  1579. return 0;
  1580. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1581. ZoneServer* zone = lua_interface->GetZone(state);
  1582. Spawn* player = lua_interface->GetSpawn(state, 2);
  1583. Client* client = 0;
  1584. if (player && player->IsPlayer())
  1585. client = player->GetZone()->GetClientBySpawn(player);
  1586. float x = lua_interface->GetFloatValue(state, 3);
  1587. float y = lua_interface->GetFloatValue(state, 4);
  1588. float z = lua_interface->GetFloatValue(state, 5);
  1589. float heading = lua_interface->GetFloatValue(state, 6);
  1590. if (zone && client) {
  1591. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1592. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1593. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1594. {
  1595. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1596. return 0;
  1597. }
  1598. if (x != 0 || y != 0 || z != 0) {
  1599. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1600. player->SetX(x);
  1601. player->SetY(y);
  1602. player->SetZ(z);
  1603. player->SetHeading(heading);
  1604. client->Zone(zone->GetZoneName(), false);
  1605. }
  1606. else
  1607. client->Zone(zone->GetZoneName());
  1608. }
  1609. else
  1610. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1611. lua_interface->ResetFunctionStack(state);
  1612. return 0;
  1613. }
  1614. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1615. if (!lua_interface)
  1616. return 0;
  1617. Spawn* spawn = lua_interface->GetSpawn(state);
  1618. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1619. if (spawn && spawn2)
  1620. spawn->AddAllowAccessSpawn(spawn2);
  1621. lua_interface->ResetFunctionStack(state);
  1622. return 0;
  1623. }
  1624. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1625. if (!lua_interface)
  1626. return 0;
  1627. Spawn* target = lua_interface->GetSpawn(state);
  1628. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1629. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1630. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1631. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1632. lua_interface->ResetFunctionStack(state);
  1633. if (!target) {
  1634. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1635. return 0;
  1636. }
  1637. if (!target->IsEntity()) {
  1638. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1639. return 0;
  1640. }
  1641. if (spell_id <= 0) {
  1642. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1643. return 0;
  1644. }
  1645. if (caster && !caster->IsEntity()) {
  1646. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1647. return 0;
  1648. }
  1649. if (spell_tier == 0)
  1650. spell_tier = 1;
  1651. if (!caster)
  1652. caster = target;
  1653. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1654. return 0;
  1655. }
  1656. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1657. if (!lua_interface)
  1658. return 0;
  1659. Spawn* target = lua_interface->GetSpawn(state);
  1660. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1661. if (!luaspell)
  1662. return 0;
  1663. Spawn* caster = luaspell->caster;
  1664. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1665. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1666. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1667. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1668. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1669. //lua_interface->ResetFunctionStack(state);
  1670. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1671. vector<int16> faction_req;
  1672. vector<int16> race_req;
  1673. int32 class_req = 0;
  1674. int32 i = 0;
  1675. int8 f = 0;
  1676. int8 r = 0;
  1677. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1678. if (class_id < 100) {
  1679. class_req += pow(2.0, double(class_id - 1));
  1680. }
  1681. else if (class_id > 100 && class_id < 1000) {
  1682. race_req.push_back(class_id);
  1683. r++;
  1684. }
  1685. else {
  1686. faction_req.push_back(class_id);
  1687. f++;
  1688. }
  1689. i++;
  1690. }
  1691. lua_interface->ResetFunctionStack(state);
  1692. if (caster && caster->IsEntity()) {
  1693. bool race_match = false;
  1694. bool success = false;
  1695. luaspell->resisted = false;
  1696. if (luaspell->targets.size() > 0) {
  1697. ZoneServer* zone = luaspell->caster->GetZone();
  1698. Spawn* target = 0;
  1699. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1700. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1701. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1702. if (race_req.size() > 0) {
  1703. for (int8 i = 0; i < race_req.size(); i++) {
  1704. if (target->GetLuaRaceId() == race_req[i]) {
  1705. race_match = true;
  1706. }
  1707. }
  1708. }
  1709. else
  1710. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1711. if (race_match == true) {
  1712. float distance = caster->GetDistance(target, true);
  1713. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1714. }
  1715. }
  1716. }
  1717. success = true;
  1718. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1719. }
  1720. else if (target) {
  1721. //check class and race/faction here
  1722. if (race_req.size() > 0) {
  1723. for (int8 i = 0; i < race_req.size(); i++) {
  1724. if (target->GetLuaRaceId() == race_req[i]) {
  1725. race_match = true;
  1726. }
  1727. }
  1728. }
  1729. else
  1730. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1731. if (race_match == true) {
  1732. float distance = caster->GetDistance(target, true);
  1733. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1734. success = true;
  1735. }
  1736. }
  1737. if (success) {
  1738. Spell* spell = luaspell->spell;
  1739. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1740. ((Player*)caster)->InCombat(true);
  1741. if (caster->GetZone())
  1742. caster->GetZone()->TriggerCharSheetTimer();
  1743. }
  1744. }
  1745. }
  1746. return 0;
  1747. }
  1748. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1749. if (!lua_interface)
  1750. return 0;
  1751. Spawn* spawn = lua_interface->GetSpawn(state);
  1752. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1753. lua_interface->ResetFunctionStack(state);
  1754. if (spawn && value != 0) {
  1755. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1756. spawn->SetPower(spawn->GetTotalPower());
  1757. else
  1758. spawn->SetPower(spawn->GetPower() + value);
  1759. }
  1760. return 0;
  1761. }
  1762. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1763. if (!lua_interface)
  1764. return 0;
  1765. Spawn* spawn = lua_interface->GetSpawn(state);
  1766. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1767. lua_interface->ResetFunctionStack(state);
  1768. if (spawn && value != 0) {
  1769. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1770. spawn->SetHP(spawn->GetTotalHP());
  1771. else
  1772. spawn->SetHP(spawn->GetHP() + value);
  1773. }
  1774. return 0;
  1775. }
  1776. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1777. if (!lua_interface)
  1778. return 0;
  1779. Spawn* spawn = lua_interface->GetSpawn(state);
  1780. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1781. lua_interface->ResetFunctionStack(state);
  1782. if (spawn && value != 0) {
  1783. spawn->SetPower(spawn->GetPower() + value);
  1784. if (value > spawn->GetTotalHPBase())
  1785. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1786. }
  1787. return 0;
  1788. }
  1789. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1790. if (!lua_interface)
  1791. return 0;
  1792. Spawn* spawn = lua_interface->GetSpawn(state);
  1793. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1794. lua_interface->ResetFunctionStack(state);
  1795. if (spawn && value != 0) {
  1796. spawn->SetHP(spawn->GetHP() + value);
  1797. if (value > spawn->GetTotalHPBase())
  1798. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1799. }
  1800. return 0;
  1801. }
  1802. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1803. if (!lua_interface)
  1804. return 0;
  1805. Spawn* spawn = lua_interface->GetSpawn(state);
  1806. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1807. lua_interface->ResetFunctionStack(state);
  1808. if (spawn) {
  1809. spawn->SetHP(value);
  1810. if (value > spawn->GetTotalHPBase())
  1811. spawn->SetTotalHP(value);
  1812. }
  1813. return 0;
  1814. }
  1815. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1816. if (!lua_interface)
  1817. return 0;
  1818. Spawn* spawn = lua_interface->GetSpawn(state);
  1819. float value = lua_interface->GetFloatValue(state, 2);
  1820. lua_interface->ResetFunctionStack(state);
  1821. if (spawn && spawn->IsEntity() && value > 0)
  1822. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1823. if (spawn->IsPlayer())
  1824. ((Player*)spawn)->SetCharSheetChanged(true);
  1825. return 0;
  1826. }
  1827. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1828. if (!lua_interface)
  1829. return 0;
  1830. Spawn* spawn = lua_interface->GetSpawn(state);
  1831. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1832. lua_interface->ResetFunctionStack(state);
  1833. if (spawn && spawn->IsEntity() && value > 0)
  1834. ((Entity*)spawn)->SetTotalHPBase(value);
  1835. return 0;
  1836. }
  1837. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1838. if (!lua_interface)
  1839. return 0;
  1840. Spawn* spawn = lua_interface->GetSpawn(state);
  1841. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1842. lua_interface->ResetFunctionStack(state);
  1843. if (spawn && value > 0) {
  1844. spawn->SetPower(value);
  1845. if (value > spawn->GetTotalPowerBase())
  1846. spawn->SetTotalPower(value);
  1847. }
  1848. return 0;
  1849. }
  1850. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1851. if (!lua_interface)
  1852. return 0;
  1853. Spawn* spawn = lua_interface->GetSpawn(state);
  1854. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1855. lua_interface->ResetFunctionStack(state);
  1856. if (spawn && spawn->IsEntity() && value > 0)
  1857. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1858. return 0;
  1859. }
  1860. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1861. if (!lua_interface)
  1862. return 0;
  1863. Spawn* spawn = lua_interface->GetSpawn(state);
  1864. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1865. lua_interface->ResetFunctionStack(state);
  1866. if (spawn && spawn->IsEntity() && value > 0)
  1867. ((Entity*)spawn)->SetTotalPowerBase(value);
  1868. return 0;
  1869. }
  1870. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1871. if (!lua_interface)
  1872. return 0;
  1873. Spawn* spawn = lua_interface->GetSpawn(state);
  1874. float x = lua_interface->GetFloatValue(state, 2);
  1875. float y = lua_interface->GetFloatValue(state, 3);
  1876. float z = lua_interface->GetFloatValue(state, 4);
  1877. float heading = lua_interface->GetFloatValue(state, 5);
  1878. lua_interface->ResetFunctionStack(state);
  1879. if (spawn) {
  1880. spawn->SetX(x);
  1881. spawn->SetY(y);
  1882. spawn->SetZ(z);
  1883. if (heading != 0)
  1884. spawn->SetHeading(heading);
  1885. spawn->SetSpawnOrigX(spawn->GetX());
  1886. spawn->SetSpawnOrigY(spawn->GetY());
  1887. spawn->SetSpawnOrigZ(spawn->GetZ());
  1888. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1889. if (spawn->IsPlayer()) {
  1890. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1891. if (client) {
  1892. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1893. client->QueuePacket(packet);
  1894. }
  1895. }
  1896. }
  1897. return 0;
  1898. }
  1899. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1900. if (!lua_interface)
  1901. return 0;
  1902. Spawn* spawn = lua_interface->GetSpawn(state);
  1903. float value = lua_interface->GetFloatValue(state, 2);
  1904. lua_interface->ResetFunctionStack(state);
  1905. if (spawn) {
  1906. spawn->SetHeading(value);
  1907. if (spawn->IsPlayer()) {
  1908. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1909. if (client) {
  1910. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1911. client->QueuePacket(packet);
  1912. }
  1913. }
  1914. }
  1915. return 0;
  1916. }
  1917. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1918. if (!lua_interface)
  1919. return 0;
  1920. Spawn* spawn = lua_interface->GetSpawn(state);
  1921. int16 value = lua_interface->GetInt16Value(state, 2);
  1922. lua_interface->ResetFunctionStack(state);
  1923. if (spawn)
  1924. spawn->SetModelType(value);
  1925. return 0;
  1926. }
  1927. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1928. if (!lua_interface)
  1929. return 0;
  1930. Spawn* spawn = lua_interface->GetSpawn(state);
  1931. int8 value = lua_interface->GetInt8Value(state, 2);
  1932. lua_interface->ResetFunctionStack(state);
  1933. if (spawn) {
  1934. if (spawn->IsPlayer())
  1935. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1936. else
  1937. spawn->SetAdventureClass(value);
  1938. }
  1939. return 0;
  1940. }
  1941. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1942. if (!lua_interface)
  1943. return 0;
  1944. Spawn* spawn = lua_interface->GetSpawn(state);
  1945. int8 value = lua_interface->GetInt8Value(state, 2);
  1946. lua_interface->ResetFunctionStack(state);
  1947. if (spawn) {
  1948. spawn->SetTradeskillClass(value);
  1949. if (spawn->IsEntity()) {
  1950. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1951. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1952. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1953. }
  1954. if (spawn->IsPlayer())
  1955. ((Player*)spawn)->SetCharSheetChanged(true);
  1956. }
  1957. return 0;
  1958. }
  1959. int EQ2Emu_lua_SetMount(lua_State* state) {
  1960. if (!lua_interface)
  1961. return 0;
  1962. Spawn* spawn = lua_interface->GetSpawn(state);
  1963. int16 value = lua_interface->GetInt16Value(state, 2);
  1964. if (spawn && spawn->IsEntity()) {
  1965. ((Entity*)spawn)->SetMount(value);
  1966. EQ2_Color color;
  1967. color.red = 255;
  1968. color.green = 255;
  1969. color.blue = 255;
  1970. ((Entity*)spawn)->SetMountColor(&color);
  1971. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1972. }
  1973. return 0;
  1974. }
  1975. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1976. if (!lua_interface)
  1977. return 0;
  1978. Spawn* spawn = lua_interface->GetSpawn(state);
  1979. EQ2_Color mount_color;
  1980. EQ2_Color saddle_color;
  1981. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1982. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1983. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1984. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1985. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1986. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1987. if (spawn && spawn->IsEntity()) {
  1988. ((Entity*)spawn)->SetMountColor(&mount_color);
  1989. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1990. }
  1991. return 0;
  1992. }
  1993. int EQ2Emu_lua_GetMount(lua_State* state) {
  1994. if (!lua_interface)
  1995. return 0;
  1996. Spawn* spawn = lua_interface->GetSpawn(state);
  1997. if (spawn && spawn->IsEntity()) {
  1998. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1999. return 1;
  2000. }
  2001. return 0;
  2002. }
  2003. int EQ2Emu_lua_GetRace(lua_State* state) {
  2004. if (!lua_interface)
  2005. return 0;
  2006. Spawn* spawn = lua_interface->GetSpawn(state);
  2007. if (spawn)
  2008. {
  2009. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2010. lua_interface->SetInt32Value(state, spawn->GetRace());
  2011. return 1;
  2012. }
  2013. return 0;
  2014. }
  2015. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2016. if (!lua_interface)
  2017. return 0;
  2018. Spawn* spawn = lua_interface->GetSpawn(state);
  2019. if (spawn) {
  2020. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2021. return 1;
  2022. }
  2023. return 0;
  2024. }
  2025. int EQ2Emu_lua_GetClass(lua_State* state) {
  2026. Spawn* spawn = lua_interface->GetSpawn(state);
  2027. if (spawn) {
  2028. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2029. return 1;
  2030. }
  2031. return 0;
  2032. }
  2033. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2034. Spawn* spawn = lua_interface->GetSpawn(state);
  2035. if (spawn) {
  2036. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2037. return 1;
  2038. }
  2039. return 0;
  2040. }
  2041. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2042. if (!lua_interface)
  2043. return 0;
  2044. Spawn* spawn = lua_interface->GetSpawn(state);
  2045. float value = lua_interface->GetFloatValue(state, 2);
  2046. lua_interface->ResetFunctionStack(state);
  2047. if (spawn) {
  2048. spawn->SetSpeed(value);
  2049. if(spawn->IsEntity())
  2050. ((Entity*)spawn)->SetSpeed(value);
  2051. if (spawn->IsPlayer()) {
  2052. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2053. if (client) {
  2054. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2055. if (packet) {
  2056. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2057. packet->setDataByName("speed", value);
  2058. packet->setDataByName("size", 0.51);
  2059. EQ2Packet* app = packet->serialize();
  2060. client->QueuePacket(app);
  2061. safe_delete(packet);
  2062. }
  2063. }
  2064. }
  2065. }
  2066. return 0;
  2067. }
  2068. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2069. if (!lua_interface)
  2070. return 0;
  2071. Spawn* spawn = lua_interface->GetSpawn(state);
  2072. const int16 type = lua_interface->GetInt16Value(state, 2);
  2073. const float value = lua_interface->GetFloatValue(state, 3);
  2074. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2075. int64 class_req = 0;
  2076. int32 class_id = 0;
  2077. vector<int16> faction_req;
  2078. vector<int16> race_req;
  2079. int32 i = 0;
  2080. int8 f = 0;
  2081. int8 r = 0;
  2082. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2083. if (class_id < 100) {
  2084. class_req += pow(2.0, double(class_id - 1));
  2085. }
  2086. else if (class_id > 100 && class_id < 1000) {
  2087. race_req.push_back(class_id);
  2088. r++;
  2089. }
  2090. else {
  2091. faction_req.push_back(class_id);
  2092. f++;
  2093. }
  2094. i++;
  2095. }
  2096. if (value != 0 && type >= 0) {
  2097. if (luaspell && luaspell->spell && luaspell->caster) {
  2098. ZoneServer* zone = luaspell->caster->GetZone();
  2099. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2100. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2101. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2102. if (target) {
  2103. if (target->IsPlayer()) {
  2104. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2105. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2106. if (((Player*)target)->GetGroupMemberInfo())
  2107. ((Player*)target)->UpdateGroupMemberInfo();
  2108. ((Player*)target)->SetCharSheetChanged(true);
  2109. }
  2110. else if (target->IsNPC())
  2111. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2112. else
  2113. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2114. }
  2115. }
  2116. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2117. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2118. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2119. }
  2120. else if (spawn && spawn->IsEntity()) {
  2121. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2122. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2123. if (spawn->IsPlayer())
  2124. ((Player*)spawn)->SetCharSheetChanged(true);
  2125. }
  2126. else
  2127. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2128. }
  2129. else
  2130. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2131. return 0;
  2132. }
  2133. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2134. if (!lua_interface)
  2135. return 0;
  2136. Spawn* spawn = lua_interface->GetSpawn(state);
  2137. int16 type = lua_interface->GetInt16Value(state, 2);
  2138. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2139. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2140. if (!spawn) {
  2141. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2142. return 0;
  2143. }
  2144. if (!spawn->IsEntity()) {
  2145. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2146. return 0;
  2147. }
  2148. if (value == 0) {
  2149. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2150. return 0;
  2151. }
  2152. if (!luaspell || !luaspell->spell) {
  2153. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2154. return 0;
  2155. }
  2156. int32 class_req = 0;
  2157. vector<int16> faction_req;
  2158. vector<int16> race_req;
  2159. int32 class_id = 0;
  2160. int32 i = 0;
  2161. int8 f = 0;
  2162. int8 r = 0;
  2163. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2164. if (class_id < 100) {
  2165. class_req += pow(2.0, double(class_id - 1));
  2166. }
  2167. else if (class_id > 100 && class_id < 1000) {
  2168. race_req.push_back(class_id);
  2169. r++;
  2170. }
  2171. else {
  2172. faction_req.push_back(class_id);
  2173. f++;
  2174. }
  2175. i++;
  2176. }
  2177. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2178. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2179. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2180. if (spawn->IsPlayer())
  2181. ((Player*)spawn)->SetCharSheetChanged(true);
  2182. return 0;
  2183. }
  2184. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2185. if (!lua_interface)
  2186. return 0;
  2187. Spawn* spawn = lua_interface->GetSpawn(state);
  2188. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2189. if (!spawn) {
  2190. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2191. return 0;
  2192. }
  2193. if (!spawn->IsEntity()) {
  2194. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2195. return 0;
  2196. }
  2197. if (!luaspell || !luaspell->spell) {
  2198. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2199. return 0;
  2200. }
  2201. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2202. if (spawn->IsPlayer())
  2203. ((Player*)spawn)->SetCharSheetChanged(true);
  2204. return 0;
  2205. }
  2206. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2207. if (!lua_interface)
  2208. return 0;
  2209. Spawn* spawn = lua_interface->GetSpawn(state);
  2210. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2211. if (luaspell && luaspell->spell) {
  2212. ZoneServer* zone = luaspell->caster->GetZone();
  2213. Spawn* target = 0;
  2214. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2215. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2216. target = zone->GetSpawnByID(luaspell->targets[i]);
  2217. if (target && target->IsEntity()) {
  2218. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2219. if (target->IsPlayer())
  2220. ((Player*)target)->SetCharSheetChanged(true);
  2221. }
  2222. }
  2223. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2224. }
  2225. else if (spawn && spawn->IsEntity()) {
  2226. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2227. if (spawn->IsPlayer())
  2228. ((Player*)spawn)->SetCharSheetChanged(true);
  2229. }
  2230. return 0;
  2231. }
  2232. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2233. if (!lua_interface)
  2234. return 0;
  2235. Spawn* spawn = lua_interface->GetSpawn(state);
  2236. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2237. float value = lua_interface->GetFloatValue(state, 3);
  2238. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2239. if (value != 0) {
  2240. int32 spell_id = 0;
  2241. if (luaspell && luaspell->spell && luaspell->caster) {
  2242. spell_id = luaspell->spell->GetSpellID();
  2243. ZoneServer* zone = luaspell->caster->GetZone();
  2244. Spawn* target = 0;
  2245. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2246. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2247. target = zone->GetSpawnByID(luaspell->targets[i]);
  2248. if (target && target->Alive()) {
  2249. if (target->IsPlayer()) {
  2250. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2251. Client* client = target->GetZone()->GetClientBySpawn(target);
  2252. if (client) {
  2253. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2254. if (packet)
  2255. client->QueuePacket(packet);
  2256. }
  2257. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2258. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2259. }
  2260. else if (target->IsNPC()) {
  2261. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2262. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2263. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2264. }
  2265. else
  2266. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2267. }
  2268. }
  2269. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2270. }
  2271. else if (spawn) {
  2272. if (spawn->IsPlayer()) {
  2273. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2274. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2275. if (client) {
  2276. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2277. if (packet)
  2278. client->QueuePacket(packet);
  2279. }
  2280. }
  2281. else if (spawn->IsNPC())
  2282. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2283. else
  2284. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2285. }
  2286. }
  2287. else
  2288. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2289. return 0;
  2290. }
  2291. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2292. if (!lua_interface)
  2293. return 0;
  2294. Spawn* spawn = lua_interface->GetSpawn(state);
  2295. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2296. if (spawn && spawn->IsPlayer()) {
  2297. int32 spell_id = 0;
  2298. if (luaspell && luaspell->spell) {
  2299. spell_id = luaspell->spell->GetSpellID();
  2300. ZoneServer* zone = luaspell->caster->GetZone();
  2301. Spawn* target = 0;
  2302. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2303. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2304. target = zone->GetSpawnByID(luaspell->targets[i]);
  2305. if (target) {
  2306. if (target->IsPlayer()) {
  2307. ((Player*)target)->RemoveSkillBonus(spell_id);
  2308. Client* client = target->GetZone()->GetClientBySpawn(target);
  2309. if (client) {
  2310. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2311. if (packet)
  2312. client->QueuePacket(packet);
  2313. }
  2314. }
  2315. else if (target->IsNPC())
  2316. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2317. else
  2318. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2319. }
  2320. }
  2321. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2322. }
  2323. else if (spawn) {
  2324. if (spawn->IsPlayer()) {
  2325. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2326. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2327. if (client) {
  2328. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2329. if (packet)
  2330. client->QueuePacket(packet);
  2331. }
  2332. }
  2333. else if (spawn->IsNPC())
  2334. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2335. else
  2336. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2337. }
  2338. }
  2339. return 0;
  2340. }
  2341. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2342. if (!lua_interface)
  2343. return 0;
  2344. Spawn* spawn = lua_interface->GetSpawn(state);
  2345. int8 type = lua_interface->GetInt32Value(state, 2);
  2346. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2347. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2348. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2349. ZoneServer* zone = luaspell->caster->GetZone();
  2350. Spawn* target = 0;
  2351. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2352. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2353. target = zone->GetSpawnByID(luaspell->targets[i]);
  2354. if (target && target->IsEntity()) {
  2355. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2356. ((Entity*)target)->AddMezSpell(luaspell);
  2357. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2358. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2359. if (target->IsNPC())
  2360. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2361. }
  2362. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2363. ((Entity*)target)->AddStifleSpell(luaspell);
  2364. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2365. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2366. if (target->IsNPC())
  2367. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2368. }
  2369. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2370. ((Entity*)target)->AddDazeSpell(luaspell);
  2371. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2372. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2373. if (target->IsNPC())
  2374. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2375. }
  2376. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2377. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2378. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2379. ((Entity*)target)->AddStunSpell(luaspell);
  2380. if (target->IsNPC())
  2381. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2382. }
  2383. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2384. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2385. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2386. ((Entity*)target)->AddRootSpell(luaspell);
  2387. if (target->IsNPC())
  2388. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2389. }
  2390. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2391. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2392. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2393. ((Entity*)target)->AddFearSpell(luaspell);
  2394. if (target->IsNPC())
  2395. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2396. }
  2397. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2398. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2399. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2400. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2401. }
  2402. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2403. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2404. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2405. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2406. }
  2407. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2408. ((Entity*)target)->AddSnareSpell(luaspell);
  2409. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2410. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2411. if (target->IsNPC())
  2412. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2413. }
  2414. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2415. ((Entity*)target)->AddFlightSpell(luaspell);
  2416. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2417. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2418. }
  2419. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2420. ((Entity*)target)->AddGlideSpell(luaspell);
  2421. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2422. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2423. }
  2424. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2425. ((Entity*)target)->AddSafefallSpell(luaspell);
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2428. }
  2429. else
  2430. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2431. }
  2432. else
  2433. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2434. }
  2435. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2436. }
  2437. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2438. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2439. ((Entity*)spawn)->AddMezSpell(luaspell);
  2440. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2441. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2442. }
  2443. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2444. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2445. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2446. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2447. }
  2448. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2449. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2450. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2451. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2452. }
  2453. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2454. ((Entity*)spawn)->AddStunSpell(luaspell);
  2455. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2456. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2457. }
  2458. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2459. ((Entity*)spawn)->AddRootSpell(luaspell);
  2460. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2461. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2462. }
  2463. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2464. ((Entity*)spawn)->AddFearSpell(luaspell);
  2465. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2466. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2467. }
  2468. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2469. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2470. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2471. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2472. }
  2473. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2474. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2475. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2476. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2477. }
  2478. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2479. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2480. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2481. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2482. }
  2483. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2484. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2485. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2486. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2487. }
  2488. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2489. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2490. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2491. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2492. }
  2493. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2494. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2495. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2496. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2497. }
  2498. else
  2499. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2500. }
  2501. else
  2502. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2503. return 0;
  2504. }
  2505. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2506. if (!lua_interface)
  2507. return 0;
  2508. Spawn* spawn = lua_interface->GetSpawn(state);
  2509. int8 type = lua_interface->GetInt8Value(state, 2);
  2510. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2511. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2512. if (spawn && spawn->IsEntity()) {
  2513. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2514. ZoneServer* zone = luaspell->caster->GetZone();
  2515. Spawn* target = 0;
  2516. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2517. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2518. target = zone->GetSpawnByID(luaspell->targets[i]);
  2519. if (target) {
  2520. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2521. ((Entity*)target)->RemoveMezSpell(luaspell);
  2522. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2523. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2524. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2525. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2526. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2527. ((Entity*)target)->RemoveStunSpell(luaspell);
  2528. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2529. ((Entity*)target)->RemoveRootSpell(luaspell);
  2530. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2531. ((Entity*)target)->RemoveFearSpell(luaspell);
  2532. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2533. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2534. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2535. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2536. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2537. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2538. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2539. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2540. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2541. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2542. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2543. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2544. else
  2545. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2546. }
  2547. }
  2548. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2549. }
  2550. else if (only_remove_spawn) {
  2551. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2552. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2553. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2554. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2555. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2556. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2557. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2558. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2559. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2560. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2561. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2562. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2563. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2564. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2565. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2566. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2567. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2568. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2569. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2570. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2571. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2572. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2573. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2574. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2575. else
  2576. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2577. }
  2578. }
  2579. return 0;
  2580. }
  2581. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2582. if (!lua_interface)
  2583. return 0;
  2584. Spawn* spawn = lua_interface->GetSpawn(state);
  2585. int8 type = lua_interface->GetInt8Value(state, 2);
  2586. bool hasEffect = false;
  2587. if (!spawn)
  2588. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2589. else if (!spawn->IsEntity())
  2590. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2591. else if (type < CONTROL_MAX_EFFECTS)
  2592. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2593. else
  2594. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2595. lua_interface->SetBooleanValue(state, hasEffect);
  2596. return 1;
  2597. }
  2598. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2599. if (!lua_interface)
  2600. return 0;
  2601. Spawn* spawn = lua_interface->GetSpawn(state);
  2602. float distance = 0.0f;
  2603. if (!spawn)
  2604. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2605. else if (!spawn->IsNPC())
  2606. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2607. else
  2608. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2609. lua_interface->SetFloatValue(state, distance);
  2610. return 1;
  2611. }
  2612. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2613. if (!lua_interface)
  2614. return 0;
  2615. Spawn* spawn = lua_interface->GetSpawn(state);
  2616. float distance = 0.0f;
  2617. if (!spawn)
  2618. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2619. else if (!spawn->IsNPC())
  2620. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2621. else
  2622. distance = ((NPC*)spawn)->GetAggroRadius();
  2623. lua_interface->SetFloatValue(state, distance);
  2624. return 1;
  2625. }
  2626. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2627. if (!lua_interface)
  2628. return 0;
  2629. Spawn* spawn = lua_interface->GetSpawn(state);
  2630. float distance = lua_interface->GetFloatValue(state, 2);
  2631. bool override = lua_interface->GetBooleanValue(state, 3);
  2632. bool result = false;
  2633. lua_interface->ResetFunctionStack(state);
  2634. if (!spawn)
  2635. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2636. else if (!spawn->IsNPC())
  2637. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2638. else
  2639. {
  2640. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2641. result = true;
  2642. }
  2643. lua_interface->SetBooleanValue(state, result);
  2644. return 1;
  2645. }
  2646. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2647. if (!lua_interface)
  2648. return 0;
  2649. Spawn* spawn = lua_interface->GetSpawn(state);
  2650. int16 value = lua_interface->GetInt16Value(state, 2);
  2651. if (spawn && spawn->IsEntity()) {
  2652. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2653. if (spawn->IsPlayer())
  2654. ((Player*)spawn)->SetCharSheetChanged(true);
  2655. }
  2656. return 0;
  2657. }
  2658. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2659. if (!lua_interface)
  2660. return 0;
  2661. Spawn* spawn = lua_interface->GetSpawn(state);
  2662. int16 value = lua_interface->GetInt16Value(state, 2);
  2663. if (spawn && spawn->IsEntity()) {
  2664. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2665. if (spawn->IsPlayer())
  2666. ((Player*)spawn)->SetCharSheetChanged(true);
  2667. }
  2668. return 0;
  2669. }
  2670. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2671. if (!lua_interface)
  2672. return 0;
  2673. Spawn* spawn = lua_interface->GetSpawn(state);
  2674. int16 value = lua_interface->GetInt16Value(state, 2);
  2675. if (spawn && spawn->IsEntity()) {
  2676. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2677. if (spawn->IsPlayer())
  2678. ((Player*)spawn)->SetCharSheetChanged(true);
  2679. }
  2680. return 0;
  2681. }
  2682. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2683. if (!lua_interface)
  2684. return 0;
  2685. Spawn* spawn = lua_interface->GetSpawn(state);
  2686. int16 value = lua_interface->GetInt16Value(state, 2);
  2687. if (spawn && spawn->IsEntity()) {
  2688. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2689. if (spawn->IsPlayer())
  2690. ((Player*)spawn)->SetCharSheetChanged(true);
  2691. }
  2692. return 0;
  2693. }
  2694. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2695. if (!lua_interface)
  2696. return 0;
  2697. Spawn* spawn = lua_interface->GetSpawn(state);
  2698. int16 value = lua_interface->GetInt16Value(state, 2);
  2699. if (spawn && spawn->IsEntity()) {
  2700. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2701. if (spawn->IsPlayer())
  2702. ((Player*)spawn)->SetCharSheetChanged(true);
  2703. }
  2704. return 0;
  2705. }
  2706. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2707. if (!lua_interface)
  2708. return 0;
  2709. Spawn* spawn = lua_interface->GetSpawn(state);
  2710. int8 value = lua_interface->GetInt8Value(state, 2);
  2711. if (spawn && spawn->IsEntity()) {
  2712. ((Entity*)spawn)->SetDeity(value);
  2713. if (spawn->IsPlayer())
  2714. ((Player*)spawn)->SetCharSheetChanged(true);
  2715. }
  2716. lua_interface->ResetFunctionStack(state);
  2717. return 0;
  2718. }
  2719. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2720. if (!lua_interface)
  2721. return 0;
  2722. Spawn* spawn = lua_interface->GetSpawn(state);
  2723. if (spawn && spawn->IsEntity()) {
  2724. int8 deity = ((Entity*)spawn)->GetDeity();
  2725. lua_interface->SetInt32Value(state, deity);
  2726. return 1;
  2727. }
  2728. return 0;
  2729. }
  2730. int EQ2Emu_lua_SetInt(lua_State* state) {
  2731. if (!lua_interface)
  2732. return 0;
  2733. Spawn* spawn = lua_interface->GetSpawn(state);
  2734. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2735. if (spawn && spawn->IsEntity()) {
  2736. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2737. if (spawn->IsPlayer())
  2738. ((Player*)spawn)->SetCharSheetChanged(true);
  2739. }
  2740. return 0;
  2741. }
  2742. int EQ2Emu_lua_SetWis(lua_State* state) {
  2743. if (!lua_interface)
  2744. return 0;
  2745. Spawn* spawn = lua_interface->GetSpawn(state);
  2746. float value = lua_interface->GetFloatValue(state, 2);
  2747. if (spawn && spawn->IsEntity()) {
  2748. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2749. if (spawn->IsPlayer())
  2750. ((Player*)spawn)->SetCharSheetChanged(true);
  2751. }
  2752. return 0;
  2753. }
  2754. int EQ2Emu_lua_SetSta(lua_State* state) {
  2755. if (!lua_interface)
  2756. return 0;
  2757. Spawn* spawn = lua_interface->GetSpawn(state);
  2758. float value = lua_interface->GetFloatValue(state, 2);
  2759. if (spawn && spawn->IsEntity()) {
  2760. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2761. if (spawn->IsPlayer())
  2762. ((Player*)spawn)->SetCharSheetChanged(true);
  2763. }
  2764. return 0;
  2765. }
  2766. int EQ2Emu_lua_SetStr(lua_State* state) {
  2767. if (!lua_interface)
  2768. return 0;
  2769. Spawn* spawn = lua_interface->GetSpawn(state);
  2770. float value = lua_interface->GetFloatValue(state, 2);
  2771. if (spawn && spawn->IsEntity()) {
  2772. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2773. if (spawn->IsPlayer())
  2774. ((Player*)spawn)->SetCharSheetChanged(true);
  2775. }
  2776. return 0;
  2777. }
  2778. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2779. if (!lua_interface)
  2780. return 0;
  2781. Spawn* spawn = lua_interface->GetSpawn(state);
  2782. float value = lua_interface->GetFloatValue(state, 2);
  2783. if (spawn && spawn->IsEntity()) {
  2784. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2785. if (spawn->IsPlayer())
  2786. ((Player*)spawn)->SetCharSheetChanged(true);
  2787. }
  2788. return 0;
  2789. }
  2790. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2791. if (!lua_interface)
  2792. return 0;
  2793. Spawn* spawn = lua_interface->GetSpawn(state);
  2794. if (spawn) {
  2795. lua_interface->SetInt32Value(state, spawn->GetHP());
  2796. return 1;
  2797. }
  2798. return 0;
  2799. }
  2800. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2801. if (!lua_interface)
  2802. return 0;
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. if (spawn) {
  2805. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2806. return 1;
  2807. }
  2808. return 0;
  2809. }
  2810. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2811. if (!lua_interface)
  2812. return 0;
  2813. Spawn* spawn = lua_interface->GetSpawn(state);
  2814. if (spawn) {
  2815. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2816. return 1;
  2817. }
  2818. return 0;
  2819. }
  2820. int EQ2Emu_lua_GetName(lua_State* state) {
  2821. if (!lua_interface)
  2822. return 0;
  2823. Spawn* spawn = lua_interface->GetSpawn(state);
  2824. if (spawn) {
  2825. lua_interface->SetStringValue(state, spawn->GetName());
  2826. return 1;
  2827. }
  2828. return 0;
  2829. }
  2830. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2831. Spawn* spawn = lua_interface->GetSpawn(state);
  2832. if (spawn) {
  2833. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2834. return 1;
  2835. }
  2836. return 0;
  2837. }
  2838. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2839. if (!lua_interface)
  2840. return 0;
  2841. Spawn* spawn = lua_interface->GetSpawn(state);
  2842. if (spawn) {
  2843. lua_interface->SetInt32Value(state, spawn->GetPower());
  2844. return 1;
  2845. }
  2846. return 0;
  2847. }
  2848. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2849. if (!lua_interface)
  2850. return 0;
  2851. Spawn* spawn = lua_interface->GetSpawn(state);
  2852. if (spawn) {
  2853. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2854. return 1;
  2855. }
  2856. return 0;
  2857. }
  2858. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2859. if (!lua_interface)
  2860. return 0;
  2861. Spawn* spawn = lua_interface->GetSpawn(state);
  2862. if (spawn) {
  2863. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2864. return 1;
  2865. }
  2866. return 0;
  2867. }
  2868. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2869. if (!lua_interface)
  2870. return 0;
  2871. Spawn* spawn = lua_interface->GetSpawn(state);
  2872. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2873. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2874. if (spawn && spawn2) {
  2875. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2876. lua_interface->SetFloatValue(state, distance);
  2877. return 1;
  2878. }
  2879. return 0;
  2880. }
  2881. int EQ2Emu_lua_GetX(lua_State* state) {
  2882. if (!lua_interface)
  2883. return 0;
  2884. Spawn* spawn = lua_interface->GetSpawn(state);
  2885. if (spawn) {
  2886. lua_interface->SetFloatValue(state, spawn->GetX());
  2887. return 1;
  2888. }
  2889. return 0;
  2890. }
  2891. int EQ2Emu_lua_GetY(lua_State* state) {
  2892. if (!lua_interface)
  2893. return 0;
  2894. Spawn* spawn = lua_interface->GetSpawn(state);
  2895. if (spawn) {
  2896. lua_interface->SetFloatValue(state, spawn->GetY());
  2897. return 1;
  2898. }
  2899. return 0;
  2900. }
  2901. int EQ2Emu_lua_GetZ(lua_State* state) {
  2902. if (!lua_interface)
  2903. return 0;
  2904. Spawn* spawn = lua_interface->GetSpawn(state);
  2905. if (spawn) {
  2906. lua_interface->SetFloatValue(state, spawn->GetZ());
  2907. return 1;
  2908. }
  2909. return 0;
  2910. }
  2911. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2912. if (!lua_interface)
  2913. return 0;
  2914. Spawn* spawn = lua_interface->GetSpawn(state);
  2915. if (spawn) {
  2916. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2917. return 1;
  2918. }
  2919. return 0;
  2920. }
  2921. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2922. if (!lua_interface)
  2923. return 0;
  2924. Spawn* spawn = lua_interface->GetSpawn(state);
  2925. if (spawn) {
  2926. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2927. return 1;
  2928. }
  2929. return 0;
  2930. }
  2931. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2932. if (!lua_interface)
  2933. return 0;
  2934. Spawn* spawn = lua_interface->GetSpawn(state);
  2935. if (spawn) {
  2936. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2937. return 1;
  2938. }
  2939. return 0;
  2940. }
  2941. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2942. if (!lua_interface)
  2943. return 0;
  2944. Spawn* spawn = lua_interface->GetSpawn(state);
  2945. if (spawn && spawn->IsEntity()) {
  2946. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2947. return 1;
  2948. }
  2949. return 0;
  2950. }
  2951. int EQ2Emu_lua_GetInt(lua_State* state) {
  2952. if (!lua_interface)
  2953. return 0;
  2954. Spawn* spawn = lua_interface->GetSpawn(state);
  2955. if (spawn && spawn->IsEntity()) {
  2956. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2957. return 1;
  2958. }
  2959. return 0;
  2960. }
  2961. int EQ2Emu_lua_GetWis(lua_State* state) {
  2962. if (!lua_interface)
  2963. return 0;
  2964. Spawn* spawn = lua_interface->GetSpawn(state);
  2965. if (spawn && spawn->IsEntity()) {
  2966. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2967. return 1;
  2968. }
  2969. return 0;
  2970. }
  2971. int EQ2Emu_lua_GetSta(lua_State* state) {
  2972. if (!lua_interface)
  2973. return 0;
  2974. Spawn* spawn = lua_interface->GetSpawn(state);
  2975. if (spawn && spawn->IsEntity()) {
  2976. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2977. return 1;
  2978. }
  2979. return 0;
  2980. }
  2981. int EQ2Emu_lua_GetStr(lua_State* state) {
  2982. if (!lua_interface)
  2983. return 0;
  2984. Spawn* spawn = lua_interface->GetSpawn(state);
  2985. if (spawn && spawn->IsEntity()) {
  2986. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2987. return 1;
  2988. }
  2989. return 0;
  2990. }
  2991. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2992. if (!lua_interface)
  2993. return 0;
  2994. Spawn* spawn = lua_interface->GetSpawn(state);
  2995. if (spawn && spawn->IsEntity()) {
  2996. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2997. return 1;
  2998. }
  2999. return 0;
  3000. }
  3001. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3002. if (!lua_interface)
  3003. return 0;
  3004. Spawn* spawn = lua_interface->GetSpawn(state);
  3005. if (spawn && spawn->IsEntity()) {
  3006. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3007. return 1;
  3008. }
  3009. return 0;
  3010. }
  3011. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3012. if (!lua_interface)
  3013. return 0;
  3014. Spawn* spawn = lua_interface->GetSpawn(state);
  3015. if (spawn && spawn->IsEntity()) {
  3016. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3017. return 1;
  3018. }
  3019. return 0;
  3020. }
  3021. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3022. if (!lua_interface)
  3023. return 0;
  3024. Spawn* spawn = lua_interface->GetSpawn(state);
  3025. if (spawn && spawn->IsEntity()) {
  3026. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3027. return 1;
  3028. }
  3029. return 0;
  3030. }
  3031. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3032. if (!lua_interface)
  3033. return 0;
  3034. Spawn* spawn = lua_interface->GetSpawn(state);
  3035. if (spawn && spawn->IsEntity()) {
  3036. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3037. return 1;
  3038. }
  3039. return 0;
  3040. }
  3041. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3042. if (!lua_interface)
  3043. return 0;
  3044. Spawn* spawn = lua_interface->GetSpawn(state);
  3045. if (spawn && spawn->IsEntity()) {
  3046. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3047. return 1;
  3048. }
  3049. return 0;
  3050. }
  3051. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3052. if (!lua_interface)
  3053. return 0;
  3054. Spawn* player = lua_interface->GetSpawn(state);
  3055. if (!player || !player->IsPlayer()) {
  3056. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3057. return 0;
  3058. }
  3059. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3060. if (quest_id <= 0) {
  3061. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3062. return 0;
  3063. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3064. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3065. return 0;
  3066. }
  3067. int32 step = lua_interface->GetInt32Value(state, 3);
  3068. if (step > 0) {
  3069. Client* client = player->GetZone()->GetClientBySpawn(player);
  3070. if (client)
  3071. client->AddPendingQuestUpdate(quest_id, step);
  3072. } else {
  3073. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3074. }
  3075. return 0;
  3076. }
  3077. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3078. Spawn* player = lua_interface->GetSpawn(state);
  3079. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3080. int32 step = lua_interface->GetInt32Value(state, 3);
  3081. int32 progress = lua_interface->GetInt32Value(state, 4);
  3082. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3083. Client* client = player->GetZone()->GetClientBySpawn(player);
  3084. if (client)
  3085. client->AddPendingQuestUpdate(quest_id, step, progress);
  3086. }
  3087. return 0;
  3088. }
  3089. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3090. if (!lua_interface)
  3091. return 0;
  3092. Spawn* player = lua_interface->GetSpawn(state);
  3093. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3094. if (player && player->IsPlayer() && quest_id > 0) {
  3095. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3096. return 1;
  3097. }
  3098. return 0;
  3099. }
  3100. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3101. if (!lua_interface)
  3102. return 0;
  3103. Spawn* player = lua_interface->GetSpawn(state);
  3104. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3105. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3106. if (player && player->IsPlayer() && quest_id > 0) {
  3107. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3108. return 1;
  3109. }
  3110. return 0;
  3111. }
  3112. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3113. if (!lua_interface)
  3114. return 0;
  3115. Spawn* player = lua_interface->GetSpawn(state);
  3116. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3117. if (player && player->IsPlayer() && quest_id > 0) {
  3118. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3119. return 1;
  3120. }
  3121. return 0;
  3122. }
  3123. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3124. if (!lua_interface)
  3125. return 0;
  3126. Quest* quest = lua_interface->GetQuest(state);
  3127. string name = lua_interface->GetStringValue(state, 2);
  3128. string type = lua_interface->GetStringValue(state, 3);
  3129. string zone = lua_interface->GetStringValue(state, 4);
  3130. int16 level = lua_interface->GetInt16Value(state, 5);
  3131. string description = lua_interface->GetStringValue(state, 6);
  3132. bool load = true;
  3133. if (!quest) {
  3134. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3135. load = false;
  3136. }
  3137. if (load && name.length() == 0) {
  3138. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3139. load = false;
  3140. }
  3141. if (load && type.length() == 0) {
  3142. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3143. load = false;
  3144. }
  3145. if (load && zone.length() == 0) {
  3146. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3147. load = false;
  3148. }
  3149. if (load && description.length() == 0) {
  3150. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3151. load = false;
  3152. }
  3153. if (load && level == 0) {
  3154. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3155. load = false;
  3156. }
  3157. if (load)
  3158. quest->RegisterQuest(name, type, zone, level, description);
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Quest* quest = lua_interface->GetQuest(state);
  3165. if (quest) {
  3166. int8 level = lua_interface->GetInt16Value(state, 2);
  3167. quest->SetPrereqLevel(level);
  3168. }
  3169. return 0;
  3170. }
  3171. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3172. if (!lua_interface)
  3173. return 0;
  3174. Quest* quest = lua_interface->GetQuest(state);
  3175. if (quest) {
  3176. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3177. quest->AddPrereqQuest(quest_id);
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Quest* quest = lua_interface->GetQuest(state);
  3185. if (quest) {
  3186. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3187. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3188. if (quantity == 0)
  3189. quantity = 1;
  3190. Item* master_item = master_item_list.GetItem(item_id);
  3191. if (master_item) {
  3192. Item* item = new Item(master_item);
  3193. item->details.count = quantity;
  3194. quest->AddPrereqItem(item);
  3195. }
  3196. }
  3197. return 0;
  3198. }
  3199. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3200. if (!lua_interface)
  3201. return 0;
  3202. Spawn* player = lua_interface->GetSpawn(state);
  3203. if(!player || !player->IsPlayer()) {
  3204. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3205. return 0;
  3206. }
  3207. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3208. if (quest_id > 0) {
  3209. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3210. return 1;
  3211. } else {
  3212. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3213. }
  3214. return 0;
  3215. }
  3216. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3217. if (!lua_interface)
  3218. return 0;
  3219. Quest* quest = lua_interface->GetQuest(state);
  3220. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3221. lua_interface->ResetFunctionStack(state);
  3222. if (quest && spawn_id > 0)
  3223. quest->SetQuestReturnNPC(spawn_id);
  3224. return 0;
  3225. }
  3226. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3227. if (!lua_interface)
  3228. return 0;
  3229. Spawn* spawn = lua_interface->GetSpawn(state);
  3230. int32 time = lua_interface->GetInt32Value(state, 2);
  3231. string function = lua_interface->GetStringValue(state, 3);
  3232. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3233. Spawn* player = lua_interface->GetSpawn(state, 5);
  3234. lua_interface->ResetFunctionStack(state);
  3235. if (!spawn) {
  3236. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3237. return 0;
  3238. }
  3239. if (time <= 0) {
  3240. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3241. return 0;
  3242. }
  3243. if (function.length() == 0) {
  3244. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3245. return 0;
  3246. }
  3247. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3248. if ( time < 10)
  3249. time = 10;
  3250. timer->timer = Timer::GetCurrentTime2() + time;
  3251. timer->function = function;
  3252. timer->spawn = spawn->GetID();
  3253. timer->player = player ? player->GetID() : 0;
  3254. if (max_count == 0)
  3255. max_count = 1;
  3256. timer->max_count = max_count;
  3257. timer->current_count = 0;
  3258. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3259. return 0;
  3260. }
  3261. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3262. if (!lua_interface)
  3263. return 0;
  3264. Spawn* spawn = lua_interface->GetSpawn(state);
  3265. string function = lua_interface->GetStringValue(state, 2);
  3266. lua_interface->ResetFunctionStack(state);
  3267. if (!spawn) {
  3268. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3269. return 0;
  3270. }
  3271. if(!spawn->GetZone()) {
  3272. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3273. return 0;
  3274. }
  3275. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3276. return 0;
  3277. }
  3278. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3279. if (!lua_interface)
  3280. return 0;
  3281. Spawn* player = lua_interface->GetSpawn(state);
  3282. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3283. lua_interface->ResetFunctionStack(state);
  3284. if (player && player->IsPlayer() && quest_id > 0) {
  3285. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3286. return 1;
  3287. }
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Spawn* player = lua_interface->GetSpawn(state);
  3294. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3295. lua_interface->ResetFunctionStack(state);
  3296. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3297. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3298. if (quest)
  3299. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3300. return 1;
  3301. }
  3302. return 0;
  3303. }
  3304. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3305. if (!lua_interface)
  3306. return 0;
  3307. Spawn* player = lua_interface->GetSpawn(state);
  3308. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3309. lua_interface->ResetFunctionStack(state);
  3310. if (player && player->IsPlayer() && quest_id > 0) {
  3311. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3312. return 1;
  3313. }
  3314. return 0;
  3315. }
  3316. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3317. if (!lua_interface)
  3318. return 0;
  3319. Spawn* npc = lua_interface->GetSpawn(state);
  3320. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3321. lua_interface->ResetFunctionStack(state);
  3322. if (npc && !npc->IsPlayer() && quest_id > 0)
  3323. npc->AddProvidedQuest(quest_id);
  3324. return 0;
  3325. }
  3326. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3327. if (!lua_interface)
  3328. return 0;
  3329. Spawn* npc = lua_interface->GetSpawn(state);
  3330. Spawn* player = lua_interface->GetSpawn(state, 2);
  3331. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3332. bool forced = lua_interface->GetBooleanValue(state, 4);
  3333. lua_interface->ResetFunctionStack(state);
  3334. /* NPC is allowed to be null */
  3335. if (player && player->IsPlayer() && quest_id > 0) {
  3336. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3337. if (master_quest) {
  3338. Client* client = player->GetZone()->GetClientBySpawn(player);
  3339. if (!client) {
  3340. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3341. }
  3342. Quest* quest = new Quest(master_quest);
  3343. if (!quest) {
  3344. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3345. }
  3346. if (client && quest) {
  3347. if (npc)
  3348. quest->SetQuestGiver(npc->GetDatabaseID());
  3349. else
  3350. quest->SetQuestGiver(0);
  3351. client->AddPendingQuest(quest, forced);
  3352. }
  3353. }
  3354. else {
  3355. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3356. }
  3357. }
  3358. else {
  3359. 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);
  3360. }
  3361. return 0;
  3362. }
  3363. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3364. if (!lua_interface)
  3365. return 0;
  3366. Quest* quest = lua_interface->GetQuest(state);
  3367. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3368. lua_interface->ResetFunctionStack(state);
  3369. if (quest) {
  3370. quest->AddPrereqClass(class_id);
  3371. }
  3372. return 0;
  3373. }
  3374. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3375. if (!lua_interface)
  3376. return 0;
  3377. Quest* quest = lua_interface->GetQuest(state);
  3378. int8 race = lua_interface->GetInt8Value(state, 2);
  3379. lua_interface->ResetFunctionStack(state);
  3380. if (quest) {
  3381. quest->AddPrereqRace(race);
  3382. }
  3383. return 0;
  3384. }
  3385. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3386. if (!lua_interface)
  3387. return 0;
  3388. Quest* quest = lua_interface->GetQuest(state);
  3389. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3390. lua_interface->ResetFunctionStack(state);
  3391. if (quest) {
  3392. quest->AddPrereqModelType(model_type);
  3393. }
  3394. return 0;
  3395. }
  3396. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3397. if (!lua_interface)
  3398. return 0;
  3399. Quest* quest = lua_interface->GetQuest(state);
  3400. int8 level = lua_interface->GetInt8Value(state, 2);
  3401. lua_interface->ResetFunctionStack(state);
  3402. if (!quest) {
  3403. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3404. return 0;
  3405. }
  3406. quest->SetPrereqTSLevel(level);
  3407. return 0;
  3408. }
  3409. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3410. if (!lua_interface)
  3411. return 0;
  3412. Quest* quest = lua_interface->GetQuest(state);
  3413. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3414. lua_interface->ResetFunctionStack(state);
  3415. if (!quest) {
  3416. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3417. return 0;
  3418. }
  3419. quest->AddPrereqTradeskillClass(class_id);
  3420. return 0;
  3421. }
  3422. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3423. if (!lua_interface)
  3424. return 0;
  3425. Quest* quest = lua_interface->GetQuest(state);
  3426. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3427. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3428. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3429. lua_interface->ResetFunctionStack(state);
  3430. if (quest) {
  3431. quest->AddPrereqFaction(faction_id, min, max);
  3432. }
  3433. return 0;
  3434. }
  3435. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3436. if (!lua_interface)
  3437. return 0;
  3438. Quest* quest = lua_interface->GetQuest(state);
  3439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3440. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3441. lua_interface->ResetFunctionStack(state);
  3442. if (quest) {
  3443. if (quantity == 0)
  3444. quantity = 1;
  3445. Item* master_item = master_item_list.GetItem(item_id);
  3446. if (master_item) {
  3447. Item* item = new Item(master_item);
  3448. item->details.count = quantity;
  3449. quest->AddSelectableRewardItem(item);
  3450. }
  3451. }
  3452. return 0;
  3453. }
  3454. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3455. if (!lua_interface)
  3456. return 0;
  3457. Quest* quest = lua_interface->GetQuest(state);
  3458. if (quest) {
  3459. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3460. vector<Item*>* items = quest->GetRewardItems();
  3461. if (items) {
  3462. vector<Item*>::iterator itr;
  3463. for (itr = items->begin(); itr != items->end(); itr++) {
  3464. if (*itr && (*itr)->details.item_id == item_id) {
  3465. lua_interface->SetBooleanValue(state, true);
  3466. return 1;
  3467. }
  3468. }
  3469. }
  3470. }
  3471. lua_interface->SetBooleanValue(state, false);
  3472. return 1;
  3473. }
  3474. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3475. if (!lua_interface)
  3476. return 0;
  3477. Quest* quest = lua_interface->GetQuest(state);
  3478. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3479. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3480. lua_interface->ResetFunctionStack(state);
  3481. if (quest) {
  3482. if (quantity == 0)
  3483. quantity = 1;
  3484. Item* master_item = master_item_list.GetItem(item_id);
  3485. if (master_item) {
  3486. Item* item = new Item(master_item);
  3487. item->details.count = quantity;
  3488. quest->AddRewardItem(item);
  3489. }
  3490. }
  3491. return 0;
  3492. }
  3493. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3494. if (!lua_interface)
  3495. return 0;
  3496. Quest* quest = lua_interface->GetQuest(state);
  3497. int32 copper = lua_interface->GetInt32Value(state, 2);
  3498. int32 silver = lua_interface->GetInt32Value(state, 3);
  3499. int32 gold = lua_interface->GetInt32Value(state, 4);
  3500. int32 plat = lua_interface->GetInt32Value(state, 5);
  3501. lua_interface->ResetFunctionStack(state);
  3502. if (quest) {
  3503. quest->AddRewardCoins(copper, silver, gold, plat);
  3504. }
  3505. return 0;
  3506. }
  3507. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3508. if (!lua_interface)
  3509. return 0;
  3510. Quest* quest = lua_interface->GetQuest(state);
  3511. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3512. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3513. lua_interface->ResetFunctionStack(state);
  3514. if (quest && faction_id > 0 && amount != 0)
  3515. quest->AddRewardFaction(faction_id, amount);
  3516. return 0;
  3517. }
  3518. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3519. if (!lua_interface)
  3520. return 0;
  3521. Quest* quest = lua_interface->GetQuest(state);
  3522. int32 status = lua_interface->GetInt32Value(state, 2);
  3523. lua_interface->ResetFunctionStack(state);
  3524. if (quest) {
  3525. quest->SetRewardStatus(status);
  3526. }
  3527. return 0;
  3528. }
  3529. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3530. if (!lua_interface)
  3531. return 0;
  3532. Quest* quest = lua_interface->GetQuest(state);
  3533. int32 status = lua_interface->GetInt32Value(state, 2);
  3534. lua_interface->ResetFunctionStack(state);
  3535. if (quest) {
  3536. quest->SetStatusTmpReward(status);
  3537. }
  3538. return 0;
  3539. }
  3540. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3541. if (!lua_interface)
  3542. return 0;
  3543. Quest* quest = lua_interface->GetQuest(state);
  3544. int64 coins = lua_interface->GetInt64Value(state, 2);
  3545. lua_interface->ResetFunctionStack(state);
  3546. if (quest) {
  3547. quest->SetCoinTmpReward(coins);
  3548. }
  3549. return 0;
  3550. }
  3551. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3552. if (!lua_interface)
  3553. return 0;
  3554. Quest* quest = lua_interface->GetQuest(state);
  3555. string comment = lua_interface->GetStringValue(state, 2);
  3556. lua_interface->ResetFunctionStack(state);
  3557. if (quest) {
  3558. quest->SetRewardComment(comment);
  3559. }
  3560. return 0;
  3561. }
  3562. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3563. if (!lua_interface)
  3564. return 0;
  3565. Quest* quest = lua_interface->GetQuest(state);
  3566. int32 exp = lua_interface->GetInt32Value(state, 2);
  3567. lua_interface->ResetFunctionStack(state);
  3568. if (quest) {
  3569. quest->SetRewardXP(exp);
  3570. }
  3571. return 0;
  3572. }
  3573. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3574. Quest* quest = lua_interface->GetQuest(state);
  3575. int32 step = lua_interface->GetInt32Value(state, 2);
  3576. string description = lua_interface->GetStringValue(state, 3);
  3577. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3578. float percentage = lua_interface->GetFloatValue(state, 5);
  3579. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3580. int16 icon = lua_interface->GetInt16Value(state, 7);
  3581. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3582. if (quest) {
  3583. const char* taskgroup = 0;
  3584. if (str_taskgroup.length() > 0)
  3585. taskgroup = str_taskgroup.c_str();
  3586. int32 id = 0;
  3587. vector<int32>* ids = 0;
  3588. int i = 0;
  3589. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3590. if (ids == 0)
  3591. ids = new vector<int32>;
  3592. ids->push_back(id);
  3593. i++;
  3594. }
  3595. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3596. if (quest_step && icon && quantity > 0)
  3597. quest_step->SetIcon(icon);
  3598. if (quest->GetPlayer()) {
  3599. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3600. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3601. }
  3602. }
  3603. lua_interface->ResetFunctionStack(state);
  3604. return 0;
  3605. }
  3606. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3607. {
  3608. if (!lua_interface)
  3609. return 0;
  3610. Quest* quest = lua_interface->GetQuest(state);
  3611. int32 step = lua_interface->GetInt32Value(state, 2);
  3612. string description = lua_interface->GetStringValue(state, 3);
  3613. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3614. float percentage = lua_interface->GetFloatValue(state, 5);
  3615. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3616. int16 icon = lua_interface->GetInt16Value(state, 7);
  3617. if (quest) {
  3618. const char* taskgroup = 0;
  3619. if (str_taskgroup.length() > 0)
  3620. taskgroup = str_taskgroup.c_str();
  3621. int32 id = 0;
  3622. vector<int32>* ids = 0;
  3623. int i = 0;
  3624. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3625. if (ids == 0)
  3626. ids = new vector<int32>;
  3627. ids->push_back(id);
  3628. i++;
  3629. }
  3630. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3631. if (quest_step && icon > 0 && quantity > 0)
  3632. quest_step->SetIcon(icon);
  3633. if (quest->GetPlayer()) {
  3634. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3635. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3636. }
  3637. safe_delete(ids);
  3638. }
  3639. lua_interface->ResetFunctionStack(state);
  3640. return 0;
  3641. }
  3642. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3643. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3644. }
  3645. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3646. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3647. }
  3648. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3649. if (!lua_interface)
  3650. return 0;
  3651. Quest* quest = lua_interface->GetQuest(state);
  3652. int32 step = lua_interface->GetInt32Value(state, 2);
  3653. string description = lua_interface->GetStringValue(state, 3);
  3654. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3655. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3656. int16 icon = lua_interface->GetInt16Value(state, 6);
  3657. if (quest) {
  3658. const char* taskgroup = 0;
  3659. if (str_taskgroup.length() > 0)
  3660. taskgroup = str_taskgroup.c_str();
  3661. int32 npc_id = 0;
  3662. vector<int32>* ids = 0;
  3663. int i = 0;
  3664. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3665. if (ids == 0)
  3666. ids = new vector<int32>;
  3667. ids->push_back(npc_id);
  3668. i++;
  3669. }
  3670. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3671. if (quest_step && icon > 0)
  3672. quest_step->SetIcon(icon);
  3673. if (quest->GetPlayer()) {
  3674. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3675. if(client)
  3676. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3677. }
  3678. safe_delete(ids);
  3679. }
  3680. lua_interface->ResetFunctionStack(state);
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Quest* quest = lua_interface->GetQuest(state);
  3687. int32 step = lua_interface->GetInt32Value(state, 2);
  3688. string description = lua_interface->GetStringValue(state, 3);
  3689. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3690. float percentage = lua_interface->GetFloatValue(state, 5);
  3691. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3692. int16 icon = lua_interface->GetInt16Value(state, 7);
  3693. if (quest) {
  3694. const char* taskgroup = 0;
  3695. if (str_taskgroup.length() > 0)
  3696. taskgroup = str_taskgroup.c_str();
  3697. int32 item_id = 0;
  3698. vector<int32>* ids = 0;
  3699. int i = 0;
  3700. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3701. if (ids == 0)
  3702. ids = new vector<int32>;
  3703. ids->push_back(item_id);
  3704. i++;
  3705. }
  3706. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3707. if (quest_step && icon > 0 && quantity > 0)
  3708. quest_step->SetIcon(icon);
  3709. if (quest->GetPlayer()) {
  3710. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3711. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3712. }
  3713. safe_delete(ids);
  3714. }
  3715. lua_interface->ResetFunctionStack(state);
  3716. return 0;
  3717. }
  3718. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3719. if (!lua_interface)
  3720. return 0;
  3721. Quest* quest = lua_interface->GetQuest(state);
  3722. int32 step = lua_interface->GetInt32Value(state, 2);
  3723. string description = lua_interface->GetStringValue(state, 3);
  3724. float max_variation = lua_interface->GetFloatValue(state, 4);
  3725. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3726. int16 icon = lua_interface->GetInt16Value(state, 6);
  3727. if (quest) {
  3728. const char* taskgroup = 0;
  3729. if (str_taskgroup.length() > 0)
  3730. taskgroup = str_taskgroup.c_str();
  3731. vector<Location>* locations = 0;
  3732. int8 i = 7;
  3733. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3734. while (true) {
  3735. Location loc;
  3736. loc.x = lua_interface->GetFloatValue(state, i);
  3737. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3738. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3739. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3740. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3741. break;
  3742. if (locations == 0)
  3743. locations = new vector<Location>;
  3744. locations->push_back(loc);
  3745. i += 4;
  3746. }
  3747. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3748. if (quest_step && icon > 0)
  3749. quest_step->SetIcon(icon);
  3750. if (quest->GetPlayer()) {
  3751. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3752. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3753. }
  3754. }
  3755. lua_interface->ResetFunctionStack(state);
  3756. return 0;
  3757. }
  3758. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3759. if (!lua_interface)
  3760. return 0;
  3761. Quest* quest = lua_interface->GetQuest(state);
  3762. int32 step = lua_interface->GetInt32Value(state, 2);
  3763. string description = lua_interface->GetStringValue(state, 3);
  3764. float max_variation = lua_interface->GetFloatValue(state, 4);
  3765. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3766. int16 icon = lua_interface->GetInt16Value(state, 6);
  3767. if (quest) {
  3768. const char* taskgroup = 0;
  3769. if (str_taskgroup.length() > 0)
  3770. taskgroup = str_taskgroup.c_str();
  3771. vector<Location>* locations = 0;
  3772. int8 i = 7;
  3773. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3774. while (true) {
  3775. Location loc;
  3776. loc.x = lua_interface->GetFloatValue(state, i);
  3777. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3778. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3779. loc.zone_id = 0;
  3780. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3781. break;
  3782. if (locations == 0)
  3783. locations = new vector<Location>;
  3784. locations->push_back(loc);
  3785. i += 3;
  3786. }
  3787. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3788. if (quest_step && icon > 0)
  3789. quest_step->SetIcon(icon);
  3790. if (quest->GetPlayer()) {
  3791. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3792. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3793. }
  3794. }
  3795. lua_interface->ResetFunctionStack(state);
  3796. return 0;
  3797. }
  3798. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3799. if (!lua_interface)
  3800. return 0;
  3801. Quest* quest = lua_interface->GetQuest(state);
  3802. int32 step = lua_interface->GetInt32Value(state, 2);
  3803. string description = lua_interface->GetStringValue(state, 3);
  3804. float max_variation = lua_interface->GetFloatValue(state, 4);
  3805. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3806. int16 icon = lua_interface->GetInt16Value(state, 6);
  3807. if (quest) {
  3808. const char* taskgroup = 0;
  3809. if (str_taskgroup.length() > 0)
  3810. taskgroup = str_taskgroup.c_str();
  3811. vector<Location>* locations = 0;
  3812. int i = 7;
  3813. while (true) {
  3814. Location loc;
  3815. loc.x = lua_interface->GetFloatValue(state, i);
  3816. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3817. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3818. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3819. break;
  3820. if (locations == 0)
  3821. locations = new vector<Location>;
  3822. locations->push_back(loc);
  3823. i += 3;
  3824. }
  3825. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3826. if (quest_step && icon > 0)
  3827. quest_step->SetIcon(icon);
  3828. if (quest->GetPlayer()) {
  3829. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3830. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3831. }
  3832. }
  3833. lua_interface->ResetFunctionStack(state);
  3834. return 0;
  3835. }
  3836. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3837. Quest* quest = lua_interface->GetQuest(state);
  3838. int32 step = lua_interface->GetInt32Value(state, 2);
  3839. string description = lua_interface->GetStringValue(state, 3);
  3840. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3841. float percentage = lua_interface->GetFloatValue(state, 5);
  3842. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3843. int16 icon = lua_interface->GetInt16Value(state, 7);
  3844. if (quest) {
  3845. const char* taskgroup = 0;
  3846. if (str_taskgroup.length() > 0)
  3847. taskgroup = str_taskgroup.c_str();
  3848. int32 spell_id = 0;
  3849. vector<int32>* ids = 0;
  3850. int i = 0;
  3851. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3852. if (ids == 0)
  3853. ids = new vector<int32>;
  3854. ids->push_back(spell_id);
  3855. i++;
  3856. }
  3857. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3858. if (quest_step && icon > 0 && quantity > 0)
  3859. quest_step->SetIcon(icon);
  3860. if (quest->GetPlayer()) {
  3861. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3862. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3863. }
  3864. safe_delete(ids);
  3865. }
  3866. lua_interface->ResetFunctionStack(state);
  3867. return 0;
  3868. }
  3869. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3870. if (!lua_interface)
  3871. return 0;
  3872. Quest* quest = lua_interface->GetQuest(state);
  3873. int32 step = lua_interface->GetInt32Value(state, 2);
  3874. string description = lua_interface->GetStringValue(state, 3);
  3875. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3876. float percentage = lua_interface->GetFloatValue(state, 5);
  3877. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3878. int16 icon = lua_interface->GetInt16Value(state, 7);
  3879. if (quest) {
  3880. const char* taskgroup = 0;
  3881. if (str_taskgroup.length() > 0)
  3882. taskgroup = str_taskgroup.c_str();
  3883. int32 item_id = 0;
  3884. vector<int32>* ids = 0;
  3885. int i = 0;
  3886. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3887. if (ids == 0)
  3888. ids = new vector<int32>;
  3889. ids->push_back(item_id);
  3890. i++;
  3891. }
  3892. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3893. if (quest_step && icon > 0 && quantity > 0)
  3894. quest_step->SetIcon(icon);
  3895. if (quest->GetPlayer()) {
  3896. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3897. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3898. }
  3899. safe_delete(ids);
  3900. }
  3901. lua_interface->ResetFunctionStack(state);
  3902. return 0;
  3903. }
  3904. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3905. if (!lua_interface)
  3906. return 0;
  3907. Quest* quest = lua_interface->GetQuest(state);
  3908. int32 step = lua_interface->GetInt32Value(state, 2);
  3909. string description = lua_interface->GetStringValue(state, 3);
  3910. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3911. float percentage = lua_interface->GetFloatValue(state, 5);
  3912. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3913. int16 icon = lua_interface->GetInt16Value(state, 7);
  3914. if (quest) {
  3915. const char* taskgroup = 0;
  3916. if (str_taskgroup.length() > 0)
  3917. taskgroup = str_taskgroup.c_str();
  3918. int32 item_id = 0;
  3919. vector<int32>* ids = 0;
  3920. int i = 0;
  3921. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3922. if (ids == 0)
  3923. ids = new vector<int32>;
  3924. ids->push_back(item_id);
  3925. i++;
  3926. }
  3927. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3928. if (quest_step && icon > 0 && quantity > 0)
  3929. quest_step->SetIcon(icon);
  3930. if (quest->GetPlayer()) {
  3931. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3932. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3933. }
  3934. safe_delete(ids);
  3935. }
  3936. lua_interface->ResetFunctionStack(state);
  3937. return 0;
  3938. }
  3939. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3940. if (!lua_interface)
  3941. return 0;
  3942. Quest* quest = lua_interface->GetQuest(state);
  3943. string action = lua_interface->GetStringValue(state, 2);
  3944. lua_interface->ResetFunctionStack(state);
  3945. if (quest) {
  3946. if (action.length() > 0)
  3947. quest->SetCompleteAction(action);
  3948. }
  3949. return 0;
  3950. }
  3951. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3952. if (!lua_interface)
  3953. return 0;
  3954. Quest* quest = lua_interface->GetQuest(state);
  3955. int32 step = lua_interface->GetInt32Value(state, 2);
  3956. string action = lua_interface->GetStringValue(state, 3);
  3957. lua_interface->ResetFunctionStack(state);
  3958. if (quest) {
  3959. if (step > 0 && action.length() > 0)
  3960. quest->AddCompleteAction(step, action);
  3961. }
  3962. return 0;
  3963. }
  3964. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3965. if (!lua_interface)
  3966. return 0;
  3967. Quest* quest = lua_interface->GetQuest(state);
  3968. int32 step = lua_interface->GetInt32Value(state, 2);
  3969. string action = lua_interface->GetStringValue(state, 3);
  3970. lua_interface->ResetFunctionStack(state);
  3971. if (quest) {
  3972. if (step > 0 && action.length() > 0)
  3973. quest->AddProgressAction(step, action);
  3974. }
  3975. return 0;
  3976. }
  3977. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3978. if (!lua_interface)
  3979. return 0;
  3980. Quest* quest = lua_interface->GetQuest(state);
  3981. string description = lua_interface->GetStringValue(state, 2);
  3982. lua_interface->ResetFunctionStack(state);
  3983. if (quest && description.length() > 0)
  3984. quest->SetDescription(description);
  3985. return 0;
  3986. }
  3987. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3988. if (!lua_interface)
  3989. return 0;
  3990. Quest* quest = lua_interface->GetQuest(state);
  3991. string description = lua_interface->GetStringValue(state, 2);
  3992. lua_interface->ResetFunctionStack(state);
  3993. if (quest && description.length() > 0)
  3994. quest->SetCompletedDescription(description);
  3995. return 0;
  3996. }
  3997. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3998. if (!lua_interface)
  3999. return 0;
  4000. Quest* quest = lua_interface->GetQuest(state);
  4001. int32 step = lua_interface->GetInt32Value(state, 2);
  4002. string description = lua_interface->GetStringValue(state, 3);
  4003. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4004. lua_interface->ResetFunctionStack(state);
  4005. if (quest && step > 0 && description.length() > 0) {
  4006. quest->SetTaskGroupDescription(step, description, display_bullets);
  4007. /* if (quest->GetPlayer()) {
  4008. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4009. if (client)
  4010. client->SendQuestUpdateStep(quest, step, false);
  4011. }*/
  4012. }
  4013. return 0;
  4014. }
  4015. int EQ2Emu_lua_UpdateQuestStepDescription(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 description = lua_interface->GetStringValue(state, 3);
  4021. lua_interface->ResetFunctionStack(state);
  4022. if (quest && step > 0 && description.length() > 0) {
  4023. quest->SetStepDescription(step, description);
  4024. /*if (quest->GetPlayer()) {
  4025. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4026. if (client)
  4027. client->SendQuestUpdateStepImmediately(quest, step);
  4028. }*/
  4029. }
  4030. return 0;
  4031. }
  4032. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4033. Quest* quest = lua_interface->GetQuest(state);
  4034. string zone = lua_interface->GetStringValue(state, 2);
  4035. lua_interface->ResetFunctionStack(state);
  4036. if (quest && zone.length() > 0)
  4037. quest->SetZone(zone);
  4038. return 0;
  4039. }
  4040. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4041. if (!lua_interface)
  4042. return 0;
  4043. Quest* quest = lua_interface->GetQuest(state);
  4044. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4045. lua_interface->ResetFunctionStack(state);
  4046. if (quest && spawn) {
  4047. if (spawn->IsPlayer()) {
  4048. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4049. if (client)
  4050. {
  4051. client->AddPendingQuestAcceptReward(quest);
  4052. client->AddPendingQuestReward(quest);
  4053. }
  4054. }
  4055. }
  4056. return 0;
  4057. }
  4058. int EQ2Emu_lua_Harvest(lua_State* state) {
  4059. if (!lua_interface)
  4060. return 0;
  4061. Spawn* player = lua_interface->GetSpawn(state);
  4062. Spawn* node = lua_interface->GetSpawn(state, 2);
  4063. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4064. Client* client = player->GetZone()->GetClientBySpawn(player);
  4065. if (client) {
  4066. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4067. ((GroundSpawn*)node)->ProcessHarvest(client);
  4068. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4069. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4070. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4071. }
  4072. }
  4073. }
  4074. else if (player && player->IsPlayer()) {
  4075. Client* client = player->GetZone()->GetClientBySpawn(player);
  4076. if (client)
  4077. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4078. }
  4079. lua_interface->ResetFunctionStack(state);
  4080. return 0;
  4081. }
  4082. int EQ2Emu_lua_Bind(lua_State* state) {
  4083. if (!lua_interface)
  4084. return 0;
  4085. Spawn* spawn = lua_interface->GetSpawn(state);
  4086. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4087. float x = lua_interface->GetFloatValue(state, 3);
  4088. float y = lua_interface->GetFloatValue(state, 4);
  4089. float z = lua_interface->GetFloatValue(state, 5);
  4090. float h = lua_interface->GetFloatValue(state, 6);
  4091. lua_interface->ResetFunctionStack(state);
  4092. if (!spawn) {
  4093. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4094. return 0;
  4095. }
  4096. if (!spawn->IsPlayer()) {
  4097. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4098. return 0;
  4099. }
  4100. if (zone_id == 0) {
  4101. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4102. if (!client) {
  4103. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4104. return 0;
  4105. }
  4106. if (!client->Bind())
  4107. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4108. }
  4109. else {
  4110. Player* player = (Player*)spawn;
  4111. player->GetPlayerInfo()->SetBindZone(zone_id);
  4112. player->GetPlayerInfo()->SetBindX(x);
  4113. player->GetPlayerInfo()->SetBindY(y);
  4114. player->GetPlayerInfo()->SetBindZ(z);
  4115. player->GetPlayerInfo()->SetBindHeading(h);
  4116. }
  4117. return 0;
  4118. }
  4119. int EQ2Emu_lua_Gate(lua_State* state) {
  4120. if (!lua_interface)
  4121. return 0;
  4122. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4123. Spawn* spawn = lua_interface->GetSpawn(state);
  4124. lua_interface->ResetFunctionStack(state);
  4125. if (spawn) {
  4126. if (spawn->IsPlayer()) {
  4127. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4128. if (client) {
  4129. if (!client->Gate((spell != nullptr) ? true : false))
  4130. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4131. }
  4132. }
  4133. }
  4134. return 0;
  4135. }
  4136. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4137. if (!lua_interface)
  4138. return 0;
  4139. bool ret = false;
  4140. Spawn* spawn = lua_interface->GetSpawn(state);
  4141. lua_interface->ResetFunctionStack(state);
  4142. if (spawn) {
  4143. if (spawn->IsPlayer()) {
  4144. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4145. if (client)
  4146. ret = client->BindAllowed();
  4147. }
  4148. }
  4149. lua_interface->SetBooleanValue(state, ret);
  4150. return 1;
  4151. }
  4152. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4153. if (!lua_interface)
  4154. return 0;
  4155. bool ret = false;
  4156. Spawn* spawn = lua_interface->GetSpawn(state);
  4157. lua_interface->ResetFunctionStack(state);
  4158. if (spawn) {
  4159. if (spawn->IsPlayer()) {
  4160. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4161. ZoneServer* zone = lua_interface->GetZone(state);
  4162. if (client && zone){
  4163. ret = zone->GetCanGate();
  4164. }
  4165. }
  4166. }
  4167. lua_interface->SetBooleanValue(state, ret);
  4168. return 1;
  4169. }
  4170. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4171. Spawn* spawn = lua_interface->GetSpawn(state);
  4172. lua_interface->ResetFunctionStack(state);
  4173. if (spawn) {
  4174. lua_interface->SetBooleanValue(state, spawn->Alive());
  4175. return 1;
  4176. }
  4177. return 0;
  4178. }
  4179. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4180. if (!lua_interface)
  4181. return 0;
  4182. Spawn* spawn = lua_interface->GetSpawn(state);
  4183. lua_interface->ResetFunctionStack(state);
  4184. if (spawn && spawn->IsEntity()) {
  4185. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4186. return 1;
  4187. }
  4188. return 0;
  4189. }
  4190. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4191. Spawn* spawn = lua_interface->GetSpawn(state);
  4192. string message = lua_interface->GetStringValue(state, 2);
  4193. string color_str = lua_interface->GetStringValue(state, 3);
  4194. lua_interface->ResetFunctionStack(state);
  4195. int8 color = CHANNEL_NARRATIVE;
  4196. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4197. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4198. if (client) {
  4199. if (color_str.length() > 0) {
  4200. // leave for backwards compat, but all future should just use the number
  4201. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4202. color = CHANNEL_COLOR_RED;
  4203. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4204. color = CHANNEL_COLOR_YELLOW;
  4205. else
  4206. {
  4207. // use a number to specify the channel as per Commands/Commands.h defines
  4208. color = (int8)atoul(color_str.c_str());
  4209. }
  4210. }
  4211. client->SimpleMessage(color, message.c_str());
  4212. }
  4213. }
  4214. return 0;
  4215. }
  4216. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4217. Spawn* spawn = lua_interface->GetSpawn(state);
  4218. string message = lua_interface->GetStringValue(state, 2);
  4219. int8 red = lua_interface->GetInt8Value(state, 3);
  4220. int8 green = lua_interface->GetInt8Value(state, 4);
  4221. int8 blue = lua_interface->GetInt8Value(state, 5);
  4222. lua_interface->ResetFunctionStack(state);
  4223. if (!spawn) {
  4224. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4225. return 0;
  4226. }
  4227. int32 words = ::CountWordsInString(message.c_str());
  4228. if (words < 5)
  4229. words = 5;
  4230. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4231. if (client)
  4232. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4233. return 0;
  4234. }
  4235. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4236. Spawn* spawn = lua_interface->GetSpawn(state);
  4237. int8 param = lua_interface->GetInt8Value(state, 2);
  4238. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4239. int8 value = lua_interface->GetInt8Value(state, 4);
  4240. lua_interface->ResetFunctionStack(state);
  4241. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4242. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4243. if (client) {
  4244. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4245. switch (param) {
  4246. case 1: {
  4247. packet->setDataByName("parameter1", param_value);
  4248. break;
  4249. }
  4250. case 2: {
  4251. packet->setDataByName("parameter2", param_value);
  4252. break;
  4253. }
  4254. case 3: {
  4255. packet->setDataByName("parameter3", param_value);
  4256. break;
  4257. }
  4258. case 4: {
  4259. packet->setDataByName("parameter4", param_value);
  4260. break;
  4261. }
  4262. case 5: {
  4263. packet->setDataByName("parameter5", param_value);
  4264. break;
  4265. }
  4266. }
  4267. packet->setDataByName("value", value);
  4268. client->QueuePacket(packet->serialize());
  4269. safe_delete(packet);
  4270. }
  4271. }
  4272. return 0;
  4273. }
  4274. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4275. Spawn* spawn = lua_interface->GetSpawn(state);
  4276. lua_interface->ResetFunctionStack(state);
  4277. if (spawn && spawn->IsPlayer()) {
  4278. if (((Player*)spawn)->GetIsTracking())
  4279. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4280. else
  4281. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4282. }
  4283. return 0;
  4284. }
  4285. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4286. Spawn* player = lua_interface->GetSpawn(state);
  4287. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4288. string name = lua_interface->GetStringValue(state, 3);
  4289. float distance = lua_interface->GetFloatValue(state, 4);
  4290. string command = lua_interface->GetStringValue(state, 5);
  4291. string error_text = lua_interface->GetStringValue(state, 6);
  4292. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4293. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4294. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4295. lua_interface->ResetFunctionStack(state);
  4296. if (spawn) {
  4297. if (distance == 0)
  4298. distance = 10.0f;
  4299. if (command.length() == 0)
  4300. command = name;
  4301. if (command.length() < 1 && name.length() < 1)
  4302. {
  4303. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4304. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4305. spawn->RemovePrimaryCommands();
  4306. }
  4307. else
  4308. {
  4309. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4310. }
  4311. }
  4312. return 0;
  4313. }
  4314. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4315. if (!lua_interface)
  4316. return 0;
  4317. Spawn* player = lua_interface->GetSpawn(state);
  4318. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4319. int16 tier = lua_interface->GetInt16Value(state, 3);
  4320. lua_interface->ResetFunctionStack(state);
  4321. if (player && player->IsPlayer()) {
  4322. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4323. return 1;
  4324. }
  4325. return 0;
  4326. }
  4327. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4328. if (!lua_interface)
  4329. return 0;
  4330. Spawn* player = lua_interface->GetSpawn(state);
  4331. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4332. int16 tier = lua_interface->GetInt16Value(state, 3);
  4333. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4334. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4335. bool add_to_hotbar = true;
  4336. if (num_args > 4) {
  4337. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4338. }
  4339. lua_interface->ResetFunctionStack(state);
  4340. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4341. if (player && spell && player->IsPlayer()) {
  4342. Client* client = player->GetClient();
  4343. if (client) {
  4344. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4345. {
  4346. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4347. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4348. client->GetPlayer()->UnlockSpell(spell);
  4349. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4350. }
  4351. else
  4352. {
  4353. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4354. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4355. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4356. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4357. client->GetPlayer()->UnlockSpell(spell);
  4358. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4359. }
  4360. //if (client ) {
  4361. // ((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);
  4362. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4363. if (outapp)
  4364. client->QueuePacket(outapp);
  4365. }
  4366. }
  4367. return 0;
  4368. }
  4369. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4370. if (!lua_interface)
  4371. return 0;
  4372. Spawn* player = lua_interface->GetSpawn(state);
  4373. lua_interface->ResetFunctionStack(state);
  4374. if (player && player->IsPlayer()) {
  4375. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4376. return 1;
  4377. }
  4378. return 0;
  4379. }
  4380. int EQ2Emu_lua_Attack(lua_State* state) {
  4381. if (lua_interface) {
  4382. Spawn* npc = lua_interface->GetSpawn(state);
  4383. Spawn* player = lua_interface->GetSpawn(state, 2);
  4384. lua_interface->ResetFunctionStack(state);
  4385. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4386. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4387. }
  4388. return 0;
  4389. }
  4390. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4391. if (lua_interface) {
  4392. Spawn* target = lua_interface->GetSpawn(state);
  4393. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4394. lua_interface->ResetFunctionStack(state);
  4395. if (target && target->GetZone())
  4396. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4397. }
  4398. return 0;
  4399. }
  4400. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4401. Spawn* player;
  4402. if (lua_interface) {
  4403. player = lua_interface->GetSpawn(state);
  4404. lua_interface->ResetFunctionStack(state);
  4405. if (player && player->IsPlayer()) {
  4406. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4407. return 1;
  4408. }
  4409. }
  4410. return 0;
  4411. }
  4412. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4413. Spawn* player;
  4414. Client* client;
  4415. if (lua_interface) {
  4416. player = lua_interface->GetSpawn(state);
  4417. lua_interface->ResetFunctionStack(state);
  4418. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4419. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4420. client->HandInCollections();
  4421. }
  4422. return 0;
  4423. }
  4424. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4425. Spawn* widget;
  4426. if (lua_interface) {
  4427. widget = lua_interface->GetSpawn(state);
  4428. lua_interface->ResetFunctionStack(state);
  4429. if (widget && widget->IsWidget())
  4430. ((Widget*)widget)->HandleUse(nullptr, "");
  4431. }
  4432. return 0;
  4433. }
  4434. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4435. Spawn* spawn = 0;
  4436. int32 primary_list = 0;
  4437. int32 secondary_list = 0;
  4438. if (lua_interface) {
  4439. spawn = lua_interface->GetSpawn(state);
  4440. primary_list = lua_interface->GetInt32Value(state, 2);
  4441. secondary_list = lua_interface->GetInt32Value(state, 3);
  4442. lua_interface->ResetFunctionStack(state);
  4443. if (!spawn->IsNPC()) {
  4444. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4445. return 0;
  4446. }
  4447. NPC* npc = (NPC*)spawn;
  4448. npc->SetPrimarySpellList(primary_list);
  4449. npc->SetSecondarySpellList(secondary_list);
  4450. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4451. }
  4452. return 0;
  4453. }
  4454. int EQ2Emu_lua_GetPet(lua_State* state) {
  4455. if (!lua_interface)
  4456. return 0;
  4457. Spawn* spawn = lua_interface->GetSpawn(state);
  4458. lua_interface->ResetFunctionStack(state);
  4459. if (spawn) {
  4460. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4461. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4462. return 1;
  4463. }
  4464. }
  4465. return 0;
  4466. }
  4467. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4468. if (!lua_interface)
  4469. return 0;
  4470. Spawn* spawn = lua_interface->GetSpawn(state);
  4471. lua_interface->ResetFunctionStack(state);
  4472. if (spawn) {
  4473. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4474. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4475. return 1;
  4476. }
  4477. }
  4478. return 0;
  4479. }
  4480. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4481. if (!lua_interface)
  4482. return 0;
  4483. Spawn* spawn = lua_interface->GetSpawn(state);
  4484. lua_interface->ResetFunctionStack(state);
  4485. if (spawn) {
  4486. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4487. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4488. return 1;
  4489. }
  4490. }
  4491. return 0;
  4492. }
  4493. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4494. if (!lua_interface)
  4495. return 0;
  4496. Spawn* spawn = lua_interface->GetSpawn(state);
  4497. lua_interface->ResetFunctionStack(state);
  4498. if (spawn) {
  4499. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4500. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4501. return 1;
  4502. }
  4503. }
  4504. return 0;
  4505. }
  4506. int EQ2Emu_lua_Charm(lua_State* state) {
  4507. if (!lua_interface)
  4508. return 0;
  4509. Spawn* owner = lua_interface->GetSpawn(state);
  4510. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4511. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4512. lua_interface->ResetFunctionStack(state);
  4513. if (!luaspell) {
  4514. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4515. return 0;
  4516. }
  4517. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4518. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4519. pet->SetPet(true);
  4520. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4521. ((NPC*)pet)->SetOwner((Entity*)owner);
  4522. // If owner is player and player does not have a summoned pet set the players charsheet
  4523. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4524. Player* player = (Player*)owner;
  4525. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4526. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4527. player->GetInfoStruct()->set_pet_movement(2);
  4528. player->GetInfoStruct()->set_pet_behavior(3);
  4529. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4530. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4531. // Make sure the values get sent to the client
  4532. player->SetCharSheetChanged(true);
  4533. }
  4534. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4535. pet->SetSpawnScript("");
  4536. // Set faction to the same as the owner
  4537. pet->SetFactionID(owner->GetFactionID());
  4538. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4539. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4540. // Clear hate list
  4541. ((NPC*)pet)->Brain()->ClearHate();
  4542. // Set the brain to a pet brain
  4543. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4544. }
  4545. return 0;
  4546. }
  4547. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4548. if (!lua_interface)
  4549. return 0;
  4550. Spawn* spawn = lua_interface->GetSpawn(state);
  4551. lua_interface->ResetFunctionStack(state);
  4552. if (!spawn) {
  4553. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4554. return 0;
  4555. }
  4556. vector<Spawn*> groupMembers;
  4557. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4558. groupMembers = *spawn->GetSpawnGroup();
  4559. }
  4560. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4561. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4562. deque<GroupMemberInfo*>::iterator itr;
  4563. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4564. if (group)
  4565. {
  4566. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4567. deque<GroupMemberInfo*>* members = group->GetMembers();
  4568. GroupMemberInfo* info = 0;
  4569. for (itr = members->begin(); itr != members->end(); itr++) {
  4570. info = *itr;
  4571. if (info->client)
  4572. groupMembers.push_back(info->client->GetPlayer());
  4573. }
  4574. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4575. }
  4576. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4577. }
  4578. else
  4579. return 0;
  4580. lua_createtable(state, groupMembers.size(), 0);
  4581. int newTable = lua_gettop(state);
  4582. for (int32 i = 0; i < groupMembers.size(); i++) {
  4583. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4584. lua_rawseti(state, newTable, i + 1);
  4585. }
  4586. return 1;
  4587. }
  4588. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4589. if (!lua_interface)
  4590. return 0;
  4591. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4592. lua_interface->SetOptionWindowValue(state, option_window);
  4593. return 1;
  4594. }
  4595. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4596. if (!lua_interface)
  4597. return 0;
  4598. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4599. if (option_window) {
  4600. OptionWindowOption option_window_option;
  4601. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4602. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4603. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4604. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4605. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4606. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4607. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4608. option_window->push_back(option_window_option);
  4609. }
  4610. return 0;
  4611. }
  4612. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4613. if (!lua_interface)
  4614. return 0;
  4615. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4616. Spawn* player = lua_interface->GetSpawn(state, 2);
  4617. string window_title = lua_interface->GetStringValue(state, 3);
  4618. string cancel_command = lua_interface->GetStringValue(state, 4);
  4619. Client* client = player->GetZone()->GetClientBySpawn(player);
  4620. if (option_window && window_title.length() > 0 && client) {
  4621. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4622. if (!packet)
  4623. return 0;
  4624. packet->setDataByName("title_text", window_title.c_str());
  4625. if (cancel_command.length() > 0)
  4626. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4627. packet->setArrayLengthByName("num_selections", option_window->size());
  4628. vector<OptionWindowOption>::iterator itr;
  4629. int8 i = 0;
  4630. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4631. OptionWindowOption opt = *itr;
  4632. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4633. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4634. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4635. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4636. if (opt.optionCommand.length() > 0)
  4637. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4638. if (opt.optionConfirmTitle.length() > 0)
  4639. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4640. i++;
  4641. }
  4642. client->QueuePacket(packet->serialize());
  4643. safe_delete(option_window);
  4644. safe_delete(packet);
  4645. }
  4646. return 0;
  4647. }
  4648. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4649. if (!lua_interface)
  4650. return 0;
  4651. Spawn* spawn = lua_interface->GetSpawn(state);
  4652. if (spawn) {
  4653. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4654. return 1;
  4655. }
  4656. else
  4657. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4658. return 0;
  4659. }
  4660. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4661. if (!lua_interface)
  4662. return 0;
  4663. Spawn* spawn = lua_interface->GetSpawn(state);
  4664. if (spawn) {
  4665. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4666. return 1;
  4667. }
  4668. else
  4669. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4670. return 0;
  4671. }
  4672. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4673. if (!lua_interface)
  4674. return 0;
  4675. Spawn* spawn = lua_interface->GetSpawn(state);
  4676. if (spawn) {
  4677. int8 class_id = spawn->GetTradeskillClass();
  4678. // Need to add 42 for the offset in the array
  4679. class_id += 44;
  4680. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4681. return 1;
  4682. }
  4683. else
  4684. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4685. return 0;
  4686. }
  4687. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4688. if (!lua_interface)
  4689. return 0;
  4690. Spawn* spawn = lua_interface->GetSpawn(state);
  4691. int16 level = lua_interface->GetInt8Value(state, 2);
  4692. if (spawn) {
  4693. if (spawn->IsPlayer())
  4694. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4695. else
  4696. spawn->SetTSLevel(level);
  4697. }
  4698. else
  4699. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4700. return 0;
  4701. }
  4702. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4703. if (!lua_interface)
  4704. return 0;
  4705. Spawn* spawn = lua_interface->GetSpawn(state);
  4706. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4707. if (spawn) {
  4708. spawn->SetAttackable(attackable);
  4709. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4710. }
  4711. return 0;
  4712. }
  4713. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4714. // Check to see if we have a valid lua_interface
  4715. if (!lua_interface)
  4716. return 0;
  4717. // Get the spawn that is getting the pet
  4718. Spawn* spawn = lua_interface->GetSpawn(state);
  4719. // Get the DB ID of the pet
  4720. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4721. // The max level the pet can gain
  4722. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4723. // Get the spell that this command was called from
  4724. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4725. // Check to make sure the spawn pointer is valid
  4726. if (!spawn) {
  4727. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4728. return 0;
  4729. }
  4730. // Check to make sure the spawn is an entity
  4731. if (!spawn->IsEntity()) {
  4732. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4733. return 0;
  4734. }
  4735. // Check to make sure the spawn doesn't already have a pet of this type
  4736. if (((Entity*)spawn)->GetPet()) {
  4737. if (spawn->IsPlayer()) {
  4738. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4739. if (client)
  4740. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4741. }
  4742. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4743. return 0;
  4744. }
  4745. // Check to see if the DB ID for the pet is set
  4746. if (pet_id == 0) {
  4747. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4748. return 0;
  4749. }
  4750. // Check to see if the pointer to the spell is valid
  4751. if (!luaspell) {
  4752. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4753. return 0;
  4754. }
  4755. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4756. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4757. if (!pet) {
  4758. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4759. return 0;
  4760. }
  4761. // Check to make sure the pet is an npc
  4762. if (!pet->IsNPC()) {
  4763. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4764. return 0;
  4765. }
  4766. // Spawn the pet at the same location as the owner
  4767. pet->SetX(spawn->GetX());
  4768. pet->SetY(spawn->GetY());
  4769. pet->SetZ(spawn->GetZ());
  4770. pet->SetLocation(spawn->GetLocation());
  4771. pet->SetHeading(spawn->GetHeading());
  4772. spawn->GetZone()->AddSpawn(pet);
  4773. /*
  4774. const char* spawn_script = world.GetSpawnScript(pet_id);
  4775. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4776. spawn->SetSpawnScript(string(spawn_script));
  4777. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4778. }*/
  4779. // Get a random pet name
  4780. string random_pet_name;
  4781. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4782. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4783. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4784. // If player set various values for the char sheet (pet window)
  4785. if (spawn->IsPlayer()) {
  4786. Player* player = (Player*)spawn;
  4787. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4788. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4789. player->GetInfoStruct()->set_pet_movement(2);
  4790. player->GetInfoStruct()->set_pet_behavior(3);
  4791. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4792. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4793. // Make sure the values get sent to the client
  4794. player->SetCharSheetChanged(true);
  4795. }
  4796. // Set the pets name
  4797. pet->SetName(random_pet_name.c_str());
  4798. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4799. if (max_level > 0)
  4800. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4801. else
  4802. pet->SetLevel(spawn->GetLevel());
  4803. // Set the max level this pet can reach
  4804. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4805. // Set the faction of the pet to the same faction as the owner
  4806. pet->SetFactionID(spawn->GetFactionID());
  4807. // Set the spawn as a pet
  4808. pet->SetPet(true);
  4809. // Give a pointer of the owner to the pet
  4810. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4811. // Give a pointer of the pet to the owner
  4812. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4813. // Set the pet type
  4814. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4815. // Set the spell id used to create this pet
  4816. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4817. // Set the spell tier used to create this pet
  4818. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4819. // Set the pets spawn type to 6
  4820. pet->SetSpawnType(6);
  4821. // Set the pets brain
  4822. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4823. // Check to see if the pet has a subtitle
  4824. if (strlen(pet->GetSubTitle()) > 0) {
  4825. // Add the players name to the front of the sub title
  4826. string pet_subtitle;
  4827. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4828. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4829. // Set the pets subtitle to the new one
  4830. pet->SetSubTitle(pet_subtitle.c_str());
  4831. }
  4832. // Add the "Pet Options" entity command to the pet
  4833. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4834. // Set the pet as the return value for this function
  4835. lua_interface->SetSpawnValue(state, pet);
  4836. return 1;
  4837. }
  4838. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4839. if (!lua_interface)
  4840. return 0;
  4841. Spawn* spawn = lua_interface->GetSpawn(state);
  4842. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4843. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4844. if (!spawn) {
  4845. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4846. return 0;
  4847. }
  4848. if (!spawn->IsEntity()) {
  4849. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4850. return 0;
  4851. }
  4852. if (((Entity*)spawn)->GetDeityPet()) {
  4853. if (spawn->IsPlayer()) {
  4854. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4855. if (client)
  4856. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4857. }
  4858. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4859. return 0;
  4860. }
  4861. if (pet_id == 0) {
  4862. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4863. return 0;
  4864. }
  4865. if (!luaspell) {
  4866. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4867. return 0;
  4868. }
  4869. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4870. if (!pet) {
  4871. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4872. return 0;
  4873. }
  4874. if (!pet->IsNPC()) {
  4875. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4876. return 0;
  4877. }
  4878. pet->SetX(spawn->GetX());
  4879. pet->SetY(spawn->GetY());
  4880. pet->SetZ(spawn->GetZ());
  4881. pet->SetLocation(spawn->GetLocation());
  4882. pet->SetHeading(spawn->GetHeading());
  4883. spawn->GetZone()->AddSpawn(pet);
  4884. string random_pet_name;
  4885. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4886. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4887. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4888. pet->SetName(random_pet_name.c_str());
  4889. pet->SetLevel(spawn->GetLevel());
  4890. pet->SetFactionID(spawn->GetFactionID());
  4891. pet->SetPet(true);
  4892. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4893. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4894. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4895. pet->SetSpawnType(6);
  4896. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4897. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4898. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4899. if (strlen(pet->GetSubTitle()) > 0) {
  4900. string pet_subtitle;
  4901. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4902. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4903. pet->SetSubTitle(pet_subtitle.c_str());
  4904. }
  4905. // deity and cosmetic pets are not attackable
  4906. pet->SetAttackable(false);
  4907. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4908. lua_interface->SetSpawnValue(state, pet);
  4909. return 1;
  4910. }
  4911. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4912. if (!lua_interface)
  4913. return 0;
  4914. Spawn* spawn = lua_interface->GetSpawn(state);
  4915. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4916. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4917. if (!spawn) {
  4918. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4919. return 0;
  4920. }
  4921. if (!spawn->IsEntity()) {
  4922. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4923. return 0;
  4924. }
  4925. if (((Entity*)spawn)->GetCosmeticPet()) {
  4926. if (spawn->IsPlayer()) {
  4927. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4928. if (client)
  4929. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4930. }
  4931. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4932. return 0;
  4933. }
  4934. if (pet_id == 0) {
  4935. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4936. return 0;
  4937. }
  4938. if (!luaspell) {
  4939. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4940. return 0;
  4941. }
  4942. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4943. if (!pet) {
  4944. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4945. return 0;
  4946. }
  4947. if (!pet->IsNPC()) {
  4948. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4949. return 0;
  4950. }
  4951. pet->SetX(spawn->GetX());
  4952. pet->SetY(spawn->GetY());
  4953. pet->SetZ(spawn->GetZ());
  4954. pet->SetLocation(spawn->GetLocation());
  4955. pet->SetHeading(spawn->GetHeading());
  4956. spawn->GetZone()->AddSpawn(pet);
  4957. string random_pet_name;
  4958. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4959. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4960. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4961. pet->SetName(random_pet_name.c_str());
  4962. pet->SetLevel(spawn->GetLevel());
  4963. pet->SetFactionID(spawn->GetFactionID());
  4964. pet->SetPet(true);
  4965. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4966. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4967. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4968. pet->SetSpawnType(6);
  4969. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4970. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4971. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4972. if (strlen(pet->GetSubTitle()) > 0) {
  4973. string pet_subtitle;
  4974. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4975. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4976. pet->SetSubTitle(pet_subtitle.c_str());
  4977. }
  4978. pet->SetAttackable(false);
  4979. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4980. lua_interface->SetSpawnValue(state, pet);
  4981. return 1;
  4982. }
  4983. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4984. if (!lua_interface)
  4985. return 0;
  4986. Spawn* spawn = lua_interface->GetSpawn(state);
  4987. if (!spawn) {
  4988. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4989. return 0;
  4990. }
  4991. if (!spawn->IsPet()) {
  4992. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4993. return 0;
  4994. }
  4995. if (!((NPC*)spawn)->IsDismissing())
  4996. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4997. return 0;
  4998. }
  4999. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5000. if (!lua_interface)
  5001. return 0;
  5002. Quest* quest = lua_interface->GetQuest(state);
  5003. if (!quest) {
  5004. 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));
  5005. return 0;
  5006. }
  5007. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5008. if (feather_color > 0)
  5009. quest->SetFeatherColor(feather_color);
  5010. return 0;
  5011. }
  5012. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5013. if (!lua_interface)
  5014. return 0;
  5015. Spawn* spawn = lua_interface->GetSpawn(state);
  5016. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5017. if (!spawn) {
  5018. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5019. return 0;
  5020. }
  5021. if (!spawn2) {
  5022. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. spawn->RemoveSpawnAccess(spawn2);
  5026. return 0;
  5027. }
  5028. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5029. if (!lua_interface)
  5030. return 0;
  5031. ZoneServer* zone = lua_interface->GetZone(state);
  5032. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5033. if (!zone) {
  5034. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5035. return 0;
  5036. }
  5037. if (location_id == 0) {
  5038. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5039. return 0;
  5040. }
  5041. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5042. if (!location) {
  5043. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5044. return 0;
  5045. }
  5046. Spawn* spawn = 0;
  5047. if (location->entities[0]) {
  5048. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5049. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5050. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5051. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5052. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5053. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5054. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5055. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5056. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5057. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5058. if(spawn && spawn->IsOmittedByDBFlag())
  5059. {
  5060. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5061. safe_delete(spawn);
  5062. spawn = 0;
  5063. return 0;
  5064. }
  5065. if (spawn) {
  5066. const char* script = 0;
  5067. for (int x = 0; x < 3; x++) {
  5068. switch (x) {
  5069. case 0:
  5070. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5071. break;
  5072. case 1:
  5073. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5074. break;
  5075. case 2:
  5076. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5077. break;
  5078. }
  5079. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5080. spawn->SetSpawnScript(string(script));
  5081. break;
  5082. }
  5083. }
  5084. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5085. lua_interface->SetSpawnValue(state, spawn);
  5086. return 1;
  5087. }
  5088. else {
  5089. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5090. safe_delete(spawn);
  5091. }
  5092. }
  5093. return 0;
  5094. }
  5095. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5096. if (!lua_interface)
  5097. return 0;
  5098. Spawn* caster = lua_interface->GetSpawn(state);
  5099. Spawn* target = lua_interface->GetSpawn(state, 2);
  5100. int32 id = lua_interface->GetInt32Value(state, 3);
  5101. string command = lua_interface->GetStringValue(state, 4);
  5102. if (!caster) {
  5103. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5104. return 0;
  5105. }
  5106. if (!target) {
  5107. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5108. return 0;
  5109. }
  5110. if (!caster->IsPlayer()) {
  5111. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5112. return 0;
  5113. }
  5114. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5115. if (!entity_command) {
  5116. 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());
  5117. return 0;
  5118. }
  5119. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5120. if (!client) {
  5121. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5122. return 0;
  5123. }
  5124. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5125. return 0;
  5126. }
  5127. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5128. if (!lua_interface)
  5129. return 0;
  5130. Spawn* spawn = lua_interface->GetSpawn(state);
  5131. if (!spawn) {
  5132. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5133. return 0;
  5134. }
  5135. if (!spawn->IsNPC()) {
  5136. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5137. return 0;
  5138. }
  5139. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5140. return 0;
  5141. }
  5142. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5143. if (!lua_interface)
  5144. return 0;
  5145. Spawn* spawn = lua_interface->GetSpawn(state);
  5146. int16 tick = lua_interface->GetInt16Value(state, 2);
  5147. if (!spawn) {
  5148. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5149. return 0;
  5150. }
  5151. if (!spawn->IsNPC()) {
  5152. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5153. return 0;
  5154. }
  5155. if (tick < 20) {
  5156. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5157. return 0;
  5158. }
  5159. ((NPC*)spawn)->Brain()->SetTick(tick);
  5160. return 0;
  5161. }
  5162. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5163. if (!lua_interface)
  5164. return 0;
  5165. Spawn* spawn = lua_interface->GetSpawn(state);
  5166. Spawn* target = lua_interface->GetSpawn(state, 2);
  5167. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5168. if (!spawn) {
  5169. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5170. return 0;
  5171. }
  5172. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5173. spawn->SetFollowTarget(target, follow_distance);
  5174. return 0;
  5175. }
  5176. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5177. if (!lua_interface)
  5178. return 0;
  5179. Spawn* spawn = lua_interface->GetSpawn(state);
  5180. if (!spawn) {
  5181. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5182. return 0;
  5183. }
  5184. Spawn* target = spawn->GetFollowTarget();
  5185. if (target) {
  5186. lua_interface->SetSpawnValue(state, target);
  5187. return 1;
  5188. }
  5189. return 0;
  5190. }
  5191. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5192. if (!lua_interface)
  5193. return 0;
  5194. Spawn* spawn = lua_interface->GetSpawn(state);
  5195. if (!spawn) {
  5196. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5197. return 0;
  5198. }
  5199. if (spawn->following)
  5200. spawn->following = false;
  5201. else
  5202. spawn->following = true;
  5203. return 0;
  5204. }
  5205. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5206. if (!lua_interface)
  5207. return 0;
  5208. Spawn* spawn = lua_interface->GetSpawn(state);
  5209. if (!spawn) {
  5210. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5211. return 0;
  5212. }
  5213. lua_interface->SetBooleanValue(state, spawn->following);
  5214. return 1;
  5215. }
  5216. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5217. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5218. // I will attempt to explain how this function works for future refrence
  5219. // Fist lets make sure lua_interface is valid, if not return out
  5220. if (!lua_interface)
  5221. return 0;
  5222. // Next we grab the first 2 params same as we usually would
  5223. Spawn* spawn = lua_interface->GetSpawn(state);
  5224. string var = lua_interface->GetStringValue(state, 2);
  5225. // 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
  5226. // 1 = Spawn
  5227. // 2 = Zone
  5228. // 3 = Item
  5229. // 4 = Quest
  5230. // 5 = String
  5231. // 6 = nil (null)
  5232. int8 dataType = 0;
  5233. // Define pointers for each potential type
  5234. Spawn* spawnVal = 0;
  5235. ZoneServer* zone = 0;
  5236. Item* item = 0;
  5237. Quest* quest = 0;
  5238. string val;
  5239. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5240. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5241. // options window are also light user data be we do not handle those.
  5242. // We check with lua_islightuserdata(lua_State*, index)
  5243. if (lua_islightuserdata(state, 3)) {
  5244. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5245. // and convert it to LUAUserData*
  5246. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5247. // Check to make sure the data we got is valid, if not give an error
  5248. if (!data || !data->IsCorrectlyInitialized()) {
  5249. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5250. }
  5251. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5252. else if (data->IsSpawn()) {
  5253. spawnVal = data->spawn;
  5254. dataType = 1;
  5255. }
  5256. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5257. else if (data->IsZone()) {
  5258. zone = data->zone;
  5259. dataType = 2;
  5260. }
  5261. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5262. else if (data->IsItem()) {
  5263. item = data->item;
  5264. dataType = 3;
  5265. }
  5266. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5267. else if (data->IsQuest()) {
  5268. quest = data->quest;
  5269. dataType = 4;
  5270. }
  5271. }
  5272. // Wasn't light user data, check if it is nil(null)
  5273. else if (lua_isnil(state, 3)) {
  5274. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5275. dataType = 6;
  5276. }
  5277. // Wasn't light user data or nil (null), must be a string
  5278. else {
  5279. // Set the string and dataType variable
  5280. val = lua_interface->GetStringValue(state, 3);
  5281. dataType = 5;
  5282. }
  5283. // We now have all the params, lets check to make sure they are valid
  5284. if (!spawn) {
  5285. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5286. return 0;
  5287. }
  5288. if (var.length() == 0) {
  5289. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5290. return 0;
  5291. }
  5292. if (dataType == 0) {
  5293. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5294. return 0;
  5295. }
  5296. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5297. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5298. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5299. switch (dataType) {
  5300. case 1:
  5301. // 1 = Spawn
  5302. spawn->AddTempVariable(var, spawnVal);
  5303. break;
  5304. case 2:
  5305. // 2 = Zone
  5306. spawn->AddTempVariable(var, zone);
  5307. break;
  5308. case 3:
  5309. // 3 = Item
  5310. spawn->AddTempVariable(var, item);
  5311. break;
  5312. case 4:
  5313. // 4 = Quest
  5314. spawn->AddTempVariable(var, quest);
  5315. break;
  5316. case 5:
  5317. // 5 = String
  5318. spawn->AddTempVariable(var, val);
  5319. break;
  5320. case 6:
  5321. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5322. spawn->DeleteTempVariable(var);
  5323. break;
  5324. }
  5325. // And we are done so return out
  5326. return 0;
  5327. }
  5328. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5329. if (!lua_interface)
  5330. return 0;
  5331. Spawn* spawn = lua_interface->GetSpawn(state);
  5332. string var = lua_interface->GetStringValue(state, 2);
  5333. if (!spawn) {
  5334. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5335. return 0;
  5336. }
  5337. if (var.length() == 0) {
  5338. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5339. return 0;
  5340. }
  5341. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5342. int8 type = spawn->GetTempVariableType(var);
  5343. Spawn* spawn2 = 0;
  5344. ZoneServer* zone = 0;
  5345. Item* item = 0;
  5346. Quest* quest = 0;
  5347. // Set the lua function return value based on the type of data the variable contains
  5348. switch (type) {
  5349. case 1:
  5350. spawn2 = spawn->GetTempVariableSpawn(var);
  5351. if (!spawn2)
  5352. return 0;
  5353. lua_interface->SetSpawnValue(state, spawn2);
  5354. break;
  5355. case 2:
  5356. zone = spawn->GetTempVariableZone(var);
  5357. if (!zone)
  5358. return 0;
  5359. lua_interface->SetZoneValue(state, zone);
  5360. break;
  5361. case 3:
  5362. item = spawn->GetTempVariableItem(var);
  5363. if (!item)
  5364. return 0;
  5365. lua_interface->SetItemValue(state, item);
  5366. break;
  5367. case 4:
  5368. quest = spawn->GetTempVariableQuest(var);
  5369. if (!quest)
  5370. return 0;
  5371. lua_interface->SetQuestValue(state, quest);
  5372. break;
  5373. case 5:
  5374. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5375. break;
  5376. default:
  5377. // Not a valid type then the variable was not set so return out
  5378. return 0;
  5379. }
  5380. // Return value was set so return out
  5381. return 1;
  5382. }
  5383. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5384. {
  5385. if (!lua_interface)
  5386. return 0;
  5387. Quest* quest = lua_interface->GetQuest(state);
  5388. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5389. string description = lua_interface->GetStringValue(state, 3);
  5390. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5391. if (!quest) {
  5392. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5393. lua_interface->SetBooleanValue(state, false);
  5394. return 1;
  5395. }
  5396. if (!spawn) {
  5397. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5398. lua_interface->SetBooleanValue(state, false);
  5399. return 1;
  5400. }
  5401. if (!spawn->IsPlayer()) {
  5402. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5403. lua_interface->SetBooleanValue(state, false);
  5404. return 1;
  5405. }
  5406. if (item_id == 0) {
  5407. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5408. lua_interface->SetBooleanValue(state, false);
  5409. return 1;
  5410. }
  5411. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5412. if (!client) {
  5413. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5414. lua_interface->SetBooleanValue(state, false);
  5415. return 1;
  5416. }
  5417. Item* item = master_item_list.GetItem(item_id);
  5418. if (!item) {
  5419. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5420. lua_interface->SetBooleanValue(state, false);
  5421. return 1;
  5422. }
  5423. Item* firstItem = new Item(item);
  5424. quest->AddTmpRewardItem(firstItem);
  5425. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5426. bool itemsAddedSuccessfully = true;
  5427. if(num_args > 4)
  5428. {
  5429. for(int8 n=5;n<num_args+1;n++)
  5430. {
  5431. int32 new_item = lua_interface->GetInt32Value(state, n);
  5432. Item* tmpItem = master_item_list.GetItem(new_item);
  5433. if(tmpItem)
  5434. {
  5435. Item* newTmpItem = new Item(tmpItem);
  5436. quest->AddTmpRewardItem(newTmpItem);
  5437. }
  5438. else
  5439. itemsAddedSuccessfully = false;
  5440. }
  5441. }
  5442. client->AddPendingQuestAcceptReward(quest);
  5443. client->DisplayQuestComplete(quest, true, description);
  5444. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5445. return 1;
  5446. }
  5447. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5448. if (!lua_interface)
  5449. return 0;
  5450. Quest* quest = lua_interface->GetQuest(state);
  5451. if (!quest) {
  5452. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5453. return 0;
  5454. }
  5455. quest->SetRepeatable(true);
  5456. return 0;
  5457. }
  5458. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5459. if (!lua_interface)
  5460. return 0;
  5461. Spawn* spawn = lua_interface->GetSpawn(state);
  5462. if (!spawn) {
  5463. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5464. return 0;
  5465. }
  5466. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5467. string ret = classes.GetClassNameCase(base_class);
  5468. if (ret.length() > 0) {
  5469. lua_interface->SetStringValue(state, ret.c_str());
  5470. return 1;
  5471. }
  5472. return 0;
  5473. }
  5474. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5475. if (!lua_interface)
  5476. return 0;
  5477. Spawn* player = lua_interface->GetSpawn(state);
  5478. if (player && player->IsPlayer()) {
  5479. Client* client = player->GetClient();
  5480. if (client)
  5481. client->SendWaypoints();
  5482. }
  5483. return 0;
  5484. }
  5485. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5486. if (!lua_interface)
  5487. return 0;
  5488. Spawn* player = lua_interface->GetSpawn(state);
  5489. string name = lua_interface->GetStringValue(state, 2);
  5490. int32 type = lua_interface->GetInt32Value(state, 3);
  5491. if (type == 0)
  5492. type = 2;
  5493. if (name.length() > 0) {
  5494. if (player && player->IsPlayer()) {
  5495. Client* client = player->GetClient();
  5496. if (client)
  5497. client->AddWaypoint(name, type);
  5498. }
  5499. }
  5500. return 0;
  5501. }
  5502. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5503. if (!lua_interface)
  5504. return 0;
  5505. Spawn* player = lua_interface->GetSpawn(state);
  5506. string name = lua_interface->GetStringValue(state, 2);
  5507. if (name.length() > 0) {
  5508. if (player && player->IsPlayer()) {
  5509. Client* client = player->GetClient();
  5510. if (client)
  5511. client->RemoveWaypoint(name);
  5512. }
  5513. }
  5514. return 0;
  5515. }
  5516. int EQ2Emu_lua_AddWard(lua_State* state) {
  5517. if (!lua_interface)
  5518. return 0;
  5519. int32 damage = lua_interface->GetInt32Value(state);
  5520. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5521. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5522. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5523. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5524. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5525. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5526. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5527. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5528. bool ward_was_added = false;
  5529. ZoneServer* zone = spell->caster->GetZone();
  5530. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5531. for (int32 i = 0; i < spell->targets.size(); i++) {
  5532. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5533. if (!target)
  5534. continue;
  5535. if (target->IsEntity()) {
  5536. // If the ward is already active remove it
  5537. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5538. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5539. // Create new ward info
  5540. WardInfo* ward = new WardInfo;
  5541. ward->Spell = spell;
  5542. ward->BaseDamage = damage;
  5543. ward->DamageLeft = damage;
  5544. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5545. ward->keepWard = keepWard;
  5546. ward->WardType = wardType;
  5547. if (damageAbsorptionPercent > 100)
  5548. damageAbsorptionPercent = 100;
  5549. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5550. if (damageAbsorptionMaxHealthPercent > 100)
  5551. damageAbsorptionMaxHealthPercent = 100;
  5552. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5553. ward->RedirectDamagePercent = redirectDamagePercent;
  5554. ward->LastRedirectDamage = 0;
  5555. ward->LastAbsorbedDamage = 0;
  5556. ward->HitCount = 0;
  5557. spell->num_triggers = maxHitCount;
  5558. spell->had_triggers = true;
  5559. spell->cancel_after_all_triggers = false;
  5560. ward->MaxHitCount = maxHitCount;
  5561. if (wardType == WARD_TYPE_MAGICAL)
  5562. ward->DamageType = damageTypes;
  5563. // Add the ward to the entity
  5564. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5565. ward_was_added = true;
  5566. }
  5567. }
  5568. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5569. if (ward_was_added && spell->caster->IsPlayer()) {
  5570. spell->had_dmg_remaining = true;
  5571. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5572. }
  5573. return 0;
  5574. }
  5575. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5576. if (!lua_interface)
  5577. return 0;
  5578. int32 amount = lua_interface->GetInt32Value(state);
  5579. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5580. WardInfo* ward = 0;
  5581. ZoneServer* zone = spell->caster->GetZone();
  5582. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5583. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5584. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5585. ward = target->GetWard(spell->spell->GetSpellID());
  5586. if (target && ward) {
  5587. ward->DamageLeft += amount;
  5588. if (ward->DamageLeft > ward->BaseDamage)
  5589. ward->DamageLeft = ward->BaseDamage;
  5590. for (int32 i = 0; i < spell->targets.size(); i++) {
  5591. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5592. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5593. }
  5594. }
  5595. }
  5596. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5597. if (ward && spell->caster->IsPlayer())
  5598. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5599. return 0;
  5600. }
  5601. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5602. if (!lua_interface)
  5603. return 0;
  5604. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5605. if (!spell) {
  5606. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5607. return 0;
  5608. }
  5609. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5610. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5611. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5612. if (ward) {
  5613. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5614. return 1;
  5615. }
  5616. }
  5617. return 0;
  5618. }
  5619. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5620. if (!lua_interface)
  5621. return 0;
  5622. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5623. if (!spell) {
  5624. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5625. return 0;
  5626. }
  5627. string type = lua_interface->GetStringValue(state, 2);
  5628. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5629. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5630. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5631. if (ward) {
  5632. if (boost::iequals(type, "damageleft"))
  5633. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5634. else if (boost::iequals(type, "basedamage"))
  5635. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5636. else if (boost::iequals(type, "keepward"))
  5637. lua_interface->SetBooleanValue(state, ward->keepWard);
  5638. else if (boost::iequals(type, "wardtype"))
  5639. lua_interface->SetInt32Value(state, ward->WardType);
  5640. else if (boost::iequals(type, "dmgabsorptionpct"))
  5641. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5642. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5643. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5644. else if (boost::iequals(type, "redirectdamagepercent"))
  5645. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5646. else if (boost::iequals(type, "lastredirectdamage"))
  5647. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5648. else if (boost::iequals(type, "lastabsorbeddamage"))
  5649. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5650. else if (boost::iequals(type, "hitcount"))
  5651. lua_interface->SetInt32Value(state, ward->HitCount);
  5652. else if (boost::iequals(type, "maxhitcount"))
  5653. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5654. else
  5655. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5656. return 1;
  5657. }
  5658. }
  5659. return 0;
  5660. }
  5661. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5662. if (!lua_interface)
  5663. return 0;
  5664. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5665. ZoneServer* zone = spell->caster->GetZone();
  5666. Spawn* target = 0;
  5667. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5668. for (int32 i = 0; i < spell->targets.size(); i++) {
  5669. target = zone->GetSpawnByID(spell->targets.at(i));
  5670. if (target && target->IsEntity()) {
  5671. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5672. }
  5673. }
  5674. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5675. return 0;
  5676. }
  5677. int EQ2Emu_lua_Interrupt(lua_State* state)
  5678. {
  5679. if (!lua_interface)
  5680. return 0;
  5681. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5682. Spawn* target = lua_interface->GetSpawn(state, 2);
  5683. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5684. if (!caster)
  5685. {
  5686. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5687. return 0;
  5688. }
  5689. if (!target)
  5690. {
  5691. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5692. return 0;
  5693. }
  5694. if (!spell) {
  5695. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5696. return 0;
  5697. }
  5698. if (!target->IsEntity() && !spell)
  5699. {
  5700. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5701. return 0;
  5702. }
  5703. if (!target && spell) {
  5704. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5705. for (int8 i = 0; i < spell->targets.size(); i++) {
  5706. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5707. if (!target || !target->IsEntity())
  5708. continue;
  5709. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5710. }
  5711. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5712. }
  5713. else
  5714. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5715. return 0;
  5716. }
  5717. int EQ2Emu_lua_Stealth(lua_State* state) {
  5718. if (!lua_interface)
  5719. return 0;
  5720. int8 type = lua_interface->GetInt8Value(state);
  5721. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5722. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5723. if (!spell) {
  5724. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5725. return 0;
  5726. }
  5727. ZoneServer* zone = spell->caster->GetZone();
  5728. if (spawn) {
  5729. if (spawn->IsEntity()) {
  5730. if (type == 1) {
  5731. ((Entity*)spawn)->AddStealthSpell(spell);
  5732. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5733. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5734. }
  5735. else if (type == 2) {
  5736. ((Entity*)spawn)->AddInvisSpell(spell);
  5737. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5738. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5739. }
  5740. return 0;
  5741. }
  5742. else {
  5743. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5744. return 0;
  5745. }
  5746. }
  5747. else {
  5748. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5749. for (int32 i = 0; i < spell->targets.size(); i++) {
  5750. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5751. if (!spawn || !spawn->IsEntity())
  5752. continue;
  5753. if (type == 1) {
  5754. ((Entity*)spawn)->AddStealthSpell(spell);
  5755. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5756. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5757. }
  5758. else if (type == 2) {
  5759. ((Entity*)spawn)->AddInvisSpell(spell);
  5760. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5761. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5762. }
  5763. else {
  5764. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5765. break;
  5766. }
  5767. }
  5768. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5769. }
  5770. return 0;
  5771. }
  5772. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5773. if (!lua_interface)
  5774. return 0;
  5775. Spawn* spawn = lua_interface->GetSpawn(state);
  5776. if (!spawn) {
  5777. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. if (spawn->IsEntity()) {
  5781. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5782. return 1;
  5783. }
  5784. else
  5785. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5786. return 0;
  5787. }
  5788. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5789. if (!lua_interface)
  5790. return 0;
  5791. Spawn* spawn = lua_interface->GetSpawn(state);
  5792. if (!spawn) {
  5793. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5794. return 0;
  5795. }
  5796. if (spawn->IsEntity()) {
  5797. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5798. return 1;
  5799. }
  5800. else
  5801. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5802. return 0;
  5803. }
  5804. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5805. if (!lua_interface)
  5806. return 0;
  5807. Spawn* player = lua_interface->GetSpawn(state);
  5808. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5809. lua_interface->ResetFunctionStack(state);
  5810. if (!player->IsPlayer()) {
  5811. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5812. return 0;
  5813. }
  5814. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5815. return 1;
  5816. }
  5817. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5818. if (!lua_interface)
  5819. return 0;
  5820. Spawn* player = lua_interface->GetSpawn(state);
  5821. int8 slot = lua_interface->GetInt8Value(state, 2);
  5822. lua_interface->ResetFunctionStack(state);
  5823. if (!player) {
  5824. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5825. return 0;
  5826. }
  5827. if (!player->IsPlayer()) {
  5828. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5829. return 0;
  5830. }
  5831. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5832. if (!item) {
  5833. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5834. return 0;
  5835. }
  5836. lua_interface->SetItemValue(state, item);
  5837. return 1;
  5838. }
  5839. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5840. if (!lua_interface)
  5841. return 0;
  5842. Spawn* player = lua_interface->GetSpawn(state);
  5843. int32 id = lua_interface->GetInt32Value(state, 2);
  5844. lua_interface->ResetFunctionStack(state);
  5845. if (!player) {
  5846. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5847. return 0;
  5848. }
  5849. if (!player->IsPlayer()) {
  5850. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5851. return 0;
  5852. }
  5853. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5854. if (!item) {
  5855. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5856. return 0;
  5857. }
  5858. lua_interface->SetItemValue(state, item);
  5859. return 1;
  5860. }
  5861. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5862. if (!lua_interface)
  5863. return 0;
  5864. Spawn* spawn = lua_interface->GetSpawn(state);
  5865. int8 slot = lua_interface->GetInt8Value(state, 2);
  5866. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5867. lua_interface->ResetFunctionStack(state);
  5868. if (!spawn) {
  5869. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5870. return 0;
  5871. }
  5872. if (!spawn->IsEntity()) {
  5873. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5874. return 0;
  5875. }
  5876. Item* item = master_item_list.GetItem(item_id);
  5877. if (!item) {
  5878. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5879. return 0;
  5880. }
  5881. Item* copy = new Item(item);
  5882. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5883. if(result)
  5884. {
  5885. ((Entity*)spawn)->SetEquipment(copy, slot);
  5886. spawn->vis_changed = true;
  5887. if(spawn->IsPlayer())
  5888. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5889. }
  5890. else
  5891. {
  5892. safe_delete(copy);
  5893. }
  5894. lua_interface->SetBooleanValue(state, result);
  5895. return 1;
  5896. }
  5897. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5898. if (!lua_interface)
  5899. return 0;
  5900. Spawn* spawn = lua_interface->GetSpawn(state);
  5901. int8 slot = lua_interface->GetInt8Value(state, 2);
  5902. Item* item = lua_interface->GetItem(state, 3);
  5903. lua_interface->ResetFunctionStack(state);
  5904. if (!spawn) {
  5905. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5906. return 0;
  5907. }
  5908. if (!spawn->IsEntity()) {
  5909. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5910. return 0;
  5911. }
  5912. if (!item) {
  5913. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5914. return 0;
  5915. }
  5916. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5917. if(result)
  5918. {
  5919. ((Entity*)spawn)->SetEquipment(item, slot);
  5920. spawn->vis_changed = true;
  5921. if(spawn->IsPlayer())
  5922. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5923. }
  5924. lua_interface->SetBooleanValue(state, result);
  5925. return 1;
  5926. }
  5927. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5928. if (!lua_interface)
  5929. return 0;
  5930. Spawn* spawn = lua_interface->GetSpawn(state);
  5931. int8 slot = lua_interface->GetInt8Value(state, 2);
  5932. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5933. lua_interface->ResetFunctionStack(state);
  5934. if (!spawn) {
  5935. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5936. return 0;
  5937. }
  5938. if (!spawn->IsEntity()) {
  5939. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5940. return 0;
  5941. }
  5942. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5943. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5944. spawn->vis_changed = true;
  5945. if(spawn->IsPlayer())
  5946. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5947. lua_interface->SetBooleanValue(state, true);
  5948. return 1;
  5949. }
  5950. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5951. if (!lua_interface)
  5952. return 0;
  5953. Spawn* spawn = lua_interface->GetSpawn(state);
  5954. int8 slot = lua_interface->GetInt8Value(state, 2);
  5955. int16 type = lua_interface->GetInt16Value(state, 3);
  5956. int8 r = lua_interface->GetInt8Value(state, 4);
  5957. int8 g = lua_interface->GetInt8Value(state, 5);
  5958. int8 b = lua_interface->GetInt8Value(state, 6);
  5959. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5960. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5961. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5962. lua_interface->ResetFunctionStack(state);
  5963. if (!spawn) {
  5964. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5965. return 0;
  5966. }
  5967. if (!spawn->IsEntity()) {
  5968. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5969. return 0;
  5970. }
  5971. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5972. spawn->vis_changed = true;
  5973. lua_interface->SetBooleanValue(state, true);
  5974. return 1;
  5975. }
  5976. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5977. if (!lua_interface)
  5978. return 0;
  5979. Spawn* player = lua_interface->GetSpawn(state);
  5980. int32 id = lua_interface->GetInt32Value(state, 2);
  5981. int8 count = lua_interface->GetInt8Value(state, 3);
  5982. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5983. lua_interface->ResetFunctionStack(state);
  5984. if (!player) {
  5985. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5986. return 0;
  5987. }
  5988. if (!player->IsPlayer()) {
  5989. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5990. return 0;
  5991. }
  5992. if (!count)
  5993. count = 1;
  5994. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5995. if (!item) {
  5996. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5997. return 0;
  5998. }
  5999. lua_interface->SetItemValue(state, item);
  6000. return 1;
  6001. }
  6002. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6003. if (!lua_interface)
  6004. return 0;
  6005. Spawn* spawn = lua_interface->GetSpawn(state);
  6006. int32 anim = lua_interface->GetInt32Value(state, 2);
  6007. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6008. int8 type = lua_interface->GetInt8Value(state, 4);
  6009. if (!spawn) {
  6010. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6011. return 0;
  6012. }
  6013. if (spawn2) {
  6014. if (spawn2->IsPlayer()) {
  6015. if (type != 1 && type != 2)
  6016. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6017. else
  6018. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6019. return 0;
  6020. }
  6021. else {
  6022. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6023. return 0;
  6024. }
  6025. }
  6026. else
  6027. spawn->GetZone()->PlayAnimation(spawn, anim);
  6028. return 0;
  6029. }
  6030. int EQ2Emu_lua_IsPet(lua_State* state) {
  6031. if (!lua_interface)
  6032. return 0;
  6033. Spawn* spawn = lua_interface->GetSpawn(state);
  6034. if (!spawn) {
  6035. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6036. return 0;
  6037. }
  6038. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6039. return 1;
  6040. }
  6041. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6042. if (!lua_interface)
  6043. return 0;
  6044. Spawn* spawn = lua_interface->GetSpawn(state);
  6045. if (!spawn) {
  6046. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6047. return 0;
  6048. }
  6049. if (!spawn->IsNPC()) {
  6050. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6051. return 0;
  6052. }
  6053. if (((NPC*)spawn)->GetOwner()) {
  6054. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6055. return 1;
  6056. }
  6057. return 0;
  6058. }
  6059. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6060. if (!lua_interface)
  6061. return 0;
  6062. Spawn* spawn = lua_interface->GetSpawn(state);
  6063. Spawn* target = lua_interface->GetSpawn(state, 2);
  6064. if (!spawn) {
  6065. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6066. return 0;
  6067. }
  6068. if (!spawn) {
  6069. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6070. return 0;
  6071. }
  6072. spawn->SetTarget(target);
  6073. return 0;
  6074. }
  6075. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6076. if (!lua_interface)
  6077. return 0;
  6078. Spawn* spawn = lua_interface->GetSpawn(state);
  6079. bool val = lua_interface->GetBooleanValue(state, 2);
  6080. if (!spawn) {
  6081. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6082. return 0;
  6083. }
  6084. if (!spawn->IsEntity()) {
  6085. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6086. return 0;
  6087. }
  6088. ((Entity*)spawn)->InCombat(val);
  6089. if (val) {
  6090. spawn->ClearRunningLocations();
  6091. spawn->CalculateRunningLocation(true);
  6092. }
  6093. return 0;
  6094. }
  6095. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6096. if (!lua_interface)
  6097. return 0;
  6098. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6099. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6100. if (!spawn1) {
  6101. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6102. return 0;
  6103. }
  6104. if (!spawn2) {
  6105. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6106. return 0;
  6107. }
  6108. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6109. return 1;
  6110. }
  6111. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6112. if (!lua_interface)
  6113. return 0;
  6114. Spawn* spawn = lua_interface->GetSpawn(state);
  6115. if (!spawn) {
  6116. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6117. return 0;
  6118. }
  6119. if (!spawn->IsNPC()) {
  6120. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6121. return 0;
  6122. }
  6123. ((NPC*)spawn)->ClearRunback();
  6124. return 0;
  6125. }
  6126. int EQ2Emu_lua_Runback(lua_State* state) {
  6127. if (!lua_interface)
  6128. return 0;
  6129. Spawn* spawn = lua_interface->GetSpawn(state);
  6130. if (!spawn) {
  6131. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6132. return 0;
  6133. }
  6134. if (!spawn->IsNPC()) {
  6135. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. ((NPC*)spawn)->Runback();
  6139. return 0;
  6140. }
  6141. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6142. if (!lua_interface)
  6143. return 0;
  6144. Spawn* spawn = lua_interface->GetSpawn(state);
  6145. if (!spawn) {
  6146. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6147. return 0;
  6148. }
  6149. if (!spawn->IsNPC()) {
  6150. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6151. return 0;
  6152. }
  6153. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6154. return 1;
  6155. }
  6156. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6157. if (!lua_interface)
  6158. return 0;
  6159. Spawn* spawn = lua_interface->GetSpawn(state);
  6160. if (!spawn) {
  6161. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. if (!spawn->IsEntity()) {
  6165. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6169. return 1;
  6170. }
  6171. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6172. if (!lua_interface)
  6173. return 0;
  6174. Spawn* spawn = lua_interface->GetSpawn(state);
  6175. if (!spawn) {
  6176. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6177. return 0;
  6178. }
  6179. if (!spawn->IsEntity()) {
  6180. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6181. return 0;
  6182. }
  6183. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6184. return 1;
  6185. }
  6186. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6187. if (!lua_interface)
  6188. return 0;
  6189. Spawn* spawn = lua_interface->GetSpawn(state);
  6190. if (!spawn) {
  6191. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6192. return 0;
  6193. }
  6194. if (!spawn->IsEntity()) {
  6195. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6196. return 0;
  6197. }
  6198. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6199. return 1;
  6200. }
  6201. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6202. if (!lua_interface)
  6203. return 0;
  6204. Spawn* spawn = lua_interface->GetSpawn(state);
  6205. if (!spawn) {
  6206. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6207. return 0;
  6208. }
  6209. if (!spawn->IsEntity()) {
  6210. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6211. return 0;
  6212. }
  6213. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6214. return 1;
  6215. }
  6216. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6217. if (!lua_interface)
  6218. return 0;
  6219. Spawn* spawn = lua_interface->GetSpawn(state);
  6220. Spawn* target = lua_interface->GetSpawn(state, 2);
  6221. float distance = lua_interface->GetFloatValue(state, 3);
  6222. if (!spawn) {
  6223. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6224. return 0;
  6225. }
  6226. if (!target) {
  6227. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6228. return 0;
  6229. }
  6230. if (!spawn->IsNPC()) {
  6231. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6232. return 0;
  6233. }
  6234. if (!target->IsEntity()) {
  6235. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6239. return 1;
  6240. }
  6241. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6242. if (!lua_interface)
  6243. return 0;
  6244. Spawn* spawn = lua_interface->GetSpawn(state);
  6245. Spawn* target = lua_interface->GetSpawn(state, 2);
  6246. float distance = lua_interface->GetFloatValue(state, 3);
  6247. if (!spawn) {
  6248. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6249. return 0;
  6250. }
  6251. if (!target) {
  6252. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6253. return 0;
  6254. }
  6255. if (!spawn->IsNPC()) {
  6256. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6257. return 0;
  6258. }
  6259. if (!target->IsEntity()) {
  6260. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6261. return 0;
  6262. }
  6263. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6264. return 0;
  6265. }
  6266. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6267. if (!lua_interface)
  6268. return 0;
  6269. Spawn* spawn = lua_interface->GetSpawn(state);
  6270. if (!spawn) {
  6271. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6272. return 0;
  6273. }
  6274. if (!spawn->IsNPC()) {
  6275. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6276. return 0;
  6277. }
  6278. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6279. return 1;
  6280. }
  6281. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6282. if (!lua_interface)
  6283. return 0;
  6284. Spawn* spawn = lua_interface->GetSpawn(state);
  6285. if (!spawn) {
  6286. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6287. return 0;
  6288. }
  6289. if (!spawn->IsNPC()) {
  6290. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6294. return 1;
  6295. }
  6296. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6297. if (!lua_interface)
  6298. return 0;
  6299. Spawn* spawn = lua_interface->GetSpawn(state);
  6300. if (!spawn) {
  6301. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6302. return 0;
  6303. }
  6304. if (!spawn->IsNPC()) {
  6305. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6306. return 0;
  6307. }
  6308. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6309. if (hated) {
  6310. lua_interface->SetSpawnValue(state, hated);
  6311. return 1;
  6312. }
  6313. return 0;
  6314. }
  6315. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6316. if (!lua_interface)
  6317. return 0;
  6318. Spawn* spawn = lua_interface->GetSpawn(state);
  6319. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6320. if (!spawn) {
  6321. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6322. return 0;
  6323. }
  6324. if (!spawn->IsNPC()) {
  6325. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6326. return 0;
  6327. }
  6328. if (!hated) {
  6329. ((NPC*)spawn)->Brain()->ClearHate();
  6330. return 0;
  6331. }
  6332. else
  6333. {
  6334. if (!hated->IsEntity()) {
  6335. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6336. return 0;
  6337. }
  6338. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6339. return 0;
  6340. }
  6341. return 0;
  6342. }
  6343. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6344. if (!lua_interface)
  6345. return 0;
  6346. Spawn* spawn = lua_interface->GetSpawn(state);
  6347. if (!spawn) {
  6348. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6349. return 0;
  6350. }
  6351. if (!spawn->IsNPC()) {
  6352. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6353. return 0;
  6354. }
  6355. ((NPC*)spawn)->Brain()->ClearEncounter();
  6356. return 0;
  6357. }
  6358. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6359. if (!lua_interface)
  6360. return 0;
  6361. Spawn* spawn = lua_interface->GetSpawn(state);
  6362. if (!spawn) {
  6363. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6364. return 0;
  6365. }
  6366. if (!spawn->IsNPC()) {
  6367. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6368. return 0;
  6369. }
  6370. // Temp list to store hate list
  6371. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6372. if (encounterList->size() == 0) {
  6373. safe_delete(encounterList);
  6374. return 0;
  6375. }
  6376. lua_createtable(state, encounterList->size(), 0);
  6377. int newTable = lua_gettop(state);
  6378. for (int32 i = 0; i < encounterList->size(); i++) {
  6379. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6380. if (temp)
  6381. lua_interface->SetSpawnValue(state, temp);
  6382. lua_rawseti(state, newTable, i + 1);
  6383. }
  6384. safe_delete(encounterList);
  6385. return 1;
  6386. }
  6387. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6388. if (!lua_interface)
  6389. return 0;
  6390. Spawn* spawn = lua_interface->GetSpawn(state);
  6391. if (!spawn) {
  6392. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6393. return 0;
  6394. }
  6395. if (!spawn->IsNPC()) {
  6396. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6397. return 0;
  6398. }
  6399. // Temp list to store hate list
  6400. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6401. if (hateList->size() == 0) {
  6402. safe_delete(hateList);
  6403. return 0;
  6404. }
  6405. lua_createtable(state, hateList->size(), 0);
  6406. int newTable = lua_gettop(state);
  6407. for (int32 i = 0; i < hateList->size(); i++) {
  6408. lua_interface->SetSpawnValue(state, hateList->at(i));
  6409. lua_rawseti(state, newTable, i + 1);
  6410. }
  6411. safe_delete(hateList);
  6412. return 1;
  6413. }
  6414. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6415. if (!lua_interface)
  6416. return 0;
  6417. Spawn* spawn = lua_interface->GetSpawn(state);
  6418. if (!spawn) {
  6419. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6420. return 0;
  6421. }
  6422. if (spawn->IsPlayer()) {
  6423. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6424. lua_interface->SetBooleanValue(state, true);
  6425. else
  6426. lua_interface->SetBooleanValue(state, false);
  6427. return 1;
  6428. }
  6429. else {
  6430. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6431. return 1;
  6432. }
  6433. }
  6434. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6435. if (!lua_interface)
  6436. return 0;
  6437. Quest* quest = lua_interface->GetQuest(state);
  6438. if (!quest) {
  6439. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6440. return 0;
  6441. }
  6442. quest->SetCompletedFlag(true);
  6443. return 0;
  6444. }
  6445. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6446. if (!lua_interface)
  6447. return 0;
  6448. Spawn* spawn = lua_interface->GetSpawn(state);
  6449. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6450. int8 tier = lua_interface->GetInt8Value(state, 3);
  6451. if (!spawn) {
  6452. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6453. return 0;
  6454. }
  6455. if (!spawn->IsEntity()) {
  6456. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6457. return 0;
  6458. }
  6459. if (spellID == 0) {
  6460. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6461. return 0;
  6462. }
  6463. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6464. if (effect) {
  6465. if (tier > 0) {
  6466. // If a tier was passed chec to see if it is the same as the effect
  6467. if (tier == effect->tier)
  6468. lua_interface->SetBooleanValue(state, true);
  6469. else
  6470. lua_interface->SetBooleanValue(state, false);
  6471. return 1;
  6472. }
  6473. else {
  6474. // Have an effect but no tier was passed so return true
  6475. lua_interface->SetBooleanValue(state, true);
  6476. }
  6477. return 1;
  6478. }
  6479. // no effect so return false
  6480. lua_interface->SetBooleanValue(state, false);
  6481. return 1;
  6482. }
  6483. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6484. if (!lua_interface)
  6485. return 0;
  6486. Spawn* spawn = lua_interface->GetSpawn(state);
  6487. int32 id = lua_interface->GetInt32Value(state, 2);
  6488. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6489. Spawn* spawn2 = 0;
  6490. vector<Spawn*> list;
  6491. if (!spawn) {
  6492. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6493. return 0;
  6494. }
  6495. //If zone not provided, use spawn's zone
  6496. if (!zone)
  6497. zone = spawn->GetZone();
  6498. list = zone->GetSpawnsByID(id);
  6499. if (list.size() == 0) {
  6500. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6501. return 0;
  6502. }
  6503. vector<Spawn*>::iterator itr = list.begin();
  6504. for (int8 i = 0; i < list.size(); i++) {
  6505. spawn2 = itr[i];
  6506. if (spawn2)
  6507. spawn2->AddAllowAccessSpawn(spawn);
  6508. }
  6509. return 0;
  6510. }
  6511. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6512. if (!lua_interface)
  6513. return 0;
  6514. Spawn* spawn = lua_interface->GetSpawn(state);
  6515. int32 id = lua_interface->GetInt32Value(state, 2);
  6516. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6517. Spawn* spawn2 = 0;
  6518. if (!spawn) {
  6519. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6520. return 0;
  6521. }
  6522. //If zone not provided, use spawn's zone
  6523. if (!zone)
  6524. zone = spawn->GetZone();
  6525. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6526. vector<Spawn*>::iterator itr = list.begin();
  6527. if (list.size() == 0) {
  6528. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6529. return 0;
  6530. }
  6531. for (int8 i = 0; i < list.size(); i++) {
  6532. spawn2 = itr[i];
  6533. if (spawn2)
  6534. spawn2->RemoveSpawnAccess(spawn);
  6535. }
  6536. return 0;
  6537. }
  6538. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6539. if (!lua_interface)
  6540. return 0;
  6541. Quest* quest = lua_interface->GetQuest(state);
  6542. if (!quest) {
  6543. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6544. return 0;
  6545. }
  6546. quest->SetYellowName(true);
  6547. return 0;
  6548. }
  6549. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6550. if (!lua_interface)
  6551. return 0;
  6552. Spawn* spawn = lua_interface->GetSpawn(state);
  6553. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6554. if (!spawn) {
  6555. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6556. return 0;
  6557. }
  6558. if (!spawn->IsPlayer()) {
  6559. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6560. return 0;
  6561. }
  6562. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6563. return 1;
  6564. }
  6565. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6566. if (!lua_interface)
  6567. return 0;
  6568. Spawn* spawn = lua_interface->GetSpawn(state);
  6569. if (!spawn) {
  6570. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6571. return 0;
  6572. }
  6573. if (!spawn->IsPlayer()) {
  6574. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6575. return 0;
  6576. }
  6577. ZoneServer* zone = spawn->GetZone();
  6578. if (!zone) {
  6579. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6580. return 0;
  6581. }
  6582. Instance_Type iType = zone->GetInstanceType();
  6583. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6584. iType == GROUP_LOCKOUT_INSTANCE ||
  6585. iType == RAID_LOCKOUT_INSTANCE ||
  6586. iType == SOLO_PERSIST_INSTANCE ||
  6587. iType == GROUP_PERSIST_INSTANCE ||
  6588. iType == RAID_PERSIST_INSTANCE) {
  6589. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6590. if (data) {
  6591. // Check to see if the timer has already been set, if it has return out.
  6592. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6593. return 0;
  6594. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6595. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6596. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6597. if (client) {
  6598. string time_msg = "";
  6599. int32 time = data->success_lockout_time;
  6600. int16 hour;
  6601. int8 min;
  6602. int8 sec;
  6603. hour = time / 3600;
  6604. time = time % 3600;
  6605. min = time / 60;
  6606. time = time % 60;
  6607. sec = time;
  6608. if (hour > 0) {
  6609. char temp[10];
  6610. sprintf(temp, " %i", hour);
  6611. time_msg.append(temp);
  6612. time_msg.append(" hour");
  6613. time_msg.append((hour > 1) ? "s" : "");
  6614. }
  6615. if (min > 0) {
  6616. char temp[5];
  6617. sprintf(temp, " %i", min);
  6618. time_msg.append(temp);
  6619. time_msg.append(" minute");
  6620. time_msg.append((min > 1) ? "s" : "");
  6621. }
  6622. // Only add seconds if minutes and hours are 0
  6623. if (hour == 0 && min == 0 && sec > 0) {
  6624. char temp[5];
  6625. sprintf(temp, " %i", sec);
  6626. time_msg.append(temp);
  6627. time_msg.append(" second");
  6628. time_msg.append((sec > 1) ? "s" : "");
  6629. }
  6630. 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());
  6631. }
  6632. }
  6633. else
  6634. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6635. }
  6636. else
  6637. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6638. return 0;
  6639. }
  6640. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6641. if (!lua_interface)
  6642. return 0;
  6643. Spawn* spawn = lua_interface->GetSpawn(state);
  6644. if (!spawn) {
  6645. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6646. return 0;
  6647. }
  6648. if (!spawn->IsPlayer()) {
  6649. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6650. return 0;
  6651. }
  6652. ZoneServer* zone = spawn->GetZone();
  6653. if (!zone) {
  6654. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6655. return 0;
  6656. }
  6657. Instance_Type iType = zone->GetInstanceType();
  6658. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6659. iType == GROUP_LOCKOUT_INSTANCE ||
  6660. iType == RAID_LOCKOUT_INSTANCE ||
  6661. iType == SOLO_PERSIST_INSTANCE ||
  6662. iType == GROUP_PERSIST_INSTANCE ||
  6663. iType == RAID_PERSIST_INSTANCE) {
  6664. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6665. if (data) {
  6666. // Check to see if the timer has already been set, if it has return out.
  6667. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6668. return 0;
  6669. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6670. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6671. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6672. if (client) {
  6673. string time_msg = "";
  6674. int32 time = data->failure_lockout_time;
  6675. int16 hour;
  6676. int8 min;
  6677. int8 sec;
  6678. hour = time / 3600;
  6679. time = time % 3600;
  6680. min = time / 60;
  6681. time = time % 60;
  6682. sec = time;
  6683. if (hour > 0) {
  6684. char temp[10];
  6685. sprintf(temp, " %i", hour);
  6686. time_msg.append(temp);
  6687. time_msg.append(" hour");
  6688. time_msg.append((hour > 1) ? "s" : "");
  6689. }
  6690. if (min > 0) {
  6691. char temp[5];
  6692. sprintf(temp, " %i", min);
  6693. time_msg.append(temp);
  6694. time_msg.append(" minute");
  6695. time_msg.append((min > 1) ? "s" : "");
  6696. }
  6697. // Only add seconds if minutes and hours are 0
  6698. if (hour == 0 && min == 0 && sec > 0) {
  6699. char temp[5];
  6700. sprintf(temp, " %i", sec);
  6701. time_msg.append(temp);
  6702. time_msg.append(" second");
  6703. time_msg.append((sec > 1) ? "s" : "");
  6704. }
  6705. 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());
  6706. }
  6707. }
  6708. else
  6709. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6710. }
  6711. else
  6712. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6713. return 0;
  6714. }
  6715. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6716. if (!lua_interface)
  6717. return 0;
  6718. Spawn* spawn = lua_interface->GetSpawn(state);
  6719. if (!spawn) {
  6720. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6721. return 0;
  6722. }
  6723. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6724. return 1;
  6725. }
  6726. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6727. if (!lua_interface)
  6728. return 0;
  6729. Spawn* player = lua_interface->GetSpawn(state);
  6730. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6731. if (!player) {
  6732. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6733. return 0;
  6734. }
  6735. if (!player->IsPlayer()) {
  6736. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6737. return 0;
  6738. }
  6739. if (!ground) {
  6740. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6741. return 0;
  6742. }
  6743. if (!ground->IsGroundSpawn()) {
  6744. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6745. return 0;
  6746. }
  6747. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6748. if (!groundspawn_entries) {
  6749. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6750. return 0;
  6751. }
  6752. Skill* skill = 0;
  6753. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6754. if (collection_skill == "Collecting")
  6755. skill = ((Player*)player)->GetSkillByName("Gathering");
  6756. else
  6757. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6758. if (!skill) {
  6759. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6760. return 0;
  6761. }
  6762. vector<GroundSpawnEntry*>::iterator itr;
  6763. GroundSpawnEntry* entry = 0;
  6764. bool can_harvest = false;
  6765. sint32 min_skill = -1;
  6766. int16 totalSkill = skill->current_val;
  6767. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6768. if(skillID != 0xFFFFFFFF)
  6769. {
  6770. ((Entity*)player)->MStats.lock();
  6771. totalSkill += ((Entity*)player)->stats[skillID];
  6772. ((Entity*)player)->MStats.unlock();
  6773. }
  6774. // first, iterate through groundspawn_entries, discard tables player cannot use
  6775. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6776. {
  6777. entry = *itr;
  6778. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6779. min_skill = entry->min_skill_level;
  6780. // if player lacks skill, skip table
  6781. if (entry->min_skill_level > totalSkill)
  6782. continue;
  6783. // if bonus, but player lacks level, skip table
  6784. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6785. continue;
  6786. can_harvest = true;
  6787. break;
  6788. }
  6789. lua_interface->SetBooleanValue(state, can_harvest);
  6790. // If false, send the message to the client
  6791. if (!can_harvest) {
  6792. Client* client = player->GetZone()->GetClientBySpawn(player);
  6793. if (client) {
  6794. string msg = "You do not have enough skill to ";
  6795. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6796. msg.append("gather");
  6797. else if (collection_skill == "Mining")
  6798. msg.append("mine");
  6799. else if (collection_skill == "Trapping")
  6800. msg.append("trap");
  6801. else if (collection_skill == "Foresting")
  6802. msg.append("forest");
  6803. else if (collection_skill == "Fishing")
  6804. msg.append("catch");
  6805. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6806. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6807. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6808. }
  6809. }
  6810. return 1;
  6811. }
  6812. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6813. if (!lua_interface)
  6814. return 0;
  6815. Spawn* player = lua_interface->GetSpawn(state);
  6816. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6817. if (!player) {
  6818. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6819. return 0;
  6820. }
  6821. if (!player->IsPlayer()) {
  6822. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6823. return 0;
  6824. }
  6825. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6826. lua_interface->SetBooleanValue(state, ret);
  6827. return 1;
  6828. }
  6829. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6830. // Check to see if we have a valid lua_interface
  6831. if (!lua_interface)
  6832. return 0;
  6833. // Get the spawn that is getting the pet
  6834. Spawn* spawn = lua_interface->GetSpawn(state);
  6835. Spawn* target = lua_interface->GetSpawn(state, 2);
  6836. // Get the DB ID of the pet
  6837. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6838. float x = lua_interface->GetFloatValue(state, 4);
  6839. float y = lua_interface->GetFloatValue(state, 5);
  6840. float z = lua_interface->GetFloatValue(state, 6);
  6841. // Get the spell that this command was called from
  6842. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6843. // Check to make sure the spawn pointer is valid
  6844. if (!spawn) {
  6845. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6846. return 0;
  6847. }
  6848. // Check to make sure the spawn is an entity
  6849. if (!spawn->IsEntity()) {
  6850. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6851. return 0;
  6852. }
  6853. if (!target) {
  6854. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6855. return 0;
  6856. }
  6857. if (!target->IsEntity()) {
  6858. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6859. return 0;
  6860. }
  6861. // Check to see if the DB ID for the pet is set
  6862. if (pet_id == 0) {
  6863. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6864. return 0;
  6865. }
  6866. // Check to see if the pointer to the spell is valid
  6867. if (!luaspell) {
  6868. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6869. return 0;
  6870. }
  6871. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6872. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6873. if (!pet) {
  6874. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6875. return 0;
  6876. }
  6877. // Check to make sure the pet is an npc
  6878. if (!pet->IsNPC()) {
  6879. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6880. return 0;
  6881. }
  6882. if (x == 0)
  6883. x = spawn->GetX();
  6884. if (y == 0)
  6885. y = spawn->GetY();
  6886. if (z == 0)
  6887. z = spawn->GetZ();
  6888. // Spawn the pet at the same location as the owner
  6889. pet->SetX(x);
  6890. pet->SetY(y);
  6891. pet->SetZ(z);
  6892. pet->SetLocation(spawn->GetLocation());
  6893. pet->SetHeading(spawn->GetHeading());
  6894. spawn->GetZone()->AddSpawn(pet);
  6895. /*
  6896. const char* spawn_script = world.GetSpawnScript(pet_id);
  6897. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6898. spawn->SetSpawnScript(string(spawn_script));
  6899. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6900. }*/
  6901. // Get a random pet name
  6902. string random_pet_name;
  6903. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6904. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6905. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6906. // Set the pets name
  6907. pet->SetName(random_pet_name.c_str());
  6908. // Set the level of the pet to the owners level
  6909. pet->SetLevel(spawn->GetLevel());
  6910. // Set the faction of the pet to the same faction as the owner
  6911. pet->SetFactionID(spawn->GetFactionID());
  6912. // Set the spawn as a pet
  6913. pet->SetPet(true);
  6914. // Give a pointer of the owner to the pet
  6915. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6916. // Set the pet type
  6917. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6918. // Set the spell id used to create this pet
  6919. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6920. // Set the spell tier used to create this pet
  6921. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6922. // Set the pets spawn type to 6
  6923. pet->SetSpawnType(6);
  6924. // Set the pets brain
  6925. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6926. // Check to see if the pet has a subtitle
  6927. if (strlen(pet->GetSubTitle()) > 0) {
  6928. // Add the players name to the front of the sub title
  6929. string pet_subtitle;
  6930. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6931. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6932. // Set the pets subtitle to the new one
  6933. pet->SetSubTitle(pet_subtitle.c_str());
  6934. }
  6935. // Set the pet as the return value for this function
  6936. lua_interface->SetSpawnValue(state, pet);
  6937. return 1;
  6938. }
  6939. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6940. if (!lua_interface)
  6941. return 0;
  6942. Spawn* spawn = lua_interface->GetSpawn(state);
  6943. Spawn* player = lua_interface->GetSpawn(state, 2);
  6944. float max_distance = lua_interface->GetFloatValue(state, 3);
  6945. string type = lua_interface->GetStringValue(state, 4);
  6946. if (!spawn || (spawn && spawn->IsPlayer())) {
  6947. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6948. return 0;
  6949. }
  6950. if (!player || (player && !player->IsPlayer())) {
  6951. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6952. return 0;
  6953. }
  6954. Client* client = 0;
  6955. if (player->GetZone())
  6956. client = player->GetZone()->GetClientBySpawn(player);
  6957. if (!client) {
  6958. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6959. return 0;
  6960. }
  6961. //Set max_distance to default if not set or not proper value
  6962. if (max_distance <= 0)
  6963. max_distance = 500;
  6964. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6965. if (packet) {
  6966. float unknown2_3 = 0;
  6967. int8 placement_mode = 0;
  6968. if (type == "wall") {
  6969. placement_mode = 2;
  6970. unknown2_3 = 150;
  6971. }
  6972. else if (type == "ceiling")
  6973. placement_mode = 1;
  6974. packet->setDataByName("placement_mode", placement_mode);
  6975. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6976. packet->setDataByName("model_type", spawn->GetModelType());
  6977. packet->setDataByName("unknown", 1); //size
  6978. packet->setDataByName("unknown2", 1); //size 2
  6979. packet->setDataByName("unknown2", .5, 1); //size 3
  6980. packet->setDataByName("unknown2", 3, 2);
  6981. packet->setDataByName("unknown2", unknown2_3, 3);
  6982. packet->setDataByName("max_distance", max_distance);
  6983. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6984. client->QueuePacket(packet->serialize());
  6985. safe_delete(packet);
  6986. }
  6987. return 0;
  6988. }
  6989. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6990. if (!lua_interface)
  6991. return 0;
  6992. Item* item = lua_interface->GetItem(state);
  6993. if (!item) {
  6994. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6995. return 0;
  6996. }
  6997. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6998. return 1;
  6999. }
  7000. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7001. if (!lua_interface)
  7002. return 0;
  7003. Spawn* spawn = lua_interface->GetSpawn(state);
  7004. if (!spawn) {
  7005. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7006. return 0;
  7007. }
  7008. if (spawn->GetZone())
  7009. spawn->GetZone()->AddTransportSpawn(spawn);
  7010. return 0;
  7011. }
  7012. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7013. if (!lua_interface)
  7014. return 0;
  7015. Spawn* spawn = lua_interface->GetSpawn(state);
  7016. if (!spawn) {
  7017. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7018. return 0;
  7019. }
  7020. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7021. return 1;
  7022. }
  7023. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7024. if (!lua_interface)
  7025. return 0;
  7026. Skill* skill = lua_interface->GetSkill(state);
  7027. if (!skill) {
  7028. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7029. return 0;
  7030. }
  7031. lua_interface->SetInt32Value(state, skill->current_val);
  7032. return 1;
  7033. }
  7034. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7035. if (!lua_interface)
  7036. return 0;
  7037. Skill* skill = lua_interface->GetSkill(state);
  7038. if (!skill) {
  7039. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7040. return 0;
  7041. }
  7042. lua_interface->SetInt32Value(state, skill->max_val);
  7043. return 1;
  7044. }
  7045. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7046. if (!lua_interface)
  7047. return 0;
  7048. Skill* skill = lua_interface->GetSkill(state);
  7049. if (!skill) {
  7050. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7051. return 0;
  7052. }
  7053. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7054. return 1;
  7055. }
  7056. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7057. if (!lua_interface)
  7058. return 0;
  7059. Skill* skill = lua_interface->GetSkill(state);
  7060. int16 value = lua_interface->GetInt16Value(state, 2);
  7061. if (!skill) {
  7062. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7063. return 0;
  7064. }
  7065. skill->max_val = value;
  7066. if (skill->max_val < skill->current_val)
  7067. skill->current_val = skill->max_val;
  7068. return 0;
  7069. }
  7070. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7071. if (!lua_interface)
  7072. return 0;
  7073. Skill* skill = lua_interface->GetSkill(state);
  7074. int16 value = lua_interface->GetInt16Value(state, 2);
  7075. if (!skill) {
  7076. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7077. return 0;
  7078. }
  7079. if (value > skill->max_val)
  7080. skill->current_val = skill->max_val;
  7081. else
  7082. skill->current_val = value;
  7083. return 0;
  7084. }
  7085. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7086. if (!lua_interface)
  7087. return 0;
  7088. Spawn* player = lua_interface->GetSpawn(state);
  7089. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7090. if (skill_id > 0 && player && player->IsPlayer()) {
  7091. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7092. return 1;
  7093. }
  7094. return 0;
  7095. }
  7096. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7097. if (!lua_interface)
  7098. return 0;
  7099. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7100. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7101. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7102. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7103. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7104. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7105. if (player_spawn && player_spawn->IsPlayer()) {
  7106. Player* player = (Player*)player_spawn;
  7107. bool added = false;
  7108. if (!player->skill_list.HasSkill(skill_id)) {
  7109. player->AddSkill(skill_id, current_val, max_val, true);
  7110. added = true;
  7111. }
  7112. 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
  7113. Client* client = player->GetClient();
  7114. if (client) {
  7115. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7116. if (packet)
  7117. client->QueuePacket(packet);
  7118. }
  7119. }
  7120. if (added) {
  7121. lua_interface->SetBooleanValue(state, true);
  7122. return 1;
  7123. }
  7124. }
  7125. else {
  7126. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7127. }
  7128. }
  7129. else {
  7130. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7131. }
  7132. lua_interface->SetBooleanValue(state, false);
  7133. return 1;
  7134. }
  7135. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7136. if (!lua_interface)
  7137. return 0;
  7138. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7139. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7140. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7141. if (skill_id > 0) {
  7142. if (player_spawn && player_spawn->IsPlayer()) {
  7143. Player* player = (Player*)player_spawn;
  7144. if (player->skill_list.HasSkill(skill_id)) {
  7145. player->RemovePlayerSkill(skill_id);
  7146. if (!more_to_remove) {
  7147. Client* client = player->GetClient();
  7148. if (client) {
  7149. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7150. if (packet)
  7151. client->QueuePacket(packet);
  7152. }
  7153. }
  7154. }
  7155. }
  7156. else {
  7157. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7158. }
  7159. }
  7160. else {
  7161. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7162. }
  7163. return 0;
  7164. }
  7165. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7166. if (!lua_interface)
  7167. return 0;
  7168. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7169. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7170. int16 amount = lua_interface->GetInt8Value(state, 3);
  7171. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7172. if (amount > 0 && skill_type < 100) {
  7173. if (player_spawn && player_spawn->IsPlayer()) {
  7174. Player* player = (Player*)player_spawn;
  7175. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7176. if (!more_to_increase) {
  7177. Client* client = player->GetClient();
  7178. if (client) {
  7179. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7180. if (packet)
  7181. client->QueuePacket(packet);
  7182. }
  7183. }
  7184. }
  7185. else {
  7186. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7187. }
  7188. }
  7189. else {
  7190. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7191. }
  7192. return 0;
  7193. }
  7194. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7195. if (!lua_interface)
  7196. return 0;
  7197. Spawn* spawn = lua_interface->GetSpawn(state);
  7198. string name = lua_interface->GetStringValue(state, 2);
  7199. if (!spawn) {
  7200. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7201. return 0;
  7202. }
  7203. if (!spawn->IsEntity()) {
  7204. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7205. return 0;
  7206. }
  7207. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7208. if (skill) {
  7209. lua_interface->SetSkillValue(state, skill);
  7210. return 1;
  7211. }
  7212. return 0;
  7213. }
  7214. int EQ2Emu_lua_AddProc(lua_State* state) {
  7215. if (!lua_interface)
  7216. return 0;
  7217. Spawn* spawn = lua_interface->GetSpawn(state);
  7218. int8 type = lua_interface->GetInt8Value(state, 2);
  7219. float chance = lua_interface->GetFloatValue(state, 3);
  7220. Item* item = lua_interface->GetItem(state, 4);
  7221. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7222. LuaSpell* spell = 0;
  7223. if (!spawn && (!spell || !use_all_spelltargets)) {
  7224. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7225. return 0;
  7226. }
  7227. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7228. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7229. return 0;
  7230. }
  7231. if (!item)
  7232. spell = lua_interface->GetCurrentSpell(state);
  7233. if (!item && !spell) {
  7234. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7235. return 0;
  7236. }
  7237. if (spell && use_all_spelltargets) {
  7238. Spawn* target;
  7239. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7240. for (int8 i = 0; i < spell->targets.size(); i++) {
  7241. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7242. if (!target || !target->IsEntity())
  7243. continue;
  7244. ((Entity*)target)->AddProc(type, chance, item, spell);
  7245. }
  7246. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7247. }
  7248. else
  7249. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7250. return 0;
  7251. }
  7252. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7253. if (!lua_interface)
  7254. return 0;
  7255. Spawn* spawn = lua_interface->GetSpawn(state);
  7256. Item* item = lua_interface->GetItem(state, 2);
  7257. LuaSpell* spell = 0;
  7258. if (!spawn) {
  7259. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7260. return 0;
  7261. }
  7262. if (!spawn->IsEntity()) {
  7263. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7264. return 0;
  7265. }
  7266. if (!item)
  7267. spell = lua_interface->GetCurrentSpell(state);
  7268. if (!item && !spell) {
  7269. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7270. return 0;
  7271. }
  7272. if (spell) {
  7273. Spawn* target;
  7274. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7275. for (int8 i = 0; i < spell->targets.size(); i++) {
  7276. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7277. if (!target || !target->IsEntity())
  7278. continue;
  7279. ((Entity*)target)->RemoveProc(item, spell);
  7280. }
  7281. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7282. spell->caster->RemoveProc(item, spell);
  7283. }
  7284. else
  7285. ((Entity*)spawn)->RemoveProc(item, spell);
  7286. return 0;
  7287. }
  7288. int EQ2Emu_lua_Knockback(lua_State* state) {
  7289. if (!lua_interface)
  7290. return 0;
  7291. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7292. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7293. int32 duration = lua_interface->GetInt32Value(state, 3);
  7294. float vertical = lua_interface->GetFloatValue(state, 4);
  7295. float horizontal = lua_interface->GetFloatValue(state, 5);
  7296. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7297. if (!target_spawn) {
  7298. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7299. return 0;
  7300. }
  7301. if (!spawn) {
  7302. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7303. return 0;
  7304. }
  7305. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7306. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7307. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7308. if (packet) {
  7309. packet->setDataByName("target_x", target_spawn->GetX());
  7310. packet->setDataByName("target_y", target_spawn->GetY());
  7311. packet->setDataByName("target_z", target_spawn->GetZ());
  7312. packet->setDataByName("vertical_movement", vertical);
  7313. packet->setDataByName("horizontal_movement", horizontal);
  7314. if (use_heading)
  7315. packet->setDataByName("use_player_heading", 1);
  7316. client->QueuePacket(packet->serialize());
  7317. }
  7318. safe_delete(packet);
  7319. }
  7320. return 0;
  7321. }
  7322. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7323. if (!lua_interface)
  7324. return 0;
  7325. Spawn* spawn = lua_interface->GetSpawn(state);
  7326. if (!spawn) {
  7327. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7328. return 0;
  7329. }
  7330. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7331. return 1;
  7332. }
  7333. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7334. if (!lua_interface)
  7335. return 0;
  7336. Spawn* caster = lua_interface->GetSpawn(state);
  7337. Spawn* target = lua_interface->GetSpawn(state, 2);
  7338. string name = lua_interface->GetStringValue(state, 3);
  7339. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7340. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7341. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7342. string success_msg = lua_interface->GetStringValue(state, 7);
  7343. string effect_msg = lua_interface->GetStringValue(state, 8);
  7344. if (!caster) {
  7345. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7346. return 0;
  7347. }
  7348. if (!caster->IsEntity()) {
  7349. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7350. return 0;
  7351. }
  7352. if (!target) {
  7353. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7354. return 0;
  7355. }
  7356. if (!target->IsEntity()) {
  7357. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7358. return 0;
  7359. }
  7360. if (name.length() == 0) {
  7361. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7362. return 0;
  7363. }
  7364. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7365. return 0;
  7366. }
  7367. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7368. if (!lua_interface)
  7369. return 0;
  7370. string name = lua_interface->GetStringValue(state);
  7371. if (name.length() == 0) {
  7372. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7373. return 0;
  7374. }
  7375. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7376. if (!skill) {
  7377. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7378. return 0;
  7379. }
  7380. lua_interface->SetInt32Value(state, skill->skill_id);
  7381. return 1;
  7382. }
  7383. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7384. if (!lua_interface)
  7385. return 0;
  7386. Spawn* spawn = lua_interface->GetSpawn(state);
  7387. if (!spawn) {
  7388. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7389. return 0;
  7390. }
  7391. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7392. return 1;
  7393. }
  7394. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7395. if (!lua_interface)
  7396. return 0;
  7397. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7398. if (!luaspell) {
  7399. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7400. return 0;
  7401. }
  7402. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7403. return 1;
  7404. }
  7405. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7406. if (!lua_interface)
  7407. return 0;
  7408. Spawn* spawn = lua_interface->GetSpawn(state);
  7409. Spawn* target = lua_interface->GetSpawn(state, 2);
  7410. if (!spawn) {
  7411. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7412. return 0;
  7413. }
  7414. if (!spawn->IsEntity()) {
  7415. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7416. return 0;
  7417. }
  7418. if (!target) {
  7419. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7420. return 0;
  7421. }
  7422. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7423. return 1;
  7424. }
  7425. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7426. if (!lua_interface)
  7427. return 0;
  7428. Spawn* spawn = lua_interface->GetSpawn(state);
  7429. Spawn* target = lua_interface->GetSpawn(state, 2);
  7430. if (!spawn) {
  7431. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7432. return 0;
  7433. }
  7434. if (!spawn->IsEntity()) {
  7435. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7436. return 0;
  7437. }
  7438. if (!target) {
  7439. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7440. return 0;
  7441. }
  7442. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7443. return 1;
  7444. }
  7445. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7446. if (!lua_interface)
  7447. return 0;
  7448. Item* item = lua_interface->GetItem(state);
  7449. if (!item) {
  7450. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7451. return 0;
  7452. }
  7453. lua_interface->SetInt32Value(state, item->details.count);
  7454. return 1;
  7455. }
  7456. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7457. if (!lua_interface)
  7458. return 0;
  7459. Item* item = lua_interface->GetItem(state);
  7460. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7461. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7462. if (!item) {
  7463. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7464. return 0;
  7465. }
  7466. if (!owner) {
  7467. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7468. return 0;
  7469. }
  7470. if (!owner->IsPlayer()) {
  7471. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7472. return 0;
  7473. }
  7474. if (item->stack_count < new_count) {
  7475. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7476. return 0;
  7477. }
  7478. if (new_count > 0) {
  7479. item->details.count = new_count;
  7480. item->save_needed = true;
  7481. }
  7482. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7483. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7484. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7485. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7486. else
  7487. {
  7488. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7489. return 0;
  7490. }
  7491. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7492. if (!client)
  7493. return 0;
  7494. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7495. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7496. if (app)
  7497. client->QueuePacket(app);
  7498. return 0;
  7499. }
  7500. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7501. if (!lua_interface)
  7502. return 0;
  7503. int32 time = lua_interface->GetInt32Value(state);
  7504. string function = lua_interface->GetStringValue(state, 2);
  7505. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7506. Spawn* target = lua_interface->GetSpawn(state, 4);
  7507. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7508. if (time == 0) {
  7509. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7510. return 0;
  7511. }
  7512. if (function.length() == 0) {
  7513. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7514. return 0;
  7515. }
  7516. if (!spell) {
  7517. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7518. return 0;
  7519. }
  7520. SpellScriptTimer* timer = new SpellScriptTimer;
  7521. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7522. #ifdef WIN32
  7523. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7524. #else
  7525. bzero(timer, sizeof(SpellScriptTimer));
  7526. #endif*/
  7527. timer->caster = 0;
  7528. timer->deleteWhenDone = false;
  7529. timer->target = 0;
  7530. timer->time = Timer::GetCurrentTime2() + time;
  7531. timer->customFunction = function;
  7532. timer->spell = spell;
  7533. if (caster)
  7534. timer->caster = caster->GetID();
  7535. if (target)
  7536. timer->target = target->GetID();
  7537. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7538. return 0;
  7539. }
  7540. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7541. if (!lua_interface)
  7542. return 0;
  7543. float hp_perc = lua_interface->GetFloatValue(state);
  7544. float power_perc = lua_interface->GetFloatValue(state, 2);
  7545. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7546. Spawn* target = lua_interface->GetSpawn(state, 4);
  7547. string heal_name = lua_interface->GetStringValue(state, 5);
  7548. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7549. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7550. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7551. if (!spell) {
  7552. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7553. return 0;
  7554. }
  7555. Entity* caster = spell->caster;
  7556. if (!caster) {
  7557. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7558. return 0;
  7559. }
  7560. Client* client = 0;
  7561. PendingResurrection* rez = 0;
  7562. ZoneServer* zone = spell->caster->GetZone();
  7563. if (!target) {
  7564. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7565. if (spell->targets.size() > 0) {
  7566. vector<int32> spell_targets = spell->targets;
  7567. for (int8 i = 0; i < spell_targets.size(); i++) {
  7568. target = zone->GetSpawnByID(spell_targets.at(i));
  7569. if (!target)
  7570. continue;
  7571. if (!target->IsPlayer())
  7572. continue;
  7573. client = target->GetZone()->GetClientBySpawn(target);
  7574. if (!client)
  7575. continue;
  7576. rez = client->GetCurrentRez();
  7577. if (rez->active)
  7578. continue;
  7579. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7580. rez->active = true;
  7581. rez->caster = caster;
  7582. rez->expire_timer = new Timer;
  7583. int32 duration = spell->spell->GetSpellDuration();
  7584. rez->expire_timer->Start(duration * 100);
  7585. rez->hp_perc = hp_perc;
  7586. rez->mp_perc = power_perc;
  7587. rez->range = spell->spell->GetSpellData()->range;
  7588. rez->spell_name = spell->spell->GetName();
  7589. if (heal_name.length() > 0)
  7590. rez->heal_name = heal_name;
  7591. else
  7592. rez->heal_name = rez->spell_name;
  7593. rez->no_calcs = no_calcs;
  7594. rez->crit_mod = crit_mod;
  7595. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7596. if (send_window)
  7597. client->SendResurrectionWindow();
  7598. else {
  7599. target->GetZone()->ResurrectSpawn(target, client);
  7600. rez->should_delete = true;
  7601. }
  7602. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7603. }
  7604. }
  7605. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7606. }
  7607. else {
  7608. client = target->GetZone()->GetClientBySpawn(target);
  7609. if (!client)
  7610. return 0;
  7611. rez = client->GetCurrentRez();
  7612. if (rez->active)
  7613. return 0;
  7614. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7615. rez->active = true;
  7616. rez->caster = caster;
  7617. rez->expire_timer = new Timer;
  7618. int32 duration = spell->spell->GetSpellDuration();
  7619. rez->expire_timer->Start(duration * 100);
  7620. rez->hp_perc = hp_perc;
  7621. rez->mp_perc = power_perc;
  7622. rez->range = spell->spell->GetSpellData()->range;
  7623. rez->spell_name = spell->spell->GetName();
  7624. if (heal_name.length() > 0)
  7625. rez->heal_name = heal_name;
  7626. else
  7627. rez->heal_name = rez->spell_name;
  7628. rez->no_calcs = no_calcs;
  7629. rez->crit_mod = crit_mod;
  7630. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7631. if (send_window)
  7632. client->SendResurrectionWindow();
  7633. else {
  7634. target->GetZone()->ResurrectSpawn(target, client);
  7635. rez->should_delete = true;
  7636. }
  7637. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7638. }
  7639. return 0;
  7640. }
  7641. int EQ2Emu_lua_SetVision(lua_State* state) {
  7642. if (!lua_interface)
  7643. return 0;
  7644. Spawn* spawn = lua_interface->GetSpawn(state);
  7645. int8 vision = lua_interface->GetInt8Value(state, 2);
  7646. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7647. if (!spawn) {
  7648. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7649. return 0;
  7650. }
  7651. if (!spawn->IsEntity()) {
  7652. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7653. return 0;
  7654. }
  7655. if (spell && spell->targets.size() > 0) {
  7656. ZoneServer* zone = spell->caster->GetZone();
  7657. for (int8 i = 0; i < spell->targets.size(); i++) {
  7658. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7659. if (target && target->IsEntity()) {
  7660. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7661. if (target->IsPlayer())
  7662. ((Player*)target)->SetCharSheetChanged(true);
  7663. }
  7664. }
  7665. }
  7666. else {
  7667. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7668. if (spawn->IsPlayer())
  7669. ((Player*)spawn)->SetCharSheetChanged(true);
  7670. }
  7671. return 0;
  7672. }
  7673. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7674. if (!lua_interface)
  7675. return 0;
  7676. Spawn* spawn = lua_interface->GetSpawn(state);
  7677. float intensity = lua_interface->GetFloatValue(state, 2);
  7678. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7679. if (!spawn) {
  7680. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7681. return 0;
  7682. }
  7683. if (!spawn->IsEntity()) {
  7684. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7685. return 0;
  7686. }
  7687. if (spell && spell->targets.size() > 0) {
  7688. ZoneServer* zone = spell->caster->GetZone();
  7689. for (int8 i = 0; i < spell->targets.size(); i++) {
  7690. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7691. if (target && target->IsEntity()) {
  7692. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7693. if (target->IsPlayer())
  7694. ((Player*)target)->SetCharSheetChanged(true);
  7695. }
  7696. }
  7697. }
  7698. else {
  7699. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7700. if (spawn->IsPlayer())
  7701. ((Player*)spawn)->SetCharSheetChanged(true);
  7702. }
  7703. return 0;
  7704. }
  7705. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7706. if (!lua_interface)
  7707. return 0;
  7708. Spawn* spawn = lua_interface->GetSpawn(state);
  7709. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7710. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7711. if (!spawn) {
  7712. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7713. return 0;
  7714. }
  7715. if (!spawn->IsEntity()) {
  7716. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7717. return 0;
  7718. }
  7719. if (spell && spell->targets.size() > 0) {
  7720. ZoneServer* zone = spell->caster->GetZone();
  7721. for (int8 i = 0; i < spell->targets.size(); i++) {
  7722. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7723. if (target && target->IsEntity()) {
  7724. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7725. if (target->IsPlayer())
  7726. ((Player*)target)->SetCharSheetChanged(true);
  7727. }
  7728. }
  7729. }
  7730. else {
  7731. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7732. if (spawn->IsPlayer())
  7733. ((Player*)spawn)->SetCharSheetChanged(true);
  7734. }
  7735. return 0;
  7736. }
  7737. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7738. if (!lua_interface)
  7739. return 0;
  7740. Item* item = lua_interface->GetItem(state);
  7741. int8 type = lua_interface->GetInt32Value(state, 2);
  7742. if (!item) {
  7743. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7744. return 0;
  7745. }
  7746. if (type == 1)
  7747. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7748. else if (type == 2)
  7749. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7750. return 1;
  7751. }
  7752. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7753. if (!lua_interface)
  7754. return 0;
  7755. Spawn* target = lua_interface->GetSpawn(state);
  7756. float val = lua_interface->GetFloatValue(state, 2);
  7757. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7758. // Added from Gangrenous post
  7759. if (spell && spell->resisted)
  7760. return 0;
  7761. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7762. if (val > 1.0f)
  7763. val = 1.0f - (val / 100.0f);
  7764. if (spell && spell->spell && spell->targets.size() > 0) {
  7765. ZoneServer* zone = spell->caster->GetZone();
  7766. for (int32 i = 0; i != spell->targets.size(); i++) {
  7767. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7768. if (spawn && spawn->IsEntity()) {
  7769. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7770. if (spawn->IsPlayer())
  7771. ((Player*)spawn)->SetCharSheetChanged(true);
  7772. }
  7773. }
  7774. }
  7775. else {
  7776. if (target && target->IsEntity()) {
  7777. ((Entity*)target)->SetSpeedMultiplier(val);
  7778. if (target->IsPlayer())
  7779. ((Player*)target)->SetCharSheetChanged(true);
  7780. }
  7781. }
  7782. return 0;
  7783. }
  7784. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7785. if (!lua_interface)
  7786. return 0;
  7787. Spawn* spawn = lua_interface->GetSpawn(state);
  7788. int16 model = lua_interface->GetInt16Value(state, 2);
  7789. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7790. if (spell && spell->spell && spell->targets.size() > 0) {
  7791. ZoneServer* zone = spell->caster->GetZone();
  7792. for (int32 i = 0; i < spell->targets.size(); i++) {
  7793. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7794. if (target)
  7795. target->SetIllusionModel(model);
  7796. }
  7797. }
  7798. else {
  7799. if (!spawn) {
  7800. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7801. return 0;
  7802. }
  7803. spawn->SetIllusionModel(model);
  7804. }
  7805. return 0;
  7806. }
  7807. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7808. if (!lua_interface)
  7809. return 0;
  7810. Spawn* spawn = lua_interface->GetSpawn(state);
  7811. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7812. if (spell && spell->spell && spell->targets.size() > 0) {
  7813. ZoneServer* zone = spell->caster->GetZone();
  7814. for (int32 i = 0; i < spell->targets.size(); i++) {
  7815. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7816. if (target)
  7817. target->SetIllusionModel(0);
  7818. }
  7819. }
  7820. else {
  7821. if (!spawn) {
  7822. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7823. return 0;
  7824. }
  7825. spawn->SetIllusionModel(0);
  7826. }
  7827. return 0;
  7828. }
  7829. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7830. if (!lua_interface)
  7831. return 0;
  7832. Spawn* caster = lua_interface->GetSpawn(state);
  7833. Spawn* target = lua_interface->GetSpawn(state, 2);
  7834. float chance = lua_interface->GetFloatValue(state, 3);
  7835. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7836. if (!caster) {
  7837. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7838. return 0;
  7839. }
  7840. if (!caster->IsEntity()) {
  7841. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7842. return 0;
  7843. }
  7844. if (!target) {
  7845. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7846. return 0;
  7847. }
  7848. if (!target->IsEntity()) {
  7849. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7850. return 0;
  7851. }
  7852. if (chance <= 0) {
  7853. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7854. return 0;
  7855. }
  7856. if (!spell) {
  7857. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7858. return 0;
  7859. }
  7860. if (((Entity*)caster)->GetThreatTransfer()) {
  7861. return 0;
  7862. }
  7863. ThreatTransfer* transfer = new ThreatTransfer;
  7864. transfer->Target = target->GetID();
  7865. transfer->Amount = chance;
  7866. transfer->Spell = spell;
  7867. ((Entity*)caster)->SetThreatTransfer(transfer);
  7868. return 0;
  7869. }
  7870. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7871. if (!lua_interface)
  7872. return 0;
  7873. Spawn* spawn = lua_interface->GetSpawn(state);
  7874. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7875. if (!spawn) {
  7876. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7877. return 0;
  7878. }
  7879. if (!spell) {
  7880. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7881. return 0;
  7882. }
  7883. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7884. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7885. ((Entity*)spawn)->SetThreatTransfer(0);
  7886. safe_delete(transfer);
  7887. }
  7888. return 0;
  7889. }
  7890. int EQ2Emu_lua_CureByType(lua_State* state) {
  7891. if (!lua_interface)
  7892. return 0;
  7893. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7894. if (!spell) {
  7895. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7896. return 0;
  7897. }
  7898. int8 cure_count = lua_interface->GetInt8Value(state);
  7899. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7900. string cure_name = lua_interface->GetStringValue(state, 3);
  7901. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7902. Spawn* target = lua_interface->GetSpawn(state, 5);
  7903. if (target) {
  7904. if (!target->IsEntity()) {
  7905. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7906. return 0;
  7907. }
  7908. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7909. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7910. }
  7911. else {
  7912. ZoneServer* zone = spell->caster->GetZone();
  7913. vector<int32> targets = spell->targets;
  7914. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7915. for (int8 i = 0; i < targets.size(); i++) {
  7916. target = zone->GetSpawnByID(targets.at(i));
  7917. if (!target || !target->IsEntity())
  7918. continue;
  7919. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7920. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7921. }
  7922. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7923. }
  7924. return 0;
  7925. }
  7926. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7927. if (!lua_interface)
  7928. return 0;
  7929. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7930. if (!spell) {
  7931. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7932. return 0;
  7933. }
  7934. int8 cure_count = lua_interface->GetInt8Value(state);
  7935. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7936. string cure_name = lua_interface->GetStringValue(state, 3);
  7937. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7938. Spawn* target = lua_interface->GetSpawn(state, 5);
  7939. if (target) {
  7940. if (!target->IsEntity()) {
  7941. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7942. return 0;
  7943. }
  7944. if (((Entity*)target)->GetDetCount() > 0)
  7945. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7946. }
  7947. else {
  7948. ZoneServer* zone = spell->caster->GetZone();
  7949. vector<int32> targets = spell->targets;
  7950. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7951. for (int8 i = 0; i < targets.size(); i++) {
  7952. target = zone->GetSpawnByID(targets.at(i));
  7953. if (!target || !target->IsEntity())
  7954. continue;
  7955. if (((Entity*)target)->GetDetCount() > 0)
  7956. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7957. }
  7958. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7959. }
  7960. return 0;
  7961. }
  7962. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7963. if (!lua_interface)
  7964. return 0;
  7965. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7966. if (!spell) {
  7967. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7968. return 0;
  7969. }
  7970. if (!spell->caster) {
  7971. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7972. return 0;
  7973. }
  7974. if (!spell->caster->GetZone()) {
  7975. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7976. return 0;
  7977. }
  7978. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7979. return 0;
  7980. }
  7981. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7982. if (!lua_interface)
  7983. return 0;
  7984. Spawn* spawn = lua_interface->GetSpawn(state);
  7985. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7986. if (!spell) {
  7987. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7988. return 0;
  7989. }
  7990. if (spawn && spawn->IsEntity())
  7991. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7992. else {
  7993. ZoneServer* zone = spell->caster->GetZone();
  7994. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7995. for (int32 i = 0; i < spell->targets.size(); i++) {
  7996. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7997. if (!spawn || !spawn->IsEntity())
  7998. continue;
  7999. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8000. }
  8001. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8002. }
  8003. return 0;
  8004. }
  8005. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8006. if (!lua_interface)
  8007. return 0;
  8008. Spawn* spawn = lua_interface->GetSpawn(state);
  8009. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8010. if (!spell) {
  8011. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8012. return 0;
  8013. }
  8014. if (spawn && spawn->IsEntity())
  8015. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8016. else {
  8017. ZoneServer* zone = spell->caster->GetZone();
  8018. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8019. for (int32 i = 0; i < spell->targets.size(); i++) {
  8020. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8021. if (!spawn || !spawn->IsEntity())
  8022. continue;
  8023. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8024. }
  8025. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8026. }
  8027. return 0;
  8028. }
  8029. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8030. if (!lua_interface)
  8031. return 0;
  8032. Spawn* caster = lua_interface->GetSpawn(state);
  8033. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8034. if (!caster) {
  8035. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8036. return 0;
  8037. }
  8038. if (!caster->IsPlayer()) {
  8039. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8040. return 0;
  8041. }
  8042. Spawn* target = caster->GetTarget();
  8043. if (!target) {
  8044. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8045. return 0;
  8046. }
  8047. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8048. if (!client) {
  8049. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8050. return 0;
  8051. }
  8052. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8053. if (ho) {
  8054. ho->SetTarget(target->GetID());
  8055. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8056. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8057. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8058. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8059. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8060. deque<GroupMemberInfo*>::iterator itr;
  8061. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8062. if (group)
  8063. {
  8064. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8065. deque<GroupMemberInfo*>* members = group->GetMembers();
  8066. for (itr = members->begin(); itr != members->end(); itr++) {
  8067. if ((*itr)->client)
  8068. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8069. }
  8070. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8071. }
  8072. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8073. }
  8074. else
  8075. safe_delete(ho);
  8076. }
  8077. else {
  8078. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8079. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8080. }
  8081. else
  8082. safe_delete(ho);
  8083. }
  8084. }
  8085. return 0;
  8086. }
  8087. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8088. if (!lua_interface)
  8089. return 0;
  8090. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8091. if (!spell) {
  8092. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8093. return 0;
  8094. }
  8095. int16 triggerCount = lua_interface->GetInt16Value(state);
  8096. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8097. if (!triggerCount) {
  8098. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8099. return 0;
  8100. }
  8101. spell->num_triggers = triggerCount;
  8102. spell->had_triggers = true;
  8103. spell->cancel_after_all_triggers = cancel_after_triggers;
  8104. return 0;
  8105. }
  8106. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8107. if (!lua_interface)
  8108. return 0;
  8109. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8110. if (!spell) {
  8111. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8112. return 0;
  8113. }
  8114. lua_interface->SetInt32Value(state, spell->num_triggers);
  8115. return 1;
  8116. }
  8117. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8118. if (!lua_interface)
  8119. return 0;
  8120. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8121. if (!spell) {
  8122. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8123. return 0;
  8124. }
  8125. int16 remove_count = lua_interface->GetInt16Value(state);
  8126. if (!remove_count)
  8127. remove_count = 1;
  8128. if (remove_count >= spell->num_triggers) {
  8129. spell->num_triggers = 0;
  8130. if (spell->cancel_after_all_triggers)
  8131. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8132. }
  8133. else {
  8134. spell->num_triggers -= remove_count;
  8135. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8136. }
  8137. return 0;
  8138. }
  8139. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8140. if (!lua_interface)
  8141. return 0;
  8142. Spawn* spawn = lua_interface->GetSpawn(state);
  8143. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8144. if (!spawn) {
  8145. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8146. return 0;
  8147. }
  8148. if (!copy_spawn) {
  8149. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8150. return 0;
  8151. }
  8152. spawn->CopySpawnAppearance(copy_spawn);
  8153. return 0;
  8154. }
  8155. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8156. Spawn* spawn = lua_interface->GetSpawn(state);
  8157. int8 type = lua_interface->GetInt8Value(state, 2);
  8158. if (!spawn) {
  8159. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8160. return 0;
  8161. }
  8162. else if (!spawn->IsEntity()) {
  8163. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8164. return 0;
  8165. }
  8166. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8167. return 1;
  8168. }
  8169. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8170. if (!lua_interface)
  8171. return 0;
  8172. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8173. int8 type = lua_interface->GetInt8Value(state);
  8174. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8175. if (!spell) {
  8176. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8177. return 0;
  8178. }
  8179. if (spawn) {
  8180. if (!spawn->IsEntity()) {
  8181. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8182. return 0;
  8183. }
  8184. Entity* entity = ((Entity*)spawn);
  8185. entity->AddImmunity(spell, type);
  8186. }
  8187. else {
  8188. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8189. for (int8 i = 0; i < spell->targets.size(); i++) {
  8190. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8191. if (!spawn || !spawn->IsEntity())
  8192. continue;
  8193. Entity* entity = ((Entity*)spawn);
  8194. entity->AddImmunity(spell, type);
  8195. }
  8196. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8197. }
  8198. return 0;
  8199. }
  8200. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8201. if (!lua_interface)
  8202. return 0;
  8203. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8204. int8 type = lua_interface->GetInt8Value(state);
  8205. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8206. if (!spell) {
  8207. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8208. return 0;
  8209. }
  8210. if (spawn) {
  8211. if (!spawn->IsEntity()) {
  8212. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8213. return 0;
  8214. }
  8215. Entity* entity = ((Entity*)spawn);
  8216. entity->RemoveImmunity(spell, type);
  8217. }
  8218. else {
  8219. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8220. for (int8 i = 0; i < spell->targets.size(); i++) {
  8221. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8222. if (!spawn || !spawn->IsEntity())
  8223. continue;
  8224. Entity* entity = ((Entity*)spawn);
  8225. entity->RemoveImmunity(spell, type);
  8226. }
  8227. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8228. }
  8229. return 0;
  8230. }
  8231. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8232. if (!lua_interface)
  8233. return 0;
  8234. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8235. if (!spell) {
  8236. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8237. return 0;
  8238. }
  8239. float snare = lua_interface->GetFloatValue(state);
  8240. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8241. // convert the val to the speed multipler value (100 - val)
  8242. float val = 100.0 - snare;
  8243. val /= 100.0;
  8244. if (spawn) {
  8245. if (!spawn->IsEntity()) {
  8246. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8247. return 0;
  8248. }
  8249. ((Entity*)spawn)->SetSnareValue(spell, val);
  8250. }
  8251. else {
  8252. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8253. for (int8 i = 0; i < spell->targets.size(); i++) {
  8254. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8255. if (!spawn || !spawn->IsEntity())
  8256. continue;
  8257. ((Entity*)spawn)->SetSnareValue(spell, val);
  8258. }
  8259. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8260. }
  8261. return 0;
  8262. }
  8263. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8264. if (!lua_interface)
  8265. return 0;
  8266. Spawn* spawn = lua_interface->GetSpawn(state);
  8267. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8268. if (!spawn) {
  8269. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8270. return 0;
  8271. }
  8272. if (race_id == 0) {
  8273. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8274. return 0;
  8275. }
  8276. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8277. return 1;
  8278. }
  8279. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8280. if (!lua_interface)
  8281. return 0;
  8282. Spawn* spawn = lua_interface->GetSpawn(state);
  8283. if (!spawn) {
  8284. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8285. return 0;
  8286. }
  8287. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8288. return 1;
  8289. }
  8290. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8291. if (!lua_interface)
  8292. return 0;
  8293. Spawn* spawn = lua_interface->GetSpawn(state);
  8294. if (!spawn) {
  8295. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8296. return 0;
  8297. }
  8298. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8299. return 1;
  8300. }
  8301. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8302. if (!lua_interface)
  8303. return 0;
  8304. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8305. if (!spell) {
  8306. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8307. return 0;
  8308. }
  8309. lua_interface->SetStringValue(state, spell->spell->GetName());
  8310. return 1;
  8311. }
  8312. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8313. if (!lua_interface)
  8314. return 0;
  8315. Quest* quest = lua_interface->GetQuest(state);
  8316. if (!quest) {
  8317. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8318. return 0;
  8319. }
  8320. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8321. return 1;
  8322. }
  8323. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8324. if (!lua_interface)
  8325. return 0;
  8326. Quest* quest = lua_interface->GetQuest(state);
  8327. int32 flags = lua_interface->GetInt32Value(state, 2);
  8328. if (!quest) {
  8329. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8330. return 0;
  8331. }
  8332. quest->SetQuestFlags(flags);
  8333. return 0;
  8334. }
  8335. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8336. if (!lua_interface)
  8337. return 0;
  8338. Quest* quest = lua_interface->GetQuest(state);
  8339. Spawn* player = lua_interface->GetSpawn(state, 2);
  8340. int32 step = lua_interface->GetInt32Value(state, 3);
  8341. int32 duration = lua_interface->GetInt32Value(state, 4);
  8342. string action = lua_interface->GetStringValue(state, 5);
  8343. if (!quest) {
  8344. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8345. return 0;
  8346. }
  8347. if (!player) {
  8348. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8349. return 0;
  8350. }
  8351. if (!player->IsPlayer()) {
  8352. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8353. return 0;
  8354. }
  8355. if (step == 0) {
  8356. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8357. return 0;
  8358. }
  8359. if (duration == 0) {
  8360. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8361. return 0;
  8362. }
  8363. if (action.length() == 0) {
  8364. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8365. return 0;
  8366. }
  8367. Client* client = player->GetZone()->GetClientBySpawn(player);
  8368. if (!client) {
  8369. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8370. return 0;
  8371. }
  8372. quest->SetTimerStep(step);
  8373. quest->AddFailedAction(step, action);
  8374. quest->SetStepTimer(duration);
  8375. client->AddQuestTimer(quest->GetQuestID());
  8376. return 0;
  8377. }
  8378. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8379. if (!lua_interface)
  8380. return 0;
  8381. Quest* quest = lua_interface->GetQuest(state);
  8382. Spawn* player = lua_interface->GetSpawn(state, 2);
  8383. if (!quest) {
  8384. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8385. return 0;
  8386. }
  8387. if (!player) {
  8388. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8389. return 0;
  8390. }
  8391. if (!player->IsPlayer()) {
  8392. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8393. return 0;
  8394. }
  8395. Client* client = player->GetZone()->GetClientBySpawn(player);
  8396. if (!client) {
  8397. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8398. return 0;
  8399. }
  8400. quest->SetTimerStep(0);
  8401. quest->SetStepTimer(0);
  8402. client->RemoveQuestTimer(quest->GetQuestID());
  8403. return 0;
  8404. }
  8405. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8406. if (!lua_interface)
  8407. return 0;
  8408. Spawn* player = lua_interface->GetSpawn(state);
  8409. Quest* quest = lua_interface->GetQuest(state, 2);
  8410. int32 step = lua_interface->GetInt32Value(state, 3);
  8411. if (!player) {
  8412. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8413. return 0;
  8414. }
  8415. if (!player->IsPlayer()) {
  8416. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8417. return 0;
  8418. }
  8419. if (!quest) {
  8420. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8421. return 0;
  8422. }
  8423. if (step == 0) {
  8424. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8425. return 0;
  8426. }
  8427. Client* client = player->GetZone()->GetClientBySpawn(player);
  8428. if (!client) {
  8429. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8430. return 0;
  8431. }
  8432. if (quest->RemoveQuestStep(step, client)) {
  8433. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8434. client->GetCurrentZone()->SendQuestUpdates(client);
  8435. }
  8436. else
  8437. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8438. return 0;
  8439. }
  8440. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8441. if (!lua_interface)
  8442. return 0;
  8443. Quest* quest = lua_interface->GetQuest(state, 1);
  8444. int32 step = lua_interface->GetInt32Value(state, 2);
  8445. string desc = lua_interface->GetStringValue(state, 3);
  8446. string task_group = lua_interface->GetStringValue(state, 4);
  8447. if (!quest) {
  8448. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8449. return 0;
  8450. }
  8451. if (step == 0) {
  8452. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8453. return 0;
  8454. }
  8455. QuestStep* quest_step = quest->GetQuestStep(step);
  8456. if (!quest_step) {
  8457. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8458. return 0;
  8459. }
  8460. quest_step->SetStepProgress(0);
  8461. quest_step->SetTaskGroup(task_group);
  8462. quest_step->SetDescription(desc);
  8463. return 0;
  8464. }
  8465. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8466. if (!lua_interface)
  8467. return 0;
  8468. Quest* quest = lua_interface->GetQuest(state);
  8469. int32 step = lua_interface->GetInt32Value(state, 2);
  8470. string action = lua_interface->GetStringValue(state, 3);
  8471. if (!quest) {
  8472. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8473. return 0;
  8474. }
  8475. if (step == 0) {
  8476. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8477. return 0;
  8478. }
  8479. if (action.length() == 0) {
  8480. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8481. return 0;
  8482. }
  8483. quest->AddFailedAction(step, action);
  8484. return 0;
  8485. }
  8486. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8487. if (!lua_interface)
  8488. return 0;
  8489. Spawn* player = lua_interface->GetSpawn(state);
  8490. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8491. int32 step = lua_interface->GetInt32Value(state, 3);
  8492. if (!player) {
  8493. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8494. return 0;
  8495. }
  8496. if (!player->IsPlayer()) {
  8497. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8498. return 0;
  8499. }
  8500. if (quest_id == 0) {
  8501. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8502. return 0;
  8503. }
  8504. if (step == 0) {
  8505. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8506. return 0;
  8507. }
  8508. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8509. if (!quest) {
  8510. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8511. return 0;
  8512. }
  8513. quest->StepFailed(step);
  8514. return 0;
  8515. }
  8516. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8517. if (!lua_interface)
  8518. return 0;
  8519. Spawn* player = lua_interface->GetSpawn(state);
  8520. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8521. if (!player) {
  8522. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8523. return 0;
  8524. }
  8525. if (!player->IsPlayer()) {
  8526. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8527. return 0;
  8528. }
  8529. if (quest_id == 0) {
  8530. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8531. return 0;
  8532. }
  8533. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8534. if (!quest) {
  8535. lua_interface->SetInt32Value(state, 0);
  8536. return 1;
  8537. }
  8538. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8539. return 1;
  8540. }
  8541. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8542. if (!lua_interface)
  8543. return 0;
  8544. string name = lua_interface->GetStringValue(state);
  8545. string value = lua_interface->GetStringValue(state, 2);
  8546. string comment = lua_interface->GetStringValue(state, 3);
  8547. if (name.length() == 0) {
  8548. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8549. return 0;
  8550. }
  8551. if (value.length() == 0) {
  8552. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8553. return 0;
  8554. }
  8555. string varname = string("lua_").append(name);
  8556. Variable* var = variables.FindVariable(varname);
  8557. if (var)
  8558. var->SetValue(value.c_str());
  8559. else {
  8560. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8561. variables.AddVariable(var);
  8562. }
  8563. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8564. return 0;
  8565. }
  8566. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8567. if (!lua_interface)
  8568. return 0;
  8569. string name = lua_interface->GetStringValue(state);
  8570. if (name.length() == 0) {
  8571. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8572. return 0;
  8573. }
  8574. string varname = string("lua_").append(name);
  8575. Variable* var = variables.FindVariable(varname);
  8576. if (var)
  8577. lua_interface->SetStringValue(state, var->GetValue());
  8578. else
  8579. lua_interface->SetStringValue(state, "NULL");
  8580. return 1;
  8581. }
  8582. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8583. if (!lua_interface)
  8584. return 0;
  8585. Spawn* player = lua_interface->GetSpawn(state);
  8586. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8587. if (!player) {
  8588. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8589. return 0;
  8590. }
  8591. if (!player->IsPlayer()) {
  8592. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8593. return 0;
  8594. }
  8595. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8596. return 1;
  8597. }
  8598. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8599. if (!lua_interface)
  8600. return 0;
  8601. Spawn* player = lua_interface->GetSpawn(state);
  8602. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8603. if (!player) {
  8604. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8605. return 0;
  8606. }
  8607. if (!player->IsPlayer()) {
  8608. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8609. return 0;
  8610. }
  8611. Language* language = master_languages_list.GetLanguage(language_id);
  8612. if (language)
  8613. {
  8614. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8615. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8616. }
  8617. return 0;
  8618. }
  8619. int EQ2Emu_lua_IsNight(lua_State* state) {
  8620. if (!lua_interface)
  8621. return 0;
  8622. ZoneServer* zone = lua_interface->GetZone(state);
  8623. if (!zone) {
  8624. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8625. return 0;
  8626. }
  8627. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8628. return 1;
  8629. }
  8630. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8631. if (!lua_interface)
  8632. return 0;
  8633. Spawn* spawn = lua_interface->GetSpawn(state);
  8634. if (!spawn) {
  8635. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8636. return 0;
  8637. }
  8638. if (!spawn->IsWidget()) {
  8639. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8640. return 0;
  8641. }
  8642. ((Widget*)spawn)->SetMultiFloorLift(true);
  8643. if (spawn->GetZone())
  8644. spawn->GetZone()->AddTransportSpawn(spawn);
  8645. return 0;
  8646. }
  8647. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8648. if (!lua_interface)
  8649. return 0;
  8650. Spawn* player = lua_interface->GetSpawn(state);
  8651. int32 path = lua_interface->GetInt32Value(state, 2);
  8652. if (!player) {
  8653. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8654. return 0;
  8655. }
  8656. if (!player->IsPlayer()) {
  8657. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8658. return 0;
  8659. }
  8660. if (path == 0) {
  8661. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8662. return 0;
  8663. }
  8664. Client* client = player->GetZone()->GetClientBySpawn(player);
  8665. if (!client) {
  8666. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. client->SendFlightAutoMount(path);
  8670. return 0;
  8671. }
  8672. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8673. if (!lua_interface)
  8674. return 0;
  8675. Spawn* player = lua_interface->GetSpawn(state);
  8676. if (!player) {
  8677. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8678. return 0;
  8679. }
  8680. if (!player->IsPlayer()) {
  8681. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8682. return 0;
  8683. }
  8684. Client* client = player->GetZone()->GetClientBySpawn(player);
  8685. if (!client) {
  8686. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8687. return 0;
  8688. }
  8689. client->EndAutoMount();
  8690. return 0;
  8691. }
  8692. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8693. if (!lua_interface)
  8694. return 0;
  8695. Spawn* player = lua_interface->GetSpawn(state);
  8696. if (!player) {
  8697. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8698. return 0;
  8699. }
  8700. if (!player->IsPlayer()) {
  8701. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8702. return 0;
  8703. }
  8704. Client* client = player->GetZone()->GetClientBySpawn(player);
  8705. if (!client) {
  8706. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8707. return 0;
  8708. }
  8709. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8710. return 1;
  8711. }
  8712. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8713. if (!lua_interface)
  8714. return 0;
  8715. Spawn* player = lua_interface->GetSpawn(state);
  8716. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8717. int32 value = lua_interface->GetInt32Value(state, 3);
  8718. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8719. if (!player) {
  8720. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8721. return 0;
  8722. }
  8723. if (!player->IsPlayer()) {
  8724. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8725. return 0;
  8726. }
  8727. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8728. return 0;
  8729. }
  8730. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8731. if (!lua_interface)
  8732. return 0;
  8733. Spawn* player = lua_interface->GetSpawn(state);
  8734. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8735. if (!player) {
  8736. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8737. return 0;
  8738. }
  8739. if (!player->IsPlayer()) {
  8740. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8741. return 0;
  8742. }
  8743. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8744. if (!hd)
  8745. return 0;
  8746. lua_interface->SetInt32Value(state, hd->Value);
  8747. lua_interface->SetInt32Value(state, hd->Value2);
  8748. return 2;
  8749. }
  8750. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8751. if (!lua_interface)
  8752. return 0;
  8753. Spawn* spawn = lua_interface->GetSpawn(state);
  8754. int32 grid = lua_interface->GetInt32Value(state, 2);
  8755. if (!spawn) {
  8756. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8757. return 0;
  8758. }
  8759. if (grid == 0) {
  8760. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8761. return 0;
  8762. }
  8763. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8764. return 0;
  8765. }
  8766. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8767. if (!lua_interface)
  8768. return 0;
  8769. Spawn* spawn = lua_interface->GetSpawn(state);
  8770. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8771. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8772. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8773. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8774. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8775. if (!spawn) {
  8776. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8777. return 0;
  8778. }
  8779. //Add this quest to the list of required quests for this spawn
  8780. spawn->SetRequiredHistory(event_id, value1, value2);
  8781. //If private spawn value set
  8782. if (private_spawn) {
  8783. //Set the spawn to be private when not granted access via history
  8784. spawn->AddAllowAccessSpawn(spawn);
  8785. spawn->SetPrivateQuestSpawn(true);
  8786. }
  8787. //This value will override vis_flags in the vis packet
  8788. if (flag_override > 0)
  8789. spawn->SetQuestsRequiredOverride(flag_override);
  8790. return 0;
  8791. }
  8792. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8793. if (!lua_interface)
  8794. return 0;
  8795. Spawn* player = lua_interface->GetSpawn(state);
  8796. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8797. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8798. if (!player) {
  8799. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8800. return 0;
  8801. }
  8802. if (!player->IsPlayer()) {
  8803. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8804. return 0;
  8805. }
  8806. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8807. return 1;
  8808. }
  8809. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8810. if (!lua_interface)
  8811. return 0;
  8812. Spawn* player = lua_interface->GetSpawn(state);
  8813. int8 level = lua_interface->GetInt8Value(state, 2);
  8814. if (!player) {
  8815. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8816. return 0;
  8817. }
  8818. if (!player->IsPlayer()) {
  8819. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8820. return 0;
  8821. }
  8822. if (level == 0) {
  8823. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8824. return 0;
  8825. }
  8826. Client* client = player->GetZone()->GetClientBySpawn(player);
  8827. if (!client) {
  8828. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8829. return 0;
  8830. }
  8831. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8832. return 0;
  8833. }
  8834. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8835. if (!lua_interface)
  8836. return 0;
  8837. Spawn* player = lua_interface->GetSpawn(state);
  8838. int32 amount = lua_interface->GetInt32Value(state, 2);
  8839. if (!player) {
  8840. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8841. return 0;
  8842. }
  8843. if (!player->IsPlayer()) {
  8844. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8845. return 0;
  8846. }
  8847. if (amount == 0) {
  8848. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8849. return 0;
  8850. }
  8851. ((Player*)player)->AddCoins(amount);
  8852. return 0;
  8853. }
  8854. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8855. if (!lua_interface)
  8856. return 0;
  8857. Spawn* player = lua_interface->GetSpawn(state);
  8858. int32 amount = lua_interface->GetInt32Value(state, 2);
  8859. if (!player) {
  8860. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8861. return 0;
  8862. }
  8863. if (!player->IsPlayer()) {
  8864. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8865. return 0;
  8866. }
  8867. if (amount == 0) {
  8868. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8869. return 0;
  8870. }
  8871. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8872. return 1;
  8873. }
  8874. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8875. if (!lua_interface)
  8876. return 0;
  8877. ZoneServer* zone = lua_interface->GetZone(state);
  8878. if (!zone) {
  8879. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8880. return 0;
  8881. }
  8882. vector<Entity*> players = zone->GetPlayers();
  8883. if (players.size() == 0)
  8884. return 0;
  8885. lua_createtable(state, players.size(), 0);
  8886. int newTable = lua_gettop(state);
  8887. for (int32 i = 0; i < players.size(); i++) {
  8888. lua_interface->SetSpawnValue(state, players.at(i));
  8889. lua_rawseti(state, newTable, i + 1);
  8890. }
  8891. return 1;
  8892. }
  8893. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8894. if (!lua_interface)
  8895. return 0;
  8896. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8897. if (!zone) {
  8898. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8899. return 0;
  8900. }
  8901. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8902. //Map of <placement_id, location_id>
  8903. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8904. map<int32, int32>::iterator itr;
  8905. vector<Spawn*> group;
  8906. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8907. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8908. if (!location) {
  8909. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8910. return 0;
  8911. }
  8912. Spawn* spawn = 0;
  8913. if (location->entities[0]) {
  8914. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8915. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8916. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8917. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8918. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8919. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8920. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8921. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8922. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8923. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8924. if(spawn && spawn->IsOmittedByDBFlag())
  8925. {
  8926. 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);
  8927. safe_delete(spawn);
  8928. continue;
  8929. }
  8930. if (spawn) {
  8931. const char* script = 0;
  8932. for (int x = 0; x < 3; x++) {
  8933. switch (x) {
  8934. case 0:
  8935. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8936. break;
  8937. case 1:
  8938. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8939. break;
  8940. case 2:
  8941. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8942. break;
  8943. }
  8944. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8945. spawn->SetSpawnScript(string(script));
  8946. break;
  8947. }
  8948. }
  8949. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8950. lua_interface->SetSpawnValue(state, spawn);
  8951. group.push_back(spawn);
  8952. }
  8953. else {
  8954. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  8955. safe_delete(spawn);
  8956. }
  8957. }
  8958. }
  8959. if (!group.empty()) {
  8960. lua_createtable(state, group.size(), 0);
  8961. int newTable = lua_gettop(state);
  8962. for (int32 i = 0; i < group.size(); i++) {
  8963. lua_interface->SetSpawnValue(state, group[i]);
  8964. lua_rawseti(state, newTable, i + 1);
  8965. }
  8966. }
  8967. else
  8968. lua_pushnil(state);
  8969. return 1;
  8970. }
  8971. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8972. if (!lua_interface)
  8973. return 0;
  8974. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8975. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8976. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8977. if (!spawn) {
  8978. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8979. return 0;
  8980. }
  8981. if (anim_id == 0) {
  8982. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8983. return 0;
  8984. }
  8985. if (leeway == 0)
  8986. leeway = 5000;
  8987. spawn->SetSpawnAnim(anim_id);
  8988. spawn->SetSpawnAnimLeeway(leeway);
  8989. return 0;
  8990. }
  8991. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8992. if (!lua_interface)
  8993. return 0;
  8994. Spawn* player = lua_interface->GetSpawn(state);
  8995. if (!player) {
  8996. return 0;
  8997. }
  8998. Client* client = player->GetZone()->GetClientBySpawn(player);
  8999. if (!client) {
  9000. return 0;
  9001. }
  9002. lua_interface->SetInt32Value(state, client->GetVersion());
  9003. return 1;
  9004. }
  9005. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9006. if (!lua_interface)
  9007. return 0;
  9008. Item* item = lua_interface->GetItem(state);
  9009. if (!item) {
  9010. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9011. return 0;
  9012. }
  9013. lua_interface->SetInt32Value(state, item->details.item_id);
  9014. return 1;
  9015. }
  9016. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9017. if (!lua_interface)
  9018. return 0;
  9019. Spawn* spawn = lua_interface->GetSpawn(state);
  9020. if (!spawn) {
  9021. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9022. return 0;
  9023. }
  9024. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9025. return 1;
  9026. }
  9027. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9028. if (!lua_interface)
  9029. return 0;
  9030. Spawn* spawn = lua_interface->GetSpawn(state);
  9031. if (!spawn) {
  9032. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9033. return 0;
  9034. }
  9035. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9036. return 1;
  9037. }
  9038. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9039. if (!lua_interface)
  9040. return 0;
  9041. Spawn* spawn = lua_interface->GetSpawn(state);
  9042. if (!spawn) {
  9043. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9044. return 0;
  9045. }
  9046. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9047. return 1;
  9048. }
  9049. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9050. if (!lua_interface)
  9051. return 0;
  9052. Spawn* spawn = lua_interface->GetSpawn(state);
  9053. if (!spawn) {
  9054. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9055. return 0;
  9056. }
  9057. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9058. return 1;
  9059. }
  9060. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9061. if (!lua_interface)
  9062. return 0;
  9063. Spawn* spawn = lua_interface->GetSpawn(state);
  9064. float pct = lua_interface->GetFloatValue(state, 2);
  9065. if (!spawn) {
  9066. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9067. return 0;
  9068. }
  9069. if (pct == 0) {
  9070. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9071. return 0;
  9072. }
  9073. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9074. lua_interface->SetInt32Value(state, amount);
  9075. return 1;
  9076. }
  9077. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9078. if (!lua_interface)
  9079. return 0;
  9080. Spawn* spawn = lua_interface->GetSpawn(state);
  9081. float pct = lua_interface->GetFloatValue(state, 2);
  9082. if (!spawn) {
  9083. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9084. return 0;
  9085. }
  9086. if (pct == 0) {
  9087. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9088. return 0;
  9089. }
  9090. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9091. lua_interface->SetInt32Value(state, amount);
  9092. return 1;
  9093. }
  9094. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9095. if (!lua_interface)
  9096. return 0;
  9097. Spawn* spawn = lua_interface->GetSpawn(state);
  9098. if (!spawn) {
  9099. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9100. return 0;
  9101. }
  9102. if (!spawn->IsPlayer()) {
  9103. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9104. return 0;
  9105. }
  9106. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9107. return 1;
  9108. }
  9109. int EQ2Emu_lua_Evac(lua_State* state) {
  9110. if (!lua_interface)
  9111. return 0;
  9112. Spawn* target = lua_interface->GetSpawn(state);
  9113. if (target) {
  9114. float x = target->GetZone()->GetSafeX();
  9115. float y = target->GetZone()->GetSafeY();
  9116. float z = target->GetZone()->GetSafeZ();
  9117. float h = target->GetZone()->GetSafeHeading();
  9118. target->SetX(x);
  9119. target->SetY(y);
  9120. target->SetZ(z);
  9121. target->SetHeading(h);
  9122. target->SetSpawnOrigX(x);
  9123. target->SetSpawnOrigY(y);
  9124. target->SetSpawnOrigZ(z);
  9125. target->SetSpawnOrigHeading(h);
  9126. if (target->IsPlayer()) {
  9127. Client* client = target->GetZone()->GetClientBySpawn(target);
  9128. if (client) {
  9129. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9130. int numargs = lua_interface->GetNumberOfArgs(state);
  9131. if(numargs == 4) {
  9132. x = lua_interface->GetFloatValue(state,1);
  9133. y = lua_interface->GetFloatValue(state,2);
  9134. z = lua_interface->GetFloatValue(state,3);
  9135. h = lua_interface->GetFloatValue(state,4);
  9136. }
  9137. client->SetReloadingZone(true);
  9138. target->SetX(x);
  9139. target->SetY(y);
  9140. target->SetZ(z);
  9141. target->SetHeading(h);
  9142. target->SetSpawnOrigX(x);
  9143. target->SetSpawnOrigY(y);
  9144. target->SetSpawnOrigZ(z);
  9145. target->SetSpawnOrigHeading(h);
  9146. target->SetAppearancePosition(x,y,z);
  9147. client->SetZoningCoords(x,y,z,h);
  9148. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9149. if (packet)
  9150. {
  9151. packet->setDataByName("x", x);
  9152. packet->setDataByName("y", y);
  9153. packet->setDataByName("z", z);
  9154. client->QueuePacket(packet->serialize());
  9155. safe_delete(packet);
  9156. }
  9157. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9158. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9159. }
  9160. }
  9161. }
  9162. else {
  9163. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9164. ZoneServer* zone = spell->caster->GetZone();
  9165. float x = spell->caster->GetZone()->GetSafeX();
  9166. float y = spell->caster->GetZone()->GetSafeY();
  9167. float z = spell->caster->GetZone()->GetSafeZ();
  9168. float h = spell->caster->GetZone()->GetSafeHeading();
  9169. int numargs = lua_interface->GetNumberOfArgs(state);
  9170. if(numargs == 4) {
  9171. x = lua_interface->GetFloatValue(state,1);
  9172. y = lua_interface->GetFloatValue(state,2);
  9173. z = lua_interface->GetFloatValue(state,3);
  9174. h = lua_interface->GetFloatValue(state,4);
  9175. }
  9176. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9177. for (int32 i = 0; i < spell->targets.size(); i++) {
  9178. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9179. if (!target2)
  9180. continue;
  9181. if (target2->IsPlayer()) {
  9182. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9183. if (client) {
  9184. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9185. client->SetReloadingZone(true);
  9186. target2->SetX(x);
  9187. target2->SetY(y);
  9188. target2->SetZ(z);
  9189. target2->SetHeading(h);
  9190. target2->SetSpawnOrigX(x);
  9191. target2->SetSpawnOrigY(y);
  9192. target2->SetSpawnOrigZ(z);
  9193. target2->SetSpawnOrigHeading(h);
  9194. target2->SetAppearancePosition(x,y,z);
  9195. client->SetZoningCoords(x,y,z,h);
  9196. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9197. if (packet)
  9198. {
  9199. packet->setDataByName("x", x);
  9200. packet->setDataByName("y", y);
  9201. packet->setDataByName("z", z);
  9202. client->QueuePacket(packet->serialize());
  9203. safe_delete(packet);
  9204. }
  9205. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9206. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9207. }
  9208. }
  9209. }
  9210. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9211. }
  9212. return 0;
  9213. }
  9214. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9215. if (!lua_interface)
  9216. return 0;
  9217. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9218. if (!luaspell) {
  9219. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9220. return 0;
  9221. }
  9222. int8 tier = luaspell->spell->GetSpellTier();
  9223. lua_interface->SetInt32Value(state, tier);
  9224. return 1;
  9225. }
  9226. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9227. if (!lua_interface)
  9228. return 0;
  9229. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9230. if (!luaspell) {
  9231. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9232. return 0;
  9233. }
  9234. int32 spell_id = luaspell->spell->GetSpellID();
  9235. lua_interface->SetInt32Value(state, spell_id);
  9236. return 1;
  9237. }
  9238. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9239. if (!lua_interface)
  9240. return 0;
  9241. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9242. if (!spawn) {
  9243. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9244. return 0;
  9245. }
  9246. if (!spawn->IsPlayer()) {
  9247. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9248. return 0;
  9249. }
  9250. ZoneServer* zone = spawn->GetZone();
  9251. if (!zone) {
  9252. return 0;
  9253. }
  9254. Client* client = zone->GetClientBySpawn(spawn);
  9255. if (!client) {
  9256. return 0;
  9257. }
  9258. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9259. return 0;
  9260. }
  9261. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9262. if (!lua_interface)
  9263. return 0;
  9264. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9265. if (!spawn) {
  9266. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9267. return 0;
  9268. }
  9269. if (!spawn->IsPlayer()) {
  9270. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9271. return 0;
  9272. }
  9273. ZoneServer* zone = spawn->GetZone();
  9274. if (!zone) {
  9275. return 0;
  9276. }
  9277. Client* client = zone->GetClientBySpawn(spawn);
  9278. if (!client) {
  9279. return 0;
  9280. }
  9281. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9282. return 0;
  9283. }
  9284. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9285. if (!lua_interface)
  9286. return 0;
  9287. Spawn* caster = lua_interface->GetSpawn(state);
  9288. Spawn* target = lua_interface->GetSpawn(state, 2);
  9289. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9290. string spell_name = lua_interface->GetStringValue(state, 4);
  9291. if (!caster) {
  9292. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9293. return 0;
  9294. }
  9295. if (!caster->IsEntity()) {
  9296. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9297. return 0;
  9298. }
  9299. if (!target) {
  9300. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9301. return 0;
  9302. }
  9303. if (!target->IsEntity()) {
  9304. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9305. return 0;
  9306. }
  9307. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9308. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9309. return 0;
  9310. }
  9311. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9312. if (!lua_interface)
  9313. return 0;
  9314. Spawn* player = lua_interface->GetSpawn(state);
  9315. int32 amount = lua_interface->GetInt32Value(state, 2);
  9316. if (player && player->IsPlayer() && amount > 0) {
  9317. ((Player*)player)->AddXP(amount);
  9318. ((Player*)player)->SetCharSheetChanged(true);
  9319. Client* client = player->GetZone()->GetClientBySpawn(player);
  9320. if (client) {
  9321. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9322. }
  9323. }
  9324. return 0;
  9325. }
  9326. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9327. if (!lua_interface)
  9328. return 0;
  9329. Spawn* player = lua_interface->GetSpawn(state);
  9330. int8 type = lua_interface->GetInt8Value(state, 2);
  9331. string text = lua_interface->GetStringValue(state, 3);
  9332. Client* client = 0;
  9333. if (player && player->IsPlayer())
  9334. client = player->GetZone()->GetClientBySpawn(player);
  9335. if (!client || text.length() == 0) {
  9336. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9337. return 0;
  9338. }
  9339. client->SimpleMessage(type, text.c_str());
  9340. return 0;
  9341. }
  9342. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9343. if (!lua_interface)
  9344. return 0;
  9345. Spawn* player = lua_interface->GetSpawn(state);
  9346. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9347. Client* client = 0;
  9348. if (player && player->IsPlayer())
  9349. client = player->GetZone()->GetClientBySpawn(player);
  9350. if (!client || !spawn) {
  9351. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9352. return 0;
  9353. }
  9354. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9355. if (!items) {
  9356. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9357. return 0;
  9358. }
  9359. client->Loot(spawn->GetLootCoins(), items, spawn);
  9360. return 0;
  9361. }
  9362. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9363. if (!lua_interface)
  9364. return 0;
  9365. Spawn* spawnref = lua_interface->GetSpawn(state);
  9366. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9367. if (spawn_id > 0 && spawnref) {
  9368. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9369. if (spawns.size() == 0) {
  9370. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9371. return 0;
  9372. }
  9373. Spawn* spawn = 0;
  9374. int16 index = MakeRandomInt(0, spawns.size());
  9375. if (index >= spawns.size() || index < 0)
  9376. index = 0;
  9377. spawn = spawns[index];
  9378. lua_interface->SetSpawnValue(state, spawn);
  9379. return 1;
  9380. }
  9381. else {
  9382. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9383. }
  9384. return 0;
  9385. }
  9386. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9387. Spawn* player = lua_interface->GetSpawn(state);
  9388. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9389. string name = lua_interface->GetStringValue(state, 3);
  9390. float distance = lua_interface->GetFloatValue(state, 4);
  9391. string command = lua_interface->GetStringValue(state, 5);
  9392. string error_text = lua_interface->GetStringValue(state, 6);
  9393. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9394. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9395. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9396. if (distance == 0)
  9397. distance = 10.0f;
  9398. if (command.length() == 0)
  9399. command = name;
  9400. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9401. if (spawns.size() == 0) {
  9402. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9403. return 0;
  9404. }
  9405. Spawn* spawn = 0;
  9406. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9407. spawn = *itr;
  9408. if (spawn) {
  9409. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9410. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9411. }
  9412. }
  9413. }
  9414. return 0;
  9415. }
  9416. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9417. if (!lua_interface)
  9418. return 0;
  9419. Client* client = 0;
  9420. Spawn* player = lua_interface->GetSpawn(state);
  9421. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9422. if (player && player->IsPlayer() && player->GetZone())
  9423. client = player->GetZone()->GetClientBySpawn(player);
  9424. else{
  9425. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9426. return 0;
  9427. }
  9428. if (client) {
  9429. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9430. if (packet) {
  9431. packet->setDataByName("goal_num", goal_num);
  9432. client->QueuePacket(packet->serialize());
  9433. safe_delete(packet);
  9434. }
  9435. }
  9436. return 0;
  9437. }
  9438. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9439. if (!lua_interface)
  9440. return 0;
  9441. Client* client = 0;
  9442. Spawn* player = lua_interface->GetSpawn(state);
  9443. if (player && player->IsPlayer() && player->GetZone())
  9444. client = player->GetZone()->GetClientBySpawn(player);
  9445. else {
  9446. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9447. return 0;
  9448. }
  9449. if (client) {
  9450. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9451. }
  9452. return 0;
  9453. }
  9454. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9455. if (!lua_interface)
  9456. return 0;
  9457. Client* client = 0;
  9458. Spawn* player = lua_interface->GetSpawn(state);
  9459. float duration = lua_interface->GetFloatValue(state, 2);
  9460. string text = lua_interface->GetStringValue(state, 3);
  9461. string voice = lua_interface->GetStringValue(state, 4);
  9462. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9463. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9464. string signal = lua_interface->GetStringValue(state, 7);
  9465. string goal1 = lua_interface->GetStringValue(state, 8);
  9466. string task1 = lua_interface->GetStringValue(state, 9);
  9467. string goal2 = lua_interface->GetStringValue(state, 10);
  9468. string task2 = lua_interface->GetStringValue(state, 11);
  9469. string goal3 = lua_interface->GetStringValue(state, 12);
  9470. string task3 = lua_interface->GetStringValue(state, 13);
  9471. string goal4 = lua_interface->GetStringValue(state, 14);
  9472. string task4 = lua_interface->GetStringValue(state, 15);
  9473. if (!player) {
  9474. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9475. return 0;
  9476. }
  9477. if (!player->IsPlayer()) {
  9478. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9479. return 0;
  9480. }
  9481. else
  9482. client = ((Player*)player)->GetClient();
  9483. if (!client) {
  9484. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9485. return 0;
  9486. }
  9487. if (text.length() == 0) {
  9488. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9489. return 0;
  9490. }
  9491. if (duration >= 0 && duration < 2)
  9492. duration = 2;
  9493. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9494. if (packet) {
  9495. packet->setDataByName("open_seconds_max", duration);
  9496. packet->setDataByName("text", text.c_str());
  9497. packet->setDataByName("voice", voice.c_str());
  9498. int8 num_goals = 1;
  9499. if (task2.length() > 0)
  9500. num_goals++;
  9501. if (task3.length() > 0)
  9502. num_goals++;
  9503. if (task4.length() > 0)
  9504. num_goals++;
  9505. packet->setArrayLengthByName("num_goals", num_goals);
  9506. for (int8 i = 0; i < num_goals; i++) {
  9507. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9508. }
  9509. if (goal1.length() > 0)
  9510. packet->setArrayDataByName("goal_text", goal1.c_str());
  9511. if (goal2.length() > 0)
  9512. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9513. if (goal3.length() > 0)
  9514. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9515. if (goal4.length() > 0)
  9516. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9517. packet->setSubArrayDataByName("task_text", task1.c_str());
  9518. if (task2.length() > 0)
  9519. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9520. if (task3.length() > 0)
  9521. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9522. if (task4.length() > 0)
  9523. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9524. packet->setDataByName("complete_sound", "click");
  9525. packet->setDataByName("signal", signal.c_str());
  9526. packet->setDataByName("voice_key1", voice_key1);
  9527. packet->setDataByName("voice_key2", voice_key2);
  9528. client->QueuePacket(packet->serialize());
  9529. safe_delete(packet);
  9530. }
  9531. return 0;
  9532. }
  9533. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9534. if (!lua_interface)
  9535. return 0;
  9536. Client* client = 0;
  9537. Spawn* player = lua_interface->GetSpawn(state);
  9538. string window = lua_interface->GetStringValue(state, 2);
  9539. int8 show = lua_interface->GetInt8Value(state, 3);
  9540. if (!player) {
  9541. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9542. return 0;
  9543. }
  9544. if (!player->IsPlayer()) {
  9545. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9546. return 0;
  9547. }
  9548. else
  9549. client = ((Player*)player)->GetClient();
  9550. if (!client) {
  9551. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9552. return 0;
  9553. }
  9554. if (window.length() == 0) {
  9555. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9556. return 0;
  9557. }
  9558. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9559. if (packet) {
  9560. packet->setDataByName("window", window.c_str());
  9561. packet->setDataByName("show", show);
  9562. client->QueuePacket(packet->serialize());
  9563. safe_delete(packet);
  9564. }
  9565. return 0;
  9566. }
  9567. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9568. //See GameEvents.txt for options that can be used for this function
  9569. if (!lua_interface)
  9570. return 0;
  9571. Client* client = 0;
  9572. Spawn* player = lua_interface->GetSpawn(state);
  9573. string event_name = lua_interface->GetStringValue(state, 2);
  9574. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9575. if (!player || !player->IsPlayer()) {
  9576. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9577. return 0;
  9578. }
  9579. if (player->GetZone())
  9580. client = player->GetZone()->GetClientBySpawn(player);
  9581. if (!client) {
  9582. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9583. return 0;
  9584. }
  9585. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9586. if (packet) {
  9587. packet->setDataByName("event_name", event_name.c_str());
  9588. packet->setDataByName("enabled", enabled);
  9589. client->QueuePacket(packet->serialize());
  9590. safe_delete(packet);
  9591. }
  9592. return 0;
  9593. }
  9594. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9595. if (!lua_interface)
  9596. return 0;
  9597. Spawn* player = lua_interface->GetSpawn(state);
  9598. if (player && player->IsPlayer()) {
  9599. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9600. return 1;
  9601. }
  9602. return 0;
  9603. }
  9604. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9605. if (!lua_interface)
  9606. return 0;
  9607. Spawn* player = lua_interface->GetSpawn(state);
  9608. int8 step = lua_interface->GetInt8Value(state, 2);
  9609. if (player && player->IsPlayer() && step > 0) {
  9610. ((Player*)player)->SetTutorialStep(step);
  9611. }
  9612. return 0;
  9613. }
  9614. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9615. if (!lua_interface)
  9616. return 0;
  9617. Client* client = 0;
  9618. Spawn* player = lua_interface->GetSpawn(state);
  9619. string window = lua_interface->GetStringValue(state, 2);
  9620. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9621. if (!player) {
  9622. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9623. return 0;
  9624. }
  9625. if (!player->IsPlayer()) {
  9626. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9627. return 0;
  9628. }
  9629. else
  9630. client = ((Player*)player)->GetClient();
  9631. if (!client) {
  9632. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9633. return 0;
  9634. }
  9635. if (window.length() == 0) {
  9636. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9637. return 0;
  9638. }
  9639. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9640. if (packet) {
  9641. packet->setDataByName("window", window.c_str());
  9642. packet->setDataByName("flash_seconds", flash_seconds);
  9643. client->QueuePacket(packet->serialize());
  9644. safe_delete(packet);
  9645. }
  9646. return 0;
  9647. }
  9648. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9649. if (!lua_interface)
  9650. return 0;
  9651. Spawn* spawn = lua_interface->GetSpawn(state);
  9652. Spawn* target = lua_interface->GetSpawn(state, 2);
  9653. if (spawn && target)
  9654. return spawn->CheckLoS(target);
  9655. return 0;
  9656. }
  9657. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9658. if (!lua_interface)
  9659. return 0;
  9660. Spawn* spawn = lua_interface->GetSpawn(state);
  9661. float x = lua_interface->GetFloatValue(state, 2);
  9662. float y = lua_interface->GetFloatValue(state, 3);
  9663. float z = lua_interface->GetFloatValue(state, 4);
  9664. if (spawn)
  9665. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9666. return 0;
  9667. }
  9668. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9669. if (!lua_interface)
  9670. return 0;
  9671. ZoneServer* zone = lua_interface->GetZone(state);
  9672. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9673. if (zone)
  9674. zone->SetExpansionFlag(xpackFlag);
  9675. return 0;
  9676. }
  9677. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9678. if (!lua_interface)
  9679. return 0;
  9680. ZoneServer* zone = lua_interface->GetZone(state);
  9681. if (zone) {
  9682. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9683. return 1;
  9684. }
  9685. return 0;
  9686. }
  9687. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9688. if (!lua_interface)
  9689. return 0;
  9690. ZoneServer* zone = lua_interface->GetZone(state);
  9691. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9692. if (zone)
  9693. zone->SetHolidayFlag(holidayFlag);
  9694. return 0;
  9695. }
  9696. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9697. if (!lua_interface)
  9698. return 0;
  9699. ZoneServer* zone = lua_interface->GetZone(state);
  9700. if (zone) {
  9701. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9702. return 1;
  9703. }
  9704. return 0;
  9705. }
  9706. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  9707. if (!lua_interface)
  9708. return 0;
  9709. Spawn* player = lua_interface->GetSpawn(state);
  9710. ZoneServer* zone = player->GetZone();
  9711. bool canbind = lua_interface->GetInt32Value(state, 2);
  9712. if (zone)
  9713. zone->SetCanBind(canbind);
  9714. return 0;
  9715. }
  9716. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  9717. if (!lua_interface)
  9718. return 0;
  9719. Spawn* player = lua_interface->GetSpawn(state);
  9720. ZoneServer* zone = player->GetZone();
  9721. if (zone) {
  9722. lua_interface->SetInt32Value(state, zone->GetCanBind());
  9723. return 1;
  9724. }
  9725. return 0;
  9726. }
  9727. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  9728. if (!lua_interface)
  9729. return 0;
  9730. Spawn* player = lua_interface->GetSpawn(state);
  9731. ZoneServer* zone = player->GetZone();
  9732. bool cangate = lua_interface->GetInt32Value(state, 2);
  9733. if (zone)
  9734. zone->SetCanGate(cangate);
  9735. return 0;
  9736. }
  9737. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  9738. if (!lua_interface)
  9739. return 0;
  9740. Spawn* player = lua_interface->GetSpawn(state);
  9741. ZoneServer* zone = player->GetZone();
  9742. if (zone) {
  9743. lua_interface->SetInt32Value(state, zone->GetCanGate());
  9744. return 1;
  9745. }
  9746. return 0;
  9747. }
  9748. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9749. if (!lua_interface)
  9750. return 0;
  9751. Spawn* spawn = lua_interface->GetSpawn(state);
  9752. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9753. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9754. float distance = lua_interface->GetFloatValue(state, 4);
  9755. string in_range_function = lua_interface->GetStringValue(state, 5);
  9756. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9757. if (spawn && distance > 0 && in_range_function.length() > 0)
  9758. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9759. return 0;
  9760. }
  9761. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9762. if (!lua_interface)
  9763. return 0;
  9764. Spawn* spawn = lua_interface->GetSpawn(state);
  9765. Spawn* target = lua_interface->GetSpawn(state, 2);
  9766. if (spawn && target)
  9767. {
  9768. if (spawn->IsPlayer() && target->IsEntity())
  9769. {
  9770. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9771. return 1;
  9772. }
  9773. else if (spawn->IsEntity() && target->IsEntity())
  9774. {
  9775. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9776. return 1;
  9777. }
  9778. }
  9779. return 0;
  9780. }
  9781. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9782. if (!lua_interface)
  9783. return 0;
  9784. Spawn* spawn = lua_interface->GetSpawn(state);
  9785. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9786. if (spawn && spawn->IsEntity())
  9787. {
  9788. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9789. if (spawn->IsPlayer())
  9790. {
  9791. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9792. if (client)
  9793. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9794. }
  9795. }
  9796. return 0;
  9797. }
  9798. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9799. if (!lua_interface)
  9800. return 0;
  9801. Spawn* spawn = lua_interface->GetSpawn(state);
  9802. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9803. if (spawn && spawn->IsEntity())
  9804. {
  9805. ((Entity*)spawn)->SetSeeHideSpell(val);
  9806. if (spawn->IsPlayer())
  9807. {
  9808. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9809. if (client)
  9810. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9811. }
  9812. }
  9813. return 0;
  9814. }
  9815. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9816. {
  9817. if (!lua_interface)
  9818. return 0;
  9819. Spawn* player = lua_interface->GetSpawn(state);
  9820. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9821. string command = lua_interface->GetStringValue(state, 3);
  9822. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9823. lua_interface->ResetFunctionStack(state);
  9824. if (spawn && player && player->IsPlayer())
  9825. {
  9826. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9827. bool res = false;
  9828. if (cmd)
  9829. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9830. lua_interface->SetBooleanValue(state, res);
  9831. return 1;
  9832. }
  9833. return 0;
  9834. }
  9835. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9836. {
  9837. if (!lua_interface)
  9838. return 0;
  9839. Spawn* spawn = lua_interface->GetSpawn(state);
  9840. int32 charID = lua_interface->GetInt32Value(state, 2);
  9841. string command = lua_interface->GetStringValue(state, 3);
  9842. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9843. lua_interface->ResetFunctionStack(state);
  9844. if (spawn && charID)
  9845. {
  9846. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9847. bool res = false;
  9848. if (cmd)
  9849. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9850. lua_interface->SetBooleanValue(state, res);
  9851. return 1;
  9852. }
  9853. return 0;
  9854. }
  9855. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9856. {
  9857. if (!lua_interface)
  9858. return 0;
  9859. Spawn* spawn = lua_interface->GetSpawn(state);
  9860. string command = lua_interface->GetStringValue(state, 2);
  9861. lua_interface->ResetFunctionStack(state);
  9862. if (spawn && command.length() > 0)
  9863. spawn->RemovePrimaryEntityCommand(command.c_str());
  9864. return 0;
  9865. }
  9866. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9867. if (!lua_interface)
  9868. return 0;
  9869. Spawn* spawn = lua_interface->GetSpawn(state);
  9870. float distance = lua_interface->GetFloatValue(state, 2);
  9871. string command = lua_interface->GetStringValue(state, 3);
  9872. Spawn* player = lua_interface->GetSpawn(state, 4);
  9873. lua_interface->ResetFunctionStack(state);
  9874. if (spawn) {
  9875. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9876. }
  9877. return 0;
  9878. }
  9879. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9880. if (!lua_interface)
  9881. return 0;
  9882. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9883. Spawn* spawn = lua_interface->GetSpawn(state);
  9884. Spawn* player = lua_interface->GetSpawn(state, 2);
  9885. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9886. lua_interface->ResetFunctionStack(state);
  9887. if (spawn && player && transport_id && player->IsPlayer()) {
  9888. Client* client = 0;
  9889. if (player && player->IsPlayer())
  9890. client = player->GetZone()->GetClientBySpawn(player);
  9891. if (!client)
  9892. return 0;
  9893. vector<TransportDestination*> destinations;
  9894. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9895. if (destinations.size())
  9896. {
  9897. client->SetTemporaryTransportID(transport_id);
  9898. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9899. }
  9900. else
  9901. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9902. }
  9903. return 0;
  9904. }
  9905. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9906. if (!lua_interface)
  9907. return 0;
  9908. Spawn* player = lua_interface->GetSpawn(state);
  9909. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9910. lua_interface->ResetFunctionStack(state);
  9911. if (player && player->IsPlayer()) {
  9912. Client* client = 0;
  9913. if (player && player->IsPlayer())
  9914. client = player->GetZone()->GetClientBySpawn(player);
  9915. if (!client)
  9916. return 0;
  9917. client->SetTemporaryTransportID(transport_id);
  9918. }
  9919. return 0;
  9920. }
  9921. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9922. if (!lua_interface)
  9923. return 0;
  9924. Spawn* player = lua_interface->GetSpawn(state);
  9925. lua_interface->ResetFunctionStack(state);
  9926. if (player && player->IsPlayer()) {
  9927. Client* client = 0;
  9928. if (player && player->IsPlayer())
  9929. client = player->GetZone()->GetClientBySpawn(player);
  9930. if (!client)
  9931. return 0;
  9932. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9933. return 1;
  9934. }
  9935. return 0;
  9936. }
  9937. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9938. if (!lua_interface)
  9939. return 0;
  9940. Spawn* spawn = lua_interface->GetSpawn(state);
  9941. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9942. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9943. if (!spawn) {
  9944. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9945. return 0;
  9946. }
  9947. if (!spawn->IsEntity()) {
  9948. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9949. return 0;
  9950. }
  9951. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9952. {
  9953. 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);
  9954. return 0;
  9955. }
  9956. lua_interface->ResetFunctionStack(state);
  9957. if (spell && spell->targets.size() > 0) {
  9958. ZoneServer* zone = spell->caster->GetZone();
  9959. for (int8 i = 0; i < spell->targets.size(); i++) {
  9960. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9961. if (target && target->IsEntity()) {
  9962. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9963. if (target->IsPlayer())
  9964. ((Player*)target)->SetCharSheetChanged(true);
  9965. }
  9966. }
  9967. }
  9968. else {
  9969. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9970. if (spawn->IsPlayer())
  9971. ((Player*)spawn)->SetCharSheetChanged(true);
  9972. }
  9973. return 0;
  9974. }
  9975. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9976. if (!lua_interface)
  9977. return 0;
  9978. Spawn* spawn = lua_interface->GetSpawn(state);
  9979. lua_interface->ResetFunctionStack(state);
  9980. if (!spawn) {
  9981. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9982. return 0;
  9983. }
  9984. if (!spawn->IsEntity()) {
  9985. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9986. return 0;
  9987. }
  9988. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9989. return 1;
  9990. }
  9991. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9992. if (!lua_interface)
  9993. return 0;
  9994. int32 spell_id = lua_interface->GetInt32Value(state);
  9995. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9996. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9997. if (spell_id > 0) {
  9998. if (spell_tier == 0)
  9999. spell_tier = 1;
  10000. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10001. LuaSpell* lua_spell = 0;
  10002. if(custom_lua_script.size() > 0)
  10003. {
  10004. // attempt to load the custom script since it isn't already loaded
  10005. // we will re-obtain the lua_spell further below
  10006. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10007. {
  10008. 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());
  10009. lua_interface->LoadLuaSpell(custom_lua_script);
  10010. }
  10011. }
  10012. else
  10013. custom_lua_script = spell->GetSpellData()->lua_script;
  10014. if (!lua_spell && lua_interface)
  10015. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10016. if (!lua_spell)
  10017. {
  10018. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10019. return 0;
  10020. }
  10021. lua_spell->spell = new Spell(spell);
  10022. lua_interface->AddCustomSpell(lua_spell);
  10023. lua_interface->SetSpellValue(state, lua_spell);
  10024. return 1;
  10025. }
  10026. return 0;
  10027. }
  10028. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10029. if (!lua_interface)
  10030. return 0;
  10031. LuaSpell* spell = lua_interface->GetSpell(state);
  10032. string field = lua_interface->GetStringValue(state, 2);
  10033. if (!spell) {
  10034. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10035. return 0;
  10036. }
  10037. if (!spell->spell || !spell->spell->GetSpellData()) {
  10038. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10039. return 0;
  10040. }
  10041. boost::to_lower(field);
  10042. return spell->spell->GetSpellData(state, field);
  10043. }
  10044. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10045. if (!lua_interface)
  10046. return 0;
  10047. LuaSpell* spell = lua_interface->GetSpell(state);
  10048. string field = lua_interface->GetStringValue(state, 2);
  10049. int8 fieldArg = 3; // field value after the initial set
  10050. if (!spell) {
  10051. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10052. return 0;
  10053. }
  10054. if (!spell->spell || !spell->spell->GetSpellData()) {
  10055. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10056. return 0;
  10057. }
  10058. boost::to_lower(field);
  10059. bool valSet = false;
  10060. spell->spell->SetSpellData(state, field, fieldArg);
  10061. return valSet;
  10062. }
  10063. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10064. if (!lua_interface)
  10065. return 0;
  10066. LuaSpell* spell = lua_interface->GetSpell(state);
  10067. int8 idx = lua_interface->GetInt32Value(state, 2);
  10068. if (!spell) {
  10069. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10070. return 0;
  10071. }
  10072. if (!spell->spell || !spell->spell->GetSpellData()) {
  10073. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10074. return 0;
  10075. }
  10076. if (spell->spell->lua_data.size() <= idx)
  10077. {
  10078. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10079. return 0;
  10080. }
  10081. bool setVal = true;
  10082. LUAData* data = spell->spell->lua_data[idx];
  10083. switch (data->type)
  10084. {
  10085. case 0:
  10086. {
  10087. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10088. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10089. data->int_value = value;
  10090. data->int_value2 = value2;
  10091. break;
  10092. }
  10093. case 1:
  10094. {
  10095. float value = lua_interface->GetFloatValue(state, 3);
  10096. float value2 = lua_interface->GetFloatValue(state, 4);
  10097. data->float_value = value;
  10098. data->float_value2 = value2;
  10099. break;
  10100. }
  10101. case 2:
  10102. {
  10103. bool value = lua_interface->GetBooleanValue(state, 3);
  10104. data->bool_value = value;
  10105. break;
  10106. }
  10107. case 3:
  10108. {
  10109. string value = lua_interface->GetStringValue(state, 3);
  10110. string value2 = lua_interface->GetStringValue(state, 4);
  10111. data->string_value = value;
  10112. data->string_value2 = value2;
  10113. break;
  10114. }
  10115. default:
  10116. setVal = false;
  10117. }
  10118. return setVal;
  10119. }
  10120. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10121. if (!lua_interface)
  10122. return 0;
  10123. LuaSpell* spell = lua_interface->GetSpell(state);
  10124. int8 idx = lua_interface->GetInt32Value(state, 2);
  10125. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10126. if (!spell) {
  10127. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10128. return 0;
  10129. }
  10130. if (!spell->spell || !spell->spell->GetSpellData()) {
  10131. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10132. return 0;
  10133. }
  10134. if (spell->spell->lua_data.size() <= idx)
  10135. {
  10136. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10137. return 0;
  10138. }
  10139. bool setVal = true;
  10140. LUAData* data = spell->spell->lua_data[idx];
  10141. switch (data->type)
  10142. {
  10143. case 0:
  10144. {
  10145. if(!secondfield)
  10146. lua_interface->SetSInt32Value(state, data->int_value);
  10147. else
  10148. lua_interface->SetSInt32Value(state, data->int_value2);
  10149. break;
  10150. }
  10151. case 1:
  10152. {
  10153. if (!secondfield)
  10154. lua_interface->SetFloatValue(state, data->float_value);
  10155. else
  10156. lua_interface->SetFloatValue(state, data->float_value2);
  10157. break;
  10158. }
  10159. case 2:
  10160. {
  10161. lua_interface->SetBooleanValue(state, data->bool_value);
  10162. break;
  10163. }
  10164. case 3:
  10165. {
  10166. if (!secondfield)
  10167. lua_interface->SetStringValue(state, data->string_value.c_str());
  10168. else
  10169. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10170. break;
  10171. }
  10172. default:
  10173. setVal = false;
  10174. }
  10175. return setVal;
  10176. }
  10177. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10178. if (!lua_interface)
  10179. return 0;
  10180. LuaSpell* spell = lua_interface->GetSpell(state);
  10181. int8 idx = lua_interface->GetInt32Value(state, 2);
  10182. string field = lua_interface->GetStringValue(state, 3);
  10183. boost::to_lower(field);
  10184. if (!spell) {
  10185. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10186. return 0;
  10187. }
  10188. if (!spell->spell || !spell->spell->GetSpellData()) {
  10189. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10190. return 0;
  10191. }
  10192. if (spell->spell->effects.size() <= idx)
  10193. {
  10194. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10195. return 0;
  10196. }
  10197. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10198. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10199. if (field == "description")
  10200. effect->description = string(lua_interface->GetStringValue(state, 4));
  10201. else if (field == "bullet")
  10202. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10203. else if (field == "percentage")
  10204. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10205. else // no match
  10206. return 0;
  10207. return 1;
  10208. }
  10209. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10210. if (!lua_interface)
  10211. return 0;
  10212. LuaSpell* spell = lua_interface->GetSpell(state);
  10213. int8 idx = lua_interface->GetInt32Value(state, 2);
  10214. string field = lua_interface->GetStringValue(state, 3);
  10215. boost::to_lower(field);
  10216. if (!spell) {
  10217. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10218. return 0;
  10219. }
  10220. if (!spell->spell || !spell->spell->GetSpellData()) {
  10221. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10222. return 0;
  10223. }
  10224. if (spell->spell->effects.size() <= idx)
  10225. {
  10226. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10227. return 0;
  10228. }
  10229. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10230. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10231. if (field == "description")
  10232. lua_interface->SetStringValue(state, effect->description.c_str());
  10233. else if (field == "bullet")
  10234. lua_interface->SetInt32Value(state, effect->subbullet);
  10235. else if (field == "percentage")
  10236. lua_interface->SetInt32Value(state, effect->percentage);
  10237. else // no match
  10238. return 0;
  10239. return 1;
  10240. }
  10241. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10242. if (!lua_interface)
  10243. return 0;
  10244. LuaSpell* spell = lua_interface->GetSpell(state);
  10245. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10246. Spawn* target = lua_interface->GetSpawn(state, 3);
  10247. if (!target) {
  10248. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10249. return 0;
  10250. }
  10251. if (!target->IsEntity()) {
  10252. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10253. return 0;
  10254. }
  10255. if (!spell) {
  10256. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10257. return 0;
  10258. }
  10259. if (caster && !caster->IsEntity()) {
  10260. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10261. return 0;
  10262. }
  10263. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10264. return 0;
  10265. }
  10266. int EQ2Emu_lua_InWater(lua_State* state) {
  10267. if (!lua_interface)
  10268. return 0;
  10269. Spawn* spawn = lua_interface->GetSpawn(state);
  10270. lua_interface->ResetFunctionStack(state);
  10271. if (spawn) {
  10272. lua_interface->SetBooleanValue(state, spawn->InWater());
  10273. return 1;
  10274. }
  10275. return 0;
  10276. }
  10277. int EQ2Emu_lua_InLava(lua_State* state) {
  10278. if (!lua_interface)
  10279. return 0;
  10280. Spawn* spawn = lua_interface->GetSpawn(state);
  10281. lua_interface->ResetFunctionStack(state);
  10282. if (spawn) {
  10283. lua_interface->SetBooleanValue(state, spawn->InLava());
  10284. return 1;
  10285. }
  10286. return 0;
  10287. }
  10288. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10289. if (!lua_interface)
  10290. return 0;
  10291. Spawn* attacker = lua_interface->GetSpawn(state);
  10292. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10293. int8 type = lua_interface->GetInt8Value(state, 3);
  10294. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10295. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10296. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10297. string spell_name = lua_interface->GetStringValue(state, 7);
  10298. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10299. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10300. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10301. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10302. lua_interface->ResetFunctionStack(state);
  10303. if (!attacker) {
  10304. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10305. return 0;
  10306. }
  10307. if (!attacker->IsEntity()) {
  10308. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10309. return 0;
  10310. }
  10311. if (!victim) {
  10312. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10313. return 0;
  10314. }
  10315. if (!victim->IsEntity()) {
  10316. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10317. return 0;
  10318. }
  10319. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10320. return 0;
  10321. }
  10322. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10323. if (!lua_interface)
  10324. return 0;
  10325. Spawn* spawn = lua_interface->GetSpawn(state);
  10326. lua_interface->ResetFunctionStack(state);
  10327. if (spawn) {
  10328. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10329. return 1;
  10330. }
  10331. return 0;
  10332. }
  10333. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10334. if (!lua_interface)
  10335. return 0;
  10336. Spawn* spawn = lua_interface->GetSpawn(state);
  10337. bool invul = lua_interface->GetBooleanValue(state, 2);
  10338. lua_interface->ResetFunctionStack(state);
  10339. if (spawn) {
  10340. spawn->SetInvulnerable(invul);
  10341. }
  10342. return 0;
  10343. }
  10344. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10345. if (!lua_interface)
  10346. return 0;
  10347. string category = lua_interface->GetStringValue(state);
  10348. string name = lua_interface->GetStringValue(state, 2);
  10349. lua_interface->ResetFunctionStack(state);
  10350. Rule *ret = 0;
  10351. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10352. lua_interface->SetBooleanValue(state, ret->GetBool());
  10353. return 1;
  10354. }
  10355. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10356. return 0;
  10357. }
  10358. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10359. if (!lua_interface)
  10360. return 0;
  10361. string category = lua_interface->GetStringValue(state);
  10362. string name = lua_interface->GetStringValue(state, 2);
  10363. lua_interface->ResetFunctionStack(state);
  10364. Rule *ret = 0;
  10365. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10366. lua_interface->SetInt32Value(state, ret->GetInt32());
  10367. return 1;
  10368. }
  10369. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10370. return 0;
  10371. }
  10372. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10373. if (!lua_interface)
  10374. return 0;
  10375. string category = lua_interface->GetStringValue(state);
  10376. string name = lua_interface->GetStringValue(state, 2);
  10377. lua_interface->ResetFunctionStack(state);
  10378. Rule *ret = 0;
  10379. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10380. lua_interface->SetFloatValue(state, ret->GetFloat());
  10381. return 1;
  10382. }
  10383. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10384. return 0;
  10385. }
  10386. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10387. if (!lua_interface)
  10388. return 0;
  10389. Spawn* spawn = lua_interface->GetSpawn(state);
  10390. string type = lua_interface->GetStringValue(state, 2);
  10391. lua_interface->ResetFunctionStack(state);
  10392. if (spawn) {
  10393. int res = 1;
  10394. boost::to_lower(type);
  10395. if(type == "assigned_aa")
  10396. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10397. else if ( type == "unassigned_aa")
  10398. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10399. else if ( type == "assigned_tradeskill_aa")
  10400. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10401. else if ( type == "unassigned_tradeskill_aa")
  10402. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10403. else if ( type == "assigned_prestige_aa")
  10404. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10405. else if ( type == "unassigned_prestige_aa")
  10406. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10407. else if ( type == "assigned_tradeskill_prestige_aa")
  10408. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10409. else if ( type == "unassigned_tradeskill_prestige_aa")
  10410. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10411. else
  10412. res = 0;
  10413. return res;
  10414. }
  10415. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10416. return 0;
  10417. }
  10418. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10419. if (!lua_interface)
  10420. return 0;
  10421. Spawn* spawn = lua_interface->GetSpawn(state);
  10422. string type = lua_interface->GetStringValue(state, 2);
  10423. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10424. lua_interface->ResetFunctionStack(state);
  10425. if (spawn) {
  10426. boost::to_lower(type);
  10427. if(type == "assigned_aa")
  10428. spawn->SetAssignedAA((sint16)value);
  10429. else if ( type == "unassigned_aa")
  10430. spawn->SetUnassignedAA((sint16)value);
  10431. else if ( type == "assigned_tradeskill_aa")
  10432. spawn->SetTradeskillAA((sint16)value);
  10433. else if ( type == "unassigned_tradeskill_aa")
  10434. spawn->SetUnassignedTradeskillAA((sint16)value);
  10435. else if ( type == "assigned_prestige_aa")
  10436. spawn->SetPrestigeAA((sint16)value);
  10437. else if ( type == "unassigned_prestige_aa")
  10438. spawn->SetUnassignedPrestigeAA((sint16)value);
  10439. else if ( type == "assigned_tradeskill_prestige_aa")
  10440. spawn->SetTradeskillPrestigeAA((sint16)value);
  10441. else if ( type == "unassigned_tradeskill_prestige_aa")
  10442. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10443. if(spawn->IsPlayer())
  10444. ((Player*)spawn)->SetCharSheetChanged(true);
  10445. }
  10446. return 0;
  10447. }
  10448. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10449. if (!lua_interface)
  10450. return 0;
  10451. string titleName = lua_interface->GetStringValue(state);
  10452. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10453. lua_interface->ResetFunctionStack(state);
  10454. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10455. lua_interface->SetSInt32Value(state, index);
  10456. return 1;
  10457. }
  10458. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10459. if (!lua_interface)
  10460. return 0;
  10461. Spawn* spawn = lua_interface->GetSpawn(state);
  10462. string titleName = lua_interface->GetStringValue(state, 2);
  10463. lua_interface->ResetFunctionStack(state);
  10464. if(!spawn->IsPlayer())
  10465. {
  10466. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10467. lua_interface->SetSInt32Value(state, -1);
  10468. return 1;
  10469. }
  10470. Player* player = (Player*)spawn;
  10471. // check if player already has the title, don't need to add twice
  10472. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10473. if ( playerHasTitle)
  10474. {
  10475. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10476. return 1;
  10477. }
  10478. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10479. if(!title)
  10480. {
  10481. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10482. lua_interface->SetSInt32Value(state, -1);
  10483. return 1;
  10484. }
  10485. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10486. if(returnIdx < 0)
  10487. {
  10488. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10489. }
  10490. lua_interface->SetSInt32Value(state, returnIdx);
  10491. player->GetClient()->SendTitleUpdate();
  10492. return 1;
  10493. }
  10494. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10495. if (!lua_interface)
  10496. return 0;
  10497. Spawn* spawn = lua_interface->GetSpawn(state);
  10498. string titleName = lua_interface->GetStringValue(state, 2);
  10499. lua_interface->ResetFunctionStack(state);
  10500. if(!spawn->IsPlayer())
  10501. {
  10502. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10503. return 0;
  10504. }
  10505. Player* player = (Player*)spawn;
  10506. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10507. if(!title)
  10508. {
  10509. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10510. return 0;
  10511. }
  10512. if(title->GetPrefix())
  10513. {
  10514. 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());
  10515. return 0;
  10516. }
  10517. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10518. player->GetClient()->SendTitleUpdate();
  10519. return 1;
  10520. }
  10521. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10522. if (!lua_interface)
  10523. return 0;
  10524. Spawn* spawn = lua_interface->GetSpawn(state);
  10525. string titleName = lua_interface->GetStringValue(state, 2);
  10526. lua_interface->ResetFunctionStack(state);
  10527. if(!spawn->IsPlayer())
  10528. {
  10529. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10530. return 0;
  10531. }
  10532. Player* player = (Player*)spawn;
  10533. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10534. if(!title)
  10535. {
  10536. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10537. return 0;
  10538. }
  10539. if(!title->GetPrefix())
  10540. {
  10541. 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());
  10542. return 0;
  10543. }
  10544. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10545. player->GetClient()->SendTitleUpdate();
  10546. return 1;
  10547. }
  10548. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10549. if (!lua_interface)
  10550. return 0;
  10551. Spawn* spawn = lua_interface->GetSpawn(state);
  10552. lua_interface->ResetFunctionStack(state);
  10553. if(!spawn->IsPlayer())
  10554. {
  10555. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10556. return 0;
  10557. }
  10558. Player* player = (Player*)spawn;
  10559. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10560. player->GetClient()->SendTitleUpdate();
  10561. return 1;
  10562. }
  10563. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10564. if (!lua_interface)
  10565. return 0;
  10566. Spawn* spawn = lua_interface->GetSpawn(state);
  10567. lua_interface->ResetFunctionStack(state);
  10568. if(!spawn->IsPlayer())
  10569. {
  10570. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10571. return 0;
  10572. }
  10573. Player* player = (Player*)spawn;
  10574. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10575. player->GetClient()->SendTitleUpdate();
  10576. return 1;
  10577. }
  10578. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10579. if (!lua_interface)
  10580. return 0;
  10581. Spawn* spawn = lua_interface->GetSpawn(state);
  10582. string field = lua_interface->GetStringValue(state, 2);
  10583. lua_interface->ResetFunctionStack(state);
  10584. if(!spawn || !spawn->IsEntity())
  10585. {
  10586. 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));
  10587. return 0;
  10588. }
  10589. Entity* ent = (Entity*)spawn;
  10590. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10591. return 1;
  10592. }
  10593. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10594. if (!lua_interface)
  10595. return 0;
  10596. Spawn* spawn = lua_interface->GetSpawn(state);
  10597. string field = lua_interface->GetStringValue(state, 2);
  10598. lua_interface->ResetFunctionStack(state);
  10599. if(!spawn || !spawn->IsEntity())
  10600. {
  10601. 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));
  10602. return 0;
  10603. }
  10604. Entity* ent = (Entity*)spawn;
  10605. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10606. return 1;
  10607. }
  10608. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10609. if (!lua_interface)
  10610. return 0;
  10611. Spawn* spawn = lua_interface->GetSpawn(state);
  10612. string field = lua_interface->GetStringValue(state, 2);
  10613. lua_interface->ResetFunctionStack(state);
  10614. if(!spawn || !spawn->IsEntity())
  10615. {
  10616. 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));
  10617. return 0;
  10618. }
  10619. Entity* ent = (Entity*)spawn;
  10620. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10621. return 1;
  10622. }
  10623. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10624. if (!lua_interface)
  10625. return 0;
  10626. Spawn* spawn = lua_interface->GetSpawn(state);
  10627. string field = lua_interface->GetStringValue(state, 2);
  10628. lua_interface->ResetFunctionStack(state);
  10629. if(!spawn || !spawn->IsEntity())
  10630. {
  10631. 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));
  10632. return 0;
  10633. }
  10634. Entity* ent = (Entity*)spawn;
  10635. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10636. return 1;
  10637. }
  10638. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10639. if (!lua_interface)
  10640. return 0;
  10641. Spawn* spawn = lua_interface->GetSpawn(state);
  10642. string field = lua_interface->GetStringValue(state, 2);
  10643. string value = lua_interface->GetStringValue(state, 3);
  10644. lua_interface->ResetFunctionStack(state);
  10645. if(!spawn || !spawn->IsEntity())
  10646. {
  10647. 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));
  10648. return 0;
  10649. }
  10650. Entity* ent = (Entity*)spawn;
  10651. bool set_ = ent->SetInfoStructString(field, value);
  10652. lua_interface->SetBooleanValue(state, set_);
  10653. return 1;
  10654. }
  10655. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10656. if (!lua_interface)
  10657. return 0;
  10658. Spawn* spawn = lua_interface->GetSpawn(state);
  10659. string field = lua_interface->GetStringValue(state, 2);
  10660. int64 value = lua_interface->GetInt64Value(state, 3);
  10661. lua_interface->ResetFunctionStack(state);
  10662. if(!spawn || !spawn->IsEntity())
  10663. {
  10664. 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));
  10665. return 0;
  10666. }
  10667. Entity* ent = (Entity*)spawn;
  10668. bool set_ = ent->SetInfoStructUInt(field, value);
  10669. lua_interface->SetBooleanValue(state, set_);
  10670. return 1;
  10671. }
  10672. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10673. if (!lua_interface)
  10674. return 0;
  10675. Spawn* spawn = lua_interface->GetSpawn(state);
  10676. string field = lua_interface->GetStringValue(state, 2);
  10677. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10678. lua_interface->ResetFunctionStack(state);
  10679. if(!spawn || !spawn->IsEntity())
  10680. {
  10681. 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));
  10682. return 0;
  10683. }
  10684. Entity* ent = (Entity*)spawn;
  10685. bool set_ = ent->SetInfoStructSInt(field, value);
  10686. lua_interface->SetBooleanValue(state, set_);
  10687. return 1;
  10688. }
  10689. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10690. if (!lua_interface)
  10691. return 0;
  10692. Spawn* spawn = lua_interface->GetSpawn(state);
  10693. string field = lua_interface->GetStringValue(state, 2);
  10694. float value = lua_interface->GetFloatValue(state, 3);
  10695. lua_interface->ResetFunctionStack(state);
  10696. if(!spawn || !spawn->IsEntity())
  10697. {
  10698. 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));
  10699. return 0;
  10700. }
  10701. Entity* ent = (Entity*)spawn;
  10702. bool set_ = ent->SetInfoStructFloat(field, value);
  10703. lua_interface->SetBooleanValue(state, set_);
  10704. return 1;
  10705. }
  10706. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10707. if (!lua_interface)
  10708. return 0;
  10709. Spawn* spawn = lua_interface->GetSpawn(state);
  10710. bool value = lua_interface->GetBooleanValue(state, 2);
  10711. lua_interface->ResetFunctionStack(state);
  10712. if(!spawn || !spawn->IsPlayer())
  10713. {
  10714. 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));
  10715. return 0;
  10716. }
  10717. ((Player*)spawn)->SetCharSheetChanged(value);
  10718. return 0;
  10719. }
  10720. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10721. if (!lua_interface)
  10722. return 0;
  10723. Spawn* spawn = lua_interface->GetSpawn(state);
  10724. std::string fromName = lua_interface->GetStringValue(state, 2);
  10725. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10726. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10727. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10728. int32 copper = lua_interface->GetInt32Value(state, 6);
  10729. int32 silver = lua_interface->GetInt32Value(state, 7);
  10730. int32 gold = lua_interface->GetInt32Value(state, 8);
  10731. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10732. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10733. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10734. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10735. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10736. lua_interface->ResetFunctionStack(state);
  10737. if(!spawn || !spawn->IsPlayer())
  10738. {
  10739. 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));
  10740. lua_interface->SetBooleanValue(state, false);
  10741. return 1;
  10742. }
  10743. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10744. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10745. lua_interface->SetBooleanValue(state, true);
  10746. return 1;
  10747. }
  10748. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10749. if (!lua_interface)
  10750. return 0;
  10751. int32 char_id = lua_interface->GetInt32Value(state);
  10752. std::string fromName = lua_interface->GetStringValue(state, 2);
  10753. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10754. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10755. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10756. int32 copper = lua_interface->GetInt32Value(state, 6);
  10757. int32 silver = lua_interface->GetInt32Value(state, 7);
  10758. int32 gold = lua_interface->GetInt32Value(state, 8);
  10759. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10760. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10761. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10762. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10763. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10764. lua_interface->ResetFunctionStack(state);
  10765. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10766. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10767. lua_interface->SetBooleanValue(state, true);
  10768. return 1;
  10769. }
  10770. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10771. Spawn* widget;
  10772. if (lua_interface) {
  10773. widget = lua_interface->GetSpawn(state);
  10774. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10775. lua_interface->ResetFunctionStack(state);
  10776. if (widget && widget->IsWidget())
  10777. {
  10778. ((Widget*)widget)->OpenDoor();
  10779. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10780. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10781. }
  10782. else
  10783. 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));
  10784. }
  10785. return 0;
  10786. }
  10787. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10788. Spawn* widget;
  10789. if (lua_interface) {
  10790. widget = lua_interface->GetSpawn(state);
  10791. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10792. lua_interface->ResetFunctionStack(state);
  10793. if (widget && widget->IsWidget())
  10794. {
  10795. ((Widget*)widget)->CloseDoor();
  10796. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10797. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10798. }
  10799. else
  10800. 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));
  10801. }
  10802. return 0;
  10803. }
  10804. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10805. if (!lua_interface)
  10806. return 0;
  10807. Spawn* widget = lua_interface->GetSpawn(state);
  10808. lua_interface->ResetFunctionStack(state);
  10809. if (widget && widget->IsWidget())
  10810. {
  10811. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10812. return 1;
  10813. }
  10814. return 0;
  10815. }
  10816. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10817. if (!lua_interface)
  10818. return 0;
  10819. sint32 min = lua_interface->GetSInt32Value(state);
  10820. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10821. lua_interface->ResetFunctionStack(state);
  10822. sint32 result = MakeRandomInt(min, max);
  10823. lua_interface->SetSInt32Value(state, result);
  10824. return 1;
  10825. }
  10826. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10827. if (!lua_interface)
  10828. return 0;
  10829. float min = lua_interface->GetFloatValue(state);
  10830. float max = lua_interface->GetFloatValue(state, 2);
  10831. lua_interface->ResetFunctionStack(state);
  10832. float result = MakeRandomFloat(min, max);
  10833. lua_interface->SetFloatValue(state, result);
  10834. return 1;
  10835. }
  10836. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10837. if (!lua_interface)
  10838. return 0;
  10839. Spawn* spawn = lua_interface->GetSpawn(state);
  10840. int32 value = lua_interface->GetInt32Value(state, 2);
  10841. lua_interface->ResetFunctionStack(state);
  10842. if(!spawn)
  10843. {
  10844. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10845. lua_interface->SetBooleanValue(state, false);
  10846. return 1;
  10847. }
  10848. spawn->AddIconValue(value);
  10849. lua_interface->SetBooleanValue(state, true);
  10850. return 1;
  10851. }
  10852. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10853. if (!lua_interface)
  10854. return 0;
  10855. Spawn* spawn = lua_interface->GetSpawn(state);
  10856. int32 value = lua_interface->GetInt32Value(state, 2);
  10857. lua_interface->ResetFunctionStack(state);
  10858. if(!spawn)
  10859. {
  10860. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10861. lua_interface->SetBooleanValue(state, false);
  10862. return 1;
  10863. }
  10864. spawn->RemoveIconValue(value);
  10865. lua_interface->SetBooleanValue(state, true);
  10866. return 1;
  10867. }
  10868. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10869. Spawn* npc = lua_interface->GetSpawn(state);
  10870. lua_interface->ResetFunctionStack(state);
  10871. if (npc && npc->IsNPC()) {
  10872. NPC* shard = (NPC*)npc;
  10873. int32 shardid = shard->GetShardID();
  10874. lua_interface->SetInt32Value(state, shardid);
  10875. return 1;
  10876. }
  10877. lua_interface->SetInt32Value(state, 0);
  10878. return 1;
  10879. }
  10880. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10881. Spawn* npc = lua_interface->GetSpawn(state);
  10882. lua_interface->ResetFunctionStack(state);
  10883. if (npc && npc->IsNPC()) {
  10884. NPC* shard = (NPC*)npc;
  10885. int32 charid = shard->GetShardCharID();
  10886. lua_interface->SetInt32Value(state, charid);
  10887. return 1;
  10888. }
  10889. lua_interface->SetInt32Value(state, 0);
  10890. return 1;
  10891. }
  10892. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10893. Spawn* npc = lua_interface->GetSpawn(state);
  10894. lua_interface->ResetFunctionStack(state);
  10895. if (npc && npc->IsNPC()) {
  10896. NPC* shard = (NPC*)npc;
  10897. int64 timestamp = shard->GetShardCreatedTimestamp();
  10898. lua_interface->SetSInt64Value(state, timestamp);
  10899. return 1;
  10900. }
  10901. lua_interface->SetSInt64Value(state, 0);
  10902. return 1;
  10903. }
  10904. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10905. if (!lua_interface)
  10906. return 0;
  10907. int32 shardid = lua_interface->GetInt32Value(state);
  10908. lua_interface->ResetFunctionStack(state);
  10909. if(shardid < 1)
  10910. lua_interface->SetBooleanValue(state, false);
  10911. else
  10912. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10913. return 1;
  10914. }
  10915. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10916. if (!lua_interface)
  10917. return 0;
  10918. Spawn* spawn = lua_interface->GetSpawn(state);
  10919. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10920. if (spawn) {
  10921. spawn->PauseMovement(delay_in_ms);
  10922. }
  10923. lua_interface->ResetFunctionStack(state);
  10924. return 0;
  10925. }
  10926. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10927. if (!lua_interface)
  10928. return 0;
  10929. Spawn* spawn = lua_interface->GetSpawn(state);
  10930. if (spawn) {
  10931. spawn->StopMovement();
  10932. }
  10933. lua_interface->ResetFunctionStack(state);
  10934. return 0;
  10935. }
  10936. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10937. Player* player = (Player*)lua_interface->GetSpawn(state);
  10938. int8 level = lua_interface->GetInt8Value(state, 2);
  10939. lua_interface->ResetFunctionStack(state);
  10940. if (player && player->IsPlayer() && level > 0) {
  10941. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10942. return 1;
  10943. }
  10944. return 0;
  10945. }
  10946. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10947. Player* player = (Player*)lua_interface->GetSpawn(state);
  10948. int8 level = lua_interface->GetInt8Value(state, 2);
  10949. lua_interface->ResetFunctionStack(state);
  10950. if (player && player->IsPlayer() && level > 0) {
  10951. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10952. return 1;
  10953. }
  10954. return 0;
  10955. }
  10956. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10957. ZoneServer* zone = lua_interface->GetZone(state);
  10958. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10959. lua_interface->ResetFunctionStack(state);
  10960. if (zone) {
  10961. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10962. if (spawn) {
  10963. lua_interface->SetSpawnValue(state, spawn);
  10964. return 1;
  10965. }
  10966. }
  10967. return 0;
  10968. }
  10969. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10970. if (!lua_interface)
  10971. return 0;
  10972. Spawn* spawn = lua_interface->GetSpawn(state);
  10973. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10974. lua_interface->ResetFunctionStack(state);
  10975. bool res = false;
  10976. if(spawn && spawn->IsTransportSpawn())
  10977. {
  10978. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10979. spawn->SetRailID(rail_id);
  10980. res = true;
  10981. }
  10982. else if (!spawn) {
  10983. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10984. }
  10985. else if(!spawn->IsTransportSpawn()) {
  10986. 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());
  10987. }
  10988. lua_interface->SetBooleanValue(state, res);
  10989. return 1;
  10990. }
  10991. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10992. if (!lua_interface)
  10993. return 0;
  10994. ZoneServer* zone = lua_interface->GetZone(state);
  10995. lua_interface->ResetFunctionStack(state);
  10996. if (zone) {
  10997. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10998. return 1;
  10999. }
  11000. return 0;
  11001. }
  11002. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11003. if (!lua_interface)
  11004. return 0;
  11005. Spawn* spawn = lua_interface->GetSpawn(state);
  11006. lua_interface->ResetFunctionStack(state);
  11007. if (spawn) {
  11008. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11009. return 1;
  11010. }
  11011. return 0;
  11012. }
  11013. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11014. if (!lua_interface)
  11015. return 0;
  11016. Spawn* player = lua_interface->GetSpawn(state);
  11017. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11018. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11019. lua_interface->ResetFunctionStack(state);
  11020. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11021. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11022. }
  11023. else if(!zoneID) {
  11024. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11025. }
  11026. else
  11027. {
  11028. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11029. return 1;
  11030. }
  11031. return 0;
  11032. }
  11033. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11034. if (!lua_interface)
  11035. return 0;
  11036. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11037. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11038. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11039. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11040. lua_interface->ResetFunctionStack(state);
  11041. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11042. world.GetWorldTimeStruct()->year = newYear;
  11043. world.GetWorldTimeStruct()->month = newMonth;
  11044. world.GetWorldTimeStruct()->hour = newHour;
  11045. world.GetWorldTimeStruct()->minute = newMinute;
  11046. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11047. return 0;
  11048. }
  11049. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11050. if (!lua_interface)
  11051. return 0;
  11052. lua_interface->ResetFunctionStack(state);
  11053. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11054. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11055. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11056. return 1;
  11057. }
  11058. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11059. if (!lua_interface)
  11060. return 0;
  11061. lua_interface->ResetFunctionStack(state);
  11062. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11063. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11064. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11065. return 1;
  11066. }
  11067. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11068. if (!lua_interface)
  11069. return 0;
  11070. lua_interface->ResetFunctionStack(state);
  11071. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11072. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11073. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11074. return 1;
  11075. }
  11076. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11077. if (!lua_interface)
  11078. return 0;
  11079. lua_interface->ResetFunctionStack(state);
  11080. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11081. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11082. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11083. return 1;
  11084. }
  11085. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11086. if (!lua_interface)
  11087. return 0;
  11088. lua_interface->ResetFunctionStack(state);
  11089. world.SendTimeUpdate();
  11090. return 0;
  11091. }
  11092. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11093. bool update_result = false;
  11094. Faction* faction = 0;
  11095. Player* player = (Player*)lua_interface->GetSpawn(state);
  11096. Client* client = player->GetZone()->GetClientBySpawn(player);
  11097. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11098. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11099. lua_interface->ResetFunctionStack(state);
  11100. if (player && player->IsPlayer() && faction_id > 0) {
  11101. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11102. if(hasfaction == 0) {
  11103. //they do not have the faction. Lets get the default value and feed it in.
  11104. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11105. //add the default faction for the player.
  11106. player->SetFactionValue(faction_id, defaultfaction);
  11107. }
  11108. if(increase >= 0) {
  11109. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11110. faction = master_faction_list.GetFaction(faction_id);
  11111. if(faction && update_result)
  11112. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11113. else if(faction)
  11114. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11115. lua_interface->SetBooleanValue(state, true);
  11116. return 1;
  11117. }
  11118. if(increase < 0){
  11119. //change the negative to a positive, since thats how decreasefaction() likes it.
  11120. increase *= -1;
  11121. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11122. faction = master_faction_list.GetFaction(faction_id);
  11123. if(faction && update_result)
  11124. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11125. else if(faction)
  11126. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11127. lua_interface->SetBooleanValue(state, true);
  11128. return 1;
  11129. }
  11130. }
  11131. lua_interface->SetBooleanValue(state, false);
  11132. return 1;
  11133. }
  11134. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11135. bool hascoin = 0;
  11136. Player* player = (Player*)lua_interface->GetSpawn(state);
  11137. int32 coins = lua_interface->GetInt32Value(state, 2);
  11138. lua_interface->ResetFunctionStack(state);
  11139. if (player && player->IsPlayer()) {
  11140. hascoin = player->HasCoins(coins);
  11141. if(hascoin == 0) {
  11142. lua_interface->SetBooleanValue(state, false);
  11143. return 1;
  11144. }
  11145. if(hascoin == 1) {
  11146. lua_interface->SetBooleanValue(state, true);
  11147. return 1;
  11148. }
  11149. }
  11150. }
  11151. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11152. int32 loot_tier = 0;
  11153. Spawn* spawn = lua_interface->GetSpawn(state);
  11154. lua_interface->ResetFunctionStack(state);
  11155. if (spawn) {
  11156. loot_tier = spawn->GetLootTier();
  11157. lua_interface->SetInt32Value(state, loot_tier);
  11158. return 1;
  11159. }
  11160. return 0;
  11161. }
  11162. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11163. if (!lua_interface)
  11164. return 0;
  11165. Spawn* spawn = lua_interface->GetSpawn(state);
  11166. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11167. lua_interface->ResetFunctionStack(state);
  11168. if (spawn) {
  11169. spawn->SetLootTier(loot_tier);
  11170. lua_interface->SetBooleanValue(state, true);
  11171. return 1;
  11172. }
  11173. lua_interface->SetBooleanValue(state, false);
  11174. return 1;
  11175. }
  11176. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11177. int32 loot_drop_type = 0;
  11178. Spawn* spawn = lua_interface->GetSpawn(state);
  11179. lua_interface->ResetFunctionStack(state);
  11180. if (spawn) {
  11181. loot_drop_type = spawn->GetLootDropType();
  11182. lua_interface->SetInt32Value(state, loot_drop_type);
  11183. return 1;
  11184. }
  11185. return 0;
  11186. }
  11187. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11188. if (!lua_interface)
  11189. return 0;
  11190. Spawn* spawn = lua_interface->GetSpawn(state);
  11191. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11192. lua_interface->ResetFunctionStack(state);
  11193. if (spawn) {
  11194. spawn->SetLootDropType(loot_drop_type);
  11195. lua_interface->SetBooleanValue(state, true);
  11196. return 1;
  11197. }
  11198. lua_interface->SetBooleanValue(state, false);
  11199. return 1;
  11200. }