LuaFunctions.cpp 371 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. if (spawn) {
  156. const char* mp3 = 0;
  157. const char* text = 0;
  158. const char* emote = 0;
  159. if (mp3_string.length() > 0)
  160. mp3 = mp3_string.c_str();
  161. if (text_string.length() > 0)
  162. text = text_string.c_str();
  163. if (emote_string.length() > 0)
  164. emote = emote_string.c_str();
  165. Client* client = 0;
  166. if (player && player->IsPlayer())
  167. client = spawn->GetZone()->GetClientBySpawn(player);
  168. if (client) {
  169. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  170. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  171. }
  172. else
  173. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  174. }
  175. return 0;
  176. }
  177. int EQ2Emu_lua_PlaySound(lua_State* state) {
  178. if (!lua_interface)
  179. return 0;
  180. Spawn* spawn = lua_interface->GetSpawn(state);
  181. string sound_string = lua_interface->GetStringValue(state, 2);
  182. float x = lua_interface->GetFloatValue(state, 3);
  183. float y = lua_interface->GetFloatValue(state, 4);
  184. float z = lua_interface->GetFloatValue(state, 5);
  185. Spawn* player = lua_interface->GetSpawn(state, 6);
  186. if (spawn && sound_string.length() > 0) {
  187. Client* client = 0;
  188. if (player && player->IsPlayer())
  189. client = spawn->GetZone()->GetClientBySpawn(player);
  190. if (client)
  191. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  192. else
  193. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  194. }
  195. return 0;
  196. }
  197. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  202. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  203. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  204. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  205. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  206. if (!spawn) {
  207. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  208. return 0;
  209. }
  210. if (quest_id > 0) {
  211. //Add this quest to the list of required quests for this spawn
  212. spawn->SetQuestsRequired(quest_id, quest_step);
  213. //If private spawn value set
  214. if (private_spawn) {
  215. //Set the spawn to be private when not granted access through this quest
  216. spawn->AddAllowAccessSpawn(spawn);
  217. spawn->SetPrivateQuestSpawn(true);
  218. }
  219. //This value allows access after a quest step, or the whole quest has been completed
  220. if (continued_access)
  221. spawn->SetQuestsRequiredContinuedAccess(true);
  222. //This value will override vis_flags in the vis packet
  223. if (flag_override > 0)
  224. spawn->SetQuestsRequiredOverride(flag_override);
  225. }
  226. return 0;
  227. }
  228. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  229. if (!lua_interface)
  230. return 0;
  231. Spawn* spawn = lua_interface->GetSpawn(state);
  232. float max_distance = lua_interface->GetFloatValue(state, 2);
  233. string variable = lua_interface->GetStringValue(state, 3);
  234. string value = lua_interface->GetStringValue(state, 4);
  235. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  236. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  237. return 0;
  238. }
  239. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  240. if (!lua_interface)
  241. return 0;
  242. Client* client = 0;
  243. Spawn* player = lua_interface->GetSpawn(state);
  244. if (!player) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  246. return 0;
  247. }
  248. if (!player->IsPlayer()) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  250. return 0;
  251. }
  252. if (player->GetZone())
  253. client = player->GetZone()->GetClientBySpawn(player);
  254. if (!client) {
  255. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  256. return 0;
  257. }
  258. float intensity = lua_interface->GetFloatValue(state, 2);
  259. int8 direction = lua_interface->GetInt8Value(state, 3);
  260. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  261. if (packet) {
  262. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  263. v1 = *(float *)(a1 + 4);
  264. if ( v1 > 0.0 )
  265. v2 = fminf(v1, 1.0);
  266. else
  267. v2 = 0.1;
  268. */
  269. packet->setDataByName("intensity", intensity);
  270. if ( client->GetVersion() > 546 )
  271. packet->setDataByName("direction", direction);
  272. client->QueuePacket(packet->serialize());
  273. safe_delete(packet);
  274. }
  275. return 0;
  276. }
  277. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  278. if (!lua_interface)
  279. return 0;
  280. Spawn* dead = lua_interface->GetSpawn(state);
  281. Spawn* killer = lua_interface->GetSpawn(state, 2);
  282. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  283. if (dead && dead->Alive() && dead->GetZone())
  284. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  285. return 0;
  286. }
  287. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  288. if (!lua_interface)
  289. return 0;
  290. Spawn* spawn = lua_interface->GetSpawn(state);
  291. float max_distance = lua_interface->GetFloatValue(state, 2);
  292. bool include_players = lua_interface->GetInt8Value(state, 3);
  293. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  294. if (max_distance > 0 && spawn && spawn->GetZone())
  295. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  296. return 0;
  297. }
  298. int EQ2Emu_lua_Despawn(lua_State* state) {
  299. if (!lua_interface)
  300. return 0;
  301. Spawn* spawn = lua_interface->GetSpawn(state);
  302. int32 delay = lua_interface->GetInt32Value(state, 2);
  303. if (spawn && spawn->GetZone())
  304. spawn->GetZone()->Despawn(spawn, delay);
  305. return 0;
  306. }
  307. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* spawn = lua_interface->GetSpawn(state);
  311. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  312. if (spawn) {
  313. spawn->info_changed = true;
  314. spawn->SetShowHandIcon(displayHandIcon);
  315. }
  316. return 0;
  317. }
  318. //this function is used to force an update packet to be sent.
  319. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  320. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  321. if (!lua_interface)
  322. return 0;
  323. Spawn* spawn = lua_interface->GetSpawn(state);
  324. if (spawn) {
  325. spawn->vis_changed = true;
  326. }
  327. return 0;
  328. }
  329. //this function is used to force an update packet to be sent.
  330. //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
  331. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  332. if (!lua_interface)
  333. return 0;
  334. Spawn* spawn = lua_interface->GetSpawn(state);
  335. if (spawn) {
  336. spawn->info_changed = true;
  337. }
  338. return 0;
  339. }
  340. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int32 new_state = lua_interface->GetInt32Value(state, 2);
  345. if (spawn) {
  346. spawn->GetZone()->SendStateCommand(spawn, new_state);
  347. }
  348. return 0;
  349. }
  350. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  351. if (!lua_interface)
  352. return 0;
  353. Spawn* spawn = lua_interface->GetSpawn(state);
  354. string variable = lua_interface->GetStringValue(state, 2);
  355. string value = lua_interface->GetStringValue(state, 3);
  356. 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.
  357. bool temporary_flag = true;
  358. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  359. if(num_args >= 5)
  360. 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
  361. int32 type = commands.GetSpawnSetType(variable);
  362. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  363. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  364. return 0;
  365. }
  366. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  367. if (!lua_interface)
  368. return 0;
  369. Spawn* spawn = lua_interface->GetSpawn(state);
  370. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  371. if (spawn && spawn_id > 0) {
  372. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  373. if (closest_spawn) {
  374. lua_interface->SetSpawnValue(state, closest_spawn);
  375. return 1;
  376. }
  377. }
  378. return 0;
  379. }
  380. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  381. if (!lua_interface)
  382. return 0;
  383. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  384. int32 position = lua_interface->GetInt32Value(state, 2);
  385. if (spawnList) {
  386. if (spawnList->size() > position) {
  387. lua_interface->SetSpawnValue(state, spawnList->at(position));
  388. return 1;
  389. }
  390. else {
  391. return 0;
  392. }
  393. return spawnList->size();
  394. }
  395. return 0;
  396. }
  397. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  398. if (!lua_interface)
  399. return 0;
  400. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  401. if (spawnList) {
  402. return spawnList->size();
  403. }
  404. return 0;
  405. }
  406. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  407. if (!lua_interface)
  408. return 0;
  409. vector<Spawn*>* spawnList = new vector<Spawn*>();
  410. lua_interface->SetSpawnListValue(state, spawnList);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  417. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  418. if (spawnList) {
  419. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  420. if (it == spawnList->end())
  421. spawnList->push_back(spawn);
  422. }
  423. return 0;
  424. }
  425. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  426. if (!lua_interface)
  427. return 0;
  428. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  429. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  430. if (spawnList) {
  431. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  432. if(it != spawnList->end())
  433. spawnList->erase(it);
  434. }
  435. return 0;
  436. }
  437. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  438. if (!lua_interface)
  439. return 0;
  440. Spawn* spawn = lua_interface->GetSpawn(state);
  441. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  442. if (spawn) {
  443. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  444. if (spawns.size() > 0) {
  445. vector<Spawn*>* spawnList = new vector<Spawn*>();
  446. vector<Spawn*>::iterator itr;
  447. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  448. spawnList->push_back(*itr);
  449. }
  450. lua_interface->SetSpawnListValue(state, spawnList);
  451. return 1;
  452. }
  453. }
  454. return 0;
  455. }
  456. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  457. if (!lua_interface)
  458. return 0;
  459. string variable_name = lua_interface->GetStringValue(state);
  460. Variable* var = variables.FindVariable(variable_name);
  461. if (var) {
  462. lua_interface->SetStringValue(state, var->GetValue());
  463. return 1;
  464. }
  465. return 0;
  466. }
  467. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  468. if (!lua_interface)
  469. return 0;
  470. int32 total_coins = lua_interface->GetInt32Value(state);
  471. if (total_coins == 0) {
  472. lua_interface->SetStringValue(state, "0 copper");
  473. return 1;
  474. }
  475. char tmp[64] = { 0 };
  476. string message = "";
  477. int32 val = 0;
  478. if (total_coins >= 1000000) {
  479. val = total_coins / 1000000;
  480. total_coins -= 1000000 * val;
  481. sprintf(tmp, " %u Platinum", val);
  482. message.append(tmp);
  483. memset(tmp, 0, 64);
  484. }
  485. if (total_coins >= 10000) {
  486. val = total_coins / 10000;
  487. total_coins -= 10000 * val;
  488. sprintf(tmp, " %u Gold", val);
  489. message.append(tmp);
  490. memset(tmp, 0, 64);
  491. }
  492. if (total_coins >= 100) {
  493. val = total_coins / 100;
  494. total_coins -= 100 * val;
  495. sprintf(tmp, " %u Silver", val);
  496. message.append(tmp);
  497. memset(tmp, 0, 64);
  498. }
  499. if (total_coins > 0) {
  500. sprintf(tmp, " %u Copper", (int32)total_coins);
  501. message.append(tmp);
  502. }
  503. lua_interface->SetStringValue(state, message.c_str());
  504. return 1;
  505. }
  506. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  507. ZoneServer* zone = lua_interface->GetZone(state);
  508. int32 group_id = lua_interface->GetInt32Value(state, 2);
  509. if (zone) {
  510. Spawn* spawn = zone->GetSpawnGroup(group_id);
  511. if (spawn) {
  512. lua_interface->SetSpawnValue(state, spawn);
  513. return 1;
  514. }
  515. }
  516. return 0;
  517. }
  518. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  519. ZoneServer* zone = lua_interface->GetZone(state);
  520. int32 location_id = lua_interface->GetInt32Value(state, 2);
  521. if (zone) {
  522. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  523. if (spawn) {
  524. lua_interface->SetSpawnValue(state, spawn);
  525. return 1;
  526. }
  527. }
  528. return 0;
  529. }
  530. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. if (spawn) {
  533. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  534. return 1;
  535. }
  536. return 0;
  537. }
  538. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  539. Spawn* spawn = lua_interface->GetSpawn(state);
  540. if (spawn) {
  541. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  542. return 1;
  543. }
  544. return 0;
  545. }
  546. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  547. if (!lua_interface)
  548. return 0;
  549. Spawn* spawn = lua_interface->GetSpawn(state);
  550. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  551. lua_interface->ResetFunctionStack(state);
  552. if (spawn) {
  553. spawn->SetSpawnGroupID(new_group_id);
  554. lua_interface->SetBooleanValue(state, true);
  555. return 1;
  556. }
  557. lua_interface->SetBooleanValue(state, false);
  558. return 1;
  559. }
  560. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  561. Spawn* spawn = lua_interface->GetSpawn(state);
  562. if (spawn) {
  563. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  564. return 1;
  565. }
  566. return 0;
  567. }
  568. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  569. Spawn* spawn = lua_interface->GetSpawn(state);
  570. if (spawn) {
  571. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  572. return 1;
  573. }
  574. return 0;
  575. }
  576. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  577. Player* player = (Player*)lua_interface->GetSpawn(state);
  578. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  579. if (player && player->IsPlayer() && faction_id > 0) {
  580. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  581. return 1;
  582. }
  583. return 0;
  584. }
  585. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  586. if (!lua_interface)
  587. return 0;
  588. Spawn* spawn = lua_interface->GetSpawn(state);
  589. int32 value = lua_interface->GetInt32Value(state, 2);
  590. if (spawn) {
  591. spawn->SetFactionID(value);
  592. }
  593. return 0;
  594. }
  595. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  596. Spawn* spawn = lua_interface->GetSpawn(state);
  597. if (spawn) {
  598. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  599. return 1;
  600. }
  601. return 0;
  602. }
  603. int EQ2Emu_lua_GetGender(lua_State* state) {
  604. Spawn* spawn = lua_interface->GetSpawn(state);
  605. if (spawn) {
  606. lua_interface->SetInt32Value(state, spawn->GetGender());
  607. return 1;
  608. }
  609. return 0;
  610. }
  611. int EQ2Emu_lua_GetTarget(lua_State* state) {
  612. Spawn* spawn = lua_interface->GetSpawn(state);
  613. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  614. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  615. return 1;
  616. }
  617. return 0;
  618. }
  619. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  620. if (!lua_interface)
  621. return 0;
  622. Spawn* spawn = lua_interface->GetSpawn(state);
  623. string mp3_string = lua_interface->GetStringValue(state, 2);
  624. int32 key1 = lua_interface->GetInt32Value(state, 3);
  625. int32 key2 = lua_interface->GetInt32Value(state, 4);
  626. Spawn* player = lua_interface->GetSpawn(state, 5);
  627. if (spawn && mp3_string.length() > 0) {
  628. Client* client = 0;
  629. if (player && player->IsPlayer())
  630. client = spawn->GetZone()->GetClientBySpawn(player);
  631. if (client) {
  632. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  633. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  634. }
  635. else
  636. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. if (spawn) {
  645. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  646. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  647. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  648. return 3;
  649. }
  650. return 0;
  651. }
  652. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  653. if (!lua_interface)
  654. return 0;
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. if (spawn) {
  657. int32 item_id = lua_interface->GetInt32Value(state, 2);
  658. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. if (spawn && spawn->IsEntity()) {
  668. int32 item_id = lua_interface->GetInt32Value(state, 2);
  669. int16 charges = lua_interface->GetInt16Value(state, 3);
  670. if (charges == 0)
  671. charges = 1;
  672. ((Entity*)spawn)->AddLootItem(item_id, charges);
  673. }
  674. return 0;
  675. }
  676. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  677. if (!lua_interface)
  678. return 0;
  679. Spawn* spawn = lua_interface->GetSpawn(state);
  680. if (spawn && spawn->IsEntity()) {
  681. int32 item_id = lua_interface->GetInt32Value(state, 2);
  682. spawn->LootItem(item_id);
  683. }
  684. return 0;
  685. }
  686. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  687. if (!lua_interface)
  688. return 0;
  689. Spawn* spawn = lua_interface->GetSpawn(state);
  690. if (spawn) {
  691. int32 val = lua_interface->GetInt32Value(state, 2);
  692. spawn->AddLootCoins(val);
  693. }
  694. return 0;
  695. }
  696. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  697. if (!lua_interface)
  698. return 0;
  699. Spawn* entity = lua_interface->GetSpawn(state);
  700. Spawn* player = lua_interface->GetSpawn(state, 2);
  701. if (entity && player && player->IsPlayer()) {
  702. int32 coins = lua_interface->GetInt32Value(state, 3);
  703. vector<Item*>* items = 0;
  704. int i = 0;
  705. int32 item_id = 0;
  706. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  707. if (items == 0)
  708. items = new vector<Item*>;
  709. if (master_item_list.GetItem(item_id))
  710. items->push_back(master_item_list.GetItem(item_id));
  711. i++;
  712. }
  713. Client* client = 0;
  714. client = player->GetZone()->GetClientBySpawn(player);
  715. if (client)
  716. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  717. if(coins > 0)
  718. entity->AddLootCoins(coins);
  719. safe_delete(items);
  720. }
  721. return 0;
  722. }
  723. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  724. if (!lua_interface)
  725. return 0;
  726. Spawn* entity = lua_interface->GetSpawn(state);
  727. Spawn* player = lua_interface->GetSpawn(state, 2);
  728. int32 item_id = lua_interface->GetInt32Value(state, 3);
  729. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  730. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  731. return 1;
  732. }
  733. return 0;
  734. }
  735. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  736. if (!lua_interface)
  737. return 0;
  738. Spawn* entity = lua_interface->GetSpawn(state);
  739. Spawn* player = lua_interface->GetSpawn(state, 2);
  740. if (entity && player && player->IsPlayer()) {
  741. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  742. return 1;
  743. }
  744. return 0;
  745. }
  746. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  747. if (!lua_interface)
  748. return 0;
  749. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  750. safe_delete(conversation);
  751. conversation = new vector<ConversationOption>();
  752. lua_interface->SetConversationValue(state, conversation);
  753. return 1;
  754. }
  755. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  756. if (!lua_interface)
  757. return 0;
  758. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  759. if (conversation) {
  760. ConversationOption conv_option;
  761. conv_option.option = lua_interface->GetStringValue(state, 2);
  762. conv_option.function = lua_interface->GetStringValue(state, 3);
  763. if (conv_option.option.length() > 0)
  764. conversation->push_back(conv_option);
  765. }
  766. return 0;
  767. }
  768. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  769. if (!lua_interface)
  770. return 0;
  771. Spawn* npc = lua_interface->GetSpawn(state);
  772. Spawn* player = lua_interface->GetSpawn(state, 2);
  773. if (npc && player && player->IsPlayer() && player->GetZone()) {
  774. Client* client = player->GetZone()->GetClientBySpawn(player);
  775. if (client) {
  776. int32 conversation_id = client->GetConversationID(npc, 0);
  777. client->CloseDialog(conversation_id);
  778. }
  779. }
  780. return 0;
  781. }
  782. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  783. if (!lua_interface)
  784. return 0;
  785. Item* item = lua_interface->GetItem(state);
  786. Spawn* player = lua_interface->GetSpawn(state, 2);
  787. if (item && player && player->IsPlayer() && player->GetZone()) {
  788. Client* client = player->GetZone()->GetClientBySpawn(player);
  789. if (client) {
  790. int32 conversation_id = client->GetConversationID(0, item);
  791. client->CloseDialog(conversation_id);
  792. }
  793. }
  794. return 0;
  795. }
  796. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  800. Spawn* spawn = 0;
  801. Item* item = 0;
  802. int8 type = lua_interface->GetInt8Value(state, 2);
  803. if (type == 1 || type == 3)
  804. spawn = lua_interface->GetSpawn(state, 3);
  805. else if (type == 2 || type == 4)
  806. item = lua_interface->GetItem(state, 3);
  807. Spawn* player = lua_interface->GetSpawn(state, 4);
  808. string text = lua_interface->GetStringValue(state, 5);
  809. string mp3 = lua_interface->GetStringValue(state, 6);
  810. int32 key1 = lua_interface->GetInt32Value(state, 7);
  811. int32 key2 = lua_interface->GetInt32Value(state, 8);
  812. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  813. Client* client = player->GetZone()->GetClientBySpawn(player);
  814. if (client) {
  815. if (spawn) {
  816. // Need to do this so the function works the same as it did before
  817. if (type == 1)
  818. type++;
  819. if (mp3.length() > 0)
  820. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  821. else
  822. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  823. }
  824. else {
  825. if (mp3.length() > 0)
  826. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  827. else
  828. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  829. }
  830. }
  831. }
  832. safe_delete(conversation);
  833. lua_interface->SetConversationValue(state, NULL);
  834. return 0;
  835. }
  836. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  837. if(!lua_interface)
  838. return 0;
  839. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  840. Item* item = lua_interface->GetItem(state, 2);
  841. Spawn* player = lua_interface->GetSpawn(state, 3);
  842. string text = lua_interface->GetStringValue(state, 4);
  843. string mp3 = lua_interface->GetStringValue(state, 5);
  844. int32 key1 = lua_interface->GetInt32Value(state, 6);
  845. int32 key2 = lua_interface->GetInt32Value(state, 7);
  846. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  847. Client* client = player->GetZone()->GetClientBySpawn(player);
  848. if(client){
  849. if(mp3.length() > 0)
  850. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  851. else
  852. client->DisplayConversation(item, conversation, (char*)text.c_str());
  853. }
  854. safe_delete(conversation);
  855. }
  856. return 0;
  857. }*/
  858. int EQ2Emu_lua_StartConversation(lua_State* state) {
  859. if (!lua_interface)
  860. return 0;
  861. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  862. Spawn* source = lua_interface->GetSpawn(state, 2);
  863. Spawn* player = lua_interface->GetSpawn(state, 3);
  864. string text = lua_interface->GetStringValue(state, 4);
  865. string mp3 = lua_interface->GetStringValue(state, 5);
  866. int32 key1 = lua_interface->GetInt32Value(state, 6);
  867. int32 key2 = lua_interface->GetInt32Value(state, 7);
  868. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  869. Client* client = source->GetZone()->GetClientBySpawn(player);
  870. if (mp3.length() > 0)
  871. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  872. else
  873. client->DisplayConversation(source, 1, conversation, text.c_str());
  874. safe_delete(conversation);
  875. lua_interface->SetConversationValue(state, NULL);
  876. }
  877. else
  878. 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);
  879. return 0;
  880. }
  881. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  882. if (!lua_interface)
  883. return 0;
  884. Spawn* spawn = lua_interface->GetSpawn(state);
  885. float distance = lua_interface->GetFloatValue(state, 2);
  886. string in_range_function = lua_interface->GetStringValue(state, 3);
  887. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  888. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  889. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  890. return 0;
  891. }
  892. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  893. ZoneServer* zone = lua_interface->GetZone(state);
  894. float x = lua_interface->GetFloatValue(state, 2);
  895. float y = lua_interface->GetFloatValue(state, 3);
  896. float z = lua_interface->GetFloatValue(state, 4);
  897. float max_variation = lua_interface->GetFloatValue(state, 5);
  898. string in_range_function = lua_interface->GetStringValue(state, 6);
  899. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  900. if (zone && in_range_function.length() > 0)
  901. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  902. return 0;
  903. }
  904. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  905. if (!lua_interface)
  906. return 0;
  907. Spawn* spawn = lua_interface->GetSpawn(state);
  908. if (spawn && spawn->IsEntity()) {
  909. int32 val = lua_interface->GetInt32Value(state, 2);
  910. ((Entity*)spawn)->SetLootCoins(val);
  911. }
  912. return 0;
  913. }
  914. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  915. if (!lua_interface)
  916. return 0;
  917. Spawn* spawn = lua_interface->GetSpawn(state);
  918. if (spawn && spawn->IsEntity()) {
  919. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  920. return 1;
  921. }
  922. return 0;
  923. }
  924. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  925. if (!lua_interface)
  926. return 0;
  927. Spawn* spawn = lua_interface->GetSpawn(state);
  928. float x = lua_interface->GetFloatValue(state, 2);
  929. float y = lua_interface->GetFloatValue(state, 3);
  930. float z = lua_interface->GetFloatValue(state, 4);
  931. float speed = lua_interface->GetFloatValue(state, 5);
  932. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  933. string function = lua_interface->GetStringValue(state, 7);
  934. if (spawn) {
  935. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  936. spawn->GetZone()->AddMovementNPC(spawn);
  937. }
  938. lua_interface->ResetFunctionStack(state);
  939. return 0;
  940. }
  941. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  942. if (!lua_interface)
  943. return 0;
  944. Spawn* spawn = lua_interface->GetSpawn(state);
  945. if (spawn) {
  946. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  947. return 1;
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. Spawn* spawn = lua_interface->GetSpawn(state);
  955. if (spawn && spawn->IsPlayer()) {
  956. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  957. return 1;
  958. }
  959. lua_interface->SetInt32Value(state, 0);
  960. return 1;
  961. }
  962. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  963. if (!lua_interface)
  964. return 0;
  965. Spawn* spawn = lua_interface->GetSpawn(state);
  966. Spawn* target = lua_interface->GetSpawn(state, 2);
  967. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  968. bool reset_action_state = true;
  969. if(num_args > 2)
  970. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  971. if (spawn && target) {
  972. if (spawn->IsEntity())
  973. // ((Entity*)spawn)->FaceTarget(target);
  974. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  975. }
  976. lua_interface->ResetFunctionStack(state);
  977. return 0;
  978. }
  979. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  980. if (!lua_interface)
  981. return 0;
  982. Spawn* spawn = lua_interface->GetSpawn(state);
  983. float x = lua_interface->GetFloatValue(state, 2);
  984. float y = lua_interface->GetFloatValue(state, 3);
  985. float z = lua_interface->GetFloatValue(state, 4);
  986. float speed = lua_interface->GetFloatValue(state, 5);
  987. string lua_function = lua_interface->GetStringValue(state, 6);
  988. bool more_points = lua_interface->GetBooleanValue(state, 7);
  989. if (spawn) {
  990. if (speed == 0)
  991. speed = spawn->GetSpeed();
  992. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  993. }
  994. lua_interface->ResetFunctionStack(state);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. Spawn* spawn = lua_interface->GetSpawn(state);
  1001. if (spawn) {
  1002. spawn->ClearRunningLocations();
  1003. }
  1004. return 0;
  1005. }
  1006. int EQ2Emu_lua_Say(lua_State* state) {
  1007. if (!lua_interface)
  1008. return 0;
  1009. Spawn* spawn = lua_interface->GetSpawn(state);
  1010. string message = lua_interface->GetStringValue(state, 2);
  1011. Spawn* player = lua_interface->GetSpawn(state, 3);
  1012. int32 language = lua_interface->GetInt32Value(state, 4);
  1013. if (spawn && message.length() > 0) {
  1014. Client* client = 0;
  1015. if (player && player->IsPlayer())
  1016. client = spawn->GetZone()->GetClientBySpawn(player);
  1017. if (client)
  1018. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1019. else
  1020. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1021. }
  1022. lua_interface->ResetFunctionStack(state);
  1023. return 0;
  1024. }
  1025. int EQ2Emu_lua_Shout(lua_State* state) {
  1026. if (!lua_interface)
  1027. return 0;
  1028. Spawn* spawn = lua_interface->GetSpawn(state);
  1029. string message = lua_interface->GetStringValue(state, 2);
  1030. Spawn* player = lua_interface->GetSpawn(state, 3);
  1031. if (spawn && message.length() > 0) {
  1032. Client* client = 0;
  1033. if (player && player->IsPlayer())
  1034. client = spawn->GetZone()->GetClientBySpawn(player);
  1035. if (client)
  1036. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1037. else
  1038. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1039. }
  1040. lua_interface->ResetFunctionStack(state);
  1041. return 0;
  1042. }
  1043. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1044. if (!lua_interface)
  1045. return 0;
  1046. Spawn* spawn = lua_interface->GetSpawn(state);
  1047. string message = lua_interface->GetStringValue(state, 2);
  1048. Spawn* player = lua_interface->GetSpawn(state, 3);
  1049. if (spawn && message.length() > 0) {
  1050. Client* client = 0;
  1051. if (player && player->IsPlayer())
  1052. client = spawn->GetZone()->GetClientBySpawn(player);
  1053. if (client)
  1054. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1055. else
  1056. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_Emote(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. string message = lua_interface->GetStringValue(state, 2);
  1066. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1067. Spawn* player = lua_interface->GetSpawn(state, 4);
  1068. char* to = 0;
  1069. if (spawn2)
  1070. to = spawn2->GetName();
  1071. if (spawn && message.length() > 0) {
  1072. Client* client = 0;
  1073. if (player && player->IsPlayer())
  1074. client = spawn->GetZone()->GetClientBySpawn(player);
  1075. if (client)
  1076. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1077. else
  1078. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1079. }
  1080. lua_interface->ResetFunctionStack(state);
  1081. return 0;
  1082. }
  1083. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1084. if (!lua_interface)
  1085. return 0;
  1086. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1087. if (!luaspell)
  1088. return 0;
  1089. Spawn* caster = luaspell->caster;
  1090. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1091. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1092. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1093. Spawn* target = lua_interface->GetSpawn(state, 4);
  1094. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1095. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1096. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1097. lua_interface->ResetFunctionStack(state);
  1098. boost::to_lower(heal_type);
  1099. if (caster && caster->IsEntity()) {
  1100. bool success = false;
  1101. luaspell->resisted = false;
  1102. if (target) {
  1103. float distance = caster->GetDistance(target, true);
  1104. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1105. success = true;
  1106. }
  1107. if (luaspell->targets.size() > 0) {
  1108. Spawn* target = 0;
  1109. ZoneServer* zone = luaspell->caster->GetZone();
  1110. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1111. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1112. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1113. float distance = caster->GetDistance(target, true);
  1114. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1115. }
  1116. }
  1117. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1118. success = true;
  1119. }
  1120. if (success) {
  1121. if (caster->GetZone())
  1122. caster->GetZone()->TriggerCharSheetTimer();
  1123. }
  1124. }
  1125. return 0;
  1126. }
  1127. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1128. if (!lua_interface)
  1129. return 0;
  1130. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1131. if (!luaspell)
  1132. return 0;
  1133. Spawn* caster = luaspell->caster;
  1134. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1135. float percentage = lua_interface->GetFloatValue(state, 2);
  1136. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1137. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1138. Spawn* target = lua_interface->GetSpawn(state, 5);
  1139. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1140. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1141. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1142. lua_interface->ResetFunctionStack(state);
  1143. boost::to_lower(heal_type);
  1144. int32 min_heal = 0, max_heal = 0;
  1145. if (caster && caster->IsEntity() && target) {
  1146. if(percentage <= 0.0f)
  1147. {
  1148. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1149. return 0;
  1150. }
  1151. if(heal_type == "power")
  1152. {
  1153. if(current_value)
  1154. {
  1155. if(caster_value)
  1156. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1157. else
  1158. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1159. }
  1160. else
  1161. {
  1162. if(caster_value)
  1163. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1164. else
  1165. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1166. }
  1167. }
  1168. else
  1169. {
  1170. if(current_value)
  1171. {
  1172. if(caster_value)
  1173. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1174. else
  1175. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1176. }
  1177. else
  1178. {
  1179. if(caster_value)
  1180. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1181. else
  1182. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1183. }
  1184. }
  1185. bool success = false;
  1186. luaspell->resisted = false;
  1187. if (target) {
  1188. float distance = caster->GetDistance(target, true);
  1189. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1190. success = true;
  1191. }
  1192. if (luaspell->targets.size() > 0) {
  1193. Spawn* target = 0;
  1194. ZoneServer* zone = luaspell->caster->GetZone();
  1195. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1196. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1197. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1198. float distance = caster->GetDistance(target, true);
  1199. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1200. }
  1201. }
  1202. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1203. success = true;
  1204. }
  1205. if (success) {
  1206. if (caster->GetZone())
  1207. caster->GetZone()->TriggerCharSheetTimer();
  1208. }
  1209. }
  1210. return 0;
  1211. }
  1212. int EQ2Emu_lua_AddItem(lua_State* state) {
  1213. if (!lua_interface)
  1214. return 0;
  1215. Spawn* spawn = lua_interface->GetSpawn(state);
  1216. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1217. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1218. // default of 1 quantity to add
  1219. if (quantity == 0)
  1220. quantity = 1;
  1221. if (spawn && spawn->IsPlayer()) {
  1222. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1223. if (client && item_id > 0) {
  1224. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1225. return 1;
  1226. }
  1227. }
  1228. lua_interface->SetBooleanValue(state, false);
  1229. return 1;
  1230. }
  1231. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1232. if (!lua_interface)
  1233. return 0;
  1234. Spawn* spawn = lua_interface->GetSpawn(state);
  1235. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1236. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1237. string location = lua_interface->GetStringValue(state, 4);
  1238. if (spawn && spawn->IsPlayer()) {
  1239. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1240. if (client && item_id > 0) {
  1241. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1242. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1243. else
  1244. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1245. if (send_messages) {
  1246. Item* item = master_item_list.GetItem(item_id);
  1247. if (item) {
  1248. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1249. string popup_text = "You receive " + item->name;
  1250. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1251. }
  1252. }
  1253. return 1;
  1254. }
  1255. }
  1256. lua_interface->SetBooleanValue(state, false);
  1257. return 1;
  1258. }
  1259. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1260. Spawn* spawn = lua_interface->GetSpawn(state);
  1261. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1262. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1263. // default of 1 to remove
  1264. if (quantity == 0)
  1265. quantity = 1;
  1266. Client* client;
  1267. Item* item;
  1268. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1269. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1270. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1271. if (client->RemoveItem(item, quantity)) {
  1272. lua_interface->SetBooleanValue(state, true);
  1273. return 1;
  1274. }
  1275. }
  1276. }
  1277. }
  1278. lua_interface->SetBooleanValue(state, false);
  1279. return 1;
  1280. }
  1281. int EQ2Emu_lua_HasItem(lua_State* state) {
  1282. Spawn* player = lua_interface->GetSpawn(state);
  1283. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1284. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1285. if (player && player->IsPlayer()) {
  1286. bool hasItem = false;
  1287. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1288. if (!hasItem)
  1289. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1290. lua_interface->SetBooleanValue(state, hasItem);
  1291. return 1;
  1292. }
  1293. lua_interface->SetBooleanValue(state, false);
  1294. return 1;
  1295. }
  1296. int EQ2Emu_lua_Spawn(lua_State* state) {
  1297. if (!lua_interface)
  1298. return 0;
  1299. ZoneServer* zone = lua_interface->GetZone(state);
  1300. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1301. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1302. float x = lua_interface->GetFloatValue(state, 4);
  1303. float y = lua_interface->GetFloatValue(state, 5);
  1304. float z = lua_interface->GetFloatValue(state, 6);
  1305. float heading = lua_interface->GetFloatValue(state, 7);
  1306. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1307. Spawn* spawn = zone->GetSpawn(spawn_id);
  1308. if (!spawn)
  1309. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1310. else {
  1311. spawn->SetX(x);
  1312. spawn->SetZ(z);
  1313. spawn->SetY(y,true,true);
  1314. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1315. spawn->SetHeading(heading);
  1316. if (restricted_npc)
  1317. spawn->AddAllowAccessSpawn(spawn);
  1318. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1319. bool scriptActive = false;
  1320. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1321. scriptActive = true;
  1322. spawn->SetSpawnScript(string(spawn_script));
  1323. }
  1324. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1325. zone->AddSpawn(spawn);
  1326. if (scriptActive) {
  1327. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1328. }
  1329. lua_interface->SetSpawnValue(state, spawn);
  1330. return 1;
  1331. }
  1332. }
  1333. else {
  1334. string output = "Invalid paramaters to LUA Spawn command: \n";
  1335. if (!zone)
  1336. output = output.append("\t").append("Missing zone reference. \n");
  1337. if (spawn_id == 0)
  1338. output = output.append("\t").append("Missing spawn_id.");
  1339. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1340. }
  1341. return 0;
  1342. }
  1343. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1344. if (!lua_interface)
  1345. return 0;
  1346. ZoneServer* zone = lua_interface->GetZone(state);
  1347. if (zone) {
  1348. lua_interface->SetStringValue(state, zone->GetZoneName());
  1349. return 1;
  1350. }
  1351. return 0;
  1352. }
  1353. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1354. if (!lua_interface)
  1355. return 0;
  1356. ZoneServer* zone = lua_interface->GetZone(state);
  1357. if (zone) {
  1358. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1359. return 1;
  1360. }
  1361. return 0;
  1362. }
  1363. int EQ2Emu_lua_GetZone(lua_State* state) {
  1364. if (!lua_interface)
  1365. return 0;
  1366. int32 zone_id = lua_interface->GetInt32Value(state);
  1367. ZoneServer* zone = 0;
  1368. if (zone_id > 0)
  1369. zone = zone_list.Get(zone_id);
  1370. else {
  1371. string zone_name = lua_interface->GetStringValue(state);
  1372. if (zone_name.length() > 0) {
  1373. zone = zone_list.Get(zone_name.c_str());
  1374. }
  1375. else {
  1376. Spawn* spawn = lua_interface->GetSpawn(state);
  1377. if (spawn)
  1378. zone = spawn->GetZone();
  1379. }
  1380. }
  1381. if (zone) {
  1382. lua_interface->SetZoneValue(state, zone);
  1383. return 1;
  1384. }
  1385. return 0;
  1386. }
  1387. int EQ2Emu_lua_AddHate(lua_State* state) {
  1388. Spawn* entity = lua_interface->GetSpawn(state);
  1389. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1390. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1391. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1392. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1393. if (entity && entity->IsEntity() && amount != 0) {
  1394. if (luaspell) {
  1395. ZoneServer* zone = luaspell->caster->GetZone();
  1396. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1397. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1398. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1399. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1400. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1401. if (send_packet)
  1402. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1403. }
  1404. }
  1405. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1406. }
  1407. else if (npc && npc->IsNPC() && npc->GetZone())
  1408. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1409. }
  1410. return 0;
  1411. }
  1412. int EQ2Emu_lua_Zone(lua_State* state) {
  1413. if (!lua_interface)
  1414. return 0;
  1415. ZoneServer* zone = lua_interface->GetZone(state);
  1416. Spawn* player = lua_interface->GetSpawn(state, 2);
  1417. Client* client = 0;
  1418. if (player && player->IsPlayer())
  1419. client = player->GetZone()->GetClientBySpawn(player);
  1420. float x = lua_interface->GetFloatValue(state, 3);
  1421. float y = lua_interface->GetFloatValue(state, 4);
  1422. float z = lua_interface->GetFloatValue(state, 5);
  1423. float heading = lua_interface->GetFloatValue(state, 6);
  1424. if (zone && client) {
  1425. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1426. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1427. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1428. {
  1429. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1430. return 0;
  1431. }
  1432. if (x != 0 || y != 0 || z != 0) {
  1433. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1434. player->SetX(x);
  1435. player->SetY(y);
  1436. player->SetZ(z);
  1437. player->SetHeading(heading);
  1438. client->Zone(zone->GetZoneName(), false);
  1439. }
  1440. else
  1441. client->Zone(zone->GetZoneName());
  1442. }
  1443. else
  1444. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1445. return 0;
  1446. }
  1447. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1448. if (!lua_interface)
  1449. return 0;
  1450. Spawn* spawn = lua_interface->GetSpawn(state);
  1451. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1452. if (spawn && spawn2)
  1453. spawn->AddAllowAccessSpawn(spawn2);
  1454. return 0;
  1455. }
  1456. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1457. if (!lua_interface)
  1458. return 0;
  1459. Spawn* target = lua_interface->GetSpawn(state);
  1460. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1461. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1462. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1463. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1464. if (!target) {
  1465. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1466. return 0;
  1467. }
  1468. if (!target->IsEntity()) {
  1469. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1470. return 0;
  1471. }
  1472. if (spell_id <= 0) {
  1473. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1474. return 0;
  1475. }
  1476. if (caster && !caster->IsEntity()) {
  1477. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1478. return 0;
  1479. }
  1480. if (spell_tier == 0)
  1481. spell_tier = 1;
  1482. if (!caster)
  1483. caster = target;
  1484. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1485. return 0;
  1486. }
  1487. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1488. if (!lua_interface)
  1489. return 0;
  1490. Spawn* target = lua_interface->GetSpawn(state);
  1491. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1492. if (!luaspell)
  1493. return 0;
  1494. Spawn* caster = luaspell->caster;
  1495. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1496. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1497. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1498. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1499. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1500. //lua_interface->ResetFunctionStack(state);
  1501. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1502. vector<int16> faction_req;
  1503. vector<int16> race_req;
  1504. int32 class_req = 0;
  1505. int32 i = 0;
  1506. int8 f = 0;
  1507. int8 r = 0;
  1508. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1509. if (class_id < 100) {
  1510. class_req += pow(2.0, double(class_id - 1));
  1511. }
  1512. else if (class_id > 100 && class_id < 1000) {
  1513. race_req.push_back(class_id);
  1514. r++;
  1515. }
  1516. else {
  1517. faction_req.push_back(class_id);
  1518. f++;
  1519. }
  1520. i++;
  1521. }
  1522. if (caster && caster->IsEntity()) {
  1523. bool race_match = false;
  1524. bool success = false;
  1525. luaspell->resisted = false;
  1526. if (luaspell->targets.size() > 0) {
  1527. ZoneServer* zone = luaspell->caster->GetZone();
  1528. Spawn* target = 0;
  1529. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1530. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1531. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1532. if (race_req.size() > 0) {
  1533. for (int8 i = 0; i < race_req.size(); i++) {
  1534. if (target->GetLuaRaceId() == race_req[i]) {
  1535. race_match = true;
  1536. }
  1537. }
  1538. }
  1539. else
  1540. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1541. if (race_match == true) {
  1542. float distance = caster->GetDistance(target, true);
  1543. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1544. }
  1545. }
  1546. }
  1547. success = true;
  1548. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1549. }
  1550. else if (target) {
  1551. //check class and race/faction here
  1552. if (race_req.size() > 0) {
  1553. for (int8 i = 0; i < race_req.size(); i++) {
  1554. if (target->GetLuaRaceId() == race_req[i]) {
  1555. race_match = true;
  1556. }
  1557. }
  1558. }
  1559. else
  1560. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1561. if (race_match == true) {
  1562. float distance = caster->GetDistance(target, true);
  1563. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1564. success = true;
  1565. }
  1566. }
  1567. if (success) {
  1568. Spell* spell = luaspell->spell;
  1569. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1570. ((Player*)caster)->InCombat(true);
  1571. if (caster->GetZone())
  1572. caster->GetZone()->TriggerCharSheetTimer();
  1573. }
  1574. }
  1575. }
  1576. return 0;
  1577. }
  1578. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1579. if (!lua_interface)
  1580. return 0;
  1581. Spawn* spawn = lua_interface->GetSpawn(state);
  1582. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1583. lua_interface->ResetFunctionStack(state);
  1584. if (spawn && value != 0) {
  1585. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1586. spawn->SetPower(spawn->GetTotalPower());
  1587. else
  1588. spawn->SetPower(spawn->GetPower() + value);
  1589. }
  1590. return 0;
  1591. }
  1592. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1593. if (!lua_interface)
  1594. return 0;
  1595. Spawn* spawn = lua_interface->GetSpawn(state);
  1596. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1597. lua_interface->ResetFunctionStack(state);
  1598. if (spawn && value != 0) {
  1599. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1600. spawn->SetHP(spawn->GetTotalHP());
  1601. else
  1602. spawn->SetHP(spawn->GetHP() + value);
  1603. }
  1604. return 0;
  1605. }
  1606. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1607. if (!lua_interface)
  1608. return 0;
  1609. Spawn* spawn = lua_interface->GetSpawn(state);
  1610. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1611. lua_interface->ResetFunctionStack(state);
  1612. if (spawn && value != 0) {
  1613. spawn->SetPower(spawn->GetPower() + value);
  1614. if (value > spawn->GetTotalHPBase())
  1615. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1616. }
  1617. return 0;
  1618. }
  1619. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1620. if (!lua_interface)
  1621. return 0;
  1622. Spawn* spawn = lua_interface->GetSpawn(state);
  1623. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1624. lua_interface->ResetFunctionStack(state);
  1625. if (spawn && value != 0) {
  1626. spawn->SetHP(spawn->GetHP() + value);
  1627. if (value > spawn->GetTotalHPBase())
  1628. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1629. }
  1630. return 0;
  1631. }
  1632. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1633. if (!lua_interface)
  1634. return 0;
  1635. Spawn* spawn = lua_interface->GetSpawn(state);
  1636. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1637. lua_interface->ResetFunctionStack(state);
  1638. if (spawn) {
  1639. spawn->SetHP(value);
  1640. if (value > spawn->GetTotalHPBase())
  1641. spawn->SetTotalHP(value);
  1642. }
  1643. return 0;
  1644. }
  1645. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1646. if (!lua_interface)
  1647. return 0;
  1648. Spawn* spawn = lua_interface->GetSpawn(state);
  1649. float value = lua_interface->GetFloatValue(state, 2);
  1650. lua_interface->ResetFunctionStack(state);
  1651. if (spawn && spawn->IsEntity() && value > 0)
  1652. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1653. if (spawn->IsPlayer())
  1654. ((Player*)spawn)->SetCharSheetChanged(true);
  1655. return 0;
  1656. }
  1657. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1658. if (!lua_interface)
  1659. return 0;
  1660. Spawn* spawn = lua_interface->GetSpawn(state);
  1661. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1662. lua_interface->ResetFunctionStack(state);
  1663. if (spawn && spawn->IsEntity() && value > 0)
  1664. ((Entity*)spawn)->SetTotalHPBase(value);
  1665. return 0;
  1666. }
  1667. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1668. if (!lua_interface)
  1669. return 0;
  1670. Spawn* spawn = lua_interface->GetSpawn(state);
  1671. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1672. lua_interface->ResetFunctionStack(state);
  1673. if (spawn && value > 0) {
  1674. spawn->SetPower(value);
  1675. if (value > spawn->GetTotalPowerBase())
  1676. spawn->SetTotalPower(value);
  1677. }
  1678. return 0;
  1679. }
  1680. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1681. if (!lua_interface)
  1682. return 0;
  1683. Spawn* spawn = lua_interface->GetSpawn(state);
  1684. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1685. lua_interface->ResetFunctionStack(state);
  1686. if (spawn && spawn->IsEntity() && value > 0)
  1687. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1688. return 0;
  1689. }
  1690. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1691. if (!lua_interface)
  1692. return 0;
  1693. Spawn* spawn = lua_interface->GetSpawn(state);
  1694. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1695. lua_interface->ResetFunctionStack(state);
  1696. if (spawn && spawn->IsEntity() && value > 0)
  1697. ((Entity*)spawn)->SetTotalPowerBase(value);
  1698. return 0;
  1699. }
  1700. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1701. if (!lua_interface)
  1702. return 0;
  1703. Spawn* spawn = lua_interface->GetSpawn(state);
  1704. float x = lua_interface->GetFloatValue(state, 2);
  1705. float y = lua_interface->GetFloatValue(state, 3);
  1706. float z = lua_interface->GetFloatValue(state, 4);
  1707. float heading = lua_interface->GetFloatValue(state, 5);
  1708. lua_interface->ResetFunctionStack(state);
  1709. if (spawn) {
  1710. spawn->SetX(x);
  1711. spawn->SetY(y);
  1712. spawn->SetZ(z);
  1713. if (heading != 0)
  1714. spawn->SetHeading(heading);
  1715. spawn->SetSpawnOrigX(spawn->GetX());
  1716. spawn->SetSpawnOrigY(spawn->GetY());
  1717. spawn->SetSpawnOrigZ(spawn->GetZ());
  1718. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1719. if (spawn->IsPlayer()) {
  1720. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1721. if (client) {
  1722. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1723. client->QueuePacket(packet);
  1724. }
  1725. }
  1726. }
  1727. return 0;
  1728. }
  1729. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1730. if (!lua_interface)
  1731. return 0;
  1732. Spawn* spawn = lua_interface->GetSpawn(state);
  1733. float value = lua_interface->GetFloatValue(state, 2);
  1734. lua_interface->ResetFunctionStack(state);
  1735. if (spawn) {
  1736. spawn->SetHeading(value);
  1737. if (spawn->IsPlayer()) {
  1738. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1739. if (client) {
  1740. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1741. client->QueuePacket(packet);
  1742. }
  1743. }
  1744. }
  1745. return 0;
  1746. }
  1747. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1748. if (!lua_interface)
  1749. return 0;
  1750. Spawn* spawn = lua_interface->GetSpawn(state);
  1751. int16 value = lua_interface->GetInt16Value(state, 2);
  1752. lua_interface->ResetFunctionStack(state);
  1753. if (spawn)
  1754. spawn->SetModelType(value);
  1755. return 0;
  1756. }
  1757. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1758. if (!lua_interface)
  1759. return 0;
  1760. Spawn* spawn = lua_interface->GetSpawn(state);
  1761. int8 value = lua_interface->GetInt8Value(state, 2);
  1762. lua_interface->ResetFunctionStack(state);
  1763. if (spawn) {
  1764. if (spawn->IsPlayer())
  1765. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1766. else
  1767. spawn->SetAdventureClass(value);
  1768. }
  1769. return 0;
  1770. }
  1771. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1772. if (!lua_interface)
  1773. return 0;
  1774. Spawn* spawn = lua_interface->GetSpawn(state);
  1775. int8 value = lua_interface->GetInt8Value(state, 2);
  1776. lua_interface->ResetFunctionStack(state);
  1777. if (spawn) {
  1778. spawn->SetTradeskillClass(value);
  1779. if (spawn->IsEntity()) {
  1780. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1781. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1782. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1783. }
  1784. if (spawn->IsPlayer())
  1785. ((Player*)spawn)->SetCharSheetChanged(true);
  1786. }
  1787. return 0;
  1788. }
  1789. int EQ2Emu_lua_SetMount(lua_State* state) {
  1790. if (!lua_interface)
  1791. return 0;
  1792. Spawn* spawn = lua_interface->GetSpawn(state);
  1793. int16 value = lua_interface->GetInt16Value(state, 2);
  1794. if (spawn && spawn->IsEntity()) {
  1795. ((Entity*)spawn)->SetMount(value);
  1796. EQ2_Color color;
  1797. color.red = 255;
  1798. color.green = 255;
  1799. color.blue = 255;
  1800. ((Entity*)spawn)->SetMountColor(&color);
  1801. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1802. }
  1803. return 0;
  1804. }
  1805. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1806. if (!lua_interface)
  1807. return 0;
  1808. Spawn* spawn = lua_interface->GetSpawn(state);
  1809. EQ2_Color mount_color;
  1810. EQ2_Color saddle_color;
  1811. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1812. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1813. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1814. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1815. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1816. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1817. if (spawn && spawn->IsEntity()) {
  1818. ((Entity*)spawn)->SetMountColor(&mount_color);
  1819. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1820. }
  1821. return 0;
  1822. }
  1823. int EQ2Emu_lua_GetMount(lua_State* state) {
  1824. if (!lua_interface)
  1825. return 0;
  1826. Spawn* spawn = lua_interface->GetSpawn(state);
  1827. if (spawn && spawn->IsEntity()) {
  1828. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1829. return 1;
  1830. }
  1831. return 0;
  1832. }
  1833. int EQ2Emu_lua_GetRace(lua_State* state) {
  1834. if (!lua_interface)
  1835. return 0;
  1836. Spawn* spawn = lua_interface->GetSpawn(state);
  1837. if (spawn)
  1838. {
  1839. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1840. lua_interface->SetInt32Value(state, spawn->GetRace());
  1841. return 1;
  1842. }
  1843. return 0;
  1844. }
  1845. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1846. if (!lua_interface)
  1847. return 0;
  1848. Spawn* spawn = lua_interface->GetSpawn(state);
  1849. if (spawn) {
  1850. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1851. return 1;
  1852. }
  1853. return 0;
  1854. }
  1855. int EQ2Emu_lua_GetClass(lua_State* state) {
  1856. Spawn* spawn = lua_interface->GetSpawn(state);
  1857. if (spawn) {
  1858. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1859. return 1;
  1860. }
  1861. return 0;
  1862. }
  1863. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1864. Spawn* spawn = lua_interface->GetSpawn(state);
  1865. if (spawn) {
  1866. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1867. return 1;
  1868. }
  1869. return 0;
  1870. }
  1871. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1872. if (!lua_interface)
  1873. return 0;
  1874. Spawn* spawn = lua_interface->GetSpawn(state);
  1875. float value = lua_interface->GetFloatValue(state, 2);
  1876. lua_interface->ResetFunctionStack(state);
  1877. if (spawn) {
  1878. spawn->SetSpeed(value);
  1879. ((Entity*)spawn)->SetSpeed(value);
  1880. if (spawn->IsPlayer()) {
  1881. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1882. if (client) {
  1883. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1884. if (packet) {
  1885. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1886. packet->setDataByName("speed", value);
  1887. packet->setDataByName("size", 0.51);
  1888. EQ2Packet* app = packet->serialize();
  1889. client->QueuePacket(app);
  1890. safe_delete(packet);
  1891. }
  1892. }
  1893. }
  1894. }
  1895. return 0;
  1896. }
  1897. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1898. if (!lua_interface)
  1899. return 0;
  1900. Spawn* spawn = lua_interface->GetSpawn(state);
  1901. const int16 type = lua_interface->GetInt16Value(state, 2);
  1902. const float value = lua_interface->GetFloatValue(state, 3);
  1903. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1904. int64 class_req = 0;
  1905. int32 class_id = 0;
  1906. vector<int16> faction_req;
  1907. vector<int16> race_req;
  1908. int32 i = 0;
  1909. int8 f = 0;
  1910. int8 r = 0;
  1911. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1912. if (class_id < 100) {
  1913. class_req += pow(2.0, double(class_id - 1));
  1914. }
  1915. else if (class_id > 100 && class_id < 1000) {
  1916. race_req.push_back(class_id);
  1917. r++;
  1918. }
  1919. else {
  1920. faction_req.push_back(class_id);
  1921. f++;
  1922. }
  1923. i++;
  1924. }
  1925. if (value != 0 && type >= 0) {
  1926. if (luaspell && luaspell->spell && luaspell->caster) {
  1927. ZoneServer* zone = luaspell->caster->GetZone();
  1928. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1929. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1930. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1931. if (target) {
  1932. if (target->IsPlayer()) {
  1933. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1934. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1935. if (((Player*)target)->GetGroupMemberInfo())
  1936. ((Player*)target)->UpdateGroupMemberInfo();
  1937. ((Player*)target)->SetCharSheetChanged(true);
  1938. }
  1939. else if (target->IsNPC())
  1940. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1941. else
  1942. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1943. }
  1944. }
  1945. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1946. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1947. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1948. }
  1949. else if (spawn && spawn->IsEntity()) {
  1950. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1951. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1952. if (spawn->IsPlayer())
  1953. ((Player*)spawn)->SetCharSheetChanged(true);
  1954. }
  1955. else
  1956. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1957. }
  1958. else
  1959. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1960. return 0;
  1961. }
  1962. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1963. if (!lua_interface)
  1964. return 0;
  1965. Spawn* spawn = lua_interface->GetSpawn(state);
  1966. int16 type = lua_interface->GetInt16Value(state, 2);
  1967. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1968. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1969. if (!spawn) {
  1970. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1971. return 0;
  1972. }
  1973. if (!spawn->IsEntity()) {
  1974. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1975. return 0;
  1976. }
  1977. if (value == 0) {
  1978. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1979. return 0;
  1980. }
  1981. if (!luaspell || !luaspell->spell) {
  1982. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1983. return 0;
  1984. }
  1985. int32 class_req = 0;
  1986. vector<int16> faction_req;
  1987. vector<int16> race_req;
  1988. int32 class_id = 0;
  1989. int32 i = 0;
  1990. int8 f = 0;
  1991. int8 r = 0;
  1992. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1993. if (class_id < 100) {
  1994. class_req += pow(2.0, double(class_id - 1));
  1995. }
  1996. else if (class_id > 100 && class_id < 1000) {
  1997. race_req.push_back(class_id);
  1998. r++;
  1999. }
  2000. else {
  2001. faction_req.push_back(class_id);
  2002. f++;
  2003. }
  2004. i++;
  2005. }
  2006. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2007. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2008. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2009. if (spawn->IsPlayer())
  2010. ((Player*)spawn)->SetCharSheetChanged(true);
  2011. return 0;
  2012. }
  2013. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2014. if (!lua_interface)
  2015. return 0;
  2016. Spawn* spawn = lua_interface->GetSpawn(state);
  2017. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2018. if (!spawn) {
  2019. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2020. return 0;
  2021. }
  2022. if (!spawn->IsEntity()) {
  2023. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2024. return 0;
  2025. }
  2026. if (!luaspell || !luaspell->spell) {
  2027. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2028. return 0;
  2029. }
  2030. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2031. if (spawn->IsPlayer())
  2032. ((Player*)spawn)->SetCharSheetChanged(true);
  2033. return 0;
  2034. }
  2035. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2036. if (!lua_interface)
  2037. return 0;
  2038. Spawn* spawn = lua_interface->GetSpawn(state);
  2039. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2040. if (luaspell && luaspell->spell) {
  2041. ZoneServer* zone = luaspell->caster->GetZone();
  2042. Spawn* target = 0;
  2043. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2044. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2045. target = zone->GetSpawnByID(luaspell->targets[i]);
  2046. if (target && target->IsEntity()) {
  2047. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2048. if (target->IsPlayer())
  2049. ((Player*)target)->SetCharSheetChanged(true);
  2050. }
  2051. }
  2052. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2053. }
  2054. else if (spawn && spawn->IsEntity()) {
  2055. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2056. if (spawn->IsPlayer())
  2057. ((Player*)spawn)->SetCharSheetChanged(true);
  2058. }
  2059. return 0;
  2060. }
  2061. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2062. if (!lua_interface)
  2063. return 0;
  2064. Spawn* spawn = lua_interface->GetSpawn(state);
  2065. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2066. float value = lua_interface->GetFloatValue(state, 3);
  2067. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2068. if (value != 0) {
  2069. int32 spell_id = 0;
  2070. if (luaspell && luaspell->spell && luaspell->caster) {
  2071. spell_id = luaspell->spell->GetSpellID();
  2072. ZoneServer* zone = luaspell->caster->GetZone();
  2073. Spawn* target = 0;
  2074. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2075. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2076. target = zone->GetSpawnByID(luaspell->targets[i]);
  2077. if (target && target->Alive()) {
  2078. if (target->IsPlayer()) {
  2079. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2080. Client* client = target->GetZone()->GetClientBySpawn(target);
  2081. if (client) {
  2082. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2083. if (packet)
  2084. client->QueuePacket(packet);
  2085. }
  2086. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2087. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2088. }
  2089. else if (target->IsNPC()) {
  2090. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2091. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2092. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2093. }
  2094. else
  2095. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2096. }
  2097. }
  2098. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2099. }
  2100. else if (spawn) {
  2101. if (spawn->IsPlayer()) {
  2102. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2103. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2104. if (client) {
  2105. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2106. if (packet)
  2107. client->QueuePacket(packet);
  2108. }
  2109. }
  2110. else if (spawn->IsNPC())
  2111. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2112. else
  2113. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2114. }
  2115. }
  2116. else
  2117. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2118. return 0;
  2119. }
  2120. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2121. if (!lua_interface)
  2122. return 0;
  2123. Spawn* spawn = lua_interface->GetSpawn(state);
  2124. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2125. if (spawn && spawn->IsPlayer()) {
  2126. int32 spell_id = 0;
  2127. if (luaspell && luaspell->spell) {
  2128. spell_id = luaspell->spell->GetSpellID();
  2129. ZoneServer* zone = luaspell->caster->GetZone();
  2130. Spawn* target = 0;
  2131. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2132. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2133. target = zone->GetSpawnByID(luaspell->targets[i]);
  2134. if (target) {
  2135. if (target->IsPlayer()) {
  2136. ((Player*)target)->RemoveSkillBonus(spell_id);
  2137. Client* client = target->GetZone()->GetClientBySpawn(target);
  2138. if (client) {
  2139. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2140. if (packet)
  2141. client->QueuePacket(packet);
  2142. }
  2143. }
  2144. else if (target->IsNPC())
  2145. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2146. else
  2147. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2148. }
  2149. }
  2150. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2151. }
  2152. else if (spawn) {
  2153. if (spawn->IsPlayer()) {
  2154. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2155. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2156. if (client) {
  2157. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2158. if (packet)
  2159. client->QueuePacket(packet);
  2160. }
  2161. }
  2162. else if (spawn->IsNPC())
  2163. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2164. else
  2165. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2166. }
  2167. }
  2168. return 0;
  2169. }
  2170. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2171. if (!lua_interface)
  2172. return 0;
  2173. Spawn* spawn = lua_interface->GetSpawn(state);
  2174. int8 type = lua_interface->GetInt32Value(state, 2);
  2175. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2176. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2177. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2178. ZoneServer* zone = luaspell->caster->GetZone();
  2179. Spawn* target = 0;
  2180. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2181. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2182. target = zone->GetSpawnByID(luaspell->targets[i]);
  2183. if (target && target->IsEntity()) {
  2184. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2185. ((Entity*)target)->AddMezSpell(luaspell);
  2186. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2187. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2188. if (target->IsNPC())
  2189. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2190. }
  2191. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2192. ((Entity*)target)->AddStifleSpell(luaspell);
  2193. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2194. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2195. if (target->IsNPC())
  2196. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2197. }
  2198. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2199. ((Entity*)target)->AddDazeSpell(luaspell);
  2200. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2201. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2202. if (target->IsNPC())
  2203. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2204. }
  2205. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2206. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2207. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2208. ((Entity*)target)->AddStunSpell(luaspell);
  2209. if (target->IsNPC())
  2210. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2211. }
  2212. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2213. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2214. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2215. ((Entity*)target)->AddRootSpell(luaspell);
  2216. if (target->IsNPC())
  2217. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2218. }
  2219. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2220. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2221. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2222. ((Entity*)target)->AddFearSpell(luaspell);
  2223. if (target->IsNPC())
  2224. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2225. }
  2226. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2227. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2228. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2229. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2230. }
  2231. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2232. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2233. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2234. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2235. }
  2236. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2237. ((Entity*)target)->AddSnareSpell(luaspell);
  2238. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2239. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2240. if (target->IsNPC())
  2241. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2242. }
  2243. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2244. ((Entity*)target)->AddFlightSpell(luaspell);
  2245. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2246. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2247. }
  2248. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2249. ((Entity*)target)->AddGlideSpell(luaspell);
  2250. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2251. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2252. }
  2253. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2254. ((Entity*)target)->AddSafefallSpell(luaspell);
  2255. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2256. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2257. }
  2258. else
  2259. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2260. }
  2261. else
  2262. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2263. }
  2264. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2265. }
  2266. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2267. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2268. ((Entity*)spawn)->AddMezSpell(luaspell);
  2269. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2270. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2271. }
  2272. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2273. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2274. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2275. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2276. }
  2277. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2278. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2279. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2280. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2281. }
  2282. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2283. ((Entity*)spawn)->AddStunSpell(luaspell);
  2284. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2285. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2286. }
  2287. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2288. ((Entity*)spawn)->AddRootSpell(luaspell);
  2289. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2290. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2291. }
  2292. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2293. ((Entity*)spawn)->AddFearSpell(luaspell);
  2294. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2295. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2296. }
  2297. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2298. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2299. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2300. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2301. }
  2302. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2303. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2304. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2305. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2306. }
  2307. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2308. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2309. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2310. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2311. }
  2312. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2313. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2314. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2315. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2316. }
  2317. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2318. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2319. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2320. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2321. }
  2322. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2323. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2324. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2325. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2326. }
  2327. else
  2328. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2329. }
  2330. else
  2331. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2332. return 0;
  2333. }
  2334. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2335. if (!lua_interface)
  2336. return 0;
  2337. Spawn* spawn = lua_interface->GetSpawn(state);
  2338. int8 type = lua_interface->GetInt8Value(state, 2);
  2339. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2340. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2341. if (spawn && spawn->IsEntity()) {
  2342. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2343. ZoneServer* zone = luaspell->caster->GetZone();
  2344. Spawn* target = 0;
  2345. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2346. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2347. target = zone->GetSpawnByID(luaspell->targets[i]);
  2348. if (target) {
  2349. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2350. ((Entity*)target)->RemoveMezSpell(luaspell);
  2351. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2352. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2353. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2354. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2355. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2356. ((Entity*)target)->RemoveStunSpell(luaspell);
  2357. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2358. ((Entity*)target)->RemoveRootSpell(luaspell);
  2359. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2360. ((Entity*)target)->RemoveFearSpell(luaspell);
  2361. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2362. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2363. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2364. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2365. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2366. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2367. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2368. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2369. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2370. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2371. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2372. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2373. else
  2374. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2375. }
  2376. }
  2377. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2378. }
  2379. else if (only_remove_spawn) {
  2380. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2381. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2382. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2383. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2384. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2385. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2386. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2387. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2388. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2389. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2390. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2391. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2392. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2393. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2394. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2395. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2396. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2397. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2398. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2399. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2400. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2401. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2402. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2403. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2404. else
  2405. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2406. }
  2407. }
  2408. return 0;
  2409. }
  2410. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2411. if (!lua_interface)
  2412. return 0;
  2413. Spawn* spawn = lua_interface->GetSpawn(state);
  2414. int8 type = lua_interface->GetInt8Value(state, 2);
  2415. bool hasEffect = false;
  2416. if (!spawn)
  2417. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2418. else if (!spawn->IsEntity())
  2419. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2420. else if (type < CONTROL_MAX_EFFECTS)
  2421. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2422. else
  2423. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2424. lua_interface->SetBooleanValue(state, hasEffect);
  2425. return 1;
  2426. }
  2427. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2428. if (!lua_interface)
  2429. return 0;
  2430. Spawn* spawn = lua_interface->GetSpawn(state);
  2431. float distance = 0.0f;
  2432. if (!spawn)
  2433. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2434. else if (!spawn->IsNPC())
  2435. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2436. else
  2437. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2438. lua_interface->SetFloatValue(state, distance);
  2439. return 1;
  2440. }
  2441. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2442. if (!lua_interface)
  2443. return 0;
  2444. Spawn* spawn = lua_interface->GetSpawn(state);
  2445. float distance = 0.0f;
  2446. if (!spawn)
  2447. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2448. else if (!spawn->IsNPC())
  2449. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2450. else
  2451. distance = ((NPC*)spawn)->GetAggroRadius();
  2452. lua_interface->SetFloatValue(state, distance);
  2453. return 1;
  2454. }
  2455. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2456. if (!lua_interface)
  2457. return 0;
  2458. Spawn* spawn = lua_interface->GetSpawn(state);
  2459. float distance = lua_interface->GetFloatValue(state, 2);
  2460. bool override = lua_interface->GetBooleanValue(state, 3);
  2461. bool result = false;
  2462. lua_interface->ResetFunctionStack(state);
  2463. if (!spawn)
  2464. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2465. else if (!spawn->IsNPC())
  2466. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2467. else
  2468. {
  2469. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2470. result = true;
  2471. }
  2472. lua_interface->SetBooleanValue(state, result);
  2473. return 1;
  2474. }
  2475. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2476. if (!lua_interface)
  2477. return 0;
  2478. Spawn* spawn = lua_interface->GetSpawn(state);
  2479. int16 value = lua_interface->GetInt16Value(state, 2);
  2480. if (spawn && spawn->IsEntity()) {
  2481. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2482. if (spawn->IsPlayer())
  2483. ((Player*)spawn)->SetCharSheetChanged(true);
  2484. }
  2485. return 0;
  2486. }
  2487. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2488. if (!lua_interface)
  2489. return 0;
  2490. Spawn* spawn = lua_interface->GetSpawn(state);
  2491. int16 value = lua_interface->GetInt16Value(state, 2);
  2492. if (spawn && spawn->IsEntity()) {
  2493. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2494. if (spawn->IsPlayer())
  2495. ((Player*)spawn)->SetCharSheetChanged(true);
  2496. }
  2497. return 0;
  2498. }
  2499. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2500. if (!lua_interface)
  2501. return 0;
  2502. Spawn* spawn = lua_interface->GetSpawn(state);
  2503. int16 value = lua_interface->GetInt16Value(state, 2);
  2504. if (spawn && spawn->IsEntity()) {
  2505. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2506. if (spawn->IsPlayer())
  2507. ((Player*)spawn)->SetCharSheetChanged(true);
  2508. }
  2509. return 0;
  2510. }
  2511. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2512. if (!lua_interface)
  2513. return 0;
  2514. Spawn* spawn = lua_interface->GetSpawn(state);
  2515. int16 value = lua_interface->GetInt16Value(state, 2);
  2516. if (spawn && spawn->IsEntity()) {
  2517. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2518. if (spawn->IsPlayer())
  2519. ((Player*)spawn)->SetCharSheetChanged(true);
  2520. }
  2521. return 0;
  2522. }
  2523. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2524. if (!lua_interface)
  2525. return 0;
  2526. Spawn* spawn = lua_interface->GetSpawn(state);
  2527. int16 value = lua_interface->GetInt16Value(state, 2);
  2528. if (spawn && spawn->IsEntity()) {
  2529. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2530. if (spawn->IsPlayer())
  2531. ((Player*)spawn)->SetCharSheetChanged(true);
  2532. }
  2533. return 0;
  2534. }
  2535. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2536. if (!lua_interface)
  2537. return 0;
  2538. Spawn* spawn = lua_interface->GetSpawn(state);
  2539. int8 value = lua_interface->GetInt8Value(state, 2);
  2540. if (spawn && spawn->IsEntity()) {
  2541. ((Entity*)spawn)->SetDeity(value);
  2542. if (spawn->IsPlayer())
  2543. ((Player*)spawn)->SetCharSheetChanged(true);
  2544. }
  2545. lua_interface->ResetFunctionStack(state);
  2546. return 0;
  2547. }
  2548. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2549. if (!lua_interface)
  2550. return 0;
  2551. Spawn* spawn = lua_interface->GetSpawn(state);
  2552. if (spawn && spawn->IsEntity()) {
  2553. int8 deity = ((Entity*)spawn)->GetDeity();
  2554. lua_interface->SetInt32Value(state, deity);
  2555. return 1;
  2556. }
  2557. return 0;
  2558. }
  2559. int EQ2Emu_lua_SetInt(lua_State* state) {
  2560. if (!lua_interface)
  2561. return 0;
  2562. Spawn* spawn = lua_interface->GetSpawn(state);
  2563. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2564. if (spawn && spawn->IsEntity()) {
  2565. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2566. if (spawn->IsPlayer())
  2567. ((Player*)spawn)->SetCharSheetChanged(true);
  2568. }
  2569. return 0;
  2570. }
  2571. int EQ2Emu_lua_SetWis(lua_State* state) {
  2572. if (!lua_interface)
  2573. return 0;
  2574. Spawn* spawn = lua_interface->GetSpawn(state);
  2575. float value = lua_interface->GetFloatValue(state, 2);
  2576. if (spawn && spawn->IsEntity()) {
  2577. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2578. if (spawn->IsPlayer())
  2579. ((Player*)spawn)->SetCharSheetChanged(true);
  2580. }
  2581. return 0;
  2582. }
  2583. int EQ2Emu_lua_SetSta(lua_State* state) {
  2584. if (!lua_interface)
  2585. return 0;
  2586. Spawn* spawn = lua_interface->GetSpawn(state);
  2587. float value = lua_interface->GetFloatValue(state, 2);
  2588. if (spawn && spawn->IsEntity()) {
  2589. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2590. if (spawn->IsPlayer())
  2591. ((Player*)spawn)->SetCharSheetChanged(true);
  2592. }
  2593. return 0;
  2594. }
  2595. int EQ2Emu_lua_SetStr(lua_State* state) {
  2596. if (!lua_interface)
  2597. return 0;
  2598. Spawn* spawn = lua_interface->GetSpawn(state);
  2599. float value = lua_interface->GetFloatValue(state, 2);
  2600. if (spawn && spawn->IsEntity()) {
  2601. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2602. if (spawn->IsPlayer())
  2603. ((Player*)spawn)->SetCharSheetChanged(true);
  2604. }
  2605. return 0;
  2606. }
  2607. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2608. if (!lua_interface)
  2609. return 0;
  2610. Spawn* spawn = lua_interface->GetSpawn(state);
  2611. float value = lua_interface->GetFloatValue(state, 2);
  2612. if (spawn && spawn->IsEntity()) {
  2613. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2614. if (spawn->IsPlayer())
  2615. ((Player*)spawn)->SetCharSheetChanged(true);
  2616. }
  2617. return 0;
  2618. }
  2619. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2620. if (!lua_interface)
  2621. return 0;
  2622. Spawn* spawn = lua_interface->GetSpawn(state);
  2623. if (spawn) {
  2624. lua_interface->SetInt32Value(state, spawn->GetHP());
  2625. return 1;
  2626. }
  2627. return 0;
  2628. }
  2629. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2630. if (!lua_interface)
  2631. return 0;
  2632. Spawn* spawn = lua_interface->GetSpawn(state);
  2633. if (spawn) {
  2634. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2635. return 1;
  2636. }
  2637. return 0;
  2638. }
  2639. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2640. if (!lua_interface)
  2641. return 0;
  2642. Spawn* spawn = lua_interface->GetSpawn(state);
  2643. if (spawn) {
  2644. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2645. return 1;
  2646. }
  2647. return 0;
  2648. }
  2649. int EQ2Emu_lua_GetName(lua_State* state) {
  2650. if (!lua_interface)
  2651. return 0;
  2652. Spawn* spawn = lua_interface->GetSpawn(state);
  2653. if (spawn) {
  2654. lua_interface->SetStringValue(state, spawn->GetName());
  2655. return 1;
  2656. }
  2657. return 0;
  2658. }
  2659. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2660. Spawn* spawn = lua_interface->GetSpawn(state);
  2661. if (spawn) {
  2662. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2663. return 1;
  2664. }
  2665. return 0;
  2666. }
  2667. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2668. if (!lua_interface)
  2669. return 0;
  2670. Spawn* spawn = lua_interface->GetSpawn(state);
  2671. if (spawn) {
  2672. lua_interface->SetInt32Value(state, spawn->GetPower());
  2673. return 1;
  2674. }
  2675. return 0;
  2676. }
  2677. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2678. if (!lua_interface)
  2679. return 0;
  2680. Spawn* spawn = lua_interface->GetSpawn(state);
  2681. if (spawn) {
  2682. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2683. return 1;
  2684. }
  2685. return 0;
  2686. }
  2687. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2688. if (!lua_interface)
  2689. return 0;
  2690. Spawn* spawn = lua_interface->GetSpawn(state);
  2691. if (spawn) {
  2692. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2693. return 1;
  2694. }
  2695. return 0;
  2696. }
  2697. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2698. if (!lua_interface)
  2699. return 0;
  2700. Spawn* spawn = lua_interface->GetSpawn(state);
  2701. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2702. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2703. if (spawn && spawn2) {
  2704. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2705. lua_interface->SetFloatValue(state, distance);
  2706. return 1;
  2707. }
  2708. return 0;
  2709. }
  2710. int EQ2Emu_lua_GetX(lua_State* state) {
  2711. if (!lua_interface)
  2712. return 0;
  2713. Spawn* spawn = lua_interface->GetSpawn(state);
  2714. if (spawn) {
  2715. lua_interface->SetFloatValue(state, spawn->GetX());
  2716. return 1;
  2717. }
  2718. return 0;
  2719. }
  2720. int EQ2Emu_lua_GetY(lua_State* state) {
  2721. if (!lua_interface)
  2722. return 0;
  2723. Spawn* spawn = lua_interface->GetSpawn(state);
  2724. if (spawn) {
  2725. lua_interface->SetFloatValue(state, spawn->GetY());
  2726. return 1;
  2727. }
  2728. return 0;
  2729. }
  2730. int EQ2Emu_lua_GetZ(lua_State* state) {
  2731. if (!lua_interface)
  2732. return 0;
  2733. Spawn* spawn = lua_interface->GetSpawn(state);
  2734. if (spawn) {
  2735. lua_interface->SetFloatValue(state, spawn->GetZ());
  2736. return 1;
  2737. }
  2738. return 0;
  2739. }
  2740. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2741. if (!lua_interface)
  2742. return 0;
  2743. Spawn* spawn = lua_interface->GetSpawn(state);
  2744. if (spawn) {
  2745. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2746. return 1;
  2747. }
  2748. return 0;
  2749. }
  2750. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2751. if (!lua_interface)
  2752. return 0;
  2753. Spawn* spawn = lua_interface->GetSpawn(state);
  2754. if (spawn) {
  2755. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2756. return 1;
  2757. }
  2758. return 0;
  2759. }
  2760. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2761. if (!lua_interface)
  2762. return 0;
  2763. Spawn* spawn = lua_interface->GetSpawn(state);
  2764. if (spawn) {
  2765. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2766. return 1;
  2767. }
  2768. return 0;
  2769. }
  2770. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2771. if (!lua_interface)
  2772. return 0;
  2773. Spawn* spawn = lua_interface->GetSpawn(state);
  2774. if (spawn && spawn->IsEntity()) {
  2775. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2776. return 1;
  2777. }
  2778. return 0;
  2779. }
  2780. int EQ2Emu_lua_GetInt(lua_State* state) {
  2781. if (!lua_interface)
  2782. return 0;
  2783. Spawn* spawn = lua_interface->GetSpawn(state);
  2784. if (spawn && spawn->IsEntity()) {
  2785. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2786. return 1;
  2787. }
  2788. return 0;
  2789. }
  2790. int EQ2Emu_lua_GetWis(lua_State* state) {
  2791. if (!lua_interface)
  2792. return 0;
  2793. Spawn* spawn = lua_interface->GetSpawn(state);
  2794. if (spawn && spawn->IsEntity()) {
  2795. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2796. return 1;
  2797. }
  2798. return 0;
  2799. }
  2800. int EQ2Emu_lua_GetSta(lua_State* state) {
  2801. if (!lua_interface)
  2802. return 0;
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. if (spawn && spawn->IsEntity()) {
  2805. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2806. return 1;
  2807. }
  2808. return 0;
  2809. }
  2810. int EQ2Emu_lua_GetStr(lua_State* state) {
  2811. if (!lua_interface)
  2812. return 0;
  2813. Spawn* spawn = lua_interface->GetSpawn(state);
  2814. if (spawn && spawn->IsEntity()) {
  2815. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2816. return 1;
  2817. }
  2818. return 0;
  2819. }
  2820. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2821. if (!lua_interface)
  2822. return 0;
  2823. Spawn* spawn = lua_interface->GetSpawn(state);
  2824. if (spawn && spawn->IsEntity()) {
  2825. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2826. return 1;
  2827. }
  2828. return 0;
  2829. }
  2830. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2831. if (!lua_interface)
  2832. return 0;
  2833. Spawn* spawn = lua_interface->GetSpawn(state);
  2834. if (spawn && spawn->IsEntity()) {
  2835. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2836. return 1;
  2837. }
  2838. return 0;
  2839. }
  2840. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2841. if (!lua_interface)
  2842. return 0;
  2843. Spawn* spawn = lua_interface->GetSpawn(state);
  2844. if (spawn && spawn->IsEntity()) {
  2845. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2846. return 1;
  2847. }
  2848. return 0;
  2849. }
  2850. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2851. if (!lua_interface)
  2852. return 0;
  2853. Spawn* spawn = lua_interface->GetSpawn(state);
  2854. if (spawn && spawn->IsEntity()) {
  2855. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2856. return 1;
  2857. }
  2858. return 0;
  2859. }
  2860. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2861. if (!lua_interface)
  2862. return 0;
  2863. Spawn* spawn = lua_interface->GetSpawn(state);
  2864. if (spawn && spawn->IsEntity()) {
  2865. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2866. return 1;
  2867. }
  2868. return 0;
  2869. }
  2870. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2871. if (!lua_interface)
  2872. return 0;
  2873. Spawn* spawn = lua_interface->GetSpawn(state);
  2874. if (spawn && spawn->IsEntity()) {
  2875. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2876. return 1;
  2877. }
  2878. return 0;
  2879. }
  2880. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2881. if (!lua_interface)
  2882. return 0;
  2883. Spawn* player = lua_interface->GetSpawn(state);
  2884. if (!player || !player->IsPlayer()) {
  2885. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2886. return 0;
  2887. }
  2888. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2889. if (quest_id <= 0) {
  2890. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2891. return 0;
  2892. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2893. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2894. return 0;
  2895. }
  2896. int32 step = lua_interface->GetInt32Value(state, 3);
  2897. if (step > 0) {
  2898. Client* client = player->GetZone()->GetClientBySpawn(player);
  2899. if (client)
  2900. client->AddPendingQuestUpdate(quest_id, step);
  2901. } else {
  2902. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2903. }
  2904. return 0;
  2905. }
  2906. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2907. Spawn* player = lua_interface->GetSpawn(state);
  2908. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2909. int32 step = lua_interface->GetInt32Value(state, 3);
  2910. int32 progress = lua_interface->GetInt32Value(state, 4);
  2911. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2912. Client* client = player->GetZone()->GetClientBySpawn(player);
  2913. if (client)
  2914. client->AddPendingQuestUpdate(quest_id, step, progress);
  2915. }
  2916. return 0;
  2917. }
  2918. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2919. if (!lua_interface)
  2920. return 0;
  2921. Spawn* player = lua_interface->GetSpawn(state);
  2922. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2923. if (player && player->IsPlayer() && quest_id > 0) {
  2924. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2925. return 1;
  2926. }
  2927. return 0;
  2928. }
  2929. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2930. if (!lua_interface)
  2931. return 0;
  2932. Spawn* player = lua_interface->GetSpawn(state);
  2933. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2934. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2935. if (player && player->IsPlayer() && quest_id > 0) {
  2936. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2937. return 1;
  2938. }
  2939. return 0;
  2940. }
  2941. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2942. if (!lua_interface)
  2943. return 0;
  2944. Spawn* player = lua_interface->GetSpawn(state);
  2945. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2946. if (player && player->IsPlayer() && quest_id > 0) {
  2947. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2948. return 1;
  2949. }
  2950. return 0;
  2951. }
  2952. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2953. if (!lua_interface)
  2954. return 0;
  2955. Quest* quest = lua_interface->GetQuest(state);
  2956. string name = lua_interface->GetStringValue(state, 2);
  2957. string type = lua_interface->GetStringValue(state, 3);
  2958. string zone = lua_interface->GetStringValue(state, 4);
  2959. int16 level = lua_interface->GetInt16Value(state, 5);
  2960. string description = lua_interface->GetStringValue(state, 6);
  2961. bool load = true;
  2962. if (!quest) {
  2963. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2964. load = false;
  2965. }
  2966. if (load && name.length() == 0) {
  2967. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2968. load = false;
  2969. }
  2970. if (load && type.length() == 0) {
  2971. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2972. load = false;
  2973. }
  2974. if (load && zone.length() == 0) {
  2975. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2976. load = false;
  2977. }
  2978. if (load && description.length() == 0) {
  2979. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2980. load = false;
  2981. }
  2982. if (load && level == 0) {
  2983. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2984. load = false;
  2985. }
  2986. if (load)
  2987. quest->RegisterQuest(name, type, zone, level, description);
  2988. return 0;
  2989. }
  2990. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2991. if (!lua_interface)
  2992. return 0;
  2993. Quest* quest = lua_interface->GetQuest(state);
  2994. if (quest) {
  2995. int8 level = lua_interface->GetInt16Value(state, 2);
  2996. quest->SetPrereqLevel(level);
  2997. }
  2998. return 0;
  2999. }
  3000. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3001. if (!lua_interface)
  3002. return 0;
  3003. Quest* quest = lua_interface->GetQuest(state);
  3004. if (quest) {
  3005. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3006. quest->AddPrereqQuest(quest_id);
  3007. }
  3008. return 0;
  3009. }
  3010. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3011. if (!lua_interface)
  3012. return 0;
  3013. Quest* quest = lua_interface->GetQuest(state);
  3014. if (quest) {
  3015. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3016. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3017. if (quantity == 0)
  3018. quantity = 1;
  3019. Item* master_item = master_item_list.GetItem(item_id);
  3020. if (master_item) {
  3021. Item* item = new Item(master_item);
  3022. item->details.count = quantity;
  3023. quest->AddPrereqItem(item);
  3024. }
  3025. }
  3026. return 0;
  3027. }
  3028. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3029. if (!lua_interface)
  3030. return 0;
  3031. Spawn* player = lua_interface->GetSpawn(state);
  3032. if(!player || !player->IsPlayer()) {
  3033. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3034. return 0;
  3035. }
  3036. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3037. if (quest_id > 0) {
  3038. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3039. return 1;
  3040. } else {
  3041. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3042. }
  3043. return 0;
  3044. }
  3045. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3046. if (!lua_interface)
  3047. return 0;
  3048. Quest* quest = lua_interface->GetQuest(state);
  3049. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3050. if (quest && spawn_id > 0)
  3051. quest->SetQuestReturnNPC(spawn_id);
  3052. return 0;
  3053. }
  3054. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3055. if (!lua_interface)
  3056. return 0;
  3057. Spawn* spawn = lua_interface->GetSpawn(state);
  3058. if (!spawn) {
  3059. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3060. return 0;
  3061. }
  3062. int32 time = lua_interface->GetInt32Value(state, 2);
  3063. if (time <= 0) {
  3064. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3065. return 0;
  3066. }
  3067. string function = lua_interface->GetStringValue(state, 3);
  3068. if (function.length() == 0) {
  3069. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3070. return 0;
  3071. }
  3072. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3073. Spawn* player = lua_interface->GetSpawn(state, 5);
  3074. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3075. timer->timer = Timer::GetCurrentTime2() + time;
  3076. timer->function = function;
  3077. timer->spawn = spawn->GetID();
  3078. timer->player = player ? player->GetID() : 0;
  3079. if (max_count == 0)
  3080. max_count = 1;
  3081. timer->max_count = max_count;
  3082. timer->current_count = 0;
  3083. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3084. return 0;
  3085. }
  3086. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3087. if (!lua_interface)
  3088. return 0;
  3089. Spawn* player = lua_interface->GetSpawn(state);
  3090. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3091. if (player && player->IsPlayer() && quest_id > 0) {
  3092. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3093. return 1;
  3094. }
  3095. return 0;
  3096. }
  3097. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3098. if (!lua_interface)
  3099. return 0;
  3100. Spawn* player = lua_interface->GetSpawn(state);
  3101. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3102. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3103. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3104. if (quest)
  3105. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3106. return 1;
  3107. }
  3108. return 0;
  3109. }
  3110. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3111. if (!lua_interface)
  3112. return 0;
  3113. Spawn* player = lua_interface->GetSpawn(state);
  3114. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3115. if (player && player->IsPlayer() && quest_id > 0) {
  3116. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3117. return 1;
  3118. }
  3119. return 0;
  3120. }
  3121. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3122. if (!lua_interface)
  3123. return 0;
  3124. Spawn* npc = lua_interface->GetSpawn(state);
  3125. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3126. if (npc && !npc->IsPlayer() && quest_id > 0)
  3127. npc->AddProvidedQuest(quest_id);
  3128. return 0;
  3129. }
  3130. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3131. if (!lua_interface)
  3132. return 0;
  3133. Spawn* npc = lua_interface->GetSpawn(state);
  3134. Spawn* player = lua_interface->GetSpawn(state, 2);
  3135. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3136. bool forced = lua_interface->GetBooleanValue(state, 4);
  3137. /* NPC is allowed to be null */
  3138. if (player && player->IsPlayer() && quest_id > 0) {
  3139. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3140. if (master_quest) {
  3141. Client* client = player->GetZone()->GetClientBySpawn(player);
  3142. if (!client) {
  3143. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3144. }
  3145. Quest* quest = new Quest(master_quest);
  3146. if (!quest) {
  3147. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3148. }
  3149. if (client && quest) {
  3150. if (npc)
  3151. quest->SetQuestGiver(npc->GetDatabaseID());
  3152. else
  3153. quest->SetQuestGiver(0);
  3154. client->AddPendingQuest(quest, forced);
  3155. }
  3156. }
  3157. else {
  3158. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3159. }
  3160. }
  3161. else {
  3162. 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);
  3163. }
  3164. return 0;
  3165. }
  3166. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3167. if (!lua_interface)
  3168. return 0;
  3169. Quest* quest = lua_interface->GetQuest(state);
  3170. if (quest) {
  3171. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3172. quest->AddPrereqClass(class_id);
  3173. }
  3174. return 0;
  3175. }
  3176. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3177. if (!lua_interface)
  3178. return 0;
  3179. Quest* quest = lua_interface->GetQuest(state);
  3180. if (quest) {
  3181. int8 race = lua_interface->GetInt8Value(state, 2);
  3182. quest->AddPrereqRace(race);
  3183. }
  3184. return 0;
  3185. }
  3186. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3187. if (!lua_interface)
  3188. return 0;
  3189. Quest* quest = lua_interface->GetQuest(state);
  3190. if (quest) {
  3191. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3192. quest->AddPrereqModelType(model_type);
  3193. }
  3194. return 0;
  3195. }
  3196. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3197. if (!lua_interface)
  3198. return 0;
  3199. Quest* quest = lua_interface->GetQuest(state);
  3200. if (!quest) {
  3201. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3202. return 0;
  3203. }
  3204. int8 level = lua_interface->GetInt8Value(state, 2);
  3205. quest->SetPrereqTSLevel(level);
  3206. return 0;
  3207. }
  3208. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3209. if (!lua_interface)
  3210. return 0;
  3211. Quest* quest = lua_interface->GetQuest(state);
  3212. if (!quest) {
  3213. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3214. return 0;
  3215. }
  3216. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3217. quest->AddPrereqTradeskillClass(class_id);
  3218. return 0;
  3219. }
  3220. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3221. if (!lua_interface)
  3222. return 0;
  3223. Quest* quest = lua_interface->GetQuest(state);
  3224. if (quest) {
  3225. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3226. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3227. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3228. quest->AddPrereqFaction(faction_id, min, max);
  3229. }
  3230. return 0;
  3231. }
  3232. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3233. if (!lua_interface)
  3234. return 0;
  3235. Quest* quest = lua_interface->GetQuest(state);
  3236. if (quest) {
  3237. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3238. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3239. if (quantity == 0)
  3240. quantity = 1;
  3241. Item* master_item = master_item_list.GetItem(item_id);
  3242. if (master_item) {
  3243. Item* item = new Item(master_item);
  3244. item->details.count = quantity;
  3245. quest->AddSelectableRewardItem(item);
  3246. }
  3247. }
  3248. return 0;
  3249. }
  3250. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3251. if (!lua_interface)
  3252. return 0;
  3253. Quest* quest = lua_interface->GetQuest(state);
  3254. if (quest) {
  3255. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3256. vector<Item*>* items = quest->GetRewardItems();
  3257. if (items) {
  3258. vector<Item*>::iterator itr;
  3259. for (itr = items->begin(); itr != items->end(); itr++) {
  3260. if (*itr && (*itr)->details.item_id == item_id) {
  3261. lua_interface->SetBooleanValue(state, true);
  3262. return 1;
  3263. }
  3264. }
  3265. }
  3266. }
  3267. lua_interface->SetBooleanValue(state, false);
  3268. return 1;
  3269. }
  3270. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3271. if (!lua_interface)
  3272. return 0;
  3273. Quest* quest = lua_interface->GetQuest(state);
  3274. if (quest) {
  3275. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3276. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3277. if (quantity == 0)
  3278. quantity = 1;
  3279. Item* master_item = master_item_list.GetItem(item_id);
  3280. if (master_item) {
  3281. Item* item = new Item(master_item);
  3282. item->details.count = quantity;
  3283. quest->AddRewardItem(item);
  3284. }
  3285. }
  3286. return 0;
  3287. }
  3288. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3289. if (!lua_interface)
  3290. return 0;
  3291. Quest* quest = lua_interface->GetQuest(state);
  3292. if (quest) {
  3293. int32 copper = lua_interface->GetInt32Value(state, 2);
  3294. int32 silver = lua_interface->GetInt32Value(state, 3);
  3295. int32 gold = lua_interface->GetInt32Value(state, 4);
  3296. int32 plat = lua_interface->GetInt32Value(state, 5);
  3297. quest->AddRewardCoins(copper, silver, gold, plat);
  3298. }
  3299. return 0;
  3300. }
  3301. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3302. if (!lua_interface)
  3303. return 0;
  3304. Quest* quest = lua_interface->GetQuest(state);
  3305. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3306. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3307. if (quest && faction_id > 0 && amount != 0)
  3308. quest->AddRewardFaction(faction_id, amount);
  3309. return 0;
  3310. }
  3311. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3312. if (!lua_interface)
  3313. return 0;
  3314. Quest* quest = lua_interface->GetQuest(state);
  3315. if (quest) {
  3316. int32 status = lua_interface->GetInt32Value(state, 2);
  3317. quest->SetRewardStatus(status);
  3318. }
  3319. return 0;
  3320. }
  3321. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3322. if (!lua_interface)
  3323. return 0;
  3324. Quest* quest = lua_interface->GetQuest(state);
  3325. if (quest) {
  3326. string comment = lua_interface->GetStringValue(state, 2);
  3327. quest->SetRewardComment(comment);
  3328. }
  3329. return 0;
  3330. }
  3331. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3332. if (!lua_interface)
  3333. return 0;
  3334. Quest* quest = lua_interface->GetQuest(state);
  3335. if (quest) {
  3336. int32 exp = lua_interface->GetInt32Value(state, 2);
  3337. quest->SetRewardXP(exp);
  3338. }
  3339. return 0;
  3340. }
  3341. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3342. Quest* quest = lua_interface->GetQuest(state);
  3343. if (quest) {
  3344. int32 step = lua_interface->GetInt32Value(state, 2);
  3345. string description = lua_interface->GetStringValue(state, 3);
  3346. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3347. float percentage = lua_interface->GetFloatValue(state, 5);
  3348. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3349. int16 icon = lua_interface->GetInt16Value(state, 7);
  3350. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3351. const char* taskgroup = 0;
  3352. if (str_taskgroup.length() > 0)
  3353. taskgroup = str_taskgroup.c_str();
  3354. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3355. if (quest_step && icon && quantity > 0)
  3356. quest_step->SetIcon(icon);
  3357. }
  3358. return 0;
  3359. }
  3360. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3361. if (!lua_interface)
  3362. return 0;
  3363. Quest* quest = lua_interface->GetQuest(state);
  3364. if (quest) {
  3365. int32 step = lua_interface->GetInt32Value(state, 2);
  3366. string description = lua_interface->GetStringValue(state, 3);
  3367. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3368. float percentage = lua_interface->GetFloatValue(state, 5);
  3369. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3370. int16 icon = lua_interface->GetInt16Value(state, 7);
  3371. const char* taskgroup = 0;
  3372. if (str_taskgroup.length() > 0)
  3373. taskgroup = str_taskgroup.c_str();
  3374. int32 npc_id = 0;
  3375. vector<int32>* ids = 0;
  3376. int i = 0;
  3377. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3378. if (ids == 0)
  3379. ids = new vector<int32>;
  3380. ids->push_back(npc_id);
  3381. i++;
  3382. }
  3383. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3384. if (quest_step && icon > 0 && quantity > 0)
  3385. quest_step->SetIcon(icon);
  3386. if (quest->GetPlayer()) {
  3387. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3388. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3389. }
  3390. }
  3391. return 0;
  3392. }
  3393. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3394. if (!lua_interface)
  3395. return 0;
  3396. Quest* quest = lua_interface->GetQuest(state);
  3397. if (quest) {
  3398. int32 step = lua_interface->GetInt32Value(state, 2);
  3399. string description = lua_interface->GetStringValue(state, 3);
  3400. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3401. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3402. int16 icon = lua_interface->GetInt16Value(state, 6);
  3403. const char* taskgroup = 0;
  3404. if (str_taskgroup.length() > 0)
  3405. taskgroup = str_taskgroup.c_str();
  3406. int32 npc_id = 0;
  3407. vector<int32>* ids = 0;
  3408. int i = 0;
  3409. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3410. if (ids == 0)
  3411. ids = new vector<int32>;
  3412. ids->push_back(npc_id);
  3413. i++;
  3414. }
  3415. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3416. if (quest_step && icon > 0)
  3417. quest_step->SetIcon(icon);
  3418. if (quest->GetPlayer()) {
  3419. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3420. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3421. }
  3422. }
  3423. return 0;
  3424. }
  3425. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3426. if (!lua_interface)
  3427. return 0;
  3428. Quest* quest = lua_interface->GetQuest(state);
  3429. if (quest) {
  3430. int32 step = lua_interface->GetInt32Value(state, 2);
  3431. string description = lua_interface->GetStringValue(state, 3);
  3432. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3433. float percentage = lua_interface->GetFloatValue(state, 5);
  3434. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3435. int16 icon = lua_interface->GetInt16Value(state, 7);
  3436. const char* taskgroup = 0;
  3437. if (str_taskgroup.length() > 0)
  3438. taskgroup = str_taskgroup.c_str();
  3439. int32 item_id = 0;
  3440. vector<int32>* ids = 0;
  3441. int i = 0;
  3442. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3443. if (ids == 0)
  3444. ids = new vector<int32>;
  3445. ids->push_back(item_id);
  3446. i++;
  3447. }
  3448. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3449. if (quest_step && icon > 0 && quantity > 0)
  3450. quest_step->SetIcon(icon);
  3451. if (quest->GetPlayer()) {
  3452. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3453. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3454. }
  3455. }
  3456. return 0;
  3457. }
  3458. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3459. if (!lua_interface)
  3460. return 0;
  3461. Quest* quest = lua_interface->GetQuest(state);
  3462. if (quest) {
  3463. int32 step = lua_interface->GetInt32Value(state, 2);
  3464. string description = lua_interface->GetStringValue(state, 3);
  3465. float max_variation = lua_interface->GetFloatValue(state, 4);
  3466. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3467. int16 icon = lua_interface->GetInt16Value(state, 6);
  3468. const char* taskgroup = 0;
  3469. if (str_taskgroup.length() > 0)
  3470. taskgroup = str_taskgroup.c_str();
  3471. vector<Location>* locations = 0;
  3472. int i = 7;
  3473. while (true) {
  3474. Location loc;
  3475. loc.x = lua_interface->GetFloatValue(state, i);
  3476. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3477. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3478. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3479. break;
  3480. if (locations == 0)
  3481. locations = new vector<Location>;
  3482. locations->push_back(loc);
  3483. i += 3;
  3484. }
  3485. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3486. if (quest_step && icon > 0)
  3487. quest_step->SetIcon(icon);
  3488. if (quest->GetPlayer()) {
  3489. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3490. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3491. }
  3492. }
  3493. return 0;
  3494. }
  3495. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3496. if (!lua_interface)
  3497. return 0;
  3498. Quest* quest = lua_interface->GetQuest(state);
  3499. if (quest) {
  3500. int32 step = lua_interface->GetInt32Value(state, 2);
  3501. string description = lua_interface->GetStringValue(state, 3);
  3502. float max_variation = lua_interface->GetFloatValue(state, 4);
  3503. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3504. int16 icon = lua_interface->GetInt16Value(state, 6);
  3505. const char* taskgroup = 0;
  3506. if (str_taskgroup.length() > 0)
  3507. taskgroup = str_taskgroup.c_str();
  3508. vector<Location>* locations = 0;
  3509. int i = 7;
  3510. while (true) {
  3511. Location loc;
  3512. loc.x = lua_interface->GetFloatValue(state, i);
  3513. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3514. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3515. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3516. break;
  3517. if (locations == 0)
  3518. locations = new vector<Location>;
  3519. locations->push_back(loc);
  3520. i += 3;
  3521. }
  3522. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3523. if (quest_step && icon > 0)
  3524. quest_step->SetIcon(icon);
  3525. if (quest->GetPlayer()) {
  3526. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3527. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3528. }
  3529. }
  3530. return 0;
  3531. }
  3532. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3533. Quest* quest = lua_interface->GetQuest(state);
  3534. if (quest) {
  3535. int32 step = lua_interface->GetInt32Value(state, 2);
  3536. string description = lua_interface->GetStringValue(state, 3);
  3537. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3538. float percentage = lua_interface->GetFloatValue(state, 5);
  3539. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3540. int16 icon = lua_interface->GetInt16Value(state, 7);
  3541. const char* taskgroup = 0;
  3542. if (str_taskgroup.length() > 0)
  3543. taskgroup = str_taskgroup.c_str();
  3544. int32 spell_id = 0;
  3545. vector<int32>* ids = 0;
  3546. int i = 0;
  3547. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3548. if (ids == 0)
  3549. ids = new vector<int32>;
  3550. ids->push_back(spell_id);
  3551. i++;
  3552. }
  3553. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3554. if (quest_step && icon > 0 && quantity > 0)
  3555. quest_step->SetIcon(icon);
  3556. if (quest->GetPlayer()) {
  3557. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3558. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3559. }
  3560. }
  3561. return 0;
  3562. }
  3563. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3564. if (!lua_interface)
  3565. return 0;
  3566. Quest* quest = lua_interface->GetQuest(state);
  3567. if (quest) {
  3568. int32 step = lua_interface->GetInt32Value(state, 2);
  3569. string description = lua_interface->GetStringValue(state, 3);
  3570. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3571. float percentage = lua_interface->GetFloatValue(state, 5);
  3572. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3573. int16 icon = lua_interface->GetInt16Value(state, 7);
  3574. const char* taskgroup = 0;
  3575. if (str_taskgroup.length() > 0)
  3576. taskgroup = str_taskgroup.c_str();
  3577. int32 item_id = 0;
  3578. vector<int32>* ids = 0;
  3579. int i = 0;
  3580. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3581. if (ids == 0)
  3582. ids = new vector<int32>;
  3583. ids->push_back(item_id);
  3584. i++;
  3585. }
  3586. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3587. if (quest_step && icon > 0 && quantity > 0)
  3588. quest_step->SetIcon(icon);
  3589. if (quest->GetPlayer()) {
  3590. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3591. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3592. }
  3593. }
  3594. return 0;
  3595. }
  3596. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3597. if (!lua_interface)
  3598. return 0;
  3599. Quest* quest = lua_interface->GetQuest(state);
  3600. if (quest) {
  3601. int32 step = lua_interface->GetInt32Value(state, 2);
  3602. string description = lua_interface->GetStringValue(state, 3);
  3603. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3604. float percentage = lua_interface->GetFloatValue(state, 5);
  3605. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3606. int16 icon = lua_interface->GetInt16Value(state, 7);
  3607. const char* taskgroup = 0;
  3608. if (str_taskgroup.length() > 0)
  3609. taskgroup = str_taskgroup.c_str();
  3610. int32 item_id = 0;
  3611. vector<int32>* ids = 0;
  3612. int i = 0;
  3613. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3614. if (ids == 0)
  3615. ids = new vector<int32>;
  3616. ids->push_back(item_id);
  3617. i++;
  3618. }
  3619. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3620. if (quest_step && icon > 0 && quantity > 0)
  3621. quest_step->SetIcon(icon);
  3622. if (quest->GetPlayer()) {
  3623. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3624. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3625. }
  3626. }
  3627. return 0;
  3628. }
  3629. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3630. if (!lua_interface)
  3631. return 0;
  3632. Quest* quest = lua_interface->GetQuest(state);
  3633. if (quest) {
  3634. string action = lua_interface->GetStringValue(state, 2);
  3635. if (action.length() > 0)
  3636. quest->SetCompleteAction(action);
  3637. }
  3638. return 0;
  3639. }
  3640. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3641. if (!lua_interface)
  3642. return 0;
  3643. Quest* quest = lua_interface->GetQuest(state);
  3644. if (quest) {
  3645. int32 step = lua_interface->GetInt32Value(state, 2);
  3646. string action = lua_interface->GetStringValue(state, 3);
  3647. if (step > 0 && action.length() > 0)
  3648. quest->AddCompleteAction(step, action);
  3649. }
  3650. return 0;
  3651. }
  3652. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3653. if (!lua_interface)
  3654. return 0;
  3655. Quest* quest = lua_interface->GetQuest(state);
  3656. if (quest) {
  3657. int32 step = lua_interface->GetInt32Value(state, 2);
  3658. string action = lua_interface->GetStringValue(state, 3);
  3659. if (step > 0 && action.length() > 0)
  3660. quest->AddProgressAction(step, action);
  3661. }
  3662. return 0;
  3663. }
  3664. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3665. if (!lua_interface)
  3666. return 0;
  3667. Quest* quest = lua_interface->GetQuest(state);
  3668. string description = lua_interface->GetStringValue(state, 2);
  3669. if (quest && description.length() > 0)
  3670. quest->SetDescription(description);
  3671. return 0;
  3672. }
  3673. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3674. if (!lua_interface)
  3675. return 0;
  3676. Quest* quest = lua_interface->GetQuest(state);
  3677. string description = lua_interface->GetStringValue(state, 2);
  3678. if (quest && description.length() > 0)
  3679. quest->SetCompletedDescription(description);
  3680. return 0;
  3681. }
  3682. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3683. if (!lua_interface)
  3684. return 0;
  3685. Quest* quest = lua_interface->GetQuest(state);
  3686. int32 step = lua_interface->GetInt32Value(state, 2);
  3687. string description = lua_interface->GetStringValue(state, 3);
  3688. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3689. if (quest && step > 0 && description.length() > 0) {
  3690. quest->SetTaskGroupDescription(step, description, display_bullets);
  3691. if (quest->GetPlayer()) {
  3692. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3693. if (client)
  3694. client->SendQuestUpdateStep(quest, step, false);
  3695. }
  3696. }
  3697. return 0;
  3698. }
  3699. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3700. if (!lua_interface)
  3701. return 0;
  3702. Quest* quest = lua_interface->GetQuest(state);
  3703. int32 step = lua_interface->GetInt32Value(state, 2);
  3704. string description = lua_interface->GetStringValue(state, 3);
  3705. if (quest && step > 0 && description.length() > 0) {
  3706. quest->SetStepDescription(step, description);
  3707. if (quest->GetPlayer()) {
  3708. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3709. if (client)
  3710. client->SendQuestUpdateStepImmediately(quest, step);
  3711. }
  3712. }
  3713. return 0;
  3714. }
  3715. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3716. Quest* quest = lua_interface->GetQuest(state);
  3717. string zone = lua_interface->GetStringValue(state, 2);
  3718. if (quest && zone.length() > 0)
  3719. quest->SetZone(zone);
  3720. return 0;
  3721. }
  3722. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3723. if (!lua_interface)
  3724. return 0;
  3725. Quest* quest = lua_interface->GetQuest(state);
  3726. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3727. int32 coin = lua_interface->GetInt32Value(state, 3);
  3728. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3729. string rewards_str = lua_interface->GetStringValue(state, 5);
  3730. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3731. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3732. string text = lua_interface->GetStringValue(state, 8);
  3733. if (playerSpawn && playerSpawn->IsPlayer()) {
  3734. Player* player = (Player*)playerSpawn;
  3735. Client* client = player->GetZone()->GetClientBySpawn(player);
  3736. if (client) {
  3737. vector<Item*> reward_items;
  3738. vector<Item*> selectable_reward_items;
  3739. if (rewards_str.length() > 0) {
  3740. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3741. map<unsigned int, unsigned short>::iterator itr;
  3742. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3743. if (itr->first > 0) {
  3744. Item* item = new Item(master_item_list.GetItem(itr->first));
  3745. if (item) {
  3746. if (itr->second > 0)
  3747. item->details.count = itr->second;
  3748. reward_items.push_back(item);
  3749. }
  3750. }
  3751. }
  3752. }
  3753. if (select_rewards_str.length() > 0) {
  3754. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3755. map<unsigned int, unsigned short>::iterator itr;
  3756. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3757. if (itr->first > 0) {
  3758. Item* item = new Item(master_item_list.GetItem(itr->first));
  3759. if (item) {
  3760. if (itr->second > 0)
  3761. item->stack_count = itr->second;
  3762. selectable_reward_items.push_back(item);
  3763. }
  3764. }
  3765. }
  3766. }
  3767. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3768. const char* reward_type = "Quest Reward!";
  3769. if (!quest)
  3770. reward_type = "Reward!";
  3771. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3772. }
  3773. }
  3774. return 0;
  3775. }
  3776. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3777. if (!lua_interface)
  3778. return 0;
  3779. Quest* quest = lua_interface->GetQuest(state);
  3780. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3781. if (quest && spawn) {
  3782. if (spawn->IsPlayer()) {
  3783. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3784. if (client)
  3785. client->AddPendingQuestReward(quest);
  3786. }
  3787. }
  3788. return 0;
  3789. }
  3790. int EQ2Emu_lua_Harvest(lua_State* state) {
  3791. if (!lua_interface)
  3792. return 0;
  3793. Spawn* player = lua_interface->GetSpawn(state);
  3794. Spawn* node = lua_interface->GetSpawn(state, 2);
  3795. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3796. Client* client = player->GetZone()->GetClientBySpawn(player);
  3797. if (client) {
  3798. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3799. ((GroundSpawn*)node)->ProcessHarvest(client);
  3800. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3801. player->GetZone()->RemoveSpawn(node, true);
  3802. }
  3803. }
  3804. else if (player && player->IsPlayer()) {
  3805. Client* client = player->GetZone()->GetClientBySpawn(player);
  3806. if (client)
  3807. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3808. }
  3809. return 0;
  3810. }
  3811. int EQ2Emu_lua_Bind(lua_State* state) {
  3812. if (!lua_interface)
  3813. return 0;
  3814. Spawn* spawn = lua_interface->GetSpawn(state);
  3815. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3816. float x = lua_interface->GetFloatValue(state, 3);
  3817. float y = lua_interface->GetFloatValue(state, 4);
  3818. float z = lua_interface->GetFloatValue(state, 5);
  3819. float h = lua_interface->GetFloatValue(state, 6);
  3820. if (!spawn) {
  3821. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3822. return 0;
  3823. }
  3824. if (!spawn->IsPlayer()) {
  3825. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3826. return 0;
  3827. }
  3828. if (zone_id == 0) {
  3829. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3830. if (!client) {
  3831. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3832. return 0;
  3833. }
  3834. if (!client->Bind())
  3835. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3836. }
  3837. else {
  3838. Player* player = (Player*)spawn;
  3839. player->GetPlayerInfo()->SetBindZone(zone_id);
  3840. player->GetPlayerInfo()->SetBindX(x);
  3841. player->GetPlayerInfo()->SetBindY(y);
  3842. player->GetPlayerInfo()->SetBindZ(z);
  3843. player->GetPlayerInfo()->SetBindHeading(h);
  3844. }
  3845. return 0;
  3846. }
  3847. int EQ2Emu_lua_Gate(lua_State* state) {
  3848. if (!lua_interface)
  3849. return 0;
  3850. Spawn* spawn = lua_interface->GetSpawn(state);
  3851. if (spawn) {
  3852. if (spawn->IsPlayer()) {
  3853. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3854. if (client) {
  3855. if (!client->Gate())
  3856. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3857. }
  3858. }
  3859. }
  3860. return 0;
  3861. }
  3862. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3863. if (!lua_interface)
  3864. return 0;
  3865. bool ret = false;
  3866. Spawn* spawn = lua_interface->GetSpawn(state);
  3867. if (spawn) {
  3868. if (spawn->IsPlayer()) {
  3869. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3870. if (client)
  3871. ret = client->BindAllowed();
  3872. }
  3873. }
  3874. lua_interface->SetBooleanValue(state, ret);
  3875. return 1;
  3876. }
  3877. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3878. if (!lua_interface)
  3879. return 0;
  3880. bool ret = false;
  3881. Spawn* spawn = lua_interface->GetSpawn(state);
  3882. if (spawn) {
  3883. if (spawn->IsPlayer()) {
  3884. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3885. if (client)
  3886. ret = client->GateAllowed();
  3887. }
  3888. }
  3889. lua_interface->SetBooleanValue(state, ret);
  3890. return 1;
  3891. }
  3892. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3893. Spawn* spawn = lua_interface->GetSpawn(state);
  3894. if (spawn) {
  3895. lua_interface->SetBooleanValue(state, spawn->Alive());
  3896. return 1;
  3897. }
  3898. return 0;
  3899. }
  3900. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3901. if (!lua_interface)
  3902. return 0;
  3903. Spawn* spawn = lua_interface->GetSpawn(state);
  3904. if (spawn && spawn->IsEntity()) {
  3905. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3906. return 1;
  3907. }
  3908. return 0;
  3909. }
  3910. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3911. Spawn* spawn = lua_interface->GetSpawn(state);
  3912. string message = lua_interface->GetStringValue(state, 2);
  3913. string color_str = lua_interface->GetStringValue(state, 3);
  3914. int8 color = CHANNEL_NARRATIVE;
  3915. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3916. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3917. if (client) {
  3918. if (color_str.length() > 0) {
  3919. // leave for backwards compat, but all future should just use the number
  3920. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3921. color = CHANNEL_COLOR_RED;
  3922. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3923. color = CHANNEL_COLOR_YELLOW;
  3924. else
  3925. {
  3926. // use a number to specify the channel as per Commands/Commands.h defines
  3927. color = (int8)atoul(color_str.c_str());
  3928. }
  3929. }
  3930. client->SimpleMessage(color, message.c_str());
  3931. }
  3932. }
  3933. return 0;
  3934. }
  3935. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3936. Spawn* spawn = lua_interface->GetSpawn(state);
  3937. string message = lua_interface->GetStringValue(state, 2);
  3938. int8 red = lua_interface->GetInt8Value(state, 3);
  3939. int8 green = lua_interface->GetInt8Value(state, 4);
  3940. int8 blue = lua_interface->GetInt8Value(state, 5);
  3941. if (!spawn) {
  3942. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3943. return 0;
  3944. }
  3945. int32 words = ::CountWordsInString(message.c_str());
  3946. if (words < 5)
  3947. words = 5;
  3948. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3949. if (client)
  3950. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3951. return 0;
  3952. }
  3953. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3954. Spawn* spawn = lua_interface->GetSpawn(state);
  3955. int8 param = lua_interface->GetInt8Value(state, 2);
  3956. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3957. int8 value = lua_interface->GetInt8Value(state, 4);
  3958. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3959. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3960. if (client) {
  3961. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3962. switch (param) {
  3963. case 1: {
  3964. packet->setDataByName("parameter1", param_value);
  3965. break;
  3966. }
  3967. case 2: {
  3968. packet->setDataByName("parameter2", param_value);
  3969. break;
  3970. }
  3971. case 3: {
  3972. packet->setDataByName("parameter3", param_value);
  3973. break;
  3974. }
  3975. case 4: {
  3976. packet->setDataByName("parameter4", param_value);
  3977. break;
  3978. }
  3979. case 5: {
  3980. packet->setDataByName("parameter5", param_value);
  3981. break;
  3982. }
  3983. }
  3984. packet->setDataByName("value", value);
  3985. client->QueuePacket(packet->serialize());
  3986. safe_delete(packet);
  3987. }
  3988. }
  3989. return 0;
  3990. }
  3991. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3992. Spawn* spawn = lua_interface->GetSpawn(state);
  3993. if (spawn && spawn->IsPlayer()) {
  3994. if (((Player*)spawn)->GetIsTracking())
  3995. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3996. else
  3997. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3998. }
  3999. return 0;
  4000. }
  4001. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4002. Spawn* player = lua_interface->GetSpawn(state);
  4003. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4004. string name = lua_interface->GetStringValue(state, 3);
  4005. float distance = lua_interface->GetFloatValue(state, 4);
  4006. string command = lua_interface->GetStringValue(state, 5);
  4007. string error_text = lua_interface->GetStringValue(state, 6);
  4008. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4009. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4010. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4011. if (spawn) {
  4012. if (distance == 0)
  4013. distance = 10.0f;
  4014. if (command.length() == 0)
  4015. command = name;
  4016. if (command.length() < 1 && name.length() < 1)
  4017. {
  4018. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4019. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4020. spawn->RemovePrimaryCommands();
  4021. }
  4022. else
  4023. {
  4024. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4025. }
  4026. }
  4027. return 0;
  4028. }
  4029. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4030. if (!lua_interface)
  4031. return 0;
  4032. Spawn* player = lua_interface->GetSpawn(state);
  4033. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4034. int16 tier = lua_interface->GetInt16Value(state, 3);
  4035. if (player && player->IsPlayer()) {
  4036. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4037. return 1;
  4038. }
  4039. return 0;
  4040. }
  4041. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4042. if (!lua_interface)
  4043. return 0;
  4044. Spawn* player = lua_interface->GetSpawn(state);
  4045. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4046. int16 tier = lua_interface->GetInt16Value(state, 3);
  4047. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4048. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4049. bool add_to_hotbar = true;
  4050. if (num_args > 4) {
  4051. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4052. }
  4053. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4054. if (player && spell && player->IsPlayer()) {
  4055. Client* client = player->GetClient();
  4056. if (client) {
  4057. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4058. {
  4059. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4060. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4061. client->GetPlayer()->UnlockSpell(spell);
  4062. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4063. }
  4064. else
  4065. {
  4066. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4067. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4068. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4069. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4070. client->GetPlayer()->UnlockSpell(spell);
  4071. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4072. }
  4073. //if (client ) {
  4074. // ((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);
  4075. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4076. if (outapp)
  4077. client->QueuePacket(outapp);
  4078. }
  4079. }
  4080. return 0;
  4081. }
  4082. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4083. if (!lua_interface)
  4084. return 0;
  4085. Spawn* player = lua_interface->GetSpawn(state);
  4086. if (player && player->IsPlayer()) {
  4087. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4088. return 1;
  4089. }
  4090. return 0;
  4091. }
  4092. int EQ2Emu_lua_Attack(lua_State* state) {
  4093. if (lua_interface) {
  4094. Spawn* npc = lua_interface->GetSpawn(state);
  4095. Spawn* player = lua_interface->GetSpawn(state, 2);
  4096. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4097. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4098. }
  4099. return 0;
  4100. }
  4101. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4102. if (lua_interface) {
  4103. Spawn* target = lua_interface->GetSpawn(state);
  4104. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4105. if (target && target->GetZone())
  4106. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4107. }
  4108. return 0;
  4109. }
  4110. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4111. Spawn* player;
  4112. if (lua_interface) {
  4113. player = lua_interface->GetSpawn(state);
  4114. if (player && player->IsPlayer()) {
  4115. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4116. return 1;
  4117. }
  4118. }
  4119. return 0;
  4120. }
  4121. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4122. Spawn* player;
  4123. Client* client;
  4124. if (lua_interface) {
  4125. player = lua_interface->GetSpawn(state);
  4126. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4127. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4128. client->HandInCollections();
  4129. }
  4130. return 0;
  4131. }
  4132. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4133. Spawn* widget;
  4134. if (lua_interface) {
  4135. widget = lua_interface->GetSpawn(state);
  4136. if (widget && widget->IsWidget())
  4137. ((Widget*)widget)->HandleUse(nullptr, "");
  4138. }
  4139. return 0;
  4140. }
  4141. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4142. Spawn* spawn = 0;
  4143. int32 primary_list = 0;
  4144. int32 secondary_list = 0;
  4145. if (lua_interface) {
  4146. spawn = lua_interface->GetSpawn(state);
  4147. primary_list = lua_interface->GetInt32Value(state, 2);
  4148. secondary_list = lua_interface->GetInt32Value(state, 3);
  4149. if (!spawn->IsNPC()) {
  4150. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4151. return 0;
  4152. }
  4153. NPC* npc = (NPC*)spawn;
  4154. npc->SetPrimarySpellList(primary_list);
  4155. npc->SetSecondarySpellList(secondary_list);
  4156. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4157. }
  4158. return 0;
  4159. }
  4160. int EQ2Emu_lua_GetPet(lua_State* state) {
  4161. if (!lua_interface)
  4162. return 0;
  4163. Spawn* spawn = lua_interface->GetSpawn(state);
  4164. if (spawn) {
  4165. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4166. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4167. return 1;
  4168. }
  4169. }
  4170. return 0;
  4171. }
  4172. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4173. if (!lua_interface)
  4174. return 0;
  4175. Spawn* spawn = lua_interface->GetSpawn(state);
  4176. if (spawn) {
  4177. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4178. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4179. return 1;
  4180. }
  4181. }
  4182. return 0;
  4183. }
  4184. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4185. if (!lua_interface)
  4186. return 0;
  4187. Spawn* spawn = lua_interface->GetSpawn(state);
  4188. if (spawn) {
  4189. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4190. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4191. return 1;
  4192. }
  4193. }
  4194. return 0;
  4195. }
  4196. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4197. if (!lua_interface)
  4198. return 0;
  4199. Spawn* spawn = lua_interface->GetSpawn(state);
  4200. if (spawn) {
  4201. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4202. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4203. return 1;
  4204. }
  4205. }
  4206. return 0;
  4207. }
  4208. int EQ2Emu_lua_Charm(lua_State* state) {
  4209. if (!lua_interface)
  4210. return 0;
  4211. Spawn* owner = lua_interface->GetSpawn(state);
  4212. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4213. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4214. if (!luaspell) {
  4215. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4216. return 0;
  4217. }
  4218. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4219. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4220. pet->SetPet(true);
  4221. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4222. ((NPC*)pet)->SetOwner((Entity*)owner);
  4223. // If owner is player and player does not have a summoned pet set the players charsheet
  4224. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4225. Player* player = (Player*)owner;
  4226. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4227. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4228. player->GetInfoStruct()->set_pet_movement(2);
  4229. player->GetInfoStruct()->set_pet_behavior(3);
  4230. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4231. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4232. // Make sure the values get sent to the client
  4233. player->SetCharSheetChanged(true);
  4234. }
  4235. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4236. pet->SetSpawnScript("");
  4237. // Set faction to the same as the owner
  4238. pet->SetFactionID(owner->GetFactionID());
  4239. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4240. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4241. // Clear hate list
  4242. ((NPC*)pet)->Brain()->ClearHate();
  4243. // Set the brain to a pet brain
  4244. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4245. }
  4246. return 0;
  4247. }
  4248. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4249. if (!lua_interface)
  4250. return 0;
  4251. Spawn* spawn = lua_interface->GetSpawn(state);
  4252. if (!spawn) {
  4253. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4254. return 0;
  4255. }
  4256. vector<Spawn*> groupMembers;
  4257. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4258. groupMembers = *spawn->GetSpawnGroup();
  4259. }
  4260. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4261. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4262. deque<GroupMemberInfo*>::iterator itr;
  4263. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4264. if (group)
  4265. {
  4266. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4267. deque<GroupMemberInfo*>* members = group->GetMembers();
  4268. GroupMemberInfo* info = 0;
  4269. for (itr = members->begin(); itr != members->end(); itr++) {
  4270. info = *itr;
  4271. if (info->client)
  4272. groupMembers.push_back(info->client->GetPlayer());
  4273. }
  4274. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4275. }
  4276. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4277. }
  4278. else
  4279. return 0;
  4280. lua_createtable(state, groupMembers.size(), 0);
  4281. int newTable = lua_gettop(state);
  4282. for (int32 i = 0; i < groupMembers.size(); i++) {
  4283. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4284. lua_rawseti(state, newTable, i + 1);
  4285. }
  4286. return 1;
  4287. }
  4288. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4289. if (!lua_interface)
  4290. return 0;
  4291. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4292. lua_interface->SetOptionWindowValue(state, option_window);
  4293. return 1;
  4294. }
  4295. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4296. if (!lua_interface)
  4297. return 0;
  4298. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4299. if (option_window) {
  4300. OptionWindowOption option_window_option;
  4301. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4302. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4303. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4304. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4305. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4306. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4307. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4308. option_window->push_back(option_window_option);
  4309. }
  4310. return 0;
  4311. }
  4312. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4313. if (!lua_interface)
  4314. return 0;
  4315. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4316. Spawn* player = lua_interface->GetSpawn(state, 2);
  4317. string window_title = lua_interface->GetStringValue(state, 3);
  4318. string cancel_command = lua_interface->GetStringValue(state, 4);
  4319. Client* client = player->GetZone()->GetClientBySpawn(player);
  4320. if (option_window && window_title.length() > 0 && client) {
  4321. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4322. if (!packet)
  4323. return 0;
  4324. packet->setDataByName("title_text", window_title.c_str());
  4325. if (cancel_command.length() > 0)
  4326. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4327. packet->setArrayLengthByName("num_selections", option_window->size());
  4328. vector<OptionWindowOption>::iterator itr;
  4329. int8 i = 0;
  4330. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4331. OptionWindowOption opt = *itr;
  4332. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4333. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4334. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4335. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4336. if (opt.optionCommand.length() > 0)
  4337. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4338. if (opt.optionConfirmTitle.length() > 0)
  4339. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4340. i++;
  4341. }
  4342. client->QueuePacket(packet->serialize());
  4343. safe_delete(option_window);
  4344. safe_delete(packet);
  4345. }
  4346. return 0;
  4347. }
  4348. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4349. if (!lua_interface)
  4350. return 0;
  4351. Spawn* spawn = lua_interface->GetSpawn(state);
  4352. if (spawn) {
  4353. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4354. return 1;
  4355. }
  4356. else
  4357. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4358. return 0;
  4359. }
  4360. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4361. if (!lua_interface)
  4362. return 0;
  4363. Spawn* spawn = lua_interface->GetSpawn(state);
  4364. if (spawn) {
  4365. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4366. return 1;
  4367. }
  4368. else
  4369. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4370. return 0;
  4371. }
  4372. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4373. if (!lua_interface)
  4374. return 0;
  4375. Spawn* spawn = lua_interface->GetSpawn(state);
  4376. if (spawn) {
  4377. int8 class_id = spawn->GetTradeskillClass();
  4378. // Need to add 42 for the offset in the array
  4379. class_id += 44;
  4380. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4381. return 1;
  4382. }
  4383. else
  4384. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4385. return 0;
  4386. }
  4387. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4388. if (!lua_interface)
  4389. return 0;
  4390. Spawn* spawn = lua_interface->GetSpawn(state);
  4391. int16 level = lua_interface->GetInt8Value(state, 2);
  4392. if (spawn) {
  4393. if (spawn->IsPlayer())
  4394. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4395. else
  4396. spawn->SetTSLevel(level);
  4397. }
  4398. else
  4399. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4400. return 0;
  4401. }
  4402. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4403. if (!lua_interface)
  4404. return 0;
  4405. Spawn* spawn = lua_interface->GetSpawn(state);
  4406. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4407. if (spawn) {
  4408. spawn->SetAttackable(attackable);
  4409. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4410. }
  4411. return 0;
  4412. }
  4413. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4414. // Check to see if we have a valid lua_interface
  4415. if (!lua_interface)
  4416. return 0;
  4417. // Get the spawn that is getting the pet
  4418. Spawn* spawn = lua_interface->GetSpawn(state);
  4419. // Get the DB ID of the pet
  4420. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4421. // The max level the pet can gain
  4422. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4423. // Get the spell that this command was called from
  4424. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4425. // Check to make sure the spawn pointer is valid
  4426. if (!spawn) {
  4427. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4428. return 0;
  4429. }
  4430. // Check to make sure the spawn is an entity
  4431. if (!spawn->IsEntity()) {
  4432. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4433. return 0;
  4434. }
  4435. // Check to make sure the spawn doesn't already have a pet of this type
  4436. if (((Entity*)spawn)->GetPet()) {
  4437. if (spawn->IsPlayer()) {
  4438. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4439. if (client)
  4440. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4441. }
  4442. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4443. return 0;
  4444. }
  4445. // Check to see if the DB ID for the pet is set
  4446. if (pet_id == 0) {
  4447. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4448. return 0;
  4449. }
  4450. // Check to see if the pointer to the spell is valid
  4451. if (!luaspell) {
  4452. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4453. return 0;
  4454. }
  4455. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4456. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4457. if (!pet) {
  4458. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4459. return 0;
  4460. }
  4461. // Check to make sure the pet is an npc
  4462. if (!pet->IsNPC()) {
  4463. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4464. return 0;
  4465. }
  4466. // Spawn the pet at the same location as the owner
  4467. pet->SetX(spawn->GetX());
  4468. pet->SetY(spawn->GetY());
  4469. pet->SetZ(spawn->GetZ());
  4470. pet->SetLocation(spawn->GetLocation());
  4471. pet->SetHeading(spawn->GetHeading());
  4472. spawn->GetZone()->AddSpawn(pet);
  4473. /*
  4474. const char* spawn_script = world.GetSpawnScript(pet_id);
  4475. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4476. spawn->SetSpawnScript(string(spawn_script));
  4477. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4478. }*/
  4479. // Get a random pet name
  4480. string random_pet_name;
  4481. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4482. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4483. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4484. // If player set various values for the char sheet (pet window)
  4485. if (spawn->IsPlayer()) {
  4486. Player* player = (Player*)spawn;
  4487. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4488. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4489. player->GetInfoStruct()->set_pet_movement(2);
  4490. player->GetInfoStruct()->set_pet_behavior(3);
  4491. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4492. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4493. // Make sure the values get sent to the client
  4494. player->SetCharSheetChanged(true);
  4495. }
  4496. // Set the pets name
  4497. pet->SetName(random_pet_name.c_str());
  4498. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4499. if (max_level > 0)
  4500. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4501. else
  4502. pet->SetLevel(spawn->GetLevel());
  4503. // Set the max level this pet can reach
  4504. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4505. // Set the faction of the pet to the same faction as the owner
  4506. pet->SetFactionID(spawn->GetFactionID());
  4507. // Set the spawn as a pet
  4508. pet->SetPet(true);
  4509. // Give a pointer of the owner to the pet
  4510. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4511. // Give a pointer of the pet to the owner
  4512. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4513. // Set the pet type
  4514. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4515. // Set the spell id used to create this pet
  4516. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4517. // Set the spell tier used to create this pet
  4518. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4519. // Set the pets spawn type to 6
  4520. pet->SetSpawnType(6);
  4521. // Set the pets brain
  4522. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4523. // Check to see if the pet has a subtitle
  4524. if (strlen(pet->GetSubTitle()) > 0) {
  4525. // Add the players name to the front of the sub title
  4526. string pet_subtitle;
  4527. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4528. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4529. // Set the pets subtitle to the new one
  4530. pet->SetSubTitle(pet_subtitle.c_str());
  4531. }
  4532. // Add the "Pet Options" entity command to the pet
  4533. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4534. // Set the pet as the return value for this function
  4535. lua_interface->SetSpawnValue(state, pet);
  4536. return 1;
  4537. }
  4538. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4539. if (!lua_interface)
  4540. return 0;
  4541. Spawn* spawn = lua_interface->GetSpawn(state);
  4542. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4543. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4544. if (!spawn) {
  4545. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4546. return 0;
  4547. }
  4548. if (!spawn->IsEntity()) {
  4549. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4550. return 0;
  4551. }
  4552. if (((Entity*)spawn)->GetDeityPet()) {
  4553. if (spawn->IsPlayer()) {
  4554. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4555. if (client)
  4556. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4557. }
  4558. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4559. return 0;
  4560. }
  4561. if (pet_id == 0) {
  4562. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4563. return 0;
  4564. }
  4565. if (!luaspell) {
  4566. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4567. return 0;
  4568. }
  4569. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4570. if (!pet) {
  4571. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4572. return 0;
  4573. }
  4574. if (!pet->IsNPC()) {
  4575. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4576. return 0;
  4577. }
  4578. pet->SetX(spawn->GetX());
  4579. pet->SetY(spawn->GetY());
  4580. pet->SetZ(spawn->GetZ());
  4581. pet->SetLocation(spawn->GetLocation());
  4582. pet->SetHeading(spawn->GetHeading());
  4583. spawn->GetZone()->AddSpawn(pet);
  4584. string random_pet_name;
  4585. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4586. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4587. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4588. pet->SetName(random_pet_name.c_str());
  4589. pet->SetLevel(spawn->GetLevel());
  4590. pet->SetFactionID(spawn->GetFactionID());
  4591. pet->SetPet(true);
  4592. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4593. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4594. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4595. pet->SetSpawnType(6);
  4596. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4597. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4598. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4599. if (strlen(pet->GetSubTitle()) > 0) {
  4600. string pet_subtitle;
  4601. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4602. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4603. pet->SetSubTitle(pet_subtitle.c_str());
  4604. }
  4605. // deity and cosmetic pets are not attackable
  4606. pet->SetAttackable(false);
  4607. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4608. lua_interface->SetSpawnValue(state, pet);
  4609. return 1;
  4610. }
  4611. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4612. if (!lua_interface)
  4613. return 0;
  4614. Spawn* spawn = lua_interface->GetSpawn(state);
  4615. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4616. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4617. if (!spawn) {
  4618. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4619. return 0;
  4620. }
  4621. if (!spawn->IsEntity()) {
  4622. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4623. return 0;
  4624. }
  4625. if (((Entity*)spawn)->GetCosmeticPet()) {
  4626. if (spawn->IsPlayer()) {
  4627. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4628. if (client)
  4629. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4630. }
  4631. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4632. return 0;
  4633. }
  4634. if (pet_id == 0) {
  4635. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4636. return 0;
  4637. }
  4638. if (!luaspell) {
  4639. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4640. return 0;
  4641. }
  4642. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4643. if (!pet) {
  4644. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4645. return 0;
  4646. }
  4647. if (!pet->IsNPC()) {
  4648. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4649. return 0;
  4650. }
  4651. pet->SetX(spawn->GetX());
  4652. pet->SetY(spawn->GetY());
  4653. pet->SetZ(spawn->GetZ());
  4654. pet->SetLocation(spawn->GetLocation());
  4655. pet->SetHeading(spawn->GetHeading());
  4656. spawn->GetZone()->AddSpawn(pet);
  4657. string random_pet_name;
  4658. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4659. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4660. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4661. pet->SetName(random_pet_name.c_str());
  4662. pet->SetLevel(spawn->GetLevel());
  4663. pet->SetFactionID(spawn->GetFactionID());
  4664. pet->SetPet(true);
  4665. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4666. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4667. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4668. pet->SetSpawnType(6);
  4669. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4670. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4671. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4672. if (strlen(pet->GetSubTitle()) > 0) {
  4673. string pet_subtitle;
  4674. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4675. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4676. pet->SetSubTitle(pet_subtitle.c_str());
  4677. }
  4678. pet->SetAttackable(false);
  4679. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4680. lua_interface->SetSpawnValue(state, pet);
  4681. return 1;
  4682. }
  4683. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4684. if (!lua_interface)
  4685. return 0;
  4686. Spawn* spawn = lua_interface->GetSpawn(state);
  4687. if (!spawn) {
  4688. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4689. return 0;
  4690. }
  4691. if (!spawn->IsPet()) {
  4692. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4693. return 0;
  4694. }
  4695. if (!((NPC*)spawn)->IsDismissing())
  4696. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4697. return 0;
  4698. }
  4699. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4700. if (!lua_interface)
  4701. return 0;
  4702. Quest* quest = lua_interface->GetQuest(state);
  4703. if (!quest) {
  4704. 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));
  4705. return 0;
  4706. }
  4707. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4708. if (feather_color > 0)
  4709. quest->SetFeatherColor(feather_color);
  4710. return 0;
  4711. }
  4712. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4713. if (!lua_interface)
  4714. return 0;
  4715. Spawn* spawn = lua_interface->GetSpawn(state);
  4716. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4717. if (!spawn) {
  4718. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4719. return 0;
  4720. }
  4721. if (!spawn2) {
  4722. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4723. return 0;
  4724. }
  4725. spawn->RemoveSpawnAccess(spawn2);
  4726. return 0;
  4727. }
  4728. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4729. if (!lua_interface)
  4730. return 0;
  4731. ZoneServer* zone = lua_interface->GetZone(state);
  4732. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4733. if (!zone) {
  4734. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4735. return 0;
  4736. }
  4737. if (location_id == 0) {
  4738. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4739. return 0;
  4740. }
  4741. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4742. if (!location) {
  4743. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4744. return 0;
  4745. }
  4746. Spawn* spawn = 0;
  4747. if (location->entities[0]) {
  4748. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4749. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4750. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4751. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4752. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4753. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4754. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4755. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4756. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4757. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4758. if (spawn) {
  4759. const char* script = 0;
  4760. for (int x = 0; x < 3; x++) {
  4761. switch (x) {
  4762. case 0:
  4763. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4764. break;
  4765. case 1:
  4766. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4767. break;
  4768. case 2:
  4769. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4770. break;
  4771. }
  4772. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4773. spawn->SetSpawnScript(string(script));
  4774. break;
  4775. }
  4776. }
  4777. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4778. lua_interface->SetSpawnValue(state, spawn);
  4779. return 1;
  4780. }
  4781. else {
  4782. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4783. safe_delete(spawn);
  4784. }
  4785. }
  4786. return 0;
  4787. }
  4788. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4789. if (!lua_interface)
  4790. return 0;
  4791. Spawn* caster = lua_interface->GetSpawn(state);
  4792. Spawn* target = lua_interface->GetSpawn(state, 2);
  4793. int32 id = lua_interface->GetInt32Value(state, 3);
  4794. string command = lua_interface->GetStringValue(state, 4);
  4795. if (!caster) {
  4796. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4797. return 0;
  4798. }
  4799. if (!target) {
  4800. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4801. return 0;
  4802. }
  4803. if (!caster->IsPlayer()) {
  4804. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4805. return 0;
  4806. }
  4807. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4808. if (!entity_command) {
  4809. 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());
  4810. return 0;
  4811. }
  4812. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4813. if (!client) {
  4814. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4815. return 0;
  4816. }
  4817. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4818. return 0;
  4819. }
  4820. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4821. if (!lua_interface)
  4822. return 0;
  4823. Spawn* spawn = lua_interface->GetSpawn(state);
  4824. if (!spawn) {
  4825. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4826. return 0;
  4827. }
  4828. if (!spawn->IsNPC()) {
  4829. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4830. return 0;
  4831. }
  4832. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4833. return 0;
  4834. }
  4835. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4836. if (!lua_interface)
  4837. return 0;
  4838. Spawn* spawn = lua_interface->GetSpawn(state);
  4839. int16 tick = lua_interface->GetInt16Value(state, 2);
  4840. if (!spawn) {
  4841. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4842. return 0;
  4843. }
  4844. if (!spawn->IsNPC()) {
  4845. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4846. return 0;
  4847. }
  4848. if (tick < 20) {
  4849. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4850. return 0;
  4851. }
  4852. ((NPC*)spawn)->Brain()->SetTick(tick);
  4853. return 0;
  4854. }
  4855. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4856. if (!lua_interface)
  4857. return 0;
  4858. Spawn* spawn = lua_interface->GetSpawn(state);
  4859. Spawn* target = lua_interface->GetSpawn(state, 2);
  4860. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4861. if (!spawn) {
  4862. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4863. return 0;
  4864. }
  4865. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4866. spawn->SetFollowTarget(target, follow_distance);
  4867. return 0;
  4868. }
  4869. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4870. if (!lua_interface)
  4871. return 0;
  4872. Spawn* spawn = lua_interface->GetSpawn(state);
  4873. if (!spawn) {
  4874. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4875. return 0;
  4876. }
  4877. Spawn* target = spawn->GetFollowTarget();
  4878. if (target) {
  4879. lua_interface->SetSpawnValue(state, target);
  4880. return 1;
  4881. }
  4882. return 0;
  4883. }
  4884. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4885. if (!lua_interface)
  4886. return 0;
  4887. Spawn* spawn = lua_interface->GetSpawn(state);
  4888. if (!spawn) {
  4889. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4890. return 0;
  4891. }
  4892. if (spawn->following)
  4893. spawn->following = false;
  4894. else
  4895. spawn->following = true;
  4896. return 0;
  4897. }
  4898. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4899. if (!lua_interface)
  4900. return 0;
  4901. Spawn* spawn = lua_interface->GetSpawn(state);
  4902. if (!spawn) {
  4903. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4904. return 0;
  4905. }
  4906. lua_interface->SetBooleanValue(state, spawn->following);
  4907. return 1;
  4908. }
  4909. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4910. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4911. // I will attempt to explain how this function works for future refrence
  4912. // Fist lets make sure lua_interface is valid, if not return out
  4913. if (!lua_interface)
  4914. return 0;
  4915. // Next we grab the first 2 params same as we usually would
  4916. Spawn* spawn = lua_interface->GetSpawn(state);
  4917. string var = lua_interface->GetStringValue(state, 2);
  4918. // 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
  4919. // 1 = Spawn
  4920. // 2 = Zone
  4921. // 3 = Item
  4922. // 4 = Quest
  4923. // 5 = String
  4924. // 6 = nil (null)
  4925. int8 dataType = 0;
  4926. // Define pointers for each potential type
  4927. Spawn* spawnVal = 0;
  4928. ZoneServer* zone = 0;
  4929. Item* item = 0;
  4930. Quest* quest = 0;
  4931. string val;
  4932. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4933. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4934. // options window are also light user data be we do not handle those.
  4935. // We check with lua_islightuserdata(lua_State*, index)
  4936. if (lua_islightuserdata(state, 3)) {
  4937. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4938. // and convert it to LUAUserData*
  4939. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4940. // Check to make sure the data we got is valid, if not give an error
  4941. if (!data || !data->IsCorrectlyInitialized()) {
  4942. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4943. }
  4944. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4945. else if (data->IsSpawn()) {
  4946. spawnVal = data->spawn;
  4947. dataType = 1;
  4948. }
  4949. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4950. else if (data->IsZone()) {
  4951. zone = data->zone;
  4952. dataType = 2;
  4953. }
  4954. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4955. else if (data->IsItem()) {
  4956. item = data->item;
  4957. dataType = 3;
  4958. }
  4959. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4960. else if (data->IsQuest()) {
  4961. quest = data->quest;
  4962. dataType = 4;
  4963. }
  4964. }
  4965. // Wasn't light user data, check if it is nil(null)
  4966. else if (lua_isnil(state, 3)) {
  4967. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4968. dataType = 6;
  4969. }
  4970. // Wasn't light user data or nil (null), must be a string
  4971. else {
  4972. // Set the string and dataType variable
  4973. val = lua_interface->GetStringValue(state, 3);
  4974. dataType = 5;
  4975. }
  4976. // We now have all the params, lets check to make sure they are valid
  4977. if (!spawn) {
  4978. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4979. return 0;
  4980. }
  4981. if (var.length() == 0) {
  4982. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4983. return 0;
  4984. }
  4985. if (dataType == 0) {
  4986. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4987. return 0;
  4988. }
  4989. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4990. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4991. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4992. switch (dataType) {
  4993. case 1:
  4994. // 1 = Spawn
  4995. spawn->AddTempVariable(var, spawnVal);
  4996. break;
  4997. case 2:
  4998. // 2 = Zone
  4999. spawn->AddTempVariable(var, zone);
  5000. break;
  5001. case 3:
  5002. // 3 = Item
  5003. spawn->AddTempVariable(var, item);
  5004. break;
  5005. case 4:
  5006. // 4 = Quest
  5007. spawn->AddTempVariable(var, quest);
  5008. break;
  5009. case 5:
  5010. // 5 = String
  5011. spawn->AddTempVariable(var, val);
  5012. break;
  5013. case 6:
  5014. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5015. spawn->DeleteTempVariable(var);
  5016. break;
  5017. }
  5018. // And we are done so return out
  5019. return 0;
  5020. }
  5021. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5022. if (!lua_interface)
  5023. return 0;
  5024. Spawn* spawn = lua_interface->GetSpawn(state);
  5025. string var = lua_interface->GetStringValue(state, 2);
  5026. if (!spawn) {
  5027. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5028. return 0;
  5029. }
  5030. if (var.length() == 0) {
  5031. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5032. return 0;
  5033. }
  5034. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5035. int8 type = spawn->GetTempVariableType(var);
  5036. Spawn* spawn2 = 0;
  5037. ZoneServer* zone = 0;
  5038. Item* item = 0;
  5039. Quest* quest = 0;
  5040. // Set the lua function return value based on the type of data the variable contains
  5041. switch (type) {
  5042. case 1:
  5043. spawn2 = spawn->GetTempVariableSpawn(var);
  5044. if (!spawn2)
  5045. return 0;
  5046. lua_interface->SetSpawnValue(state, spawn2);
  5047. break;
  5048. case 2:
  5049. zone = spawn->GetTempVariableZone(var);
  5050. if (!zone)
  5051. return 0;
  5052. lua_interface->SetZoneValue(state, zone);
  5053. break;
  5054. case 3:
  5055. item = spawn->GetTempVariableItem(var);
  5056. if (!item)
  5057. return 0;
  5058. lua_interface->SetItemValue(state, item);
  5059. break;
  5060. case 4:
  5061. quest = spawn->GetTempVariableQuest(var);
  5062. if (!quest)
  5063. return 0;
  5064. lua_interface->SetQuestValue(state, quest);
  5065. break;
  5066. case 5:
  5067. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5068. break;
  5069. default:
  5070. // Not a valid type then the variable was not set so return out
  5071. return 0;
  5072. }
  5073. // Return value was set so return out
  5074. return 1;
  5075. }
  5076. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5077. {
  5078. if (!lua_interface)
  5079. return 0;
  5080. Quest* quest = lua_interface->GetQuest(state);
  5081. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5082. string description = lua_interface->GetStringValue(state, 3);
  5083. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5084. if (!quest) {
  5085. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5086. lua_interface->SetBooleanValue(state, false);
  5087. return 1;
  5088. }
  5089. if (!spawn) {
  5090. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5091. lua_interface->SetBooleanValue(state, false);
  5092. return 1;
  5093. }
  5094. if (!spawn->IsPlayer()) {
  5095. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5096. lua_interface->SetBooleanValue(state, false);
  5097. return 1;
  5098. }
  5099. if (item_id == 0) {
  5100. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5101. lua_interface->SetBooleanValue(state, false);
  5102. return 1;
  5103. }
  5104. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5105. if (!client) {
  5106. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5107. lua_interface->SetBooleanValue(state, false);
  5108. return 1;
  5109. }
  5110. Item* item = master_item_list.GetItem(item_id);
  5111. if (!item) {
  5112. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5113. lua_interface->SetBooleanValue(state, false);
  5114. return 1;
  5115. }
  5116. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  5117. if (packet) {
  5118. packet->setDataByName("title", "Quest Reward!");
  5119. packet->setDataByName("name", quest->GetName());
  5120. packet->setDataByName("description", description.c_str());
  5121. packet->setDataByName("level", quest->GetLevel());
  5122. packet->setArrayLengthByName("num_rewards", 1);
  5123. packet->setArrayDataByName("reward_id", item->details.item_id);
  5124. if (client->GetVersion() < 860)
  5125. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  5126. else if (client->GetVersion() < 1193)
  5127. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  5128. else
  5129. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  5130. client->QueuePacket(packet->serialize());
  5131. safe_delete(packet);
  5132. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  5133. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  5134. return 1;
  5135. }
  5136. lua_interface->SetBooleanValue(state, false);
  5137. return 1;
  5138. }
  5139. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5140. if (!lua_interface)
  5141. return 0;
  5142. Quest* quest = lua_interface->GetQuest(state);
  5143. if (!quest) {
  5144. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5145. return 0;
  5146. }
  5147. quest->SetRepeatable(true);
  5148. return 0;
  5149. }
  5150. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5151. if (!lua_interface)
  5152. return 0;
  5153. Spawn* spawn = lua_interface->GetSpawn(state);
  5154. if (!spawn) {
  5155. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5156. return 0;
  5157. }
  5158. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5159. string ret = classes.GetClassNameCase(base_class);
  5160. if (ret.length() > 0) {
  5161. lua_interface->SetStringValue(state, ret.c_str());
  5162. return 1;
  5163. }
  5164. return 0;
  5165. }
  5166. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5167. if (!lua_interface)
  5168. return 0;
  5169. Spawn* player = lua_interface->GetSpawn(state);
  5170. if (player && player->IsPlayer()) {
  5171. Client* client = player->GetClient();
  5172. if (client)
  5173. client->SendWaypoints();
  5174. }
  5175. return 0;
  5176. }
  5177. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5178. if (!lua_interface)
  5179. return 0;
  5180. Spawn* player = lua_interface->GetSpawn(state);
  5181. string name = lua_interface->GetStringValue(state, 2);
  5182. int32 type = lua_interface->GetInt32Value(state, 3);
  5183. if (type == 0)
  5184. type = 2;
  5185. if (name.length() > 0) {
  5186. if (player && player->IsPlayer()) {
  5187. Client* client = player->GetClient();
  5188. if (client)
  5189. client->AddWaypoint(name, type);
  5190. }
  5191. }
  5192. return 0;
  5193. }
  5194. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5195. if (!lua_interface)
  5196. return 0;
  5197. Spawn* player = lua_interface->GetSpawn(state);
  5198. string name = lua_interface->GetStringValue(state, 2);
  5199. if (name.length() > 0) {
  5200. if (player && player->IsPlayer()) {
  5201. Client* client = player->GetClient();
  5202. if (client)
  5203. client->RemoveWaypoint(name);
  5204. }
  5205. }
  5206. return 0;
  5207. }
  5208. int EQ2Emu_lua_AddWard(lua_State* state) {
  5209. if (!lua_interface)
  5210. return 0;
  5211. int32 damage = lua_interface->GetInt32Value(state);
  5212. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5213. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5214. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5215. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5216. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5217. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5218. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5219. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5220. bool ward_was_added = false;
  5221. ZoneServer* zone = spell->caster->GetZone();
  5222. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5223. for (int32 i = 0; i < spell->targets.size(); i++) {
  5224. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5225. if (!target)
  5226. continue;
  5227. if (target->IsEntity()) {
  5228. // If the ward is already active remove it
  5229. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5230. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5231. // Create new ward info
  5232. WardInfo* ward = new WardInfo;
  5233. ward->Spell = spell;
  5234. ward->BaseDamage = damage;
  5235. ward->DamageLeft = damage;
  5236. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5237. ward->keepWard = keepWard;
  5238. ward->WardType = wardType;
  5239. if (damageAbsorptionPercent > 100)
  5240. damageAbsorptionPercent = 100;
  5241. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5242. if (damageAbsorptionMaxHealthPercent > 100)
  5243. damageAbsorptionMaxHealthPercent = 100;
  5244. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5245. ward->RedirectDamagePercent = redirectDamagePercent;
  5246. ward->LastRedirectDamage = 0;
  5247. ward->LastAbsorbedDamage = 0;
  5248. ward->HitCount = 0;
  5249. spell->num_triggers = maxHitCount;
  5250. spell->had_triggers = true;
  5251. spell->cancel_after_all_triggers = false;
  5252. ward->MaxHitCount = maxHitCount;
  5253. if (wardType == WARD_TYPE_MAGICAL)
  5254. ward->DamageType = damageTypes;
  5255. // Add the ward to the entity
  5256. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5257. ward_was_added = true;
  5258. }
  5259. }
  5260. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5261. if (ward_was_added && spell->caster->IsPlayer()) {
  5262. spell->had_dmg_remaining = true;
  5263. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5264. }
  5265. return 0;
  5266. }
  5267. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5268. if (!lua_interface)
  5269. return 0;
  5270. int32 amount = lua_interface->GetInt32Value(state);
  5271. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5272. WardInfo* ward = 0;
  5273. ZoneServer* zone = spell->caster->GetZone();
  5274. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5275. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5276. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5277. ward = target->GetWard(spell->spell->GetSpellID());
  5278. if (ward) {
  5279. ward->DamageLeft += amount;
  5280. if (ward->DamageLeft > ward->BaseDamage)
  5281. ward->DamageLeft = ward->BaseDamage;
  5282. for (int32 i = 0; i < spell->targets.size(); i++) {
  5283. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5284. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5285. }
  5286. }
  5287. }
  5288. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5289. if (ward && spell->caster->IsPlayer())
  5290. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5291. return 0;
  5292. }
  5293. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5294. if (!lua_interface)
  5295. return 0;
  5296. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5297. if (!spell) {
  5298. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5299. return 0;
  5300. }
  5301. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5302. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5303. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5304. if (ward) {
  5305. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5306. return 1;
  5307. }
  5308. }
  5309. return 0;
  5310. }
  5311. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5312. if (!lua_interface)
  5313. return 0;
  5314. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5315. if (!spell) {
  5316. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5317. return 0;
  5318. }
  5319. string type = lua_interface->GetStringValue(state, 2);
  5320. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5321. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5322. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5323. if (ward) {
  5324. if (boost::iequals(type, "damageleft"))
  5325. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5326. else if (boost::iequals(type, "basedamage"))
  5327. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5328. else if (boost::iequals(type, "keepward"))
  5329. lua_interface->SetBooleanValue(state, ward->keepWard);
  5330. else if (boost::iequals(type, "wardtype"))
  5331. lua_interface->SetInt32Value(state, ward->WardType);
  5332. else if (boost::iequals(type, "dmgabsorptionpct"))
  5333. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5334. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5335. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5336. else if (boost::iequals(type, "redirectdamagepercent"))
  5337. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5338. else if (boost::iequals(type, "lastredirectdamage"))
  5339. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5340. else if (boost::iequals(type, "lastabsorbeddamage"))
  5341. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5342. else if (boost::iequals(type, "hitcount"))
  5343. lua_interface->SetInt32Value(state, ward->HitCount);
  5344. else if (boost::iequals(type, "maxhitcount"))
  5345. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5346. else
  5347. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5348. return 1;
  5349. }
  5350. }
  5351. return 0;
  5352. }
  5353. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5354. if (!lua_interface)
  5355. return 0;
  5356. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5357. ZoneServer* zone = spell->caster->GetZone();
  5358. Spawn* target = 0;
  5359. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5360. for (int32 i = 0; i < spell->targets.size(); i++) {
  5361. target = zone->GetSpawnByID(spell->targets.at(i));
  5362. if (target && target->IsEntity()) {
  5363. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5364. }
  5365. }
  5366. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5367. return 0;
  5368. }
  5369. int EQ2Emu_lua_Interrupt(lua_State* state)
  5370. {
  5371. if (!lua_interface)
  5372. return 0;
  5373. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5374. Spawn* target = lua_interface->GetSpawn(state, 2);
  5375. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5376. if (!caster)
  5377. {
  5378. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5379. return 0;
  5380. }
  5381. if (!target)
  5382. {
  5383. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5384. return 0;
  5385. }
  5386. if (!spell) {
  5387. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5388. return 0;
  5389. }
  5390. if (!target->IsEntity() && !spell)
  5391. {
  5392. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5393. return 0;
  5394. }
  5395. if (!target && spell) {
  5396. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5397. for (int8 i = 0; i < spell->targets.size(); i++) {
  5398. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5399. if (!target || !target->IsEntity())
  5400. continue;
  5401. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5402. }
  5403. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5404. }
  5405. else
  5406. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5407. return 0;
  5408. }
  5409. int EQ2Emu_lua_Stealth(lua_State* state) {
  5410. if (!lua_interface)
  5411. return 0;
  5412. int8 type = lua_interface->GetInt8Value(state);
  5413. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5414. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5415. if (!spell) {
  5416. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5417. return 0;
  5418. }
  5419. ZoneServer* zone = spell->caster->GetZone();
  5420. if (spawn) {
  5421. if (spawn->IsEntity()) {
  5422. if (type == 1) {
  5423. ((Entity*)spawn)->AddStealthSpell(spell);
  5424. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5425. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5426. }
  5427. else if (type == 2) {
  5428. ((Entity*)spawn)->AddInvisSpell(spell);
  5429. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5430. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5431. }
  5432. return 0;
  5433. }
  5434. else {
  5435. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5436. return 0;
  5437. }
  5438. }
  5439. else {
  5440. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5441. for (int32 i = 0; i < spell->targets.size(); i++) {
  5442. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5443. if (!spawn || !spawn->IsEntity())
  5444. continue;
  5445. if (type == 1) {
  5446. ((Entity*)spawn)->AddStealthSpell(spell);
  5447. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5448. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5449. }
  5450. else if (type == 2) {
  5451. ((Entity*)spawn)->AddInvisSpell(spell);
  5452. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5453. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5454. }
  5455. else {
  5456. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5457. break;
  5458. }
  5459. }
  5460. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5461. }
  5462. return 0;
  5463. }
  5464. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5465. if (!lua_interface)
  5466. return 0;
  5467. Spawn* spawn = lua_interface->GetSpawn(state);
  5468. if (!spawn) {
  5469. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5470. return 0;
  5471. }
  5472. if (spawn->IsEntity()) {
  5473. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5474. return 1;
  5475. }
  5476. else
  5477. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5478. return 0;
  5479. }
  5480. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5481. if (!lua_interface)
  5482. return 0;
  5483. Spawn* spawn = lua_interface->GetSpawn(state);
  5484. if (!spawn) {
  5485. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5486. return 0;
  5487. }
  5488. if (spawn->IsEntity()) {
  5489. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5490. return 1;
  5491. }
  5492. else
  5493. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5494. return 0;
  5495. }
  5496. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5497. if (!lua_interface)
  5498. return 0;
  5499. Spawn* player = lua_interface->GetSpawn(state);
  5500. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5501. lua_interface->ResetFunctionStack(state);
  5502. if (!player->IsPlayer()) {
  5503. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5504. return 0;
  5505. }
  5506. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5507. return 1;
  5508. }
  5509. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5510. if (!lua_interface)
  5511. return 0;
  5512. Spawn* player = lua_interface->GetSpawn(state);
  5513. int8 slot = lua_interface->GetInt8Value(state, 2);
  5514. lua_interface->ResetFunctionStack(state);
  5515. if (!player) {
  5516. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5517. return 0;
  5518. }
  5519. if (!player->IsPlayer()) {
  5520. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5521. return 0;
  5522. }
  5523. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5524. if (!item) {
  5525. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5526. return 0;
  5527. }
  5528. lua_interface->SetItemValue(state, item);
  5529. return 1;
  5530. }
  5531. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5532. if (!lua_interface)
  5533. return 0;
  5534. Spawn* player = lua_interface->GetSpawn(state);
  5535. int32 id = lua_interface->GetInt32Value(state, 2);
  5536. lua_interface->ResetFunctionStack(state);
  5537. if (!player) {
  5538. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5539. return 0;
  5540. }
  5541. if (!player->IsPlayer()) {
  5542. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5543. return 0;
  5544. }
  5545. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5546. if (!item) {
  5547. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5548. return 0;
  5549. }
  5550. lua_interface->SetItemValue(state, item);
  5551. return 1;
  5552. }
  5553. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5554. if (!lua_interface)
  5555. return 0;
  5556. Spawn* spawn = lua_interface->GetSpawn(state);
  5557. int8 slot = lua_interface->GetInt8Value(state, 2);
  5558. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5559. lua_interface->ResetFunctionStack(state);
  5560. if (!spawn) {
  5561. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5562. return 0;
  5563. }
  5564. if (!spawn->IsEntity()) {
  5565. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5566. return 0;
  5567. }
  5568. Item* item = master_item_list.GetItem(item_id);
  5569. if (!item) {
  5570. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5571. return 0;
  5572. }
  5573. Item* copy = new Item(item);
  5574. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5575. if(result)
  5576. {
  5577. ((Entity*)spawn)->SetEquipment(copy, slot);
  5578. spawn->vis_changed = true;
  5579. if(spawn->IsPlayer())
  5580. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5581. }
  5582. else
  5583. {
  5584. safe_delete(copy);
  5585. }
  5586. lua_interface->SetBooleanValue(state, result);
  5587. return 1;
  5588. }
  5589. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5590. if (!lua_interface)
  5591. return 0;
  5592. Spawn* spawn = lua_interface->GetSpawn(state);
  5593. int8 slot = lua_interface->GetInt8Value(state, 2);
  5594. Item* item = lua_interface->GetItem(state, 3);
  5595. lua_interface->ResetFunctionStack(state);
  5596. if (!spawn) {
  5597. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5598. return 0;
  5599. }
  5600. if (!spawn->IsEntity()) {
  5601. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5602. return 0;
  5603. }
  5604. if (!item) {
  5605. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5606. return 0;
  5607. }
  5608. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5609. if(result)
  5610. {
  5611. ((Entity*)spawn)->SetEquipment(item, slot);
  5612. spawn->vis_changed = true;
  5613. if(spawn->IsPlayer())
  5614. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5615. }
  5616. lua_interface->SetBooleanValue(state, result);
  5617. return 1;
  5618. }
  5619. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5620. if (!lua_interface)
  5621. return 0;
  5622. Spawn* spawn = lua_interface->GetSpawn(state);
  5623. int8 slot = lua_interface->GetInt8Value(state, 2);
  5624. 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
  5625. lua_interface->ResetFunctionStack(state);
  5626. if (!spawn) {
  5627. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5628. return 0;
  5629. }
  5630. if (!spawn->IsEntity()) {
  5631. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5632. return 0;
  5633. }
  5634. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5635. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5636. spawn->vis_changed = true;
  5637. if(spawn->IsPlayer())
  5638. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5639. lua_interface->SetBooleanValue(state, true);
  5640. return 1;
  5641. }
  5642. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5643. if (!lua_interface)
  5644. return 0;
  5645. Spawn* spawn = lua_interface->GetSpawn(state);
  5646. int8 slot = lua_interface->GetInt8Value(state, 2);
  5647. int16 type = lua_interface->GetInt16Value(state, 3);
  5648. int8 r = lua_interface->GetInt8Value(state, 4);
  5649. int8 g = lua_interface->GetInt8Value(state, 5);
  5650. int8 b = lua_interface->GetInt8Value(state, 6);
  5651. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5652. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5653. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5654. lua_interface->ResetFunctionStack(state);
  5655. if (!spawn) {
  5656. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5657. return 0;
  5658. }
  5659. if (!spawn->IsEntity()) {
  5660. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5661. return 0;
  5662. }
  5663. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5664. spawn->vis_changed = true;
  5665. lua_interface->SetBooleanValue(state, true);
  5666. return 1;
  5667. }
  5668. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5669. if (!lua_interface)
  5670. return 0;
  5671. Spawn* player = lua_interface->GetSpawn(state);
  5672. int32 id = lua_interface->GetInt32Value(state, 2);
  5673. int8 count = lua_interface->GetInt8Value(state, 3);
  5674. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5675. lua_interface->ResetFunctionStack(state);
  5676. if (!player) {
  5677. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5678. return 0;
  5679. }
  5680. if (!player->IsPlayer()) {
  5681. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5682. return 0;
  5683. }
  5684. if (!count)
  5685. count = 1;
  5686. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5687. if (!item) {
  5688. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5689. return 0;
  5690. }
  5691. lua_interface->SetItemValue(state, item);
  5692. return 1;
  5693. }
  5694. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5695. if (!lua_interface)
  5696. return 0;
  5697. Spawn* spawn = lua_interface->GetSpawn(state);
  5698. int32 anim = lua_interface->GetInt32Value(state, 2);
  5699. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5700. int8 type = lua_interface->GetInt8Value(state, 4);
  5701. if (!spawn) {
  5702. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5703. return 0;
  5704. }
  5705. if (spawn2) {
  5706. if (spawn2->IsPlayer()) {
  5707. if (type != 1 && type != 2)
  5708. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5709. else
  5710. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5711. return 0;
  5712. }
  5713. else {
  5714. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5715. return 0;
  5716. }
  5717. }
  5718. else
  5719. spawn->GetZone()->PlayAnimation(spawn, anim);
  5720. return 0;
  5721. }
  5722. int EQ2Emu_lua_IsPet(lua_State* state) {
  5723. if (!lua_interface)
  5724. return 0;
  5725. Spawn* spawn = lua_interface->GetSpawn(state);
  5726. if (!spawn) {
  5727. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5728. return 0;
  5729. }
  5730. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5731. return 1;
  5732. }
  5733. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5734. if (!lua_interface)
  5735. return 0;
  5736. Spawn* spawn = lua_interface->GetSpawn(state);
  5737. if (!spawn) {
  5738. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5739. return 0;
  5740. }
  5741. if (!spawn->IsNPC()) {
  5742. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5743. return 0;
  5744. }
  5745. if (((NPC*)spawn)->GetOwner()) {
  5746. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5747. return 1;
  5748. }
  5749. return 0;
  5750. }
  5751. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5752. if (!lua_interface)
  5753. return 0;
  5754. Spawn* spawn = lua_interface->GetSpawn(state);
  5755. Spawn* target = lua_interface->GetSpawn(state, 2);
  5756. if (!spawn) {
  5757. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5758. return 0;
  5759. }
  5760. if (!spawn) {
  5761. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5762. return 0;
  5763. }
  5764. spawn->SetTarget(target);
  5765. return 0;
  5766. }
  5767. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5768. if (!lua_interface)
  5769. return 0;
  5770. Spawn* spawn = lua_interface->GetSpawn(state);
  5771. bool val = lua_interface->GetBooleanValue(state, 2);
  5772. if (!spawn) {
  5773. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5774. return 0;
  5775. }
  5776. if (!spawn->IsEntity()) {
  5777. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. ((Entity*)spawn)->InCombat(val);
  5781. if (val) {
  5782. spawn->ClearRunningLocations();
  5783. spawn->CalculateRunningLocation(true);
  5784. }
  5785. return 0;
  5786. }
  5787. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5788. if (!lua_interface)
  5789. return 0;
  5790. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5791. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5792. if (!spawn1) {
  5793. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5794. return 0;
  5795. }
  5796. if (!spawn2) {
  5797. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5798. return 0;
  5799. }
  5800. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5801. return 1;
  5802. }
  5803. int EQ2Emu_lua_Runback(lua_State* state) {
  5804. if (!lua_interface)
  5805. return 0;
  5806. Spawn* spawn = lua_interface->GetSpawn(state);
  5807. if (!spawn) {
  5808. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5809. return 0;
  5810. }
  5811. if (!spawn->IsNPC()) {
  5812. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5813. return 0;
  5814. }
  5815. ((NPC*)spawn)->Runback();
  5816. return 0;
  5817. }
  5818. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5819. if (!lua_interface)
  5820. return 0;
  5821. Spawn* spawn = lua_interface->GetSpawn(state);
  5822. if (!spawn) {
  5823. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5824. return 0;
  5825. }
  5826. if (!spawn->IsNPC()) {
  5827. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5828. return 0;
  5829. }
  5830. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5831. return 1;
  5832. }
  5833. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5834. if (!lua_interface)
  5835. return 0;
  5836. Spawn* spawn = lua_interface->GetSpawn(state);
  5837. if (!spawn) {
  5838. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5839. return 0;
  5840. }
  5841. if (!spawn->IsEntity()) {
  5842. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5843. return 0;
  5844. }
  5845. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5846. return 1;
  5847. }
  5848. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5849. if (!lua_interface)
  5850. return 0;
  5851. Spawn* spawn = lua_interface->GetSpawn(state);
  5852. if (!spawn) {
  5853. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5854. return 0;
  5855. }
  5856. if (!spawn->IsEntity()) {
  5857. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5858. return 0;
  5859. }
  5860. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5861. return 1;
  5862. }
  5863. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5864. if (!lua_interface)
  5865. return 0;
  5866. Spawn* spawn = lua_interface->GetSpawn(state);
  5867. if (!spawn) {
  5868. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5869. return 0;
  5870. }
  5871. if (!spawn->IsEntity()) {
  5872. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5873. return 0;
  5874. }
  5875. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5876. return 1;
  5877. }
  5878. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5879. if (!lua_interface)
  5880. return 0;
  5881. Spawn* spawn = lua_interface->GetSpawn(state);
  5882. if (!spawn) {
  5883. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5884. return 0;
  5885. }
  5886. if (!spawn->IsEntity()) {
  5887. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5888. return 0;
  5889. }
  5890. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5891. return 1;
  5892. }
  5893. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5894. if (!lua_interface)
  5895. return 0;
  5896. Spawn* spawn = lua_interface->GetSpawn(state);
  5897. Spawn* target = lua_interface->GetSpawn(state, 2);
  5898. float distance = lua_interface->GetFloatValue(state, 3);
  5899. if (!spawn) {
  5900. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5901. return 0;
  5902. }
  5903. if (!target) {
  5904. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5905. return 0;
  5906. }
  5907. if (!spawn->IsNPC()) {
  5908. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5909. return 0;
  5910. }
  5911. if (!target->IsEntity()) {
  5912. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5913. return 0;
  5914. }
  5915. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5916. return 1;
  5917. }
  5918. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5919. if (!lua_interface)
  5920. return 0;
  5921. Spawn* spawn = lua_interface->GetSpawn(state);
  5922. Spawn* target = lua_interface->GetSpawn(state, 2);
  5923. float distance = lua_interface->GetFloatValue(state, 3);
  5924. if (!spawn) {
  5925. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5926. return 0;
  5927. }
  5928. if (!target) {
  5929. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5930. return 0;
  5931. }
  5932. if (!spawn->IsNPC()) {
  5933. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5934. return 0;
  5935. }
  5936. if (!target->IsEntity()) {
  5937. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5938. return 0;
  5939. }
  5940. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5941. return 0;
  5942. }
  5943. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5944. if (!lua_interface)
  5945. return 0;
  5946. Spawn* spawn = lua_interface->GetSpawn(state);
  5947. if (!spawn) {
  5948. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5949. return 0;
  5950. }
  5951. if (!spawn->IsNPC()) {
  5952. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5953. return 0;
  5954. }
  5955. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5956. return 1;
  5957. }
  5958. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5959. if (!lua_interface)
  5960. return 0;
  5961. Spawn* spawn = lua_interface->GetSpawn(state);
  5962. if (!spawn) {
  5963. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5964. return 0;
  5965. }
  5966. if (!spawn->IsNPC()) {
  5967. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5968. return 0;
  5969. }
  5970. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5971. return 1;
  5972. }
  5973. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5974. if (!lua_interface)
  5975. return 0;
  5976. Spawn* spawn = lua_interface->GetSpawn(state);
  5977. if (!spawn) {
  5978. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5979. return 0;
  5980. }
  5981. if (!spawn->IsNPC()) {
  5982. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5983. return 0;
  5984. }
  5985. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5986. if (hated) {
  5987. lua_interface->SetSpawnValue(state, hated);
  5988. return 1;
  5989. }
  5990. return 0;
  5991. }
  5992. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5993. if (!lua_interface)
  5994. return 0;
  5995. Spawn* spawn = lua_interface->GetSpawn(state);
  5996. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5997. if (!spawn) {
  5998. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. if (!spawn->IsNPC()) {
  6002. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6003. return 0;
  6004. }
  6005. if (!hated) {
  6006. ((NPC*)spawn)->Brain()->ClearHate();
  6007. return 0;
  6008. }
  6009. else
  6010. {
  6011. if (!hated->IsEntity()) {
  6012. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6013. return 0;
  6014. }
  6015. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6016. return 0;
  6017. }
  6018. return 0;
  6019. }
  6020. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6021. if (!lua_interface)
  6022. return 0;
  6023. Spawn* spawn = lua_interface->GetSpawn(state);
  6024. if (!spawn) {
  6025. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6026. return 0;
  6027. }
  6028. if (!spawn->IsNPC()) {
  6029. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6030. return 0;
  6031. }
  6032. ((NPC*)spawn)->Brain()->ClearEncounter();
  6033. return 0;
  6034. }
  6035. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6036. if (!lua_interface)
  6037. return 0;
  6038. Spawn* spawn = lua_interface->GetSpawn(state);
  6039. if (!spawn) {
  6040. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6041. return 0;
  6042. }
  6043. if (!spawn->IsNPC()) {
  6044. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6045. return 0;
  6046. }
  6047. // Temp list to store hate list
  6048. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6049. if (encounterList->size() == 0) {
  6050. safe_delete(encounterList);
  6051. return 0;
  6052. }
  6053. lua_createtable(state, encounterList->size(), 0);
  6054. int newTable = lua_gettop(state);
  6055. for (int32 i = 0; i < encounterList->size(); i++) {
  6056. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6057. if (temp)
  6058. lua_interface->SetSpawnValue(state, temp);
  6059. lua_rawseti(state, newTable, i + 1);
  6060. }
  6061. safe_delete(encounterList);
  6062. return 1;
  6063. }
  6064. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6065. if (!lua_interface)
  6066. return 0;
  6067. Spawn* spawn = lua_interface->GetSpawn(state);
  6068. if (!spawn) {
  6069. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6070. return 0;
  6071. }
  6072. if (!spawn->IsNPC()) {
  6073. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6074. return 0;
  6075. }
  6076. // Temp list to store hate list
  6077. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6078. if (hateList->size() == 0) {
  6079. safe_delete(hateList);
  6080. return 0;
  6081. }
  6082. lua_createtable(state, hateList->size(), 0);
  6083. int newTable = lua_gettop(state);
  6084. for (int32 i = 0; i < hateList->size(); i++) {
  6085. lua_interface->SetSpawnValue(state, hateList->at(i));
  6086. lua_rawseti(state, newTable, i + 1);
  6087. }
  6088. safe_delete(hateList);
  6089. return 1;
  6090. }
  6091. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6092. if (!lua_interface)
  6093. return 0;
  6094. Spawn* spawn = lua_interface->GetSpawn(state);
  6095. if (!spawn) {
  6096. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6097. return 0;
  6098. }
  6099. if (spawn->IsPlayer()) {
  6100. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6101. lua_interface->SetBooleanValue(state, true);
  6102. else
  6103. lua_interface->SetBooleanValue(state, false);
  6104. return 1;
  6105. }
  6106. else {
  6107. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6108. return 1;
  6109. }
  6110. }
  6111. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6112. if (!lua_interface)
  6113. return 0;
  6114. Quest* quest = lua_interface->GetQuest(state);
  6115. if (!quest) {
  6116. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6117. return 0;
  6118. }
  6119. quest->SetCompletedFlag(true);
  6120. return 0;
  6121. }
  6122. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6123. if (!lua_interface)
  6124. return 0;
  6125. Spawn* spawn = lua_interface->GetSpawn(state);
  6126. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6127. int8 tier = lua_interface->GetInt8Value(state, 3);
  6128. if (!spawn) {
  6129. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6130. return 0;
  6131. }
  6132. if (!spawn->IsEntity()) {
  6133. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6134. return 0;
  6135. }
  6136. if (spellID == 0) {
  6137. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6138. return 0;
  6139. }
  6140. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6141. if (effect) {
  6142. if (tier > 0) {
  6143. // If a tier was passed chec to see if it is the same as the effect
  6144. if (tier == effect->tier)
  6145. lua_interface->SetBooleanValue(state, true);
  6146. else
  6147. lua_interface->SetBooleanValue(state, false);
  6148. return 1;
  6149. }
  6150. else {
  6151. // Have an effect but no tier was passed so return true
  6152. lua_interface->SetBooleanValue(state, true);
  6153. }
  6154. return 1;
  6155. }
  6156. // no effect so return false
  6157. lua_interface->SetBooleanValue(state, false);
  6158. return 1;
  6159. }
  6160. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6161. if (!lua_interface)
  6162. return 0;
  6163. Spawn* spawn = lua_interface->GetSpawn(state);
  6164. int32 id = lua_interface->GetInt32Value(state, 2);
  6165. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6166. Spawn* spawn2 = 0;
  6167. vector<Spawn*> list;
  6168. if (!spawn) {
  6169. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6170. return 0;
  6171. }
  6172. //If zone not provided, use spawn's zone
  6173. if (!zone)
  6174. zone = spawn->GetZone();
  6175. list = zone->GetSpawnsByID(id);
  6176. if (list.size() == 0) {
  6177. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6178. return 0;
  6179. }
  6180. vector<Spawn*>::iterator itr = list.begin();
  6181. for (int8 i = 0; i < list.size(); i++) {
  6182. spawn2 = itr[i];
  6183. if (spawn2)
  6184. spawn2->AddAllowAccessSpawn(spawn);
  6185. }
  6186. return 0;
  6187. }
  6188. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6189. if (!lua_interface)
  6190. return 0;
  6191. Spawn* spawn = lua_interface->GetSpawn(state);
  6192. int32 id = lua_interface->GetInt32Value(state, 2);
  6193. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6194. Spawn* spawn2 = 0;
  6195. if (!spawn) {
  6196. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6197. return 0;
  6198. }
  6199. //If zone not provided, use spawn's zone
  6200. if (!zone)
  6201. zone = spawn->GetZone();
  6202. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6203. vector<Spawn*>::iterator itr = list.begin();
  6204. if (list.size() == 0) {
  6205. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6206. return 0;
  6207. }
  6208. for (int8 i = 0; i < list.size(); i++) {
  6209. spawn2 = itr[i];
  6210. if (spawn2)
  6211. spawn2->RemoveSpawnAccess(spawn);
  6212. }
  6213. return 0;
  6214. }
  6215. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6216. if (!lua_interface)
  6217. return 0;
  6218. Quest* quest = lua_interface->GetQuest(state);
  6219. if (!quest) {
  6220. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6221. return 0;
  6222. }
  6223. quest->SetYellowName(true);
  6224. return 0;
  6225. }
  6226. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6227. if (!lua_interface)
  6228. return 0;
  6229. Spawn* spawn = lua_interface->GetSpawn(state);
  6230. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6231. if (!spawn) {
  6232. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6233. return 0;
  6234. }
  6235. if (!spawn->IsPlayer()) {
  6236. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6237. return 0;
  6238. }
  6239. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6240. return 1;
  6241. }
  6242. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6243. if (!lua_interface)
  6244. return 0;
  6245. Spawn* spawn = lua_interface->GetSpawn(state);
  6246. if (!spawn) {
  6247. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6248. return 0;
  6249. }
  6250. if (!spawn->IsPlayer()) {
  6251. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6252. return 0;
  6253. }
  6254. ZoneServer* zone = spawn->GetZone();
  6255. if (!zone) {
  6256. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6257. return 0;
  6258. }
  6259. Instance_Type iType = zone->GetInstanceType();
  6260. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6261. iType == GROUP_LOCKOUT_INSTANCE ||
  6262. iType == RAID_LOCKOUT_INSTANCE ||
  6263. iType == SOLO_PERSIST_INSTANCE ||
  6264. iType == GROUP_PERSIST_INSTANCE ||
  6265. iType == RAID_PERSIST_INSTANCE) {
  6266. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6267. if (data) {
  6268. // Check to see if the timer has already been set, if it has return out.
  6269. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6270. return 0;
  6271. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6272. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6273. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6274. if (client) {
  6275. string time_msg = "";
  6276. int32 time = data->success_lockout_time;
  6277. int16 hour;
  6278. int8 min;
  6279. int8 sec;
  6280. hour = time / 3600;
  6281. time = time % 3600;
  6282. min = time / 60;
  6283. time = time % 60;
  6284. sec = time;
  6285. if (hour > 0) {
  6286. char temp[10];
  6287. sprintf(temp, " %i", hour);
  6288. time_msg.append(temp);
  6289. time_msg.append(" hour");
  6290. time_msg.append((hour > 1) ? "s" : "");
  6291. }
  6292. if (min > 0) {
  6293. char temp[5];
  6294. sprintf(temp, " %i", min);
  6295. time_msg.append(temp);
  6296. time_msg.append(" minute");
  6297. time_msg.append((min > 1) ? "s" : "");
  6298. }
  6299. // Only add seconds if minutes and hours are 0
  6300. if (hour == 0 && min == 0 && sec > 0) {
  6301. char temp[5];
  6302. sprintf(temp, " %i", sec);
  6303. time_msg.append(temp);
  6304. time_msg.append(" second");
  6305. time_msg.append((sec > 1) ? "s" : "");
  6306. }
  6307. 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());
  6308. }
  6309. }
  6310. else
  6311. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6312. }
  6313. else
  6314. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6315. return 0;
  6316. }
  6317. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6318. if (!lua_interface)
  6319. return 0;
  6320. Spawn* spawn = lua_interface->GetSpawn(state);
  6321. if (!spawn) {
  6322. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6323. return 0;
  6324. }
  6325. if (!spawn->IsPlayer()) {
  6326. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6327. return 0;
  6328. }
  6329. ZoneServer* zone = spawn->GetZone();
  6330. if (!zone) {
  6331. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6332. return 0;
  6333. }
  6334. Instance_Type iType = zone->GetInstanceType();
  6335. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6336. iType == GROUP_LOCKOUT_INSTANCE ||
  6337. iType == RAID_LOCKOUT_INSTANCE ||
  6338. iType == SOLO_PERSIST_INSTANCE ||
  6339. iType == GROUP_PERSIST_INSTANCE ||
  6340. iType == RAID_PERSIST_INSTANCE) {
  6341. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6342. if (data) {
  6343. // Check to see if the timer has already been set, if it has return out.
  6344. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6345. return 0;
  6346. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6347. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6348. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6349. if (client) {
  6350. string time_msg = "";
  6351. int32 time = data->failure_lockout_time;
  6352. int16 hour;
  6353. int8 min;
  6354. int8 sec;
  6355. hour = time / 3600;
  6356. time = time % 3600;
  6357. min = time / 60;
  6358. time = time % 60;
  6359. sec = time;
  6360. if (hour > 0) {
  6361. char temp[10];
  6362. sprintf(temp, " %i", hour);
  6363. time_msg.append(temp);
  6364. time_msg.append(" hour");
  6365. time_msg.append((hour > 1) ? "s" : "");
  6366. }
  6367. if (min > 0) {
  6368. char temp[5];
  6369. sprintf(temp, " %i", min);
  6370. time_msg.append(temp);
  6371. time_msg.append(" minute");
  6372. time_msg.append((min > 1) ? "s" : "");
  6373. }
  6374. // Only add seconds if minutes and hours are 0
  6375. if (hour == 0 && min == 0 && sec > 0) {
  6376. char temp[5];
  6377. sprintf(temp, " %i", sec);
  6378. time_msg.append(temp);
  6379. time_msg.append(" second");
  6380. time_msg.append((sec > 1) ? "s" : "");
  6381. }
  6382. 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());
  6383. }
  6384. }
  6385. else
  6386. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6387. }
  6388. else
  6389. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6390. return 0;
  6391. }
  6392. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6393. if (!lua_interface)
  6394. return 0;
  6395. Spawn* spawn = lua_interface->GetSpawn(state);
  6396. if (!spawn) {
  6397. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6398. return 0;
  6399. }
  6400. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6401. return 1;
  6402. }
  6403. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6404. if (!lua_interface)
  6405. return 0;
  6406. Spawn* player = lua_interface->GetSpawn(state);
  6407. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6408. if (!player) {
  6409. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6410. return 0;
  6411. }
  6412. if (!player->IsPlayer()) {
  6413. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6414. return 0;
  6415. }
  6416. if (!ground) {
  6417. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6418. return 0;
  6419. }
  6420. if (!ground->IsGroundSpawn()) {
  6421. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6422. return 0;
  6423. }
  6424. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6425. if (!groundspawn_entries) {
  6426. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6427. return 0;
  6428. }
  6429. Skill* skill = 0;
  6430. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6431. if (collection_skill == "Collecting")
  6432. skill = ((Player*)player)->GetSkillByName("Gathering");
  6433. else
  6434. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6435. if (!skill) {
  6436. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6437. return 0;
  6438. }
  6439. vector<GroundSpawnEntry*>::iterator itr;
  6440. GroundSpawnEntry* entry = 0;
  6441. bool can_harvest = false;
  6442. sint32 min_skill = -1;
  6443. int16 totalSkill = skill->current_val;
  6444. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6445. if(skillID != 0xFFFFFFFF)
  6446. {
  6447. ((Entity*)player)->MStats.lock();
  6448. totalSkill += ((Entity*)player)->stats[skillID];
  6449. ((Entity*)player)->MStats.unlock();
  6450. }
  6451. // first, iterate through groundspawn_entries, discard tables player cannot use
  6452. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6453. {
  6454. entry = *itr;
  6455. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6456. min_skill = entry->min_skill_level;
  6457. // if player lacks skill, skip table
  6458. if (entry->min_skill_level > totalSkill)
  6459. continue;
  6460. // if bonus, but player lacks level, skip table
  6461. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6462. continue;
  6463. can_harvest = true;
  6464. break;
  6465. }
  6466. lua_interface->SetBooleanValue(state, can_harvest);
  6467. // If false, send the message to the client
  6468. if (!can_harvest) {
  6469. Client* client = player->GetZone()->GetClientBySpawn(player);
  6470. if (client) {
  6471. string msg = "You do not have enough skill to ";
  6472. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6473. msg.append("gather");
  6474. else if (collection_skill == "Mining")
  6475. msg.append("mine");
  6476. else if (collection_skill == "Trapping")
  6477. msg.append("trap");
  6478. else if (collection_skill == "Foresting")
  6479. msg.append("forest");
  6480. else if (collection_skill == "Fishing")
  6481. msg.append("catch");
  6482. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6483. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6484. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6485. }
  6486. }
  6487. return 1;
  6488. }
  6489. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6490. if (!lua_interface)
  6491. return 0;
  6492. Spawn* player = lua_interface->GetSpawn(state);
  6493. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6494. if (!player) {
  6495. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6496. return 0;
  6497. }
  6498. if (!player->IsPlayer()) {
  6499. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6500. return 0;
  6501. }
  6502. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6503. lua_interface->SetBooleanValue(state, ret);
  6504. return 1;
  6505. }
  6506. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6507. // Check to see if we have a valid lua_interface
  6508. if (!lua_interface)
  6509. return 0;
  6510. // Get the spawn that is getting the pet
  6511. Spawn* spawn = lua_interface->GetSpawn(state);
  6512. Spawn* target = lua_interface->GetSpawn(state, 2);
  6513. // Get the DB ID of the pet
  6514. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6515. float x = lua_interface->GetFloatValue(state, 4);
  6516. float y = lua_interface->GetFloatValue(state, 5);
  6517. float z = lua_interface->GetFloatValue(state, 6);
  6518. // Get the spell that this command was called from
  6519. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6520. // Check to make sure the spawn pointer is valid
  6521. if (!spawn) {
  6522. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6523. return 0;
  6524. }
  6525. // Check to make sure the spawn is an entity
  6526. if (!spawn->IsEntity()) {
  6527. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6528. return 0;
  6529. }
  6530. if (!target) {
  6531. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6532. return 0;
  6533. }
  6534. if (!target->IsEntity()) {
  6535. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6536. return 0;
  6537. }
  6538. // Check to see if the DB ID for the pet is set
  6539. if (pet_id == 0) {
  6540. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6541. return 0;
  6542. }
  6543. // Check to see if the pointer to the spell is valid
  6544. if (!luaspell) {
  6545. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6546. return 0;
  6547. }
  6548. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6549. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6550. if (!pet) {
  6551. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6552. return 0;
  6553. }
  6554. // Check to make sure the pet is an npc
  6555. if (!pet->IsNPC()) {
  6556. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6557. return 0;
  6558. }
  6559. if (x == 0)
  6560. x = spawn->GetX();
  6561. if (y == 0)
  6562. y = spawn->GetY();
  6563. if (z == 0)
  6564. z = spawn->GetZ();
  6565. // Spawn the pet at the same location as the owner
  6566. pet->SetX(x);
  6567. pet->SetY(y);
  6568. pet->SetZ(z);
  6569. pet->SetLocation(spawn->GetLocation());
  6570. pet->SetHeading(spawn->GetHeading());
  6571. spawn->GetZone()->AddSpawn(pet);
  6572. /*
  6573. const char* spawn_script = world.GetSpawnScript(pet_id);
  6574. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6575. spawn->SetSpawnScript(string(spawn_script));
  6576. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6577. }*/
  6578. // Get a random pet name
  6579. string random_pet_name;
  6580. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6581. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6582. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6583. // Set the pets name
  6584. pet->SetName(random_pet_name.c_str());
  6585. // Set the level of the pet to the owners level
  6586. pet->SetLevel(spawn->GetLevel());
  6587. // Set the faction of the pet to the same faction as the owner
  6588. pet->SetFactionID(spawn->GetFactionID());
  6589. // Set the spawn as a pet
  6590. pet->SetPet(true);
  6591. // Give a pointer of the owner to the pet
  6592. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6593. // Set the pet type
  6594. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6595. // Set the spell id used to create this pet
  6596. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6597. // Set the spell tier used to create this pet
  6598. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6599. // Set the pets spawn type to 6
  6600. pet->SetSpawnType(6);
  6601. // Set the pets brain
  6602. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6603. // Check to see if the pet has a subtitle
  6604. if (strlen(pet->GetSubTitle()) > 0) {
  6605. // Add the players name to the front of the sub title
  6606. string pet_subtitle;
  6607. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6608. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6609. // Set the pets subtitle to the new one
  6610. pet->SetSubTitle(pet_subtitle.c_str());
  6611. }
  6612. // Set the pet as the return value for this function
  6613. lua_interface->SetSpawnValue(state, pet);
  6614. return 1;
  6615. }
  6616. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6617. if (!lua_interface)
  6618. return 0;
  6619. Spawn* spawn = lua_interface->GetSpawn(state);
  6620. Spawn* player = lua_interface->GetSpawn(state, 2);
  6621. float max_distance = lua_interface->GetFloatValue(state, 3);
  6622. string type = lua_interface->GetStringValue(state, 4);
  6623. if (!spawn || (spawn && spawn->IsPlayer())) {
  6624. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6625. return 0;
  6626. }
  6627. if (!player || (player && !player->IsPlayer())) {
  6628. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6629. return 0;
  6630. }
  6631. Client* client = 0;
  6632. if (player->GetZone())
  6633. client = player->GetZone()->GetClientBySpawn(player);
  6634. if (!client) {
  6635. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6636. return 0;
  6637. }
  6638. //Set max_distance to default if not set or not proper value
  6639. if (max_distance <= 0)
  6640. max_distance = 500;
  6641. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6642. if (packet) {
  6643. float unknown2_3 = 0;
  6644. int8 placement_mode = 0;
  6645. if (type == "wall") {
  6646. placement_mode = 2;
  6647. unknown2_3 = 150;
  6648. }
  6649. else if (type == "ceiling")
  6650. placement_mode = 1;
  6651. packet->setDataByName("placement_mode", placement_mode);
  6652. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6653. packet->setDataByName("model_type", spawn->GetModelType());
  6654. packet->setDataByName("unknown", 1); //size
  6655. packet->setDataByName("unknown2", 1); //size 2
  6656. packet->setDataByName("unknown2", .5, 1); //size 3
  6657. packet->setDataByName("unknown2", 3, 2);
  6658. packet->setDataByName("unknown2", unknown2_3, 3);
  6659. packet->setDataByName("max_distance", max_distance);
  6660. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6661. client->QueuePacket(packet->serialize());
  6662. safe_delete(packet);
  6663. }
  6664. return 0;
  6665. }
  6666. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6667. if (!lua_interface)
  6668. return 0;
  6669. Item* item = lua_interface->GetItem(state);
  6670. if (!item) {
  6671. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6672. return 0;
  6673. }
  6674. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6675. return 1;
  6676. }
  6677. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6678. if (!lua_interface)
  6679. return 0;
  6680. Spawn* spawn = lua_interface->GetSpawn(state);
  6681. if (!spawn) {
  6682. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6683. return 0;
  6684. }
  6685. if (spawn->GetZone())
  6686. spawn->GetZone()->AddTransportSpawn(spawn);
  6687. return 0;
  6688. }
  6689. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6690. if (!lua_interface)
  6691. return 0;
  6692. Skill* skill = lua_interface->GetSkill(state);
  6693. if (!skill) {
  6694. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6695. return 0;
  6696. }
  6697. lua_interface->SetInt32Value(state, skill->current_val);
  6698. return 1;
  6699. }
  6700. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6701. if (!lua_interface)
  6702. return 0;
  6703. Skill* skill = lua_interface->GetSkill(state);
  6704. if (!skill) {
  6705. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6706. return 0;
  6707. }
  6708. lua_interface->SetInt32Value(state, skill->max_val);
  6709. return 1;
  6710. }
  6711. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6712. if (!lua_interface)
  6713. return 0;
  6714. Skill* skill = lua_interface->GetSkill(state);
  6715. if (!skill) {
  6716. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6717. return 0;
  6718. }
  6719. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6720. return 1;
  6721. }
  6722. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6723. if (!lua_interface)
  6724. return 0;
  6725. Skill* skill = lua_interface->GetSkill(state);
  6726. int16 value = lua_interface->GetInt16Value(state, 2);
  6727. if (!skill) {
  6728. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6729. return 0;
  6730. }
  6731. skill->max_val = value;
  6732. if (skill->max_val < skill->current_val)
  6733. skill->current_val = skill->max_val;
  6734. return 0;
  6735. }
  6736. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6737. if (!lua_interface)
  6738. return 0;
  6739. Skill* skill = lua_interface->GetSkill(state);
  6740. int16 value = lua_interface->GetInt16Value(state, 2);
  6741. if (!skill) {
  6742. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6743. return 0;
  6744. }
  6745. if (value > skill->max_val)
  6746. skill->current_val = skill->max_val;
  6747. else
  6748. skill->current_val = value;
  6749. return 0;
  6750. }
  6751. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6752. if (!lua_interface)
  6753. return 0;
  6754. Spawn* player = lua_interface->GetSpawn(state);
  6755. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6756. if (skill_id > 0 && player && player->IsPlayer()) {
  6757. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6758. return 1;
  6759. }
  6760. return 0;
  6761. }
  6762. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6763. if (!lua_interface)
  6764. return 0;
  6765. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6766. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6767. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6768. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6769. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6770. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6771. if (player_spawn && player_spawn->IsPlayer()) {
  6772. Player* player = (Player*)player_spawn;
  6773. bool added = false;
  6774. if (!player->skill_list.HasSkill(skill_id)) {
  6775. player->AddSkill(skill_id, current_val, max_val, true);
  6776. added = true;
  6777. }
  6778. 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
  6779. Client* client = player->GetClient();
  6780. if (client) {
  6781. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6782. if (packet)
  6783. client->QueuePacket(packet);
  6784. }
  6785. }
  6786. if (added) {
  6787. lua_interface->SetBooleanValue(state, true);
  6788. return 1;
  6789. }
  6790. }
  6791. else {
  6792. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6793. }
  6794. }
  6795. else {
  6796. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6797. }
  6798. lua_interface->SetBooleanValue(state, false);
  6799. return 1;
  6800. }
  6801. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6802. if (!lua_interface)
  6803. return 0;
  6804. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6805. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6806. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6807. if (skill_id > 0) {
  6808. if (player_spawn && player_spawn->IsPlayer()) {
  6809. Player* player = (Player*)player_spawn;
  6810. if (player->skill_list.HasSkill(skill_id)) {
  6811. player->RemovePlayerSkill(skill_id);
  6812. if (!more_to_remove) {
  6813. Client* client = player->GetClient();
  6814. if (client) {
  6815. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6816. if (packet)
  6817. client->QueuePacket(packet);
  6818. }
  6819. }
  6820. }
  6821. }
  6822. else {
  6823. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6824. }
  6825. }
  6826. else {
  6827. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6828. }
  6829. return 0;
  6830. }
  6831. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6832. if (!lua_interface)
  6833. return 0;
  6834. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6835. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6836. int16 amount = lua_interface->GetInt8Value(state, 3);
  6837. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6838. if (amount > 0 && skill_type < 100) {
  6839. if (player_spawn && player_spawn->IsPlayer()) {
  6840. Player* player = (Player*)player_spawn;
  6841. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6842. if (!more_to_increase) {
  6843. Client* client = player->GetClient();
  6844. if (client) {
  6845. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6846. if (packet)
  6847. client->QueuePacket(packet);
  6848. }
  6849. }
  6850. }
  6851. else {
  6852. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6853. }
  6854. }
  6855. else {
  6856. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6857. }
  6858. return 0;
  6859. }
  6860. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6861. if (!lua_interface)
  6862. return 0;
  6863. Spawn* spawn = lua_interface->GetSpawn(state);
  6864. string name = lua_interface->GetStringValue(state, 2);
  6865. if (!spawn) {
  6866. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6867. return 0;
  6868. }
  6869. if (!spawn->IsEntity()) {
  6870. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6871. return 0;
  6872. }
  6873. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6874. if (skill) {
  6875. lua_interface->SetSkillValue(state, skill);
  6876. return 1;
  6877. }
  6878. return 0;
  6879. }
  6880. int EQ2Emu_lua_AddProc(lua_State* state) {
  6881. if (!lua_interface)
  6882. return 0;
  6883. Spawn* spawn = lua_interface->GetSpawn(state);
  6884. int8 type = lua_interface->GetInt8Value(state, 2);
  6885. float chance = lua_interface->GetFloatValue(state, 3);
  6886. Item* item = lua_interface->GetItem(state, 4);
  6887. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6888. LuaSpell* spell = 0;
  6889. if (!spawn && (!spell || !use_all_spelltargets)) {
  6890. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6891. return 0;
  6892. }
  6893. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6894. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6895. return 0;
  6896. }
  6897. if (!item)
  6898. spell = lua_interface->GetCurrentSpell(state);
  6899. if (!item && !spell) {
  6900. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6901. return 0;
  6902. }
  6903. if (spell && use_all_spelltargets) {
  6904. Spawn* target;
  6905. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6906. for (int8 i = 0; i < spell->targets.size(); i++) {
  6907. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6908. if (!target || !target->IsEntity())
  6909. continue;
  6910. ((Entity*)target)->AddProc(type, chance, item, spell);
  6911. }
  6912. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6913. }
  6914. else
  6915. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6916. return 0;
  6917. }
  6918. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6919. if (!lua_interface)
  6920. return 0;
  6921. Spawn* spawn = lua_interface->GetSpawn(state);
  6922. Item* item = lua_interface->GetItem(state, 2);
  6923. LuaSpell* spell = 0;
  6924. if (!spawn) {
  6925. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6926. return 0;
  6927. }
  6928. if (!spawn->IsEntity()) {
  6929. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6930. return 0;
  6931. }
  6932. if (!item)
  6933. spell = lua_interface->GetCurrentSpell(state);
  6934. if (!item && !spell) {
  6935. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6936. return 0;
  6937. }
  6938. if (spell) {
  6939. Spawn* target;
  6940. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6941. for (int8 i = 0; i < spell->targets.size(); i++) {
  6942. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6943. if (!target || !target->IsEntity())
  6944. continue;
  6945. ((Entity*)target)->RemoveProc(item, spell);
  6946. }
  6947. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6948. spell->caster->RemoveProc(item, spell);
  6949. }
  6950. else
  6951. ((Entity*)spawn)->RemoveProc(item, spell);
  6952. return 0;
  6953. }
  6954. int EQ2Emu_lua_Knockback(lua_State* state) {
  6955. if (!lua_interface)
  6956. return 0;
  6957. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6958. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6959. int32 duration = lua_interface->GetInt32Value(state, 3);
  6960. float vertical = lua_interface->GetFloatValue(state, 4);
  6961. float horizontal = lua_interface->GetFloatValue(state, 5);
  6962. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6963. if (!target_spawn) {
  6964. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6965. return 0;
  6966. }
  6967. if (!spawn) {
  6968. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6969. return 0;
  6970. }
  6971. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6972. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6973. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6974. if (packet) {
  6975. packet->setDataByName("target_x", target_spawn->GetX());
  6976. packet->setDataByName("target_y", target_spawn->GetY());
  6977. packet->setDataByName("target_z", target_spawn->GetZ());
  6978. packet->setDataByName("vertical_movement", vertical);
  6979. packet->setDataByName("horizontal_movement", horizontal);
  6980. if (use_heading)
  6981. packet->setDataByName("use_player_heading", 1);
  6982. client->QueuePacket(packet->serialize());
  6983. }
  6984. safe_delete(packet);
  6985. }
  6986. return 0;
  6987. }
  6988. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6989. if (!lua_interface)
  6990. return 0;
  6991. Spawn* spawn = lua_interface->GetSpawn(state);
  6992. if (!spawn) {
  6993. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6994. return 0;
  6995. }
  6996. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6997. return 1;
  6998. }
  6999. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7000. if (!lua_interface)
  7001. return 0;
  7002. Spawn* caster = lua_interface->GetSpawn(state);
  7003. Spawn* target = lua_interface->GetSpawn(state, 2);
  7004. string name = lua_interface->GetStringValue(state, 3);
  7005. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7006. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7007. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7008. string success_msg = lua_interface->GetStringValue(state, 7);
  7009. string effect_msg = lua_interface->GetStringValue(state, 8);
  7010. if (!caster) {
  7011. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7012. return 0;
  7013. }
  7014. if (!caster->IsEntity()) {
  7015. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7016. return 0;
  7017. }
  7018. if (!target) {
  7019. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7020. return 0;
  7021. }
  7022. if (!target->IsEntity()) {
  7023. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7024. return 0;
  7025. }
  7026. if (name.length() == 0) {
  7027. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7028. return 0;
  7029. }
  7030. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7031. return 0;
  7032. }
  7033. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7034. if (!lua_interface)
  7035. return 0;
  7036. string name = lua_interface->GetStringValue(state);
  7037. if (name.length() == 0) {
  7038. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7039. return 0;
  7040. }
  7041. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7042. if (!skill) {
  7043. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7044. return 0;
  7045. }
  7046. lua_interface->SetInt32Value(state, skill->skill_id);
  7047. return 1;
  7048. }
  7049. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7050. if (!lua_interface)
  7051. return 0;
  7052. Spawn* spawn = lua_interface->GetSpawn(state);
  7053. if (!spawn) {
  7054. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7055. return 0;
  7056. }
  7057. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7058. return 1;
  7059. }
  7060. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7061. if (!lua_interface)
  7062. return 0;
  7063. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7064. if (!luaspell) {
  7065. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7066. return 0;
  7067. }
  7068. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7069. return 1;
  7070. }
  7071. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7072. if (!lua_interface)
  7073. return 0;
  7074. Spawn* spawn = lua_interface->GetSpawn(state);
  7075. Spawn* target = lua_interface->GetSpawn(state, 2);
  7076. if (!spawn) {
  7077. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7078. return 0;
  7079. }
  7080. if (!spawn->IsEntity()) {
  7081. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7082. return 0;
  7083. }
  7084. if (!target) {
  7085. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7086. return 0;
  7087. }
  7088. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7089. return 1;
  7090. }
  7091. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7092. if (!lua_interface)
  7093. return 0;
  7094. Spawn* spawn = lua_interface->GetSpawn(state);
  7095. Spawn* target = lua_interface->GetSpawn(state, 2);
  7096. if (!spawn) {
  7097. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7098. return 0;
  7099. }
  7100. if (!spawn->IsEntity()) {
  7101. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7102. return 0;
  7103. }
  7104. if (!target) {
  7105. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7106. return 0;
  7107. }
  7108. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7109. return 1;
  7110. }
  7111. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7112. if (!lua_interface)
  7113. return 0;
  7114. Item* item = lua_interface->GetItem(state);
  7115. if (!item) {
  7116. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7117. return 0;
  7118. }
  7119. lua_interface->SetInt32Value(state, item->details.count);
  7120. return 1;
  7121. }
  7122. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7123. if (!lua_interface)
  7124. return 0;
  7125. Item* item = lua_interface->GetItem(state);
  7126. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7127. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7128. if (!item) {
  7129. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7130. return 0;
  7131. }
  7132. if (!owner) {
  7133. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7134. return 0;
  7135. }
  7136. if (!owner->IsPlayer()) {
  7137. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7138. return 0;
  7139. }
  7140. if (item->stack_count < new_count) {
  7141. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7142. return 0;
  7143. }
  7144. if (new_count > 0) {
  7145. item->details.count = new_count;
  7146. item->save_needed = true;
  7147. }
  7148. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7149. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7150. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7151. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7152. else
  7153. {
  7154. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7155. return 0;
  7156. }
  7157. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7158. if (!client)
  7159. return 0;
  7160. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7161. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  7162. if (app)
  7163. client->QueuePacket(app);
  7164. return 0;
  7165. }
  7166. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7167. if (!lua_interface)
  7168. return 0;
  7169. int32 time = lua_interface->GetInt32Value(state);
  7170. string function = lua_interface->GetStringValue(state, 2);
  7171. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7172. Spawn* target = lua_interface->GetSpawn(state, 4);
  7173. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7174. if (time == 0) {
  7175. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7176. return 0;
  7177. }
  7178. if (function.length() == 0) {
  7179. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7180. return 0;
  7181. }
  7182. if (!spell) {
  7183. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7184. return 0;
  7185. }
  7186. SpellScriptTimer* timer = new SpellScriptTimer;
  7187. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7188. #ifdef WIN32
  7189. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7190. #else
  7191. bzero(timer, sizeof(SpellScriptTimer));
  7192. #endif*/
  7193. timer->caster = 0;
  7194. timer->deleteWhenDone = false;
  7195. timer->target = 0;
  7196. timer->time = Timer::GetCurrentTime2() + time;
  7197. timer->customFunction = function;
  7198. timer->spell = spell;
  7199. if (caster)
  7200. timer->caster = caster->GetID();
  7201. if (target)
  7202. timer->target = target->GetID();
  7203. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7204. return 0;
  7205. }
  7206. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7207. if (!lua_interface)
  7208. return 0;
  7209. float hp_perc = lua_interface->GetFloatValue(state);
  7210. float power_perc = lua_interface->GetFloatValue(state, 2);
  7211. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7212. Spawn* target = lua_interface->GetSpawn(state, 4);
  7213. string heal_name = lua_interface->GetStringValue(state, 5);
  7214. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7215. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7216. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7217. if (!spell) {
  7218. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7219. return 0;
  7220. }
  7221. Entity* caster = spell->caster;
  7222. if (!caster) {
  7223. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7224. return 0;
  7225. }
  7226. Client* client = 0;
  7227. PendingResurrection* rez = 0;
  7228. ZoneServer* zone = spell->caster->GetZone();
  7229. if (!target) {
  7230. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7231. if (spell->targets.size() > 0) {
  7232. vector<int32> spell_targets = spell->targets;
  7233. for (int8 i = 0; i < spell_targets.size(); i++) {
  7234. target = zone->GetSpawnByID(spell_targets.at(i));
  7235. if (!target)
  7236. continue;
  7237. if (!target->IsPlayer())
  7238. continue;
  7239. client = target->GetZone()->GetClientBySpawn(target);
  7240. if (!client)
  7241. continue;
  7242. rez = client->GetCurrentRez();
  7243. if (rez->active)
  7244. continue;
  7245. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7246. rez->active = true;
  7247. rez->caster = caster;
  7248. rez->expire_timer = new Timer;
  7249. int32 duration = spell->spell->GetSpellDuration();
  7250. rez->expire_timer->Start(duration * 100);
  7251. rez->hp_perc = hp_perc;
  7252. rez->mp_perc = power_perc;
  7253. rez->range = spell->spell->GetSpellData()->range;
  7254. rez->spell_name = spell->spell->GetName();
  7255. if (heal_name.length() > 0)
  7256. rez->heal_name = heal_name;
  7257. else
  7258. rez->heal_name = rez->spell_name;
  7259. rez->no_calcs = no_calcs;
  7260. rez->crit_mod = crit_mod;
  7261. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7262. if (send_window)
  7263. client->SendResurrectionWindow();
  7264. else {
  7265. target->GetZone()->ResurrectSpawn(target, client);
  7266. rez->should_delete = true;
  7267. }
  7268. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7269. }
  7270. }
  7271. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7272. }
  7273. else {
  7274. client = target->GetZone()->GetClientBySpawn(target);
  7275. if (!client)
  7276. return 0;
  7277. rez = client->GetCurrentRez();
  7278. if (rez->active)
  7279. return 0;
  7280. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7281. rez->active = true;
  7282. rez->caster = caster;
  7283. rez->expire_timer = new Timer;
  7284. int32 duration = spell->spell->GetSpellDuration();
  7285. rez->expire_timer->Start(duration * 100);
  7286. rez->hp_perc = hp_perc;
  7287. rez->mp_perc = power_perc;
  7288. rez->range = spell->spell->GetSpellData()->range;
  7289. rez->spell_name = spell->spell->GetName();
  7290. if (heal_name.length() > 0)
  7291. rez->heal_name = heal_name;
  7292. else
  7293. rez->heal_name = rez->spell_name;
  7294. rez->no_calcs = no_calcs;
  7295. rez->crit_mod = crit_mod;
  7296. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7297. if (send_window)
  7298. client->SendResurrectionWindow();
  7299. else {
  7300. target->GetZone()->ResurrectSpawn(target, client);
  7301. rez->should_delete = true;
  7302. }
  7303. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7304. }
  7305. return 0;
  7306. }
  7307. int EQ2Emu_lua_SetVision(lua_State* state) {
  7308. if (!lua_interface)
  7309. return 0;
  7310. Spawn* spawn = lua_interface->GetSpawn(state);
  7311. int8 vision = lua_interface->GetInt8Value(state, 2);
  7312. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7313. if (!spawn) {
  7314. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. if (!spawn->IsEntity()) {
  7318. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7319. return 0;
  7320. }
  7321. if (spell && spell->targets.size() > 0) {
  7322. ZoneServer* zone = spell->caster->GetZone();
  7323. for (int8 i = 0; i < spell->targets.size(); i++) {
  7324. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7325. if (target->IsEntity()) {
  7326. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7327. if (target->IsPlayer())
  7328. ((Player*)target)->SetCharSheetChanged(true);
  7329. }
  7330. }
  7331. }
  7332. else {
  7333. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7334. if (spawn->IsPlayer())
  7335. ((Player*)spawn)->SetCharSheetChanged(true);
  7336. }
  7337. return 0;
  7338. }
  7339. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7340. if (!lua_interface)
  7341. return 0;
  7342. Spawn* spawn = lua_interface->GetSpawn(state);
  7343. float intensity = lua_interface->GetFloatValue(state, 2);
  7344. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7345. if (!spawn) {
  7346. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7347. return 0;
  7348. }
  7349. if (!spawn->IsEntity()) {
  7350. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7351. return 0;
  7352. }
  7353. if (spell && spell->targets.size() > 0) {
  7354. ZoneServer* zone = spell->caster->GetZone();
  7355. for (int8 i = 0; i < spell->targets.size(); i++) {
  7356. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7357. if (target && target->IsEntity()) {
  7358. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7359. if (target->IsPlayer())
  7360. ((Player*)target)->SetCharSheetChanged(true);
  7361. }
  7362. }
  7363. }
  7364. else {
  7365. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7366. if (spawn->IsPlayer())
  7367. ((Player*)spawn)->SetCharSheetChanged(true);
  7368. }
  7369. return 0;
  7370. }
  7371. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7372. if (!lua_interface)
  7373. return 0;
  7374. Spawn* spawn = lua_interface->GetSpawn(state);
  7375. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7376. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7377. if (!spawn) {
  7378. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7379. return 0;
  7380. }
  7381. if (!spawn->IsEntity()) {
  7382. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7383. return 0;
  7384. }
  7385. if (spell && spell->targets.size() > 0) {
  7386. ZoneServer* zone = spell->caster->GetZone();
  7387. for (int8 i = 0; i < spell->targets.size(); i++) {
  7388. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7389. if (target->IsEntity()) {
  7390. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7391. if (target->IsPlayer())
  7392. ((Player*)target)->SetCharSheetChanged(true);
  7393. }
  7394. }
  7395. }
  7396. else {
  7397. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7398. if (spawn->IsPlayer())
  7399. ((Player*)spawn)->SetCharSheetChanged(true);
  7400. }
  7401. return 0;
  7402. }
  7403. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7404. if (!lua_interface)
  7405. return 0;
  7406. Item* item = lua_interface->GetItem(state);
  7407. int8 type = lua_interface->GetInt32Value(state, 2);
  7408. if (!item) {
  7409. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7410. return 0;
  7411. }
  7412. if (type == 1)
  7413. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7414. else if (type == 2)
  7415. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7416. return 1;
  7417. }
  7418. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7419. if (!lua_interface)
  7420. return 0;
  7421. Spawn* target = lua_interface->GetSpawn(state);
  7422. float val = lua_interface->GetFloatValue(state, 2);
  7423. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7424. // Added from Gangrenous post
  7425. if (spell && spell->resisted)
  7426. return 0;
  7427. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7428. if (val > 1.0f)
  7429. val = 1.0f - (val / 100.0f);
  7430. if (spell && spell->spell && spell->targets.size() > 0) {
  7431. ZoneServer* zone = spell->caster->GetZone();
  7432. for (int32 i = 0; i != spell->targets.size(); i++) {
  7433. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7434. if (spawn && spawn->IsEntity()) {
  7435. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7436. if (spawn->IsPlayer())
  7437. ((Player*)spawn)->SetCharSheetChanged(true);
  7438. }
  7439. }
  7440. }
  7441. else {
  7442. if (target && target->IsEntity()) {
  7443. ((Entity*)target)->SetSpeedMultiplier(val);
  7444. if (target->IsPlayer())
  7445. ((Player*)target)->SetCharSheetChanged(true);
  7446. }
  7447. }
  7448. return 0;
  7449. }
  7450. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7451. if (!lua_interface)
  7452. return 0;
  7453. Spawn* spawn = lua_interface->GetSpawn(state);
  7454. int16 model = lua_interface->GetInt16Value(state, 2);
  7455. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7456. if (spell && spell->spell && spell->targets.size() > 0) {
  7457. ZoneServer* zone = spell->caster->GetZone();
  7458. for (int32 i = 0; i < spell->targets.size(); i++) {
  7459. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7460. if (target)
  7461. target->SetIllusionModel(model);
  7462. }
  7463. }
  7464. else {
  7465. if (!spawn) {
  7466. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7467. return 0;
  7468. }
  7469. spawn->SetIllusionModel(model);
  7470. }
  7471. return 0;
  7472. }
  7473. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7474. if (!lua_interface)
  7475. return 0;
  7476. Spawn* spawn = lua_interface->GetSpawn(state);
  7477. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7478. if (spell && spell->spell && spell->targets.size() > 0) {
  7479. ZoneServer* zone = spell->caster->GetZone();
  7480. for (int32 i = 0; i < spell->targets.size(); i++) {
  7481. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7482. if (target)
  7483. target->SetIllusionModel(0);
  7484. }
  7485. }
  7486. else {
  7487. if (!spawn) {
  7488. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7489. return 0;
  7490. }
  7491. spawn->SetIllusionModel(0);
  7492. }
  7493. return 0;
  7494. }
  7495. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7496. if (!lua_interface)
  7497. return 0;
  7498. Spawn* caster = lua_interface->GetSpawn(state);
  7499. Spawn* target = lua_interface->GetSpawn(state, 2);
  7500. float chance = lua_interface->GetFloatValue(state, 3);
  7501. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7502. if (!caster) {
  7503. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7504. return 0;
  7505. }
  7506. if (!caster->IsEntity()) {
  7507. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7508. return 0;
  7509. }
  7510. if (!target) {
  7511. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7512. return 0;
  7513. }
  7514. if (!target->IsEntity()) {
  7515. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7516. return 0;
  7517. }
  7518. if (chance <= 0) {
  7519. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7520. return 0;
  7521. }
  7522. if (!spell) {
  7523. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7524. return 0;
  7525. }
  7526. if (((Entity*)caster)->GetThreatTransfer()) {
  7527. return 0;
  7528. }
  7529. ThreatTransfer* transfer = new ThreatTransfer;
  7530. transfer->Target = target->GetID();
  7531. transfer->Amount = chance;
  7532. transfer->Spell = spell;
  7533. ((Entity*)caster)->SetThreatTransfer(transfer);
  7534. return 0;
  7535. }
  7536. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7537. if (!lua_interface)
  7538. return 0;
  7539. Spawn* spawn = lua_interface->GetSpawn(state);
  7540. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7541. if (!spawn) {
  7542. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7543. return 0;
  7544. }
  7545. if (!spell) {
  7546. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7547. return 0;
  7548. }
  7549. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7550. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7551. ((Entity*)spawn)->SetThreatTransfer(0);
  7552. safe_delete(transfer);
  7553. }
  7554. return 0;
  7555. }
  7556. int EQ2Emu_lua_CureByType(lua_State* state) {
  7557. if (!lua_interface)
  7558. return 0;
  7559. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7560. if (!spell) {
  7561. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7562. return 0;
  7563. }
  7564. int8 cure_count = lua_interface->GetInt8Value(state);
  7565. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7566. string cure_name = lua_interface->GetStringValue(state, 3);
  7567. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7568. Spawn* target = lua_interface->GetSpawn(state, 5);
  7569. if (target) {
  7570. if (!target->IsEntity()) {
  7571. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7572. return 0;
  7573. }
  7574. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7575. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7576. }
  7577. else {
  7578. ZoneServer* zone = spell->caster->GetZone();
  7579. vector<int32> targets = spell->targets;
  7580. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7581. for (int8 i = 0; i < targets.size(); i++) {
  7582. target = zone->GetSpawnByID(targets.at(i));
  7583. if (!target || !target->IsEntity())
  7584. continue;
  7585. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7586. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7587. }
  7588. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7589. }
  7590. return 0;
  7591. }
  7592. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7593. if (!lua_interface)
  7594. return 0;
  7595. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7596. if (!spell) {
  7597. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7598. return 0;
  7599. }
  7600. int8 cure_count = lua_interface->GetInt8Value(state);
  7601. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7602. string cure_name = lua_interface->GetStringValue(state, 3);
  7603. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7604. Spawn* target = lua_interface->GetSpawn(state, 5);
  7605. if (target) {
  7606. if (!target->IsEntity()) {
  7607. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7608. return 0;
  7609. }
  7610. if (((Entity*)target)->GetDetCount() > 0)
  7611. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7612. }
  7613. else {
  7614. ZoneServer* zone = spell->caster->GetZone();
  7615. vector<int32> targets = spell->targets;
  7616. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7617. for (int8 i = 0; i < targets.size(); i++) {
  7618. target = zone->GetSpawnByID(targets.at(i));
  7619. if (!target || !target->IsEntity())
  7620. continue;
  7621. if (((Entity*)target)->GetDetCount() > 0)
  7622. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7623. }
  7624. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7625. }
  7626. return 0;
  7627. }
  7628. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7629. if (!lua_interface)
  7630. return 0;
  7631. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7632. if (!spell) {
  7633. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7634. return 0;
  7635. }
  7636. if (!spell->caster) {
  7637. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7638. return 0;
  7639. }
  7640. if (!spell->caster->GetZone()) {
  7641. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7642. return 0;
  7643. }
  7644. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7645. return 0;
  7646. }
  7647. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7648. if (!lua_interface)
  7649. return 0;
  7650. Spawn* spawn = lua_interface->GetSpawn(state);
  7651. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7652. if (!spell) {
  7653. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7654. return 0;
  7655. }
  7656. if (spawn && spawn->IsEntity())
  7657. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7658. else {
  7659. ZoneServer* zone = spell->caster->GetZone();
  7660. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7661. for (int32 i = 0; i < spell->targets.size(); i++) {
  7662. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7663. if (!spawn || !spawn->IsEntity())
  7664. continue;
  7665. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7666. }
  7667. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7668. }
  7669. return 0;
  7670. }
  7671. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7672. if (!lua_interface)
  7673. return 0;
  7674. Spawn* spawn = lua_interface->GetSpawn(state);
  7675. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7676. if (!spell) {
  7677. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7678. return 0;
  7679. }
  7680. if (spawn && spawn->IsEntity())
  7681. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7682. else {
  7683. ZoneServer* zone = spell->caster->GetZone();
  7684. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7685. for (int32 i = 0; i < spell->targets.size(); i++) {
  7686. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7687. if (!spawn || !spawn->IsEntity())
  7688. continue;
  7689. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7690. }
  7691. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7692. }
  7693. return 0;
  7694. }
  7695. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7696. if (!lua_interface)
  7697. return 0;
  7698. Spawn* caster = lua_interface->GetSpawn(state);
  7699. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7700. if (!caster) {
  7701. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7702. return 0;
  7703. }
  7704. if (!caster->IsPlayer()) {
  7705. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7706. return 0;
  7707. }
  7708. Spawn* target = caster->GetTarget();
  7709. if (!target) {
  7710. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7711. return 0;
  7712. }
  7713. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7714. if (!client) {
  7715. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7716. return 0;
  7717. }
  7718. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7719. if (ho) {
  7720. ho->SetTarget(target->GetID());
  7721. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7722. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7723. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7724. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7725. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7726. deque<GroupMemberInfo*>::iterator itr;
  7727. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7728. if (group)
  7729. {
  7730. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7731. deque<GroupMemberInfo*>* members = group->GetMembers();
  7732. for (itr = members->begin(); itr != members->end(); itr++) {
  7733. if ((*itr)->client)
  7734. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7735. }
  7736. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7737. }
  7738. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7739. }
  7740. else
  7741. safe_delete(ho);
  7742. }
  7743. else {
  7744. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7745. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7746. }
  7747. else
  7748. safe_delete(ho);
  7749. }
  7750. }
  7751. return 0;
  7752. }
  7753. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7754. if (!lua_interface)
  7755. return 0;
  7756. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7757. if (!spell) {
  7758. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7759. return 0;
  7760. }
  7761. int16 triggerCount = lua_interface->GetInt16Value(state);
  7762. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7763. if (!triggerCount) {
  7764. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7765. return 0;
  7766. }
  7767. spell->num_triggers = triggerCount;
  7768. spell->had_triggers = true;
  7769. spell->cancel_after_all_triggers = cancel_after_triggers;
  7770. return 0;
  7771. }
  7772. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7773. if (!lua_interface)
  7774. return 0;
  7775. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7776. if (!spell) {
  7777. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7778. return 0;
  7779. }
  7780. lua_interface->SetInt32Value(state, spell->num_triggers);
  7781. return 1;
  7782. }
  7783. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7784. if (!lua_interface)
  7785. return 0;
  7786. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7787. if (!spell) {
  7788. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7789. return 0;
  7790. }
  7791. int16 remove_count = lua_interface->GetInt16Value(state);
  7792. if (!remove_count)
  7793. remove_count = 1;
  7794. if (remove_count >= spell->num_triggers) {
  7795. spell->num_triggers = 0;
  7796. if (spell->cancel_after_all_triggers)
  7797. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7798. }
  7799. else {
  7800. spell->num_triggers -= remove_count;
  7801. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7802. }
  7803. return 0;
  7804. }
  7805. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7806. if (!lua_interface)
  7807. return 0;
  7808. Spawn* spawn = lua_interface->GetSpawn(state);
  7809. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7810. if (!spawn) {
  7811. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7812. return 0;
  7813. }
  7814. if (!copy_spawn) {
  7815. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7816. return 0;
  7817. }
  7818. spawn->CopySpawnAppearance(copy_spawn);
  7819. return 0;
  7820. }
  7821. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7822. Spawn* spawn = lua_interface->GetSpawn(state);
  7823. int8 type = lua_interface->GetInt8Value(state, 2);
  7824. if (!spawn) {
  7825. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7826. return 0;
  7827. }
  7828. else if (!spawn->IsEntity()) {
  7829. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7830. return 0;
  7831. }
  7832. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7833. return 1;
  7834. }
  7835. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7836. if (!lua_interface)
  7837. return 0;
  7838. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7839. int8 type = lua_interface->GetInt8Value(state);
  7840. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7841. if (!spell) {
  7842. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. if (spawn) {
  7846. if (!spawn->IsEntity()) {
  7847. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7848. return 0;
  7849. }
  7850. Entity* entity = ((Entity*)spawn);
  7851. entity->AddImmunity(spell, type);
  7852. }
  7853. else {
  7854. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7855. for (int8 i = 0; i < spell->targets.size(); i++) {
  7856. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7857. if (!spawn || !spawn->IsEntity())
  7858. continue;
  7859. Entity* entity = ((Entity*)spawn);
  7860. entity->AddImmunity(spell, type);
  7861. }
  7862. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7863. }
  7864. return 0;
  7865. }
  7866. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7867. if (!lua_interface)
  7868. return 0;
  7869. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7870. int8 type = lua_interface->GetInt8Value(state);
  7871. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7872. if (!spell) {
  7873. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7874. return 0;
  7875. }
  7876. if (spawn) {
  7877. if (!spawn->IsEntity()) {
  7878. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7879. return 0;
  7880. }
  7881. Entity* entity = ((Entity*)spawn);
  7882. entity->RemoveImmunity(spell, type);
  7883. }
  7884. else {
  7885. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7886. for (int8 i = 0; i < spell->targets.size(); i++) {
  7887. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7888. if (!spawn || !spawn->IsEntity())
  7889. continue;
  7890. Entity* entity = ((Entity*)spawn);
  7891. entity->RemoveImmunity(spell, type);
  7892. }
  7893. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7894. }
  7895. return 0;
  7896. }
  7897. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7898. if (!lua_interface)
  7899. return 0;
  7900. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7901. if (!spell) {
  7902. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7903. return 0;
  7904. }
  7905. float snare = lua_interface->GetFloatValue(state);
  7906. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7907. // convert the val to the speed multipler value (100 - val)
  7908. float val = 100.0 - snare;
  7909. val /= 100.0;
  7910. if (spawn) {
  7911. if (!spawn->IsEntity()) {
  7912. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7913. return 0;
  7914. }
  7915. ((Entity*)spawn)->SetSnareValue(spell, val);
  7916. }
  7917. else {
  7918. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7919. for (int8 i = 0; i < spell->targets.size(); i++) {
  7920. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7921. if (!spawn || !spawn->IsEntity())
  7922. continue;
  7923. ((Entity*)spawn)->SetSnareValue(spell, val);
  7924. }
  7925. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7926. }
  7927. return 0;
  7928. }
  7929. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7930. if (!lua_interface)
  7931. return 0;
  7932. Spawn* spawn = lua_interface->GetSpawn(state);
  7933. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7934. if (!spawn) {
  7935. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7936. return 0;
  7937. }
  7938. if (race_id == 0) {
  7939. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7940. return 0;
  7941. }
  7942. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7943. return 1;
  7944. }
  7945. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7946. if (!lua_interface)
  7947. return 0;
  7948. Spawn* spawn = lua_interface->GetSpawn(state);
  7949. if (!spawn) {
  7950. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7951. return 0;
  7952. }
  7953. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7954. return 1;
  7955. }
  7956. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7957. if (!lua_interface)
  7958. return 0;
  7959. Spawn* spawn = lua_interface->GetSpawn(state);
  7960. if (!spawn) {
  7961. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7962. return 0;
  7963. }
  7964. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7965. return 1;
  7966. }
  7967. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7968. if (!lua_interface)
  7969. return 0;
  7970. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7971. if (!spell) {
  7972. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7973. return 0;
  7974. }
  7975. lua_interface->SetStringValue(state, spell->spell->GetName());
  7976. return 1;
  7977. }
  7978. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7979. if (!lua_interface)
  7980. return 0;
  7981. Quest* quest = lua_interface->GetQuest(state);
  7982. if (!quest) {
  7983. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7984. return 0;
  7985. }
  7986. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7987. return 1;
  7988. }
  7989. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7990. if (!lua_interface)
  7991. return 0;
  7992. Quest* quest = lua_interface->GetQuest(state);
  7993. int32 flags = lua_interface->GetInt32Value(state, 2);
  7994. if (!quest) {
  7995. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7996. return 0;
  7997. }
  7998. quest->SetQuestFlags(flags);
  7999. return 0;
  8000. }
  8001. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8002. if (!lua_interface)
  8003. return 0;
  8004. Quest* quest = lua_interface->GetQuest(state);
  8005. Spawn* player = lua_interface->GetSpawn(state, 2);
  8006. int32 step = lua_interface->GetInt32Value(state, 3);
  8007. int32 duration = lua_interface->GetInt32Value(state, 4);
  8008. string action = lua_interface->GetStringValue(state, 5);
  8009. if (!quest) {
  8010. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8011. return 0;
  8012. }
  8013. if (!player) {
  8014. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8015. return 0;
  8016. }
  8017. if (!player->IsPlayer()) {
  8018. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8019. return 0;
  8020. }
  8021. if (step == 0) {
  8022. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8023. return 0;
  8024. }
  8025. if (duration == 0) {
  8026. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8027. return 0;
  8028. }
  8029. if (action.length() == 0) {
  8030. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8031. return 0;
  8032. }
  8033. Client* client = player->GetZone()->GetClientBySpawn(player);
  8034. if (!client) {
  8035. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8036. return 0;
  8037. }
  8038. quest->SetTimerStep(step);
  8039. quest->AddFailedAction(step, action);
  8040. quest->SetStepTimer(duration);
  8041. client->AddQuestTimer(quest->GetQuestID());
  8042. return 0;
  8043. }
  8044. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8045. if (!lua_interface)
  8046. return 0;
  8047. Quest* quest = lua_interface->GetQuest(state);
  8048. Spawn* player = lua_interface->GetSpawn(state, 2);
  8049. if (!quest) {
  8050. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8051. return 0;
  8052. }
  8053. if (!player) {
  8054. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8055. return 0;
  8056. }
  8057. if (!player->IsPlayer()) {
  8058. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8059. return 0;
  8060. }
  8061. Client* client = player->GetZone()->GetClientBySpawn(player);
  8062. if (!client) {
  8063. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8064. return 0;
  8065. }
  8066. quest->SetTimerStep(0);
  8067. quest->SetStepTimer(0);
  8068. client->RemoveQuestTimer(quest->GetQuestID());
  8069. return 0;
  8070. }
  8071. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8072. if (!lua_interface)
  8073. return 0;
  8074. Spawn* player = lua_interface->GetSpawn(state);
  8075. Quest* quest = lua_interface->GetQuest(state, 2);
  8076. int32 step = lua_interface->GetInt32Value(state, 3);
  8077. if (!player) {
  8078. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8079. return 0;
  8080. }
  8081. if (!player->IsPlayer()) {
  8082. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8083. return 0;
  8084. }
  8085. if (!quest) {
  8086. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8087. return 0;
  8088. }
  8089. if (step == 0) {
  8090. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8091. return 0;
  8092. }
  8093. Client* client = player->GetZone()->GetClientBySpawn(player);
  8094. if (!client) {
  8095. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8096. return 0;
  8097. }
  8098. if (quest->RemoveQuestStep(step, client)) {
  8099. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8100. client->GetCurrentZone()->SendQuestUpdates(client);
  8101. }
  8102. else
  8103. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8104. return 0;
  8105. }
  8106. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8107. if (!lua_interface)
  8108. return 0;
  8109. Quest* quest = lua_interface->GetQuest(state, 1);
  8110. int32 step = lua_interface->GetInt32Value(state, 2);
  8111. string desc = lua_interface->GetStringValue(state, 3);
  8112. string task_group = lua_interface->GetStringValue(state, 4);
  8113. if (!quest) {
  8114. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8115. return 0;
  8116. }
  8117. if (step == 0) {
  8118. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8119. return 0;
  8120. }
  8121. QuestStep* quest_step = quest->GetQuestStep(step);
  8122. if (!quest_step) {
  8123. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8124. return 0;
  8125. }
  8126. quest_step->SetStepProgress(0);
  8127. quest_step->SetTaskGroup(task_group);
  8128. quest_step->SetDescription(desc);
  8129. return 0;
  8130. }
  8131. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8132. if (!lua_interface)
  8133. return 0;
  8134. Quest* quest = lua_interface->GetQuest(state);
  8135. int32 step = lua_interface->GetInt32Value(state, 2);
  8136. string action = lua_interface->GetStringValue(state, 3);
  8137. if (!quest) {
  8138. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8139. return 0;
  8140. }
  8141. if (step == 0) {
  8142. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8143. return 0;
  8144. }
  8145. if (action.length() == 0) {
  8146. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8147. return 0;
  8148. }
  8149. quest->AddFailedAction(step, action);
  8150. return 0;
  8151. }
  8152. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8153. if (!lua_interface)
  8154. return 0;
  8155. Spawn* player = lua_interface->GetSpawn(state);
  8156. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8157. int32 step = lua_interface->GetInt32Value(state, 3);
  8158. if (!player) {
  8159. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8160. return 0;
  8161. }
  8162. if (!player->IsPlayer()) {
  8163. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8164. return 0;
  8165. }
  8166. if (quest_id == 0) {
  8167. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8168. return 0;
  8169. }
  8170. if (step == 0) {
  8171. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8172. return 0;
  8173. }
  8174. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8175. if (!quest) {
  8176. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8177. return 0;
  8178. }
  8179. quest->StepFailed(step);
  8180. return 0;
  8181. }
  8182. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8183. if (!lua_interface)
  8184. return 0;
  8185. Spawn* player = lua_interface->GetSpawn(state);
  8186. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8187. if (!player) {
  8188. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8189. return 0;
  8190. }
  8191. if (!player->IsPlayer()) {
  8192. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8193. return 0;
  8194. }
  8195. if (quest_id == 0) {
  8196. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8197. return 0;
  8198. }
  8199. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8200. if (!quest) {
  8201. lua_interface->SetInt32Value(state, 0);
  8202. return 1;
  8203. }
  8204. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8205. return 1;
  8206. }
  8207. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8208. if (!lua_interface)
  8209. return 0;
  8210. string name = lua_interface->GetStringValue(state);
  8211. string value = lua_interface->GetStringValue(state, 2);
  8212. string comment = lua_interface->GetStringValue(state, 3);
  8213. if (name.length() == 0) {
  8214. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8215. return 0;
  8216. }
  8217. if (value.length() == 0) {
  8218. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8219. return 0;
  8220. }
  8221. string varname = string("lua_").append(name);
  8222. Variable* var = variables.FindVariable(varname);
  8223. if (var)
  8224. var->SetValue(value.c_str());
  8225. else {
  8226. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8227. variables.AddVariable(var);
  8228. }
  8229. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8230. return 0;
  8231. }
  8232. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8233. if (!lua_interface)
  8234. return 0;
  8235. string name = lua_interface->GetStringValue(state);
  8236. if (name.length() == 0) {
  8237. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8238. return 0;
  8239. }
  8240. string varname = string("lua_").append(name);
  8241. Variable* var = variables.FindVariable(varname);
  8242. if (var)
  8243. lua_interface->SetStringValue(state, var->GetValue());
  8244. else
  8245. lua_interface->SetStringValue(state, "NULL");
  8246. return 1;
  8247. }
  8248. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8249. if (!lua_interface)
  8250. return 0;
  8251. Spawn* player = lua_interface->GetSpawn(state);
  8252. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8253. if (!player) {
  8254. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8255. return 0;
  8256. }
  8257. if (!player->IsPlayer()) {
  8258. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8259. return 0;
  8260. }
  8261. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8262. return 1;
  8263. }
  8264. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8265. if (!lua_interface)
  8266. return 0;
  8267. Spawn* player = lua_interface->GetSpawn(state);
  8268. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8269. if (!player) {
  8270. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8271. return 0;
  8272. }
  8273. if (!player->IsPlayer()) {
  8274. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8275. return 0;
  8276. }
  8277. Language* language = master_languages_list.GetLanguage(language_id);
  8278. if (language)
  8279. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8280. return 0;
  8281. }
  8282. int EQ2Emu_lua_IsNight(lua_State* state) {
  8283. if (!lua_interface)
  8284. return 0;
  8285. ZoneServer* zone = lua_interface->GetZone(state);
  8286. if (!zone) {
  8287. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8288. return 0;
  8289. }
  8290. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8291. return 1;
  8292. }
  8293. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8294. if (!lua_interface)
  8295. return 0;
  8296. Spawn* spawn = lua_interface->GetSpawn(state);
  8297. if (!spawn) {
  8298. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8299. return 0;
  8300. }
  8301. if (!spawn->IsWidget()) {
  8302. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8303. return 0;
  8304. }
  8305. ((Widget*)spawn)->SetMultiFloorLift(true);
  8306. if (spawn->GetZone())
  8307. spawn->GetZone()->AddTransportSpawn(spawn);
  8308. return 0;
  8309. }
  8310. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8311. if (!lua_interface)
  8312. return 0;
  8313. Spawn* player = lua_interface->GetSpawn(state);
  8314. int32 path = lua_interface->GetInt32Value(state, 2);
  8315. if (!player) {
  8316. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8317. return 0;
  8318. }
  8319. if (!player->IsPlayer()) {
  8320. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8321. return 0;
  8322. }
  8323. if (path == 0) {
  8324. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8325. return 0;
  8326. }
  8327. Client* client = player->GetZone()->GetClientBySpawn(player);
  8328. if (!client) {
  8329. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8330. return 0;
  8331. }
  8332. client->SendFlightAutoMount(path);
  8333. return 0;
  8334. }
  8335. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8336. if (!lua_interface)
  8337. return 0;
  8338. Spawn* player = lua_interface->GetSpawn(state);
  8339. if (!player) {
  8340. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8341. return 0;
  8342. }
  8343. if (!player->IsPlayer()) {
  8344. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8345. return 0;
  8346. }
  8347. Client* client = player->GetZone()->GetClientBySpawn(player);
  8348. if (!client) {
  8349. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8350. return 0;
  8351. }
  8352. client->EndAutoMount();
  8353. return 0;
  8354. }
  8355. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8356. if (!lua_interface)
  8357. return 0;
  8358. Spawn* player = lua_interface->GetSpawn(state);
  8359. if (!player) {
  8360. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8361. return 0;
  8362. }
  8363. if (!player->IsPlayer()) {
  8364. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8365. return 0;
  8366. }
  8367. Client* client = player->GetZone()->GetClientBySpawn(player);
  8368. if (!client) {
  8369. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8370. return 0;
  8371. }
  8372. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8373. return 1;
  8374. }
  8375. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8376. if (!lua_interface)
  8377. return 0;
  8378. Spawn* player = lua_interface->GetSpawn(state);
  8379. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8380. int32 value = lua_interface->GetInt32Value(state, 3);
  8381. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8382. if (!player) {
  8383. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8384. return 0;
  8385. }
  8386. if (!player->IsPlayer()) {
  8387. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8388. return 0;
  8389. }
  8390. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8391. return 0;
  8392. }
  8393. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8394. if (!lua_interface)
  8395. return 0;
  8396. Spawn* player = lua_interface->GetSpawn(state);
  8397. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8398. if (!player) {
  8399. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8400. return 0;
  8401. }
  8402. if (!player->IsPlayer()) {
  8403. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8404. return 0;
  8405. }
  8406. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8407. if (!hd)
  8408. return 0;
  8409. lua_interface->SetInt32Value(state, hd->Value);
  8410. lua_interface->SetInt32Value(state, hd->Value2);
  8411. return 2;
  8412. }
  8413. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8414. if (!lua_interface)
  8415. return 0;
  8416. Spawn* spawn = lua_interface->GetSpawn(state);
  8417. int32 grid = lua_interface->GetInt32Value(state, 2);
  8418. if (!spawn) {
  8419. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8420. return 0;
  8421. }
  8422. if (grid == 0) {
  8423. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8424. return 0;
  8425. }
  8426. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8427. return 0;
  8428. }
  8429. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8430. if (!lua_interface)
  8431. return 0;
  8432. Spawn* spawn = lua_interface->GetSpawn(state);
  8433. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8434. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8435. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8436. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8437. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8438. if (!spawn) {
  8439. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8440. return 0;
  8441. }
  8442. //Add this quest to the list of required quests for this spawn
  8443. spawn->SetRequiredHistory(event_id, value1, value2);
  8444. //If private spawn value set
  8445. if (private_spawn) {
  8446. //Set the spawn to be private when not granted access via history
  8447. spawn->AddAllowAccessSpawn(spawn);
  8448. spawn->SetPrivateQuestSpawn(true);
  8449. }
  8450. //This value will override vis_flags in the vis packet
  8451. if (flag_override > 0)
  8452. spawn->SetQuestsRequiredOverride(flag_override);
  8453. return 0;
  8454. }
  8455. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8456. if (!lua_interface)
  8457. return 0;
  8458. Spawn* player = lua_interface->GetSpawn(state);
  8459. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8460. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8461. if (!player) {
  8462. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8463. return 0;
  8464. }
  8465. if (!player->IsPlayer()) {
  8466. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8467. return 0;
  8468. }
  8469. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8470. return 1;
  8471. }
  8472. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8473. if (!lua_interface)
  8474. return 0;
  8475. Spawn* player = lua_interface->GetSpawn(state);
  8476. int8 level = lua_interface->GetInt8Value(state, 2);
  8477. if (!player) {
  8478. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8479. return 0;
  8480. }
  8481. if (!player->IsPlayer()) {
  8482. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8483. return 0;
  8484. }
  8485. if (level == 0) {
  8486. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8487. return 0;
  8488. }
  8489. Client* client = player->GetZone()->GetClientBySpawn(player);
  8490. if (!client) {
  8491. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8492. return 0;
  8493. }
  8494. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8495. return 0;
  8496. }
  8497. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8498. if (!lua_interface)
  8499. return 0;
  8500. Spawn* player = lua_interface->GetSpawn(state);
  8501. int32 amount = lua_interface->GetInt32Value(state, 2);
  8502. if (!player) {
  8503. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8504. return 0;
  8505. }
  8506. if (!player->IsPlayer()) {
  8507. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8508. return 0;
  8509. }
  8510. if (amount == 0) {
  8511. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8512. return 0;
  8513. }
  8514. ((Player*)player)->AddCoins(amount);
  8515. return 0;
  8516. }
  8517. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8518. if (!lua_interface)
  8519. return 0;
  8520. Spawn* player = lua_interface->GetSpawn(state);
  8521. int32 amount = lua_interface->GetInt32Value(state, 2);
  8522. if (!player) {
  8523. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8524. return 0;
  8525. }
  8526. if (!player->IsPlayer()) {
  8527. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8528. return 0;
  8529. }
  8530. if (amount == 0) {
  8531. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8532. return 0;
  8533. }
  8534. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8535. return 1;
  8536. }
  8537. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8538. if (!lua_interface)
  8539. return 0;
  8540. ZoneServer* zone = lua_interface->GetZone(state);
  8541. if (!zone) {
  8542. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8543. return 0;
  8544. }
  8545. vector<Entity*> players = zone->GetPlayers();
  8546. if (players.size() == 0)
  8547. return 0;
  8548. lua_createtable(state, players.size(), 0);
  8549. int newTable = lua_gettop(state);
  8550. for (int32 i = 0; i < players.size(); i++) {
  8551. lua_interface->SetSpawnValue(state, players.at(i));
  8552. lua_rawseti(state, newTable, i + 1);
  8553. }
  8554. return 1;
  8555. }
  8556. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8557. if (!lua_interface)
  8558. return 0;
  8559. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8560. if (!zone) {
  8561. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8562. return 0;
  8563. }
  8564. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8565. //Map of <placement_id, location_id>
  8566. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8567. map<int32, int32>::iterator itr;
  8568. vector<Spawn*> group;
  8569. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8570. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8571. if (!location) {
  8572. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8573. return 0;
  8574. }
  8575. Spawn* spawn = 0;
  8576. if (location->entities[0]) {
  8577. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8578. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8579. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8580. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8581. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8582. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8583. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8584. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8585. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8586. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8587. if (spawn) {
  8588. const char* script = 0;
  8589. for (int x = 0; x < 3; x++) {
  8590. switch (x) {
  8591. case 0:
  8592. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8593. break;
  8594. case 1:
  8595. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8596. break;
  8597. case 2:
  8598. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8599. break;
  8600. }
  8601. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8602. spawn->SetSpawnScript(string(script));
  8603. break;
  8604. }
  8605. }
  8606. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8607. lua_interface->SetSpawnValue(state, spawn);
  8608. group.push_back(spawn);
  8609. }
  8610. else {
  8611. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8612. safe_delete(spawn);
  8613. }
  8614. }
  8615. }
  8616. if (!group.empty()) {
  8617. lua_createtable(state, group.size(), 0);
  8618. int newTable = lua_gettop(state);
  8619. for (int32 i = 0; i < group.size(); i++) {
  8620. lua_interface->SetSpawnValue(state, group[i]);
  8621. lua_rawseti(state, newTable, i + 1);
  8622. }
  8623. }
  8624. else
  8625. lua_pushnil(state);
  8626. return 1;
  8627. }
  8628. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8629. if (!lua_interface)
  8630. return 0;
  8631. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8632. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8633. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8634. if (!spawn) {
  8635. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8636. return 0;
  8637. }
  8638. if (anim_id == 0) {
  8639. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8640. return 0;
  8641. }
  8642. if (leeway == 0)
  8643. leeway = 5000;
  8644. spawn->SetSpawnAnim(anim_id);
  8645. spawn->SetSpawnAnimLeeway(leeway);
  8646. return 0;
  8647. }
  8648. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8649. if (!lua_interface)
  8650. return 0;
  8651. Spawn* player = lua_interface->GetSpawn(state);
  8652. if (!player) {
  8653. return 0;
  8654. }
  8655. Client* client = player->GetZone()->GetClientBySpawn(player);
  8656. if (!client) {
  8657. return 0;
  8658. }
  8659. lua_interface->SetInt32Value(state, client->GetVersion());
  8660. return 1;
  8661. }
  8662. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8663. if (!lua_interface)
  8664. return 0;
  8665. Item* item = lua_interface->GetItem(state);
  8666. if (!item) {
  8667. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8668. return 0;
  8669. }
  8670. lua_interface->SetInt32Value(state, item->details.item_id);
  8671. return 1;
  8672. }
  8673. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8674. if (!lua_interface)
  8675. return 0;
  8676. Spawn* spawn = lua_interface->GetSpawn(state);
  8677. if (!spawn) {
  8678. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8679. return 0;
  8680. }
  8681. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8682. return 1;
  8683. }
  8684. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8685. if (!lua_interface)
  8686. return 0;
  8687. Spawn* spawn = lua_interface->GetSpawn(state);
  8688. if (!spawn) {
  8689. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8690. return 0;
  8691. }
  8692. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8693. return 1;
  8694. }
  8695. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8696. if (!lua_interface)
  8697. return 0;
  8698. Spawn* spawn = lua_interface->GetSpawn(state);
  8699. if (!spawn) {
  8700. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8701. return 0;
  8702. }
  8703. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8704. return 1;
  8705. }
  8706. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8707. if (!lua_interface)
  8708. return 0;
  8709. Spawn* spawn = lua_interface->GetSpawn(state);
  8710. if (!spawn) {
  8711. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8712. return 0;
  8713. }
  8714. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8715. return 1;
  8716. }
  8717. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8718. if (!lua_interface)
  8719. return 0;
  8720. Spawn* spawn = lua_interface->GetSpawn(state);
  8721. float pct = lua_interface->GetFloatValue(state, 2);
  8722. if (!spawn) {
  8723. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8724. return 0;
  8725. }
  8726. if (pct == 0) {
  8727. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8728. return 0;
  8729. }
  8730. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8731. lua_interface->SetInt32Value(state, amount);
  8732. return 1;
  8733. }
  8734. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8735. if (!lua_interface)
  8736. return 0;
  8737. Spawn* spawn = lua_interface->GetSpawn(state);
  8738. float pct = lua_interface->GetFloatValue(state, 2);
  8739. if (!spawn) {
  8740. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8741. return 0;
  8742. }
  8743. if (pct == 0) {
  8744. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8745. return 0;
  8746. }
  8747. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8748. lua_interface->SetInt32Value(state, amount);
  8749. return 1;
  8750. }
  8751. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8752. if (!lua_interface)
  8753. return 0;
  8754. Spawn* spawn = lua_interface->GetSpawn(state);
  8755. if (!spawn) {
  8756. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8757. return 0;
  8758. }
  8759. if (!spawn->IsPlayer()) {
  8760. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8761. return 0;
  8762. }
  8763. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8764. return 1;
  8765. }
  8766. int EQ2Emu_lua_Evac(lua_State* state) {
  8767. if (!lua_interface)
  8768. return 0;
  8769. Spawn* target = lua_interface->GetSpawn(state);
  8770. if (target) {
  8771. float x = target->GetZone()->GetSafeX();
  8772. float y = target->GetZone()->GetSafeY();
  8773. float z = target->GetZone()->GetSafeZ();
  8774. float h = target->GetZone()->GetSafeHeading();
  8775. target->SetX(x);
  8776. target->SetY(y);
  8777. target->SetZ(z);
  8778. target->SetHeading(h);
  8779. target->SetSpawnOrigX(target->GetX());
  8780. target->SetSpawnOrigY(target->GetY());
  8781. target->SetSpawnOrigZ(target->GetZ());
  8782. target->SetSpawnOrigHeading(target->GetHeading());
  8783. if (target->IsPlayer()) {
  8784. Client* client = target->GetZone()->GetClientBySpawn(target);
  8785. if (client) {
  8786. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8787. if (packet)
  8788. {
  8789. packet->setDataByName("x", x);
  8790. packet->setDataByName("y", y);
  8791. packet->setDataByName("z", z);
  8792. client->QueuePacket(packet->serialize());
  8793. safe_delete(packet);
  8794. }
  8795. }
  8796. }
  8797. }
  8798. else {
  8799. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8800. ZoneServer* zone = spell->caster->GetZone();
  8801. float x = spell->caster->GetZone()->GetSafeX();
  8802. float y = spell->caster->GetZone()->GetSafeY();
  8803. float z = spell->caster->GetZone()->GetSafeZ();
  8804. float h = spell->caster->GetZone()->GetSafeHeading();
  8805. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8806. for (int32 i = 0; i < spell->targets.size(); i++) {
  8807. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8808. if (!target2)
  8809. continue;
  8810. target2->SetX(x);
  8811. target2->SetY(y);
  8812. target2->SetZ(z);
  8813. target2->SetHeading(h);
  8814. target2->SetSpawnOrigX(target2->GetX());
  8815. target2->SetSpawnOrigY(target2->GetY());
  8816. target2->SetSpawnOrigZ(target2->GetZ());
  8817. target2->SetSpawnOrigHeading(target2->GetHeading());
  8818. if (target2->IsPlayer()) {
  8819. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8820. if (client) {
  8821. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8822. if (packet)
  8823. {
  8824. client->SetReloadingZone(true);
  8825. packet->setDataByName("x", x);
  8826. packet->setDataByName("y", y);
  8827. packet->setDataByName("z", z);
  8828. client->QueuePacket(packet->serialize());
  8829. safe_delete(packet);
  8830. }
  8831. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8832. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8833. }
  8834. }
  8835. }
  8836. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8837. }
  8838. return 0;
  8839. }
  8840. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8841. if (!lua_interface)
  8842. return 0;
  8843. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8844. if (!luaspell) {
  8845. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8846. return 0;
  8847. }
  8848. int8 tier = luaspell->spell->GetSpellTier();
  8849. lua_interface->SetInt32Value(state, tier);
  8850. return 1;
  8851. }
  8852. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8853. if (!lua_interface)
  8854. return 0;
  8855. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8856. if (!luaspell) {
  8857. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8858. return 0;
  8859. }
  8860. int32 spell_id = luaspell->spell->GetSpellID();
  8861. lua_interface->SetInt32Value(state, spell_id);
  8862. return 1;
  8863. }
  8864. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8865. if (!lua_interface)
  8866. return 0;
  8867. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8868. if (!spawn) {
  8869. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8870. return 0;
  8871. }
  8872. if (!spawn->IsPlayer()) {
  8873. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8874. return 0;
  8875. }
  8876. ZoneServer* zone = spawn->GetZone();
  8877. if (!zone) {
  8878. return 0;
  8879. }
  8880. Client* client = zone->GetClientBySpawn(spawn);
  8881. if (!client) {
  8882. return 0;
  8883. }
  8884. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8885. return 0;
  8886. }
  8887. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8888. if (!lua_interface)
  8889. return 0;
  8890. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8891. if (!spawn) {
  8892. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8893. return 0;
  8894. }
  8895. if (!spawn->IsPlayer()) {
  8896. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8897. return 0;
  8898. }
  8899. ZoneServer* zone = spawn->GetZone();
  8900. if (!zone) {
  8901. return 0;
  8902. }
  8903. Client* client = zone->GetClientBySpawn(spawn);
  8904. if (!client) {
  8905. return 0;
  8906. }
  8907. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8908. return 0;
  8909. }
  8910. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8911. if (!lua_interface)
  8912. return 0;
  8913. Spawn* caster = lua_interface->GetSpawn(state);
  8914. Spawn* target = lua_interface->GetSpawn(state, 2);
  8915. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8916. string spell_name = lua_interface->GetStringValue(state, 4);
  8917. if (!caster) {
  8918. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8919. return 0;
  8920. }
  8921. if (!caster->IsEntity()) {
  8922. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8923. return 0;
  8924. }
  8925. if (!target) {
  8926. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8927. return 0;
  8928. }
  8929. if (!target->IsEntity()) {
  8930. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8931. return 0;
  8932. }
  8933. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8934. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8935. return 0;
  8936. }
  8937. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8938. if (!lua_interface)
  8939. return 0;
  8940. Spawn* player = lua_interface->GetSpawn(state);
  8941. int32 amount = lua_interface->GetInt32Value(state, 2);
  8942. if (player && player->IsPlayer() && amount > 0) {
  8943. ((Player*)player)->AddXP(amount);
  8944. ((Player*)player)->SetCharSheetChanged(true);
  8945. Client* client = player->GetZone()->GetClientBySpawn(player);
  8946. if (client) {
  8947. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8948. }
  8949. }
  8950. return 0;
  8951. }
  8952. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8953. if (!lua_interface)
  8954. return 0;
  8955. Spawn* player = lua_interface->GetSpawn(state);
  8956. int8 type = lua_interface->GetInt8Value(state, 2);
  8957. string text = lua_interface->GetStringValue(state, 3);
  8958. Client* client = 0;
  8959. if (player && player->IsPlayer())
  8960. client = player->GetZone()->GetClientBySpawn(player);
  8961. if (!client || text.length() == 0) {
  8962. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8963. return 0;
  8964. }
  8965. client->SimpleMessage(type, text.c_str());
  8966. return 0;
  8967. }
  8968. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8969. if (!lua_interface)
  8970. return 0;
  8971. Spawn* player = lua_interface->GetSpawn(state);
  8972. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8973. Client* client = 0;
  8974. if (player && player->IsPlayer())
  8975. client = player->GetZone()->GetClientBySpawn(player);
  8976. if (!client || !spawn) {
  8977. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8978. return 0;
  8979. }
  8980. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8981. if (!items) {
  8982. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8983. return 0;
  8984. }
  8985. client->Loot(spawn->GetLootCoins(), items, spawn);
  8986. return 0;
  8987. }
  8988. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8989. if (!lua_interface)
  8990. return 0;
  8991. Spawn* spawnref = lua_interface->GetSpawn(state);
  8992. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8993. if (spawn_id > 0 && spawnref) {
  8994. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8995. if (spawns.size() == 0) {
  8996. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8997. return 0;
  8998. }
  8999. Spawn* spawn = 0;
  9000. int16 index = MakeRandomInt(0, spawns.size());
  9001. if (index >= spawns.size() || index < 0)
  9002. index = 0;
  9003. spawn = spawns[index];
  9004. lua_interface->SetSpawnValue(state, spawn);
  9005. return 1;
  9006. }
  9007. else {
  9008. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9009. }
  9010. return 0;
  9011. }
  9012. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9013. Spawn* player = lua_interface->GetSpawn(state);
  9014. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9015. string name = lua_interface->GetStringValue(state, 3);
  9016. float distance = lua_interface->GetFloatValue(state, 4);
  9017. string command = lua_interface->GetStringValue(state, 5);
  9018. string error_text = lua_interface->GetStringValue(state, 6);
  9019. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9020. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9021. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9022. if (distance == 0)
  9023. distance = 10.0f;
  9024. if (command.length() == 0)
  9025. command = name;
  9026. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9027. if (spawns.size() == 0) {
  9028. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9029. return 0;
  9030. }
  9031. Spawn* spawn = 0;
  9032. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9033. spawn = *itr;
  9034. if (spawn) {
  9035. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9036. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9037. }
  9038. }
  9039. }
  9040. return 0;
  9041. }
  9042. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9043. if (!lua_interface)
  9044. return 0;
  9045. Client* client = 0;
  9046. Spawn* player = lua_interface->GetSpawn(state);
  9047. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9048. if (player && player->IsPlayer() && player->GetZone())
  9049. client = player->GetZone()->GetClientBySpawn(player);
  9050. else{
  9051. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9052. return 0;
  9053. }
  9054. if (client) {
  9055. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9056. if (packet) {
  9057. packet->setDataByName("goal_num", goal_num);
  9058. client->QueuePacket(packet->serialize());
  9059. safe_delete(packet);
  9060. }
  9061. }
  9062. return 0;
  9063. }
  9064. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9065. if (!lua_interface)
  9066. return 0;
  9067. Client* client = 0;
  9068. Spawn* player = lua_interface->GetSpawn(state);
  9069. if (player && player->IsPlayer() && player->GetZone())
  9070. client = player->GetZone()->GetClientBySpawn(player);
  9071. else {
  9072. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9073. return 0;
  9074. }
  9075. if (client) {
  9076. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9077. }
  9078. return 0;
  9079. }
  9080. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9081. if (!lua_interface)
  9082. return 0;
  9083. Client* client = 0;
  9084. Spawn* player = lua_interface->GetSpawn(state);
  9085. float duration = lua_interface->GetFloatValue(state, 2);
  9086. string text = lua_interface->GetStringValue(state, 3);
  9087. string voice = lua_interface->GetStringValue(state, 4);
  9088. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9089. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9090. string signal = lua_interface->GetStringValue(state, 7);
  9091. string goal1 = lua_interface->GetStringValue(state, 8);
  9092. string task1 = lua_interface->GetStringValue(state, 9);
  9093. string goal2 = lua_interface->GetStringValue(state, 10);
  9094. string task2 = lua_interface->GetStringValue(state, 11);
  9095. string goal3 = lua_interface->GetStringValue(state, 12);
  9096. string task3 = lua_interface->GetStringValue(state, 13);
  9097. string goal4 = lua_interface->GetStringValue(state, 14);
  9098. string task4 = lua_interface->GetStringValue(state, 15);
  9099. if (!player) {
  9100. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9101. return 0;
  9102. }
  9103. if (!player->IsPlayer()) {
  9104. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9105. return 0;
  9106. }
  9107. else
  9108. client = ((Player*)player)->GetClient();
  9109. if (!client) {
  9110. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9111. return 0;
  9112. }
  9113. if (text.length() == 0) {
  9114. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9115. return 0;
  9116. }
  9117. if (duration >= 0 && duration < 2)
  9118. duration = 2;
  9119. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9120. if (packet) {
  9121. packet->setDataByName("open_seconds_max", duration);
  9122. packet->setDataByName("text", text.c_str());
  9123. packet->setDataByName("voice", voice.c_str());
  9124. int8 num_goals = 1;
  9125. if (task2.length() > 0)
  9126. num_goals++;
  9127. if (task3.length() > 0)
  9128. num_goals++;
  9129. if (task4.length() > 0)
  9130. num_goals++;
  9131. packet->setArrayLengthByName("num_goals", num_goals);
  9132. for (int8 i = 0; i < num_goals; i++) {
  9133. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9134. }
  9135. if (goal1.length() > 0)
  9136. packet->setArrayDataByName("goal_text", goal1.c_str());
  9137. if (goal2.length() > 0)
  9138. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9139. if (goal3.length() > 0)
  9140. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9141. if (goal4.length() > 0)
  9142. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9143. packet->setSubArrayDataByName("task_text", task1.c_str());
  9144. if (task2.length() > 0)
  9145. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9146. if (task3.length() > 0)
  9147. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9148. if (task4.length() > 0)
  9149. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9150. packet->setDataByName("complete_sound", "click");
  9151. packet->setDataByName("signal", signal.c_str());
  9152. packet->setDataByName("voice_key1", voice_key1);
  9153. packet->setDataByName("voice_key2", voice_key2);
  9154. client->QueuePacket(packet->serialize());
  9155. safe_delete(packet);
  9156. }
  9157. return 0;
  9158. }
  9159. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9160. if (!lua_interface)
  9161. return 0;
  9162. Client* client = 0;
  9163. Spawn* player = lua_interface->GetSpawn(state);
  9164. string window = lua_interface->GetStringValue(state, 2);
  9165. int8 show = lua_interface->GetInt8Value(state, 3);
  9166. if (!player) {
  9167. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9168. return 0;
  9169. }
  9170. if (!player->IsPlayer()) {
  9171. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9172. return 0;
  9173. }
  9174. else
  9175. client = ((Player*)player)->GetClient();
  9176. if (!client) {
  9177. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9178. return 0;
  9179. }
  9180. if (window.length() == 0) {
  9181. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9182. return 0;
  9183. }
  9184. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9185. if (packet) {
  9186. packet->setDataByName("window", window.c_str());
  9187. packet->setDataByName("show", show);
  9188. client->QueuePacket(packet->serialize());
  9189. safe_delete(packet);
  9190. }
  9191. return 0;
  9192. }
  9193. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9194. //See GameEvents.txt for options that can be used for this function
  9195. if (!lua_interface)
  9196. return 0;
  9197. Client* client = 0;
  9198. Spawn* player = lua_interface->GetSpawn(state);
  9199. string event_name = lua_interface->GetStringValue(state, 2);
  9200. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9201. if (!player || !player->IsPlayer()) {
  9202. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9203. return 0;
  9204. }
  9205. if (player->GetZone())
  9206. client = player->GetZone()->GetClientBySpawn(player);
  9207. if (!client) {
  9208. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9209. return 0;
  9210. }
  9211. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9212. if (packet) {
  9213. packet->setDataByName("event_name", event_name.c_str());
  9214. packet->setDataByName("enabled", enabled);
  9215. client->QueuePacket(packet->serialize());
  9216. safe_delete(packet);
  9217. }
  9218. return 0;
  9219. }
  9220. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9221. if (!lua_interface)
  9222. return 0;
  9223. Spawn* player = lua_interface->GetSpawn(state);
  9224. if (player && player->IsPlayer()) {
  9225. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9226. return 1;
  9227. }
  9228. return 0;
  9229. }
  9230. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9231. if (!lua_interface)
  9232. return 0;
  9233. Spawn* player = lua_interface->GetSpawn(state);
  9234. int8 step = lua_interface->GetInt8Value(state, 2);
  9235. if (player && player->IsPlayer() && step > 0) {
  9236. ((Player*)player)->SetTutorialStep(step);
  9237. }
  9238. return 0;
  9239. }
  9240. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9241. if (!lua_interface)
  9242. return 0;
  9243. Client* client = 0;
  9244. Spawn* player = lua_interface->GetSpawn(state);
  9245. string window = lua_interface->GetStringValue(state, 2);
  9246. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9247. if (!player) {
  9248. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9249. return 0;
  9250. }
  9251. if (!player->IsPlayer()) {
  9252. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9253. return 0;
  9254. }
  9255. else
  9256. client = ((Player*)player)->GetClient();
  9257. if (!client) {
  9258. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9259. return 0;
  9260. }
  9261. if (window.length() == 0) {
  9262. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9263. return 0;
  9264. }
  9265. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9266. if (packet) {
  9267. packet->setDataByName("window", window.c_str());
  9268. packet->setDataByName("flash_seconds", flash_seconds);
  9269. client->QueuePacket(packet->serialize());
  9270. safe_delete(packet);
  9271. }
  9272. return 0;
  9273. }
  9274. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9275. if (!lua_interface)
  9276. return 0;
  9277. Spawn* spawn = lua_interface->GetSpawn(state);
  9278. Spawn* target = lua_interface->GetSpawn(state, 2);
  9279. if (spawn && target)
  9280. return spawn->CheckLoS(target);
  9281. return 0;
  9282. }
  9283. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9284. if (!lua_interface)
  9285. return 0;
  9286. Spawn* spawn = lua_interface->GetSpawn(state);
  9287. float x = lua_interface->GetFloatValue(state, 2);
  9288. float y = lua_interface->GetFloatValue(state, 3);
  9289. float z = lua_interface->GetFloatValue(state, 4);
  9290. if (spawn)
  9291. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9292. return 0;
  9293. }
  9294. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9295. if (!lua_interface)
  9296. return 0;
  9297. ZoneServer* zone = lua_interface->GetZone(state);
  9298. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9299. if (zone)
  9300. zone->SetExpansionFlag(xpackFlag);
  9301. return 0;
  9302. }
  9303. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9304. if (!lua_interface)
  9305. return 0;
  9306. ZoneServer* zone = lua_interface->GetZone(state);
  9307. if (zone) {
  9308. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9309. return 1;
  9310. }
  9311. return 0;
  9312. }
  9313. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9314. if (!lua_interface)
  9315. return 0;
  9316. ZoneServer* zone = lua_interface->GetZone(state);
  9317. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9318. if (zone)
  9319. zone->SetHolidayFlag(holidayFlag);
  9320. return 0;
  9321. }
  9322. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9323. if (!lua_interface)
  9324. return 0;
  9325. ZoneServer* zone = lua_interface->GetZone(state);
  9326. if (zone) {
  9327. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9328. return 1;
  9329. }
  9330. return 0;
  9331. }
  9332. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9333. if (!lua_interface)
  9334. return 0;
  9335. Spawn* spawn = lua_interface->GetSpawn(state);
  9336. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9337. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9338. float distance = lua_interface->GetFloatValue(state, 4);
  9339. string in_range_function = lua_interface->GetStringValue(state, 5);
  9340. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9341. if (spawn && distance > 0 && in_range_function.length() > 0)
  9342. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9343. return 0;
  9344. }
  9345. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9346. if (!lua_interface)
  9347. return 0;
  9348. Spawn* spawn = lua_interface->GetSpawn(state);
  9349. Spawn* target = lua_interface->GetSpawn(state, 2);
  9350. if (spawn && target)
  9351. {
  9352. if (spawn->IsPlayer() && target->IsEntity())
  9353. {
  9354. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9355. return 1;
  9356. }
  9357. else if (spawn->IsEntity() && target->IsEntity())
  9358. {
  9359. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9360. return 1;
  9361. }
  9362. }
  9363. return 0;
  9364. }
  9365. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9366. if (!lua_interface)
  9367. return 0;
  9368. Spawn* spawn = lua_interface->GetSpawn(state);
  9369. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9370. if (spawn && spawn->IsEntity())
  9371. {
  9372. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9373. if (spawn->IsPlayer())
  9374. {
  9375. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9376. if (client)
  9377. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9378. }
  9379. }
  9380. return 0;
  9381. }
  9382. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9383. if (!lua_interface)
  9384. return 0;
  9385. Spawn* spawn = lua_interface->GetSpawn(state);
  9386. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9387. if (spawn && spawn->IsEntity())
  9388. {
  9389. ((Entity*)spawn)->SetSeeHideSpell(val);
  9390. if (spawn->IsPlayer())
  9391. {
  9392. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9393. if (client)
  9394. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9395. }
  9396. }
  9397. return 0;
  9398. }
  9399. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9400. {
  9401. if (!lua_interface)
  9402. return 0;
  9403. Spawn* player = lua_interface->GetSpawn(state);
  9404. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9405. string command = lua_interface->GetStringValue(state, 3);
  9406. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9407. lua_interface->ResetFunctionStack(state);
  9408. if (spawn && player && player->IsPlayer())
  9409. {
  9410. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9411. bool res = false;
  9412. if (cmd)
  9413. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9414. lua_interface->SetBooleanValue(state, res);
  9415. return 1;
  9416. }
  9417. return 0;
  9418. }
  9419. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9420. {
  9421. if (!lua_interface)
  9422. return 0;
  9423. Spawn* spawn = lua_interface->GetSpawn(state);
  9424. int32 charID = lua_interface->GetInt32Value(state, 2);
  9425. string command = lua_interface->GetStringValue(state, 3);
  9426. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9427. lua_interface->ResetFunctionStack(state);
  9428. if (spawn && charID)
  9429. {
  9430. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9431. bool res = false;
  9432. if (cmd)
  9433. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9434. lua_interface->SetBooleanValue(state, res);
  9435. return 1;
  9436. }
  9437. return 0;
  9438. }
  9439. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9440. {
  9441. if (!lua_interface)
  9442. return 0;
  9443. Spawn* spawn = lua_interface->GetSpawn(state);
  9444. string command = lua_interface->GetStringValue(state, 2);
  9445. lua_interface->ResetFunctionStack(state);
  9446. if (spawn && command.length() > 0)
  9447. spawn->RemovePrimaryEntityCommand(command.c_str());
  9448. return 0;
  9449. }
  9450. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9451. if (!lua_interface)
  9452. return 0;
  9453. Spawn* spawn = lua_interface->GetSpawn(state);
  9454. float distance = lua_interface->GetFloatValue(state, 2);
  9455. string command = lua_interface->GetStringValue(state, 3);
  9456. Spawn* player = lua_interface->GetSpawn(state, 4);
  9457. lua_interface->ResetFunctionStack(state);
  9458. if (spawn) {
  9459. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9460. }
  9461. return 0;
  9462. }
  9463. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9464. if (!lua_interface)
  9465. return 0;
  9466. Spawn* spawn = lua_interface->GetSpawn(state);
  9467. Spawn* player = lua_interface->GetSpawn(state, 2);
  9468. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9469. lua_interface->ResetFunctionStack(state);
  9470. if (spawn && player && transport_id && player->IsPlayer()) {
  9471. Client* client = 0;
  9472. if (player && player->IsPlayer())
  9473. client = player->GetZone()->GetClientBySpawn(player);
  9474. if (!client)
  9475. return 0;
  9476. vector<TransportDestination*> destinations;
  9477. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9478. if (destinations.size())
  9479. {
  9480. client->SetTemporaryTransportID(transport_id);
  9481. client->ProcessTeleport(spawn, &destinations, transport_id);
  9482. }
  9483. else
  9484. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9485. }
  9486. return 0;
  9487. }
  9488. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9489. if (!lua_interface)
  9490. return 0;
  9491. Spawn* player = lua_interface->GetSpawn(state);
  9492. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9493. lua_interface->ResetFunctionStack(state);
  9494. if (player && player->IsPlayer()) {
  9495. Client* client = 0;
  9496. if (player && player->IsPlayer())
  9497. client = player->GetZone()->GetClientBySpawn(player);
  9498. if (!client)
  9499. return 0;
  9500. client->SetTemporaryTransportID(transport_id);
  9501. }
  9502. return 0;
  9503. }
  9504. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9505. if (!lua_interface)
  9506. return 0;
  9507. Spawn* player = lua_interface->GetSpawn(state);
  9508. lua_interface->ResetFunctionStack(state);
  9509. if (player && player->IsPlayer()) {
  9510. Client* client = 0;
  9511. if (player && player->IsPlayer())
  9512. client = player->GetZone()->GetClientBySpawn(player);
  9513. if (!client)
  9514. return 0;
  9515. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9516. return 1;
  9517. }
  9518. return 0;
  9519. }
  9520. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9521. if (!lua_interface)
  9522. return 0;
  9523. Spawn* spawn = lua_interface->GetSpawn(state);
  9524. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9525. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9526. if (!spawn) {
  9527. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9528. return 0;
  9529. }
  9530. if (!spawn->IsEntity()) {
  9531. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9532. return 0;
  9533. }
  9534. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9535. {
  9536. 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);
  9537. return 0;
  9538. }
  9539. lua_interface->ResetFunctionStack(state);
  9540. if (spell && spell->targets.size() > 0) {
  9541. ZoneServer* zone = spell->caster->GetZone();
  9542. for (int8 i = 0; i < spell->targets.size(); i++) {
  9543. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9544. if (target->IsEntity()) {
  9545. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9546. if (target->IsPlayer())
  9547. ((Player*)target)->SetCharSheetChanged(true);
  9548. }
  9549. }
  9550. }
  9551. else {
  9552. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9553. if (spawn->IsPlayer())
  9554. ((Player*)spawn)->SetCharSheetChanged(true);
  9555. }
  9556. return 0;
  9557. }
  9558. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9559. if (!lua_interface)
  9560. return 0;
  9561. Spawn* spawn = lua_interface->GetSpawn(state);
  9562. lua_interface->ResetFunctionStack(state);
  9563. if (!spawn) {
  9564. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9565. return 0;
  9566. }
  9567. if (!spawn->IsEntity()) {
  9568. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9569. return 0;
  9570. }
  9571. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9572. return 1;
  9573. }
  9574. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9575. if (!lua_interface)
  9576. return 0;
  9577. int32 spell_id = lua_interface->GetInt32Value(state);
  9578. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9579. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9580. if (spell_id > 0) {
  9581. if (spell_tier == 0)
  9582. spell_tier = 1;
  9583. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9584. LuaSpell* lua_spell = 0;
  9585. if(custom_lua_script.size() > 0)
  9586. {
  9587. // attempt to load the custom script since it isn't already loaded
  9588. // we will re-obtain the lua_spell further below
  9589. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9590. {
  9591. 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());
  9592. lua_interface->LoadLuaSpell(custom_lua_script);
  9593. }
  9594. }
  9595. else
  9596. custom_lua_script = spell->GetSpellData()->lua_script;
  9597. if (!lua_spell && lua_interface)
  9598. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9599. if (!lua_spell)
  9600. {
  9601. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9602. return 0;
  9603. }
  9604. lua_spell->spell = new Spell(spell);
  9605. lua_interface->AddCustomSpell(lua_spell);
  9606. lua_interface->SetSpellValue(state, lua_spell);
  9607. return 1;
  9608. }
  9609. return 0;
  9610. }
  9611. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9612. if (!lua_interface)
  9613. return 0;
  9614. LuaSpell* spell = lua_interface->GetSpell(state);
  9615. string field = lua_interface->GetStringValue(state, 2);
  9616. if (!spell) {
  9617. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9618. return 0;
  9619. }
  9620. if (!spell->spell || !spell->spell->GetSpellData()) {
  9621. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9622. return 0;
  9623. }
  9624. boost::to_lower(field);
  9625. return spell->spell->GetSpellData(state, field);
  9626. }
  9627. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9628. if (!lua_interface)
  9629. return 0;
  9630. LuaSpell* spell = lua_interface->GetSpell(state);
  9631. string field = lua_interface->GetStringValue(state, 2);
  9632. int8 fieldArg = 3; // field value after the initial set
  9633. if (!spell) {
  9634. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9635. return 0;
  9636. }
  9637. if (!spell->spell || !spell->spell->GetSpellData()) {
  9638. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9639. return 0;
  9640. }
  9641. boost::to_lower(field);
  9642. bool valSet = false;
  9643. spell->spell->SetSpellData(state, field, fieldArg);
  9644. return valSet;
  9645. }
  9646. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9647. if (!lua_interface)
  9648. return 0;
  9649. LuaSpell* spell = lua_interface->GetSpell(state);
  9650. int8 idx = lua_interface->GetInt32Value(state, 2);
  9651. if (!spell) {
  9652. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9653. return 0;
  9654. }
  9655. if (!spell->spell || !spell->spell->GetSpellData()) {
  9656. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9657. return 0;
  9658. }
  9659. if (spell->spell->lua_data.size() <= idx)
  9660. {
  9661. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9662. return 0;
  9663. }
  9664. bool setVal = true;
  9665. LUAData* data = spell->spell->lua_data[idx];
  9666. switch (data->type)
  9667. {
  9668. case 0:
  9669. {
  9670. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9671. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9672. data->int_value = value;
  9673. data->int_value2 = value2;
  9674. break;
  9675. }
  9676. case 1:
  9677. {
  9678. float value = lua_interface->GetFloatValue(state, 3);
  9679. float value2 = lua_interface->GetFloatValue(state, 4);
  9680. data->float_value = value;
  9681. data->float_value2 = value2;
  9682. break;
  9683. }
  9684. case 2:
  9685. {
  9686. bool value = lua_interface->GetBooleanValue(state, 3);
  9687. data->bool_value = value;
  9688. break;
  9689. }
  9690. case 3:
  9691. {
  9692. string value = lua_interface->GetStringValue(state, 3);
  9693. string value2 = lua_interface->GetStringValue(state, 4);
  9694. data->string_value = value;
  9695. data->string_value2 = value2;
  9696. break;
  9697. }
  9698. default:
  9699. setVal = false;
  9700. }
  9701. return setVal;
  9702. }
  9703. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9704. if (!lua_interface)
  9705. return 0;
  9706. LuaSpell* spell = lua_interface->GetSpell(state);
  9707. int8 idx = lua_interface->GetInt32Value(state, 2);
  9708. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9709. if (!spell) {
  9710. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9711. return 0;
  9712. }
  9713. if (!spell->spell || !spell->spell->GetSpellData()) {
  9714. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9715. return 0;
  9716. }
  9717. if (spell->spell->lua_data.size() <= idx)
  9718. {
  9719. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9720. return 0;
  9721. }
  9722. bool setVal = true;
  9723. LUAData* data = spell->spell->lua_data[idx];
  9724. switch (data->type)
  9725. {
  9726. case 0:
  9727. {
  9728. if(!secondfield)
  9729. lua_interface->SetSInt32Value(state, data->int_value);
  9730. else
  9731. lua_interface->SetSInt32Value(state, data->int_value2);
  9732. break;
  9733. }
  9734. case 1:
  9735. {
  9736. if (!secondfield)
  9737. lua_interface->SetFloatValue(state, data->float_value);
  9738. else
  9739. lua_interface->SetFloatValue(state, data->float_value2);
  9740. break;
  9741. }
  9742. case 2:
  9743. {
  9744. lua_interface->SetBooleanValue(state, data->bool_value);
  9745. break;
  9746. }
  9747. case 3:
  9748. {
  9749. if (!secondfield)
  9750. lua_interface->SetStringValue(state, data->string_value.c_str());
  9751. else
  9752. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9753. break;
  9754. }
  9755. default:
  9756. setVal = false;
  9757. }
  9758. return setVal;
  9759. }
  9760. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9761. if (!lua_interface)
  9762. return 0;
  9763. LuaSpell* spell = lua_interface->GetSpell(state);
  9764. int8 idx = lua_interface->GetInt32Value(state, 2);
  9765. string field = lua_interface->GetStringValue(state, 3);
  9766. boost::to_lower(field);
  9767. if (!spell) {
  9768. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9769. return 0;
  9770. }
  9771. if (!spell->spell || !spell->spell->GetSpellData()) {
  9772. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9773. return 0;
  9774. }
  9775. if (spell->spell->effects.size() <= idx)
  9776. {
  9777. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9778. return 0;
  9779. }
  9780. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9781. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9782. if (field == "description")
  9783. effect->description = string(lua_interface->GetStringValue(state, 4));
  9784. else if (field == "bullet")
  9785. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9786. else if (field == "percentage")
  9787. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9788. else // no match
  9789. return 0;
  9790. return 1;
  9791. }
  9792. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9793. if (!lua_interface)
  9794. return 0;
  9795. LuaSpell* spell = lua_interface->GetSpell(state);
  9796. int8 idx = lua_interface->GetInt32Value(state, 2);
  9797. string field = lua_interface->GetStringValue(state, 3);
  9798. boost::to_lower(field);
  9799. if (!spell) {
  9800. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9801. return 0;
  9802. }
  9803. if (!spell->spell || !spell->spell->GetSpellData()) {
  9804. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9805. return 0;
  9806. }
  9807. if (spell->spell->effects.size() <= idx)
  9808. {
  9809. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9810. return 0;
  9811. }
  9812. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9813. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9814. if (field == "description")
  9815. lua_interface->SetStringValue(state, effect->description.c_str());
  9816. else if (field == "bullet")
  9817. lua_interface->SetInt32Value(state, effect->subbullet);
  9818. else if (field == "percentage")
  9819. lua_interface->SetInt32Value(state, effect->percentage);
  9820. else // no match
  9821. return 0;
  9822. return 1;
  9823. }
  9824. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9825. if (!lua_interface)
  9826. return 0;
  9827. LuaSpell* spell = lua_interface->GetSpell(state);
  9828. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9829. Spawn* target = lua_interface->GetSpawn(state, 3);
  9830. if (!target) {
  9831. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9832. return 0;
  9833. }
  9834. if (!target->IsEntity()) {
  9835. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9836. return 0;
  9837. }
  9838. if (!spell) {
  9839. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9840. return 0;
  9841. }
  9842. if (caster && !caster->IsEntity()) {
  9843. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9844. return 0;
  9845. }
  9846. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9847. return 0;
  9848. }
  9849. int EQ2Emu_lua_InWater(lua_State* state) {
  9850. if (!lua_interface)
  9851. return 0;
  9852. Spawn* spawn = lua_interface->GetSpawn(state);
  9853. lua_interface->ResetFunctionStack(state);
  9854. if (spawn) {
  9855. lua_interface->SetBooleanValue(state, spawn->InWater());
  9856. return 1;
  9857. }
  9858. return 0;
  9859. }
  9860. int EQ2Emu_lua_InLava(lua_State* state) {
  9861. if (!lua_interface)
  9862. return 0;
  9863. Spawn* spawn = lua_interface->GetSpawn(state);
  9864. lua_interface->ResetFunctionStack(state);
  9865. if (spawn) {
  9866. lua_interface->SetBooleanValue(state, spawn->InLava());
  9867. return 1;
  9868. }
  9869. return 0;
  9870. }
  9871. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9872. if (!lua_interface)
  9873. return 0;
  9874. Spawn* attacker = lua_interface->GetSpawn(state);
  9875. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9876. int8 type = lua_interface->GetInt8Value(state, 3);
  9877. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9878. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9879. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9880. string spell_name = lua_interface->GetStringValue(state, 7);
  9881. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9882. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9883. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9884. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9885. lua_interface->ResetFunctionStack(state);
  9886. if (!attacker) {
  9887. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9888. return 0;
  9889. }
  9890. if (!attacker->IsEntity()) {
  9891. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9892. return 0;
  9893. }
  9894. if (!victim) {
  9895. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9896. return 0;
  9897. }
  9898. if (!victim->IsEntity()) {
  9899. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9900. return 0;
  9901. }
  9902. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9903. return 0;
  9904. }
  9905. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9906. if (!lua_interface)
  9907. return 0;
  9908. Spawn* spawn = lua_interface->GetSpawn(state);
  9909. lua_interface->ResetFunctionStack(state);
  9910. if (spawn) {
  9911. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9912. return 1;
  9913. }
  9914. return 0;
  9915. }
  9916. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9917. if (!lua_interface)
  9918. return 0;
  9919. Spawn* spawn = lua_interface->GetSpawn(state);
  9920. bool invul = lua_interface->GetBooleanValue(state, 2);
  9921. lua_interface->ResetFunctionStack(state);
  9922. if (spawn) {
  9923. spawn->SetInvulnerable(invul);
  9924. }
  9925. return 0;
  9926. }
  9927. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  9928. if (!lua_interface)
  9929. return 0;
  9930. string category = lua_interface->GetStringValue(state);
  9931. string name = lua_interface->GetStringValue(state, 2);
  9932. lua_interface->ResetFunctionStack(state);
  9933. Rule *ret = 0;
  9934. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9935. lua_interface->SetBooleanValue(state, ret->GetBool());
  9936. return 1;
  9937. }
  9938. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9939. return 0;
  9940. }
  9941. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9942. if (!lua_interface)
  9943. return 0;
  9944. string category = lua_interface->GetStringValue(state);
  9945. string name = lua_interface->GetStringValue(state, 2);
  9946. lua_interface->ResetFunctionStack(state);
  9947. Rule *ret = 0;
  9948. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9949. lua_interface->SetInt32Value(state, ret->GetInt32());
  9950. return 1;
  9951. }
  9952. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9953. return 0;
  9954. }
  9955. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  9956. if (!lua_interface)
  9957. return 0;
  9958. string category = lua_interface->GetStringValue(state);
  9959. string name = lua_interface->GetStringValue(state, 2);
  9960. lua_interface->ResetFunctionStack(state);
  9961. Rule *ret = 0;
  9962. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9963. lua_interface->SetFloatValue(state, ret->GetFloat());
  9964. return 1;
  9965. }
  9966. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9967. return 0;
  9968. }
  9969. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  9970. if (!lua_interface)
  9971. return 0;
  9972. Spawn* spawn = lua_interface->GetSpawn(state);
  9973. string type = lua_interface->GetStringValue(state, 2);
  9974. lua_interface->ResetFunctionStack(state);
  9975. if (spawn) {
  9976. int res = 1;
  9977. boost::to_lower(type);
  9978. if(type == "assigned_aa")
  9979. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  9980. else if ( type == "unassigned_aa")
  9981. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  9982. else if ( type == "assigned_tradeskill_aa")
  9983. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  9984. else if ( type == "unassigned_tradeskill_aa")
  9985. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  9986. else if ( type == "assigned_prestige_aa")
  9987. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  9988. else if ( type == "unassigned_prestige_aa")
  9989. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  9990. else if ( type == "assigned_tradeskill_prestige_aa")
  9991. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  9992. else if ( type == "unassigned_tradeskill_prestige_aa")
  9993. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  9994. else
  9995. res = 0;
  9996. return res;
  9997. }
  9998. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  9999. return 0;
  10000. }
  10001. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10002. if (!lua_interface)
  10003. return 0;
  10004. Spawn* spawn = lua_interface->GetSpawn(state);
  10005. string type = lua_interface->GetStringValue(state, 2);
  10006. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10007. lua_interface->ResetFunctionStack(state);
  10008. if (spawn) {
  10009. boost::to_lower(type);
  10010. if(type == "assigned_aa")
  10011. spawn->SetAssignedAA((sint16)value);
  10012. else if ( type == "unassigned_aa")
  10013. spawn->SetUnassignedAA((sint16)value);
  10014. else if ( type == "assigned_tradeskill_aa")
  10015. spawn->SetTradeskillAA((sint16)value);
  10016. else if ( type == "unassigned_tradeskill_aa")
  10017. spawn->SetUnassignedTradeskillAA((sint16)value);
  10018. else if ( type == "assigned_prestige_aa")
  10019. spawn->SetPrestigeAA((sint16)value);
  10020. else if ( type == "unassigned_prestige_aa")
  10021. spawn->SetUnassignedPrestigeAA((sint16)value);
  10022. else if ( type == "assigned_tradeskill_prestige_aa")
  10023. spawn->SetTradeskillPrestigeAA((sint16)value);
  10024. else if ( type == "unassigned_tradeskill_prestige_aa")
  10025. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10026. if(spawn->IsPlayer())
  10027. ((Player*)spawn)->SetCharSheetChanged(true);
  10028. }
  10029. return 0;
  10030. }
  10031. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10032. if (!lua_interface)
  10033. return 0;
  10034. string titleName = lua_interface->GetStringValue(state);
  10035. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10036. lua_interface->ResetFunctionStack(state);
  10037. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10038. lua_interface->SetSInt32Value(state, index);
  10039. return 1;
  10040. }
  10041. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10042. if (!lua_interface)
  10043. return 0;
  10044. Spawn* spawn = lua_interface->GetSpawn(state);
  10045. string titleName = lua_interface->GetStringValue(state, 2);
  10046. lua_interface->ResetFunctionStack(state);
  10047. if(!spawn->IsPlayer())
  10048. {
  10049. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10050. lua_interface->SetSInt32Value(state, -1);
  10051. return 1;
  10052. }
  10053. Player* player = (Player*)spawn;
  10054. // check if player already has the title, don't need to add twice
  10055. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10056. if ( playerHasTitle)
  10057. {
  10058. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10059. return 1;
  10060. }
  10061. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10062. if(!title)
  10063. {
  10064. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10065. lua_interface->SetSInt32Value(state, -1);
  10066. return 1;
  10067. }
  10068. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10069. if(returnIdx < 0)
  10070. {
  10071. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10072. }
  10073. lua_interface->SetSInt32Value(state, returnIdx);
  10074. player->GetClient()->SendTitleUpdate();
  10075. return 1;
  10076. }
  10077. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10078. if (!lua_interface)
  10079. return 0;
  10080. Spawn* spawn = lua_interface->GetSpawn(state);
  10081. string titleName = lua_interface->GetStringValue(state, 2);
  10082. lua_interface->ResetFunctionStack(state);
  10083. if(!spawn->IsPlayer())
  10084. {
  10085. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10086. return 0;
  10087. }
  10088. Player* player = (Player*)spawn;
  10089. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10090. if(!title)
  10091. {
  10092. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10093. return 0;
  10094. }
  10095. if(title->GetPrefix())
  10096. {
  10097. 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());
  10098. return 0;
  10099. }
  10100. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10101. player->GetClient()->SendTitleUpdate();
  10102. return 1;
  10103. }
  10104. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10105. if (!lua_interface)
  10106. return 0;
  10107. Spawn* spawn = lua_interface->GetSpawn(state);
  10108. string titleName = lua_interface->GetStringValue(state, 2);
  10109. lua_interface->ResetFunctionStack(state);
  10110. if(!spawn->IsPlayer())
  10111. {
  10112. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10113. return 0;
  10114. }
  10115. Player* player = (Player*)spawn;
  10116. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10117. if(!title)
  10118. {
  10119. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10120. return 0;
  10121. }
  10122. if(!title->GetPrefix())
  10123. {
  10124. 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());
  10125. return 0;
  10126. }
  10127. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10128. player->GetClient()->SendTitleUpdate();
  10129. return 1;
  10130. }
  10131. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10132. if (!lua_interface)
  10133. return 0;
  10134. Spawn* spawn = lua_interface->GetSpawn(state);
  10135. lua_interface->ResetFunctionStack(state);
  10136. if(!spawn->IsPlayer())
  10137. {
  10138. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10139. return 0;
  10140. }
  10141. Player* player = (Player*)spawn;
  10142. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10143. player->GetClient()->SendTitleUpdate();
  10144. return 1;
  10145. }
  10146. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10147. if (!lua_interface)
  10148. return 0;
  10149. Spawn* spawn = lua_interface->GetSpawn(state);
  10150. lua_interface->ResetFunctionStack(state);
  10151. if(!spawn->IsPlayer())
  10152. {
  10153. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10154. return 0;
  10155. }
  10156. Player* player = (Player*)spawn;
  10157. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10158. player->GetClient()->SendTitleUpdate();
  10159. return 1;
  10160. }
  10161. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10162. if (!lua_interface)
  10163. return 0;
  10164. Spawn* spawn = lua_interface->GetSpawn(state);
  10165. string field = lua_interface->GetStringValue(state, 2);
  10166. lua_interface->ResetFunctionStack(state);
  10167. if(!spawn || !spawn->IsEntity())
  10168. {
  10169. 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));
  10170. return 0;
  10171. }
  10172. Entity* ent = (Entity*)spawn;
  10173. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10174. return 1;
  10175. }
  10176. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10177. if (!lua_interface)
  10178. return 0;
  10179. Spawn* spawn = lua_interface->GetSpawn(state);
  10180. string field = lua_interface->GetStringValue(state, 2);
  10181. lua_interface->ResetFunctionStack(state);
  10182. if(!spawn || !spawn->IsEntity())
  10183. {
  10184. 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));
  10185. return 0;
  10186. }
  10187. Entity* ent = (Entity*)spawn;
  10188. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10189. return 1;
  10190. }
  10191. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10192. if (!lua_interface)
  10193. return 0;
  10194. Spawn* spawn = lua_interface->GetSpawn(state);
  10195. string field = lua_interface->GetStringValue(state, 2);
  10196. lua_interface->ResetFunctionStack(state);
  10197. if(!spawn || !spawn->IsEntity())
  10198. {
  10199. 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));
  10200. return 0;
  10201. }
  10202. Entity* ent = (Entity*)spawn;
  10203. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10204. return 1;
  10205. }
  10206. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10207. if (!lua_interface)
  10208. return 0;
  10209. Spawn* spawn = lua_interface->GetSpawn(state);
  10210. string field = lua_interface->GetStringValue(state, 2);
  10211. lua_interface->ResetFunctionStack(state);
  10212. if(!spawn || !spawn->IsEntity())
  10213. {
  10214. 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));
  10215. return 0;
  10216. }
  10217. Entity* ent = (Entity*)spawn;
  10218. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10219. return 1;
  10220. }
  10221. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10222. if (!lua_interface)
  10223. return 0;
  10224. Spawn* spawn = lua_interface->GetSpawn(state);
  10225. string field = lua_interface->GetStringValue(state, 2);
  10226. string value = lua_interface->GetStringValue(state, 3);
  10227. lua_interface->ResetFunctionStack(state);
  10228. if(!spawn || !spawn->IsEntity())
  10229. {
  10230. 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));
  10231. return 0;
  10232. }
  10233. Entity* ent = (Entity*)spawn;
  10234. bool set_ = ent->SetInfoStructString(field, value);
  10235. lua_interface->SetBooleanValue(state, set_);
  10236. return 1;
  10237. }
  10238. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10239. if (!lua_interface)
  10240. return 0;
  10241. Spawn* spawn = lua_interface->GetSpawn(state);
  10242. string field = lua_interface->GetStringValue(state, 2);
  10243. int64 value = lua_interface->GetInt64Value(state, 3);
  10244. lua_interface->ResetFunctionStack(state);
  10245. if(!spawn || !spawn->IsEntity())
  10246. {
  10247. 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));
  10248. return 0;
  10249. }
  10250. Entity* ent = (Entity*)spawn;
  10251. bool set_ = ent->SetInfoStructUInt(field, value);
  10252. lua_interface->SetBooleanValue(state, set_);
  10253. return 1;
  10254. }
  10255. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10256. if (!lua_interface)
  10257. return 0;
  10258. Spawn* spawn = lua_interface->GetSpawn(state);
  10259. string field = lua_interface->GetStringValue(state, 2);
  10260. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10261. lua_interface->ResetFunctionStack(state);
  10262. if(!spawn || !spawn->IsEntity())
  10263. {
  10264. 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));
  10265. return 0;
  10266. }
  10267. Entity* ent = (Entity*)spawn;
  10268. bool set_ = ent->SetInfoStructSInt(field, value);
  10269. lua_interface->SetBooleanValue(state, set_);
  10270. return 1;
  10271. }
  10272. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10273. if (!lua_interface)
  10274. return 0;
  10275. Spawn* spawn = lua_interface->GetSpawn(state);
  10276. string field = lua_interface->GetStringValue(state, 2);
  10277. float value = lua_interface->GetFloatValue(state, 3);
  10278. lua_interface->ResetFunctionStack(state);
  10279. if(!spawn || !spawn->IsEntity())
  10280. {
  10281. 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));
  10282. return 0;
  10283. }
  10284. Entity* ent = (Entity*)spawn;
  10285. bool set_ = ent->SetInfoStructFloat(field, value);
  10286. lua_interface->SetBooleanValue(state, set_);
  10287. return 1;
  10288. }
  10289. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10290. if (!lua_interface)
  10291. return 0;
  10292. Spawn* spawn = lua_interface->GetSpawn(state);
  10293. bool value = lua_interface->GetBooleanValue(state, 2);
  10294. lua_interface->ResetFunctionStack(state);
  10295. if(!spawn || !spawn->IsPlayer())
  10296. {
  10297. 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));
  10298. return 0;
  10299. }
  10300. ((Player*)spawn)->SetCharSheetChanged(value);
  10301. return 0;
  10302. }
  10303. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10304. if (!lua_interface)
  10305. return 0;
  10306. Spawn* spawn = lua_interface->GetSpawn(state);
  10307. std::string fromName = lua_interface->GetStringValue(state, 2);
  10308. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10309. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10310. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10311. int32 copper = lua_interface->GetInt32Value(state, 6);
  10312. int32 silver = lua_interface->GetInt32Value(state, 7);
  10313. int32 gold = lua_interface->GetInt32Value(state, 8);
  10314. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10315. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10316. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10317. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10318. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10319. lua_interface->ResetFunctionStack(state);
  10320. if(!spawn || !spawn->IsPlayer())
  10321. {
  10322. 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));
  10323. lua_interface->SetBooleanValue(state, false);
  10324. return 1;
  10325. }
  10326. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10327. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10328. lua_interface->SetBooleanValue(state, true);
  10329. return 1;
  10330. }
  10331. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10332. if (!lua_interface)
  10333. return 0;
  10334. int32 char_id = lua_interface->GetInt32Value(state);
  10335. std::string fromName = lua_interface->GetStringValue(state, 2);
  10336. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10337. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10338. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10339. int32 copper = lua_interface->GetInt32Value(state, 6);
  10340. int32 silver = lua_interface->GetInt32Value(state, 7);
  10341. int32 gold = lua_interface->GetInt32Value(state, 8);
  10342. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10343. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10344. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10345. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10346. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10347. lua_interface->ResetFunctionStack(state);
  10348. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10349. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10350. lua_interface->SetBooleanValue(state, true);
  10351. return 1;
  10352. }
  10353. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10354. Spawn* widget;
  10355. if (lua_interface) {
  10356. widget = lua_interface->GetSpawn(state);
  10357. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10358. lua_interface->ResetFunctionStack(state);
  10359. if (widget && widget->IsWidget())
  10360. {
  10361. ((Widget*)widget)->OpenDoor();
  10362. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10363. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10364. }
  10365. else
  10366. 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));
  10367. }
  10368. return 0;
  10369. }
  10370. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10371. Spawn* widget;
  10372. if (lua_interface) {
  10373. widget = lua_interface->GetSpawn(state);
  10374. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10375. lua_interface->ResetFunctionStack(state);
  10376. if (widget && widget->IsWidget())
  10377. {
  10378. ((Widget*)widget)->CloseDoor();
  10379. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10380. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10381. }
  10382. else
  10383. 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));
  10384. }
  10385. return 0;
  10386. }
  10387. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10388. if (!lua_interface)
  10389. return 0;
  10390. Spawn* widget = lua_interface->GetSpawn(state);
  10391. lua_interface->ResetFunctionStack(state);
  10392. if (widget && widget->IsWidget())
  10393. {
  10394. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10395. return 1;
  10396. }
  10397. return 0;
  10398. }
  10399. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10400. if (!lua_interface)
  10401. return 0;
  10402. sint32 min = lua_interface->GetSInt32Value(state);
  10403. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10404. lua_interface->ResetFunctionStack(state);
  10405. sint32 result = MakeRandomInt(min, max);
  10406. lua_interface->SetSInt32Value(state, result);
  10407. return 1;
  10408. }
  10409. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10410. if (!lua_interface)
  10411. return 0;
  10412. float min = lua_interface->GetFloatValue(state);
  10413. float max = lua_interface->GetFloatValue(state, 2);
  10414. lua_interface->ResetFunctionStack(state);
  10415. float result = MakeRandomFloat(min, max);
  10416. lua_interface->SetFloatValue(state, result);
  10417. return 1;
  10418. }
  10419. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10420. if (!lua_interface)
  10421. return 0;
  10422. Spawn* spawn = lua_interface->GetSpawn(state);
  10423. int32 value = lua_interface->GetInt32Value(state, 2);
  10424. lua_interface->ResetFunctionStack(state);
  10425. if(!spawn)
  10426. {
  10427. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10428. lua_interface->SetBooleanValue(state, false);
  10429. return 1;
  10430. }
  10431. spawn->AddIconValue(value);
  10432. lua_interface->SetBooleanValue(state, true);
  10433. return 1;
  10434. }
  10435. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10436. if (!lua_interface)
  10437. return 0;
  10438. Spawn* spawn = lua_interface->GetSpawn(state);
  10439. int32 value = lua_interface->GetInt32Value(state, 2);
  10440. lua_interface->ResetFunctionStack(state);
  10441. if(!spawn)
  10442. {
  10443. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10444. lua_interface->SetBooleanValue(state, false);
  10445. return 1;
  10446. }
  10447. spawn->RemoveIconValue(value);
  10448. lua_interface->SetBooleanValue(state, true);
  10449. return 1;
  10450. }
  10451. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10452. Spawn* npc = lua_interface->GetSpawn(state);
  10453. lua_interface->ResetFunctionStack(state);
  10454. if (npc && npc->IsNPC()) {
  10455. NPC* shard = (NPC*)npc;
  10456. int32 shardid = shard->GetShardID();
  10457. lua_interface->SetInt32Value(state, shardid);
  10458. return 1;
  10459. }
  10460. lua_interface->SetInt32Value(state, 0);
  10461. return 1;
  10462. }
  10463. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10464. Spawn* npc = lua_interface->GetSpawn(state);
  10465. lua_interface->ResetFunctionStack(state);
  10466. if (npc && npc->IsNPC()) {
  10467. NPC* shard = (NPC*)npc;
  10468. int32 charid = shard->GetShardCharID();
  10469. lua_interface->SetInt32Value(state, charid);
  10470. return 1;
  10471. }
  10472. lua_interface->SetInt32Value(state, 0);
  10473. return 1;
  10474. }
  10475. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10476. Spawn* npc = lua_interface->GetSpawn(state);
  10477. lua_interface->ResetFunctionStack(state);
  10478. if (npc && npc->IsNPC()) {
  10479. NPC* shard = (NPC*)npc;
  10480. int64 timestamp = shard->GetShardCreatedTimestamp();
  10481. lua_interface->SetSInt64Value(state, timestamp);
  10482. return 1;
  10483. }
  10484. lua_interface->SetSInt64Value(state, 0);
  10485. return 1;
  10486. }
  10487. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10488. if (!lua_interface)
  10489. return 0;
  10490. int32 shardid = lua_interface->GetInt32Value(state);
  10491. lua_interface->ResetFunctionStack(state);
  10492. if(shardid < 1)
  10493. lua_interface->SetBooleanValue(state, false);
  10494. else
  10495. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10496. return 1;
  10497. }
  10498. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10499. if (!lua_interface)
  10500. return 0;
  10501. Spawn* spawn = lua_interface->GetSpawn(state);
  10502. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10503. if (spawn) {
  10504. spawn->PauseMovement(delay_in_ms);
  10505. }
  10506. lua_interface->ResetFunctionStack(state);
  10507. return 0;
  10508. }
  10509. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10510. Player* player = (Player*)lua_interface->GetSpawn(state);
  10511. int8 level = lua_interface->GetInt8Value(state, 2);
  10512. lua_interface->ResetFunctionStack(state);
  10513. if (player && player->IsPlayer() && level > 0) {
  10514. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10515. return 1;
  10516. }
  10517. return 0;
  10518. }
  10519. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10520. Player* player = (Player*)lua_interface->GetSpawn(state);
  10521. int8 level = lua_interface->GetInt8Value(state, 2);
  10522. lua_interface->ResetFunctionStack(state);
  10523. if (player && player->IsPlayer() && level > 0) {
  10524. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10525. return 1;
  10526. }
  10527. return 0;
  10528. }