LuaFunctions.cpp 397 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033
  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_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = spawn->GetZone()->GetClientBySpawn(player);
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = spawn->GetZone()->GetClientBySpawn(player);
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. if (!player) {
  274. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  275. return 0;
  276. }
  277. if (!player->IsPlayer()) {
  278. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  279. return 0;
  280. }
  281. if (player->GetZone())
  282. client = player->GetZone()->GetClientBySpawn(player);
  283. if (!client) {
  284. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  285. return 0;
  286. }
  287. float intensity = lua_interface->GetFloatValue(state, 2);
  288. int8 direction = lua_interface->GetInt8Value(state, 3);
  289. lua_interface->ResetFunctionStack(state);
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 546 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  453. int32 position = lua_interface->GetInt32Value(state, 2);
  454. lua_interface->ResetFunctionStack(state);
  455. if (spawnList) {
  456. if (spawnList->size() > position) {
  457. lua_interface->SetSpawnValue(state, spawnList->at(position));
  458. return 1;
  459. }
  460. else {
  461. return 0;
  462. }
  463. return spawnList->size();
  464. }
  465. return 0;
  466. }
  467. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  468. if (!lua_interface)
  469. return 0;
  470. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  471. lua_interface->ResetFunctionStack(state);
  472. if (spawnList) {
  473. return spawnList->size();
  474. }
  475. return 0;
  476. }
  477. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  478. if (!lua_interface)
  479. return 0;
  480. vector<Spawn*>* spawnList = new vector<Spawn*>();
  481. lua_interface->SetSpawnListValue(state, spawnList);
  482. return 1;
  483. }
  484. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  485. if (!lua_interface)
  486. return 0;
  487. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  488. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  489. lua_interface->ResetFunctionStack(state);
  490. if (spawnList) {
  491. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  492. if (it == spawnList->end())
  493. spawnList->push_back(spawn);
  494. }
  495. return 0;
  496. }
  497. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  498. if (!lua_interface)
  499. return 0;
  500. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  501. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  502. lua_interface->ResetFunctionStack(state);
  503. if (spawnList) {
  504. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  505. if(it != spawnList->end())
  506. spawnList->erase(it);
  507. }
  508. return 0;
  509. }
  510. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  511. if (!lua_interface)
  512. return 0;
  513. Spawn* spawn = lua_interface->GetSpawn(state);
  514. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  515. lua_interface->ResetFunctionStack(state);
  516. if (spawn) {
  517. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  518. if (spawns.size() > 0) {
  519. vector<Spawn*>* spawnList = new vector<Spawn*>();
  520. vector<Spawn*>::iterator itr;
  521. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  522. spawnList->push_back(*itr);
  523. }
  524. lua_interface->SetSpawnListValue(state, spawnList);
  525. return 1;
  526. }
  527. }
  528. return 0;
  529. }
  530. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  531. if (!lua_interface)
  532. return 0;
  533. Spawn* spawn = lua_interface->GetSpawn(state);
  534. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  535. lua_interface->ResetFunctionStack(state);
  536. if (spawn) {
  537. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  538. if (spawns.size() > 0) {
  539. vector<Spawn*>* spawnList = new vector<Spawn*>();
  540. vector<Spawn*>::iterator itr;
  541. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  542. spawnList->push_back(*itr);
  543. }
  544. lua_interface->SetSpawnListValue(state, spawnList);
  545. return 1;
  546. }
  547. }
  548. return 0;
  549. }
  550. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  551. if (!lua_interface)
  552. return 0;
  553. Spawn* spawn = lua_interface->GetSpawn(state);
  554. lua_interface->ResetFunctionStack(state);
  555. if (spawn) {
  556. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  557. if (spawns.size() > 0) {
  558. lua_createtable(state, spawns.size(), 0);
  559. int newTable = lua_gettop(state);
  560. for (int32 i = 0; i < spawns.size(); i++) {
  561. lua_interface->SetSpawnValue(state, spawns.at(i));
  562. lua_rawseti(state, newTable, i + 1);
  563. }
  564. return 1;
  565. }
  566. }
  567. return 0;
  568. }
  569. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  570. if (!lua_interface)
  571. return 0;
  572. string variable_name = lua_interface->GetStringValue(state);
  573. lua_interface->ResetFunctionStack(state);
  574. Variable* var = variables.FindVariable(variable_name);
  575. if (var) {
  576. lua_interface->SetStringValue(state, var->GetValue());
  577. return 1;
  578. }
  579. return 0;
  580. }
  581. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  582. if (!lua_interface)
  583. return 0;
  584. int32 total_coins = lua_interface->GetInt32Value(state);
  585. lua_interface->ResetFunctionStack(state);
  586. if (total_coins == 0) {
  587. lua_interface->SetStringValue(state, "0 copper");
  588. return 1;
  589. }
  590. char tmp[64] = { 0 };
  591. string message = "";
  592. int32 val = 0;
  593. if (total_coins >= 1000000) {
  594. val = total_coins / 1000000;
  595. total_coins -= 1000000 * val;
  596. sprintf(tmp, " %u Platinum", val);
  597. message.append(tmp);
  598. memset(tmp, 0, 64);
  599. }
  600. if (total_coins >= 10000) {
  601. val = total_coins / 10000;
  602. total_coins -= 10000 * val;
  603. sprintf(tmp, " %u Gold", val);
  604. message.append(tmp);
  605. memset(tmp, 0, 64);
  606. }
  607. if (total_coins >= 100) {
  608. val = total_coins / 100;
  609. total_coins -= 100 * val;
  610. sprintf(tmp, " %u Silver", val);
  611. message.append(tmp);
  612. memset(tmp, 0, 64);
  613. }
  614. if (total_coins > 0) {
  615. sprintf(tmp, " %u Copper", (int32)total_coins);
  616. message.append(tmp);
  617. }
  618. lua_interface->SetStringValue(state, message.c_str());
  619. return 1;
  620. }
  621. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  622. ZoneServer* zone = lua_interface->GetZone(state);
  623. int32 group_id = lua_interface->GetInt32Value(state, 2);
  624. lua_interface->ResetFunctionStack(state);
  625. if (zone) {
  626. Spawn* spawn = zone->GetSpawnGroup(group_id);
  627. if (spawn) {
  628. lua_interface->SetSpawnValue(state, spawn);
  629. return 1;
  630. }
  631. }
  632. return 0;
  633. }
  634. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  635. ZoneServer* zone = lua_interface->GetZone(state);
  636. int32 location_id = lua_interface->GetInt32Value(state, 2);
  637. lua_interface->ResetFunctionStack(state);
  638. if (zone) {
  639. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  640. if (spawn) {
  641. lua_interface->SetSpawnValue(state, spawn);
  642. return 1;
  643. }
  644. }
  645. return 0;
  646. }
  647. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  648. Spawn* spawn = lua_interface->GetSpawn(state);
  649. lua_interface->ResetFunctionStack(state);
  650. if (spawn) {
  651. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  652. return 1;
  653. }
  654. return 0;
  655. }
  656. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. lua_interface->ResetFunctionStack(state);
  659. if (spawn) {
  660. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  661. return 1;
  662. }
  663. return 0;
  664. }
  665. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  666. if (!lua_interface)
  667. return 0;
  668. Spawn* spawn = lua_interface->GetSpawn(state);
  669. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  670. lua_interface->ResetFunctionStack(state);
  671. if (spawn) {
  672. spawn->SetSpawnGroupID(new_group_id);
  673. lua_interface->SetBooleanValue(state, true);
  674. return 1;
  675. }
  676. lua_interface->SetBooleanValue(state, false);
  677. return 1;
  678. }
  679. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  680. if (!lua_interface)
  681. return 0;
  682. Spawn* spawn = lua_interface->GetSpawn(state);
  683. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  684. lua_interface->ResetFunctionStack(state);
  685. if (spawn) {
  686. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  687. lua_interface->SetBooleanValue(state, true);
  688. return 1;
  689. }
  690. lua_interface->SetBooleanValue(state, false);
  691. return 1;
  692. }
  693. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  694. Spawn* spawn = lua_interface->GetSpawn(state);
  695. lua_interface->ResetFunctionStack(state);
  696. if (spawn) {
  697. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  698. return 1;
  699. }
  700. return 0;
  701. }
  702. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  703. Spawn* spawn = lua_interface->GetSpawn(state);
  704. lua_interface->ResetFunctionStack(state);
  705. if (spawn) {
  706. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  707. return 1;
  708. }
  709. return 0;
  710. }
  711. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  712. Player* player = (Player*)lua_interface->GetSpawn(state);
  713. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  714. lua_interface->ResetFunctionStack(state);
  715. if (player && player->IsPlayer() && faction_id > 0) {
  716. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  717. return 1;
  718. }
  719. return 0;
  720. }
  721. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  722. if (!lua_interface)
  723. return 0;
  724. Spawn* spawn = lua_interface->GetSpawn(state);
  725. int32 value = lua_interface->GetInt32Value(state, 2);
  726. lua_interface->ResetFunctionStack(state);
  727. if (spawn) {
  728. spawn->SetFactionID(value);
  729. }
  730. return 0;
  731. }
  732. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  733. Spawn* spawn = lua_interface->GetSpawn(state);
  734. lua_interface->ResetFunctionStack(state);
  735. if (spawn) {
  736. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  737. return 1;
  738. }
  739. return 0;
  740. }
  741. int EQ2Emu_lua_GetGender(lua_State* state) {
  742. Spawn* spawn = lua_interface->GetSpawn(state);
  743. lua_interface->ResetFunctionStack(state);
  744. if (spawn) {
  745. lua_interface->SetInt32Value(state, spawn->GetGender());
  746. return 1;
  747. }
  748. return 0;
  749. }
  750. int EQ2Emu_lua_GetTarget(lua_State* state) {
  751. Spawn* spawn = lua_interface->GetSpawn(state);
  752. lua_interface->ResetFunctionStack(state);
  753. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  754. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  755. return 1;
  756. }
  757. return 0;
  758. }
  759. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  760. if (!lua_interface)
  761. return 0;
  762. Spawn* spawn = lua_interface->GetSpawn(state);
  763. string mp3_string = lua_interface->GetStringValue(state, 2);
  764. int32 key1 = lua_interface->GetInt32Value(state, 3);
  765. int32 key2 = lua_interface->GetInt32Value(state, 4);
  766. Spawn* player = lua_interface->GetSpawn(state, 5);
  767. lua_interface->ResetFunctionStack(state);
  768. if (spawn && mp3_string.length() > 0) {
  769. Client* client = 0;
  770. if (player && player->IsPlayer())
  771. client = spawn->GetZone()->GetClientBySpawn(player);
  772. if (client) {
  773. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  774. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  775. }
  776. else
  777. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  778. }
  779. return 0;
  780. }
  781. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  782. if (!lua_interface)
  783. return 0;
  784. Spawn* spawn = lua_interface->GetSpawn(state);
  785. lua_interface->ResetFunctionStack(state);
  786. if (spawn) {
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  788. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  789. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  790. return 3;
  791. }
  792. return 0;
  793. }
  794. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  795. if (!lua_interface)
  796. return 0;
  797. Spawn* spawn = lua_interface->GetSpawn(state);
  798. if (spawn) {
  799. int32 item_id = lua_interface->GetInt32Value(state, 2);
  800. lua_interface->ResetFunctionStack(state);
  801. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  802. return 1;
  803. }
  804. lua_interface->ResetFunctionStack(state);
  805. return 0;
  806. }
  807. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  808. if (!lua_interface)
  809. return 0;
  810. Spawn* spawn = lua_interface->GetSpawn(state);
  811. if (spawn && spawn->IsEntity()) {
  812. int32 item_id = lua_interface->GetInt32Value(state, 2);
  813. int16 charges = lua_interface->GetInt16Value(state, 3);
  814. if (charges == 0)
  815. charges = 1;
  816. ((Entity*)spawn)->AddLootItem(item_id, charges);
  817. }
  818. lua_interface->ResetFunctionStack(state);
  819. return 0;
  820. }
  821. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  822. if (!lua_interface)
  823. return 0;
  824. Spawn* spawn = lua_interface->GetSpawn(state);
  825. if (spawn && spawn->IsEntity()) {
  826. int32 item_id = lua_interface->GetInt32Value(state, 2);
  827. Item* item = spawn->LootItem(item_id);
  828. safe_delete(item);
  829. }
  830. lua_interface->ResetFunctionStack(state);
  831. return 0;
  832. }
  833. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  834. if (!lua_interface)
  835. return 0;
  836. Spawn* spawn = lua_interface->GetSpawn(state);
  837. if (spawn) {
  838. int32 val = lua_interface->GetInt32Value(state, 2);
  839. spawn->AddLootCoins(val);
  840. }
  841. lua_interface->ResetFunctionStack(state);
  842. return 0;
  843. }
  844. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  845. if (!lua_interface)
  846. return 0;
  847. Spawn* entity = lua_interface->GetSpawn(state);
  848. Spawn* player = lua_interface->GetSpawn(state, 2);
  849. if (entity && player && player->IsPlayer()) {
  850. int32 coins = lua_interface->GetInt32Value(state, 3);
  851. vector<Item*>* items = 0;
  852. int i = 0;
  853. int32 item_id = 0;
  854. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  855. if (items == 0)
  856. items = new vector<Item*>;
  857. if (master_item_list.GetItem(item_id))
  858. items->push_back(master_item_list.GetItem(item_id));
  859. i++;
  860. }
  861. Client* client = 0;
  862. client = player->GetZone()->GetClientBySpawn(player);
  863. if (client)
  864. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  865. if(coins > 0)
  866. entity->AddLootCoins(coins);
  867. safe_delete(items);
  868. }
  869. lua_interface->ResetFunctionStack(state);
  870. return 0;
  871. }
  872. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  873. if (!lua_interface)
  874. return 0;
  875. Spawn* entity = lua_interface->GetSpawn(state);
  876. Spawn* player = lua_interface->GetSpawn(state, 2);
  877. int32 item_id = lua_interface->GetInt32Value(state, 3);
  878. lua_interface->ResetFunctionStack(state);
  879. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  880. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  881. return 1;
  882. }
  883. return 0;
  884. }
  885. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  886. if (!lua_interface)
  887. return 0;
  888. Spawn* entity = lua_interface->GetSpawn(state);
  889. Spawn* player = lua_interface->GetSpawn(state, 2);
  890. lua_interface->ResetFunctionStack(state);
  891. if (entity && player && player->IsPlayer()) {
  892. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  893. return 1;
  894. }
  895. return 0;
  896. }
  897. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  898. if (!lua_interface)
  899. return 0;
  900. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = player->GetZone()->GetClientBySpawn(player);
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = player->GetZone()->GetClientBySpawn(player);
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = player->GetZone()->GetClientBySpawn(player);
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. safe_delete(conversation);
  994. lua_interface->SetConversationValue(state, NULL);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = source->GetZone()->GetClientBySpawn(player);
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. safe_delete(conversation);
  1020. lua_interface->SetConversationValue(state, NULL);
  1021. }
  1022. else
  1023. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = spawn->GetZone()->GetClientBySpawn(player);
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = spawn->GetZone()->GetClientBySpawn(player);
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = spawn->GetZone()->GetClientBySpawn(player);
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = spawn->GetZone()->GetClientBySpawn(player);
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. return 0;
  1247. }
  1248. Spawn* caster = luaspell->caster;
  1249. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1250. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1251. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1252. Spawn* target = lua_interface->GetSpawn(state, 4);
  1253. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1254. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1255. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1256. lua_interface->ResetFunctionStack(state);
  1257. boost::to_lower(heal_type);
  1258. if (caster && caster->IsEntity()) {
  1259. bool success = false;
  1260. luaspell->resisted = false;
  1261. if (target) {
  1262. float distance = caster->GetDistance(target, true);
  1263. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1264. success = true;
  1265. }
  1266. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1267. Spawn* target = 0;
  1268. ZoneServer* zone = luaspell->caster->GetZone();
  1269. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1270. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1271. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1272. float distance = caster->GetDistance(target, true);
  1273. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1274. }
  1275. }
  1276. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1277. success = true;
  1278. }
  1279. if (success) {
  1280. if (caster->GetZone())
  1281. caster->GetZone()->TriggerCharSheetTimer();
  1282. }
  1283. }
  1284. return 0;
  1285. }
  1286. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1287. if (!lua_interface)
  1288. return 0;
  1289. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1290. if(!luaspell || luaspell->resisted) {
  1291. return 0;
  1292. }
  1293. Spawn* caster = luaspell->caster;
  1294. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1295. float percentage = lua_interface->GetFloatValue(state, 2);
  1296. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1297. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1298. Spawn* target = lua_interface->GetSpawn(state, 5);
  1299. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1300. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1301. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1302. lua_interface->ResetFunctionStack(state);
  1303. boost::to_lower(heal_type);
  1304. int32 min_heal = 0, max_heal = 0;
  1305. if (caster && caster->IsEntity() && target) {
  1306. if(percentage <= 0.0f)
  1307. {
  1308. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1309. return 0;
  1310. }
  1311. if(heal_type == "power")
  1312. {
  1313. if(current_value)
  1314. {
  1315. if(caster_value)
  1316. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1317. else
  1318. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1319. }
  1320. else
  1321. {
  1322. if(caster_value)
  1323. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1324. else
  1325. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1326. }
  1327. }
  1328. else
  1329. {
  1330. if(current_value)
  1331. {
  1332. if(caster_value)
  1333. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1334. else
  1335. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1336. }
  1337. else
  1338. {
  1339. if(caster_value)
  1340. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1341. else
  1342. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1343. }
  1344. }
  1345. bool success = false;
  1346. luaspell->resisted = false;
  1347. if (target) {
  1348. float distance = caster->GetDistance(target, true);
  1349. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1350. success = true;
  1351. }
  1352. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1353. Spawn* target = 0;
  1354. ZoneServer* zone = luaspell->caster->GetZone();
  1355. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1356. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1357. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1358. float distance = caster->GetDistance(target, true);
  1359. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1360. }
  1361. }
  1362. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1363. success = true;
  1364. }
  1365. if (success) {
  1366. if (caster->GetZone())
  1367. caster->GetZone()->TriggerCharSheetTimer();
  1368. }
  1369. }
  1370. return 0;
  1371. }
  1372. int EQ2Emu_lua_AddItem(lua_State* state) {
  1373. if (!lua_interface)
  1374. return 0;
  1375. Spawn* spawn = lua_interface->GetSpawn(state);
  1376. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1377. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1378. lua_interface->ResetFunctionStack(state);
  1379. // default of 1 quantity to add
  1380. if (quantity == 0)
  1381. quantity = 1;
  1382. if (spawn && spawn->IsPlayer()) {
  1383. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1384. if (client && item_id > 0) {
  1385. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1386. return 1;
  1387. }
  1388. }
  1389. lua_interface->SetBooleanValue(state, false);
  1390. return 1;
  1391. }
  1392. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1393. if (!lua_interface)
  1394. return 0;
  1395. Spawn* spawn = lua_interface->GetSpawn(state);
  1396. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1397. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1398. string location = lua_interface->GetStringValue(state, 4);
  1399. int16 item_count = lua_interface->GetInt16Value(state,5);
  1400. //devn00b: if we dont have a count, assume 1 item.
  1401. if(!item_count) {
  1402. item_count = 1;
  1403. }
  1404. lua_interface->ResetFunctionStack(state);
  1405. if (spawn && spawn->IsPlayer()) {
  1406. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1407. if (client && item_id > 0) {
  1408. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1409. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1410. else
  1411. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1412. if (send_messages) {
  1413. Item* item = master_item_list.GetItem(item_id);
  1414. if (item) {
  1415. if(item_count > 1) {
  1416. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1417. string popup_text1 = "You receive "+ item_count;
  1418. string popup_text2 = " " + item->name;
  1419. string popup_text = popup_text1 + popup_text2;
  1420. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1421. // return 1;
  1422. } else {
  1423. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1424. string popup_text = "You receive " + item->name;
  1425. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1426. }
  1427. }
  1428. }
  1429. return 1;
  1430. }
  1431. }
  1432. lua_interface->SetBooleanValue(state, false);
  1433. return 1;
  1434. }
  1435. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1436. Spawn* spawn = lua_interface->GetSpawn(state);
  1437. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1438. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1439. lua_interface->ResetFunctionStack(state);
  1440. // default of 1 to remove
  1441. if (quantity == 0)
  1442. quantity = 1;
  1443. Client* client;
  1444. Item* item;
  1445. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1446. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1447. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1448. if (client->RemoveItem(item, quantity)) {
  1449. lua_interface->SetBooleanValue(state, true);
  1450. return 1;
  1451. }
  1452. }
  1453. }
  1454. }
  1455. lua_interface->SetBooleanValue(state, false);
  1456. return 1;
  1457. }
  1458. int EQ2Emu_lua_HasItem(lua_State* state) {
  1459. Spawn* player = lua_interface->GetSpawn(state);
  1460. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1461. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1462. lua_interface->ResetFunctionStack(state);
  1463. if (player && player->IsPlayer()) {
  1464. bool hasItem = false;
  1465. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1466. if (!hasItem)
  1467. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1468. lua_interface->SetBooleanValue(state, hasItem);
  1469. return 1;
  1470. }
  1471. lua_interface->SetBooleanValue(state, false);
  1472. return 1;
  1473. }
  1474. int EQ2Emu_lua_Spawn(lua_State* state) {
  1475. if (!lua_interface)
  1476. return 0;
  1477. ZoneServer* zone = lua_interface->GetZone(state);
  1478. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1479. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1480. float x = lua_interface->GetFloatValue(state, 4);
  1481. float y = lua_interface->GetFloatValue(state, 5);
  1482. float z = lua_interface->GetFloatValue(state, 6);
  1483. float heading = lua_interface->GetFloatValue(state, 7);
  1484. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1485. Spawn* spawn = zone->GetSpawn(spawn_id);
  1486. if (!spawn)
  1487. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1488. else {
  1489. spawn->SetX(x);
  1490. spawn->SetZ(z);
  1491. spawn->SetY(y,true,true);
  1492. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1493. spawn->SetHeading(heading);
  1494. if (restricted_npc)
  1495. spawn->AddAllowAccessSpawn(spawn);
  1496. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1497. bool scriptActive = false;
  1498. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1499. scriptActive = true;
  1500. spawn->SetSpawnScript(string(spawn_script));
  1501. }
  1502. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1503. zone->AddSpawn(spawn);
  1504. if (scriptActive) {
  1505. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1506. }
  1507. lua_interface->ResetFunctionStack(state);
  1508. lua_interface->SetSpawnValue(state, spawn);
  1509. return 1;
  1510. }
  1511. }
  1512. else {
  1513. string output = "Invalid paramaters to LUA Spawn command: \n";
  1514. if (!zone)
  1515. output = output.append("\t").append("Missing zone reference. \n");
  1516. if (spawn_id == 0)
  1517. output = output.append("\t").append("Missing spawn_id.");
  1518. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1519. }
  1520. lua_interface->ResetFunctionStack(state);
  1521. return 0;
  1522. }
  1523. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1524. if (!lua_interface)
  1525. return 0;
  1526. ZoneServer* zone = lua_interface->GetZone(state);
  1527. lua_interface->ResetFunctionStack(state);
  1528. if (zone) {
  1529. lua_interface->SetStringValue(state, zone->GetZoneName());
  1530. return 1;
  1531. }
  1532. return 0;
  1533. }
  1534. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1535. if (!lua_interface)
  1536. return 0;
  1537. ZoneServer* zone = lua_interface->GetZone(state);
  1538. lua_interface->ResetFunctionStack(state);
  1539. if (zone) {
  1540. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1541. return 1;
  1542. }
  1543. return 0;
  1544. }
  1545. int EQ2Emu_lua_GetZone(lua_State* state) {
  1546. if (!lua_interface)
  1547. return 0;
  1548. int32 zone_id = lua_interface->GetInt32Value(state);
  1549. ZoneServer* zone = 0;
  1550. if (zone_id > 0)
  1551. zone = zone_list.Get(zone_id);
  1552. else {
  1553. string zone_name = lua_interface->GetStringValue(state);
  1554. if (zone_name.length() > 0) {
  1555. zone = zone_list.Get(zone_name.c_str());
  1556. }
  1557. else {
  1558. Spawn* spawn = lua_interface->GetSpawn(state);
  1559. if (spawn)
  1560. zone = spawn->GetZone();
  1561. }
  1562. }
  1563. lua_interface->ResetFunctionStack(state);
  1564. if (zone) {
  1565. lua_interface->SetZoneValue(state, zone);
  1566. return 1;
  1567. }
  1568. return 0;
  1569. }
  1570. int EQ2Emu_lua_AddHate(lua_State* state) {
  1571. Spawn* entity = lua_interface->GetSpawn(state);
  1572. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1573. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1574. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1575. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1576. if(!luaspell || luaspell->resisted) {
  1577. return 0;
  1578. }
  1579. if (entity && entity->IsEntity() && amount != 0) {
  1580. if (luaspell) {
  1581. ZoneServer* zone = luaspell->caster->GetZone();
  1582. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1583. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1584. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1585. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1586. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1587. if (send_packet)
  1588. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1589. }
  1590. }
  1591. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1592. }
  1593. else if (npc && npc->IsNPC() && npc->GetZone())
  1594. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1595. }
  1596. lua_interface->ResetFunctionStack(state);
  1597. return 0;
  1598. }
  1599. int EQ2Emu_lua_Zone(lua_State* state) {
  1600. if (!lua_interface)
  1601. return 0;
  1602. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1603. ZoneServer* zone = lua_interface->GetZone(state);
  1604. Spawn* player = lua_interface->GetSpawn(state, 2);
  1605. Client* client = 0;
  1606. if (player && player->IsPlayer())
  1607. client = player->GetZone()->GetClientBySpawn(player);
  1608. float x = lua_interface->GetFloatValue(state, 3);
  1609. float y = lua_interface->GetFloatValue(state, 4);
  1610. float z = lua_interface->GetFloatValue(state, 5);
  1611. float heading = lua_interface->GetFloatValue(state, 6);
  1612. if (zone && client) {
  1613. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1614. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1615. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1616. {
  1617. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1618. return 0;
  1619. }
  1620. if (x != 0 || y != 0 || z != 0) {
  1621. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1622. player->SetX(x);
  1623. player->SetY(y);
  1624. player->SetZ(z);
  1625. player->SetHeading(heading);
  1626. client->Zone(zone->GetZoneName(), false);
  1627. }
  1628. else
  1629. client->Zone(zone->GetZoneName());
  1630. }
  1631. else
  1632. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1633. lua_interface->ResetFunctionStack(state);
  1634. return 0;
  1635. }
  1636. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1637. if (!lua_interface)
  1638. return 0;
  1639. Spawn* spawn = lua_interface->GetSpawn(state);
  1640. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1641. if (spawn && spawn2)
  1642. spawn->AddAllowAccessSpawn(spawn2);
  1643. lua_interface->ResetFunctionStack(state);
  1644. return 0;
  1645. }
  1646. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1647. if (!lua_interface)
  1648. return 0;
  1649. Spawn* target = lua_interface->GetSpawn(state);
  1650. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1651. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1652. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1653. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1654. lua_interface->ResetFunctionStack(state);
  1655. if (!target) {
  1656. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1657. return 0;
  1658. }
  1659. if (!target->IsEntity()) {
  1660. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1661. return 0;
  1662. }
  1663. if (spell_id <= 0) {
  1664. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1665. return 0;
  1666. }
  1667. if (caster && !caster->IsEntity()) {
  1668. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1669. return 0;
  1670. }
  1671. if (spell_tier == 0)
  1672. spell_tier = 1;
  1673. if (!caster)
  1674. caster = target;
  1675. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1676. return 0;
  1677. }
  1678. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1679. if (!lua_interface)
  1680. return 0;
  1681. Spawn* target = lua_interface->GetSpawn(state);
  1682. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1683. if(!luaspell || luaspell->resisted) {
  1684. return 0;
  1685. }
  1686. Spawn* caster = luaspell->caster;
  1687. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1688. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1689. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1690. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1691. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1692. //lua_interface->ResetFunctionStack(state);
  1693. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1694. vector<int16> faction_req;
  1695. vector<int16> race_req;
  1696. int32 class_req = 0;
  1697. int32 i = 0;
  1698. int8 f = 0;
  1699. int8 r = 0;
  1700. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1701. if (class_id < 100) {
  1702. class_req += pow(2.0, double(class_id - 1));
  1703. }
  1704. else if (class_id > 100 && class_id < 1000) {
  1705. race_req.push_back(class_id);
  1706. r++;
  1707. }
  1708. else {
  1709. faction_req.push_back(class_id);
  1710. f++;
  1711. }
  1712. i++;
  1713. }
  1714. lua_interface->ResetFunctionStack(state);
  1715. if (caster && caster->IsEntity()) {
  1716. bool race_match = false;
  1717. bool success = false;
  1718. luaspell->resisted = false;
  1719. if (luaspell->targets.size() > 0) {
  1720. ZoneServer* zone = luaspell->caster->GetZone();
  1721. Spawn* target = 0;
  1722. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1723. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1724. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1725. if (race_req.size() > 0) {
  1726. for (int8 i = 0; i < race_req.size(); i++) {
  1727. if(race_req[i] == target->GetRace() ||
  1728. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1729. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1730. race_match = true;
  1731. }
  1732. }
  1733. }
  1734. else
  1735. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1736. if (race_match == true) {
  1737. float distance = caster->GetDistance(target, true);
  1738. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1739. }
  1740. }
  1741. }
  1742. success = true;
  1743. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1744. }
  1745. else if (target) {
  1746. //check class and race/faction here
  1747. if (race_req.size() > 0) {
  1748. for (int8 i = 0; i < race_req.size(); i++) {
  1749. if(race_req[i] == target->GetRace() ||
  1750. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1751. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1752. race_match = true;
  1753. }
  1754. }
  1755. }
  1756. else
  1757. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1758. if (race_match == true) {
  1759. float distance = caster->GetDistance(target, true);
  1760. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1761. success = true;
  1762. }
  1763. }
  1764. if (success) {
  1765. Spell* spell = luaspell->spell;
  1766. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1767. ((Player*)caster)->InCombat(true);
  1768. if (caster->GetZone())
  1769. caster->GetZone()->TriggerCharSheetTimer();
  1770. }
  1771. }
  1772. }
  1773. return 0;
  1774. }
  1775. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1776. if (!lua_interface)
  1777. return 0;
  1778. Spawn* spawn = lua_interface->GetSpawn(state);
  1779. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1780. lua_interface->ResetFunctionStack(state);
  1781. if (spawn && value != 0) {
  1782. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1783. spawn->SetPower(spawn->GetTotalPower());
  1784. else
  1785. spawn->SetPower(spawn->GetPower() + value);
  1786. }
  1787. return 0;
  1788. }
  1789. int EQ2Emu_lua_ModifyHP(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. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1797. spawn->SetHP(spawn->GetTotalHP());
  1798. else
  1799. spawn->SetHP(spawn->GetHP() + value);
  1800. }
  1801. return 0;
  1802. }
  1803. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1804. if (!lua_interface)
  1805. return 0;
  1806. Spawn* spawn = lua_interface->GetSpawn(state);
  1807. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1808. lua_interface->ResetFunctionStack(state);
  1809. if (spawn && value != 0) {
  1810. spawn->SetPower(spawn->GetPower() + value);
  1811. if (value > spawn->GetTotalHPBase())
  1812. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1813. }
  1814. return 0;
  1815. }
  1816. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1817. if (!lua_interface)
  1818. return 0;
  1819. Spawn* spawn = lua_interface->GetSpawn(state);
  1820. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1821. lua_interface->ResetFunctionStack(state);
  1822. if (spawn && value != 0) {
  1823. spawn->SetHP(spawn->GetHP() + value);
  1824. if (value > spawn->GetTotalHPBase())
  1825. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1826. }
  1827. return 0;
  1828. }
  1829. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1830. if (!lua_interface)
  1831. return 0;
  1832. Spawn* spawn = lua_interface->GetSpawn(state);
  1833. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1834. lua_interface->ResetFunctionStack(state);
  1835. if (spawn) {
  1836. spawn->SetHP(value);
  1837. if (value > spawn->GetTotalHPBase())
  1838. spawn->SetTotalHP(value);
  1839. }
  1840. return 0;
  1841. }
  1842. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1843. if (!lua_interface)
  1844. return 0;
  1845. Spawn* spawn = lua_interface->GetSpawn(state);
  1846. float value = lua_interface->GetFloatValue(state, 2);
  1847. lua_interface->ResetFunctionStack(state);
  1848. if (spawn && spawn->IsEntity() && value > 0)
  1849. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1850. if (spawn->IsPlayer())
  1851. ((Player*)spawn)->SetCharSheetChanged(true);
  1852. return 0;
  1853. }
  1854. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1855. if (!lua_interface)
  1856. return 0;
  1857. Spawn* spawn = lua_interface->GetSpawn(state);
  1858. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1859. lua_interface->ResetFunctionStack(state);
  1860. if (spawn && spawn->IsEntity() && value > 0)
  1861. ((Entity*)spawn)->SetTotalHPBase(value);
  1862. return 0;
  1863. }
  1864. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1865. if (!lua_interface)
  1866. return 0;
  1867. Spawn* spawn = lua_interface->GetSpawn(state);
  1868. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1869. lua_interface->ResetFunctionStack(state);
  1870. if (spawn && value > 0) {
  1871. spawn->SetPower(value);
  1872. if (value > spawn->GetTotalPowerBase())
  1873. spawn->SetTotalPower(value);
  1874. }
  1875. return 0;
  1876. }
  1877. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1878. if (!lua_interface)
  1879. return 0;
  1880. Spawn* spawn = lua_interface->GetSpawn(state);
  1881. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1882. lua_interface->ResetFunctionStack(state);
  1883. if (spawn && spawn->IsEntity() && value > 0)
  1884. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1885. return 0;
  1886. }
  1887. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1888. if (!lua_interface)
  1889. return 0;
  1890. Spawn* spawn = lua_interface->GetSpawn(state);
  1891. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1892. lua_interface->ResetFunctionStack(state);
  1893. if (spawn && spawn->IsEntity() && value > 0)
  1894. ((Entity*)spawn)->SetTotalPowerBase(value);
  1895. return 0;
  1896. }
  1897. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1898. if (!lua_interface)
  1899. return 0;
  1900. Spawn* spawn = lua_interface->GetSpawn(state);
  1901. float x = lua_interface->GetFloatValue(state, 2);
  1902. float y = lua_interface->GetFloatValue(state, 3);
  1903. float z = lua_interface->GetFloatValue(state, 4);
  1904. float heading = lua_interface->GetFloatValue(state, 5);
  1905. lua_interface->ResetFunctionStack(state);
  1906. if (spawn) {
  1907. spawn->SetX(x);
  1908. spawn->SetY(y);
  1909. spawn->SetZ(z);
  1910. if (heading != 0)
  1911. spawn->SetHeading(heading);
  1912. spawn->SetSpawnOrigX(spawn->GetX());
  1913. spawn->SetSpawnOrigY(spawn->GetY());
  1914. spawn->SetSpawnOrigZ(spawn->GetZ());
  1915. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1916. if (spawn->IsPlayer()) {
  1917. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1918. if (client) {
  1919. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1920. client->QueuePacket(packet);
  1921. }
  1922. }
  1923. }
  1924. return 0;
  1925. }
  1926. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1927. if (!lua_interface)
  1928. return 0;
  1929. Spawn* spawn = lua_interface->GetSpawn(state);
  1930. float value = lua_interface->GetFloatValue(state, 2);
  1931. lua_interface->ResetFunctionStack(state);
  1932. if (spawn) {
  1933. spawn->SetHeading(value);
  1934. if (spawn->IsPlayer()) {
  1935. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1936. if (client) {
  1937. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1938. client->QueuePacket(packet);
  1939. }
  1940. }
  1941. }
  1942. return 0;
  1943. }
  1944. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1945. if (!lua_interface)
  1946. return 0;
  1947. Spawn* spawn = lua_interface->GetSpawn(state);
  1948. int16 value = lua_interface->GetInt16Value(state, 2);
  1949. lua_interface->ResetFunctionStack(state);
  1950. if (spawn)
  1951. spawn->SetModelType(value);
  1952. return 0;
  1953. }
  1954. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1955. if (!lua_interface)
  1956. return 0;
  1957. Spawn* spawn = lua_interface->GetSpawn(state);
  1958. int8 value = lua_interface->GetInt8Value(state, 2);
  1959. lua_interface->ResetFunctionStack(state);
  1960. if (spawn) {
  1961. if (spawn->IsPlayer())
  1962. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1963. else
  1964. spawn->SetAdventureClass(value);
  1965. }
  1966. return 0;
  1967. }
  1968. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1969. if (!lua_interface)
  1970. return 0;
  1971. Spawn* spawn = lua_interface->GetSpawn(state);
  1972. int8 value = lua_interface->GetInt8Value(state, 2);
  1973. lua_interface->ResetFunctionStack(state);
  1974. if (spawn) {
  1975. spawn->SetTradeskillClass(value);
  1976. if (spawn->IsEntity()) {
  1977. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1978. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1979. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1980. }
  1981. if (spawn->IsPlayer())
  1982. ((Player*)spawn)->SetCharSheetChanged(true);
  1983. }
  1984. return 0;
  1985. }
  1986. int EQ2Emu_lua_SetMount(lua_State* state) {
  1987. if (!lua_interface)
  1988. return 0;
  1989. Spawn* spawn = lua_interface->GetSpawn(state);
  1990. int16 value = lua_interface->GetInt16Value(state, 2);
  1991. if (spawn && spawn->IsEntity()) {
  1992. ((Entity*)spawn)->SetMount(value);
  1993. EQ2_Color color;
  1994. color.red = 255;
  1995. color.green = 255;
  1996. color.blue = 255;
  1997. ((Entity*)spawn)->SetMountColor(&color);
  1998. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1999. }
  2000. return 0;
  2001. }
  2002. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2003. if (!lua_interface)
  2004. return 0;
  2005. Spawn* spawn = lua_interface->GetSpawn(state);
  2006. EQ2_Color mount_color;
  2007. EQ2_Color saddle_color;
  2008. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2009. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2010. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2011. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2012. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2013. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2014. if (spawn && spawn->IsEntity()) {
  2015. ((Entity*)spawn)->SetMountColor(&mount_color);
  2016. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2017. }
  2018. return 0;
  2019. }
  2020. int EQ2Emu_lua_GetMount(lua_State* state) {
  2021. if (!lua_interface)
  2022. return 0;
  2023. Spawn* spawn = lua_interface->GetSpawn(state);
  2024. if (spawn && spawn->IsEntity()) {
  2025. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2026. return 1;
  2027. }
  2028. return 0;
  2029. }
  2030. int EQ2Emu_lua_GetRace(lua_State* state) {
  2031. if (!lua_interface)
  2032. return 0;
  2033. Spawn* spawn = lua_interface->GetSpawn(state);
  2034. if (spawn)
  2035. {
  2036. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2037. lua_interface->SetInt32Value(state, spawn->GetRace());
  2038. return 1;
  2039. }
  2040. return 0;
  2041. }
  2042. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2043. if (!lua_interface)
  2044. return 0;
  2045. Spawn* spawn = lua_interface->GetSpawn(state);
  2046. if (spawn) {
  2047. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2048. return 1;
  2049. }
  2050. return 0;
  2051. }
  2052. int EQ2Emu_lua_GetClass(lua_State* state) {
  2053. Spawn* spawn = lua_interface->GetSpawn(state);
  2054. if (spawn) {
  2055. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2056. return 1;
  2057. }
  2058. return 0;
  2059. }
  2060. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2061. Spawn* spawn = lua_interface->GetSpawn(state);
  2062. if (spawn) {
  2063. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2064. return 1;
  2065. }
  2066. return 0;
  2067. }
  2068. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2069. if (!lua_interface)
  2070. return 0;
  2071. Spawn* spawn = lua_interface->GetSpawn(state);
  2072. float value = lua_interface->GetFloatValue(state, 2);
  2073. lua_interface->ResetFunctionStack(state);
  2074. if (spawn) {
  2075. spawn->SetSpeed(value);
  2076. if(spawn->IsEntity())
  2077. ((Entity*)spawn)->SetSpeed(value);
  2078. if (spawn->IsPlayer()) {
  2079. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2080. if (client) {
  2081. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2082. if (packet) {
  2083. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2084. packet->setDataByName("speed", value);
  2085. packet->setDataByName("size", 0.51);
  2086. EQ2Packet* app = packet->serialize();
  2087. client->QueuePacket(app);
  2088. safe_delete(packet);
  2089. }
  2090. }
  2091. }
  2092. }
  2093. return 0;
  2094. }
  2095. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2096. if (!lua_interface)
  2097. return 0;
  2098. Spawn* spawn = lua_interface->GetSpawn(state);
  2099. const int16 type = lua_interface->GetInt16Value(state, 2);
  2100. const float value = lua_interface->GetFloatValue(state, 3);
  2101. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2102. if(!luaspell || luaspell->resisted) {
  2103. return 0;
  2104. }
  2105. int64 class_req = 0;
  2106. int32 class_id = 0;
  2107. vector<int16> faction_req;
  2108. vector<int16> race_req;
  2109. int32 i = 0;
  2110. int8 f = 0;
  2111. int8 r = 0;
  2112. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2113. if (class_id < 100) {
  2114. class_req += pow(2.0, double(class_id - 1));
  2115. }
  2116. else if (class_id > 100 && class_id < 1000) {
  2117. race_req.push_back(class_id);
  2118. r++;
  2119. }
  2120. else {
  2121. faction_req.push_back(class_id);
  2122. f++;
  2123. }
  2124. i++;
  2125. }
  2126. if (value != 0 && type >= 0) {
  2127. if (luaspell && luaspell->spell && luaspell->caster) {
  2128. ZoneServer* zone = luaspell->caster->GetZone();
  2129. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2130. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2131. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2132. if (target) {
  2133. if (target->IsPlayer()) {
  2134. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2135. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2136. if (((Player*)target)->GetGroupMemberInfo())
  2137. ((Player*)target)->UpdateGroupMemberInfo();
  2138. ((Player*)target)->SetCharSheetChanged(true);
  2139. }
  2140. else if (target->IsNPC())
  2141. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2142. else
  2143. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2144. }
  2145. }
  2146. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2147. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2148. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2149. }
  2150. else if (spawn && spawn->IsEntity()) {
  2151. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2152. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2153. if (spawn->IsPlayer())
  2154. ((Player*)spawn)->SetCharSheetChanged(true);
  2155. }
  2156. else
  2157. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2158. }
  2159. else
  2160. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2161. return 0;
  2162. }
  2163. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2164. if (!lua_interface)
  2165. return 0;
  2166. Spawn* spawn = lua_interface->GetSpawn(state);
  2167. int16 type = lua_interface->GetInt16Value(state, 2);
  2168. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2169. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2170. if (!spawn) {
  2171. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2172. return 0;
  2173. }
  2174. if (!spawn->IsEntity()) {
  2175. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2176. return 0;
  2177. }
  2178. if (value == 0) {
  2179. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2180. return 0;
  2181. }
  2182. if (!luaspell || !luaspell->spell) {
  2183. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2184. return 0;
  2185. }
  2186. if(luaspell->resisted) {
  2187. return 0;
  2188. }
  2189. int32 class_req = 0;
  2190. vector<int16> faction_req;
  2191. vector<int16> race_req;
  2192. int32 class_id = 0;
  2193. int32 i = 0;
  2194. int8 f = 0;
  2195. int8 r = 0;
  2196. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2197. if (class_id < 100) {
  2198. class_req += pow(2.0, double(class_id - 1));
  2199. }
  2200. else if (class_id > 100 && class_id < 1000) {
  2201. race_req.push_back(class_id);
  2202. r++;
  2203. }
  2204. else {
  2205. faction_req.push_back(class_id);
  2206. f++;
  2207. }
  2208. i++;
  2209. }
  2210. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2211. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2212. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2213. if (spawn->IsPlayer())
  2214. ((Player*)spawn)->SetCharSheetChanged(true);
  2215. return 0;
  2216. }
  2217. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2218. if (!lua_interface)
  2219. return 0;
  2220. Spawn* spawn = lua_interface->GetSpawn(state);
  2221. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2222. if (!spawn) {
  2223. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2224. return 0;
  2225. }
  2226. if (!spawn->IsEntity()) {
  2227. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2228. return 0;
  2229. }
  2230. if (!luaspell || !luaspell->spell) {
  2231. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2232. return 0;
  2233. }
  2234. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2235. if (spawn->IsPlayer())
  2236. ((Player*)spawn)->SetCharSheetChanged(true);
  2237. return 0;
  2238. }
  2239. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2240. if (!lua_interface)
  2241. return 0;
  2242. Spawn* spawn = lua_interface->GetSpawn(state);
  2243. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2244. if (luaspell && luaspell->spell) {
  2245. ZoneServer* zone = luaspell->caster->GetZone();
  2246. Spawn* target = 0;
  2247. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2248. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2249. target = zone->GetSpawnByID(luaspell->targets[i]);
  2250. if (target && target->IsEntity()) {
  2251. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2252. if (target->IsPlayer())
  2253. ((Player*)target)->SetCharSheetChanged(true);
  2254. }
  2255. }
  2256. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2257. }
  2258. else if (spawn && spawn->IsEntity()) {
  2259. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2260. if (spawn->IsPlayer())
  2261. ((Player*)spawn)->SetCharSheetChanged(true);
  2262. }
  2263. return 0;
  2264. }
  2265. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2266. if (!lua_interface)
  2267. return 0;
  2268. Spawn* spawn = lua_interface->GetSpawn(state);
  2269. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2270. float value = lua_interface->GetFloatValue(state, 3);
  2271. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2272. if (value != 0) {
  2273. int32 spell_id = 0;
  2274. if (luaspell && luaspell->spell && luaspell->caster) {
  2275. if(luaspell->resisted) {
  2276. return 0;
  2277. }
  2278. spell_id = luaspell->spell->GetSpellID();
  2279. ZoneServer* zone = luaspell->caster->GetZone();
  2280. Spawn* target = 0;
  2281. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2282. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2283. target = zone->GetSpawnByID(luaspell->targets[i]);
  2284. if (target && target->Alive()) {
  2285. if (target->IsPlayer()) {
  2286. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2287. Client* client = target->GetZone()->GetClientBySpawn(target);
  2288. if (client) {
  2289. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2290. if (packet)
  2291. client->QueuePacket(packet);
  2292. }
  2293. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2294. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2295. }
  2296. else if (target->IsNPC()) {
  2297. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2298. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2299. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2300. }
  2301. else
  2302. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2303. }
  2304. }
  2305. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2306. }
  2307. else if (spawn) {
  2308. if (spawn->IsPlayer()) {
  2309. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2310. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2311. if (client) {
  2312. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2313. if (packet)
  2314. client->QueuePacket(packet);
  2315. }
  2316. }
  2317. else if (spawn->IsNPC())
  2318. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2319. else
  2320. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2321. }
  2322. }
  2323. else
  2324. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2325. return 0;
  2326. }
  2327. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2328. if (!lua_interface)
  2329. return 0;
  2330. Spawn* spawn = lua_interface->GetSpawn(state);
  2331. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2332. if (spawn && spawn->IsPlayer()) {
  2333. int32 spell_id = 0;
  2334. if (luaspell && luaspell->spell) {
  2335. if(luaspell->resisted) {
  2336. return 0;
  2337. }
  2338. spell_id = luaspell->spell->GetSpellID();
  2339. ZoneServer* zone = luaspell->caster->GetZone();
  2340. Spawn* target = 0;
  2341. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2342. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2343. target = zone->GetSpawnByID(luaspell->targets[i]);
  2344. if (target) {
  2345. if (target->IsPlayer()) {
  2346. ((Player*)target)->RemoveSkillBonus(spell_id);
  2347. Client* client = target->GetZone()->GetClientBySpawn(target);
  2348. if (client) {
  2349. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2350. if (packet)
  2351. client->QueuePacket(packet);
  2352. }
  2353. }
  2354. else if (target->IsNPC())
  2355. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2356. else
  2357. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2358. }
  2359. }
  2360. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2361. }
  2362. else if (spawn) {
  2363. if (spawn->IsPlayer()) {
  2364. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2365. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2366. if (client) {
  2367. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2368. if (packet)
  2369. client->QueuePacket(packet);
  2370. }
  2371. }
  2372. else if (spawn->IsNPC())
  2373. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2374. else
  2375. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2376. }
  2377. }
  2378. return 0;
  2379. }
  2380. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2381. if (!lua_interface)
  2382. return 0;
  2383. Spawn* spawn = lua_interface->GetSpawn(state);
  2384. int8 type = lua_interface->GetInt32Value(state, 2);
  2385. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2386. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2387. if(luaspell && luaspell->resisted) {
  2388. return 0;
  2389. }
  2390. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2391. ZoneServer* zone = luaspell->caster->GetZone();
  2392. Spawn* target = 0;
  2393. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2394. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2395. target = zone->GetSpawnByID(luaspell->targets[i]);
  2396. if (target && target->IsEntity()) {
  2397. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2398. ((Entity*)target)->AddMezSpell(luaspell);
  2399. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2400. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2401. if (target->IsNPC())
  2402. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2403. }
  2404. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2405. ((Entity*)target)->AddStifleSpell(luaspell);
  2406. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2407. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2408. if (target->IsNPC())
  2409. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2410. }
  2411. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2412. ((Entity*)target)->AddDazeSpell(luaspell);
  2413. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2414. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2415. if (target->IsNPC())
  2416. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2417. }
  2418. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2419. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2420. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2421. ((Entity*)target)->AddStunSpell(luaspell);
  2422. if (target->IsNPC())
  2423. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2424. }
  2425. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2428. ((Entity*)target)->AddRootSpell(luaspell);
  2429. if (target->IsNPC())
  2430. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2431. }
  2432. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2433. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2434. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2435. ((Entity*)target)->AddFearSpell(luaspell);
  2436. if (target->IsNPC())
  2437. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2438. }
  2439. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2440. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2441. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2442. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2443. }
  2444. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2445. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2446. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2447. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2448. }
  2449. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2450. ((Entity*)target)->AddSnareSpell(luaspell);
  2451. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2452. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2453. if (target->IsNPC())
  2454. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2455. }
  2456. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2457. ((Entity*)target)->AddFlightSpell(luaspell);
  2458. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2459. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2460. }
  2461. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2462. ((Entity*)target)->AddGlideSpell(luaspell);
  2463. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2464. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2465. }
  2466. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2467. ((Entity*)target)->AddSafefallSpell(luaspell);
  2468. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2469. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2470. }
  2471. else
  2472. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2473. }
  2474. else
  2475. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2476. }
  2477. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2478. }
  2479. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2480. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2481. ((Entity*)spawn)->AddMezSpell(luaspell);
  2482. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2483. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2484. }
  2485. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2486. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2487. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2488. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2489. }
  2490. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2491. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2492. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2493. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2494. }
  2495. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2496. ((Entity*)spawn)->AddStunSpell(luaspell);
  2497. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2498. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2499. }
  2500. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2501. ((Entity*)spawn)->AddRootSpell(luaspell);
  2502. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2503. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2504. }
  2505. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2506. ((Entity*)spawn)->AddFearSpell(luaspell);
  2507. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2508. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2509. }
  2510. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2511. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2512. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2513. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2514. }
  2515. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2516. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2517. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2518. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2519. }
  2520. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2521. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2522. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2523. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2524. }
  2525. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2526. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2527. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2528. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2529. }
  2530. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2531. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2532. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2533. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2534. }
  2535. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2536. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2537. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2538. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2539. }
  2540. else
  2541. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2542. }
  2543. else
  2544. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2545. return 0;
  2546. }
  2547. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2548. if (!lua_interface)
  2549. return 0;
  2550. Spawn* spawn = lua_interface->GetSpawn(state);
  2551. int8 type = lua_interface->GetInt8Value(state, 2);
  2552. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2553. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2554. if (spawn && spawn->IsEntity()) {
  2555. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2556. ZoneServer* zone = luaspell->caster->GetZone();
  2557. Spawn* target = 0;
  2558. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2559. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2560. target = zone->GetSpawnByID(luaspell->targets[i]);
  2561. if (target) {
  2562. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2563. ((Entity*)target)->RemoveMezSpell(luaspell);
  2564. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2565. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2566. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2567. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2568. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2569. ((Entity*)target)->RemoveStunSpell(luaspell);
  2570. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2571. ((Entity*)target)->RemoveRootSpell(luaspell);
  2572. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2573. ((Entity*)target)->RemoveFearSpell(luaspell);
  2574. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2575. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2576. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2577. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2579. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2581. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2583. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2584. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2585. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2586. else
  2587. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2588. }
  2589. }
  2590. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2591. }
  2592. else if (only_remove_spawn) {
  2593. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2594. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2595. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2596. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2597. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2598. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2599. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2600. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2601. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2602. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2603. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2604. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2605. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2606. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2607. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2608. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2609. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2610. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2611. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2612. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2613. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2614. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2615. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2616. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2617. else
  2618. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2619. }
  2620. }
  2621. return 0;
  2622. }
  2623. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2624. if (!lua_interface)
  2625. return 0;
  2626. Spawn* spawn = lua_interface->GetSpawn(state);
  2627. int8 type = lua_interface->GetInt8Value(state, 2);
  2628. bool hasEffect = false;
  2629. if (!spawn)
  2630. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2631. else if (!spawn->IsEntity())
  2632. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2633. else if (type < CONTROL_MAX_EFFECTS)
  2634. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2635. else
  2636. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2637. lua_interface->SetBooleanValue(state, hasEffect);
  2638. return 1;
  2639. }
  2640. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2641. if (!lua_interface)
  2642. return 0;
  2643. Spawn* spawn = lua_interface->GetSpawn(state);
  2644. float distance = 0.0f;
  2645. if (!spawn)
  2646. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2647. else if (!spawn->IsNPC())
  2648. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2649. else
  2650. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2651. lua_interface->SetFloatValue(state, distance);
  2652. return 1;
  2653. }
  2654. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2655. if (!lua_interface)
  2656. return 0;
  2657. Spawn* spawn = lua_interface->GetSpawn(state);
  2658. float distance = 0.0f;
  2659. if (!spawn)
  2660. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2661. else if (!spawn->IsNPC())
  2662. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2663. else
  2664. distance = ((NPC*)spawn)->GetAggroRadius();
  2665. lua_interface->SetFloatValue(state, distance);
  2666. return 1;
  2667. }
  2668. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2669. if (!lua_interface)
  2670. return 0;
  2671. Spawn* spawn = lua_interface->GetSpawn(state);
  2672. float distance = lua_interface->GetFloatValue(state, 2);
  2673. bool override = lua_interface->GetBooleanValue(state, 3);
  2674. bool result = false;
  2675. lua_interface->ResetFunctionStack(state);
  2676. if (!spawn)
  2677. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2678. else if (!spawn->IsNPC())
  2679. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2680. else
  2681. {
  2682. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2683. result = true;
  2684. }
  2685. lua_interface->SetBooleanValue(state, result);
  2686. return 1;
  2687. }
  2688. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2689. if (!lua_interface)
  2690. return 0;
  2691. Spawn* spawn = lua_interface->GetSpawn(state);
  2692. int16 value = lua_interface->GetInt16Value(state, 2);
  2693. if (spawn && spawn->IsEntity()) {
  2694. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2695. if (spawn->IsPlayer())
  2696. ((Player*)spawn)->SetCharSheetChanged(true);
  2697. }
  2698. return 0;
  2699. }
  2700. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2701. if (!lua_interface)
  2702. return 0;
  2703. Spawn* spawn = lua_interface->GetSpawn(state);
  2704. int16 value = lua_interface->GetInt16Value(state, 2);
  2705. if (spawn && spawn->IsEntity()) {
  2706. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2707. if (spawn->IsPlayer())
  2708. ((Player*)spawn)->SetCharSheetChanged(true);
  2709. }
  2710. return 0;
  2711. }
  2712. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2713. if (!lua_interface)
  2714. return 0;
  2715. Spawn* spawn = lua_interface->GetSpawn(state);
  2716. int16 value = lua_interface->GetInt16Value(state, 2);
  2717. if (spawn && spawn->IsEntity()) {
  2718. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2719. if (spawn->IsPlayer())
  2720. ((Player*)spawn)->SetCharSheetChanged(true);
  2721. }
  2722. return 0;
  2723. }
  2724. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2725. if (!lua_interface)
  2726. return 0;
  2727. Spawn* spawn = lua_interface->GetSpawn(state);
  2728. int16 value = lua_interface->GetInt16Value(state, 2);
  2729. if (spawn && spawn->IsEntity()) {
  2730. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2731. if (spawn->IsPlayer())
  2732. ((Player*)spawn)->SetCharSheetChanged(true);
  2733. }
  2734. return 0;
  2735. }
  2736. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2737. if (!lua_interface)
  2738. return 0;
  2739. Spawn* spawn = lua_interface->GetSpawn(state);
  2740. int16 value = lua_interface->GetInt16Value(state, 2);
  2741. if (spawn && spawn->IsEntity()) {
  2742. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2743. if (spawn->IsPlayer())
  2744. ((Player*)spawn)->SetCharSheetChanged(true);
  2745. }
  2746. return 0;
  2747. }
  2748. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2749. if (!lua_interface)
  2750. return 0;
  2751. Spawn* spawn = lua_interface->GetSpawn(state);
  2752. int8 value = lua_interface->GetInt8Value(state, 2);
  2753. if (spawn && spawn->IsEntity()) {
  2754. ((Entity*)spawn)->SetDeity(value);
  2755. if (spawn->IsPlayer())
  2756. ((Player*)spawn)->SetCharSheetChanged(true);
  2757. }
  2758. lua_interface->ResetFunctionStack(state);
  2759. return 0;
  2760. }
  2761. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2762. if (!lua_interface)
  2763. return 0;
  2764. Spawn* spawn = lua_interface->GetSpawn(state);
  2765. if (spawn && spawn->IsEntity()) {
  2766. int8 deity = ((Entity*)spawn)->GetDeity();
  2767. lua_interface->SetInt32Value(state, deity);
  2768. return 1;
  2769. }
  2770. return 0;
  2771. }
  2772. int EQ2Emu_lua_SetInt(lua_State* state) {
  2773. if (!lua_interface)
  2774. return 0;
  2775. Spawn* spawn = lua_interface->GetSpawn(state);
  2776. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2777. if (spawn && spawn->IsEntity()) {
  2778. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2779. if (spawn->IsPlayer())
  2780. ((Player*)spawn)->SetCharSheetChanged(true);
  2781. }
  2782. return 0;
  2783. }
  2784. int EQ2Emu_lua_SetWis(lua_State* state) {
  2785. if (!lua_interface)
  2786. return 0;
  2787. Spawn* spawn = lua_interface->GetSpawn(state);
  2788. float value = lua_interface->GetFloatValue(state, 2);
  2789. if (spawn && spawn->IsEntity()) {
  2790. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2791. if (spawn->IsPlayer())
  2792. ((Player*)spawn)->SetCharSheetChanged(true);
  2793. }
  2794. return 0;
  2795. }
  2796. int EQ2Emu_lua_SetSta(lua_State* state) {
  2797. if (!lua_interface)
  2798. return 0;
  2799. Spawn* spawn = lua_interface->GetSpawn(state);
  2800. float value = lua_interface->GetFloatValue(state, 2);
  2801. if (spawn && spawn->IsEntity()) {
  2802. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2803. if (spawn->IsPlayer())
  2804. ((Player*)spawn)->SetCharSheetChanged(true);
  2805. }
  2806. return 0;
  2807. }
  2808. int EQ2Emu_lua_SetStr(lua_State* state) {
  2809. if (!lua_interface)
  2810. return 0;
  2811. Spawn* spawn = lua_interface->GetSpawn(state);
  2812. float value = lua_interface->GetFloatValue(state, 2);
  2813. if (spawn && spawn->IsEntity()) {
  2814. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2815. if (spawn->IsPlayer())
  2816. ((Player*)spawn)->SetCharSheetChanged(true);
  2817. }
  2818. return 0;
  2819. }
  2820. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2821. if (!lua_interface)
  2822. return 0;
  2823. Spawn* spawn = lua_interface->GetSpawn(state);
  2824. float value = lua_interface->GetFloatValue(state, 2);
  2825. if (spawn && spawn->IsEntity()) {
  2826. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2827. if (spawn->IsPlayer())
  2828. ((Player*)spawn)->SetCharSheetChanged(true);
  2829. }
  2830. return 0;
  2831. }
  2832. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2833. if (!lua_interface)
  2834. return 0;
  2835. Spawn* spawn = lua_interface->GetSpawn(state);
  2836. if (spawn) {
  2837. lua_interface->SetInt32Value(state, spawn->GetHP());
  2838. return 1;
  2839. }
  2840. return 0;
  2841. }
  2842. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2843. if (!lua_interface)
  2844. return 0;
  2845. Spawn* spawn = lua_interface->GetSpawn(state);
  2846. if (spawn) {
  2847. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2848. return 1;
  2849. }
  2850. return 0;
  2851. }
  2852. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2853. if (!lua_interface)
  2854. return 0;
  2855. Spawn* spawn = lua_interface->GetSpawn(state);
  2856. if (spawn) {
  2857. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2858. return 1;
  2859. }
  2860. return 0;
  2861. }
  2862. int EQ2Emu_lua_GetName(lua_State* state) {
  2863. if (!lua_interface)
  2864. return 0;
  2865. Spawn* spawn = lua_interface->GetSpawn(state);
  2866. if (spawn) {
  2867. lua_interface->SetStringValue(state, spawn->GetName());
  2868. return 1;
  2869. }
  2870. return 0;
  2871. }
  2872. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2873. Spawn* spawn = lua_interface->GetSpawn(state);
  2874. if (spawn) {
  2875. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2876. return 1;
  2877. }
  2878. return 0;
  2879. }
  2880. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2881. if (!lua_interface)
  2882. return 0;
  2883. Spawn* spawn = lua_interface->GetSpawn(state);
  2884. if (spawn) {
  2885. lua_interface->SetInt32Value(state, spawn->GetPower());
  2886. return 1;
  2887. }
  2888. return 0;
  2889. }
  2890. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2891. if (!lua_interface)
  2892. return 0;
  2893. Spawn* spawn = lua_interface->GetSpawn(state);
  2894. if (spawn) {
  2895. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2896. return 1;
  2897. }
  2898. return 0;
  2899. }
  2900. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2901. if (!lua_interface)
  2902. return 0;
  2903. Spawn* spawn = lua_interface->GetSpawn(state);
  2904. if (spawn) {
  2905. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2906. return 1;
  2907. }
  2908. return 0;
  2909. }
  2910. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2911. if (!lua_interface)
  2912. return 0;
  2913. Spawn* spawn = lua_interface->GetSpawn(state);
  2914. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2915. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2916. if (spawn && spawn2) {
  2917. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2918. lua_interface->SetFloatValue(state, distance);
  2919. return 1;
  2920. }
  2921. return 0;
  2922. }
  2923. int EQ2Emu_lua_GetX(lua_State* state) {
  2924. if (!lua_interface)
  2925. return 0;
  2926. Spawn* spawn = lua_interface->GetSpawn(state);
  2927. if (spawn) {
  2928. lua_interface->SetFloatValue(state, spawn->GetX());
  2929. return 1;
  2930. }
  2931. return 0;
  2932. }
  2933. int EQ2Emu_lua_GetY(lua_State* state) {
  2934. if (!lua_interface)
  2935. return 0;
  2936. Spawn* spawn = lua_interface->GetSpawn(state);
  2937. if (spawn) {
  2938. lua_interface->SetFloatValue(state, spawn->GetY());
  2939. return 1;
  2940. }
  2941. return 0;
  2942. }
  2943. int EQ2Emu_lua_GetZ(lua_State* state) {
  2944. if (!lua_interface)
  2945. return 0;
  2946. Spawn* spawn = lua_interface->GetSpawn(state);
  2947. if (spawn) {
  2948. lua_interface->SetFloatValue(state, spawn->GetZ());
  2949. return 1;
  2950. }
  2951. return 0;
  2952. }
  2953. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2954. if (!lua_interface)
  2955. return 0;
  2956. Spawn* spawn = lua_interface->GetSpawn(state);
  2957. if (spawn) {
  2958. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2959. return 1;
  2960. }
  2961. return 0;
  2962. }
  2963. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2964. if (!lua_interface)
  2965. return 0;
  2966. Spawn* spawn = lua_interface->GetSpawn(state);
  2967. if (spawn) {
  2968. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2969. return 1;
  2970. }
  2971. return 0;
  2972. }
  2973. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2974. if (!lua_interface)
  2975. return 0;
  2976. Spawn* spawn = lua_interface->GetSpawn(state);
  2977. if (spawn) {
  2978. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2979. return 1;
  2980. }
  2981. return 0;
  2982. }
  2983. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2984. if (!lua_interface)
  2985. return 0;
  2986. Spawn* spawn = lua_interface->GetSpawn(state);
  2987. if (spawn && spawn->IsEntity()) {
  2988. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2989. return 1;
  2990. }
  2991. return 0;
  2992. }
  2993. int EQ2Emu_lua_GetInt(lua_State* state) {
  2994. if (!lua_interface)
  2995. return 0;
  2996. Spawn* spawn = lua_interface->GetSpawn(state);
  2997. if (spawn && spawn->IsEntity()) {
  2998. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2999. return 1;
  3000. }
  3001. return 0;
  3002. }
  3003. int EQ2Emu_lua_GetWis(lua_State* state) {
  3004. if (!lua_interface)
  3005. return 0;
  3006. Spawn* spawn = lua_interface->GetSpawn(state);
  3007. if (spawn && spawn->IsEntity()) {
  3008. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3009. return 1;
  3010. }
  3011. return 0;
  3012. }
  3013. int EQ2Emu_lua_GetSta(lua_State* state) {
  3014. if (!lua_interface)
  3015. return 0;
  3016. Spawn* spawn = lua_interface->GetSpawn(state);
  3017. if (spawn && spawn->IsEntity()) {
  3018. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3019. return 1;
  3020. }
  3021. return 0;
  3022. }
  3023. int EQ2Emu_lua_GetStr(lua_State* state) {
  3024. if (!lua_interface)
  3025. return 0;
  3026. Spawn* spawn = lua_interface->GetSpawn(state);
  3027. if (spawn && spawn->IsEntity()) {
  3028. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3029. return 1;
  3030. }
  3031. return 0;
  3032. }
  3033. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3034. if (!lua_interface)
  3035. return 0;
  3036. Spawn* spawn = lua_interface->GetSpawn(state);
  3037. if (spawn && spawn->IsEntity()) {
  3038. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3039. return 1;
  3040. }
  3041. return 0;
  3042. }
  3043. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3044. if (!lua_interface)
  3045. return 0;
  3046. Spawn* spawn = lua_interface->GetSpawn(state);
  3047. if (spawn && spawn->IsEntity()) {
  3048. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3049. return 1;
  3050. }
  3051. return 0;
  3052. }
  3053. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3054. if (!lua_interface)
  3055. return 0;
  3056. Spawn* spawn = lua_interface->GetSpawn(state);
  3057. if (spawn && spawn->IsEntity()) {
  3058. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3059. return 1;
  3060. }
  3061. return 0;
  3062. }
  3063. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3064. if (!lua_interface)
  3065. return 0;
  3066. Spawn* spawn = lua_interface->GetSpawn(state);
  3067. if (spawn && spawn->IsEntity()) {
  3068. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3069. return 1;
  3070. }
  3071. return 0;
  3072. }
  3073. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3074. if (!lua_interface)
  3075. return 0;
  3076. Spawn* spawn = lua_interface->GetSpawn(state);
  3077. if (spawn && spawn->IsEntity()) {
  3078. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3079. return 1;
  3080. }
  3081. return 0;
  3082. }
  3083. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3084. if (!lua_interface)
  3085. return 0;
  3086. Spawn* spawn = lua_interface->GetSpawn(state);
  3087. if (spawn && spawn->IsEntity()) {
  3088. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3089. return 1;
  3090. }
  3091. return 0;
  3092. }
  3093. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3094. if (!lua_interface)
  3095. return 0;
  3096. Spawn* player = lua_interface->GetSpawn(state);
  3097. if (!player || !player->IsPlayer()) {
  3098. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3099. return 0;
  3100. }
  3101. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3102. if (quest_id <= 0) {
  3103. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3104. return 0;
  3105. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3106. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3107. return 0;
  3108. }
  3109. int32 step = lua_interface->GetInt32Value(state, 3);
  3110. if (step > 0) {
  3111. Client* client = player->GetZone()->GetClientBySpawn(player);
  3112. if (client)
  3113. client->AddPendingQuestUpdate(quest_id, step);
  3114. } else {
  3115. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3116. }
  3117. return 0;
  3118. }
  3119. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3120. Spawn* player = lua_interface->GetSpawn(state);
  3121. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3122. int32 step = lua_interface->GetInt32Value(state, 3);
  3123. int32 progress = lua_interface->GetInt32Value(state, 4);
  3124. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3125. Client* client = player->GetZone()->GetClientBySpawn(player);
  3126. if (client)
  3127. client->AddPendingQuestUpdate(quest_id, step, progress);
  3128. }
  3129. return 0;
  3130. }
  3131. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3132. if (!lua_interface)
  3133. return 0;
  3134. Spawn* player = lua_interface->GetSpawn(state);
  3135. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3136. if (player && player->IsPlayer() && quest_id > 0) {
  3137. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3138. return 1;
  3139. }
  3140. return 0;
  3141. }
  3142. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3143. if (!lua_interface)
  3144. return 0;
  3145. Spawn* player = lua_interface->GetSpawn(state);
  3146. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3147. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3148. if (player && player->IsPlayer() && quest_id > 0) {
  3149. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3150. return 1;
  3151. }
  3152. return 0;
  3153. }
  3154. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3155. if (!lua_interface)
  3156. return 0;
  3157. Spawn* player = lua_interface->GetSpawn(state);
  3158. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3159. if (player && player->IsPlayer() && quest_id > 0) {
  3160. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3161. return 1;
  3162. }
  3163. return 0;
  3164. }
  3165. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3166. if (!lua_interface)
  3167. return 0;
  3168. Quest* quest = lua_interface->GetQuest(state);
  3169. string name = lua_interface->GetStringValue(state, 2);
  3170. string type = lua_interface->GetStringValue(state, 3);
  3171. string zone = lua_interface->GetStringValue(state, 4);
  3172. int16 level = lua_interface->GetInt16Value(state, 5);
  3173. string description = lua_interface->GetStringValue(state, 6);
  3174. bool load = true;
  3175. if (!quest) {
  3176. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3177. load = false;
  3178. }
  3179. if (load && name.length() == 0) {
  3180. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3181. load = false;
  3182. }
  3183. if (load && type.length() == 0) {
  3184. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3185. load = false;
  3186. }
  3187. if (load && zone.length() == 0) {
  3188. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3189. load = false;
  3190. }
  3191. if (load && description.length() == 0) {
  3192. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3193. load = false;
  3194. }
  3195. if (load && level == 0) {
  3196. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3197. load = false;
  3198. }
  3199. if (load)
  3200. quest->RegisterQuest(name, type, zone, level, description);
  3201. return 0;
  3202. }
  3203. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3204. if (!lua_interface)
  3205. return 0;
  3206. Quest* quest = lua_interface->GetQuest(state);
  3207. if (quest) {
  3208. int8 level = lua_interface->GetInt16Value(state, 2);
  3209. quest->SetPrereqLevel(level);
  3210. }
  3211. return 0;
  3212. }
  3213. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3214. if (!lua_interface)
  3215. return 0;
  3216. Quest* quest = lua_interface->GetQuest(state);
  3217. if (quest) {
  3218. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3219. quest->AddPrereqQuest(quest_id);
  3220. }
  3221. return 0;
  3222. }
  3223. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3224. if (!lua_interface)
  3225. return 0;
  3226. Quest* quest = lua_interface->GetQuest(state);
  3227. if (quest) {
  3228. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3229. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3230. if (quantity == 0)
  3231. quantity = 1;
  3232. Item* master_item = master_item_list.GetItem(item_id);
  3233. if (master_item) {
  3234. Item* item = new Item(master_item);
  3235. item->details.count = quantity;
  3236. quest->AddPrereqItem(item);
  3237. }
  3238. }
  3239. return 0;
  3240. }
  3241. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3242. if (!lua_interface)
  3243. return 0;
  3244. Spawn* player = lua_interface->GetSpawn(state);
  3245. if(!player || !player->IsPlayer()) {
  3246. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3247. return 0;
  3248. }
  3249. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3250. if (quest_id > 0) {
  3251. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3252. return 1;
  3253. } else {
  3254. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3255. }
  3256. return 0;
  3257. }
  3258. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3259. if (!lua_interface)
  3260. return 0;
  3261. Quest* quest = lua_interface->GetQuest(state);
  3262. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3263. lua_interface->ResetFunctionStack(state);
  3264. if (quest && spawn_id > 0)
  3265. quest->SetQuestReturnNPC(spawn_id);
  3266. return 0;
  3267. }
  3268. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3269. if (!lua_interface)
  3270. return 0;
  3271. Spawn* spawn = lua_interface->GetSpawn(state);
  3272. int32 time = lua_interface->GetInt32Value(state, 2);
  3273. string function = lua_interface->GetStringValue(state, 3);
  3274. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3275. Spawn* player = lua_interface->GetSpawn(state, 5);
  3276. lua_interface->ResetFunctionStack(state);
  3277. if (!spawn) {
  3278. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3279. return 0;
  3280. }
  3281. if (time <= 0) {
  3282. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3283. return 0;
  3284. }
  3285. if (function.length() == 0) {
  3286. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3287. return 0;
  3288. }
  3289. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3290. if ( time < 10)
  3291. time = 10;
  3292. timer->timer = Timer::GetCurrentTime2() + time;
  3293. timer->function = function;
  3294. timer->spawn = spawn->GetID();
  3295. timer->player = player ? player->GetID() : 0;
  3296. if (max_count == 0)
  3297. max_count = 1;
  3298. timer->max_count = max_count;
  3299. timer->current_count = 0;
  3300. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3301. return 0;
  3302. }
  3303. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3304. if (!lua_interface)
  3305. return 0;
  3306. Spawn* spawn = lua_interface->GetSpawn(state);
  3307. string function = lua_interface->GetStringValue(state, 2);
  3308. lua_interface->ResetFunctionStack(state);
  3309. if (!spawn) {
  3310. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3311. return 0;
  3312. }
  3313. if(!spawn->GetZone()) {
  3314. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3315. return 0;
  3316. }
  3317. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3318. return 0;
  3319. }
  3320. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3321. if (!lua_interface)
  3322. return 0;
  3323. Spawn* player = lua_interface->GetSpawn(state);
  3324. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3325. lua_interface->ResetFunctionStack(state);
  3326. if (player && player->IsPlayer() && quest_id > 0) {
  3327. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3328. return 1;
  3329. }
  3330. return 0;
  3331. }
  3332. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3333. if (!lua_interface)
  3334. return 0;
  3335. Spawn* player = lua_interface->GetSpawn(state);
  3336. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3337. lua_interface->ResetFunctionStack(state);
  3338. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3339. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3340. if (quest)
  3341. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3342. return 1;
  3343. }
  3344. return 0;
  3345. }
  3346. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3347. if (!lua_interface)
  3348. return 0;
  3349. Spawn* player = lua_interface->GetSpawn(state);
  3350. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3351. lua_interface->ResetFunctionStack(state);
  3352. if (player && player->IsPlayer() && quest_id > 0) {
  3353. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3354. return 1;
  3355. }
  3356. return 0;
  3357. }
  3358. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3359. if (!lua_interface)
  3360. return 0;
  3361. Spawn* npc = lua_interface->GetSpawn(state);
  3362. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3363. lua_interface->ResetFunctionStack(state);
  3364. if (npc && !npc->IsPlayer() && quest_id > 0)
  3365. npc->AddProvidedQuest(quest_id);
  3366. return 0;
  3367. }
  3368. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3369. if (!lua_interface)
  3370. return 0;
  3371. Spawn* npc = lua_interface->GetSpawn(state);
  3372. Spawn* player = lua_interface->GetSpawn(state, 2);
  3373. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3374. bool forced = lua_interface->GetBooleanValue(state, 4);
  3375. lua_interface->ResetFunctionStack(state);
  3376. /* NPC is allowed to be null */
  3377. if (player && player->IsPlayer() && quest_id > 0) {
  3378. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3379. if (master_quest) {
  3380. Client* client = player->GetZone()->GetClientBySpawn(player);
  3381. if (!client) {
  3382. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3383. }
  3384. Quest* quest = new Quest(master_quest);
  3385. if (!quest) {
  3386. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3387. }
  3388. if (client && quest) {
  3389. if (npc)
  3390. quest->SetQuestGiver(npc->GetDatabaseID());
  3391. else
  3392. quest->SetQuestGiver(0);
  3393. client->AddPendingQuest(quest, forced);
  3394. }
  3395. }
  3396. else {
  3397. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3398. }
  3399. }
  3400. else {
  3401. 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);
  3402. }
  3403. return 0;
  3404. }
  3405. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3406. if (!lua_interface)
  3407. return 0;
  3408. Quest* quest = lua_interface->GetQuest(state);
  3409. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3410. lua_interface->ResetFunctionStack(state);
  3411. if (quest) {
  3412. quest->AddPrereqClass(class_id);
  3413. }
  3414. return 0;
  3415. }
  3416. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3417. if (!lua_interface)
  3418. return 0;
  3419. Quest* quest = lua_interface->GetQuest(state);
  3420. int8 race = lua_interface->GetInt8Value(state, 2);
  3421. lua_interface->ResetFunctionStack(state);
  3422. if (quest) {
  3423. quest->AddPrereqRace(race);
  3424. }
  3425. return 0;
  3426. }
  3427. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3428. if (!lua_interface)
  3429. return 0;
  3430. Quest* quest = lua_interface->GetQuest(state);
  3431. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3432. lua_interface->ResetFunctionStack(state);
  3433. if (quest) {
  3434. quest->AddPrereqModelType(model_type);
  3435. }
  3436. return 0;
  3437. }
  3438. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3439. if (!lua_interface)
  3440. return 0;
  3441. Quest* quest = lua_interface->GetQuest(state);
  3442. int8 level = lua_interface->GetInt8Value(state, 2);
  3443. lua_interface->ResetFunctionStack(state);
  3444. if (!quest) {
  3445. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3446. return 0;
  3447. }
  3448. quest->SetPrereqTSLevel(level);
  3449. return 0;
  3450. }
  3451. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3452. if (!lua_interface)
  3453. return 0;
  3454. Quest* quest = lua_interface->GetQuest(state);
  3455. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3456. lua_interface->ResetFunctionStack(state);
  3457. if (!quest) {
  3458. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3459. return 0;
  3460. }
  3461. quest->AddPrereqTradeskillClass(class_id);
  3462. return 0;
  3463. }
  3464. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3465. if (!lua_interface)
  3466. return 0;
  3467. Quest* quest = lua_interface->GetQuest(state);
  3468. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3469. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3470. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3471. lua_interface->ResetFunctionStack(state);
  3472. if (quest) {
  3473. quest->AddPrereqFaction(faction_id, min, max);
  3474. }
  3475. return 0;
  3476. }
  3477. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3478. if (!lua_interface)
  3479. return 0;
  3480. Quest* quest = lua_interface->GetQuest(state);
  3481. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3482. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3483. lua_interface->ResetFunctionStack(state);
  3484. if (quest) {
  3485. if (quantity == 0)
  3486. quantity = 1;
  3487. Item* master_item = master_item_list.GetItem(item_id);
  3488. if (master_item) {
  3489. Item* item = new Item(master_item);
  3490. item->details.count = quantity;
  3491. quest->AddSelectableRewardItem(item);
  3492. }
  3493. }
  3494. return 0;
  3495. }
  3496. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3497. if (!lua_interface)
  3498. return 0;
  3499. Quest* quest = lua_interface->GetQuest(state);
  3500. if (quest) {
  3501. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3502. vector<Item*>* items = quest->GetRewardItems();
  3503. if (items) {
  3504. vector<Item*>::iterator itr;
  3505. for (itr = items->begin(); itr != items->end(); itr++) {
  3506. if (*itr && (*itr)->details.item_id == item_id) {
  3507. lua_interface->SetBooleanValue(state, true);
  3508. return 1;
  3509. }
  3510. }
  3511. }
  3512. }
  3513. lua_interface->SetBooleanValue(state, false);
  3514. return 1;
  3515. }
  3516. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3517. if (!lua_interface)
  3518. return 0;
  3519. Quest* quest = lua_interface->GetQuest(state);
  3520. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3521. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3522. lua_interface->ResetFunctionStack(state);
  3523. if (quest) {
  3524. if (quantity == 0)
  3525. quantity = 1;
  3526. Item* master_item = master_item_list.GetItem(item_id);
  3527. if (master_item) {
  3528. Item* item = new Item(master_item);
  3529. item->details.count = quantity;
  3530. quest->AddRewardItem(item);
  3531. }
  3532. }
  3533. return 0;
  3534. }
  3535. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3536. if (!lua_interface)
  3537. return 0;
  3538. Quest* quest = lua_interface->GetQuest(state);
  3539. int32 copper = lua_interface->GetInt32Value(state, 2);
  3540. int32 silver = lua_interface->GetInt32Value(state, 3);
  3541. int32 gold = lua_interface->GetInt32Value(state, 4);
  3542. int32 plat = lua_interface->GetInt32Value(state, 5);
  3543. lua_interface->ResetFunctionStack(state);
  3544. if (quest) {
  3545. quest->AddRewardCoins(copper, silver, gold, plat);
  3546. }
  3547. return 0;
  3548. }
  3549. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3550. if (!lua_interface)
  3551. return 0;
  3552. Quest* quest = lua_interface->GetQuest(state);
  3553. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3554. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3555. lua_interface->ResetFunctionStack(state);
  3556. if (quest && faction_id > 0 && amount != 0)
  3557. quest->AddRewardFaction(faction_id, amount);
  3558. return 0;
  3559. }
  3560. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3561. if (!lua_interface)
  3562. return 0;
  3563. Quest* quest = lua_interface->GetQuest(state);
  3564. int32 status = lua_interface->GetInt32Value(state, 2);
  3565. lua_interface->ResetFunctionStack(state);
  3566. if (quest) {
  3567. quest->SetRewardStatus(status);
  3568. }
  3569. return 0;
  3570. }
  3571. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3572. if (!lua_interface)
  3573. return 0;
  3574. Quest* quest = lua_interface->GetQuest(state);
  3575. int32 status = lua_interface->GetInt32Value(state, 2);
  3576. lua_interface->ResetFunctionStack(state);
  3577. if (quest) {
  3578. quest->SetStatusTmpReward(status);
  3579. }
  3580. return 0;
  3581. }
  3582. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3583. if (!lua_interface)
  3584. return 0;
  3585. Quest* quest = lua_interface->GetQuest(state);
  3586. int64 coins = lua_interface->GetInt64Value(state, 2);
  3587. lua_interface->ResetFunctionStack(state);
  3588. if (quest) {
  3589. quest->SetCoinTmpReward(coins);
  3590. }
  3591. return 0;
  3592. }
  3593. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3594. if (!lua_interface)
  3595. return 0;
  3596. Quest* quest = lua_interface->GetQuest(state);
  3597. string comment = lua_interface->GetStringValue(state, 2);
  3598. lua_interface->ResetFunctionStack(state);
  3599. if (quest) {
  3600. quest->SetRewardComment(comment);
  3601. }
  3602. return 0;
  3603. }
  3604. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3605. if (!lua_interface)
  3606. return 0;
  3607. Quest* quest = lua_interface->GetQuest(state);
  3608. int32 exp = lua_interface->GetInt32Value(state, 2);
  3609. lua_interface->ResetFunctionStack(state);
  3610. if (quest) {
  3611. quest->SetRewardXP(exp);
  3612. }
  3613. return 0;
  3614. }
  3615. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3616. Quest* quest = lua_interface->GetQuest(state);
  3617. int32 step = lua_interface->GetInt32Value(state, 2);
  3618. string description = lua_interface->GetStringValue(state, 3);
  3619. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3620. float percentage = lua_interface->GetFloatValue(state, 5);
  3621. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3622. int16 icon = lua_interface->GetInt16Value(state, 7);
  3623. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3624. if (quest) {
  3625. const char* taskgroup = 0;
  3626. if (str_taskgroup.length() > 0)
  3627. taskgroup = str_taskgroup.c_str();
  3628. int32 id = 0;
  3629. vector<int32>* ids = 0;
  3630. int i = 0;
  3631. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3632. if (ids == 0)
  3633. ids = new vector<int32>;
  3634. ids->push_back(id);
  3635. i++;
  3636. }
  3637. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3638. if (quest_step && icon && quantity > 0)
  3639. quest_step->SetIcon(icon);
  3640. if (quest->GetPlayer()) {
  3641. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3642. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3643. }
  3644. }
  3645. lua_interface->ResetFunctionStack(state);
  3646. return 0;
  3647. }
  3648. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3649. {
  3650. if (!lua_interface)
  3651. return 0;
  3652. Quest* quest = lua_interface->GetQuest(state);
  3653. int32 step = lua_interface->GetInt32Value(state, 2);
  3654. string description = lua_interface->GetStringValue(state, 3);
  3655. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3656. float percentage = lua_interface->GetFloatValue(state, 5);
  3657. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3658. int16 icon = lua_interface->GetInt16Value(state, 7);
  3659. if (quest) {
  3660. const char* taskgroup = 0;
  3661. if (str_taskgroup.length() > 0)
  3662. taskgroup = str_taskgroup.c_str();
  3663. int32 id = 0;
  3664. vector<int32>* ids = 0;
  3665. int i = 0;
  3666. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3667. if (ids == 0)
  3668. ids = new vector<int32>;
  3669. ids->push_back(id);
  3670. i++;
  3671. }
  3672. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3673. if (quest_step && icon > 0 && quantity > 0)
  3674. quest_step->SetIcon(icon);
  3675. if (quest->GetPlayer()) {
  3676. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3677. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3678. }
  3679. safe_delete(ids);
  3680. }
  3681. lua_interface->ResetFunctionStack(state);
  3682. return 0;
  3683. }
  3684. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3685. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3686. }
  3687. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3688. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3689. }
  3690. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3691. if (!lua_interface)
  3692. return 0;
  3693. Quest* quest = lua_interface->GetQuest(state);
  3694. int32 step = lua_interface->GetInt32Value(state, 2);
  3695. string description = lua_interface->GetStringValue(state, 3);
  3696. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3697. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3698. int16 icon = lua_interface->GetInt16Value(state, 6);
  3699. if (quest) {
  3700. const char* taskgroup = 0;
  3701. if (str_taskgroup.length() > 0)
  3702. taskgroup = str_taskgroup.c_str();
  3703. int32 npc_id = 0;
  3704. vector<int32>* ids = 0;
  3705. int i = 0;
  3706. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3707. if (ids == 0)
  3708. ids = new vector<int32>;
  3709. ids->push_back(npc_id);
  3710. i++;
  3711. }
  3712. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3713. if (quest_step && icon > 0)
  3714. quest_step->SetIcon(icon);
  3715. if (quest->GetPlayer()) {
  3716. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3717. if(client)
  3718. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3719. }
  3720. safe_delete(ids);
  3721. }
  3722. lua_interface->ResetFunctionStack(state);
  3723. return 0;
  3724. }
  3725. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3726. if (!lua_interface)
  3727. return 0;
  3728. Quest* quest = lua_interface->GetQuest(state);
  3729. int32 step = lua_interface->GetInt32Value(state, 2);
  3730. string description = lua_interface->GetStringValue(state, 3);
  3731. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3732. float percentage = lua_interface->GetFloatValue(state, 5);
  3733. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3734. int16 icon = lua_interface->GetInt16Value(state, 7);
  3735. if (quest) {
  3736. const char* taskgroup = 0;
  3737. if (str_taskgroup.length() > 0)
  3738. taskgroup = str_taskgroup.c_str();
  3739. int32 item_id = 0;
  3740. vector<int32>* ids = 0;
  3741. int i = 0;
  3742. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3743. if (ids == 0)
  3744. ids = new vector<int32>;
  3745. ids->push_back(item_id);
  3746. i++;
  3747. }
  3748. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3749. if (quest_step && icon > 0 && quantity > 0)
  3750. quest_step->SetIcon(icon);
  3751. if (quest->GetPlayer()) {
  3752. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3753. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3754. }
  3755. safe_delete(ids);
  3756. }
  3757. lua_interface->ResetFunctionStack(state);
  3758. return 0;
  3759. }
  3760. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3761. if (!lua_interface)
  3762. return 0;
  3763. Quest* quest = lua_interface->GetQuest(state);
  3764. int32 step = lua_interface->GetInt32Value(state, 2);
  3765. string description = lua_interface->GetStringValue(state, 3);
  3766. float max_variation = lua_interface->GetFloatValue(state, 4);
  3767. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3768. int16 icon = lua_interface->GetInt16Value(state, 6);
  3769. if (quest) {
  3770. const char* taskgroup = 0;
  3771. if (str_taskgroup.length() > 0)
  3772. taskgroup = str_taskgroup.c_str();
  3773. vector<Location>* locations = 0;
  3774. int8 i = 7;
  3775. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3776. while (true) {
  3777. Location loc;
  3778. loc.x = lua_interface->GetFloatValue(state, i);
  3779. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3780. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3781. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3782. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3783. break;
  3784. if (locations == 0)
  3785. locations = new vector<Location>;
  3786. locations->push_back(loc);
  3787. i += 4;
  3788. }
  3789. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3790. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3791. if (quest_step && icon > 0)
  3792. quest_step->SetIcon(icon);
  3793. if (quest->GetPlayer()) {
  3794. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3795. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3796. }
  3797. }
  3798. lua_interface->ResetFunctionStack(state);
  3799. return 0;
  3800. }
  3801. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3802. if (!lua_interface)
  3803. return 0;
  3804. Quest* quest = lua_interface->GetQuest(state);
  3805. int32 step = lua_interface->GetInt32Value(state, 2);
  3806. string description = lua_interface->GetStringValue(state, 3);
  3807. float max_variation = lua_interface->GetFloatValue(state, 4);
  3808. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3809. int16 icon = lua_interface->GetInt16Value(state, 6);
  3810. if (quest) {
  3811. const char* taskgroup = 0;
  3812. if (str_taskgroup.length() > 0)
  3813. taskgroup = str_taskgroup.c_str();
  3814. vector<Location>* locations = 0;
  3815. int8 i = 7;
  3816. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3817. while (true) {
  3818. Location loc;
  3819. loc.x = lua_interface->GetFloatValue(state, i);
  3820. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3821. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3822. loc.zone_id = 0;
  3823. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3824. break;
  3825. if (locations == 0)
  3826. locations = new vector<Location>;
  3827. locations->push_back(loc);
  3828. i += 3;
  3829. }
  3830. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3831. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3832. if (quest_step && icon > 0)
  3833. quest_step->SetIcon(icon);
  3834. if (quest->GetPlayer()) {
  3835. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3836. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3837. }
  3838. }
  3839. lua_interface->ResetFunctionStack(state);
  3840. return 0;
  3841. }
  3842. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3843. if (!lua_interface)
  3844. return 0;
  3845. Quest* quest = lua_interface->GetQuest(state);
  3846. int32 step = lua_interface->GetInt32Value(state, 2);
  3847. string description = lua_interface->GetStringValue(state, 3);
  3848. float max_variation = lua_interface->GetFloatValue(state, 4);
  3849. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3850. int16 icon = lua_interface->GetInt16Value(state, 6);
  3851. if (quest) {
  3852. const char* taskgroup = 0;
  3853. if (str_taskgroup.length() > 0)
  3854. taskgroup = str_taskgroup.c_str();
  3855. vector<Location>* locations = 0;
  3856. int i = 7;
  3857. while (true) {
  3858. Location loc;
  3859. loc.x = lua_interface->GetFloatValue(state, i);
  3860. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3861. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3862. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3863. break;
  3864. if (locations == 0)
  3865. locations = new vector<Location>;
  3866. locations->push_back(loc);
  3867. i += 3;
  3868. }
  3869. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3870. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3871. if (quest_step && icon > 0)
  3872. quest_step->SetIcon(icon);
  3873. if (quest->GetPlayer()) {
  3874. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3875. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3876. }
  3877. }
  3878. lua_interface->ResetFunctionStack(state);
  3879. return 0;
  3880. }
  3881. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3882. Quest* quest = lua_interface->GetQuest(state);
  3883. int32 step = lua_interface->GetInt32Value(state, 2);
  3884. string description = lua_interface->GetStringValue(state, 3);
  3885. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3886. float percentage = lua_interface->GetFloatValue(state, 5);
  3887. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3888. int16 icon = lua_interface->GetInt16Value(state, 7);
  3889. if (quest) {
  3890. const char* taskgroup = 0;
  3891. if (str_taskgroup.length() > 0)
  3892. taskgroup = str_taskgroup.c_str();
  3893. int32 spell_id = 0;
  3894. vector<int32>* ids = 0;
  3895. int i = 0;
  3896. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3897. if (ids == 0)
  3898. ids = new vector<int32>;
  3899. ids->push_back(spell_id);
  3900. i++;
  3901. }
  3902. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3903. if (quest_step && icon > 0 && quantity > 0)
  3904. quest_step->SetIcon(icon);
  3905. if (quest->GetPlayer()) {
  3906. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3907. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3908. }
  3909. safe_delete(ids);
  3910. }
  3911. lua_interface->ResetFunctionStack(state);
  3912. return 0;
  3913. }
  3914. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3915. if (!lua_interface)
  3916. return 0;
  3917. Quest* quest = lua_interface->GetQuest(state);
  3918. int32 step = lua_interface->GetInt32Value(state, 2);
  3919. string description = lua_interface->GetStringValue(state, 3);
  3920. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3921. float percentage = lua_interface->GetFloatValue(state, 5);
  3922. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3923. int16 icon = lua_interface->GetInt16Value(state, 7);
  3924. if (quest) {
  3925. const char* taskgroup = 0;
  3926. if (str_taskgroup.length() > 0)
  3927. taskgroup = str_taskgroup.c_str();
  3928. int32 item_id = 0;
  3929. vector<int32>* ids = 0;
  3930. int i = 0;
  3931. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3932. if (ids == 0)
  3933. ids = new vector<int32>;
  3934. ids->push_back(item_id);
  3935. i++;
  3936. }
  3937. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3938. if (quest_step && icon > 0 && quantity > 0)
  3939. quest_step->SetIcon(icon);
  3940. if (quest->GetPlayer()) {
  3941. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3942. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3943. }
  3944. safe_delete(ids);
  3945. }
  3946. lua_interface->ResetFunctionStack(state);
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3950. if (!lua_interface)
  3951. return 0;
  3952. Quest* quest = lua_interface->GetQuest(state);
  3953. int32 step = lua_interface->GetInt32Value(state, 2);
  3954. string description = lua_interface->GetStringValue(state, 3);
  3955. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3956. float percentage = lua_interface->GetFloatValue(state, 5);
  3957. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3958. int16 icon = lua_interface->GetInt16Value(state, 7);
  3959. if (quest) {
  3960. const char* taskgroup = 0;
  3961. if (str_taskgroup.length() > 0)
  3962. taskgroup = str_taskgroup.c_str();
  3963. int32 item_id = 0;
  3964. vector<int32>* ids = 0;
  3965. int i = 0;
  3966. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3967. if (ids == 0)
  3968. ids = new vector<int32>;
  3969. ids->push_back(item_id);
  3970. i++;
  3971. }
  3972. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3973. if (quest_step && icon > 0 && quantity > 0)
  3974. quest_step->SetIcon(icon);
  3975. if (quest->GetPlayer()) {
  3976. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3977. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3978. }
  3979. safe_delete(ids);
  3980. }
  3981. lua_interface->ResetFunctionStack(state);
  3982. return 0;
  3983. }
  3984. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3985. if (!lua_interface)
  3986. return 0;
  3987. Quest* quest = lua_interface->GetQuest(state);
  3988. string action = lua_interface->GetStringValue(state, 2);
  3989. lua_interface->ResetFunctionStack(state);
  3990. if (quest) {
  3991. if (action.length() > 0)
  3992. quest->SetCompleteAction(action);
  3993. }
  3994. return 0;
  3995. }
  3996. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3997. if (!lua_interface)
  3998. return 0;
  3999. Quest* quest = lua_interface->GetQuest(state);
  4000. int32 step = lua_interface->GetInt32Value(state, 2);
  4001. string action = lua_interface->GetStringValue(state, 3);
  4002. lua_interface->ResetFunctionStack(state);
  4003. if (quest) {
  4004. if (step > 0 && action.length() > 0)
  4005. quest->AddCompleteAction(step, action);
  4006. }
  4007. return 0;
  4008. }
  4009. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4010. if (!lua_interface)
  4011. return 0;
  4012. Quest* quest = lua_interface->GetQuest(state);
  4013. int32 step = lua_interface->GetInt32Value(state, 2);
  4014. string action = lua_interface->GetStringValue(state, 3);
  4015. lua_interface->ResetFunctionStack(state);
  4016. if (quest) {
  4017. if (step > 0 && action.length() > 0)
  4018. quest->AddProgressAction(step, action);
  4019. }
  4020. return 0;
  4021. }
  4022. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4023. if (!lua_interface)
  4024. return 0;
  4025. Quest* quest = lua_interface->GetQuest(state);
  4026. string description = lua_interface->GetStringValue(state, 2);
  4027. lua_interface->ResetFunctionStack(state);
  4028. if (quest && description.length() > 0)
  4029. quest->SetDescription(description);
  4030. return 0;
  4031. }
  4032. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4033. if (!lua_interface)
  4034. return 0;
  4035. Quest* quest = lua_interface->GetQuest(state);
  4036. string description = lua_interface->GetStringValue(state, 2);
  4037. lua_interface->ResetFunctionStack(state);
  4038. if (quest && description.length() > 0)
  4039. quest->SetCompletedDescription(description);
  4040. return 0;
  4041. }
  4042. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4043. if (!lua_interface)
  4044. return 0;
  4045. Quest* quest = lua_interface->GetQuest(state);
  4046. int32 step = lua_interface->GetInt32Value(state, 2);
  4047. string description = lua_interface->GetStringValue(state, 3);
  4048. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4049. lua_interface->ResetFunctionStack(state);
  4050. if (quest && step > 0 && description.length() > 0) {
  4051. quest->SetTaskGroupDescription(step, description, display_bullets);
  4052. /* if (quest->GetPlayer()) {
  4053. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4054. if (client)
  4055. client->SendQuestUpdateStep(quest, step, false);
  4056. }*/
  4057. }
  4058. return 0;
  4059. }
  4060. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4061. if (!lua_interface)
  4062. return 0;
  4063. Quest* quest = lua_interface->GetQuest(state);
  4064. int32 step = lua_interface->GetInt32Value(state, 2);
  4065. string description = lua_interface->GetStringValue(state, 3);
  4066. lua_interface->ResetFunctionStack(state);
  4067. if (quest && step > 0 && description.length() > 0) {
  4068. quest->SetStepDescription(step, description);
  4069. /*if (quest->GetPlayer()) {
  4070. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4071. if (client)
  4072. client->SendQuestUpdateStepImmediately(quest, step);
  4073. }*/
  4074. }
  4075. return 0;
  4076. }
  4077. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4078. Quest* quest = lua_interface->GetQuest(state);
  4079. string zone = lua_interface->GetStringValue(state, 2);
  4080. lua_interface->ResetFunctionStack(state);
  4081. if (quest && zone.length() > 0)
  4082. quest->SetZone(zone);
  4083. return 0;
  4084. }
  4085. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4086. if (!lua_interface)
  4087. return 0;
  4088. Quest* quest = lua_interface->GetQuest(state);
  4089. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4090. lua_interface->ResetFunctionStack(state);
  4091. if (quest && spawn) {
  4092. if (spawn->IsPlayer()) {
  4093. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4094. if (client) {
  4095. client->AddPendingQuestReward(quest);
  4096. }
  4097. }
  4098. }
  4099. return 0;
  4100. }
  4101. int EQ2Emu_lua_Harvest(lua_State* state) {
  4102. if (!lua_interface)
  4103. return 0;
  4104. Spawn* player = lua_interface->GetSpawn(state);
  4105. Spawn* node = lua_interface->GetSpawn(state, 2);
  4106. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4107. Client* client = player->GetZone()->GetClientBySpawn(player);
  4108. if (client) {
  4109. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4110. ((GroundSpawn*)node)->ProcessHarvest(client);
  4111. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4112. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4113. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4114. }
  4115. }
  4116. }
  4117. else if (player && player->IsPlayer()) {
  4118. Client* client = player->GetZone()->GetClientBySpawn(player);
  4119. if (client)
  4120. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4121. }
  4122. lua_interface->ResetFunctionStack(state);
  4123. return 0;
  4124. }
  4125. int EQ2Emu_lua_Bind(lua_State* state) {
  4126. if (!lua_interface)
  4127. return 0;
  4128. Spawn* spawn = lua_interface->GetSpawn(state);
  4129. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4130. float x = lua_interface->GetFloatValue(state, 3);
  4131. float y = lua_interface->GetFloatValue(state, 4);
  4132. float z = lua_interface->GetFloatValue(state, 5);
  4133. float h = lua_interface->GetFloatValue(state, 6);
  4134. lua_interface->ResetFunctionStack(state);
  4135. if (!spawn) {
  4136. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4137. return 0;
  4138. }
  4139. if (!spawn->IsPlayer()) {
  4140. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4141. return 0;
  4142. }
  4143. if (zone_id == 0) {
  4144. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4145. if (!client) {
  4146. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4147. return 0;
  4148. }
  4149. if (!client->Bind())
  4150. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4151. }
  4152. else {
  4153. Player* player = (Player*)spawn;
  4154. player->GetPlayerInfo()->SetBindZone(zone_id);
  4155. player->GetPlayerInfo()->SetBindX(x);
  4156. player->GetPlayerInfo()->SetBindY(y);
  4157. player->GetPlayerInfo()->SetBindZ(z);
  4158. player->GetPlayerInfo()->SetBindHeading(h);
  4159. }
  4160. return 0;
  4161. }
  4162. int EQ2Emu_lua_Gate(lua_State* state) {
  4163. if (!lua_interface)
  4164. return 0;
  4165. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4166. Spawn* spawn = lua_interface->GetSpawn(state);
  4167. lua_interface->ResetFunctionStack(state);
  4168. if (spawn) {
  4169. if (spawn->IsPlayer()) {
  4170. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4171. if (client) {
  4172. if (!client->Gate((spell != nullptr) ? true : false))
  4173. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4174. }
  4175. }
  4176. }
  4177. return 0;
  4178. }
  4179. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4180. if (!lua_interface)
  4181. return 0;
  4182. bool ret = false;
  4183. Spawn* spawn = lua_interface->GetSpawn(state);
  4184. lua_interface->ResetFunctionStack(state);
  4185. if (spawn) {
  4186. if (spawn->IsPlayer()) {
  4187. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4188. if (client)
  4189. ret = client->BindAllowed();
  4190. }
  4191. }
  4192. lua_interface->SetBooleanValue(state, ret);
  4193. return 1;
  4194. }
  4195. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4196. if (!lua_interface)
  4197. return 0;
  4198. bool ret = false;
  4199. Spawn* spawn = lua_interface->GetSpawn(state);
  4200. lua_interface->ResetFunctionStack(state);
  4201. if (spawn) {
  4202. if (spawn->IsPlayer()) {
  4203. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4204. ZoneServer* zone = lua_interface->GetZone(state);
  4205. if (client && zone){
  4206. ret = zone->GetCanGate();
  4207. }
  4208. }
  4209. }
  4210. lua_interface->SetBooleanValue(state, ret);
  4211. return 1;
  4212. }
  4213. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4214. Spawn* spawn = lua_interface->GetSpawn(state);
  4215. lua_interface->ResetFunctionStack(state);
  4216. if (spawn) {
  4217. lua_interface->SetBooleanValue(state, spawn->Alive());
  4218. return 1;
  4219. }
  4220. return 0;
  4221. }
  4222. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4223. if (!lua_interface)
  4224. return 0;
  4225. Spawn* spawn = lua_interface->GetSpawn(state);
  4226. lua_interface->ResetFunctionStack(state);
  4227. if (spawn && spawn->IsEntity()) {
  4228. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4229. return 1;
  4230. }
  4231. return 0;
  4232. }
  4233. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4234. Spawn* spawn = lua_interface->GetSpawn(state);
  4235. string message = lua_interface->GetStringValue(state, 2);
  4236. string color_str = lua_interface->GetStringValue(state, 3);
  4237. lua_interface->ResetFunctionStack(state);
  4238. int8 color = CHANNEL_NARRATIVE;
  4239. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4240. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4241. if (client) {
  4242. if (color_str.length() > 0) {
  4243. // leave for backwards compat, but all future should just use the number
  4244. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4245. color = CHANNEL_COLOR_RED;
  4246. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4247. color = CHANNEL_COLOR_YELLOW;
  4248. else
  4249. {
  4250. // use a number to specify the channel as per Commands/Commands.h defines
  4251. color = (int8)atoul(color_str.c_str());
  4252. }
  4253. }
  4254. client->SimpleMessage(color, message.c_str());
  4255. }
  4256. }
  4257. return 0;
  4258. }
  4259. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4260. Spawn* spawn = lua_interface->GetSpawn(state);
  4261. string message = lua_interface->GetStringValue(state, 2);
  4262. int8 red = lua_interface->GetInt8Value(state, 3);
  4263. int8 green = lua_interface->GetInt8Value(state, 4);
  4264. int8 blue = lua_interface->GetInt8Value(state, 5);
  4265. lua_interface->ResetFunctionStack(state);
  4266. if (!spawn) {
  4267. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4268. return 0;
  4269. }
  4270. int32 words = ::CountWordsInString(message.c_str());
  4271. if (words < 5)
  4272. words = 5;
  4273. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4274. if (client)
  4275. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4276. return 0;
  4277. }
  4278. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4279. Spawn* spawn = lua_interface->GetSpawn(state);
  4280. int8 param = lua_interface->GetInt8Value(state, 2);
  4281. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4282. int8 value = lua_interface->GetInt8Value(state, 4);
  4283. lua_interface->ResetFunctionStack(state);
  4284. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4285. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4286. if (client) {
  4287. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4288. switch (param) {
  4289. case 1: {
  4290. packet->setDataByName("parameter1", param_value);
  4291. break;
  4292. }
  4293. case 2: {
  4294. packet->setDataByName("parameter2", param_value);
  4295. break;
  4296. }
  4297. case 3: {
  4298. packet->setDataByName("parameter3", param_value);
  4299. break;
  4300. }
  4301. case 4: {
  4302. packet->setDataByName("parameter4", param_value);
  4303. break;
  4304. }
  4305. case 5: {
  4306. packet->setDataByName("parameter5", param_value);
  4307. break;
  4308. }
  4309. }
  4310. packet->setDataByName("value", value);
  4311. client->QueuePacket(packet->serialize());
  4312. safe_delete(packet);
  4313. }
  4314. }
  4315. return 0;
  4316. }
  4317. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4318. Spawn* spawn = lua_interface->GetSpawn(state);
  4319. lua_interface->ResetFunctionStack(state);
  4320. if (spawn && spawn->IsPlayer()) {
  4321. if (((Player*)spawn)->GetIsTracking())
  4322. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4323. else
  4324. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4325. }
  4326. return 0;
  4327. }
  4328. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4329. Spawn* player = lua_interface->GetSpawn(state);
  4330. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4331. string name = lua_interface->GetStringValue(state, 3);
  4332. float distance = lua_interface->GetFloatValue(state, 4);
  4333. string command = lua_interface->GetStringValue(state, 5);
  4334. string error_text = lua_interface->GetStringValue(state, 6);
  4335. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4336. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4337. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4338. lua_interface->ResetFunctionStack(state);
  4339. if (spawn) {
  4340. if (distance == 0)
  4341. distance = 10.0f;
  4342. if (command.length() == 0)
  4343. command = name;
  4344. if (command.length() < 1 && name.length() < 1)
  4345. {
  4346. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4347. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4348. spawn->RemovePrimaryCommands();
  4349. }
  4350. else
  4351. {
  4352. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4353. }
  4354. }
  4355. return 0;
  4356. }
  4357. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4358. if (!lua_interface)
  4359. return 0;
  4360. Spawn* player = lua_interface->GetSpawn(state);
  4361. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4362. int16 tier = lua_interface->GetInt16Value(state, 3);
  4363. lua_interface->ResetFunctionStack(state);
  4364. if (player && player->IsPlayer()) {
  4365. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4366. return 1;
  4367. }
  4368. return 0;
  4369. }
  4370. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4371. if (!lua_interface)
  4372. return 0;
  4373. Spawn* player = lua_interface->GetSpawn(state);
  4374. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4375. int16 tier = lua_interface->GetInt16Value(state, 3);
  4376. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4377. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4378. bool add_to_hotbar = true;
  4379. if (num_args > 4) {
  4380. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4381. }
  4382. lua_interface->ResetFunctionStack(state);
  4383. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4384. if (player && spell && player->IsPlayer()) {
  4385. Client* client = player->GetClient();
  4386. if (client) {
  4387. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4388. {
  4389. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4390. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4391. client->GetPlayer()->UnlockSpell(spell);
  4392. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4393. }
  4394. else
  4395. {
  4396. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4397. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4398. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4399. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4400. client->GetPlayer()->UnlockSpell(spell);
  4401. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4402. }
  4403. //if (client ) {
  4404. // ((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);
  4405. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4406. if (outapp)
  4407. client->QueuePacket(outapp);
  4408. }
  4409. }
  4410. return 0;
  4411. }
  4412. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4413. if (!lua_interface)
  4414. return 0;
  4415. Spawn* player = lua_interface->GetSpawn(state);
  4416. lua_interface->ResetFunctionStack(state);
  4417. if (player && player->IsPlayer()) {
  4418. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4419. return 1;
  4420. }
  4421. return 0;
  4422. }
  4423. int EQ2Emu_lua_Attack(lua_State* state) {
  4424. if (lua_interface) {
  4425. Spawn* npc = lua_interface->GetSpawn(state);
  4426. Spawn* player = lua_interface->GetSpawn(state, 2);
  4427. lua_interface->ResetFunctionStack(state);
  4428. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4429. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4430. }
  4431. return 0;
  4432. }
  4433. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4434. if (lua_interface) {
  4435. Spawn* target = lua_interface->GetSpawn(state);
  4436. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4437. lua_interface->ResetFunctionStack(state);
  4438. if (target && target->GetZone())
  4439. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4440. }
  4441. return 0;
  4442. }
  4443. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4444. Spawn* player;
  4445. if (lua_interface) {
  4446. player = lua_interface->GetSpawn(state);
  4447. lua_interface->ResetFunctionStack(state);
  4448. if (player && player->IsPlayer()) {
  4449. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4450. return 1;
  4451. }
  4452. }
  4453. return 0;
  4454. }
  4455. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4456. Spawn* player;
  4457. Client* client;
  4458. if (lua_interface) {
  4459. player = lua_interface->GetSpawn(state);
  4460. lua_interface->ResetFunctionStack(state);
  4461. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4462. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4463. client->HandInCollections();
  4464. }
  4465. return 0;
  4466. }
  4467. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4468. Spawn* widget;
  4469. if (lua_interface) {
  4470. widget = lua_interface->GetSpawn(state);
  4471. lua_interface->ResetFunctionStack(state);
  4472. if (widget && widget->IsWidget())
  4473. ((Widget*)widget)->HandleUse(nullptr, "");
  4474. }
  4475. return 0;
  4476. }
  4477. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4478. Spawn* spawn = 0;
  4479. int32 primary_list = 0;
  4480. int32 secondary_list = 0;
  4481. if (lua_interface) {
  4482. spawn = lua_interface->GetSpawn(state);
  4483. primary_list = lua_interface->GetInt32Value(state, 2);
  4484. secondary_list = lua_interface->GetInt32Value(state, 3);
  4485. lua_interface->ResetFunctionStack(state);
  4486. if (!spawn->IsNPC()) {
  4487. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4488. return 0;
  4489. }
  4490. NPC* npc = (NPC*)spawn;
  4491. npc->SetPrimarySpellList(primary_list);
  4492. npc->SetSecondarySpellList(secondary_list);
  4493. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4494. }
  4495. return 0;
  4496. }
  4497. int EQ2Emu_lua_GetPet(lua_State* state) {
  4498. if (!lua_interface)
  4499. return 0;
  4500. Spawn* spawn = lua_interface->GetSpawn(state);
  4501. lua_interface->ResetFunctionStack(state);
  4502. if (spawn) {
  4503. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4504. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4505. return 1;
  4506. }
  4507. }
  4508. return 0;
  4509. }
  4510. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4511. if (!lua_interface)
  4512. return 0;
  4513. Spawn* spawn = lua_interface->GetSpawn(state);
  4514. lua_interface->ResetFunctionStack(state);
  4515. if (spawn) {
  4516. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4517. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4518. return 1;
  4519. }
  4520. }
  4521. return 0;
  4522. }
  4523. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4524. if (!lua_interface)
  4525. return 0;
  4526. Spawn* spawn = lua_interface->GetSpawn(state);
  4527. lua_interface->ResetFunctionStack(state);
  4528. if (spawn) {
  4529. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4530. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4531. return 1;
  4532. }
  4533. }
  4534. return 0;
  4535. }
  4536. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4537. if (!lua_interface)
  4538. return 0;
  4539. Spawn* spawn = lua_interface->GetSpawn(state);
  4540. lua_interface->ResetFunctionStack(state);
  4541. if (spawn) {
  4542. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4543. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4544. return 1;
  4545. }
  4546. }
  4547. return 0;
  4548. }
  4549. int EQ2Emu_lua_Charm(lua_State* state) {
  4550. if (!lua_interface)
  4551. return 0;
  4552. Spawn* owner = lua_interface->GetSpawn(state);
  4553. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4554. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4555. lua_interface->ResetFunctionStack(state);
  4556. if (!luaspell) {
  4557. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4558. return 0;
  4559. }
  4560. if(luaspell->resisted) {
  4561. return 0;
  4562. }
  4563. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4564. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4565. pet->SetPet(true);
  4566. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4567. ((NPC*)pet)->SetOwner((Entity*)owner);
  4568. // If owner is player and player does not have a summoned pet set the players charsheet
  4569. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4570. Player* player = (Player*)owner;
  4571. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4572. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4573. player->GetInfoStruct()->set_pet_movement(2);
  4574. player->GetInfoStruct()->set_pet_behavior(3);
  4575. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4576. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4577. // Make sure the values get sent to the client
  4578. player->SetCharSheetChanged(true);
  4579. }
  4580. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4581. pet->SetSpawnScript("");
  4582. // Set faction to the same as the owner
  4583. pet->SetFactionID(owner->GetFactionID());
  4584. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4585. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4586. // Clear hate list
  4587. ((NPC*)pet)->Brain()->ClearHate();
  4588. // Set the brain to a pet brain
  4589. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4590. }
  4591. return 0;
  4592. }
  4593. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4594. if (!lua_interface)
  4595. return 0;
  4596. Spawn* spawn = lua_interface->GetSpawn(state);
  4597. lua_interface->ResetFunctionStack(state);
  4598. if (!spawn) {
  4599. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4600. return 0;
  4601. }
  4602. vector<Spawn*> groupMembers;
  4603. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4604. groupMembers = *spawn->GetSpawnGroup();
  4605. }
  4606. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4607. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4608. deque<GroupMemberInfo*>::iterator itr;
  4609. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4610. if (group)
  4611. {
  4612. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4613. deque<GroupMemberInfo*>* members = group->GetMembers();
  4614. GroupMemberInfo* info = 0;
  4615. for (itr = members->begin(); itr != members->end(); itr++) {
  4616. info = *itr;
  4617. if (info->client)
  4618. groupMembers.push_back(info->client->GetPlayer());
  4619. }
  4620. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4621. }
  4622. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4623. }
  4624. else
  4625. return 0;
  4626. lua_createtable(state, groupMembers.size(), 0);
  4627. int newTable = lua_gettop(state);
  4628. for (int32 i = 0; i < groupMembers.size(); i++) {
  4629. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4630. lua_rawseti(state, newTable, i + 1);
  4631. }
  4632. return 1;
  4633. }
  4634. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4635. if (!lua_interface)
  4636. return 0;
  4637. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4638. lua_interface->SetOptionWindowValue(state, option_window);
  4639. return 1;
  4640. }
  4641. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4642. if (!lua_interface)
  4643. return 0;
  4644. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4645. if (option_window) {
  4646. OptionWindowOption option_window_option;
  4647. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4648. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4649. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4650. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4651. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4652. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4653. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4654. option_window->push_back(option_window_option);
  4655. }
  4656. return 0;
  4657. }
  4658. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4659. if (!lua_interface)
  4660. return 0;
  4661. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4662. Spawn* player = lua_interface->GetSpawn(state, 2);
  4663. string window_title = lua_interface->GetStringValue(state, 3);
  4664. string cancel_command = lua_interface->GetStringValue(state, 4);
  4665. Client* client = player->GetZone()->GetClientBySpawn(player);
  4666. if (option_window && window_title.length() > 0 && client) {
  4667. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4668. if (!packet)
  4669. return 0;
  4670. packet->setDataByName("title_text", window_title.c_str());
  4671. if (cancel_command.length() > 0)
  4672. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4673. packet->setArrayLengthByName("num_selections", option_window->size());
  4674. vector<OptionWindowOption>::iterator itr;
  4675. int8 i = 0;
  4676. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4677. OptionWindowOption opt = *itr;
  4678. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4679. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4680. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4681. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4682. if (opt.optionCommand.length() > 0)
  4683. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4684. if (opt.optionConfirmTitle.length() > 0)
  4685. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4686. i++;
  4687. }
  4688. client->QueuePacket(packet->serialize());
  4689. safe_delete(option_window);
  4690. safe_delete(packet);
  4691. }
  4692. return 0;
  4693. }
  4694. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4695. if (!lua_interface)
  4696. return 0;
  4697. Spawn* spawn = lua_interface->GetSpawn(state);
  4698. if (spawn) {
  4699. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4700. return 1;
  4701. }
  4702. else
  4703. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4704. return 0;
  4705. }
  4706. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4707. if (!lua_interface)
  4708. return 0;
  4709. Spawn* spawn = lua_interface->GetSpawn(state);
  4710. if (spawn) {
  4711. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4712. return 1;
  4713. }
  4714. else
  4715. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4716. return 0;
  4717. }
  4718. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4719. if (!lua_interface)
  4720. return 0;
  4721. Spawn* spawn = lua_interface->GetSpawn(state);
  4722. if (spawn) {
  4723. int8 class_id = spawn->GetTradeskillClass();
  4724. // Need to add 42 for the offset in the array
  4725. class_id += 44;
  4726. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4727. return 1;
  4728. }
  4729. else
  4730. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4731. return 0;
  4732. }
  4733. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4734. if (!lua_interface)
  4735. return 0;
  4736. Spawn* spawn = lua_interface->GetSpawn(state);
  4737. int16 level = lua_interface->GetInt8Value(state, 2);
  4738. if (spawn) {
  4739. if (spawn->IsPlayer())
  4740. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4741. else
  4742. spawn->SetTSLevel(level);
  4743. }
  4744. else
  4745. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4746. return 0;
  4747. }
  4748. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4749. if (!lua_interface)
  4750. return 0;
  4751. Spawn* spawn = lua_interface->GetSpawn(state);
  4752. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4753. if (spawn) {
  4754. spawn->SetAttackable(attackable);
  4755. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4756. }
  4757. return 0;
  4758. }
  4759. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4760. // Check to see if we have a valid lua_interface
  4761. if (!lua_interface)
  4762. return 0;
  4763. // Get the spawn that is getting the pet
  4764. Spawn* spawn = lua_interface->GetSpawn(state);
  4765. // Get the DB ID of the pet
  4766. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4767. // The max level the pet can gain
  4768. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4769. // Get the spell that this command was called from
  4770. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4771. // Check to make sure the spawn pointer is valid
  4772. if (!spawn) {
  4773. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4774. return 0;
  4775. }
  4776. // Check to make sure the spawn is an entity
  4777. if (!spawn->IsEntity()) {
  4778. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4779. return 0;
  4780. }
  4781. // Check to make sure the spawn doesn't already have a pet of this type
  4782. if (((Entity*)spawn)->GetPet()) {
  4783. if (spawn->IsPlayer()) {
  4784. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4785. if (client)
  4786. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4787. }
  4788. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4789. return 0;
  4790. }
  4791. // Check to see if the DB ID for the pet is set
  4792. if (pet_id == 0) {
  4793. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4794. return 0;
  4795. }
  4796. // Check to see if the pointer to the spell is valid
  4797. if (!luaspell) {
  4798. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4799. return 0;
  4800. }
  4801. if(luaspell->resisted) {
  4802. return 0;
  4803. }
  4804. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4805. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4806. if (!pet) {
  4807. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4808. return 0;
  4809. }
  4810. // Check to make sure the pet is an npc
  4811. if (!pet->IsNPC()) {
  4812. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4813. return 0;
  4814. }
  4815. // Spawn the pet at the same location as the owner
  4816. pet->SetX(spawn->GetX());
  4817. pet->SetY(spawn->GetY());
  4818. pet->SetZ(spawn->GetZ());
  4819. pet->SetLocation(spawn->GetLocation());
  4820. pet->SetHeading(spawn->GetHeading());
  4821. spawn->GetZone()->AddSpawn(pet);
  4822. /*
  4823. const char* spawn_script = world.GetSpawnScript(pet_id);
  4824. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4825. spawn->SetSpawnScript(string(spawn_script));
  4826. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4827. }*/
  4828. // Get a random pet name
  4829. string random_pet_name;
  4830. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4831. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4832. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4833. // If player set various values for the char sheet (pet window)
  4834. if (spawn->IsPlayer()) {
  4835. Player* player = (Player*)spawn;
  4836. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4837. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4838. player->GetInfoStruct()->set_pet_movement(2);
  4839. player->GetInfoStruct()->set_pet_behavior(3);
  4840. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4841. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4842. // Make sure the values get sent to the client
  4843. player->SetCharSheetChanged(true);
  4844. }
  4845. // Set the pets name
  4846. pet->SetName(random_pet_name.c_str());
  4847. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4848. if (max_level > 0)
  4849. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4850. else
  4851. pet->SetLevel(spawn->GetLevel());
  4852. // Set the max level this pet can reach
  4853. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4854. // Set the faction of the pet to the same faction as the owner
  4855. pet->SetFactionID(spawn->GetFactionID());
  4856. // Set the spawn as a pet
  4857. pet->SetPet(true);
  4858. // Give a pointer of the owner to the pet
  4859. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4860. // Give a pointer of the pet to the owner
  4861. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4862. // Set the pet type
  4863. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4864. // Set the spell id used to create this pet
  4865. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4866. // Set the spell tier used to create this pet
  4867. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4868. // Set the pets spawn type to 6
  4869. pet->SetSpawnType(6);
  4870. // Set the pets brain
  4871. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4872. // Check to see if the pet has a subtitle
  4873. if (strlen(pet->GetSubTitle()) > 0) {
  4874. // Add the players name to the front of the sub title
  4875. string pet_subtitle;
  4876. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4877. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4878. // Set the pets subtitle to the new one
  4879. pet->SetSubTitle(pet_subtitle.c_str());
  4880. }
  4881. // Add the "Pet Options" entity command to the pet
  4882. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4883. // Set the pet as the return value for this function
  4884. lua_interface->SetSpawnValue(state, pet);
  4885. return 1;
  4886. }
  4887. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4888. if (!lua_interface)
  4889. return 0;
  4890. Spawn* spawn = lua_interface->GetSpawn(state);
  4891. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4892. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4893. if (!spawn) {
  4894. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4895. return 0;
  4896. }
  4897. if (!spawn->IsEntity()) {
  4898. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4899. return 0;
  4900. }
  4901. if (((Entity*)spawn)->GetDeityPet()) {
  4902. if (spawn->IsPlayer()) {
  4903. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4904. if (client)
  4905. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4906. }
  4907. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4908. return 0;
  4909. }
  4910. if (pet_id == 0) {
  4911. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4912. return 0;
  4913. }
  4914. if (!luaspell) {
  4915. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4916. return 0;
  4917. }
  4918. if(luaspell->resisted) {
  4919. return 0;
  4920. }
  4921. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4922. if (!pet) {
  4923. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4924. return 0;
  4925. }
  4926. if (!pet->IsNPC()) {
  4927. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4928. return 0;
  4929. }
  4930. pet->SetX(spawn->GetX());
  4931. pet->SetY(spawn->GetY());
  4932. pet->SetZ(spawn->GetZ());
  4933. pet->SetLocation(spawn->GetLocation());
  4934. pet->SetHeading(spawn->GetHeading());
  4935. spawn->GetZone()->AddSpawn(pet);
  4936. string random_pet_name;
  4937. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4938. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4939. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4940. pet->SetName(random_pet_name.c_str());
  4941. pet->SetLevel(spawn->GetLevel());
  4942. pet->SetFactionID(spawn->GetFactionID());
  4943. pet->SetPet(true);
  4944. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4945. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4946. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4947. pet->SetSpawnType(6);
  4948. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4949. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4950. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4951. if (strlen(pet->GetSubTitle()) > 0) {
  4952. string pet_subtitle;
  4953. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4954. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4955. pet->SetSubTitle(pet_subtitle.c_str());
  4956. }
  4957. // deity and cosmetic pets are not attackable
  4958. pet->SetAttackable(false);
  4959. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4960. lua_interface->SetSpawnValue(state, pet);
  4961. return 1;
  4962. }
  4963. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4964. if (!lua_interface)
  4965. return 0;
  4966. Spawn* spawn = lua_interface->GetSpawn(state);
  4967. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4968. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4969. if (!spawn) {
  4970. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4971. return 0;
  4972. }
  4973. if (!spawn->IsEntity()) {
  4974. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4975. return 0;
  4976. }
  4977. if (((Entity*)spawn)->GetCosmeticPet()) {
  4978. if (spawn->IsPlayer()) {
  4979. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4980. if (client)
  4981. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4982. }
  4983. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4984. return 0;
  4985. }
  4986. if (pet_id == 0) {
  4987. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4988. return 0;
  4989. }
  4990. if (!luaspell) {
  4991. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4992. return 0;
  4993. }
  4994. if(luaspell->resisted) {
  4995. return 0;
  4996. }
  4997. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4998. if (!pet) {
  4999. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5000. return 0;
  5001. }
  5002. if (!pet->IsNPC()) {
  5003. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5004. return 0;
  5005. }
  5006. pet->SetX(spawn->GetX());
  5007. pet->SetY(spawn->GetY());
  5008. pet->SetZ(spawn->GetZ());
  5009. pet->SetLocation(spawn->GetLocation());
  5010. pet->SetHeading(spawn->GetHeading());
  5011. spawn->GetZone()->AddSpawn(pet);
  5012. string random_pet_name;
  5013. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5014. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5015. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5016. pet->SetName(random_pet_name.c_str());
  5017. pet->SetLevel(spawn->GetLevel());
  5018. pet->SetFactionID(spawn->GetFactionID());
  5019. pet->SetPet(true);
  5020. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5021. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5022. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5023. pet->SetSpawnType(6);
  5024. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5025. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5026. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5027. if (strlen(pet->GetSubTitle()) > 0) {
  5028. string pet_subtitle;
  5029. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5030. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5031. pet->SetSubTitle(pet_subtitle.c_str());
  5032. }
  5033. pet->SetAttackable(false);
  5034. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5035. lua_interface->SetSpawnValue(state, pet);
  5036. return 1;
  5037. }
  5038. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5039. if (!lua_interface)
  5040. return 0;
  5041. Spawn* spawn = lua_interface->GetSpawn(state);
  5042. if (!spawn) {
  5043. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5044. return 0;
  5045. }
  5046. if (!spawn->IsPet()) {
  5047. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5048. return 0;
  5049. }
  5050. if (!((NPC*)spawn)->IsDismissing())
  5051. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5052. return 0;
  5053. }
  5054. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5055. if (!lua_interface)
  5056. return 0;
  5057. Quest* quest = lua_interface->GetQuest(state);
  5058. if (!quest) {
  5059. 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));
  5060. return 0;
  5061. }
  5062. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5063. if (feather_color > 0)
  5064. quest->SetFeatherColor(feather_color);
  5065. return 0;
  5066. }
  5067. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5068. if (!lua_interface)
  5069. return 0;
  5070. Spawn* spawn = lua_interface->GetSpawn(state);
  5071. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5072. if (!spawn) {
  5073. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5074. return 0;
  5075. }
  5076. if (!spawn2) {
  5077. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5078. return 0;
  5079. }
  5080. spawn->RemoveSpawnAccess(spawn2);
  5081. return 0;
  5082. }
  5083. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5084. if (!lua_interface)
  5085. return 0;
  5086. ZoneServer* zone = lua_interface->GetZone(state);
  5087. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5088. if (!zone) {
  5089. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5090. return 0;
  5091. }
  5092. if (location_id == 0) {
  5093. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5094. return 0;
  5095. }
  5096. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5097. if (!location) {
  5098. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5099. return 0;
  5100. }
  5101. Spawn* spawn = 0;
  5102. if (location->entities[0]) {
  5103. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5104. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5105. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5106. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5107. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5108. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5109. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5110. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5111. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5112. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5113. if(spawn && spawn->IsOmittedByDBFlag())
  5114. {
  5115. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5116. safe_delete(spawn);
  5117. spawn = 0;
  5118. return 0;
  5119. }
  5120. if (spawn) {
  5121. const char* script = 0;
  5122. for (int x = 0; x < 3; x++) {
  5123. switch (x) {
  5124. case 0:
  5125. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5126. break;
  5127. case 1:
  5128. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5129. break;
  5130. case 2:
  5131. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5132. break;
  5133. }
  5134. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5135. spawn->SetSpawnScript(string(script));
  5136. break;
  5137. }
  5138. }
  5139. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5140. lua_interface->SetSpawnValue(state, spawn);
  5141. return 1;
  5142. }
  5143. else {
  5144. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5145. safe_delete(spawn);
  5146. }
  5147. }
  5148. return 0;
  5149. }
  5150. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5151. if (!lua_interface)
  5152. return 0;
  5153. Spawn* caster = lua_interface->GetSpawn(state);
  5154. Spawn* target = lua_interface->GetSpawn(state, 2);
  5155. int32 id = lua_interface->GetInt32Value(state, 3);
  5156. string command = lua_interface->GetStringValue(state, 4);
  5157. if (!caster) {
  5158. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5159. return 0;
  5160. }
  5161. if (!target) {
  5162. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5163. return 0;
  5164. }
  5165. if (!caster->IsPlayer()) {
  5166. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5167. return 0;
  5168. }
  5169. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5170. if (!entity_command) {
  5171. 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());
  5172. return 0;
  5173. }
  5174. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5175. if (!client) {
  5176. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5177. return 0;
  5178. }
  5179. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5180. return 0;
  5181. }
  5182. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5183. if (!lua_interface)
  5184. return 0;
  5185. Spawn* spawn = lua_interface->GetSpawn(state);
  5186. if (!spawn) {
  5187. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5188. return 0;
  5189. }
  5190. if (!spawn->IsNPC()) {
  5191. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5192. return 0;
  5193. }
  5194. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5195. return 0;
  5196. }
  5197. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5198. if (!lua_interface)
  5199. return 0;
  5200. Spawn* spawn = lua_interface->GetSpawn(state);
  5201. int16 tick = lua_interface->GetInt16Value(state, 2);
  5202. if (!spawn) {
  5203. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5204. return 0;
  5205. }
  5206. if (!spawn->IsNPC()) {
  5207. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5208. return 0;
  5209. }
  5210. if (tick < 20) {
  5211. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5212. return 0;
  5213. }
  5214. ((NPC*)spawn)->Brain()->SetTick(tick);
  5215. return 0;
  5216. }
  5217. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5218. if (!lua_interface)
  5219. return 0;
  5220. Spawn* spawn = lua_interface->GetSpawn(state);
  5221. Spawn* target = lua_interface->GetSpawn(state, 2);
  5222. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5223. if (!spawn) {
  5224. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5225. return 0;
  5226. }
  5227. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5228. spawn->SetFollowTarget(target, follow_distance);
  5229. return 0;
  5230. }
  5231. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5232. if (!lua_interface)
  5233. return 0;
  5234. Spawn* spawn = lua_interface->GetSpawn(state);
  5235. if (!spawn) {
  5236. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5237. return 0;
  5238. }
  5239. Spawn* target = spawn->GetFollowTarget();
  5240. if (target) {
  5241. lua_interface->SetSpawnValue(state, target);
  5242. return 1;
  5243. }
  5244. return 0;
  5245. }
  5246. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5247. if (!lua_interface)
  5248. return 0;
  5249. Spawn* spawn = lua_interface->GetSpawn(state);
  5250. if (!spawn) {
  5251. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5252. return 0;
  5253. }
  5254. if (spawn->following)
  5255. spawn->following = false;
  5256. else
  5257. spawn->following = true;
  5258. return 0;
  5259. }
  5260. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5261. if (!lua_interface)
  5262. return 0;
  5263. Spawn* spawn = lua_interface->GetSpawn(state);
  5264. if (!spawn) {
  5265. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5266. return 0;
  5267. }
  5268. lua_interface->SetBooleanValue(state, spawn->following);
  5269. return 1;
  5270. }
  5271. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5272. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5273. // I will attempt to explain how this function works for future refrence
  5274. // Fist lets make sure lua_interface is valid, if not return out
  5275. if (!lua_interface)
  5276. return 0;
  5277. // Next we grab the first 2 params same as we usually would
  5278. Spawn* spawn = lua_interface->GetSpawn(state);
  5279. string var = lua_interface->GetStringValue(state, 2);
  5280. // 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
  5281. // 1 = Spawn
  5282. // 2 = Zone
  5283. // 3 = Item
  5284. // 4 = Quest
  5285. // 5 = String
  5286. // 6 = nil (null)
  5287. int8 dataType = 0;
  5288. // Define pointers for each potential type
  5289. Spawn* spawnVal = 0;
  5290. ZoneServer* zone = 0;
  5291. Item* item = 0;
  5292. Quest* quest = 0;
  5293. string val;
  5294. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5295. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5296. // options window are also light user data be we do not handle those.
  5297. // We check with lua_islightuserdata(lua_State*, index)
  5298. if (lua_islightuserdata(state, 3)) {
  5299. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5300. // and convert it to LUAUserData*
  5301. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5302. // Check to make sure the data we got is valid, if not give an error
  5303. if (!data || !data->IsCorrectlyInitialized()) {
  5304. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5305. }
  5306. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5307. else if (data->IsSpawn()) {
  5308. spawnVal = data->spawn;
  5309. dataType = 1;
  5310. }
  5311. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5312. else if (data->IsZone()) {
  5313. zone = data->zone;
  5314. dataType = 2;
  5315. }
  5316. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5317. else if (data->IsItem()) {
  5318. item = data->item;
  5319. dataType = 3;
  5320. }
  5321. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5322. else if (data->IsQuest()) {
  5323. quest = data->quest;
  5324. dataType = 4;
  5325. }
  5326. }
  5327. // Wasn't light user data, check if it is nil(null)
  5328. else if (lua_isnil(state, 3)) {
  5329. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5330. dataType = 6;
  5331. }
  5332. // Wasn't light user data or nil (null), must be a string
  5333. else {
  5334. // Set the string and dataType variable
  5335. val = lua_interface->GetStringValue(state, 3);
  5336. dataType = 5;
  5337. }
  5338. // We now have all the params, lets check to make sure they are valid
  5339. if (!spawn) {
  5340. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5341. return 0;
  5342. }
  5343. if (var.length() == 0) {
  5344. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5345. return 0;
  5346. }
  5347. if (dataType == 0) {
  5348. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5349. return 0;
  5350. }
  5351. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5352. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5353. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5354. switch (dataType) {
  5355. case 1:
  5356. // 1 = Spawn
  5357. spawn->AddTempVariable(var, spawnVal);
  5358. break;
  5359. case 2:
  5360. // 2 = Zone
  5361. spawn->AddTempVariable(var, zone);
  5362. break;
  5363. case 3:
  5364. // 3 = Item
  5365. spawn->AddTempVariable(var, item);
  5366. break;
  5367. case 4:
  5368. // 4 = Quest
  5369. spawn->AddTempVariable(var, quest);
  5370. break;
  5371. case 5:
  5372. // 5 = String
  5373. spawn->AddTempVariable(var, val);
  5374. break;
  5375. case 6:
  5376. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5377. spawn->DeleteTempVariable(var);
  5378. break;
  5379. }
  5380. // And we are done so return out
  5381. return 0;
  5382. }
  5383. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5384. if (!lua_interface)
  5385. return 0;
  5386. Spawn* spawn = lua_interface->GetSpawn(state);
  5387. string var = lua_interface->GetStringValue(state, 2);
  5388. if (!spawn) {
  5389. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5390. return 0;
  5391. }
  5392. if (var.length() == 0) {
  5393. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5394. return 0;
  5395. }
  5396. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5397. int8 type = spawn->GetTempVariableType(var);
  5398. Spawn* spawn2 = 0;
  5399. ZoneServer* zone = 0;
  5400. Item* item = 0;
  5401. Quest* quest = 0;
  5402. // Set the lua function return value based on the type of data the variable contains
  5403. switch (type) {
  5404. case 1:
  5405. spawn2 = spawn->GetTempVariableSpawn(var);
  5406. if (!spawn2)
  5407. return 0;
  5408. lua_interface->SetSpawnValue(state, spawn2);
  5409. break;
  5410. case 2:
  5411. zone = spawn->GetTempVariableZone(var);
  5412. if (!zone)
  5413. return 0;
  5414. lua_interface->SetZoneValue(state, zone);
  5415. break;
  5416. case 3:
  5417. item = spawn->GetTempVariableItem(var);
  5418. if (!item)
  5419. return 0;
  5420. lua_interface->SetItemValue(state, item);
  5421. break;
  5422. case 4:
  5423. quest = spawn->GetTempVariableQuest(var);
  5424. if (!quest)
  5425. return 0;
  5426. lua_interface->SetQuestValue(state, quest);
  5427. break;
  5428. case 5:
  5429. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5430. break;
  5431. default:
  5432. // Not a valid type then the variable was not set so return out
  5433. return 0;
  5434. }
  5435. // Return value was set so return out
  5436. return 1;
  5437. }
  5438. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5439. {
  5440. if (!lua_interface)
  5441. return 0;
  5442. Quest* quest = lua_interface->GetQuest(state);
  5443. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5444. string description = lua_interface->GetStringValue(state, 3);
  5445. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5446. if (!quest) {
  5447. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5448. lua_interface->SetBooleanValue(state, false);
  5449. return 1;
  5450. }
  5451. if (!spawn) {
  5452. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5453. lua_interface->SetBooleanValue(state, false);
  5454. return 1;
  5455. }
  5456. if (!spawn->IsPlayer()) {
  5457. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5458. lua_interface->SetBooleanValue(state, false);
  5459. return 1;
  5460. }
  5461. if (item_id == 0) {
  5462. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5463. lua_interface->SetBooleanValue(state, false);
  5464. return 1;
  5465. }
  5466. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5467. if (!client) {
  5468. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5469. lua_interface->SetBooleanValue(state, false);
  5470. return 1;
  5471. }
  5472. Item* item = master_item_list.GetItem(item_id);
  5473. if (!item) {
  5474. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5475. lua_interface->SetBooleanValue(state, false);
  5476. return 1;
  5477. }
  5478. Item* firstItem = new Item(item);
  5479. quest->AddTmpRewardItem(firstItem);
  5480. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5481. bool itemsAddedSuccessfully = true;
  5482. if(num_args > 4)
  5483. {
  5484. for(int8 n=5;n<num_args+1;n++)
  5485. {
  5486. int32 new_item = lua_interface->GetInt32Value(state, n);
  5487. Item* tmpItem = master_item_list.GetItem(new_item);
  5488. if(tmpItem)
  5489. {
  5490. Item* newTmpItem = new Item(tmpItem);
  5491. quest->AddTmpRewardItem(newTmpItem);
  5492. }
  5493. else
  5494. itemsAddedSuccessfully = false;
  5495. }
  5496. }
  5497. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5498. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5499. return 1;
  5500. }
  5501. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5502. if (!lua_interface)
  5503. return 0;
  5504. Quest* quest = lua_interface->GetQuest(state);
  5505. if (!quest) {
  5506. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5507. return 0;
  5508. }
  5509. quest->SetRepeatable(true);
  5510. return 0;
  5511. }
  5512. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5513. if (!lua_interface)
  5514. return 0;
  5515. Spawn* spawn = lua_interface->GetSpawn(state);
  5516. if (!spawn) {
  5517. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5518. return 0;
  5519. }
  5520. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5521. string ret = classes.GetClassNameCase(base_class);
  5522. if (ret.length() > 0) {
  5523. lua_interface->SetStringValue(state, ret.c_str());
  5524. return 1;
  5525. }
  5526. return 0;
  5527. }
  5528. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5529. if (!lua_interface)
  5530. return 0;
  5531. Spawn* player = lua_interface->GetSpawn(state);
  5532. if (player && player->IsPlayer()) {
  5533. Client* client = player->GetClient();
  5534. if (client)
  5535. client->SendWaypoints();
  5536. }
  5537. return 0;
  5538. }
  5539. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5540. if (!lua_interface)
  5541. return 0;
  5542. Spawn* player = lua_interface->GetSpawn(state);
  5543. string name = lua_interface->GetStringValue(state, 2);
  5544. int32 type = lua_interface->GetInt32Value(state, 3);
  5545. if (type == 0)
  5546. type = 2;
  5547. if (name.length() > 0) {
  5548. if (player && player->IsPlayer()) {
  5549. Client* client = player->GetClient();
  5550. if (client)
  5551. client->AddWaypoint(name, type);
  5552. }
  5553. }
  5554. return 0;
  5555. }
  5556. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5557. if (!lua_interface)
  5558. return 0;
  5559. Spawn* player = lua_interface->GetSpawn(state);
  5560. string name = lua_interface->GetStringValue(state, 2);
  5561. if (name.length() > 0) {
  5562. if (player && player->IsPlayer()) {
  5563. Client* client = player->GetClient();
  5564. if (client)
  5565. client->RemoveWaypoint(name);
  5566. }
  5567. }
  5568. return 0;
  5569. }
  5570. int EQ2Emu_lua_AddWard(lua_State* state) {
  5571. if (!lua_interface)
  5572. return 0;
  5573. int32 damage = lua_interface->GetInt32Value(state);
  5574. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5575. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5576. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5577. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5578. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5579. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5580. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5581. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5582. if(!spell || spell->resisted) {
  5583. return 0;
  5584. }
  5585. bool ward_was_added = false;
  5586. ZoneServer* zone = spell->caster->GetZone();
  5587. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5588. for (int32 i = 0; i < spell->targets.size(); i++) {
  5589. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5590. if (!target)
  5591. continue;
  5592. if (target->IsEntity()) {
  5593. // If the ward is already active remove it
  5594. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5595. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5596. // Create new ward info
  5597. WardInfo* ward = new WardInfo;
  5598. ward->Spell = spell;
  5599. ward->BaseDamage = damage;
  5600. ward->DamageLeft = damage;
  5601. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5602. ward->keepWard = keepWard;
  5603. ward->WardType = wardType;
  5604. if (damageAbsorptionPercent > 100)
  5605. damageAbsorptionPercent = 100;
  5606. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5607. if (damageAbsorptionMaxHealthPercent > 100)
  5608. damageAbsorptionMaxHealthPercent = 100;
  5609. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5610. ward->RedirectDamagePercent = redirectDamagePercent;
  5611. ward->LastRedirectDamage = 0;
  5612. ward->LastAbsorbedDamage = 0;
  5613. ward->HitCount = 0;
  5614. spell->num_triggers = maxHitCount;
  5615. spell->had_triggers = true;
  5616. spell->cancel_after_all_triggers = false;
  5617. ward->MaxHitCount = maxHitCount;
  5618. if (wardType == WARD_TYPE_MAGICAL)
  5619. ward->DamageType = damageTypes;
  5620. // Add the ward to the entity
  5621. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5622. ward_was_added = true;
  5623. }
  5624. }
  5625. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5626. if (ward_was_added && spell->caster->IsPlayer()) {
  5627. spell->had_dmg_remaining = true;
  5628. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5629. }
  5630. return 0;
  5631. }
  5632. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5633. if (!lua_interface)
  5634. return 0;
  5635. int32 amount = lua_interface->GetInt32Value(state);
  5636. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5637. WardInfo* ward = 0;
  5638. if(!spell || spell->resisted) {
  5639. return 0;
  5640. }
  5641. ZoneServer* zone = spell->caster->GetZone();
  5642. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5643. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5644. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5645. ward = target->GetWard(spell->spell->GetSpellID());
  5646. if (target && ward) {
  5647. ward->DamageLeft += amount;
  5648. if (ward->DamageLeft > ward->BaseDamage)
  5649. ward->DamageLeft = ward->BaseDamage;
  5650. for (int32 i = 0; i < spell->targets.size(); i++) {
  5651. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5652. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5653. }
  5654. }
  5655. }
  5656. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5657. if (ward && spell->caster->IsPlayer())
  5658. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5659. return 0;
  5660. }
  5661. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5662. if (!lua_interface)
  5663. return 0;
  5664. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5665. if (!spell) {
  5666. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5667. return 0;
  5668. }
  5669. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5670. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5671. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5672. if (ward) {
  5673. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5674. return 1;
  5675. }
  5676. }
  5677. return 0;
  5678. }
  5679. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5680. if (!lua_interface)
  5681. return 0;
  5682. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5683. if (!spell) {
  5684. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5685. return 0;
  5686. }
  5687. string type = lua_interface->GetStringValue(state, 2);
  5688. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5689. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5690. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5691. if (ward) {
  5692. if (boost::iequals(type, "damageleft"))
  5693. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5694. else if (boost::iequals(type, "basedamage"))
  5695. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5696. else if (boost::iequals(type, "keepward"))
  5697. lua_interface->SetBooleanValue(state, ward->keepWard);
  5698. else if (boost::iequals(type, "wardtype"))
  5699. lua_interface->SetInt32Value(state, ward->WardType);
  5700. else if (boost::iequals(type, "dmgabsorptionpct"))
  5701. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5702. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5703. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5704. else if (boost::iequals(type, "redirectdamagepercent"))
  5705. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5706. else if (boost::iequals(type, "lastredirectdamage"))
  5707. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5708. else if (boost::iequals(type, "lastabsorbeddamage"))
  5709. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5710. else if (boost::iequals(type, "hitcount"))
  5711. lua_interface->SetInt32Value(state, ward->HitCount);
  5712. else if (boost::iequals(type, "maxhitcount"))
  5713. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5714. else
  5715. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5716. return 1;
  5717. }
  5718. }
  5719. return 0;
  5720. }
  5721. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5722. if (!lua_interface)
  5723. return 0;
  5724. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5725. if(!spell) {
  5726. return 0;
  5727. }
  5728. ZoneServer* zone = spell->caster->GetZone();
  5729. Spawn* target = 0;
  5730. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5731. for (int32 i = 0; i < spell->targets.size(); i++) {
  5732. target = zone->GetSpawnByID(spell->targets.at(i));
  5733. if (target && target->IsEntity()) {
  5734. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5735. }
  5736. }
  5737. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5738. return 0;
  5739. }
  5740. int EQ2Emu_lua_Interrupt(lua_State* state)
  5741. {
  5742. if (!lua_interface)
  5743. return 0;
  5744. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5745. Spawn* target = lua_interface->GetSpawn(state, 2);
  5746. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5747. if (!caster)
  5748. {
  5749. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5750. return 0;
  5751. }
  5752. if (!target)
  5753. {
  5754. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5755. return 0;
  5756. }
  5757. if (!spell) {
  5758. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5759. return 0;
  5760. }
  5761. if (!target->IsEntity() && !spell)
  5762. {
  5763. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5764. return 0;
  5765. }
  5766. if (!target && spell) {
  5767. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5768. for (int8 i = 0; i < spell->targets.size(); i++) {
  5769. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5770. if (!target || !target->IsEntity())
  5771. continue;
  5772. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5773. }
  5774. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5775. }
  5776. else
  5777. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5778. return 0;
  5779. }
  5780. int EQ2Emu_lua_Stealth(lua_State* state) {
  5781. if (!lua_interface)
  5782. return 0;
  5783. int8 type = lua_interface->GetInt8Value(state);
  5784. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5785. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5786. if (!spell) {
  5787. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5788. return 0;
  5789. }
  5790. ZoneServer* zone = spell->caster->GetZone();
  5791. if (spawn) {
  5792. if (spawn->IsEntity()) {
  5793. if (type == 1) {
  5794. ((Entity*)spawn)->AddStealthSpell(spell);
  5795. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5796. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5797. }
  5798. else if (type == 2) {
  5799. ((Entity*)spawn)->AddInvisSpell(spell);
  5800. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5801. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5802. }
  5803. return 0;
  5804. }
  5805. else {
  5806. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5807. return 0;
  5808. }
  5809. }
  5810. else {
  5811. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5812. for (int32 i = 0; i < spell->targets.size(); i++) {
  5813. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5814. if (!spawn || !spawn->IsEntity())
  5815. continue;
  5816. if (type == 1) {
  5817. ((Entity*)spawn)->AddStealthSpell(spell);
  5818. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5819. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5820. }
  5821. else if (type == 2) {
  5822. ((Entity*)spawn)->AddInvisSpell(spell);
  5823. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5824. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5825. }
  5826. else {
  5827. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5828. break;
  5829. }
  5830. }
  5831. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5832. }
  5833. return 0;
  5834. }
  5835. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5836. if (!lua_interface)
  5837. return 0;
  5838. Spawn* spawn = lua_interface->GetSpawn(state);
  5839. if (!spawn) {
  5840. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5841. return 0;
  5842. }
  5843. if (spawn->IsEntity()) {
  5844. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5845. return 1;
  5846. }
  5847. else
  5848. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5849. return 0;
  5850. }
  5851. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5852. if (!lua_interface)
  5853. return 0;
  5854. Spawn* spawn = lua_interface->GetSpawn(state);
  5855. if (!spawn) {
  5856. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5857. return 0;
  5858. }
  5859. if (spawn->IsEntity()) {
  5860. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5861. return 1;
  5862. }
  5863. else
  5864. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5865. return 0;
  5866. }
  5867. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5868. if (!lua_interface)
  5869. return 0;
  5870. Spawn* player = lua_interface->GetSpawn(state);
  5871. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5872. lua_interface->ResetFunctionStack(state);
  5873. if (!player->IsPlayer()) {
  5874. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5875. return 0;
  5876. }
  5877. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5878. return 1;
  5879. }
  5880. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5881. if (!lua_interface)
  5882. return 0;
  5883. Spawn* player = lua_interface->GetSpawn(state);
  5884. int8 slot = lua_interface->GetInt8Value(state, 2);
  5885. lua_interface->ResetFunctionStack(state);
  5886. if (!player) {
  5887. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5888. return 0;
  5889. }
  5890. if (!player->IsPlayer()) {
  5891. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5892. return 0;
  5893. }
  5894. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5895. if (!item) {
  5896. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5897. return 0;
  5898. }
  5899. lua_interface->SetItemValue(state, item);
  5900. return 1;
  5901. }
  5902. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5903. if (!lua_interface)
  5904. return 0;
  5905. Spawn* player = lua_interface->GetSpawn(state);
  5906. int32 id = lua_interface->GetInt32Value(state, 2);
  5907. lua_interface->ResetFunctionStack(state);
  5908. if (!player) {
  5909. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5910. return 0;
  5911. }
  5912. if (!player->IsPlayer()) {
  5913. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5914. return 0;
  5915. }
  5916. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5917. if (!item) {
  5918. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5919. return 0;
  5920. }
  5921. lua_interface->SetItemValue(state, item);
  5922. return 1;
  5923. }
  5924. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5925. if (!lua_interface)
  5926. return 0;
  5927. Spawn* spawn = lua_interface->GetSpawn(state);
  5928. int8 slot = lua_interface->GetInt8Value(state, 2);
  5929. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5930. lua_interface->ResetFunctionStack(state);
  5931. if (!spawn) {
  5932. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5933. return 0;
  5934. }
  5935. if (!spawn->IsEntity()) {
  5936. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5937. return 0;
  5938. }
  5939. Item* item = master_item_list.GetItem(item_id);
  5940. if (!item) {
  5941. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5942. return 0;
  5943. }
  5944. Item* copy = new Item(item);
  5945. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5946. if(result)
  5947. {
  5948. ((Entity*)spawn)->SetEquipment(copy, slot);
  5949. spawn->vis_changed = true;
  5950. if(spawn->IsPlayer())
  5951. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5952. }
  5953. else
  5954. {
  5955. safe_delete(copy);
  5956. }
  5957. lua_interface->SetBooleanValue(state, result);
  5958. return 1;
  5959. }
  5960. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5961. if (!lua_interface)
  5962. return 0;
  5963. Spawn* spawn = lua_interface->GetSpawn(state);
  5964. int8 slot = lua_interface->GetInt8Value(state, 2);
  5965. Item* item = lua_interface->GetItem(state, 3);
  5966. lua_interface->ResetFunctionStack(state);
  5967. if (!spawn) {
  5968. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5969. return 0;
  5970. }
  5971. if (!spawn->IsEntity()) {
  5972. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5973. return 0;
  5974. }
  5975. if (!item) {
  5976. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5977. return 0;
  5978. }
  5979. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5980. if(result)
  5981. {
  5982. ((Entity*)spawn)->SetEquipment(item, slot);
  5983. spawn->vis_changed = true;
  5984. if(spawn->IsPlayer())
  5985. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5986. }
  5987. lua_interface->SetBooleanValue(state, result);
  5988. return 1;
  5989. }
  5990. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5991. if (!lua_interface)
  5992. return 0;
  5993. Spawn* spawn = lua_interface->GetSpawn(state);
  5994. int8 slot = lua_interface->GetInt8Value(state, 2);
  5995. 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
  5996. lua_interface->ResetFunctionStack(state);
  5997. if (!spawn) {
  5998. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. if (!spawn->IsEntity()) {
  6002. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6003. return 0;
  6004. }
  6005. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6006. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6007. spawn->vis_changed = true;
  6008. if(spawn->IsPlayer())
  6009. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6010. lua_interface->SetBooleanValue(state, true);
  6011. return 1;
  6012. }
  6013. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6014. if (!lua_interface)
  6015. return 0;
  6016. Spawn* spawn = lua_interface->GetSpawn(state);
  6017. int8 slot = lua_interface->GetInt8Value(state, 2);
  6018. int16 type = lua_interface->GetInt16Value(state, 3);
  6019. int8 r = lua_interface->GetInt8Value(state, 4);
  6020. int8 g = lua_interface->GetInt8Value(state, 5);
  6021. int8 b = lua_interface->GetInt8Value(state, 6);
  6022. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6023. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6024. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6025. lua_interface->ResetFunctionStack(state);
  6026. if (!spawn) {
  6027. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6028. return 0;
  6029. }
  6030. if (!spawn->IsEntity()) {
  6031. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6032. return 0;
  6033. }
  6034. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6035. spawn->vis_changed = true;
  6036. lua_interface->SetBooleanValue(state, true);
  6037. return 1;
  6038. }
  6039. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6040. if (!lua_interface)
  6041. return 0;
  6042. Spawn* player = lua_interface->GetSpawn(state);
  6043. int32 id = lua_interface->GetInt32Value(state, 2);
  6044. int8 count = lua_interface->GetInt8Value(state, 3);
  6045. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6046. lua_interface->ResetFunctionStack(state);
  6047. if (!player) {
  6048. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6049. return 0;
  6050. }
  6051. if (!player->IsPlayer()) {
  6052. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6053. return 0;
  6054. }
  6055. if (!count)
  6056. count = 1;
  6057. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6058. if (!item) {
  6059. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6060. return 0;
  6061. }
  6062. lua_interface->SetItemValue(state, item);
  6063. return 1;
  6064. }
  6065. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6066. if (!lua_interface)
  6067. return 0;
  6068. Spawn* spawn = lua_interface->GetSpawn(state);
  6069. int32 anim = lua_interface->GetInt32Value(state, 2);
  6070. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6071. int8 type = lua_interface->GetInt8Value(state, 4);
  6072. if (!spawn) {
  6073. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6074. return 0;
  6075. }
  6076. if (spawn2) {
  6077. if (spawn2->IsPlayer()) {
  6078. if (type != 1 && type != 2)
  6079. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6080. else
  6081. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6082. return 0;
  6083. }
  6084. else {
  6085. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6086. return 0;
  6087. }
  6088. }
  6089. else
  6090. spawn->GetZone()->PlayAnimation(spawn, anim);
  6091. return 0;
  6092. }
  6093. int EQ2Emu_lua_IsPet(lua_State* state) {
  6094. if (!lua_interface)
  6095. return 0;
  6096. Spawn* spawn = lua_interface->GetSpawn(state);
  6097. if (!spawn) {
  6098. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6099. return 0;
  6100. }
  6101. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6102. return 1;
  6103. }
  6104. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6105. if (!lua_interface)
  6106. return 0;
  6107. Spawn* spawn = lua_interface->GetSpawn(state);
  6108. if (!spawn) {
  6109. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6110. return 0;
  6111. }
  6112. if (!spawn->IsNPC()) {
  6113. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6114. return 0;
  6115. }
  6116. if (((NPC*)spawn)->GetOwner()) {
  6117. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6118. return 1;
  6119. }
  6120. return 0;
  6121. }
  6122. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6123. if (!lua_interface)
  6124. return 0;
  6125. Spawn* spawn = lua_interface->GetSpawn(state);
  6126. Spawn* target = lua_interface->GetSpawn(state, 2);
  6127. if (!spawn) {
  6128. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6129. return 0;
  6130. }
  6131. if (!spawn) {
  6132. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6133. return 0;
  6134. }
  6135. spawn->SetTarget(target);
  6136. return 0;
  6137. }
  6138. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6139. if (!lua_interface)
  6140. return 0;
  6141. Spawn* spawn = lua_interface->GetSpawn(state);
  6142. bool val = lua_interface->GetBooleanValue(state, 2);
  6143. if (!spawn) {
  6144. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6145. return 0;
  6146. }
  6147. if (!spawn->IsEntity()) {
  6148. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6149. return 0;
  6150. }
  6151. ((Entity*)spawn)->InCombat(val);
  6152. if (val) {
  6153. spawn->ClearRunningLocations();
  6154. spawn->CalculateRunningLocation(true);
  6155. }
  6156. return 0;
  6157. }
  6158. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6159. if (!lua_interface)
  6160. return 0;
  6161. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6162. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6163. if (!spawn1) {
  6164. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6165. return 0;
  6166. }
  6167. if (!spawn2) {
  6168. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6169. return 0;
  6170. }
  6171. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6172. return 1;
  6173. }
  6174. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6175. if (!lua_interface)
  6176. return 0;
  6177. Spawn* spawn = lua_interface->GetSpawn(state);
  6178. if (!spawn) {
  6179. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6180. return 0;
  6181. }
  6182. if (!spawn->IsNPC()) {
  6183. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6184. return 0;
  6185. }
  6186. ((NPC*)spawn)->ClearRunback();
  6187. return 0;
  6188. }
  6189. int EQ2Emu_lua_Runback(lua_State* state) {
  6190. if (!lua_interface)
  6191. return 0;
  6192. Spawn* spawn = lua_interface->GetSpawn(state);
  6193. if (!spawn) {
  6194. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6195. return 0;
  6196. }
  6197. if (!spawn->IsNPC()) {
  6198. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6199. return 0;
  6200. }
  6201. ((NPC*)spawn)->Runback();
  6202. return 0;
  6203. }
  6204. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6205. if (!lua_interface)
  6206. return 0;
  6207. Spawn* spawn = lua_interface->GetSpawn(state);
  6208. if (!spawn) {
  6209. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6210. return 0;
  6211. }
  6212. if (!spawn->IsNPC()) {
  6213. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6214. return 0;
  6215. }
  6216. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6217. return 1;
  6218. }
  6219. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6220. if (!lua_interface)
  6221. return 0;
  6222. Spawn* spawn = lua_interface->GetSpawn(state);
  6223. if (!spawn) {
  6224. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6225. return 0;
  6226. }
  6227. if (!spawn->IsEntity()) {
  6228. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6229. return 0;
  6230. }
  6231. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6232. return 1;
  6233. }
  6234. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6235. if (!lua_interface)
  6236. return 0;
  6237. Spawn* spawn = lua_interface->GetSpawn(state);
  6238. if (!spawn) {
  6239. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6240. return 0;
  6241. }
  6242. if (!spawn->IsEntity()) {
  6243. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6244. return 0;
  6245. }
  6246. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6247. return 1;
  6248. }
  6249. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6250. if (!lua_interface)
  6251. return 0;
  6252. Spawn* spawn = lua_interface->GetSpawn(state);
  6253. if (!spawn) {
  6254. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6255. return 0;
  6256. }
  6257. if (!spawn->IsEntity()) {
  6258. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6259. return 0;
  6260. }
  6261. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6262. return 1;
  6263. }
  6264. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6265. if (!lua_interface)
  6266. return 0;
  6267. Spawn* spawn = lua_interface->GetSpawn(state);
  6268. if (!spawn) {
  6269. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. if (!spawn->IsEntity()) {
  6273. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6274. return 0;
  6275. }
  6276. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6277. return 1;
  6278. }
  6279. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6280. if (!lua_interface)
  6281. return 0;
  6282. Spawn* spawn = lua_interface->GetSpawn(state);
  6283. Spawn* target = lua_interface->GetSpawn(state, 2);
  6284. float distance = lua_interface->GetFloatValue(state, 3);
  6285. if (!spawn) {
  6286. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6287. return 0;
  6288. }
  6289. if (!target) {
  6290. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. if (!spawn->IsNPC()) {
  6294. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6295. return 0;
  6296. }
  6297. if (!target->IsEntity()) {
  6298. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6299. return 0;
  6300. }
  6301. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6302. return 1;
  6303. }
  6304. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6305. if (!lua_interface)
  6306. return 0;
  6307. Spawn* spawn = lua_interface->GetSpawn(state);
  6308. Spawn* target = lua_interface->GetSpawn(state, 2);
  6309. float distance = lua_interface->GetFloatValue(state, 3);
  6310. if (!spawn) {
  6311. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6312. return 0;
  6313. }
  6314. if (!target) {
  6315. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6316. return 0;
  6317. }
  6318. if (!spawn->IsNPC()) {
  6319. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6320. return 0;
  6321. }
  6322. if (!target->IsEntity()) {
  6323. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6324. return 0;
  6325. }
  6326. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6327. return 0;
  6328. }
  6329. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6330. if (!lua_interface)
  6331. return 0;
  6332. Spawn* spawn = lua_interface->GetSpawn(state);
  6333. if (!spawn) {
  6334. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6335. return 0;
  6336. }
  6337. if (!spawn->IsNPC()) {
  6338. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6339. return 0;
  6340. }
  6341. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6342. return 1;
  6343. }
  6344. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6345. if (!lua_interface)
  6346. return 0;
  6347. Spawn* spawn = lua_interface->GetSpawn(state);
  6348. if (!spawn) {
  6349. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6350. return 0;
  6351. }
  6352. if (!spawn->IsNPC()) {
  6353. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6354. return 0;
  6355. }
  6356. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6357. return 1;
  6358. }
  6359. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6360. if (!lua_interface)
  6361. return 0;
  6362. Spawn* spawn = lua_interface->GetSpawn(state);
  6363. if (!spawn) {
  6364. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6365. return 0;
  6366. }
  6367. if (!spawn->IsNPC()) {
  6368. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6369. return 0;
  6370. }
  6371. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6372. if (hated) {
  6373. lua_interface->SetSpawnValue(state, hated);
  6374. return 1;
  6375. }
  6376. return 0;
  6377. }
  6378. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6379. if (!lua_interface)
  6380. return 0;
  6381. Spawn* spawn = lua_interface->GetSpawn(state);
  6382. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6383. if (!spawn) {
  6384. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6385. return 0;
  6386. }
  6387. if (!spawn->IsNPC()) {
  6388. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6389. return 0;
  6390. }
  6391. if (!hated) {
  6392. ((NPC*)spawn)->Brain()->ClearHate();
  6393. return 0;
  6394. }
  6395. else
  6396. {
  6397. if (!hated->IsEntity()) {
  6398. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6399. return 0;
  6400. }
  6401. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6402. return 0;
  6403. }
  6404. return 0;
  6405. }
  6406. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6407. if (!lua_interface)
  6408. return 0;
  6409. Spawn* spawn = lua_interface->GetSpawn(state);
  6410. if (!spawn) {
  6411. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6412. return 0;
  6413. }
  6414. if (!spawn->IsNPC()) {
  6415. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6416. return 0;
  6417. }
  6418. ((NPC*)spawn)->Brain()->ClearEncounter();
  6419. return 0;
  6420. }
  6421. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6422. if (!lua_interface)
  6423. return 0;
  6424. Spawn* spawn = lua_interface->GetSpawn(state);
  6425. if (!spawn) {
  6426. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6427. return 0;
  6428. }
  6429. if (!spawn->IsNPC()) {
  6430. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6431. return 0;
  6432. }
  6433. // Temp list to store hate list
  6434. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6435. if (encounterList->size() == 0) {
  6436. safe_delete(encounterList);
  6437. return 0;
  6438. }
  6439. lua_createtable(state, encounterList->size(), 0);
  6440. int newTable = lua_gettop(state);
  6441. for (int32 i = 0; i < encounterList->size(); i++) {
  6442. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6443. if (temp)
  6444. lua_interface->SetSpawnValue(state, temp);
  6445. lua_rawseti(state, newTable, i + 1);
  6446. }
  6447. safe_delete(encounterList);
  6448. return 1;
  6449. }
  6450. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6451. if (!lua_interface)
  6452. return 0;
  6453. Spawn* spawn = lua_interface->GetSpawn(state);
  6454. if (!spawn) {
  6455. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6456. return 0;
  6457. }
  6458. if (!spawn->IsNPC()) {
  6459. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6460. return 0;
  6461. }
  6462. // Temp list to store hate list
  6463. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6464. if (hateList->size() == 0) {
  6465. safe_delete(hateList);
  6466. return 0;
  6467. }
  6468. lua_createtable(state, hateList->size(), 0);
  6469. int newTable = lua_gettop(state);
  6470. for (int32 i = 0; i < hateList->size(); i++) {
  6471. lua_interface->SetSpawnValue(state, hateList->at(i));
  6472. lua_rawseti(state, newTable, i + 1);
  6473. }
  6474. safe_delete(hateList);
  6475. return 1;
  6476. }
  6477. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6478. if (!lua_interface)
  6479. return 0;
  6480. Spawn* spawn = lua_interface->GetSpawn(state);
  6481. if (!spawn) {
  6482. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6483. return 0;
  6484. }
  6485. if (spawn->IsPlayer()) {
  6486. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6487. lua_interface->SetBooleanValue(state, true);
  6488. else
  6489. lua_interface->SetBooleanValue(state, false);
  6490. return 1;
  6491. }
  6492. else {
  6493. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6494. return 1;
  6495. }
  6496. }
  6497. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6498. if (!lua_interface)
  6499. return 0;
  6500. Quest* quest = lua_interface->GetQuest(state);
  6501. if (!quest) {
  6502. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6503. return 0;
  6504. }
  6505. quest->SetCompletedFlag(true);
  6506. return 0;
  6507. }
  6508. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6509. if (!lua_interface)
  6510. return 0;
  6511. Spawn* spawn = lua_interface->GetSpawn(state);
  6512. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6513. int8 tier = lua_interface->GetInt8Value(state, 3);
  6514. if (!spawn) {
  6515. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6516. return 0;
  6517. }
  6518. if (!spawn->IsEntity()) {
  6519. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6520. return 0;
  6521. }
  6522. if (spellID == 0) {
  6523. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6524. return 0;
  6525. }
  6526. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6527. if (effect) {
  6528. if (tier > 0) {
  6529. // If a tier was passed chec to see if it is the same as the effect
  6530. if (tier == effect->tier)
  6531. lua_interface->SetBooleanValue(state, true);
  6532. else
  6533. lua_interface->SetBooleanValue(state, false);
  6534. return 1;
  6535. }
  6536. else {
  6537. // Have an effect but no tier was passed so return true
  6538. lua_interface->SetBooleanValue(state, true);
  6539. }
  6540. return 1;
  6541. }
  6542. // no effect so return false
  6543. lua_interface->SetBooleanValue(state, false);
  6544. return 1;
  6545. }
  6546. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6547. if (!lua_interface)
  6548. return 0;
  6549. Spawn* spawn = lua_interface->GetSpawn(state);
  6550. int32 id = lua_interface->GetInt32Value(state, 2);
  6551. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6552. Spawn* spawn2 = 0;
  6553. vector<Spawn*> list;
  6554. if (!spawn) {
  6555. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6556. return 0;
  6557. }
  6558. //If zone not provided, use spawn's zone
  6559. if (!zone)
  6560. zone = spawn->GetZone();
  6561. list = zone->GetSpawnsByID(id);
  6562. if (list.size() == 0) {
  6563. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6564. return 0;
  6565. }
  6566. vector<Spawn*>::iterator itr = list.begin();
  6567. for (int8 i = 0; i < list.size(); i++) {
  6568. spawn2 = itr[i];
  6569. if (spawn2)
  6570. spawn2->AddAllowAccessSpawn(spawn);
  6571. }
  6572. return 0;
  6573. }
  6574. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6575. if (!lua_interface)
  6576. return 0;
  6577. Spawn* spawn = lua_interface->GetSpawn(state);
  6578. int32 id = lua_interface->GetInt32Value(state, 2);
  6579. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6580. Spawn* spawn2 = 0;
  6581. if (!spawn) {
  6582. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6583. return 0;
  6584. }
  6585. //If zone not provided, use spawn's zone
  6586. if (!zone)
  6587. zone = spawn->GetZone();
  6588. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6589. vector<Spawn*>::iterator itr = list.begin();
  6590. if (list.size() == 0) {
  6591. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6592. return 0;
  6593. }
  6594. for (int8 i = 0; i < list.size(); i++) {
  6595. spawn2 = itr[i];
  6596. if (spawn2)
  6597. spawn2->RemoveSpawnAccess(spawn);
  6598. }
  6599. return 0;
  6600. }
  6601. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6602. if (!lua_interface)
  6603. return 0;
  6604. Quest* quest = lua_interface->GetQuest(state);
  6605. if (!quest) {
  6606. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6607. return 0;
  6608. }
  6609. quest->SetYellowName(true);
  6610. return 0;
  6611. }
  6612. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6613. if (!lua_interface)
  6614. return 0;
  6615. Spawn* spawn = lua_interface->GetSpawn(state);
  6616. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6617. if (!spawn) {
  6618. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6619. return 0;
  6620. }
  6621. if (!spawn->IsPlayer()) {
  6622. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6623. return 0;
  6624. }
  6625. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6626. return 1;
  6627. }
  6628. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6629. if (!lua_interface)
  6630. return 0;
  6631. Spawn* spawn = lua_interface->GetSpawn(state);
  6632. if (!spawn) {
  6633. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6634. return 0;
  6635. }
  6636. if (!spawn->IsPlayer()) {
  6637. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6638. return 0;
  6639. }
  6640. ZoneServer* zone = spawn->GetZone();
  6641. if (!zone) {
  6642. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6643. return 0;
  6644. }
  6645. Instance_Type iType = zone->GetInstanceType();
  6646. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6647. iType == GROUP_LOCKOUT_INSTANCE ||
  6648. iType == RAID_LOCKOUT_INSTANCE ||
  6649. iType == SOLO_PERSIST_INSTANCE ||
  6650. iType == GROUP_PERSIST_INSTANCE ||
  6651. iType == RAID_PERSIST_INSTANCE) {
  6652. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6653. if (data) {
  6654. // Check to see if the timer has already been set, if it has return out.
  6655. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6656. return 0;
  6657. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6658. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6659. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6660. if (client) {
  6661. string time_msg = "";
  6662. int32 time = data->success_lockout_time;
  6663. int16 hour;
  6664. int8 min;
  6665. int8 sec;
  6666. hour = time / 3600;
  6667. time = time % 3600;
  6668. min = time / 60;
  6669. time = time % 60;
  6670. sec = time;
  6671. if (hour > 0) {
  6672. char temp[10];
  6673. sprintf(temp, " %i", hour);
  6674. time_msg.append(temp);
  6675. time_msg.append(" hour");
  6676. time_msg.append((hour > 1) ? "s" : "");
  6677. }
  6678. if (min > 0) {
  6679. char temp[5];
  6680. sprintf(temp, " %i", min);
  6681. time_msg.append(temp);
  6682. time_msg.append(" minute");
  6683. time_msg.append((min > 1) ? "s" : "");
  6684. }
  6685. // Only add seconds if minutes and hours are 0
  6686. if (hour == 0 && min == 0 && sec > 0) {
  6687. char temp[5];
  6688. sprintf(temp, " %i", sec);
  6689. time_msg.append(temp);
  6690. time_msg.append(" second");
  6691. time_msg.append((sec > 1) ? "s" : "");
  6692. }
  6693. 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());
  6694. }
  6695. }
  6696. else
  6697. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6698. }
  6699. else
  6700. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6701. return 0;
  6702. }
  6703. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6704. if (!lua_interface)
  6705. return 0;
  6706. Spawn* spawn = lua_interface->GetSpawn(state);
  6707. if (!spawn) {
  6708. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6709. return 0;
  6710. }
  6711. if (!spawn->IsPlayer()) {
  6712. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6713. return 0;
  6714. }
  6715. ZoneServer* zone = spawn->GetZone();
  6716. if (!zone) {
  6717. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6718. return 0;
  6719. }
  6720. Instance_Type iType = zone->GetInstanceType();
  6721. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6722. iType == GROUP_LOCKOUT_INSTANCE ||
  6723. iType == RAID_LOCKOUT_INSTANCE ||
  6724. iType == SOLO_PERSIST_INSTANCE ||
  6725. iType == GROUP_PERSIST_INSTANCE ||
  6726. iType == RAID_PERSIST_INSTANCE) {
  6727. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6728. if (data) {
  6729. // Check to see if the timer has already been set, if it has return out.
  6730. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6731. return 0;
  6732. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6733. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6734. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6735. if (client) {
  6736. string time_msg = "";
  6737. int32 time = data->failure_lockout_time;
  6738. int16 hour;
  6739. int8 min;
  6740. int8 sec;
  6741. hour = time / 3600;
  6742. time = time % 3600;
  6743. min = time / 60;
  6744. time = time % 60;
  6745. sec = time;
  6746. if (hour > 0) {
  6747. char temp[10];
  6748. sprintf(temp, " %i", hour);
  6749. time_msg.append(temp);
  6750. time_msg.append(" hour");
  6751. time_msg.append((hour > 1) ? "s" : "");
  6752. }
  6753. if (min > 0) {
  6754. char temp[5];
  6755. sprintf(temp, " %i", min);
  6756. time_msg.append(temp);
  6757. time_msg.append(" minute");
  6758. time_msg.append((min > 1) ? "s" : "");
  6759. }
  6760. // Only add seconds if minutes and hours are 0
  6761. if (hour == 0 && min == 0 && sec > 0) {
  6762. char temp[5];
  6763. sprintf(temp, " %i", sec);
  6764. time_msg.append(temp);
  6765. time_msg.append(" second");
  6766. time_msg.append((sec > 1) ? "s" : "");
  6767. }
  6768. 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());
  6769. }
  6770. }
  6771. else
  6772. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6773. }
  6774. else
  6775. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6776. return 0;
  6777. }
  6778. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6779. if (!lua_interface)
  6780. return 0;
  6781. Spawn* spawn = lua_interface->GetSpawn(state);
  6782. if (!spawn) {
  6783. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6784. return 0;
  6785. }
  6786. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6787. return 1;
  6788. }
  6789. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6790. if (!lua_interface)
  6791. return 0;
  6792. Spawn* player = lua_interface->GetSpawn(state);
  6793. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6794. if (!player) {
  6795. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6796. return 0;
  6797. }
  6798. if (!player->IsPlayer()) {
  6799. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6800. return 0;
  6801. }
  6802. if (!ground) {
  6803. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6804. return 0;
  6805. }
  6806. if (!ground->IsGroundSpawn()) {
  6807. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6808. return 0;
  6809. }
  6810. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6811. if (!groundspawn_entries) {
  6812. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6813. return 0;
  6814. }
  6815. Skill* skill = 0;
  6816. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6817. if (collection_skill == "Collecting")
  6818. skill = ((Player*)player)->GetSkillByName("Gathering");
  6819. else
  6820. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6821. if (!skill) {
  6822. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6823. return 0;
  6824. }
  6825. vector<GroundSpawnEntry*>::iterator itr;
  6826. GroundSpawnEntry* entry = 0;
  6827. bool can_harvest = false;
  6828. sint32 min_skill = -1;
  6829. int16 totalSkill = skill->current_val;
  6830. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6831. if(skillID != 0xFFFFFFFF)
  6832. {
  6833. ((Entity*)player)->MStats.lock();
  6834. totalSkill += ((Entity*)player)->stats[skillID];
  6835. ((Entity*)player)->MStats.unlock();
  6836. }
  6837. // first, iterate through groundspawn_entries, discard tables player cannot use
  6838. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6839. {
  6840. entry = *itr;
  6841. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6842. min_skill = entry->min_skill_level;
  6843. // if player lacks skill, skip table
  6844. if (entry->min_skill_level > totalSkill)
  6845. continue;
  6846. // if bonus, but player lacks level, skip table
  6847. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6848. continue;
  6849. can_harvest = true;
  6850. break;
  6851. }
  6852. lua_interface->SetBooleanValue(state, can_harvest);
  6853. // If false, send the message to the client
  6854. if (!can_harvest) {
  6855. Client* client = player->GetZone()->GetClientBySpawn(player);
  6856. if (client) {
  6857. string msg = "You do not have enough skill to ";
  6858. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6859. msg.append("gather");
  6860. else if (collection_skill == "Mining")
  6861. msg.append("mine");
  6862. else if (collection_skill == "Trapping")
  6863. msg.append("trap");
  6864. else if (collection_skill == "Foresting")
  6865. msg.append("forest");
  6866. else if (collection_skill == "Fishing")
  6867. msg.append("catch");
  6868. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6869. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6870. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6871. }
  6872. }
  6873. return 1;
  6874. }
  6875. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6876. if (!lua_interface)
  6877. return 0;
  6878. Spawn* player = lua_interface->GetSpawn(state);
  6879. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6880. if (!player) {
  6881. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6882. return 0;
  6883. }
  6884. if (!player->IsPlayer()) {
  6885. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6886. return 0;
  6887. }
  6888. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6889. lua_interface->SetBooleanValue(state, ret);
  6890. return 1;
  6891. }
  6892. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6893. // Check to see if we have a valid lua_interface
  6894. if (!lua_interface)
  6895. return 0;
  6896. // Get the spawn that is getting the pet
  6897. Spawn* spawn = lua_interface->GetSpawn(state);
  6898. Spawn* target = lua_interface->GetSpawn(state, 2);
  6899. // Get the DB ID of the pet
  6900. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6901. float x = lua_interface->GetFloatValue(state, 4);
  6902. float y = lua_interface->GetFloatValue(state, 5);
  6903. float z = lua_interface->GetFloatValue(state, 6);
  6904. // Get the spell that this command was called from
  6905. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6906. // Check to make sure the spawn pointer is valid
  6907. if (!spawn) {
  6908. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6909. return 0;
  6910. }
  6911. // Check to make sure the spawn is an entity
  6912. if (!spawn->IsEntity()) {
  6913. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6914. return 0;
  6915. }
  6916. if (!target) {
  6917. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6918. return 0;
  6919. }
  6920. if (!target->IsEntity()) {
  6921. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6922. return 0;
  6923. }
  6924. // Check to see if the DB ID for the pet is set
  6925. if (pet_id == 0) {
  6926. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6927. return 0;
  6928. }
  6929. // Check to see if the pointer to the spell is valid
  6930. if (!luaspell) {
  6931. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6932. return 0;
  6933. }
  6934. if(luaspell->resisted) {
  6935. return 0;
  6936. }
  6937. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6938. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6939. if (!pet) {
  6940. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6941. return 0;
  6942. }
  6943. // Check to make sure the pet is an npc
  6944. if (!pet->IsNPC()) {
  6945. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6946. return 0;
  6947. }
  6948. if (x == 0)
  6949. x = spawn->GetX();
  6950. if (y == 0)
  6951. y = spawn->GetY();
  6952. if (z == 0)
  6953. z = spawn->GetZ();
  6954. // Spawn the pet at the same location as the owner
  6955. pet->SetX(x);
  6956. pet->SetY(y);
  6957. pet->SetZ(z);
  6958. pet->SetLocation(spawn->GetLocation());
  6959. pet->SetHeading(spawn->GetHeading());
  6960. spawn->GetZone()->AddSpawn(pet);
  6961. /*
  6962. const char* spawn_script = world.GetSpawnScript(pet_id);
  6963. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6964. spawn->SetSpawnScript(string(spawn_script));
  6965. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6966. }*/
  6967. // Get a random pet name
  6968. string random_pet_name;
  6969. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6970. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6971. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6972. // Set the pets name
  6973. pet->SetName(random_pet_name.c_str());
  6974. // Set the level of the pet to the owners level
  6975. pet->SetLevel(spawn->GetLevel());
  6976. // Set the faction of the pet to the same faction as the owner
  6977. pet->SetFactionID(spawn->GetFactionID());
  6978. // Set the spawn as a pet
  6979. pet->SetPet(true);
  6980. // Give a pointer of the owner to the pet
  6981. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6982. // Set the pet type
  6983. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6984. // Set the spell id used to create this pet
  6985. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6986. // Set the spell tier used to create this pet
  6987. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6988. // Set the pets spawn type to 6
  6989. pet->SetSpawnType(6);
  6990. // Set the pets brain
  6991. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6992. // Check to see if the pet has a subtitle
  6993. if (strlen(pet->GetSubTitle()) > 0) {
  6994. // Add the players name to the front of the sub title
  6995. string pet_subtitle;
  6996. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6997. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6998. // Set the pets subtitle to the new one
  6999. pet->SetSubTitle(pet_subtitle.c_str());
  7000. }
  7001. // Set the pet as the return value for this function
  7002. lua_interface->SetSpawnValue(state, pet);
  7003. return 1;
  7004. }
  7005. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7006. if (!lua_interface)
  7007. return 0;
  7008. Spawn* spawn = lua_interface->GetSpawn(state);
  7009. Spawn* player = lua_interface->GetSpawn(state, 2);
  7010. float max_distance = lua_interface->GetFloatValue(state, 3);
  7011. string type = lua_interface->GetStringValue(state, 4);
  7012. if (!spawn || (spawn && spawn->IsPlayer())) {
  7013. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7014. return 0;
  7015. }
  7016. if (!player || (player && !player->IsPlayer())) {
  7017. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7018. return 0;
  7019. }
  7020. Client* client = 0;
  7021. if (player->GetZone())
  7022. client = player->GetZone()->GetClientBySpawn(player);
  7023. if (!client) {
  7024. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7025. return 0;
  7026. }
  7027. //Set max_distance to default if not set or not proper value
  7028. if (max_distance <= 0)
  7029. max_distance = 500;
  7030. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7031. if (packet) {
  7032. float unknown2_3 = 0;
  7033. int8 placement_mode = 0;
  7034. if (type == "wall") {
  7035. placement_mode = 2;
  7036. unknown2_3 = 150;
  7037. }
  7038. else if (type == "ceiling")
  7039. placement_mode = 1;
  7040. packet->setDataByName("placement_mode", placement_mode);
  7041. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7042. packet->setDataByName("model_type", spawn->GetModelType());
  7043. packet->setDataByName("unknown", 1); //size
  7044. packet->setDataByName("unknown2", 1); //size 2
  7045. packet->setDataByName("unknown2", .5, 1); //size 3
  7046. packet->setDataByName("unknown2", 3, 2);
  7047. packet->setDataByName("unknown2", unknown2_3, 3);
  7048. packet->setDataByName("max_distance", max_distance);
  7049. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7050. client->QueuePacket(packet->serialize());
  7051. safe_delete(packet);
  7052. }
  7053. return 0;
  7054. }
  7055. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7056. if (!lua_interface)
  7057. return 0;
  7058. Item* item = lua_interface->GetItem(state);
  7059. if (!item) {
  7060. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7061. return 0;
  7062. }
  7063. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7064. return 1;
  7065. }
  7066. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7067. if (!lua_interface)
  7068. return 0;
  7069. Item* item = lua_interface->GetItem(state);
  7070. if (!item) {
  7071. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7072. return 0;
  7073. }
  7074. lua_interface->SetInt32Value(state, item->effect_type);
  7075. return 1;
  7076. }
  7077. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7078. if (!lua_interface)
  7079. return 0;
  7080. Spawn* spawn = lua_interface->GetSpawn(state);
  7081. if (!spawn) {
  7082. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7083. return 0;
  7084. }
  7085. if (spawn->GetZone())
  7086. spawn->GetZone()->AddTransportSpawn(spawn);
  7087. return 0;
  7088. }
  7089. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7090. if (!lua_interface)
  7091. return 0;
  7092. Spawn* spawn = lua_interface->GetSpawn(state);
  7093. if (!spawn) {
  7094. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7095. return 0;
  7096. }
  7097. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7098. return 1;
  7099. }
  7100. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7101. if (!lua_interface)
  7102. return 0;
  7103. Skill* skill = lua_interface->GetSkill(state);
  7104. if (!skill) {
  7105. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7106. return 0;
  7107. }
  7108. lua_interface->SetInt32Value(state, skill->current_val);
  7109. return 1;
  7110. }
  7111. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7112. if (!lua_interface)
  7113. return 0;
  7114. Skill* skill = lua_interface->GetSkill(state);
  7115. if (!skill) {
  7116. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7117. return 0;
  7118. }
  7119. lua_interface->SetInt32Value(state, skill->max_val);
  7120. return 1;
  7121. }
  7122. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7123. if (!lua_interface)
  7124. return 0;
  7125. Skill* skill = lua_interface->GetSkill(state);
  7126. if (!skill) {
  7127. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7128. return 0;
  7129. }
  7130. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7131. return 1;
  7132. }
  7133. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7134. if (!lua_interface)
  7135. return 0;
  7136. Skill* skill = lua_interface->GetSkill(state);
  7137. int16 value = lua_interface->GetInt16Value(state, 2);
  7138. if (!skill) {
  7139. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7140. return 0;
  7141. }
  7142. skill->max_val = value;
  7143. if (skill->max_val < skill->current_val)
  7144. skill->current_val = skill->max_val;
  7145. return 0;
  7146. }
  7147. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7148. if (!lua_interface)
  7149. return 0;
  7150. Skill* skill = lua_interface->GetSkill(state);
  7151. int16 value = lua_interface->GetInt16Value(state, 2);
  7152. if (!skill) {
  7153. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7154. return 0;
  7155. }
  7156. if (value > skill->max_val)
  7157. skill->current_val = skill->max_val;
  7158. else
  7159. skill->current_val = value;
  7160. return 0;
  7161. }
  7162. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7163. if (!lua_interface)
  7164. return 0;
  7165. Spawn* player = lua_interface->GetSpawn(state);
  7166. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7167. if (skill_id > 0 && player && player->IsPlayer()) {
  7168. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7169. return 1;
  7170. }
  7171. return 0;
  7172. }
  7173. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7174. if (!lua_interface)
  7175. return 0;
  7176. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7177. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7178. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7179. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7180. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7181. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7182. if (player_spawn && player_spawn->IsPlayer()) {
  7183. Player* player = (Player*)player_spawn;
  7184. bool added = false;
  7185. if (!player->skill_list.HasSkill(skill_id)) {
  7186. player->AddSkill(skill_id, current_val, max_val, true);
  7187. added = true;
  7188. }
  7189. 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
  7190. Client* client = player->GetClient();
  7191. if (client) {
  7192. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7193. if (packet)
  7194. client->QueuePacket(packet);
  7195. }
  7196. }
  7197. if (added) {
  7198. lua_interface->SetBooleanValue(state, true);
  7199. return 1;
  7200. }
  7201. }
  7202. else {
  7203. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7204. }
  7205. }
  7206. else {
  7207. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7208. }
  7209. lua_interface->SetBooleanValue(state, false);
  7210. return 1;
  7211. }
  7212. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7213. if (!lua_interface)
  7214. return 0;
  7215. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7216. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7217. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7218. if (skill_id > 0) {
  7219. if (player_spawn && player_spawn->IsPlayer()) {
  7220. Player* player = (Player*)player_spawn;
  7221. if (player->skill_list.HasSkill(skill_id)) {
  7222. player->RemovePlayerSkill(skill_id);
  7223. if (!more_to_remove) {
  7224. Client* client = player->GetClient();
  7225. if (client) {
  7226. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7227. if (packet)
  7228. client->QueuePacket(packet);
  7229. }
  7230. }
  7231. }
  7232. }
  7233. else {
  7234. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7235. }
  7236. }
  7237. else {
  7238. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7239. }
  7240. return 0;
  7241. }
  7242. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7243. if (!lua_interface)
  7244. return 0;
  7245. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7246. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7247. int16 amount = lua_interface->GetInt8Value(state, 3);
  7248. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7249. if (amount > 0 && skill_type < 100) {
  7250. if (player_spawn && player_spawn->IsPlayer()) {
  7251. Player* player = (Player*)player_spawn;
  7252. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7253. if (!more_to_increase) {
  7254. Client* client = player->GetClient();
  7255. if (client) {
  7256. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7257. if (packet)
  7258. client->QueuePacket(packet);
  7259. }
  7260. }
  7261. }
  7262. else {
  7263. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7264. }
  7265. }
  7266. else {
  7267. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7268. }
  7269. return 0;
  7270. }
  7271. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7272. if (!lua_interface)
  7273. return 0;
  7274. Spawn* spawn = lua_interface->GetSpawn(state);
  7275. string name = lua_interface->GetStringValue(state, 2);
  7276. if (!spawn) {
  7277. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7278. return 0;
  7279. }
  7280. if (!spawn->IsEntity()) {
  7281. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7282. return 0;
  7283. }
  7284. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7285. if (skill) {
  7286. lua_interface->SetSkillValue(state, skill);
  7287. return 1;
  7288. }
  7289. return 0;
  7290. }
  7291. int EQ2Emu_lua_AddProc(lua_State* state) {
  7292. if (!lua_interface)
  7293. return 0;
  7294. Spawn* spawn = lua_interface->GetSpawn(state);
  7295. int8 type = lua_interface->GetInt8Value(state, 2);
  7296. float chance = lua_interface->GetFloatValue(state, 3);
  7297. Item* item = lua_interface->GetItem(state, 4);
  7298. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7299. LuaSpell* spell = 0;
  7300. if (!spawn && (!spell || !use_all_spelltargets)) {
  7301. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7302. return 0;
  7303. }
  7304. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7305. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7306. return 0;
  7307. }
  7308. if (!item)
  7309. spell = lua_interface->GetCurrentSpell(state);
  7310. if (!item && !spell) {
  7311. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7312. return 0;
  7313. }
  7314. if(spell && spell->resisted) {
  7315. return 0;
  7316. }
  7317. if (spell && use_all_spelltargets) {
  7318. Spawn* target;
  7319. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7320. for (int8 i = 0; i < spell->targets.size(); i++) {
  7321. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7322. if (!target || !target->IsEntity())
  7323. continue;
  7324. ((Entity*)target)->AddProc(type, chance, item, spell);
  7325. }
  7326. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7327. }
  7328. else
  7329. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7330. return 0;
  7331. }
  7332. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7333. if (!lua_interface)
  7334. return 0;
  7335. Spawn* spawn = lua_interface->GetSpawn(state);
  7336. Item* item = lua_interface->GetItem(state, 2);
  7337. LuaSpell* spell = 0;
  7338. if (!spawn) {
  7339. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7340. return 0;
  7341. }
  7342. if (!spawn->IsEntity()) {
  7343. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7344. return 0;
  7345. }
  7346. if (!item)
  7347. spell = lua_interface->GetCurrentSpell(state);
  7348. if (!item && !spell) {
  7349. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7350. return 0;
  7351. }
  7352. if (spell) {
  7353. Spawn* target;
  7354. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7355. for (int8 i = 0; i < spell->targets.size(); i++) {
  7356. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7357. if (!target || !target->IsEntity())
  7358. continue;
  7359. ((Entity*)target)->RemoveProc(item, spell);
  7360. }
  7361. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7362. spell->caster->RemoveProc(item, spell);
  7363. }
  7364. else
  7365. ((Entity*)spawn)->RemoveProc(item, spell);
  7366. return 0;
  7367. }
  7368. int EQ2Emu_lua_Knockback(lua_State* state) {
  7369. if (!lua_interface)
  7370. return 0;
  7371. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7372. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7373. int32 duration = lua_interface->GetInt32Value(state, 3);
  7374. float vertical = lua_interface->GetFloatValue(state, 4);
  7375. float horizontal = lua_interface->GetFloatValue(state, 5);
  7376. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7377. if (!target_spawn) {
  7378. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7379. return 0;
  7380. }
  7381. if (!spawn) {
  7382. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7383. return 0;
  7384. }
  7385. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7386. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7387. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7388. if (packet) {
  7389. packet->setDataByName("target_x", target_spawn->GetX());
  7390. packet->setDataByName("target_y", target_spawn->GetY());
  7391. packet->setDataByName("target_z", target_spawn->GetZ());
  7392. packet->setDataByName("vertical_movement", vertical);
  7393. packet->setDataByName("horizontal_movement", horizontal);
  7394. if (use_heading)
  7395. packet->setDataByName("use_player_heading", 1);
  7396. client->QueuePacket(packet->serialize());
  7397. }
  7398. safe_delete(packet);
  7399. }
  7400. return 0;
  7401. }
  7402. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7403. if (!lua_interface)
  7404. return 0;
  7405. Spawn* spawn = lua_interface->GetSpawn(state);
  7406. if (!spawn) {
  7407. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7408. return 0;
  7409. }
  7410. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7411. return 1;
  7412. }
  7413. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7414. if (!lua_interface)
  7415. return 0;
  7416. Spawn* caster = lua_interface->GetSpawn(state);
  7417. Spawn* target = lua_interface->GetSpawn(state, 2);
  7418. string name = lua_interface->GetStringValue(state, 3);
  7419. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7420. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7421. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7422. string success_msg = lua_interface->GetStringValue(state, 7);
  7423. string effect_msg = lua_interface->GetStringValue(state, 8);
  7424. if (!caster) {
  7425. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7426. return 0;
  7427. }
  7428. if (!caster->IsEntity()) {
  7429. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7430. return 0;
  7431. }
  7432. if (!target) {
  7433. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7434. return 0;
  7435. }
  7436. if (!target->IsEntity()) {
  7437. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7438. return 0;
  7439. }
  7440. if (name.length() == 0) {
  7441. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7442. return 0;
  7443. }
  7444. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7445. return 0;
  7446. }
  7447. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7448. if (!lua_interface)
  7449. return 0;
  7450. string name = lua_interface->GetStringValue(state);
  7451. if (name.length() == 0) {
  7452. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7453. return 0;
  7454. }
  7455. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7456. if (!skill) {
  7457. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7458. return 0;
  7459. }
  7460. lua_interface->SetInt32Value(state, skill->skill_id);
  7461. return 1;
  7462. }
  7463. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7464. if (!lua_interface)
  7465. return 0;
  7466. Spawn* spawn = lua_interface->GetSpawn(state);
  7467. if (!spawn) {
  7468. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7469. return 0;
  7470. }
  7471. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7472. return 1;
  7473. }
  7474. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7475. if (!lua_interface)
  7476. return 0;
  7477. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7478. if (!luaspell) {
  7479. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7480. return 0;
  7481. }
  7482. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7483. return 1;
  7484. }
  7485. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7486. if (!lua_interface)
  7487. return 0;
  7488. Spawn* spawn = lua_interface->GetSpawn(state);
  7489. Spawn* target = lua_interface->GetSpawn(state, 2);
  7490. if (!spawn) {
  7491. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7492. return 0;
  7493. }
  7494. if (!spawn->IsEntity()) {
  7495. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7496. return 0;
  7497. }
  7498. if (!target) {
  7499. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7500. return 0;
  7501. }
  7502. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7503. return 1;
  7504. }
  7505. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7506. if (!lua_interface)
  7507. return 0;
  7508. Spawn* spawn = lua_interface->GetSpawn(state);
  7509. Spawn* target = lua_interface->GetSpawn(state, 2);
  7510. if (!spawn) {
  7511. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7512. return 0;
  7513. }
  7514. if (!spawn->IsEntity()) {
  7515. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7516. return 0;
  7517. }
  7518. if (!target) {
  7519. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7520. return 0;
  7521. }
  7522. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7523. return 1;
  7524. }
  7525. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7526. if (!lua_interface)
  7527. return 0;
  7528. Item* item = lua_interface->GetItem(state);
  7529. if (!item) {
  7530. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7531. return 0;
  7532. }
  7533. lua_interface->SetInt32Value(state, item->details.count);
  7534. return 1;
  7535. }
  7536. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7537. if (!lua_interface)
  7538. return 0;
  7539. Item* item = lua_interface->GetItem(state);
  7540. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7541. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7542. if (!item) {
  7543. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7544. return 0;
  7545. }
  7546. if (!owner) {
  7547. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7548. return 0;
  7549. }
  7550. if (!owner->IsPlayer()) {
  7551. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7552. return 0;
  7553. }
  7554. if (item->stack_count < new_count) {
  7555. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7556. return 0;
  7557. }
  7558. if (new_count > 0) {
  7559. item->details.count = new_count;
  7560. item->save_needed = true;
  7561. }
  7562. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7563. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7564. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7565. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7566. else
  7567. {
  7568. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7569. return 0;
  7570. }
  7571. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7572. if (!client)
  7573. return 0;
  7574. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7575. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7576. if (app)
  7577. client->QueuePacket(app);
  7578. return 0;
  7579. }
  7580. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7581. if (!lua_interface)
  7582. return 0;
  7583. int32 time = lua_interface->GetInt32Value(state);
  7584. string function = lua_interface->GetStringValue(state, 2);
  7585. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7586. Spawn* target = lua_interface->GetSpawn(state, 4);
  7587. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7588. if (time == 0) {
  7589. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7590. return 0;
  7591. }
  7592. if (function.length() == 0) {
  7593. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7594. return 0;
  7595. }
  7596. if (!spell) {
  7597. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7598. return 0;
  7599. }
  7600. SpellScriptTimer* timer = new SpellScriptTimer;
  7601. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7602. #ifdef WIN32
  7603. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7604. #else
  7605. bzero(timer, sizeof(SpellScriptTimer));
  7606. #endif*/
  7607. timer->caster = 0;
  7608. timer->deleteWhenDone = false;
  7609. timer->target = 0;
  7610. timer->time = Timer::GetCurrentTime2() + time;
  7611. timer->customFunction = function;
  7612. timer->spell = spell;
  7613. if (caster)
  7614. timer->caster = caster->GetID();
  7615. if (target)
  7616. timer->target = target->GetID();
  7617. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7618. return 0;
  7619. }
  7620. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7621. if (!lua_interface)
  7622. return 0;
  7623. float hp_perc = lua_interface->GetFloatValue(state);
  7624. float power_perc = lua_interface->GetFloatValue(state, 2);
  7625. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7626. Spawn* target = lua_interface->GetSpawn(state, 4);
  7627. string heal_name = lua_interface->GetStringValue(state, 5);
  7628. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7629. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7630. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7631. if (!spell) {
  7632. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7633. return 0;
  7634. }
  7635. Entity* caster = spell->caster;
  7636. if (!caster) {
  7637. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7638. return 0;
  7639. }
  7640. Client* client = 0;
  7641. PendingResurrection* rez = 0;
  7642. ZoneServer* zone = spell->caster->GetZone();
  7643. if (!target) {
  7644. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7645. if (spell->targets.size() > 0) {
  7646. vector<int32> spell_targets = spell->targets;
  7647. for (int8 i = 0; i < spell_targets.size(); i++) {
  7648. target = zone->GetSpawnByID(spell_targets.at(i));
  7649. if (!target)
  7650. continue;
  7651. if (!target->IsPlayer())
  7652. continue;
  7653. client = target->GetZone()->GetClientBySpawn(target);
  7654. if (!client)
  7655. continue;
  7656. rez = client->GetCurrentRez();
  7657. if (rez->active)
  7658. continue;
  7659. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7660. rez->active = true;
  7661. rez->caster = caster;
  7662. rez->expire_timer = new Timer;
  7663. int32 duration = spell->spell->GetSpellDuration();
  7664. rez->expire_timer->Start(duration * 100);
  7665. rez->hp_perc = hp_perc;
  7666. rez->mp_perc = power_perc;
  7667. rez->range = spell->spell->GetSpellData()->range;
  7668. rez->spell_name = spell->spell->GetName();
  7669. if (heal_name.length() > 0)
  7670. rez->heal_name = heal_name;
  7671. else
  7672. rez->heal_name = rez->spell_name;
  7673. rez->no_calcs = no_calcs;
  7674. rez->crit_mod = crit_mod;
  7675. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7676. if (send_window)
  7677. client->SendResurrectionWindow();
  7678. else {
  7679. target->GetZone()->ResurrectSpawn(target, client);
  7680. rez->should_delete = true;
  7681. }
  7682. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7683. }
  7684. }
  7685. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7686. }
  7687. else {
  7688. client = target->GetZone()->GetClientBySpawn(target);
  7689. if (!client)
  7690. return 0;
  7691. rez = client->GetCurrentRez();
  7692. if (rez->active)
  7693. return 0;
  7694. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7695. rez->active = true;
  7696. rez->caster = caster;
  7697. rez->expire_timer = new Timer;
  7698. int32 duration = spell->spell->GetSpellDuration();
  7699. rez->expire_timer->Start(duration * 100);
  7700. rez->hp_perc = hp_perc;
  7701. rez->mp_perc = power_perc;
  7702. rez->range = spell->spell->GetSpellData()->range;
  7703. rez->spell_name = spell->spell->GetName();
  7704. if (heal_name.length() > 0)
  7705. rez->heal_name = heal_name;
  7706. else
  7707. rez->heal_name = rez->spell_name;
  7708. rez->no_calcs = no_calcs;
  7709. rez->crit_mod = crit_mod;
  7710. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7711. if (send_window)
  7712. client->SendResurrectionWindow();
  7713. else {
  7714. target->GetZone()->ResurrectSpawn(target, client);
  7715. rez->should_delete = true;
  7716. }
  7717. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7718. }
  7719. return 0;
  7720. }
  7721. int EQ2Emu_lua_SetVision(lua_State* state) {
  7722. if (!lua_interface)
  7723. return 0;
  7724. Spawn* spawn = lua_interface->GetSpawn(state);
  7725. int8 vision = lua_interface->GetInt8Value(state, 2);
  7726. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7727. if (!spawn) {
  7728. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7729. return 0;
  7730. }
  7731. if (!spawn->IsEntity()) {
  7732. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7733. return 0;
  7734. }
  7735. if (spell && spell->targets.size() > 0) {
  7736. ZoneServer* zone = spell->caster->GetZone();
  7737. for (int8 i = 0; i < spell->targets.size(); i++) {
  7738. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7739. if (target && target->IsEntity()) {
  7740. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7741. if (target->IsPlayer())
  7742. ((Player*)target)->SetCharSheetChanged(true);
  7743. }
  7744. }
  7745. }
  7746. else {
  7747. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7748. if (spawn->IsPlayer())
  7749. ((Player*)spawn)->SetCharSheetChanged(true);
  7750. }
  7751. return 0;
  7752. }
  7753. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7754. if (!lua_interface)
  7755. return 0;
  7756. Spawn* spawn = lua_interface->GetSpawn(state);
  7757. float intensity = lua_interface->GetFloatValue(state, 2);
  7758. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7759. if (!spawn) {
  7760. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7761. return 0;
  7762. }
  7763. if (!spawn->IsEntity()) {
  7764. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7765. return 0;
  7766. }
  7767. if (spell && spell->targets.size() > 0) {
  7768. ZoneServer* zone = spell->caster->GetZone();
  7769. for (int8 i = 0; i < spell->targets.size(); i++) {
  7770. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7771. if (target && target->IsEntity()) {
  7772. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7773. if (target->IsPlayer())
  7774. ((Player*)target)->SetCharSheetChanged(true);
  7775. }
  7776. }
  7777. }
  7778. else {
  7779. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7780. if (spawn->IsPlayer())
  7781. ((Player*)spawn)->SetCharSheetChanged(true);
  7782. }
  7783. return 0;
  7784. }
  7785. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7786. if (!lua_interface)
  7787. return 0;
  7788. Spawn* spawn = lua_interface->GetSpawn(state);
  7789. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7790. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7791. if (!spawn) {
  7792. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7793. return 0;
  7794. }
  7795. if (!spawn->IsEntity()) {
  7796. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7797. return 0;
  7798. }
  7799. if (spell && spell->targets.size() > 0) {
  7800. ZoneServer* zone = spell->caster->GetZone();
  7801. for (int8 i = 0; i < spell->targets.size(); i++) {
  7802. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7803. if (target && target->IsEntity()) {
  7804. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7805. if (target->IsPlayer())
  7806. ((Player*)target)->SetCharSheetChanged(true);
  7807. }
  7808. }
  7809. }
  7810. else {
  7811. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7812. if (spawn->IsPlayer())
  7813. ((Player*)spawn)->SetCharSheetChanged(true);
  7814. }
  7815. return 0;
  7816. }
  7817. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7818. if (!lua_interface)
  7819. return 0;
  7820. Item* item = lua_interface->GetItem(state);
  7821. int8 type = lua_interface->GetInt32Value(state, 2);
  7822. if (!item) {
  7823. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7824. return 0;
  7825. }
  7826. if (type == 1)
  7827. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7828. else if (type == 2)
  7829. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7830. return 1;
  7831. }
  7832. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7833. if (!lua_interface)
  7834. return 0;
  7835. Spawn* target = lua_interface->GetSpawn(state);
  7836. float val = lua_interface->GetFloatValue(state, 2);
  7837. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7838. // Added from Gangrenous post
  7839. if (spell && spell->resisted)
  7840. return 0;
  7841. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7842. if (val > 1.0f)
  7843. val = 1.0f - (val / 100.0f);
  7844. if (spell && spell->spell && spell->targets.size() > 0) {
  7845. ZoneServer* zone = spell->caster->GetZone();
  7846. for (int32 i = 0; i != spell->targets.size(); i++) {
  7847. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7848. if (spawn && spawn->IsEntity()) {
  7849. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7850. if (spawn->IsPlayer())
  7851. ((Player*)spawn)->SetCharSheetChanged(true);
  7852. }
  7853. }
  7854. }
  7855. else {
  7856. if (target && target->IsEntity()) {
  7857. ((Entity*)target)->SetSpeedMultiplier(val);
  7858. if (target->IsPlayer())
  7859. ((Player*)target)->SetCharSheetChanged(true);
  7860. }
  7861. }
  7862. return 0;
  7863. }
  7864. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7865. if (!lua_interface)
  7866. return 0;
  7867. Spawn* spawn = lua_interface->GetSpawn(state);
  7868. int16 model = lua_interface->GetInt16Value(state, 2);
  7869. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7870. if (spell && spell->spell && spell->targets.size() > 0) {
  7871. ZoneServer* zone = spell->caster->GetZone();
  7872. for (int32 i = 0; i < spell->targets.size(); i++) {
  7873. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7874. if (target)
  7875. target->SetIllusionModel(model);
  7876. }
  7877. }
  7878. else {
  7879. if (!spawn) {
  7880. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7881. return 0;
  7882. }
  7883. spawn->SetIllusionModel(model);
  7884. }
  7885. return 0;
  7886. }
  7887. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7888. if (!lua_interface)
  7889. return 0;
  7890. Spawn* spawn = lua_interface->GetSpawn(state);
  7891. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7892. if (spell && spell->spell && spell->targets.size() > 0) {
  7893. ZoneServer* zone = spell->caster->GetZone();
  7894. for (int32 i = 0; i < spell->targets.size(); i++) {
  7895. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7896. if (target)
  7897. target->SetIllusionModel(0);
  7898. }
  7899. }
  7900. else {
  7901. if (!spawn) {
  7902. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7903. return 0;
  7904. }
  7905. spawn->SetIllusionModel(0);
  7906. }
  7907. return 0;
  7908. }
  7909. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7910. if (!lua_interface)
  7911. return 0;
  7912. Spawn* caster = lua_interface->GetSpawn(state);
  7913. Spawn* target = lua_interface->GetSpawn(state, 2);
  7914. float chance = lua_interface->GetFloatValue(state, 3);
  7915. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7916. if (!caster) {
  7917. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7918. return 0;
  7919. }
  7920. if (!caster->IsEntity()) {
  7921. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7922. return 0;
  7923. }
  7924. if (!target) {
  7925. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7926. return 0;
  7927. }
  7928. if (!target->IsEntity()) {
  7929. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7930. return 0;
  7931. }
  7932. if (chance <= 0) {
  7933. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7934. return 0;
  7935. }
  7936. if (!spell) {
  7937. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7938. return 0;
  7939. }
  7940. if(spell->resisted) {
  7941. return 0;
  7942. }
  7943. if (((Entity*)caster)->GetThreatTransfer()) {
  7944. return 0;
  7945. }
  7946. ThreatTransfer* transfer = new ThreatTransfer;
  7947. transfer->Target = target->GetID();
  7948. transfer->Amount = chance;
  7949. transfer->Spell = spell;
  7950. ((Entity*)caster)->SetThreatTransfer(transfer);
  7951. return 0;
  7952. }
  7953. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7954. if (!lua_interface)
  7955. return 0;
  7956. Spawn* spawn = lua_interface->GetSpawn(state);
  7957. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7958. if (!spawn) {
  7959. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7960. return 0;
  7961. }
  7962. if (!spell) {
  7963. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7964. return 0;
  7965. }
  7966. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7967. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7968. if(transfer && transfer->Spell != spell) {
  7969. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  7970. return 0;
  7971. }
  7972. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  7973. }
  7974. return 0;
  7975. }
  7976. int EQ2Emu_lua_CureByType(lua_State* state) {
  7977. if (!lua_interface)
  7978. return 0;
  7979. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7980. int8 cure_count = lua_interface->GetInt8Value(state);
  7981. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7982. string cure_name = lua_interface->GetStringValue(state, 3);
  7983. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7984. Spawn* target = lua_interface->GetSpawn(state, 5);
  7985. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  7986. if(spell && spell->resisted) {
  7987. return 0;
  7988. }
  7989. if (target) {
  7990. if (!target->IsEntity()) {
  7991. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7992. return 0;
  7993. }
  7994. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  7995. std::string alternate_name = "item";
  7996. if(spell)
  7997. alternate_name = std::string(spell->spell->GetName());
  7998. if(!caster && spell)
  7999. caster = (Spawn*)spell->caster;
  8000. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8001. }
  8002. }
  8003. else {
  8004. ZoneServer* zone = spell->caster->GetZone();
  8005. vector<int32> targets = spell->targets;
  8006. vector<Entity*> targets_to_cure;
  8007. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8008. for (int8 i = 0; i < targets.size(); i++) {
  8009. target = zone->GetSpawnByID(targets.at(i));
  8010. if (!target || !target->IsEntity())
  8011. continue;
  8012. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8013. targets_to_cure.push_back((Entity*)target);
  8014. }
  8015. }
  8016. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8017. vector<Entity*>::iterator itr;
  8018. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8019. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8020. }
  8021. }
  8022. return 0;
  8023. }
  8024. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8025. if (!lua_interface)
  8026. return 0;
  8027. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8028. if (!spell) {
  8029. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8030. return 0;
  8031. }
  8032. if(spell->resisted) {
  8033. return 0;
  8034. }
  8035. int8 cure_count = lua_interface->GetInt8Value(state);
  8036. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8037. string cure_name = lua_interface->GetStringValue(state, 3);
  8038. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8039. Spawn* target = lua_interface->GetSpawn(state, 5);
  8040. if (target) {
  8041. if (!target->IsEntity()) {
  8042. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8043. return 0;
  8044. }
  8045. if (((Entity*)target)->GetDetCount() > 0)
  8046. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8047. }
  8048. else {
  8049. ZoneServer* zone = spell->caster->GetZone();
  8050. vector<int32> targets = spell->targets;
  8051. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8052. for (int8 i = 0; i < targets.size(); i++) {
  8053. target = zone->GetSpawnByID(targets.at(i));
  8054. if (!target || !target->IsEntity())
  8055. continue;
  8056. if (((Entity*)target)->GetDetCount() > 0)
  8057. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8058. }
  8059. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8060. }
  8061. return 0;
  8062. }
  8063. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8064. if (!lua_interface)
  8065. return 0;
  8066. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8067. if (!spell) {
  8068. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8069. return 0;
  8070. }
  8071. if (!spell->caster) {
  8072. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8073. return 0;
  8074. }
  8075. if (!spell->caster->GetZone()) {
  8076. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8077. return 0;
  8078. }
  8079. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8080. return 0;
  8081. }
  8082. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8083. if (!lua_interface)
  8084. return 0;
  8085. Spawn* spawn = lua_interface->GetSpawn(state);
  8086. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8087. if (!spell) {
  8088. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8089. return 0;
  8090. }
  8091. if (spawn && spawn->IsEntity())
  8092. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8093. else {
  8094. ZoneServer* zone = spell->caster->GetZone();
  8095. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8096. for (int32 i = 0; i < spell->targets.size(); i++) {
  8097. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8098. if (!spawn || !spawn->IsEntity())
  8099. continue;
  8100. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8101. }
  8102. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8103. }
  8104. return 0;
  8105. }
  8106. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8107. if (!lua_interface)
  8108. return 0;
  8109. Spawn* spawn = lua_interface->GetSpawn(state);
  8110. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8111. if (!spell) {
  8112. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8113. return 0;
  8114. }
  8115. if (spawn && spawn->IsEntity())
  8116. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8117. else {
  8118. ZoneServer* zone = spell->caster->GetZone();
  8119. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8120. for (int32 i = 0; i < spell->targets.size(); i++) {
  8121. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8122. if (!spawn || !spawn->IsEntity())
  8123. continue;
  8124. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8125. }
  8126. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8127. }
  8128. return 0;
  8129. }
  8130. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8131. if (!lua_interface)
  8132. return 0;
  8133. Spawn* caster = lua_interface->GetSpawn(state);
  8134. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8135. if (!caster) {
  8136. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8137. return 0;
  8138. }
  8139. if (!caster->IsPlayer()) {
  8140. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8141. return 0;
  8142. }
  8143. Spawn* target = caster->GetTarget();
  8144. if (!target) {
  8145. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8146. return 0;
  8147. }
  8148. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8149. if (!client) {
  8150. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8151. return 0;
  8152. }
  8153. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8154. if (ho) {
  8155. ho->SetTarget(target->GetID());
  8156. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8157. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8158. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8159. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8160. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8161. deque<GroupMemberInfo*>::iterator itr;
  8162. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8163. if (group)
  8164. {
  8165. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8166. deque<GroupMemberInfo*>* members = group->GetMembers();
  8167. for (itr = members->begin(); itr != members->end(); itr++) {
  8168. if ((*itr)->client)
  8169. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8170. }
  8171. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8172. }
  8173. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8174. }
  8175. else
  8176. safe_delete(ho);
  8177. }
  8178. else {
  8179. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8180. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8181. }
  8182. else
  8183. safe_delete(ho);
  8184. }
  8185. }
  8186. return 0;
  8187. }
  8188. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8189. if (!lua_interface)
  8190. return 0;
  8191. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8192. if (!spell) {
  8193. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8194. return 0;
  8195. }
  8196. int16 triggerCount = lua_interface->GetInt16Value(state);
  8197. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8198. if (!triggerCount) {
  8199. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8200. return 0;
  8201. }
  8202. spell->num_triggers = triggerCount;
  8203. spell->had_triggers = true;
  8204. spell->cancel_after_all_triggers = cancel_after_triggers;
  8205. return 0;
  8206. }
  8207. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8208. if (!lua_interface)
  8209. return 0;
  8210. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8211. if (!spell) {
  8212. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8213. return 0;
  8214. }
  8215. lua_interface->SetInt32Value(state, spell->num_triggers);
  8216. return 1;
  8217. }
  8218. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8219. if (!lua_interface)
  8220. return 0;
  8221. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8222. if (!spell) {
  8223. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8224. return 0;
  8225. }
  8226. int16 remove_count = lua_interface->GetInt16Value(state);
  8227. if (!remove_count)
  8228. remove_count = 1;
  8229. if (remove_count >= spell->num_triggers) {
  8230. spell->num_triggers = 0;
  8231. if (spell->cancel_after_all_triggers)
  8232. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8233. }
  8234. else {
  8235. spell->num_triggers -= remove_count;
  8236. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8237. }
  8238. return 0;
  8239. }
  8240. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8241. if (!lua_interface)
  8242. return 0;
  8243. Spawn* spawn = lua_interface->GetSpawn(state);
  8244. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8245. if (!spawn) {
  8246. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8247. return 0;
  8248. }
  8249. if (!copy_spawn) {
  8250. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8251. return 0;
  8252. }
  8253. spawn->CopySpawnAppearance(copy_spawn);
  8254. return 0;
  8255. }
  8256. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8257. Spawn* spawn = lua_interface->GetSpawn(state);
  8258. int8 type = lua_interface->GetInt8Value(state, 2);
  8259. if (!spawn) {
  8260. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8261. return 0;
  8262. }
  8263. else if (!spawn->IsEntity()) {
  8264. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8265. return 0;
  8266. }
  8267. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8268. return 1;
  8269. }
  8270. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8271. if (!lua_interface)
  8272. return 0;
  8273. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8274. int8 type = lua_interface->GetInt8Value(state);
  8275. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8276. if (!spell) {
  8277. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8278. return 0;
  8279. }
  8280. if(spell->resisted) {
  8281. return 0;
  8282. }
  8283. if (spawn) {
  8284. if (!spawn->IsEntity()) {
  8285. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8286. return 0;
  8287. }
  8288. Entity* entity = ((Entity*)spawn);
  8289. entity->AddImmunity(spell, type);
  8290. }
  8291. else {
  8292. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8293. for (int8 i = 0; i < spell->targets.size(); i++) {
  8294. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8295. if (!spawn || !spawn->IsEntity())
  8296. continue;
  8297. Entity* entity = ((Entity*)spawn);
  8298. entity->AddImmunity(spell, type);
  8299. }
  8300. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8301. }
  8302. return 0;
  8303. }
  8304. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8305. if (!lua_interface)
  8306. return 0;
  8307. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8308. int8 type = lua_interface->GetInt8Value(state);
  8309. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8310. if (!spell) {
  8311. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8312. return 0;
  8313. }
  8314. if (spawn) {
  8315. if (!spawn->IsEntity()) {
  8316. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8317. return 0;
  8318. }
  8319. Entity* entity = ((Entity*)spawn);
  8320. entity->RemoveImmunity(spell, type);
  8321. }
  8322. else {
  8323. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8324. for (int8 i = 0; i < spell->targets.size(); i++) {
  8325. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8326. if (!spawn || !spawn->IsEntity())
  8327. continue;
  8328. Entity* entity = ((Entity*)spawn);
  8329. entity->RemoveImmunity(spell, type);
  8330. }
  8331. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8332. }
  8333. return 0;
  8334. }
  8335. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8336. if (!lua_interface)
  8337. return 0;
  8338. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8339. if (!spell) {
  8340. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8341. return 0;
  8342. }
  8343. if(spell->resisted) {
  8344. return 0;
  8345. }
  8346. float snare = lua_interface->GetFloatValue(state);
  8347. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8348. // convert the val to the speed multipler value (100 - val)
  8349. float val = 100.0 - snare;
  8350. val /= 100.0;
  8351. if (spawn) {
  8352. if (!spawn->IsEntity()) {
  8353. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8354. return 0;
  8355. }
  8356. ((Entity*)spawn)->SetSnareValue(spell, val);
  8357. }
  8358. else {
  8359. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8360. for (int8 i = 0; i < spell->targets.size(); i++) {
  8361. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8362. if (!spawn || !spawn->IsEntity())
  8363. continue;
  8364. ((Entity*)spawn)->SetSnareValue(spell, val);
  8365. }
  8366. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8367. }
  8368. return 0;
  8369. }
  8370. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8371. if (!lua_interface)
  8372. return 0;
  8373. Spawn* spawn = lua_interface->GetSpawn(state);
  8374. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8375. if (!spawn) {
  8376. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8377. return 0;
  8378. }
  8379. if (race_id == 0) {
  8380. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8381. return 0;
  8382. }
  8383. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8384. return 1;
  8385. }
  8386. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8387. if (!lua_interface)
  8388. return 0;
  8389. Spawn* spawn = lua_interface->GetSpawn(state);
  8390. if (!spawn) {
  8391. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8392. return 0;
  8393. }
  8394. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8395. return 1;
  8396. }
  8397. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8398. if (!lua_interface)
  8399. return 0;
  8400. Spawn* spawn = lua_interface->GetSpawn(state);
  8401. if (!spawn) {
  8402. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8403. return 0;
  8404. }
  8405. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8406. return 1;
  8407. }
  8408. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8409. if (!lua_interface)
  8410. return 0;
  8411. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8412. if (!spell) {
  8413. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8414. return 0;
  8415. }
  8416. lua_interface->SetStringValue(state, spell->spell->GetName());
  8417. return 1;
  8418. }
  8419. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8420. if (!lua_interface)
  8421. return 0;
  8422. Quest* quest = lua_interface->GetQuest(state);
  8423. if (!quest) {
  8424. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8425. return 0;
  8426. }
  8427. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8428. return 1;
  8429. }
  8430. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8431. if (!lua_interface)
  8432. return 0;
  8433. Quest* quest = lua_interface->GetQuest(state);
  8434. int32 flags = lua_interface->GetInt32Value(state, 2);
  8435. if (!quest) {
  8436. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8437. return 0;
  8438. }
  8439. quest->SetQuestFlags(flags);
  8440. return 0;
  8441. }
  8442. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8443. if (!lua_interface)
  8444. return 0;
  8445. Quest* quest = lua_interface->GetQuest(state);
  8446. Spawn* player = lua_interface->GetSpawn(state, 2);
  8447. int32 step = lua_interface->GetInt32Value(state, 3);
  8448. int32 duration = lua_interface->GetInt32Value(state, 4);
  8449. string action = lua_interface->GetStringValue(state, 5);
  8450. if (!quest) {
  8451. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8452. return 0;
  8453. }
  8454. if (!player) {
  8455. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. if (!player->IsPlayer()) {
  8459. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8460. return 0;
  8461. }
  8462. if (step == 0) {
  8463. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8464. return 0;
  8465. }
  8466. if (duration == 0) {
  8467. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8468. return 0;
  8469. }
  8470. if (action.length() == 0) {
  8471. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8472. return 0;
  8473. }
  8474. Client* client = player->GetZone()->GetClientBySpawn(player);
  8475. if (!client) {
  8476. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8477. return 0;
  8478. }
  8479. quest->SetTimerStep(step);
  8480. quest->AddFailedAction(step, action);
  8481. quest->SetStepTimer(duration);
  8482. client->AddQuestTimer(quest->GetQuestID());
  8483. return 0;
  8484. }
  8485. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8486. if (!lua_interface)
  8487. return 0;
  8488. Quest* quest = lua_interface->GetQuest(state);
  8489. Spawn* player = lua_interface->GetSpawn(state, 2);
  8490. if (!quest) {
  8491. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8492. return 0;
  8493. }
  8494. if (!player) {
  8495. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8496. return 0;
  8497. }
  8498. if (!player->IsPlayer()) {
  8499. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8500. return 0;
  8501. }
  8502. Client* client = player->GetZone()->GetClientBySpawn(player);
  8503. if (!client) {
  8504. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8505. return 0;
  8506. }
  8507. quest->SetTimerStep(0);
  8508. quest->SetStepTimer(0);
  8509. client->RemoveQuestTimer(quest->GetQuestID());
  8510. return 0;
  8511. }
  8512. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8513. if (!lua_interface)
  8514. return 0;
  8515. Spawn* player = lua_interface->GetSpawn(state);
  8516. Quest* quest = lua_interface->GetQuest(state, 2);
  8517. int32 step = lua_interface->GetInt32Value(state, 3);
  8518. if (!player) {
  8519. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8520. return 0;
  8521. }
  8522. if (!player->IsPlayer()) {
  8523. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8524. return 0;
  8525. }
  8526. if (!quest) {
  8527. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8528. return 0;
  8529. }
  8530. if (step == 0) {
  8531. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8532. return 0;
  8533. }
  8534. Client* client = player->GetZone()->GetClientBySpawn(player);
  8535. if (!client) {
  8536. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8537. return 0;
  8538. }
  8539. if (quest->RemoveQuestStep(step, client)) {
  8540. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8541. client->GetCurrentZone()->SendQuestUpdates(client);
  8542. }
  8543. else
  8544. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8545. return 0;
  8546. }
  8547. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8548. if (!lua_interface)
  8549. return 0;
  8550. Quest* quest = lua_interface->GetQuest(state, 1);
  8551. int32 step = lua_interface->GetInt32Value(state, 2);
  8552. string desc = lua_interface->GetStringValue(state, 3);
  8553. string task_group = lua_interface->GetStringValue(state, 4);
  8554. if (!quest) {
  8555. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8556. return 0;
  8557. }
  8558. if (step == 0) {
  8559. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8560. return 0;
  8561. }
  8562. QuestStep* quest_step = quest->GetQuestStep(step);
  8563. if (!quest_step) {
  8564. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8565. return 0;
  8566. }
  8567. quest_step->SetStepProgress(0);
  8568. quest_step->SetTaskGroup(task_group);
  8569. quest_step->SetDescription(desc);
  8570. return 0;
  8571. }
  8572. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8573. if (!lua_interface)
  8574. return 0;
  8575. Quest* quest = lua_interface->GetQuest(state);
  8576. int32 step = lua_interface->GetInt32Value(state, 2);
  8577. string action = lua_interface->GetStringValue(state, 3);
  8578. if (!quest) {
  8579. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8580. return 0;
  8581. }
  8582. if (step == 0) {
  8583. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8584. return 0;
  8585. }
  8586. if (action.length() == 0) {
  8587. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8588. return 0;
  8589. }
  8590. quest->AddFailedAction(step, action);
  8591. return 0;
  8592. }
  8593. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8594. if (!lua_interface)
  8595. return 0;
  8596. Spawn* player = lua_interface->GetSpawn(state);
  8597. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8598. int32 step = lua_interface->GetInt32Value(state, 3);
  8599. if (!player) {
  8600. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8601. return 0;
  8602. }
  8603. if (!player->IsPlayer()) {
  8604. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8605. return 0;
  8606. }
  8607. if (quest_id == 0) {
  8608. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8609. return 0;
  8610. }
  8611. if (step == 0) {
  8612. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8613. return 0;
  8614. }
  8615. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8616. if (!quest) {
  8617. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8618. return 0;
  8619. }
  8620. quest->StepFailed(step);
  8621. return 0;
  8622. }
  8623. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8624. if (!lua_interface)
  8625. return 0;
  8626. Spawn* player = lua_interface->GetSpawn(state);
  8627. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8628. if (!player) {
  8629. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8630. return 0;
  8631. }
  8632. if (!player->IsPlayer()) {
  8633. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8634. return 0;
  8635. }
  8636. if (quest_id == 0) {
  8637. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8638. return 0;
  8639. }
  8640. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8641. if (!quest) {
  8642. lua_interface->SetInt32Value(state, 0);
  8643. return 1;
  8644. }
  8645. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8646. return 1;
  8647. }
  8648. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8649. if (!lua_interface)
  8650. return 0;
  8651. string name = lua_interface->GetStringValue(state);
  8652. string value = lua_interface->GetStringValue(state, 2);
  8653. string comment = lua_interface->GetStringValue(state, 3);
  8654. if (name.length() == 0) {
  8655. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8656. return 0;
  8657. }
  8658. if (value.length() == 0) {
  8659. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8660. return 0;
  8661. }
  8662. string varname = string("lua_").append(name);
  8663. Variable* var = variables.FindVariable(varname);
  8664. if (var)
  8665. var->SetValue(value.c_str());
  8666. else {
  8667. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8668. variables.AddVariable(var);
  8669. }
  8670. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8671. return 0;
  8672. }
  8673. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8674. if (!lua_interface)
  8675. return 0;
  8676. string name = lua_interface->GetStringValue(state);
  8677. if (name.length() == 0) {
  8678. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8679. return 0;
  8680. }
  8681. string varname = string("lua_").append(name);
  8682. Variable* var = variables.FindVariable(varname);
  8683. if (var)
  8684. lua_interface->SetStringValue(state, var->GetValue());
  8685. else
  8686. lua_interface->SetStringValue(state, "NULL");
  8687. return 1;
  8688. }
  8689. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8690. if (!lua_interface)
  8691. return 0;
  8692. Spawn* player = lua_interface->GetSpawn(state);
  8693. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8694. if (!player) {
  8695. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8696. return 0;
  8697. }
  8698. if (!player->IsPlayer()) {
  8699. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8700. return 0;
  8701. }
  8702. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8703. return 1;
  8704. }
  8705. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8706. if (!lua_interface)
  8707. return 0;
  8708. Spawn* player = lua_interface->GetSpawn(state);
  8709. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8710. if (!player) {
  8711. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8712. return 0;
  8713. }
  8714. if (!player->IsPlayer()) {
  8715. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8716. return 0;
  8717. }
  8718. Language* language = master_languages_list.GetLanguage(language_id);
  8719. if (language)
  8720. {
  8721. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8722. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8723. }
  8724. return 0;
  8725. }
  8726. int EQ2Emu_lua_IsNight(lua_State* state) {
  8727. if (!lua_interface)
  8728. return 0;
  8729. ZoneServer* zone = lua_interface->GetZone(state);
  8730. if (!zone) {
  8731. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8732. return 0;
  8733. }
  8734. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8735. return 1;
  8736. }
  8737. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8738. if (!lua_interface)
  8739. return 0;
  8740. Spawn* spawn = lua_interface->GetSpawn(state);
  8741. if (!spawn) {
  8742. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8743. return 0;
  8744. }
  8745. if (!spawn->IsWidget()) {
  8746. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8747. return 0;
  8748. }
  8749. ((Widget*)spawn)->SetMultiFloorLift(true);
  8750. if (spawn->GetZone())
  8751. spawn->GetZone()->AddTransportSpawn(spawn);
  8752. return 0;
  8753. }
  8754. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8755. if (!lua_interface)
  8756. return 0;
  8757. Spawn* player = lua_interface->GetSpawn(state);
  8758. int32 path = lua_interface->GetInt32Value(state, 2);
  8759. if (!player) {
  8760. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8761. return 0;
  8762. }
  8763. if (!player->IsPlayer()) {
  8764. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8765. return 0;
  8766. }
  8767. if (path == 0) {
  8768. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8769. return 0;
  8770. }
  8771. Client* client = player->GetZone()->GetClientBySpawn(player);
  8772. if (!client) {
  8773. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8774. return 0;
  8775. }
  8776. client->SendFlightAutoMount(path);
  8777. return 0;
  8778. }
  8779. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8780. if (!lua_interface)
  8781. return 0;
  8782. Spawn* player = lua_interface->GetSpawn(state);
  8783. if (!player) {
  8784. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8785. return 0;
  8786. }
  8787. if (!player->IsPlayer()) {
  8788. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8789. return 0;
  8790. }
  8791. Client* client = player->GetZone()->GetClientBySpawn(player);
  8792. if (!client) {
  8793. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8794. return 0;
  8795. }
  8796. client->EndAutoMount();
  8797. return 0;
  8798. }
  8799. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8800. if (!lua_interface)
  8801. return 0;
  8802. Spawn* player = lua_interface->GetSpawn(state);
  8803. if (!player) {
  8804. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8805. return 0;
  8806. }
  8807. if (!player->IsPlayer()) {
  8808. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8809. return 0;
  8810. }
  8811. Client* client = player->GetZone()->GetClientBySpawn(player);
  8812. if (!client) {
  8813. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8814. return 0;
  8815. }
  8816. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8817. return 1;
  8818. }
  8819. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8820. if (!lua_interface)
  8821. return 0;
  8822. Spawn* player = lua_interface->GetSpawn(state);
  8823. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8824. int32 value = lua_interface->GetInt32Value(state, 3);
  8825. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8826. if (!player) {
  8827. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8828. return 0;
  8829. }
  8830. if (!player->IsPlayer()) {
  8831. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8832. return 0;
  8833. }
  8834. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8835. return 0;
  8836. }
  8837. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8838. if (!lua_interface)
  8839. return 0;
  8840. Spawn* player = lua_interface->GetSpawn(state);
  8841. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8842. if (!player) {
  8843. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8844. return 0;
  8845. }
  8846. if (!player->IsPlayer()) {
  8847. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8848. return 0;
  8849. }
  8850. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8851. if (!hd)
  8852. return 0;
  8853. lua_interface->SetInt32Value(state, hd->Value);
  8854. lua_interface->SetInt32Value(state, hd->Value2);
  8855. return 2;
  8856. }
  8857. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8858. if (!lua_interface)
  8859. return 0;
  8860. Spawn* spawn = lua_interface->GetSpawn(state);
  8861. int32 grid = lua_interface->GetInt32Value(state, 2);
  8862. if (!spawn) {
  8863. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8864. return 0;
  8865. }
  8866. if (grid == 0) {
  8867. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8868. return 0;
  8869. }
  8870. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8871. return 0;
  8872. }
  8873. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8874. if (!lua_interface)
  8875. return 0;
  8876. Spawn* spawn = lua_interface->GetSpawn(state);
  8877. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8878. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8879. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8880. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8881. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8882. if (!spawn) {
  8883. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8884. return 0;
  8885. }
  8886. //Add this quest to the list of required quests for this spawn
  8887. spawn->SetRequiredHistory(event_id, value1, value2);
  8888. //If private spawn value set
  8889. if (private_spawn) {
  8890. //Set the spawn to be private when not granted access via history
  8891. spawn->AddAllowAccessSpawn(spawn);
  8892. spawn->SetPrivateQuestSpawn(true);
  8893. }
  8894. //This value will override vis_flags in the vis packet
  8895. if (flag_override > 0)
  8896. spawn->SetQuestsRequiredOverride(flag_override);
  8897. return 0;
  8898. }
  8899. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8900. if (!lua_interface)
  8901. return 0;
  8902. Spawn* player = lua_interface->GetSpawn(state);
  8903. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8904. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8905. if (!player) {
  8906. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8907. return 0;
  8908. }
  8909. if (!player->IsPlayer()) {
  8910. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8911. return 0;
  8912. }
  8913. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8914. return 1;
  8915. }
  8916. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8917. if (!lua_interface)
  8918. return 0;
  8919. Spawn* player = lua_interface->GetSpawn(state);
  8920. int8 level = lua_interface->GetInt8Value(state, 2);
  8921. if (!player) {
  8922. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8923. return 0;
  8924. }
  8925. if (!player->IsPlayer()) {
  8926. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8927. return 0;
  8928. }
  8929. if (level == 0) {
  8930. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8931. return 0;
  8932. }
  8933. Client* client = player->GetZone()->GetClientBySpawn(player);
  8934. if (!client) {
  8935. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8936. return 0;
  8937. }
  8938. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8939. return 0;
  8940. }
  8941. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8942. if (!lua_interface)
  8943. return 0;
  8944. Spawn* player = lua_interface->GetSpawn(state);
  8945. int32 amount = lua_interface->GetInt32Value(state, 2);
  8946. if (!player) {
  8947. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8948. return 0;
  8949. }
  8950. if (!player->IsPlayer()) {
  8951. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8952. return 0;
  8953. }
  8954. if (amount == 0) {
  8955. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8956. return 0;
  8957. }
  8958. ((Player*)player)->AddCoins(amount);
  8959. return 0;
  8960. }
  8961. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8962. if (!lua_interface)
  8963. return 0;
  8964. Spawn* player = lua_interface->GetSpawn(state);
  8965. int32 amount = lua_interface->GetInt32Value(state, 2);
  8966. if (!player) {
  8967. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8968. return 0;
  8969. }
  8970. if (!player->IsPlayer()) {
  8971. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8972. return 0;
  8973. }
  8974. if (amount == 0) {
  8975. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8976. return 0;
  8977. }
  8978. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8979. return 1;
  8980. }
  8981. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8982. if (!lua_interface)
  8983. return 0;
  8984. ZoneServer* zone = lua_interface->GetZone(state);
  8985. if (!zone) {
  8986. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8987. return 0;
  8988. }
  8989. vector<Entity*> players = zone->GetPlayers();
  8990. if (players.size() == 0)
  8991. return 0;
  8992. lua_createtable(state, players.size(), 0);
  8993. int newTable = lua_gettop(state);
  8994. for (int32 i = 0; i < players.size(); i++) {
  8995. lua_interface->SetSpawnValue(state, players.at(i));
  8996. lua_rawseti(state, newTable, i + 1);
  8997. }
  8998. return 1;
  8999. }
  9000. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9001. if (!lua_interface)
  9002. return 0;
  9003. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9004. if (!zone) {
  9005. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9006. return 0;
  9007. }
  9008. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9009. //Map of <placement_id, location_id>
  9010. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9011. map<int32, int32>::iterator itr;
  9012. vector<Spawn*> group;
  9013. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9014. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9015. if (!location) {
  9016. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9017. return 0;
  9018. }
  9019. Spawn* spawn = 0;
  9020. if (location->entities[0]) {
  9021. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9022. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9023. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9024. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9025. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9026. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9027. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9028. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9029. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9030. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9031. if(spawn && spawn->IsOmittedByDBFlag())
  9032. {
  9033. 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);
  9034. safe_delete(spawn);
  9035. continue;
  9036. }
  9037. if (spawn) {
  9038. const char* script = 0;
  9039. for (int x = 0; x < 3; x++) {
  9040. switch (x) {
  9041. case 0:
  9042. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9043. break;
  9044. case 1:
  9045. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9046. break;
  9047. case 2:
  9048. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9049. break;
  9050. }
  9051. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9052. spawn->SetSpawnScript(string(script));
  9053. break;
  9054. }
  9055. }
  9056. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9057. lua_interface->SetSpawnValue(state, spawn);
  9058. group.push_back(spawn);
  9059. }
  9060. else {
  9061. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9062. safe_delete(spawn);
  9063. }
  9064. }
  9065. }
  9066. if (!group.empty()) {
  9067. lua_createtable(state, group.size(), 0);
  9068. int newTable = lua_gettop(state);
  9069. for (int32 i = 0; i < group.size(); i++) {
  9070. lua_interface->SetSpawnValue(state, group[i]);
  9071. lua_rawseti(state, newTable, i + 1);
  9072. }
  9073. }
  9074. else
  9075. lua_pushnil(state);
  9076. return 1;
  9077. }
  9078. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9079. if (!lua_interface)
  9080. return 0;
  9081. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9082. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9083. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9084. if (!spawn) {
  9085. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9086. return 0;
  9087. }
  9088. if (anim_id == 0) {
  9089. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9090. return 0;
  9091. }
  9092. if (leeway == 0)
  9093. leeway = 5000;
  9094. spawn->SetSpawnAnim(anim_id);
  9095. spawn->SetSpawnAnimLeeway(leeway);
  9096. return 0;
  9097. }
  9098. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9099. if (!lua_interface)
  9100. return 0;
  9101. Spawn* player = lua_interface->GetSpawn(state);
  9102. if (!player) {
  9103. return 0;
  9104. }
  9105. Client* client = player->GetZone()->GetClientBySpawn(player);
  9106. if (!client) {
  9107. return 0;
  9108. }
  9109. lua_interface->SetInt32Value(state, client->GetVersion());
  9110. return 1;
  9111. }
  9112. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9113. if (!lua_interface)
  9114. return 0;
  9115. Item* item = lua_interface->GetItem(state);
  9116. if (!item) {
  9117. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9118. return 0;
  9119. }
  9120. lua_interface->SetInt32Value(state, item->details.item_id);
  9121. return 1;
  9122. }
  9123. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9124. if (!lua_interface)
  9125. return 0;
  9126. Spawn* spawn = lua_interface->GetSpawn(state);
  9127. if (!spawn) {
  9128. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9129. return 0;
  9130. }
  9131. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9132. return 1;
  9133. }
  9134. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9135. if (!lua_interface)
  9136. return 0;
  9137. Spawn* spawn = lua_interface->GetSpawn(state);
  9138. if (!spawn) {
  9139. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9140. return 0;
  9141. }
  9142. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9143. return 1;
  9144. }
  9145. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9146. if (!lua_interface)
  9147. return 0;
  9148. Spawn* spawn = lua_interface->GetSpawn(state);
  9149. if (!spawn) {
  9150. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9151. return 0;
  9152. }
  9153. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9154. return 1;
  9155. }
  9156. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9157. if (!lua_interface)
  9158. return 0;
  9159. Spawn* spawn = lua_interface->GetSpawn(state);
  9160. if (!spawn) {
  9161. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9162. return 0;
  9163. }
  9164. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9165. return 1;
  9166. }
  9167. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9168. if (!lua_interface)
  9169. return 0;
  9170. Spawn* spawn = lua_interface->GetSpawn(state);
  9171. float pct = lua_interface->GetFloatValue(state, 2);
  9172. if (!spawn) {
  9173. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9174. return 0;
  9175. }
  9176. if (pct == 0) {
  9177. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9178. return 0;
  9179. }
  9180. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9181. lua_interface->SetInt32Value(state, amount);
  9182. return 1;
  9183. }
  9184. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9185. if (!lua_interface)
  9186. return 0;
  9187. Spawn* spawn = lua_interface->GetSpawn(state);
  9188. float pct = lua_interface->GetFloatValue(state, 2);
  9189. if (!spawn) {
  9190. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9191. return 0;
  9192. }
  9193. if (pct == 0) {
  9194. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9195. return 0;
  9196. }
  9197. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9198. lua_interface->SetInt32Value(state, amount);
  9199. return 1;
  9200. }
  9201. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9202. if (!lua_interface)
  9203. return 0;
  9204. Spawn* spawn = lua_interface->GetSpawn(state);
  9205. if (!spawn) {
  9206. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9207. return 0;
  9208. }
  9209. if (!spawn->IsPlayer()) {
  9210. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9211. return 0;
  9212. }
  9213. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9214. return 1;
  9215. }
  9216. int EQ2Emu_lua_Evac(lua_State* state) {
  9217. if (!lua_interface)
  9218. return 0;
  9219. Spawn* target = lua_interface->GetSpawn(state);
  9220. if (target) {
  9221. float x = target->GetZone()->GetSafeX();
  9222. float y = target->GetZone()->GetSafeY();
  9223. float z = target->GetZone()->GetSafeZ();
  9224. float h = target->GetZone()->GetSafeHeading();
  9225. target->SetX(x);
  9226. target->SetY(y);
  9227. target->SetZ(z);
  9228. target->SetHeading(h);
  9229. target->SetSpawnOrigX(x);
  9230. target->SetSpawnOrigY(y);
  9231. target->SetSpawnOrigZ(z);
  9232. target->SetSpawnOrigHeading(h);
  9233. if (target->IsPlayer()) {
  9234. Client* client = target->GetZone()->GetClientBySpawn(target);
  9235. if (client) {
  9236. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9237. int numargs = lua_interface->GetNumberOfArgs(state);
  9238. if(numargs == 4) {
  9239. x = lua_interface->GetFloatValue(state,1);
  9240. y = lua_interface->GetFloatValue(state,2);
  9241. z = lua_interface->GetFloatValue(state,3);
  9242. h = lua_interface->GetFloatValue(state,4);
  9243. }
  9244. client->SetReloadingZone(true);
  9245. target->SetX(x);
  9246. target->SetY(y);
  9247. target->SetZ(z);
  9248. target->SetHeading(h);
  9249. target->SetSpawnOrigX(x);
  9250. target->SetSpawnOrigY(y);
  9251. target->SetSpawnOrigZ(z);
  9252. target->SetSpawnOrigHeading(h);
  9253. target->SetAppearancePosition(x,y,z);
  9254. client->SetZoningCoords(x,y,z,h);
  9255. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9256. if (packet)
  9257. {
  9258. packet->setDataByName("x", x);
  9259. packet->setDataByName("y", y);
  9260. packet->setDataByName("z", z);
  9261. client->QueuePacket(packet->serialize());
  9262. safe_delete(packet);
  9263. }
  9264. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9265. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9266. }
  9267. }
  9268. }
  9269. else {
  9270. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9271. if(!spell)
  9272. return 0;
  9273. ZoneServer* zone = spell->caster->GetZone();
  9274. float x = spell->caster->GetZone()->GetSafeX();
  9275. float y = spell->caster->GetZone()->GetSafeY();
  9276. float z = spell->caster->GetZone()->GetSafeZ();
  9277. float h = spell->caster->GetZone()->GetSafeHeading();
  9278. int numargs = lua_interface->GetNumberOfArgs(state);
  9279. if(numargs == 4) {
  9280. x = lua_interface->GetFloatValue(state,1);
  9281. y = lua_interface->GetFloatValue(state,2);
  9282. z = lua_interface->GetFloatValue(state,3);
  9283. h = lua_interface->GetFloatValue(state,4);
  9284. }
  9285. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9286. for (int32 i = 0; i < spell->targets.size(); i++) {
  9287. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9288. if (!target2)
  9289. continue;
  9290. if (target2->IsPlayer()) {
  9291. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9292. if (client) {
  9293. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9294. client->SetReloadingZone(true);
  9295. target2->SetX(x);
  9296. target2->SetY(y);
  9297. target2->SetZ(z);
  9298. target2->SetHeading(h);
  9299. target2->SetSpawnOrigX(x);
  9300. target2->SetSpawnOrigY(y);
  9301. target2->SetSpawnOrigZ(z);
  9302. target2->SetSpawnOrigHeading(h);
  9303. target2->SetAppearancePosition(x,y,z);
  9304. client->SetZoningCoords(x,y,z,h);
  9305. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9306. if (packet)
  9307. {
  9308. packet->setDataByName("x", x);
  9309. packet->setDataByName("y", y);
  9310. packet->setDataByName("z", z);
  9311. client->QueuePacket(packet->serialize());
  9312. safe_delete(packet);
  9313. }
  9314. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9315. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9316. }
  9317. }
  9318. }
  9319. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9320. }
  9321. return 0;
  9322. }
  9323. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9324. if (!lua_interface)
  9325. return 0;
  9326. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9327. if (!luaspell) {
  9328. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9329. return 0;
  9330. }
  9331. int8 tier = luaspell->spell->GetSpellTier();
  9332. lua_interface->SetInt32Value(state, tier);
  9333. return 1;
  9334. }
  9335. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9336. if (!lua_interface)
  9337. return 0;
  9338. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9339. if (!luaspell) {
  9340. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9341. return 0;
  9342. }
  9343. int32 spell_id = luaspell->spell->GetSpellID();
  9344. lua_interface->SetInt32Value(state, spell_id);
  9345. return 1;
  9346. }
  9347. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9348. if (!lua_interface)
  9349. return 0;
  9350. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9351. if (!spawn) {
  9352. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9353. return 0;
  9354. }
  9355. if (!spawn->IsPlayer()) {
  9356. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9357. return 0;
  9358. }
  9359. ZoneServer* zone = spawn->GetZone();
  9360. if (!zone) {
  9361. return 0;
  9362. }
  9363. Client* client = zone->GetClientBySpawn(spawn);
  9364. if (!client) {
  9365. return 0;
  9366. }
  9367. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9368. return 0;
  9369. }
  9370. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9371. if (!lua_interface)
  9372. return 0;
  9373. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9374. if (!spawn) {
  9375. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9376. return 0;
  9377. }
  9378. if (!spawn->IsPlayer()) {
  9379. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9380. return 0;
  9381. }
  9382. ZoneServer* zone = spawn->GetZone();
  9383. if (!zone) {
  9384. return 0;
  9385. }
  9386. Client* client = zone->GetClientBySpawn(spawn);
  9387. if (!client) {
  9388. return 0;
  9389. }
  9390. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9391. return 0;
  9392. }
  9393. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9394. if (!lua_interface)
  9395. return 0;
  9396. Spawn* caster = lua_interface->GetSpawn(state);
  9397. Spawn* target = lua_interface->GetSpawn(state, 2);
  9398. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9399. string spell_name = lua_interface->GetStringValue(state, 4);
  9400. if (!caster) {
  9401. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9402. return 0;
  9403. }
  9404. if (!caster->IsEntity()) {
  9405. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9406. return 0;
  9407. }
  9408. if (!target) {
  9409. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9410. return 0;
  9411. }
  9412. if (!target->IsEntity()) {
  9413. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9414. return 0;
  9415. }
  9416. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9417. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9418. return 0;
  9419. }
  9420. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9421. if (!lua_interface)
  9422. return 0;
  9423. Spawn* player = lua_interface->GetSpawn(state);
  9424. int32 amount = lua_interface->GetInt32Value(state, 2);
  9425. if (player && player->IsPlayer() && amount > 0) {
  9426. ((Player*)player)->AddXP(amount);
  9427. ((Player*)player)->SetCharSheetChanged(true);
  9428. Client* client = player->GetZone()->GetClientBySpawn(player);
  9429. if (client) {
  9430. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9431. }
  9432. }
  9433. return 0;
  9434. }
  9435. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9436. if (!lua_interface)
  9437. return 0;
  9438. Spawn* player = lua_interface->GetSpawn(state);
  9439. int8 type = lua_interface->GetInt8Value(state, 2);
  9440. string text = lua_interface->GetStringValue(state, 3);
  9441. Client* client = 0;
  9442. if (player && player->IsPlayer())
  9443. client = player->GetZone()->GetClientBySpawn(player);
  9444. if (!client || text.length() == 0) {
  9445. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9446. return 0;
  9447. }
  9448. client->SimpleMessage(type, text.c_str());
  9449. return 0;
  9450. }
  9451. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9452. if (!lua_interface)
  9453. return 0;
  9454. Spawn* player = lua_interface->GetSpawn(state);
  9455. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9456. Client* client = 0;
  9457. if (player && player->IsPlayer())
  9458. client = player->GetZone()->GetClientBySpawn(player);
  9459. if (!client || !spawn) {
  9460. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9461. return 0;
  9462. }
  9463. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9464. if (!items) {
  9465. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9466. return 0;
  9467. }
  9468. client->Loot(spawn->GetLootCoins(), items, spawn);
  9469. return 0;
  9470. }
  9471. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9472. if (!lua_interface)
  9473. return 0;
  9474. Spawn* spawnref = lua_interface->GetSpawn(state);
  9475. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9476. if (spawn_id > 0 && spawnref) {
  9477. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9478. if (spawns.size() == 0) {
  9479. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9480. return 0;
  9481. }
  9482. Spawn* spawn = 0;
  9483. int16 index = MakeRandomInt(0, spawns.size());
  9484. if (index >= spawns.size() || index < 0)
  9485. index = 0;
  9486. spawn = spawns[index];
  9487. lua_interface->SetSpawnValue(state, spawn);
  9488. return 1;
  9489. }
  9490. else {
  9491. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9492. }
  9493. return 0;
  9494. }
  9495. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9496. Spawn* player = lua_interface->GetSpawn(state);
  9497. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9498. string name = lua_interface->GetStringValue(state, 3);
  9499. float distance = lua_interface->GetFloatValue(state, 4);
  9500. string command = lua_interface->GetStringValue(state, 5);
  9501. string error_text = lua_interface->GetStringValue(state, 6);
  9502. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9503. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9504. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9505. if (distance == 0)
  9506. distance = 10.0f;
  9507. if (command.length() == 0)
  9508. command = name;
  9509. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9510. if (spawns.size() == 0) {
  9511. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9512. return 0;
  9513. }
  9514. Spawn* spawn = 0;
  9515. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9516. spawn = *itr;
  9517. if (spawn) {
  9518. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9519. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9520. }
  9521. }
  9522. }
  9523. return 0;
  9524. }
  9525. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9526. if (!lua_interface)
  9527. return 0;
  9528. Client* client = 0;
  9529. Spawn* player = lua_interface->GetSpawn(state);
  9530. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9531. if (player && player->IsPlayer() && player->GetZone())
  9532. client = player->GetZone()->GetClientBySpawn(player);
  9533. else{
  9534. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9535. return 0;
  9536. }
  9537. if (client) {
  9538. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9539. if (packet) {
  9540. packet->setDataByName("goal_num", goal_num);
  9541. client->QueuePacket(packet->serialize());
  9542. safe_delete(packet);
  9543. }
  9544. }
  9545. return 0;
  9546. }
  9547. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9548. if (!lua_interface)
  9549. return 0;
  9550. Client* client = 0;
  9551. Spawn* player = lua_interface->GetSpawn(state);
  9552. if (player && player->IsPlayer() && player->GetZone())
  9553. client = player->GetZone()->GetClientBySpawn(player);
  9554. else {
  9555. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9556. return 0;
  9557. }
  9558. if (client) {
  9559. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9560. }
  9561. return 0;
  9562. }
  9563. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9564. if (!lua_interface)
  9565. return 0;
  9566. Client* client = 0;
  9567. Spawn* player = lua_interface->GetSpawn(state);
  9568. float duration = lua_interface->GetFloatValue(state, 2);
  9569. string text = lua_interface->GetStringValue(state, 3);
  9570. string voice = lua_interface->GetStringValue(state, 4);
  9571. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9572. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9573. string signal = lua_interface->GetStringValue(state, 7);
  9574. string goal1 = lua_interface->GetStringValue(state, 8);
  9575. string task1 = lua_interface->GetStringValue(state, 9);
  9576. string goal2 = lua_interface->GetStringValue(state, 10);
  9577. string task2 = lua_interface->GetStringValue(state, 11);
  9578. string goal3 = lua_interface->GetStringValue(state, 12);
  9579. string task3 = lua_interface->GetStringValue(state, 13);
  9580. string goal4 = lua_interface->GetStringValue(state, 14);
  9581. string task4 = lua_interface->GetStringValue(state, 15);
  9582. if (!player) {
  9583. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9584. return 0;
  9585. }
  9586. if (!player->IsPlayer()) {
  9587. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9588. return 0;
  9589. }
  9590. else
  9591. client = ((Player*)player)->GetClient();
  9592. if (!client) {
  9593. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9594. return 0;
  9595. }
  9596. if (text.length() == 0) {
  9597. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9598. return 0;
  9599. }
  9600. if (duration >= 0 && duration < 2)
  9601. duration = 2;
  9602. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9603. if (packet) {
  9604. packet->setDataByName("open_seconds_max", duration);
  9605. packet->setDataByName("text", text.c_str());
  9606. packet->setDataByName("voice", voice.c_str());
  9607. int8 num_goals = 1;
  9608. if (task2.length() > 0)
  9609. num_goals++;
  9610. if (task3.length() > 0)
  9611. num_goals++;
  9612. if (task4.length() > 0)
  9613. num_goals++;
  9614. packet->setArrayLengthByName("num_goals", num_goals);
  9615. for (int8 i = 0; i < num_goals; i++) {
  9616. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9617. }
  9618. if (goal1.length() > 0)
  9619. packet->setArrayDataByName("goal_text", goal1.c_str());
  9620. if (goal2.length() > 0)
  9621. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9622. if (goal3.length() > 0)
  9623. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9624. if (goal4.length() > 0)
  9625. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9626. packet->setSubArrayDataByName("task_text", task1.c_str());
  9627. if (task2.length() > 0)
  9628. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9629. if (task3.length() > 0)
  9630. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9631. if (task4.length() > 0)
  9632. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9633. packet->setDataByName("complete_sound", "click");
  9634. packet->setDataByName("signal", signal.c_str());
  9635. packet->setDataByName("voice_key1", voice_key1);
  9636. packet->setDataByName("voice_key2", voice_key2);
  9637. client->QueuePacket(packet->serialize());
  9638. safe_delete(packet);
  9639. }
  9640. return 0;
  9641. }
  9642. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9643. if (!lua_interface)
  9644. return 0;
  9645. Client* client = 0;
  9646. Spawn* player = lua_interface->GetSpawn(state);
  9647. string window = lua_interface->GetStringValue(state, 2);
  9648. int8 show = lua_interface->GetInt8Value(state, 3);
  9649. if (!player) {
  9650. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9651. return 0;
  9652. }
  9653. if (!player->IsPlayer()) {
  9654. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9655. return 0;
  9656. }
  9657. else
  9658. client = ((Player*)player)->GetClient();
  9659. if (!client) {
  9660. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9661. return 0;
  9662. }
  9663. if (window.length() == 0) {
  9664. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9665. return 0;
  9666. }
  9667. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9668. if (packet) {
  9669. packet->setDataByName("window", window.c_str());
  9670. packet->setDataByName("show", show);
  9671. client->QueuePacket(packet->serialize());
  9672. safe_delete(packet);
  9673. }
  9674. return 0;
  9675. }
  9676. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9677. //See GameEvents.txt for options that can be used for this function
  9678. if (!lua_interface)
  9679. return 0;
  9680. Client* client = 0;
  9681. Spawn* player = lua_interface->GetSpawn(state);
  9682. string event_name = lua_interface->GetStringValue(state, 2);
  9683. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9684. if (!player || !player->IsPlayer()) {
  9685. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9686. return 0;
  9687. }
  9688. if (player->GetZone())
  9689. client = player->GetZone()->GetClientBySpawn(player);
  9690. if (!client) {
  9691. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9692. return 0;
  9693. }
  9694. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9695. if (packet) {
  9696. packet->setDataByName("event_name", event_name.c_str());
  9697. packet->setDataByName("enabled", enabled);
  9698. client->QueuePacket(packet->serialize());
  9699. safe_delete(packet);
  9700. }
  9701. return 0;
  9702. }
  9703. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9704. if (!lua_interface)
  9705. return 0;
  9706. Spawn* player = lua_interface->GetSpawn(state);
  9707. if (player && player->IsPlayer()) {
  9708. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9709. return 1;
  9710. }
  9711. return 0;
  9712. }
  9713. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9714. if (!lua_interface)
  9715. return 0;
  9716. Spawn* player = lua_interface->GetSpawn(state);
  9717. int8 step = lua_interface->GetInt8Value(state, 2);
  9718. if (player && player->IsPlayer() && step > 0) {
  9719. ((Player*)player)->SetTutorialStep(step);
  9720. }
  9721. return 0;
  9722. }
  9723. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9724. if (!lua_interface)
  9725. return 0;
  9726. Client* client = 0;
  9727. Spawn* player = lua_interface->GetSpawn(state);
  9728. string window = lua_interface->GetStringValue(state, 2);
  9729. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9730. if (!player) {
  9731. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9732. return 0;
  9733. }
  9734. if (!player->IsPlayer()) {
  9735. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9736. return 0;
  9737. }
  9738. else
  9739. client = ((Player*)player)->GetClient();
  9740. if (!client) {
  9741. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9742. return 0;
  9743. }
  9744. if (window.length() == 0) {
  9745. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9746. return 0;
  9747. }
  9748. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9749. if (packet) {
  9750. packet->setDataByName("window", window.c_str());
  9751. packet->setDataByName("flash_seconds", flash_seconds);
  9752. client->QueuePacket(packet->serialize());
  9753. safe_delete(packet);
  9754. }
  9755. return 0;
  9756. }
  9757. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9758. if (!lua_interface)
  9759. return 0;
  9760. Spawn* spawn = lua_interface->GetSpawn(state);
  9761. Spawn* target = lua_interface->GetSpawn(state, 2);
  9762. if (spawn && target)
  9763. return spawn->CheckLoS(target);
  9764. return 0;
  9765. }
  9766. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9767. if (!lua_interface)
  9768. return 0;
  9769. Spawn* spawn = lua_interface->GetSpawn(state);
  9770. float x = lua_interface->GetFloatValue(state, 2);
  9771. float y = lua_interface->GetFloatValue(state, 3);
  9772. float z = lua_interface->GetFloatValue(state, 4);
  9773. if (spawn)
  9774. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9775. return 0;
  9776. }
  9777. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9778. if (!lua_interface)
  9779. return 0;
  9780. ZoneServer* zone = lua_interface->GetZone(state);
  9781. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9782. if (zone)
  9783. zone->SetExpansionFlag(xpackFlag);
  9784. return 0;
  9785. }
  9786. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9787. if (!lua_interface)
  9788. return 0;
  9789. ZoneServer* zone = lua_interface->GetZone(state);
  9790. if (zone) {
  9791. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9792. return 1;
  9793. }
  9794. return 0;
  9795. }
  9796. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9797. if (!lua_interface)
  9798. return 0;
  9799. ZoneServer* zone = lua_interface->GetZone(state);
  9800. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9801. if (zone)
  9802. zone->SetHolidayFlag(holidayFlag);
  9803. return 0;
  9804. }
  9805. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9806. if (!lua_interface)
  9807. return 0;
  9808. ZoneServer* zone = lua_interface->GetZone(state);
  9809. if (zone) {
  9810. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9811. return 1;
  9812. }
  9813. return 0;
  9814. }
  9815. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  9816. if (!lua_interface)
  9817. return 0;
  9818. Spawn* player = lua_interface->GetSpawn(state);
  9819. ZoneServer* zone = player->GetZone();
  9820. bool canbind = lua_interface->GetInt32Value(state, 2);
  9821. if (zone)
  9822. zone->SetCanBind(canbind);
  9823. return 0;
  9824. }
  9825. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  9826. if (!lua_interface)
  9827. return 0;
  9828. Spawn* player = lua_interface->GetSpawn(state);
  9829. ZoneServer* zone = player->GetZone();
  9830. if (zone) {
  9831. lua_interface->SetInt32Value(state, zone->GetCanBind());
  9832. return 1;
  9833. }
  9834. return 0;
  9835. }
  9836. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  9837. if (!lua_interface)
  9838. return 0;
  9839. Spawn* player = lua_interface->GetSpawn(state);
  9840. ZoneServer* zone = player->GetZone();
  9841. bool cangate = lua_interface->GetInt32Value(state, 2);
  9842. if (zone)
  9843. zone->SetCanGate(cangate);
  9844. return 0;
  9845. }
  9846. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  9847. if (!lua_interface)
  9848. return 0;
  9849. Spawn* player = lua_interface->GetSpawn(state);
  9850. ZoneServer* zone = player->GetZone();
  9851. if (zone) {
  9852. lua_interface->SetInt32Value(state, zone->GetCanGate());
  9853. return 1;
  9854. }
  9855. return 0;
  9856. }
  9857. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9858. if (!lua_interface)
  9859. return 0;
  9860. Spawn* spawn = lua_interface->GetSpawn(state);
  9861. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9862. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9863. float distance = lua_interface->GetFloatValue(state, 4);
  9864. string in_range_function = lua_interface->GetStringValue(state, 5);
  9865. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9866. if (spawn && distance > 0 && in_range_function.length() > 0)
  9867. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9868. return 0;
  9869. }
  9870. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9871. if (!lua_interface)
  9872. return 0;
  9873. Spawn* spawn = lua_interface->GetSpawn(state);
  9874. Spawn* target = lua_interface->GetSpawn(state, 2);
  9875. if (spawn && target)
  9876. {
  9877. if (spawn->IsPlayer() && target->IsEntity())
  9878. {
  9879. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9880. return 1;
  9881. }
  9882. else if (spawn->IsEntity() && target->IsEntity())
  9883. {
  9884. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9885. return 1;
  9886. }
  9887. }
  9888. return 0;
  9889. }
  9890. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9891. if (!lua_interface)
  9892. return 0;
  9893. Spawn* spawn = lua_interface->GetSpawn(state);
  9894. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9895. if (spawn && spawn->IsEntity())
  9896. {
  9897. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9898. if (spawn->IsPlayer())
  9899. {
  9900. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9901. if (client)
  9902. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9903. }
  9904. }
  9905. return 0;
  9906. }
  9907. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9908. if (!lua_interface)
  9909. return 0;
  9910. Spawn* spawn = lua_interface->GetSpawn(state);
  9911. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9912. if (spawn && spawn->IsEntity())
  9913. {
  9914. ((Entity*)spawn)->SetSeeHideSpell(val);
  9915. if (spawn->IsPlayer())
  9916. {
  9917. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9918. if (client)
  9919. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9920. }
  9921. }
  9922. return 0;
  9923. }
  9924. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9925. {
  9926. if (!lua_interface)
  9927. return 0;
  9928. Spawn* player = lua_interface->GetSpawn(state);
  9929. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9930. string command = lua_interface->GetStringValue(state, 3);
  9931. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9932. lua_interface->ResetFunctionStack(state);
  9933. if (spawn && player && player->IsPlayer())
  9934. {
  9935. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9936. bool res = false;
  9937. if (cmd)
  9938. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9939. lua_interface->SetBooleanValue(state, res);
  9940. return 1;
  9941. }
  9942. return 0;
  9943. }
  9944. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9945. {
  9946. if (!lua_interface)
  9947. return 0;
  9948. Spawn* spawn = lua_interface->GetSpawn(state);
  9949. int32 charID = lua_interface->GetInt32Value(state, 2);
  9950. string command = lua_interface->GetStringValue(state, 3);
  9951. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9952. lua_interface->ResetFunctionStack(state);
  9953. if (spawn && charID)
  9954. {
  9955. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9956. bool res = false;
  9957. if (cmd)
  9958. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9959. lua_interface->SetBooleanValue(state, res);
  9960. return 1;
  9961. }
  9962. return 0;
  9963. }
  9964. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9965. {
  9966. if (!lua_interface)
  9967. return 0;
  9968. Spawn* spawn = lua_interface->GetSpawn(state);
  9969. string command = lua_interface->GetStringValue(state, 2);
  9970. lua_interface->ResetFunctionStack(state);
  9971. if (spawn && command.length() > 0)
  9972. spawn->RemovePrimaryEntityCommand(command.c_str());
  9973. return 0;
  9974. }
  9975. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9976. if (!lua_interface)
  9977. return 0;
  9978. Spawn* spawn = lua_interface->GetSpawn(state);
  9979. float distance = lua_interface->GetFloatValue(state, 2);
  9980. string command = lua_interface->GetStringValue(state, 3);
  9981. Spawn* player = lua_interface->GetSpawn(state, 4);
  9982. lua_interface->ResetFunctionStack(state);
  9983. if (spawn) {
  9984. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9985. }
  9986. return 0;
  9987. }
  9988. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9989. if (!lua_interface)
  9990. return 0;
  9991. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9992. Spawn* spawn = lua_interface->GetSpawn(state);
  9993. Spawn* player = lua_interface->GetSpawn(state, 2);
  9994. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9995. lua_interface->ResetFunctionStack(state);
  9996. if (spawn && player && transport_id && player->IsPlayer()) {
  9997. Client* client = 0;
  9998. if (player && player->IsPlayer())
  9999. client = player->GetZone()->GetClientBySpawn(player);
  10000. if (!client)
  10001. return 0;
  10002. vector<TransportDestination*> destinations;
  10003. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10004. if (destinations.size())
  10005. {
  10006. client->SetTemporaryTransportID(transport_id);
  10007. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10008. }
  10009. else
  10010. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10011. }
  10012. return 0;
  10013. }
  10014. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10015. if (!lua_interface)
  10016. return 0;
  10017. Spawn* player = lua_interface->GetSpawn(state);
  10018. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10019. lua_interface->ResetFunctionStack(state);
  10020. if (player && player->IsPlayer()) {
  10021. Client* client = 0;
  10022. if (player && player->IsPlayer())
  10023. client = player->GetZone()->GetClientBySpawn(player);
  10024. if (!client)
  10025. return 0;
  10026. client->SetTemporaryTransportID(transport_id);
  10027. }
  10028. return 0;
  10029. }
  10030. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10031. if (!lua_interface)
  10032. return 0;
  10033. Spawn* player = lua_interface->GetSpawn(state);
  10034. lua_interface->ResetFunctionStack(state);
  10035. if (player && player->IsPlayer()) {
  10036. Client* client = 0;
  10037. if (player && player->IsPlayer())
  10038. client = player->GetZone()->GetClientBySpawn(player);
  10039. if (!client)
  10040. return 0;
  10041. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10042. return 1;
  10043. }
  10044. return 0;
  10045. }
  10046. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10047. if (!lua_interface)
  10048. return 0;
  10049. Spawn* spawn = lua_interface->GetSpawn(state);
  10050. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10051. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10052. if (!spawn) {
  10053. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10054. return 0;
  10055. }
  10056. if (!spawn->IsEntity()) {
  10057. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10058. return 0;
  10059. }
  10060. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10061. {
  10062. 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);
  10063. return 0;
  10064. }
  10065. lua_interface->ResetFunctionStack(state);
  10066. if (spell && spell->targets.size() > 0) {
  10067. ZoneServer* zone = spell->caster->GetZone();
  10068. for (int8 i = 0; i < spell->targets.size(); i++) {
  10069. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10070. if (target && target->IsEntity()) {
  10071. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10072. if (target->IsPlayer())
  10073. ((Player*)target)->SetCharSheetChanged(true);
  10074. }
  10075. }
  10076. }
  10077. else {
  10078. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10079. if (spawn->IsPlayer())
  10080. ((Player*)spawn)->SetCharSheetChanged(true);
  10081. }
  10082. return 0;
  10083. }
  10084. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10085. if (!lua_interface)
  10086. return 0;
  10087. Spawn* spawn = lua_interface->GetSpawn(state);
  10088. lua_interface->ResetFunctionStack(state);
  10089. if (!spawn) {
  10090. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10091. return 0;
  10092. }
  10093. if (!spawn->IsEntity()) {
  10094. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10095. return 0;
  10096. }
  10097. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10098. return 1;
  10099. }
  10100. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10101. if (!lua_interface)
  10102. return 0;
  10103. int32 spell_id = lua_interface->GetInt32Value(state);
  10104. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10105. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10106. if (spell_id > 0) {
  10107. if (spell_tier == 0)
  10108. spell_tier = 1;
  10109. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10110. LuaSpell* lua_spell = 0;
  10111. if(custom_lua_script.size() > 0)
  10112. {
  10113. // attempt to load the custom script since it isn't already loaded
  10114. // we will re-obtain the lua_spell further below
  10115. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10116. {
  10117. 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());
  10118. lua_interface->LoadLuaSpell(custom_lua_script);
  10119. }
  10120. }
  10121. else
  10122. custom_lua_script = spell->GetSpellData()->lua_script;
  10123. if (!lua_spell && lua_interface)
  10124. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10125. if (!lua_spell)
  10126. {
  10127. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10128. return 0;
  10129. }
  10130. lua_spell->spell = new Spell(spell);
  10131. lua_interface->AddCustomSpell(lua_spell);
  10132. lua_interface->SetSpellValue(state, lua_spell);
  10133. return 1;
  10134. }
  10135. return 0;
  10136. }
  10137. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10138. if (!lua_interface)
  10139. return 0;
  10140. LuaSpell* spell = lua_interface->GetSpell(state);
  10141. string field = lua_interface->GetStringValue(state, 2);
  10142. if (!spell) {
  10143. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10144. return 0;
  10145. }
  10146. if (!spell->spell || !spell->spell->GetSpellData()) {
  10147. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10148. return 0;
  10149. }
  10150. boost::to_lower(field);
  10151. return spell->spell->GetSpellData(state, field);
  10152. }
  10153. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10154. if (!lua_interface)
  10155. return 0;
  10156. LuaSpell* spell = lua_interface->GetSpell(state);
  10157. string field = lua_interface->GetStringValue(state, 2);
  10158. int8 fieldArg = 3; // field value after the initial set
  10159. if (!spell) {
  10160. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10161. return 0;
  10162. }
  10163. if (!spell->spell || !spell->spell->GetSpellData()) {
  10164. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10165. return 0;
  10166. }
  10167. boost::to_lower(field);
  10168. bool valSet = false;
  10169. spell->spell->SetSpellData(state, field, fieldArg);
  10170. return valSet;
  10171. }
  10172. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10173. if (!lua_interface)
  10174. return 0;
  10175. LuaSpell* spell = lua_interface->GetSpell(state);
  10176. int8 idx = lua_interface->GetInt32Value(state, 2);
  10177. if (!spell) {
  10178. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10179. return 0;
  10180. }
  10181. if (!spell->spell || !spell->spell->GetSpellData()) {
  10182. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10183. return 0;
  10184. }
  10185. if (spell->spell->lua_data.size() <= idx)
  10186. {
  10187. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10188. return 0;
  10189. }
  10190. bool setVal = true;
  10191. LUAData* data = spell->spell->lua_data[idx];
  10192. switch (data->type)
  10193. {
  10194. case 0:
  10195. {
  10196. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10197. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10198. data->int_value = value;
  10199. data->int_value2 = value2;
  10200. break;
  10201. }
  10202. case 1:
  10203. {
  10204. float value = lua_interface->GetFloatValue(state, 3);
  10205. float value2 = lua_interface->GetFloatValue(state, 4);
  10206. data->float_value = value;
  10207. data->float_value2 = value2;
  10208. break;
  10209. }
  10210. case 2:
  10211. {
  10212. bool value = lua_interface->GetBooleanValue(state, 3);
  10213. data->bool_value = value;
  10214. break;
  10215. }
  10216. case 3:
  10217. {
  10218. string value = lua_interface->GetStringValue(state, 3);
  10219. string value2 = lua_interface->GetStringValue(state, 4);
  10220. data->string_value = value;
  10221. data->string_value2 = value2;
  10222. break;
  10223. }
  10224. default:
  10225. setVal = false;
  10226. }
  10227. return setVal;
  10228. }
  10229. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10230. if (!lua_interface)
  10231. return 0;
  10232. LuaSpell* spell = lua_interface->GetSpell(state);
  10233. int8 idx = lua_interface->GetInt32Value(state, 2);
  10234. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10235. if (!spell) {
  10236. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10237. return 0;
  10238. }
  10239. if (!spell->spell || !spell->spell->GetSpellData()) {
  10240. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10241. return 0;
  10242. }
  10243. if (spell->spell->lua_data.size() <= idx)
  10244. {
  10245. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10246. return 0;
  10247. }
  10248. bool setVal = true;
  10249. LUAData* data = spell->spell->lua_data[idx];
  10250. switch (data->type)
  10251. {
  10252. case 0:
  10253. {
  10254. if(!secondfield)
  10255. lua_interface->SetSInt32Value(state, data->int_value);
  10256. else
  10257. lua_interface->SetSInt32Value(state, data->int_value2);
  10258. break;
  10259. }
  10260. case 1:
  10261. {
  10262. if (!secondfield)
  10263. lua_interface->SetFloatValue(state, data->float_value);
  10264. else
  10265. lua_interface->SetFloatValue(state, data->float_value2);
  10266. break;
  10267. }
  10268. case 2:
  10269. {
  10270. lua_interface->SetBooleanValue(state, data->bool_value);
  10271. break;
  10272. }
  10273. case 3:
  10274. {
  10275. if (!secondfield)
  10276. lua_interface->SetStringValue(state, data->string_value.c_str());
  10277. else
  10278. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10279. break;
  10280. }
  10281. default:
  10282. setVal = false;
  10283. }
  10284. return setVal;
  10285. }
  10286. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10287. if (!lua_interface)
  10288. return 0;
  10289. LuaSpell* spell = lua_interface->GetSpell(state);
  10290. int8 idx = lua_interface->GetInt32Value(state, 2);
  10291. string field = lua_interface->GetStringValue(state, 3);
  10292. boost::to_lower(field);
  10293. if (!spell) {
  10294. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10295. return 0;
  10296. }
  10297. if (!spell->spell || !spell->spell->GetSpellData()) {
  10298. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10299. return 0;
  10300. }
  10301. if (spell->spell->effects.size() <= idx)
  10302. {
  10303. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10304. return 0;
  10305. }
  10306. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10307. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10308. if (field == "description")
  10309. effect->description = string(lua_interface->GetStringValue(state, 4));
  10310. else if (field == "bullet")
  10311. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10312. else if (field == "percentage")
  10313. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10314. else // no match
  10315. return 0;
  10316. return 1;
  10317. }
  10318. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10319. if (!lua_interface)
  10320. return 0;
  10321. LuaSpell* spell = lua_interface->GetSpell(state);
  10322. int8 idx = lua_interface->GetInt32Value(state, 2);
  10323. string field = lua_interface->GetStringValue(state, 3);
  10324. boost::to_lower(field);
  10325. if (!spell) {
  10326. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10327. return 0;
  10328. }
  10329. if (!spell->spell || !spell->spell->GetSpellData()) {
  10330. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10331. return 0;
  10332. }
  10333. if (spell->spell->effects.size() <= idx)
  10334. {
  10335. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10336. return 0;
  10337. }
  10338. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10339. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10340. if (field == "description")
  10341. lua_interface->SetStringValue(state, effect->description.c_str());
  10342. else if (field == "bullet")
  10343. lua_interface->SetInt32Value(state, effect->subbullet);
  10344. else if (field == "percentage")
  10345. lua_interface->SetInt32Value(state, effect->percentage);
  10346. else // no match
  10347. return 0;
  10348. return 1;
  10349. }
  10350. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10351. if (!lua_interface)
  10352. return 0;
  10353. LuaSpell* spell = lua_interface->GetSpell(state);
  10354. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10355. Spawn* target = lua_interface->GetSpawn(state, 3);
  10356. if (!target) {
  10357. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10358. return 0;
  10359. }
  10360. if (!target->IsEntity()) {
  10361. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10362. return 0;
  10363. }
  10364. if (!spell) {
  10365. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10366. return 0;
  10367. }
  10368. if (caster && !caster->IsEntity()) {
  10369. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10370. return 0;
  10371. }
  10372. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10373. return 0;
  10374. }
  10375. int EQ2Emu_lua_InWater(lua_State* state) {
  10376. if (!lua_interface)
  10377. return 0;
  10378. Spawn* spawn = lua_interface->GetSpawn(state);
  10379. lua_interface->ResetFunctionStack(state);
  10380. if (spawn) {
  10381. lua_interface->SetBooleanValue(state, spawn->InWater());
  10382. return 1;
  10383. }
  10384. return 0;
  10385. }
  10386. int EQ2Emu_lua_InLava(lua_State* state) {
  10387. if (!lua_interface)
  10388. return 0;
  10389. Spawn* spawn = lua_interface->GetSpawn(state);
  10390. lua_interface->ResetFunctionStack(state);
  10391. if (spawn) {
  10392. lua_interface->SetBooleanValue(state, spawn->InLava());
  10393. return 1;
  10394. }
  10395. return 0;
  10396. }
  10397. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10398. if (!lua_interface)
  10399. return 0;
  10400. Spawn* attacker = lua_interface->GetSpawn(state);
  10401. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10402. int8 type = lua_interface->GetInt8Value(state, 3);
  10403. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10404. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10405. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10406. string spell_name = lua_interface->GetStringValue(state, 7);
  10407. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10408. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10409. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10410. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10411. lua_interface->ResetFunctionStack(state);
  10412. if (!attacker) {
  10413. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10414. return 0;
  10415. }
  10416. if (!attacker->IsEntity()) {
  10417. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10418. return 0;
  10419. }
  10420. if (!victim) {
  10421. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10422. return 0;
  10423. }
  10424. if (!victim->IsEntity()) {
  10425. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10426. return 0;
  10427. }
  10428. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10429. return 0;
  10430. }
  10431. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10432. if (!lua_interface)
  10433. return 0;
  10434. Spawn* spawn = lua_interface->GetSpawn(state);
  10435. lua_interface->ResetFunctionStack(state);
  10436. if (spawn) {
  10437. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10438. return 1;
  10439. }
  10440. return 0;
  10441. }
  10442. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10443. if (!lua_interface)
  10444. return 0;
  10445. Spawn* spawn = lua_interface->GetSpawn(state);
  10446. bool invul = lua_interface->GetBooleanValue(state, 2);
  10447. lua_interface->ResetFunctionStack(state);
  10448. if (spawn) {
  10449. spawn->SetInvulnerable(invul);
  10450. }
  10451. return 0;
  10452. }
  10453. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10454. if (!lua_interface)
  10455. return 0;
  10456. string category = lua_interface->GetStringValue(state);
  10457. string name = lua_interface->GetStringValue(state, 2);
  10458. lua_interface->ResetFunctionStack(state);
  10459. Rule *ret = 0;
  10460. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10461. lua_interface->SetBooleanValue(state, ret->GetBool());
  10462. return 1;
  10463. }
  10464. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10465. return 0;
  10466. }
  10467. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10468. if (!lua_interface)
  10469. return 0;
  10470. string category = lua_interface->GetStringValue(state);
  10471. string name = lua_interface->GetStringValue(state, 2);
  10472. lua_interface->ResetFunctionStack(state);
  10473. Rule *ret = 0;
  10474. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10475. lua_interface->SetInt32Value(state, ret->GetInt32());
  10476. return 1;
  10477. }
  10478. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10479. return 0;
  10480. }
  10481. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10482. if (!lua_interface)
  10483. return 0;
  10484. string category = lua_interface->GetStringValue(state);
  10485. string name = lua_interface->GetStringValue(state, 2);
  10486. lua_interface->ResetFunctionStack(state);
  10487. Rule *ret = 0;
  10488. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10489. lua_interface->SetFloatValue(state, ret->GetFloat());
  10490. return 1;
  10491. }
  10492. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10493. return 0;
  10494. }
  10495. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10496. if (!lua_interface)
  10497. return 0;
  10498. Spawn* spawn = lua_interface->GetSpawn(state);
  10499. string type = lua_interface->GetStringValue(state, 2);
  10500. lua_interface->ResetFunctionStack(state);
  10501. if (spawn) {
  10502. int res = 1;
  10503. boost::to_lower(type);
  10504. if(type == "assigned_aa")
  10505. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10506. else if ( type == "unassigned_aa")
  10507. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10508. else if ( type == "assigned_tradeskill_aa")
  10509. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10510. else if ( type == "unassigned_tradeskill_aa")
  10511. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10512. else if ( type == "assigned_prestige_aa")
  10513. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10514. else if ( type == "unassigned_prestige_aa")
  10515. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10516. else if ( type == "assigned_tradeskill_prestige_aa")
  10517. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10518. else if ( type == "unassigned_tradeskill_prestige_aa")
  10519. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10520. else
  10521. res = 0;
  10522. return res;
  10523. }
  10524. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10525. return 0;
  10526. }
  10527. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10528. if (!lua_interface)
  10529. return 0;
  10530. Spawn* spawn = lua_interface->GetSpawn(state);
  10531. string type = lua_interface->GetStringValue(state, 2);
  10532. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10533. lua_interface->ResetFunctionStack(state);
  10534. if (spawn) {
  10535. boost::to_lower(type);
  10536. if(type == "assigned_aa")
  10537. spawn->SetAssignedAA((sint16)value);
  10538. else if ( type == "unassigned_aa")
  10539. spawn->SetUnassignedAA((sint16)value);
  10540. else if ( type == "assigned_tradeskill_aa")
  10541. spawn->SetTradeskillAA((sint16)value);
  10542. else if ( type == "unassigned_tradeskill_aa")
  10543. spawn->SetUnassignedTradeskillAA((sint16)value);
  10544. else if ( type == "assigned_prestige_aa")
  10545. spawn->SetPrestigeAA((sint16)value);
  10546. else if ( type == "unassigned_prestige_aa")
  10547. spawn->SetUnassignedPrestigeAA((sint16)value);
  10548. else if ( type == "assigned_tradeskill_prestige_aa")
  10549. spawn->SetTradeskillPrestigeAA((sint16)value);
  10550. else if ( type == "unassigned_tradeskill_prestige_aa")
  10551. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10552. if(spawn->IsPlayer())
  10553. ((Player*)spawn)->SetCharSheetChanged(true);
  10554. }
  10555. return 0;
  10556. }
  10557. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10558. if (!lua_interface)
  10559. return 0;
  10560. string titleName = lua_interface->GetStringValue(state);
  10561. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10562. lua_interface->ResetFunctionStack(state);
  10563. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10564. lua_interface->SetSInt32Value(state, index);
  10565. return 1;
  10566. }
  10567. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10568. if (!lua_interface)
  10569. return 0;
  10570. Spawn* spawn = lua_interface->GetSpawn(state);
  10571. string titleName = lua_interface->GetStringValue(state, 2);
  10572. lua_interface->ResetFunctionStack(state);
  10573. if(!spawn->IsPlayer())
  10574. {
  10575. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10576. lua_interface->SetSInt32Value(state, -1);
  10577. return 1;
  10578. }
  10579. Player* player = (Player*)spawn;
  10580. // check if player already has the title, don't need to add twice
  10581. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10582. if ( playerHasTitle)
  10583. {
  10584. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10585. return 1;
  10586. }
  10587. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10588. if(!title)
  10589. {
  10590. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10591. lua_interface->SetSInt32Value(state, -1);
  10592. return 1;
  10593. }
  10594. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10595. if(returnIdx < 0)
  10596. {
  10597. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10598. }
  10599. lua_interface->SetSInt32Value(state, returnIdx);
  10600. player->GetClient()->SendTitleUpdate();
  10601. return 1;
  10602. }
  10603. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10604. if (!lua_interface)
  10605. return 0;
  10606. Spawn* spawn = lua_interface->GetSpawn(state);
  10607. string titleName = lua_interface->GetStringValue(state, 2);
  10608. lua_interface->ResetFunctionStack(state);
  10609. if(!spawn->IsPlayer())
  10610. {
  10611. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10612. return 0;
  10613. }
  10614. Player* player = (Player*)spawn;
  10615. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10616. if(!title)
  10617. {
  10618. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10619. return 0;
  10620. }
  10621. if(title->GetPrefix())
  10622. {
  10623. 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());
  10624. return 0;
  10625. }
  10626. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10627. player->GetClient()->SendTitleUpdate();
  10628. return 1;
  10629. }
  10630. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10631. if (!lua_interface)
  10632. return 0;
  10633. Spawn* spawn = lua_interface->GetSpawn(state);
  10634. string titleName = lua_interface->GetStringValue(state, 2);
  10635. lua_interface->ResetFunctionStack(state);
  10636. if(!spawn->IsPlayer())
  10637. {
  10638. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10639. return 0;
  10640. }
  10641. Player* player = (Player*)spawn;
  10642. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10643. if(!title)
  10644. {
  10645. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10646. return 0;
  10647. }
  10648. if(!title->GetPrefix())
  10649. {
  10650. 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());
  10651. return 0;
  10652. }
  10653. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10654. player->GetClient()->SendTitleUpdate();
  10655. return 1;
  10656. }
  10657. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10658. if (!lua_interface)
  10659. return 0;
  10660. Spawn* spawn = lua_interface->GetSpawn(state);
  10661. lua_interface->ResetFunctionStack(state);
  10662. if(!spawn->IsPlayer())
  10663. {
  10664. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10665. return 0;
  10666. }
  10667. Player* player = (Player*)spawn;
  10668. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10669. player->GetClient()->SendTitleUpdate();
  10670. return 1;
  10671. }
  10672. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10673. if (!lua_interface)
  10674. return 0;
  10675. Spawn* spawn = lua_interface->GetSpawn(state);
  10676. lua_interface->ResetFunctionStack(state);
  10677. if(!spawn->IsPlayer())
  10678. {
  10679. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10680. return 0;
  10681. }
  10682. Player* player = (Player*)spawn;
  10683. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10684. player->GetClient()->SendTitleUpdate();
  10685. return 1;
  10686. }
  10687. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10688. if (!lua_interface)
  10689. return 0;
  10690. Spawn* spawn = lua_interface->GetSpawn(state);
  10691. string field = lua_interface->GetStringValue(state, 2);
  10692. lua_interface->ResetFunctionStack(state);
  10693. if(!spawn || !spawn->IsEntity())
  10694. {
  10695. 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));
  10696. return 0;
  10697. }
  10698. Entity* ent = (Entity*)spawn;
  10699. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10700. return 1;
  10701. }
  10702. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10703. if (!lua_interface)
  10704. return 0;
  10705. Spawn* spawn = lua_interface->GetSpawn(state);
  10706. string field = lua_interface->GetStringValue(state, 2);
  10707. lua_interface->ResetFunctionStack(state);
  10708. if(!spawn || !spawn->IsEntity())
  10709. {
  10710. 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));
  10711. return 0;
  10712. }
  10713. Entity* ent = (Entity*)spawn;
  10714. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10715. return 1;
  10716. }
  10717. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10718. if (!lua_interface)
  10719. return 0;
  10720. Spawn* spawn = lua_interface->GetSpawn(state);
  10721. string field = lua_interface->GetStringValue(state, 2);
  10722. lua_interface->ResetFunctionStack(state);
  10723. if(!spawn || !spawn->IsEntity())
  10724. {
  10725. 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));
  10726. return 0;
  10727. }
  10728. Entity* ent = (Entity*)spawn;
  10729. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10730. return 1;
  10731. }
  10732. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10733. if (!lua_interface)
  10734. return 0;
  10735. Spawn* spawn = lua_interface->GetSpawn(state);
  10736. string field = lua_interface->GetStringValue(state, 2);
  10737. lua_interface->ResetFunctionStack(state);
  10738. if(!spawn || !spawn->IsEntity())
  10739. {
  10740. 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));
  10741. return 0;
  10742. }
  10743. Entity* ent = (Entity*)spawn;
  10744. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10745. return 1;
  10746. }
  10747. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10748. if (!lua_interface)
  10749. return 0;
  10750. Spawn* spawn = lua_interface->GetSpawn(state);
  10751. string field = lua_interface->GetStringValue(state, 2);
  10752. string value = lua_interface->GetStringValue(state, 3);
  10753. lua_interface->ResetFunctionStack(state);
  10754. if(!spawn || !spawn->IsEntity())
  10755. {
  10756. 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));
  10757. return 0;
  10758. }
  10759. Entity* ent = (Entity*)spawn;
  10760. bool set_ = ent->SetInfoStructString(field, value);
  10761. lua_interface->SetBooleanValue(state, set_);
  10762. return 1;
  10763. }
  10764. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10765. if (!lua_interface)
  10766. return 0;
  10767. Spawn* spawn = lua_interface->GetSpawn(state);
  10768. string field = lua_interface->GetStringValue(state, 2);
  10769. int64 value = lua_interface->GetInt64Value(state, 3);
  10770. lua_interface->ResetFunctionStack(state);
  10771. if(!spawn || !spawn->IsEntity())
  10772. {
  10773. 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));
  10774. return 0;
  10775. }
  10776. Entity* ent = (Entity*)spawn;
  10777. bool set_ = ent->SetInfoStructUInt(field, value);
  10778. lua_interface->SetBooleanValue(state, set_);
  10779. return 1;
  10780. }
  10781. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10782. if (!lua_interface)
  10783. return 0;
  10784. Spawn* spawn = lua_interface->GetSpawn(state);
  10785. string field = lua_interface->GetStringValue(state, 2);
  10786. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10787. lua_interface->ResetFunctionStack(state);
  10788. if(!spawn || !spawn->IsEntity())
  10789. {
  10790. 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));
  10791. return 0;
  10792. }
  10793. Entity* ent = (Entity*)spawn;
  10794. bool set_ = ent->SetInfoStructSInt(field, value);
  10795. lua_interface->SetBooleanValue(state, set_);
  10796. return 1;
  10797. }
  10798. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10799. if (!lua_interface)
  10800. return 0;
  10801. Spawn* spawn = lua_interface->GetSpawn(state);
  10802. string field = lua_interface->GetStringValue(state, 2);
  10803. float value = lua_interface->GetFloatValue(state, 3);
  10804. lua_interface->ResetFunctionStack(state);
  10805. if(!spawn || !spawn->IsEntity())
  10806. {
  10807. 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));
  10808. return 0;
  10809. }
  10810. Entity* ent = (Entity*)spawn;
  10811. bool set_ = ent->SetInfoStructFloat(field, value);
  10812. lua_interface->SetBooleanValue(state, set_);
  10813. return 1;
  10814. }
  10815. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10816. if (!lua_interface)
  10817. return 0;
  10818. Spawn* spawn = lua_interface->GetSpawn(state);
  10819. bool value = lua_interface->GetBooleanValue(state, 2);
  10820. lua_interface->ResetFunctionStack(state);
  10821. if(!spawn || !spawn->IsPlayer())
  10822. {
  10823. 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));
  10824. return 0;
  10825. }
  10826. ((Player*)spawn)->SetCharSheetChanged(value);
  10827. return 0;
  10828. }
  10829. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10830. if (!lua_interface)
  10831. return 0;
  10832. Spawn* spawn = lua_interface->GetSpawn(state);
  10833. std::string fromName = lua_interface->GetStringValue(state, 2);
  10834. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10835. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10836. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10837. int32 copper = lua_interface->GetInt32Value(state, 6);
  10838. int32 silver = lua_interface->GetInt32Value(state, 7);
  10839. int32 gold = lua_interface->GetInt32Value(state, 8);
  10840. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10841. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10842. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10843. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10844. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10845. lua_interface->ResetFunctionStack(state);
  10846. if(!spawn || !spawn->IsPlayer())
  10847. {
  10848. 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));
  10849. lua_interface->SetBooleanValue(state, false);
  10850. return 1;
  10851. }
  10852. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10853. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10854. lua_interface->SetBooleanValue(state, true);
  10855. return 1;
  10856. }
  10857. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10858. if (!lua_interface)
  10859. return 0;
  10860. int32 char_id = lua_interface->GetInt32Value(state);
  10861. std::string fromName = lua_interface->GetStringValue(state, 2);
  10862. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10863. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10864. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10865. int32 copper = lua_interface->GetInt32Value(state, 6);
  10866. int32 silver = lua_interface->GetInt32Value(state, 7);
  10867. int32 gold = lua_interface->GetInt32Value(state, 8);
  10868. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10869. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10870. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10871. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10872. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10873. lua_interface->ResetFunctionStack(state);
  10874. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10875. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10876. lua_interface->SetBooleanValue(state, true);
  10877. return 1;
  10878. }
  10879. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10880. Spawn* widget;
  10881. if (lua_interface) {
  10882. widget = lua_interface->GetSpawn(state);
  10883. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10884. lua_interface->ResetFunctionStack(state);
  10885. if (widget && widget->IsWidget())
  10886. {
  10887. ((Widget*)widget)->OpenDoor();
  10888. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10889. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10890. }
  10891. else
  10892. 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));
  10893. }
  10894. return 0;
  10895. }
  10896. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10897. Spawn* widget;
  10898. if (lua_interface) {
  10899. widget = lua_interface->GetSpawn(state);
  10900. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10901. lua_interface->ResetFunctionStack(state);
  10902. if (widget && widget->IsWidget())
  10903. {
  10904. ((Widget*)widget)->CloseDoor();
  10905. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10906. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10907. }
  10908. else
  10909. 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));
  10910. }
  10911. return 0;
  10912. }
  10913. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10914. if (!lua_interface)
  10915. return 0;
  10916. Spawn* widget = lua_interface->GetSpawn(state);
  10917. lua_interface->ResetFunctionStack(state);
  10918. if (widget && widget->IsWidget())
  10919. {
  10920. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10921. return 1;
  10922. }
  10923. return 0;
  10924. }
  10925. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10926. if (!lua_interface)
  10927. return 0;
  10928. sint32 min = lua_interface->GetSInt32Value(state);
  10929. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10930. lua_interface->ResetFunctionStack(state);
  10931. sint32 result = MakeRandomInt(min, max);
  10932. lua_interface->SetSInt32Value(state, result);
  10933. return 1;
  10934. }
  10935. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10936. if (!lua_interface)
  10937. return 0;
  10938. float min = lua_interface->GetFloatValue(state);
  10939. float max = lua_interface->GetFloatValue(state, 2);
  10940. lua_interface->ResetFunctionStack(state);
  10941. float result = MakeRandomFloat(min, max);
  10942. lua_interface->SetFloatValue(state, result);
  10943. return 1;
  10944. }
  10945. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10946. if (!lua_interface)
  10947. return 0;
  10948. Spawn* spawn = lua_interface->GetSpawn(state);
  10949. int32 value = lua_interface->GetInt32Value(state, 2);
  10950. lua_interface->ResetFunctionStack(state);
  10951. if(!spawn)
  10952. {
  10953. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10954. lua_interface->SetBooleanValue(state, false);
  10955. return 1;
  10956. }
  10957. spawn->AddIconValue(value);
  10958. lua_interface->SetBooleanValue(state, true);
  10959. return 1;
  10960. }
  10961. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10962. if (!lua_interface)
  10963. return 0;
  10964. Spawn* spawn = lua_interface->GetSpawn(state);
  10965. int32 value = lua_interface->GetInt32Value(state, 2);
  10966. lua_interface->ResetFunctionStack(state);
  10967. if(!spawn)
  10968. {
  10969. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10970. lua_interface->SetBooleanValue(state, false);
  10971. return 1;
  10972. }
  10973. spawn->RemoveIconValue(value);
  10974. lua_interface->SetBooleanValue(state, true);
  10975. return 1;
  10976. }
  10977. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10978. Spawn* npc = lua_interface->GetSpawn(state);
  10979. lua_interface->ResetFunctionStack(state);
  10980. if (npc && npc->IsNPC()) {
  10981. NPC* shard = (NPC*)npc;
  10982. int32 shardid = shard->GetShardID();
  10983. lua_interface->SetInt32Value(state, shardid);
  10984. return 1;
  10985. }
  10986. lua_interface->SetInt32Value(state, 0);
  10987. return 1;
  10988. }
  10989. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10990. Spawn* npc = lua_interface->GetSpawn(state);
  10991. lua_interface->ResetFunctionStack(state);
  10992. if (npc && npc->IsNPC()) {
  10993. NPC* shard = (NPC*)npc;
  10994. int32 charid = shard->GetShardCharID();
  10995. lua_interface->SetInt32Value(state, charid);
  10996. return 1;
  10997. }
  10998. lua_interface->SetInt32Value(state, 0);
  10999. return 1;
  11000. }
  11001. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11002. Spawn* npc = lua_interface->GetSpawn(state);
  11003. lua_interface->ResetFunctionStack(state);
  11004. if (npc && npc->IsNPC()) {
  11005. NPC* shard = (NPC*)npc;
  11006. int64 timestamp = shard->GetShardCreatedTimestamp();
  11007. lua_interface->SetSInt64Value(state, timestamp);
  11008. return 1;
  11009. }
  11010. lua_interface->SetSInt64Value(state, 0);
  11011. return 1;
  11012. }
  11013. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11014. if (!lua_interface)
  11015. return 0;
  11016. int32 shardid = lua_interface->GetInt32Value(state);
  11017. lua_interface->ResetFunctionStack(state);
  11018. if(shardid < 1)
  11019. lua_interface->SetBooleanValue(state, false);
  11020. else
  11021. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11022. return 1;
  11023. }
  11024. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11025. if (!lua_interface)
  11026. return 0;
  11027. Spawn* spawn = lua_interface->GetSpawn(state);
  11028. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11029. if (spawn) {
  11030. spawn->PauseMovement(delay_in_ms);
  11031. }
  11032. lua_interface->ResetFunctionStack(state);
  11033. return 0;
  11034. }
  11035. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11036. if (!lua_interface)
  11037. return 0;
  11038. Spawn* spawn = lua_interface->GetSpawn(state);
  11039. if (spawn) {
  11040. spawn->StopMovement();
  11041. }
  11042. lua_interface->ResetFunctionStack(state);
  11043. return 0;
  11044. }
  11045. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11046. Player* player = (Player*)lua_interface->GetSpawn(state);
  11047. int8 level = lua_interface->GetInt8Value(state, 2);
  11048. lua_interface->ResetFunctionStack(state);
  11049. if (player && player->IsPlayer() && level > 0) {
  11050. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11051. return 1;
  11052. }
  11053. return 0;
  11054. }
  11055. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11056. Player* player = (Player*)lua_interface->GetSpawn(state);
  11057. int8 level = lua_interface->GetInt8Value(state, 2);
  11058. lua_interface->ResetFunctionStack(state);
  11059. if (player && player->IsPlayer() && level > 0) {
  11060. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11061. return 1;
  11062. }
  11063. return 0;
  11064. }
  11065. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11066. ZoneServer* zone = lua_interface->GetZone(state);
  11067. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11068. lua_interface->ResetFunctionStack(state);
  11069. if (zone) {
  11070. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11071. if (spawn) {
  11072. lua_interface->SetSpawnValue(state, spawn);
  11073. return 1;
  11074. }
  11075. }
  11076. return 0;
  11077. }
  11078. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11079. if (!lua_interface)
  11080. return 0;
  11081. Spawn* spawn = lua_interface->GetSpawn(state);
  11082. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11083. lua_interface->ResetFunctionStack(state);
  11084. bool res = false;
  11085. if(spawn && spawn->IsTransportSpawn())
  11086. {
  11087. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11088. spawn->SetRailID(rail_id);
  11089. res = true;
  11090. }
  11091. else if (!spawn) {
  11092. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11093. }
  11094. else if(!spawn->IsTransportSpawn()) {
  11095. 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());
  11096. }
  11097. lua_interface->SetBooleanValue(state, res);
  11098. return 1;
  11099. }
  11100. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11101. if (!lua_interface)
  11102. return 0;
  11103. ZoneServer* zone = lua_interface->GetZone(state);
  11104. lua_interface->ResetFunctionStack(state);
  11105. if (zone) {
  11106. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11107. return 1;
  11108. }
  11109. return 0;
  11110. }
  11111. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11112. if (!lua_interface)
  11113. return 0;
  11114. Spawn* spawn = lua_interface->GetSpawn(state);
  11115. lua_interface->ResetFunctionStack(state);
  11116. if (spawn) {
  11117. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11118. return 1;
  11119. }
  11120. return 0;
  11121. }
  11122. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11123. if (!lua_interface)
  11124. return 0;
  11125. Spawn* player = lua_interface->GetSpawn(state);
  11126. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11127. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11128. lua_interface->ResetFunctionStack(state);
  11129. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11130. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11131. }
  11132. else if(!zoneID) {
  11133. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11134. }
  11135. else
  11136. {
  11137. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11138. return 1;
  11139. }
  11140. return 0;
  11141. }
  11142. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11143. if (!lua_interface)
  11144. return 0;
  11145. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11146. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11147. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11148. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11149. lua_interface->ResetFunctionStack(state);
  11150. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11151. world.GetWorldTimeStruct()->year = newYear;
  11152. world.GetWorldTimeStruct()->month = newMonth;
  11153. world.GetWorldTimeStruct()->hour = newHour;
  11154. world.GetWorldTimeStruct()->minute = newMinute;
  11155. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11156. return 0;
  11157. }
  11158. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11159. if (!lua_interface)
  11160. return 0;
  11161. lua_interface->ResetFunctionStack(state);
  11162. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11163. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11164. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11165. return 1;
  11166. }
  11167. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11168. if (!lua_interface)
  11169. return 0;
  11170. lua_interface->ResetFunctionStack(state);
  11171. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11172. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11173. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11174. return 1;
  11175. }
  11176. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11177. if (!lua_interface)
  11178. return 0;
  11179. lua_interface->ResetFunctionStack(state);
  11180. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11181. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11182. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11183. return 1;
  11184. }
  11185. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11186. if (!lua_interface)
  11187. return 0;
  11188. lua_interface->ResetFunctionStack(state);
  11189. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11190. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11191. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11192. return 1;
  11193. }
  11194. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11195. if (!lua_interface)
  11196. return 0;
  11197. lua_interface->ResetFunctionStack(state);
  11198. world.SendTimeUpdate();
  11199. return 0;
  11200. }
  11201. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11202. bool update_result = false;
  11203. Faction* faction = 0;
  11204. Player* player = (Player*)lua_interface->GetSpawn(state);
  11205. Client* client = player->GetZone()->GetClientBySpawn(player);
  11206. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11207. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11208. lua_interface->ResetFunctionStack(state);
  11209. if (player && player->IsPlayer() && faction_id > 0) {
  11210. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11211. if(hasfaction == 0) {
  11212. //they do not have the faction. Lets get the default value and feed it in.
  11213. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11214. //add the default faction for the player.
  11215. player->SetFactionValue(faction_id, defaultfaction);
  11216. }
  11217. if(increase >= 0) {
  11218. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11219. faction = master_faction_list.GetFaction(faction_id);
  11220. if(faction && update_result)
  11221. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11222. else if(faction)
  11223. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11224. lua_interface->SetBooleanValue(state, true);
  11225. return 1;
  11226. }
  11227. if(increase < 0){
  11228. //change the negative to a positive, since thats how decreasefaction() likes it.
  11229. increase *= -1;
  11230. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11231. faction = master_faction_list.GetFaction(faction_id);
  11232. if(faction && update_result)
  11233. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11234. else if(faction)
  11235. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11236. lua_interface->SetBooleanValue(state, true);
  11237. return 1;
  11238. }
  11239. }
  11240. lua_interface->SetBooleanValue(state, false);
  11241. return 1;
  11242. }
  11243. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11244. bool hascoin = 0;
  11245. Player* player = (Player*)lua_interface->GetSpawn(state);
  11246. int32 coins = lua_interface->GetInt32Value(state, 2);
  11247. lua_interface->ResetFunctionStack(state);
  11248. if (player && player->IsPlayer()) {
  11249. hascoin = player->HasCoins(coins);
  11250. if(hascoin == 0) {
  11251. lua_interface->SetBooleanValue(state, false);
  11252. return 1;
  11253. }
  11254. if(hascoin == 1) {
  11255. lua_interface->SetBooleanValue(state, true);
  11256. return 1;
  11257. }
  11258. }
  11259. return 0;
  11260. }
  11261. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11262. int32 loot_tier = 0;
  11263. Spawn* spawn = lua_interface->GetSpawn(state);
  11264. lua_interface->ResetFunctionStack(state);
  11265. if (spawn) {
  11266. loot_tier = spawn->GetLootTier();
  11267. lua_interface->SetInt32Value(state, loot_tier);
  11268. return 1;
  11269. }
  11270. return 0;
  11271. }
  11272. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11273. if (!lua_interface)
  11274. return 0;
  11275. Spawn* spawn = lua_interface->GetSpawn(state);
  11276. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11277. lua_interface->ResetFunctionStack(state);
  11278. if (spawn) {
  11279. spawn->SetLootTier(loot_tier);
  11280. lua_interface->SetBooleanValue(state, true);
  11281. return 1;
  11282. }
  11283. lua_interface->SetBooleanValue(state, false);
  11284. return 1;
  11285. }
  11286. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11287. int32 loot_drop_type = 0;
  11288. Spawn* spawn = lua_interface->GetSpawn(state);
  11289. lua_interface->ResetFunctionStack(state);
  11290. if (spawn) {
  11291. loot_drop_type = spawn->GetLootDropType();
  11292. lua_interface->SetInt32Value(state, loot_drop_type);
  11293. return 1;
  11294. }
  11295. return 0;
  11296. }
  11297. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11298. if (!lua_interface)
  11299. return 0;
  11300. Spawn* spawn = lua_interface->GetSpawn(state);
  11301. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11302. lua_interface->ResetFunctionStack(state);
  11303. if (spawn) {
  11304. spawn->SetLootDropType(loot_drop_type);
  11305. lua_interface->SetBooleanValue(state, true);
  11306. return 1;
  11307. }
  11308. lua_interface->SetBooleanValue(state, false);
  11309. return 1;
  11310. }