LuaFunctions.cpp 369 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064
  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 = lua_interface->GetBooleanValue(state, 5); // default false as originally designed, allow user to set temporary_flag true to not update DB
  358. int32 type = commands.GetSpawnSetType(variable);
  359. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  360. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  361. return 0;
  362. }
  363. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  364. if (!lua_interface)
  365. return 0;
  366. Spawn* spawn = lua_interface->GetSpawn(state);
  367. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  368. if (spawn && spawn_id > 0) {
  369. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  370. if (closest_spawn) {
  371. lua_interface->SetSpawnValue(state, closest_spawn);
  372. return 1;
  373. }
  374. }
  375. return 0;
  376. }
  377. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  381. int32 position = lua_interface->GetInt32Value(state, 2);
  382. if (spawnList) {
  383. if (spawnList->size() > position) {
  384. lua_interface->SetSpawnValue(state, spawnList->at(position));
  385. return 1;
  386. }
  387. else {
  388. return 0;
  389. }
  390. return spawnList->size();
  391. }
  392. return 0;
  393. }
  394. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  395. if (!lua_interface)
  396. return 0;
  397. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  398. if (spawnList) {
  399. return spawnList->size();
  400. }
  401. return 0;
  402. }
  403. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  404. if (!lua_interface)
  405. return 0;
  406. vector<Spawn*>* spawnList = new vector<Spawn*>();
  407. lua_interface->SetSpawnListValue(state, spawnList);
  408. return 1;
  409. }
  410. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  411. if (!lua_interface)
  412. return 0;
  413. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  414. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  415. if (spawnList) {
  416. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  417. if (it == spawnList->end())
  418. spawnList->push_back(spawn);
  419. }
  420. return 0;
  421. }
  422. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  423. if (!lua_interface)
  424. return 0;
  425. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  426. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  427. if (spawnList) {
  428. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  429. if(it != spawnList->end())
  430. spawnList->erase(it);
  431. }
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. if (spawn) {
  440. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  441. if (spawns.size() > 0) {
  442. vector<Spawn*>* spawnList = new vector<Spawn*>();
  443. vector<Spawn*>::iterator itr;
  444. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  445. spawnList->push_back(*itr);
  446. }
  447. lua_interface->SetSpawnListValue(state, spawnList);
  448. return 1;
  449. }
  450. }
  451. return 0;
  452. }
  453. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  454. if (!lua_interface)
  455. return 0;
  456. string variable_name = lua_interface->GetStringValue(state);
  457. Variable* var = variables.FindVariable(variable_name);
  458. if (var) {
  459. lua_interface->SetStringValue(state, var->GetValue());
  460. return 1;
  461. }
  462. return 0;
  463. }
  464. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  465. if (!lua_interface)
  466. return 0;
  467. int32 total_coins = lua_interface->GetInt32Value(state);
  468. if (total_coins == 0) {
  469. lua_interface->SetStringValue(state, "0 copper");
  470. return 1;
  471. }
  472. char tmp[64] = { 0 };
  473. string message = "";
  474. int32 val = 0;
  475. if (total_coins >= 1000000) {
  476. val = total_coins / 1000000;
  477. total_coins -= 1000000 * val;
  478. sprintf(tmp, " %u Platinum", val);
  479. message.append(tmp);
  480. memset(tmp, 0, 64);
  481. }
  482. if (total_coins >= 10000) {
  483. val = total_coins / 10000;
  484. total_coins -= 10000 * val;
  485. sprintf(tmp, " %u Gold", val);
  486. message.append(tmp);
  487. memset(tmp, 0, 64);
  488. }
  489. if (total_coins >= 100) {
  490. val = total_coins / 100;
  491. total_coins -= 100 * val;
  492. sprintf(tmp, " %u Silver", val);
  493. message.append(tmp);
  494. memset(tmp, 0, 64);
  495. }
  496. if (total_coins > 0) {
  497. sprintf(tmp, " %u Copper", (int32)total_coins);
  498. message.append(tmp);
  499. }
  500. lua_interface->SetStringValue(state, message.c_str());
  501. return 1;
  502. }
  503. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  504. ZoneServer* zone = lua_interface->GetZone(state);
  505. int32 group_id = lua_interface->GetInt32Value(state, 2);
  506. if (zone) {
  507. Spawn* spawn = zone->GetSpawnGroup(group_id);
  508. if (spawn) {
  509. lua_interface->SetSpawnValue(state, spawn);
  510. return 1;
  511. }
  512. }
  513. return 0;
  514. }
  515. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  516. ZoneServer* zone = lua_interface->GetZone(state);
  517. int32 location_id = lua_interface->GetInt32Value(state, 2);
  518. if (zone) {
  519. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  520. if (spawn) {
  521. lua_interface->SetSpawnValue(state, spawn);
  522. return 1;
  523. }
  524. }
  525. return 0;
  526. }
  527. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. if (spawn) {
  530. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  531. return 1;
  532. }
  533. return 0;
  534. }
  535. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  536. Spawn* spawn = lua_interface->GetSpawn(state);
  537. if (spawn) {
  538. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  539. return 1;
  540. }
  541. return 0;
  542. }
  543. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  544. Spawn* spawn = lua_interface->GetSpawn(state);
  545. if (spawn) {
  546. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  547. return 1;
  548. }
  549. return 0;
  550. }
  551. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  552. Spawn* spawn = lua_interface->GetSpawn(state);
  553. if (spawn) {
  554. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  555. return 1;
  556. }
  557. return 0;
  558. }
  559. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  560. Player* player = (Player*)lua_interface->GetSpawn(state);
  561. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  562. if (player && player->IsPlayer() && faction_id > 0) {
  563. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  564. return 1;
  565. }
  566. return 0;
  567. }
  568. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  569. if (!lua_interface)
  570. return 0;
  571. Spawn* spawn = lua_interface->GetSpawn(state);
  572. int32 value = lua_interface->GetInt32Value(state, 2);
  573. if (spawn) {
  574. spawn->SetFactionID(value);
  575. }
  576. return 0;
  577. }
  578. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  579. Spawn* spawn = lua_interface->GetSpawn(state);
  580. if (spawn) {
  581. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  582. return 1;
  583. }
  584. return 0;
  585. }
  586. int EQ2Emu_lua_GetGender(lua_State* state) {
  587. Spawn* spawn = lua_interface->GetSpawn(state);
  588. if (spawn) {
  589. lua_interface->SetInt32Value(state, spawn->GetGender());
  590. return 1;
  591. }
  592. return 0;
  593. }
  594. int EQ2Emu_lua_GetTarget(lua_State* state) {
  595. Spawn* spawn = lua_interface->GetSpawn(state);
  596. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  597. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  598. return 1;
  599. }
  600. return 0;
  601. }
  602. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  603. if (!lua_interface)
  604. return 0;
  605. Spawn* spawn = lua_interface->GetSpawn(state);
  606. string mp3_string = lua_interface->GetStringValue(state, 2);
  607. int32 key1 = lua_interface->GetInt32Value(state, 3);
  608. int32 key2 = lua_interface->GetInt32Value(state, 4);
  609. Spawn* player = lua_interface->GetSpawn(state, 5);
  610. if (spawn && mp3_string.length() > 0) {
  611. Client* client = 0;
  612. if (player && player->IsPlayer())
  613. client = spawn->GetZone()->GetClientBySpawn(player);
  614. if (client) {
  615. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  616. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  617. }
  618. else
  619. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  620. }
  621. return 0;
  622. }
  623. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  624. if (!lua_interface)
  625. return 0;
  626. Spawn* spawn = lua_interface->GetSpawn(state);
  627. if (spawn) {
  628. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  629. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  630. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  631. return 3;
  632. }
  633. return 0;
  634. }
  635. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  636. if (!lua_interface)
  637. return 0;
  638. Spawn* spawn = lua_interface->GetSpawn(state);
  639. if (spawn) {
  640. int32 item_id = lua_interface->GetInt32Value(state, 2);
  641. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  642. return 1;
  643. }
  644. return 0;
  645. }
  646. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  647. if (!lua_interface)
  648. return 0;
  649. Spawn* spawn = lua_interface->GetSpawn(state);
  650. if (spawn && spawn->IsEntity()) {
  651. int32 item_id = lua_interface->GetInt32Value(state, 2);
  652. int16 charges = lua_interface->GetInt16Value(state, 3);
  653. if (charges == 0)
  654. charges = 1;
  655. ((Entity*)spawn)->AddLootItem(item_id, charges);
  656. }
  657. return 0;
  658. }
  659. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  660. if (!lua_interface)
  661. return 0;
  662. Spawn* spawn = lua_interface->GetSpawn(state);
  663. if (spawn && spawn->IsEntity()) {
  664. int32 item_id = lua_interface->GetInt32Value(state, 2);
  665. spawn->LootItem(item_id);
  666. }
  667. return 0;
  668. }
  669. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  670. if (!lua_interface)
  671. return 0;
  672. Spawn* spawn = lua_interface->GetSpawn(state);
  673. if (spawn) {
  674. int32 val = lua_interface->GetInt32Value(state, 2);
  675. spawn->AddLootCoins(val);
  676. }
  677. return 0;
  678. }
  679. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  680. if (!lua_interface)
  681. return 0;
  682. Spawn* entity = lua_interface->GetSpawn(state);
  683. Spawn* player = lua_interface->GetSpawn(state, 2);
  684. if (entity && player && player->IsPlayer()) {
  685. int32 coins = lua_interface->GetInt32Value(state, 3);
  686. vector<Item*>* items = 0;
  687. int i = 0;
  688. int32 item_id = 0;
  689. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  690. if (items == 0)
  691. items = new vector<Item*>;
  692. if (master_item_list.GetItem(item_id))
  693. items->push_back(master_item_list.GetItem(item_id));
  694. i++;
  695. }
  696. Client* client = 0;
  697. client = player->GetZone()->GetClientBySpawn(player);
  698. if (client)
  699. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  700. if(coins > 0)
  701. entity->AddLootCoins(coins);
  702. safe_delete(items);
  703. }
  704. return 0;
  705. }
  706. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  707. if (!lua_interface)
  708. return 0;
  709. Spawn* entity = lua_interface->GetSpawn(state);
  710. Spawn* player = lua_interface->GetSpawn(state, 2);
  711. int32 item_id = lua_interface->GetInt32Value(state, 3);
  712. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  713. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  714. return 1;
  715. }
  716. return 0;
  717. }
  718. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  719. if (!lua_interface)
  720. return 0;
  721. Spawn* entity = lua_interface->GetSpawn(state);
  722. Spawn* player = lua_interface->GetSpawn(state, 2);
  723. if (entity && player && player->IsPlayer()) {
  724. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  725. return 1;
  726. }
  727. return 0;
  728. }
  729. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  730. if (!lua_interface)
  731. return 0;
  732. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  733. safe_delete(conversation);
  734. conversation = new vector<ConversationOption>();
  735. lua_interface->SetConversationValue(state, conversation);
  736. return 1;
  737. }
  738. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  739. if (!lua_interface)
  740. return 0;
  741. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  742. if (conversation) {
  743. ConversationOption conv_option;
  744. conv_option.option = lua_interface->GetStringValue(state, 2);
  745. conv_option.function = lua_interface->GetStringValue(state, 3);
  746. if (conv_option.option.length() > 0)
  747. conversation->push_back(conv_option);
  748. }
  749. return 0;
  750. }
  751. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  752. if (!lua_interface)
  753. return 0;
  754. Spawn* npc = lua_interface->GetSpawn(state);
  755. Spawn* player = lua_interface->GetSpawn(state, 2);
  756. if (npc && player && player->IsPlayer() && player->GetZone()) {
  757. Client* client = player->GetZone()->GetClientBySpawn(player);
  758. if (client) {
  759. int32 conversation_id = client->GetConversationID(npc, 0);
  760. client->CloseDialog(conversation_id);
  761. }
  762. }
  763. return 0;
  764. }
  765. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  766. if (!lua_interface)
  767. return 0;
  768. Item* item = lua_interface->GetItem(state);
  769. Spawn* player = lua_interface->GetSpawn(state, 2);
  770. if (item && player && player->IsPlayer() && player->GetZone()) {
  771. Client* client = player->GetZone()->GetClientBySpawn(player);
  772. if (client) {
  773. int32 conversation_id = client->GetConversationID(0, item);
  774. client->CloseDialog(conversation_id);
  775. }
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  783. Spawn* spawn = 0;
  784. Item* item = 0;
  785. int8 type = lua_interface->GetInt8Value(state, 2);
  786. if (type == 1 || type == 3)
  787. spawn = lua_interface->GetSpawn(state, 3);
  788. else if (type == 2 || type == 4)
  789. item = lua_interface->GetItem(state, 3);
  790. Spawn* player = lua_interface->GetSpawn(state, 4);
  791. string text = lua_interface->GetStringValue(state, 5);
  792. string mp3 = lua_interface->GetStringValue(state, 6);
  793. int32 key1 = lua_interface->GetInt32Value(state, 7);
  794. int32 key2 = lua_interface->GetInt32Value(state, 8);
  795. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  796. Client* client = player->GetZone()->GetClientBySpawn(player);
  797. if (client) {
  798. if (spawn) {
  799. // Need to do this so the function works the same as it did before
  800. if (type == 1)
  801. type++;
  802. if (mp3.length() > 0)
  803. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  804. else
  805. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  806. }
  807. else {
  808. if (mp3.length() > 0)
  809. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  810. else
  811. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  812. }
  813. }
  814. }
  815. safe_delete(conversation);
  816. lua_interface->SetConversationValue(state, NULL);
  817. return 0;
  818. }
  819. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  820. if(!lua_interface)
  821. return 0;
  822. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  823. Item* item = lua_interface->GetItem(state, 2);
  824. Spawn* player = lua_interface->GetSpawn(state, 3);
  825. string text = lua_interface->GetStringValue(state, 4);
  826. string mp3 = lua_interface->GetStringValue(state, 5);
  827. int32 key1 = lua_interface->GetInt32Value(state, 6);
  828. int32 key2 = lua_interface->GetInt32Value(state, 7);
  829. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  830. Client* client = player->GetZone()->GetClientBySpawn(player);
  831. if(client){
  832. if(mp3.length() > 0)
  833. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  834. else
  835. client->DisplayConversation(item, conversation, (char*)text.c_str());
  836. }
  837. safe_delete(conversation);
  838. }
  839. return 0;
  840. }*/
  841. int EQ2Emu_lua_StartConversation(lua_State* state) {
  842. if (!lua_interface)
  843. return 0;
  844. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  845. Spawn* source = lua_interface->GetSpawn(state, 2);
  846. Spawn* player = lua_interface->GetSpawn(state, 3);
  847. string text = lua_interface->GetStringValue(state, 4);
  848. string mp3 = lua_interface->GetStringValue(state, 5);
  849. int32 key1 = lua_interface->GetInt32Value(state, 6);
  850. int32 key2 = lua_interface->GetInt32Value(state, 7);
  851. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  852. Client* client = source->GetZone()->GetClientBySpawn(player);
  853. if (mp3.length() > 0)
  854. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  855. else
  856. client->DisplayConversation(source, 1, conversation, text.c_str());
  857. safe_delete(conversation);
  858. lua_interface->SetConversationValue(state, NULL);
  859. }
  860. else
  861. 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);
  862. return 0;
  863. }
  864. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  865. if (!lua_interface)
  866. return 0;
  867. Spawn* spawn = lua_interface->GetSpawn(state);
  868. float distance = lua_interface->GetFloatValue(state, 2);
  869. string in_range_function = lua_interface->GetStringValue(state, 3);
  870. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  871. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  872. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  873. return 0;
  874. }
  875. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  876. ZoneServer* zone = lua_interface->GetZone(state);
  877. float x = lua_interface->GetFloatValue(state, 2);
  878. float y = lua_interface->GetFloatValue(state, 3);
  879. float z = lua_interface->GetFloatValue(state, 4);
  880. float max_variation = lua_interface->GetFloatValue(state, 5);
  881. string in_range_function = lua_interface->GetStringValue(state, 6);
  882. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  883. if (zone && in_range_function.length() > 0)
  884. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  885. return 0;
  886. }
  887. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  888. if (!lua_interface)
  889. return 0;
  890. Spawn* spawn = lua_interface->GetSpawn(state);
  891. if (spawn && spawn->IsEntity()) {
  892. int32 val = lua_interface->GetInt32Value(state, 2);
  893. ((Entity*)spawn)->SetLootCoins(val);
  894. }
  895. return 0;
  896. }
  897. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  898. if (!lua_interface)
  899. return 0;
  900. Spawn* spawn = lua_interface->GetSpawn(state);
  901. if (spawn && spawn->IsEntity()) {
  902. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  903. return 1;
  904. }
  905. return 0;
  906. }
  907. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. Spawn* spawn = lua_interface->GetSpawn(state);
  911. float x = lua_interface->GetFloatValue(state, 2);
  912. float y = lua_interface->GetFloatValue(state, 3);
  913. float z = lua_interface->GetFloatValue(state, 4);
  914. float speed = lua_interface->GetFloatValue(state, 5);
  915. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  916. string function = lua_interface->GetStringValue(state, 7);
  917. if (spawn) {
  918. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  919. spawn->GetZone()->AddMovementNPC(spawn);
  920. }
  921. lua_interface->ResetFunctionStack(state);
  922. return 0;
  923. }
  924. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  925. if (!lua_interface)
  926. return 0;
  927. Spawn* spawn = lua_interface->GetSpawn(state);
  928. if (spawn) {
  929. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  930. return 1;
  931. }
  932. return 0;
  933. }
  934. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  935. if (!lua_interface)
  936. return 0;
  937. Spawn* spawn = lua_interface->GetSpawn(state);
  938. if (spawn && spawn->IsPlayer()) {
  939. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  940. return 1;
  941. }
  942. lua_interface->SetInt32Value(state, 0);
  943. return 1;
  944. }
  945. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  946. if (!lua_interface)
  947. return 0;
  948. Spawn* spawn = lua_interface->GetSpawn(state);
  949. Spawn* target = lua_interface->GetSpawn(state, 2);
  950. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  951. bool reset_action_state = true;
  952. if(num_args > 2)
  953. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  954. if (spawn && target) {
  955. if (spawn->IsEntity())
  956. // ((Entity*)spawn)->FaceTarget(target);
  957. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  958. }
  959. lua_interface->ResetFunctionStack(state);
  960. return 0;
  961. }
  962. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  963. if (!lua_interface)
  964. return 0;
  965. Spawn* spawn = lua_interface->GetSpawn(state);
  966. float x = lua_interface->GetFloatValue(state, 2);
  967. float y = lua_interface->GetFloatValue(state, 3);
  968. float z = lua_interface->GetFloatValue(state, 4);
  969. float speed = lua_interface->GetFloatValue(state, 5);
  970. string lua_function = lua_interface->GetStringValue(state, 6);
  971. bool more_points = lua_interface->GetBooleanValue(state, 7);
  972. if (spawn) {
  973. if (speed == 0)
  974. speed = spawn->GetSpeed();
  975. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  976. }
  977. lua_interface->ResetFunctionStack(state);
  978. return 0;
  979. }
  980. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  981. if (!lua_interface)
  982. return 0;
  983. Spawn* spawn = lua_interface->GetSpawn(state);
  984. if (spawn) {
  985. spawn->ClearRunningLocations();
  986. }
  987. return 0;
  988. }
  989. int EQ2Emu_lua_Say(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. Spawn* spawn = lua_interface->GetSpawn(state);
  993. string message = lua_interface->GetStringValue(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. int32 language = lua_interface->GetInt32Value(state, 4);
  996. if (spawn && message.length() > 0) {
  997. Client* client = 0;
  998. if (player && player->IsPlayer())
  999. client = spawn->GetZone()->GetClientBySpawn(player);
  1000. if (client)
  1001. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1002. else
  1003. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1004. }
  1005. lua_interface->ResetFunctionStack(state);
  1006. return 0;
  1007. }
  1008. int EQ2Emu_lua_Shout(lua_State* state) {
  1009. if (!lua_interface)
  1010. return 0;
  1011. Spawn* spawn = lua_interface->GetSpawn(state);
  1012. string message = lua_interface->GetStringValue(state, 2);
  1013. Spawn* player = lua_interface->GetSpawn(state, 3);
  1014. if (spawn && message.length() > 0) {
  1015. Client* client = 0;
  1016. if (player && player->IsPlayer())
  1017. client = spawn->GetZone()->GetClientBySpawn(player);
  1018. if (client)
  1019. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1020. else
  1021. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1022. }
  1023. lua_interface->ResetFunctionStack(state);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. string message = lua_interface->GetStringValue(state, 2);
  1031. Spawn* player = lua_interface->GetSpawn(state, 3);
  1032. if (spawn && message.length() > 0) {
  1033. Client* client = 0;
  1034. if (player && player->IsPlayer())
  1035. client = spawn->GetZone()->GetClientBySpawn(player);
  1036. if (client)
  1037. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1038. else
  1039. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1040. }
  1041. lua_interface->ResetFunctionStack(state);
  1042. return 0;
  1043. }
  1044. int EQ2Emu_lua_Emote(lua_State* state) {
  1045. if (!lua_interface)
  1046. return 0;
  1047. Spawn* spawn = lua_interface->GetSpawn(state);
  1048. string message = lua_interface->GetStringValue(state, 2);
  1049. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1050. Spawn* player = lua_interface->GetSpawn(state, 4);
  1051. char* to = 0;
  1052. if (spawn2)
  1053. to = spawn2->GetName();
  1054. if (spawn && message.length() > 0) {
  1055. Client* client = 0;
  1056. if (player && player->IsPlayer())
  1057. client = spawn->GetZone()->GetClientBySpawn(player);
  1058. if (client)
  1059. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1060. else
  1061. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1062. }
  1063. lua_interface->ResetFunctionStack(state);
  1064. return 0;
  1065. }
  1066. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1067. if (!lua_interface)
  1068. return 0;
  1069. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1070. if (!luaspell)
  1071. return 0;
  1072. Spawn* caster = luaspell->caster;
  1073. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1074. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1075. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1076. Spawn* target = lua_interface->GetSpawn(state, 4);
  1077. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1078. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1079. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1080. lua_interface->ResetFunctionStack(state);
  1081. boost::to_lower(heal_type);
  1082. if (caster && caster->IsEntity()) {
  1083. bool success = false;
  1084. luaspell->resisted = false;
  1085. if (target) {
  1086. float distance = caster->GetDistance(target, true);
  1087. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1088. success = true;
  1089. }
  1090. if (luaspell->targets.size() > 0) {
  1091. Spawn* target = 0;
  1092. ZoneServer* zone = luaspell->caster->GetZone();
  1093. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1094. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1095. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1096. float distance = caster->GetDistance(target, true);
  1097. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1098. }
  1099. }
  1100. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1101. success = true;
  1102. }
  1103. if (success) {
  1104. if (caster->GetZone())
  1105. caster->GetZone()->TriggerCharSheetTimer();
  1106. }
  1107. }
  1108. return 0;
  1109. }
  1110. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1111. if (!lua_interface)
  1112. return 0;
  1113. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1114. if (!luaspell)
  1115. return 0;
  1116. Spawn* caster = luaspell->caster;
  1117. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1118. float percentage = lua_interface->GetFloatValue(state, 2);
  1119. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1120. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1121. Spawn* target = lua_interface->GetSpawn(state, 5);
  1122. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1123. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1124. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1125. lua_interface->ResetFunctionStack(state);
  1126. boost::to_lower(heal_type);
  1127. int32 min_heal = 0, max_heal = 0;
  1128. if (caster && caster->IsEntity() && target) {
  1129. if(percentage <= 0.0f)
  1130. {
  1131. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1132. return 0;
  1133. }
  1134. if(heal_type == "power")
  1135. {
  1136. if(current_value)
  1137. {
  1138. if(caster_value)
  1139. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1140. else
  1141. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1142. }
  1143. else
  1144. {
  1145. if(caster_value)
  1146. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1147. else
  1148. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1149. }
  1150. }
  1151. else
  1152. {
  1153. if(current_value)
  1154. {
  1155. if(caster_value)
  1156. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1157. else
  1158. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1159. }
  1160. else
  1161. {
  1162. if(caster_value)
  1163. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1164. else
  1165. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1166. }
  1167. }
  1168. bool success = false;
  1169. luaspell->resisted = false;
  1170. if (target) {
  1171. float distance = caster->GetDistance(target, true);
  1172. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1173. success = true;
  1174. }
  1175. if (luaspell->targets.size() > 0) {
  1176. Spawn* target = 0;
  1177. ZoneServer* zone = luaspell->caster->GetZone();
  1178. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1179. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1180. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1181. float distance = caster->GetDistance(target, true);
  1182. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1183. }
  1184. }
  1185. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1186. success = true;
  1187. }
  1188. if (success) {
  1189. if (caster->GetZone())
  1190. caster->GetZone()->TriggerCharSheetTimer();
  1191. }
  1192. }
  1193. return 0;
  1194. }
  1195. int EQ2Emu_lua_AddItem(lua_State* state) {
  1196. if (!lua_interface)
  1197. return 0;
  1198. Spawn* spawn = lua_interface->GetSpawn(state);
  1199. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1200. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1201. // default of 1 quantity to add
  1202. if (quantity == 0)
  1203. quantity = 1;
  1204. if (spawn && spawn->IsPlayer()) {
  1205. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1206. if (client && item_id > 0) {
  1207. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1208. return 1;
  1209. }
  1210. }
  1211. lua_interface->SetBooleanValue(state, false);
  1212. return 1;
  1213. }
  1214. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1215. if (!lua_interface)
  1216. return 0;
  1217. Spawn* spawn = lua_interface->GetSpawn(state);
  1218. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1219. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1220. string location = lua_interface->GetStringValue(state, 4);
  1221. if (spawn && spawn->IsPlayer()) {
  1222. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1223. if (client && item_id > 0) {
  1224. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1225. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1226. else
  1227. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1228. if (send_messages) {
  1229. Item* item = master_item_list.GetItem(item_id);
  1230. if (item) {
  1231. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1232. string popup_text = "You receive " + item->name;
  1233. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1234. }
  1235. }
  1236. return 1;
  1237. }
  1238. }
  1239. lua_interface->SetBooleanValue(state, false);
  1240. return 1;
  1241. }
  1242. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1243. Spawn* spawn = lua_interface->GetSpawn(state);
  1244. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1245. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1246. // default of 1 to remove
  1247. if (quantity == 0)
  1248. quantity = 1;
  1249. Client* client;
  1250. Item* item;
  1251. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1252. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1253. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1254. if (client->RemoveItem(item, quantity)) {
  1255. lua_interface->SetBooleanValue(state, true);
  1256. return 1;
  1257. }
  1258. }
  1259. }
  1260. }
  1261. lua_interface->SetBooleanValue(state, false);
  1262. return 1;
  1263. }
  1264. int EQ2Emu_lua_HasItem(lua_State* state) {
  1265. Spawn* player = lua_interface->GetSpawn(state);
  1266. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1267. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1268. if (player && player->IsPlayer()) {
  1269. bool hasItem = false;
  1270. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1271. if (!hasItem)
  1272. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1273. lua_interface->SetBooleanValue(state, hasItem);
  1274. return 1;
  1275. }
  1276. lua_interface->SetBooleanValue(state, false);
  1277. return 1;
  1278. }
  1279. int EQ2Emu_lua_Spawn(lua_State* state) {
  1280. if (!lua_interface)
  1281. return 0;
  1282. ZoneServer* zone = lua_interface->GetZone(state);
  1283. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1284. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1285. float x = lua_interface->GetFloatValue(state, 4);
  1286. float y = lua_interface->GetFloatValue(state, 5);
  1287. float z = lua_interface->GetFloatValue(state, 6);
  1288. float heading = lua_interface->GetFloatValue(state, 7);
  1289. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1290. Spawn* spawn = zone->GetSpawn(spawn_id);
  1291. if (!spawn)
  1292. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1293. else {
  1294. spawn->SetX(x);
  1295. spawn->SetZ(z);
  1296. spawn->SetY(y,true,true);
  1297. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1298. spawn->SetHeading(heading);
  1299. if (restricted_npc)
  1300. spawn->AddAllowAccessSpawn(spawn);
  1301. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1302. bool scriptActive = false;
  1303. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1304. scriptActive = true;
  1305. spawn->SetSpawnScript(string(spawn_script));
  1306. }
  1307. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1308. zone->AddSpawn(spawn);
  1309. if (scriptActive) {
  1310. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1311. }
  1312. lua_interface->SetSpawnValue(state, spawn);
  1313. return 1;
  1314. }
  1315. }
  1316. else {
  1317. string output = "Invalid paramaters to LUA Spawn command: \n";
  1318. if (!zone)
  1319. output = output.append("\t").append("Missing zone reference. \n");
  1320. if (spawn_id == 0)
  1321. output = output.append("\t").append("Missing spawn_id.");
  1322. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1323. }
  1324. return 0;
  1325. }
  1326. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1327. if (!lua_interface)
  1328. return 0;
  1329. ZoneServer* zone = lua_interface->GetZone(state);
  1330. if (zone) {
  1331. lua_interface->SetStringValue(state, zone->GetZoneName());
  1332. return 1;
  1333. }
  1334. return 0;
  1335. }
  1336. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1337. if (!lua_interface)
  1338. return 0;
  1339. ZoneServer* zone = lua_interface->GetZone(state);
  1340. if (zone) {
  1341. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1342. return 1;
  1343. }
  1344. return 0;
  1345. }
  1346. int EQ2Emu_lua_GetZone(lua_State* state) {
  1347. if (!lua_interface)
  1348. return 0;
  1349. int32 zone_id = lua_interface->GetInt32Value(state);
  1350. ZoneServer* zone = 0;
  1351. if (zone_id > 0)
  1352. zone = zone_list.Get(zone_id);
  1353. else {
  1354. string zone_name = lua_interface->GetStringValue(state);
  1355. if (zone_name.length() > 0) {
  1356. zone = zone_list.Get(zone_name.c_str());
  1357. }
  1358. else {
  1359. Spawn* spawn = lua_interface->GetSpawn(state);
  1360. if (spawn)
  1361. zone = spawn->GetZone();
  1362. }
  1363. }
  1364. if (zone) {
  1365. lua_interface->SetZoneValue(state, zone);
  1366. return 1;
  1367. }
  1368. return 0;
  1369. }
  1370. int EQ2Emu_lua_AddHate(lua_State* state) {
  1371. Spawn* entity = lua_interface->GetSpawn(state);
  1372. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1373. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1374. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1375. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1376. if (entity && entity->IsEntity() && amount != 0) {
  1377. if (luaspell) {
  1378. ZoneServer* zone = luaspell->caster->GetZone();
  1379. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1380. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1381. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1382. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1383. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1384. if (send_packet)
  1385. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1386. }
  1387. }
  1388. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1389. }
  1390. else if (npc && npc->IsNPC() && npc->GetZone())
  1391. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1392. }
  1393. return 0;
  1394. }
  1395. int EQ2Emu_lua_Zone(lua_State* state) {
  1396. if (!lua_interface)
  1397. return 0;
  1398. ZoneServer* zone = lua_interface->GetZone(state);
  1399. Spawn* player = lua_interface->GetSpawn(state, 2);
  1400. Client* client = 0;
  1401. if (player && player->IsPlayer())
  1402. client = player->GetZone()->GetClientBySpawn(player);
  1403. float x = lua_interface->GetFloatValue(state, 3);
  1404. float y = lua_interface->GetFloatValue(state, 4);
  1405. float z = lua_interface->GetFloatValue(state, 5);
  1406. float heading = lua_interface->GetFloatValue(state, 6);
  1407. if (zone && client) {
  1408. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1409. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1410. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1411. {
  1412. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1413. return 0;
  1414. }
  1415. if (x != 0 || y != 0 || z != 0) {
  1416. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1417. player->SetX(x);
  1418. player->SetY(y);
  1419. player->SetZ(z);
  1420. player->SetHeading(heading);
  1421. client->Zone(zone->GetZoneName(), false);
  1422. }
  1423. else
  1424. client->Zone(zone->GetZoneName());
  1425. }
  1426. else
  1427. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1428. return 0;
  1429. }
  1430. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1431. if (!lua_interface)
  1432. return 0;
  1433. Spawn* spawn = lua_interface->GetSpawn(state);
  1434. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1435. if (spawn && spawn2)
  1436. spawn->AddAllowAccessSpawn(spawn2);
  1437. return 0;
  1438. }
  1439. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1440. if (!lua_interface)
  1441. return 0;
  1442. Spawn* target = lua_interface->GetSpawn(state);
  1443. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1444. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1445. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1446. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1447. if (!target) {
  1448. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1449. return 0;
  1450. }
  1451. if (!target->IsEntity()) {
  1452. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1453. return 0;
  1454. }
  1455. if (spell_id <= 0) {
  1456. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1457. return 0;
  1458. }
  1459. if (caster && !caster->IsEntity()) {
  1460. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1461. return 0;
  1462. }
  1463. if (spell_tier == 0)
  1464. spell_tier = 1;
  1465. if (!caster)
  1466. caster = target;
  1467. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1468. return 0;
  1469. }
  1470. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1471. if (!lua_interface)
  1472. return 0;
  1473. Spawn* target = lua_interface->GetSpawn(state);
  1474. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1475. if (!luaspell)
  1476. return 0;
  1477. Spawn* caster = luaspell->caster;
  1478. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1479. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1480. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1481. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1482. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1483. //lua_interface->ResetFunctionStack(state);
  1484. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1485. vector<int16> faction_req;
  1486. vector<int16> race_req;
  1487. int32 class_req = 0;
  1488. int32 i = 0;
  1489. int8 f = 0;
  1490. int8 r = 0;
  1491. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1492. if (class_id < 100) {
  1493. class_req += pow(2.0, double(class_id - 1));
  1494. }
  1495. else if (class_id > 100 && class_id < 1000) {
  1496. race_req.push_back(class_id);
  1497. r++;
  1498. }
  1499. else {
  1500. faction_req.push_back(class_id);
  1501. f++;
  1502. }
  1503. i++;
  1504. }
  1505. if (caster && caster->IsEntity()) {
  1506. bool race_match = false;
  1507. bool success = false;
  1508. luaspell->resisted = false;
  1509. if (luaspell->targets.size() > 0) {
  1510. ZoneServer* zone = luaspell->caster->GetZone();
  1511. Spawn* target = 0;
  1512. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1513. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1514. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1515. if (race_req.size() > 0) {
  1516. for (int8 i = 0; i < race_req.size(); i++) {
  1517. if (target->GetLuaRaceId() == race_req[i]) {
  1518. race_match = true;
  1519. }
  1520. }
  1521. }
  1522. else
  1523. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1524. if (race_match == true) {
  1525. float distance = caster->GetDistance(target, true);
  1526. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1527. }
  1528. }
  1529. }
  1530. success = true;
  1531. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1532. }
  1533. else if (target) {
  1534. //check class and race/faction here
  1535. if (race_req.size() > 0) {
  1536. for (int8 i = 0; i < race_req.size(); i++) {
  1537. if (target->GetLuaRaceId() == race_req[i]) {
  1538. race_match = true;
  1539. }
  1540. }
  1541. }
  1542. else
  1543. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1544. if (race_match == true) {
  1545. float distance = caster->GetDistance(target, true);
  1546. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1547. success = true;
  1548. }
  1549. }
  1550. if (success) {
  1551. Spell* spell = luaspell->spell;
  1552. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1553. ((Player*)caster)->InCombat(true);
  1554. if (caster->GetZone())
  1555. caster->GetZone()->TriggerCharSheetTimer();
  1556. }
  1557. }
  1558. }
  1559. return 0;
  1560. }
  1561. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1562. if (!lua_interface)
  1563. return 0;
  1564. Spawn* spawn = lua_interface->GetSpawn(state);
  1565. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1566. lua_interface->ResetFunctionStack(state);
  1567. if (spawn && value != 0) {
  1568. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1569. spawn->SetPower(spawn->GetTotalPower());
  1570. else
  1571. spawn->SetPower(spawn->GetPower() + value);
  1572. }
  1573. return 0;
  1574. }
  1575. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1576. if (!lua_interface)
  1577. return 0;
  1578. Spawn* spawn = lua_interface->GetSpawn(state);
  1579. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1580. lua_interface->ResetFunctionStack(state);
  1581. if (spawn && value != 0) {
  1582. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1583. spawn->SetHP(spawn->GetTotalHP());
  1584. else
  1585. spawn->SetHP(spawn->GetHP() + value);
  1586. }
  1587. return 0;
  1588. }
  1589. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1590. if (!lua_interface)
  1591. return 0;
  1592. Spawn* spawn = lua_interface->GetSpawn(state);
  1593. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1594. lua_interface->ResetFunctionStack(state);
  1595. if (spawn && value != 0) {
  1596. spawn->SetPower(spawn->GetPower() + value);
  1597. if (value > spawn->GetTotalHPBase())
  1598. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1599. }
  1600. return 0;
  1601. }
  1602. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1603. if (!lua_interface)
  1604. return 0;
  1605. Spawn* spawn = lua_interface->GetSpawn(state);
  1606. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1607. lua_interface->ResetFunctionStack(state);
  1608. if (spawn && value != 0) {
  1609. spawn->SetHP(spawn->GetHP() + value);
  1610. if (value > spawn->GetTotalHPBase())
  1611. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1612. }
  1613. return 0;
  1614. }
  1615. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1616. if (!lua_interface)
  1617. return 0;
  1618. Spawn* spawn = lua_interface->GetSpawn(state);
  1619. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1620. lua_interface->ResetFunctionStack(state);
  1621. if (spawn) {
  1622. spawn->SetHP(value);
  1623. if (value > spawn->GetTotalHPBase())
  1624. spawn->SetTotalHP(value);
  1625. }
  1626. return 0;
  1627. }
  1628. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1629. if (!lua_interface)
  1630. return 0;
  1631. Spawn* spawn = lua_interface->GetSpawn(state);
  1632. float value = lua_interface->GetFloatValue(state, 2);
  1633. lua_interface->ResetFunctionStack(state);
  1634. if (spawn && spawn->IsEntity() && value > 0)
  1635. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1636. if (spawn->IsPlayer())
  1637. ((Player*)spawn)->SetCharSheetChanged(true);
  1638. return 0;
  1639. }
  1640. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1641. if (!lua_interface)
  1642. return 0;
  1643. Spawn* spawn = lua_interface->GetSpawn(state);
  1644. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1645. lua_interface->ResetFunctionStack(state);
  1646. if (spawn && spawn->IsEntity() && value > 0)
  1647. ((Entity*)spawn)->SetTotalHPBase(value);
  1648. return 0;
  1649. }
  1650. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1651. if (!lua_interface)
  1652. return 0;
  1653. Spawn* spawn = lua_interface->GetSpawn(state);
  1654. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1655. lua_interface->ResetFunctionStack(state);
  1656. if (spawn && value > 0) {
  1657. spawn->SetPower(value);
  1658. if (value > spawn->GetTotalPowerBase())
  1659. spawn->SetTotalPower(value);
  1660. }
  1661. return 0;
  1662. }
  1663. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1664. if (!lua_interface)
  1665. return 0;
  1666. Spawn* spawn = lua_interface->GetSpawn(state);
  1667. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1668. lua_interface->ResetFunctionStack(state);
  1669. if (spawn && spawn->IsEntity() && value > 0)
  1670. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1671. return 0;
  1672. }
  1673. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1674. if (!lua_interface)
  1675. return 0;
  1676. Spawn* spawn = lua_interface->GetSpawn(state);
  1677. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1678. lua_interface->ResetFunctionStack(state);
  1679. if (spawn && spawn->IsEntity() && value > 0)
  1680. ((Entity*)spawn)->SetTotalPowerBase(value);
  1681. return 0;
  1682. }
  1683. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1684. if (!lua_interface)
  1685. return 0;
  1686. Spawn* spawn = lua_interface->GetSpawn(state);
  1687. float x = lua_interface->GetFloatValue(state, 2);
  1688. float y = lua_interface->GetFloatValue(state, 3);
  1689. float z = lua_interface->GetFloatValue(state, 4);
  1690. float heading = lua_interface->GetFloatValue(state, 5);
  1691. lua_interface->ResetFunctionStack(state);
  1692. if (spawn) {
  1693. spawn->SetX(x);
  1694. spawn->SetY(y);
  1695. spawn->SetZ(z);
  1696. if (heading != 0)
  1697. spawn->SetHeading(heading);
  1698. spawn->SetSpawnOrigX(spawn->GetX());
  1699. spawn->SetSpawnOrigY(spawn->GetY());
  1700. spawn->SetSpawnOrigZ(spawn->GetZ());
  1701. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1702. if (spawn->IsPlayer()) {
  1703. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1704. if (client) {
  1705. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1706. client->QueuePacket(packet);
  1707. }
  1708. }
  1709. }
  1710. return 0;
  1711. }
  1712. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1713. if (!lua_interface)
  1714. return 0;
  1715. Spawn* spawn = lua_interface->GetSpawn(state);
  1716. float value = lua_interface->GetFloatValue(state, 2);
  1717. lua_interface->ResetFunctionStack(state);
  1718. if (spawn) {
  1719. spawn->SetHeading(value);
  1720. if (spawn->IsPlayer()) {
  1721. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1722. if (client) {
  1723. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1724. client->QueuePacket(packet);
  1725. }
  1726. }
  1727. }
  1728. return 0;
  1729. }
  1730. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1731. if (!lua_interface)
  1732. return 0;
  1733. Spawn* spawn = lua_interface->GetSpawn(state);
  1734. int16 value = lua_interface->GetInt16Value(state, 2);
  1735. lua_interface->ResetFunctionStack(state);
  1736. if (spawn)
  1737. spawn->SetModelType(value);
  1738. return 0;
  1739. }
  1740. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1741. if (!lua_interface)
  1742. return 0;
  1743. Spawn* spawn = lua_interface->GetSpawn(state);
  1744. int8 value = lua_interface->GetInt8Value(state, 2);
  1745. lua_interface->ResetFunctionStack(state);
  1746. if (spawn) {
  1747. if (spawn->IsPlayer())
  1748. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1749. else
  1750. spawn->SetAdventureClass(value);
  1751. }
  1752. return 0;
  1753. }
  1754. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1755. if (!lua_interface)
  1756. return 0;
  1757. Spawn* spawn = lua_interface->GetSpawn(state);
  1758. int8 value = lua_interface->GetInt8Value(state, 2);
  1759. lua_interface->ResetFunctionStack(state);
  1760. if (spawn) {
  1761. spawn->SetTradeskillClass(value);
  1762. if (spawn->IsEntity()) {
  1763. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1764. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1765. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1766. }
  1767. if (spawn->IsPlayer())
  1768. ((Player*)spawn)->SetCharSheetChanged(true);
  1769. }
  1770. return 0;
  1771. }
  1772. int EQ2Emu_lua_SetMount(lua_State* state) {
  1773. if (!lua_interface)
  1774. return 0;
  1775. Spawn* spawn = lua_interface->GetSpawn(state);
  1776. int16 value = lua_interface->GetInt16Value(state, 2);
  1777. if (spawn && spawn->IsEntity()) {
  1778. ((Entity*)spawn)->SetMount(value);
  1779. EQ2_Color color;
  1780. color.red = 255;
  1781. color.green = 255;
  1782. color.blue = 255;
  1783. ((Entity*)spawn)->SetMountColor(&color);
  1784. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1785. }
  1786. return 0;
  1787. }
  1788. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1789. if (!lua_interface)
  1790. return 0;
  1791. Spawn* spawn = lua_interface->GetSpawn(state);
  1792. EQ2_Color mount_color;
  1793. EQ2_Color saddle_color;
  1794. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1795. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1796. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1797. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1798. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1799. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1800. if (spawn && spawn->IsEntity()) {
  1801. ((Entity*)spawn)->SetMountColor(&mount_color);
  1802. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1803. }
  1804. return 0;
  1805. }
  1806. int EQ2Emu_lua_GetMount(lua_State* state) {
  1807. if (!lua_interface)
  1808. return 0;
  1809. Spawn* spawn = lua_interface->GetSpawn(state);
  1810. if (spawn && spawn->IsEntity()) {
  1811. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1812. return 1;
  1813. }
  1814. return 0;
  1815. }
  1816. int EQ2Emu_lua_GetRace(lua_State* state) {
  1817. if (!lua_interface)
  1818. return 0;
  1819. Spawn* spawn = lua_interface->GetSpawn(state);
  1820. if (spawn)
  1821. {
  1822. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1823. lua_interface->SetInt32Value(state, spawn->GetRace());
  1824. return 1;
  1825. }
  1826. return 0;
  1827. }
  1828. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1829. if (!lua_interface)
  1830. return 0;
  1831. Spawn* spawn = lua_interface->GetSpawn(state);
  1832. if (spawn) {
  1833. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1834. return 1;
  1835. }
  1836. return 0;
  1837. }
  1838. int EQ2Emu_lua_GetClass(lua_State* state) {
  1839. Spawn* spawn = lua_interface->GetSpawn(state);
  1840. if (spawn) {
  1841. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1842. return 1;
  1843. }
  1844. return 0;
  1845. }
  1846. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1847. Spawn* spawn = lua_interface->GetSpawn(state);
  1848. if (spawn) {
  1849. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1850. return 1;
  1851. }
  1852. return 0;
  1853. }
  1854. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1855. if (!lua_interface)
  1856. return 0;
  1857. Spawn* spawn = lua_interface->GetSpawn(state);
  1858. float value = lua_interface->GetFloatValue(state, 2);
  1859. lua_interface->ResetFunctionStack(state);
  1860. if (spawn) {
  1861. printf("Speed set lua: %f\n",value);
  1862. spawn->SetSpeed(value);
  1863. ((Entity*)spawn)->SetSpeed(value);
  1864. if (spawn->IsPlayer()) {
  1865. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1866. if (client) {
  1867. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1868. if (packet) {
  1869. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1870. packet->setDataByName("speed", value);
  1871. packet->setDataByName("size", 0.51);
  1872. EQ2Packet* app = packet->serialize();
  1873. client->QueuePacket(app);
  1874. safe_delete(packet);
  1875. }
  1876. }
  1877. }
  1878. }
  1879. return 0;
  1880. }
  1881. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1882. if (!lua_interface)
  1883. return 0;
  1884. Spawn* spawn = lua_interface->GetSpawn(state);
  1885. const int16 type = lua_interface->GetInt16Value(state, 2);
  1886. const float value = lua_interface->GetFloatValue(state, 3);
  1887. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1888. int64 class_req = 0;
  1889. int32 class_id = 0;
  1890. vector<int16> faction_req;
  1891. vector<int16> race_req;
  1892. int32 i = 0;
  1893. int8 f = 0;
  1894. int8 r = 0;
  1895. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1896. if (class_id < 100) {
  1897. class_req += pow(2.0, double(class_id - 1));
  1898. }
  1899. else if (class_id > 100 && class_id < 1000) {
  1900. race_req.push_back(class_id);
  1901. r++;
  1902. }
  1903. else {
  1904. faction_req.push_back(class_id);
  1905. f++;
  1906. }
  1907. i++;
  1908. }
  1909. if (value != 0 && type >= 0) {
  1910. if (luaspell && luaspell->spell && luaspell->caster) {
  1911. ZoneServer* zone = luaspell->caster->GetZone();
  1912. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1913. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1914. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1915. if (target) {
  1916. if (target->IsPlayer()) {
  1917. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1918. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1919. if (((Player*)target)->GetGroupMemberInfo())
  1920. ((Player*)target)->UpdateGroupMemberInfo();
  1921. ((Player*)target)->SetCharSheetChanged(true);
  1922. }
  1923. else if (target->IsNPC())
  1924. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1925. else
  1926. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1927. }
  1928. }
  1929. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1930. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1931. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1932. }
  1933. else if (spawn && spawn->IsEntity()) {
  1934. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1935. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1936. if (spawn->IsPlayer())
  1937. ((Player*)spawn)->SetCharSheetChanged(true);
  1938. }
  1939. else
  1940. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1941. }
  1942. else
  1943. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1944. return 0;
  1945. }
  1946. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1947. if (!lua_interface)
  1948. return 0;
  1949. Spawn* spawn = lua_interface->GetSpawn(state);
  1950. int16 type = lua_interface->GetInt16Value(state, 2);
  1951. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1952. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1953. if (!spawn) {
  1954. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1955. return 0;
  1956. }
  1957. if (!spawn->IsEntity()) {
  1958. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1959. return 0;
  1960. }
  1961. if (value == 0) {
  1962. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1963. return 0;
  1964. }
  1965. if (!luaspell || !luaspell->spell) {
  1966. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1967. return 0;
  1968. }
  1969. int32 class_req = 0;
  1970. vector<int16> faction_req;
  1971. vector<int16> race_req;
  1972. int32 class_id = 0;
  1973. int32 i = 0;
  1974. int8 f = 0;
  1975. int8 r = 0;
  1976. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1977. if (class_id < 100) {
  1978. class_req += pow(2.0, double(class_id - 1));
  1979. }
  1980. else if (class_id > 100 && class_id < 1000) {
  1981. race_req.push_back(class_id);
  1982. r++;
  1983. }
  1984. else {
  1985. faction_req.push_back(class_id);
  1986. f++;
  1987. }
  1988. i++;
  1989. }
  1990. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1991. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1992. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1993. if (spawn->IsPlayer())
  1994. ((Player*)spawn)->SetCharSheetChanged(true);
  1995. return 0;
  1996. }
  1997. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  1998. if (!lua_interface)
  1999. return 0;
  2000. Spawn* spawn = lua_interface->GetSpawn(state);
  2001. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2002. if (!spawn) {
  2003. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2004. return 0;
  2005. }
  2006. if (!spawn->IsEntity()) {
  2007. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2008. return 0;
  2009. }
  2010. if (!luaspell || !luaspell->spell) {
  2011. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2012. return 0;
  2013. }
  2014. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2015. if (spawn->IsPlayer())
  2016. ((Player*)spawn)->SetCharSheetChanged(true);
  2017. return 0;
  2018. }
  2019. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2020. if (!lua_interface)
  2021. return 0;
  2022. Spawn* spawn = lua_interface->GetSpawn(state);
  2023. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2024. if (luaspell && luaspell->spell) {
  2025. ZoneServer* zone = luaspell->caster->GetZone();
  2026. Spawn* target = 0;
  2027. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2028. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2029. target = zone->GetSpawnByID(luaspell->targets[i]);
  2030. if (target && target->IsEntity()) {
  2031. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2032. if (target->IsPlayer())
  2033. ((Player*)target)->SetCharSheetChanged(true);
  2034. }
  2035. }
  2036. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2037. }
  2038. else if (spawn && spawn->IsEntity()) {
  2039. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2040. if (spawn->IsPlayer())
  2041. ((Player*)spawn)->SetCharSheetChanged(true);
  2042. }
  2043. return 0;
  2044. }
  2045. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2046. if (!lua_interface)
  2047. return 0;
  2048. Spawn* spawn = lua_interface->GetSpawn(state);
  2049. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2050. float value = lua_interface->GetFloatValue(state, 3);
  2051. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2052. if (value != 0) {
  2053. int32 spell_id = 0;
  2054. if (luaspell && luaspell->spell && luaspell->caster) {
  2055. spell_id = luaspell->spell->GetSpellID();
  2056. ZoneServer* zone = luaspell->caster->GetZone();
  2057. Spawn* target = 0;
  2058. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2059. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2060. target = zone->GetSpawnByID(luaspell->targets[i]);
  2061. if (target && target->Alive()) {
  2062. if (target->IsPlayer()) {
  2063. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2064. Client* client = target->GetZone()->GetClientBySpawn(target);
  2065. if (client) {
  2066. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2067. if (packet)
  2068. client->QueuePacket(packet);
  2069. }
  2070. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2071. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2072. }
  2073. else if (target->IsNPC()) {
  2074. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2075. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2076. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2077. }
  2078. else
  2079. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2080. }
  2081. }
  2082. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2083. }
  2084. else if (spawn) {
  2085. if (spawn->IsPlayer()) {
  2086. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2087. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2088. if (client) {
  2089. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2090. if (packet)
  2091. client->QueuePacket(packet);
  2092. }
  2093. }
  2094. else if (spawn->IsNPC())
  2095. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2096. else
  2097. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2098. }
  2099. }
  2100. else
  2101. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2102. return 0;
  2103. }
  2104. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2105. if (!lua_interface)
  2106. return 0;
  2107. Spawn* spawn = lua_interface->GetSpawn(state);
  2108. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2109. if (spawn && spawn->IsPlayer()) {
  2110. int32 spell_id = 0;
  2111. if (luaspell && luaspell->spell) {
  2112. spell_id = luaspell->spell->GetSpellID();
  2113. ZoneServer* zone = luaspell->caster->GetZone();
  2114. Spawn* target = 0;
  2115. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2116. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2117. target = zone->GetSpawnByID(luaspell->targets[i]);
  2118. if (target) {
  2119. if (target->IsPlayer()) {
  2120. ((Player*)target)->RemoveSkillBonus(spell_id);
  2121. Client* client = target->GetZone()->GetClientBySpawn(target);
  2122. if (client) {
  2123. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2124. if (packet)
  2125. client->QueuePacket(packet);
  2126. }
  2127. }
  2128. else if (target->IsNPC())
  2129. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2130. else
  2131. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2132. }
  2133. }
  2134. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2135. }
  2136. else if (spawn) {
  2137. if (spawn->IsPlayer()) {
  2138. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2139. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2140. if (client) {
  2141. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2142. if (packet)
  2143. client->QueuePacket(packet);
  2144. }
  2145. }
  2146. else if (spawn->IsNPC())
  2147. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2148. else
  2149. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2150. }
  2151. }
  2152. return 0;
  2153. }
  2154. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2155. if (!lua_interface)
  2156. return 0;
  2157. Spawn* spawn = lua_interface->GetSpawn(state);
  2158. int8 type = lua_interface->GetInt32Value(state, 2);
  2159. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2160. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2161. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2162. ZoneServer* zone = luaspell->caster->GetZone();
  2163. Spawn* target = 0;
  2164. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2165. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2166. target = zone->GetSpawnByID(luaspell->targets[i]);
  2167. if (target && target->IsEntity()) {
  2168. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2169. ((Entity*)target)->AddMezSpell(luaspell);
  2170. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2171. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2172. if (target->IsNPC())
  2173. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2174. }
  2175. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2176. ((Entity*)target)->AddStifleSpell(luaspell);
  2177. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2178. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2179. if (target->IsNPC())
  2180. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2181. }
  2182. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2183. ((Entity*)target)->AddDazeSpell(luaspell);
  2184. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2185. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2186. if (target->IsNPC())
  2187. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2188. }
  2189. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2190. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2191. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2192. ((Entity*)target)->AddStunSpell(luaspell);
  2193. if (target->IsNPC())
  2194. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2195. }
  2196. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2197. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2198. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2199. ((Entity*)target)->AddRootSpell(luaspell);
  2200. if (target->IsNPC())
  2201. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2202. }
  2203. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2204. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2205. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2206. ((Entity*)target)->AddFearSpell(luaspell);
  2207. if (target->IsNPC())
  2208. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2209. }
  2210. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2211. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2212. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2213. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2214. }
  2215. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2216. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2217. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2218. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2219. }
  2220. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2221. ((Entity*)target)->AddSnareSpell(luaspell);
  2222. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2223. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2224. if (target->IsNPC())
  2225. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2226. }
  2227. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2228. ((Entity*)target)->AddFlightSpell(luaspell);
  2229. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2230. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2231. }
  2232. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2233. ((Entity*)target)->AddGlideSpell(luaspell);
  2234. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2235. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2236. }
  2237. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2238. ((Entity*)target)->AddSafefallSpell(luaspell);
  2239. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2240. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2241. }
  2242. else
  2243. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2244. }
  2245. else
  2246. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2247. }
  2248. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2249. }
  2250. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2251. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2252. ((Entity*)spawn)->AddMezSpell(luaspell);
  2253. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2254. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2255. }
  2256. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2257. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2258. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2259. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2260. }
  2261. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2262. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2263. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2264. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2265. }
  2266. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2267. ((Entity*)spawn)->AddStunSpell(luaspell);
  2268. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2269. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2270. }
  2271. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2272. ((Entity*)spawn)->AddRootSpell(luaspell);
  2273. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2274. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2275. }
  2276. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2277. ((Entity*)spawn)->AddFearSpell(luaspell);
  2278. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2279. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2280. }
  2281. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2282. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2283. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2284. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2285. }
  2286. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2287. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2288. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2289. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2290. }
  2291. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2292. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2293. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2294. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2295. }
  2296. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2297. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2298. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2299. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2300. }
  2301. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2302. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2303. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2304. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2305. }
  2306. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2307. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2308. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2309. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2310. }
  2311. else
  2312. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2313. }
  2314. else
  2315. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2316. return 0;
  2317. }
  2318. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2319. if (!lua_interface)
  2320. return 0;
  2321. Spawn* spawn = lua_interface->GetSpawn(state);
  2322. int8 type = lua_interface->GetInt8Value(state, 2);
  2323. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2324. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2325. if (spawn && spawn->IsEntity()) {
  2326. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2327. ZoneServer* zone = luaspell->caster->GetZone();
  2328. Spawn* target = 0;
  2329. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2330. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2331. target = zone->GetSpawnByID(luaspell->targets[i]);
  2332. if (target) {
  2333. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2334. ((Entity*)target)->RemoveMezSpell(luaspell);
  2335. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2336. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2337. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2338. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2339. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2340. ((Entity*)target)->RemoveStunSpell(luaspell);
  2341. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2342. ((Entity*)target)->RemoveRootSpell(luaspell);
  2343. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2344. ((Entity*)target)->RemoveFearSpell(luaspell);
  2345. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2346. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2347. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2348. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2349. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2350. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2351. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2352. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2353. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2354. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2355. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2356. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2357. else
  2358. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2359. }
  2360. }
  2361. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2362. }
  2363. else if (only_remove_spawn) {
  2364. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2365. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2366. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2367. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2368. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2369. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2370. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2371. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2372. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2373. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2374. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2375. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2376. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2377. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2378. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2379. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2380. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2381. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2382. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2383. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2384. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2385. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2386. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2387. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2388. else
  2389. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2390. }
  2391. }
  2392. return 0;
  2393. }
  2394. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2395. if (!lua_interface)
  2396. return 0;
  2397. Spawn* spawn = lua_interface->GetSpawn(state);
  2398. int8 type = lua_interface->GetInt8Value(state, 2);
  2399. bool hasEffect = false;
  2400. if (!spawn)
  2401. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2402. else if (!spawn->IsEntity())
  2403. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2404. else if (type < CONTROL_MAX_EFFECTS)
  2405. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2406. else
  2407. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2408. lua_interface->SetBooleanValue(state, hasEffect);
  2409. return 1;
  2410. }
  2411. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2412. if (!lua_interface)
  2413. return 0;
  2414. Spawn* spawn = lua_interface->GetSpawn(state);
  2415. float distance = 0.0f;
  2416. if (!spawn)
  2417. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2418. else if (!spawn->IsNPC())
  2419. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2420. else
  2421. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2422. lua_interface->SetFloatValue(state, distance);
  2423. return 1;
  2424. }
  2425. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2426. if (!lua_interface)
  2427. return 0;
  2428. Spawn* spawn = lua_interface->GetSpawn(state);
  2429. float distance = 0.0f;
  2430. if (!spawn)
  2431. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2432. else if (!spawn->IsNPC())
  2433. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2434. else
  2435. distance = ((NPC*)spawn)->GetAggroRadius();
  2436. lua_interface->SetFloatValue(state, distance);
  2437. return 1;
  2438. }
  2439. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2440. if (!lua_interface)
  2441. return 0;
  2442. Spawn* spawn = lua_interface->GetSpawn(state);
  2443. float distance = lua_interface->GetFloatValue(state, 2);
  2444. bool override = lua_interface->GetBooleanValue(state, 3);
  2445. bool result = false;
  2446. lua_interface->ResetFunctionStack(state);
  2447. if (!spawn)
  2448. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2449. else if (!spawn->IsNPC())
  2450. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2451. else
  2452. {
  2453. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2454. result = true;
  2455. }
  2456. lua_interface->SetBooleanValue(state, result);
  2457. return 1;
  2458. }
  2459. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2460. if (!lua_interface)
  2461. return 0;
  2462. Spawn* spawn = lua_interface->GetSpawn(state);
  2463. int16 value = lua_interface->GetInt16Value(state, 2);
  2464. if (spawn && spawn->IsEntity()) {
  2465. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2466. if (spawn->IsPlayer())
  2467. ((Player*)spawn)->SetCharSheetChanged(true);
  2468. }
  2469. return 0;
  2470. }
  2471. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2472. if (!lua_interface)
  2473. return 0;
  2474. Spawn* spawn = lua_interface->GetSpawn(state);
  2475. int16 value = lua_interface->GetInt16Value(state, 2);
  2476. if (spawn && spawn->IsEntity()) {
  2477. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2478. if (spawn->IsPlayer())
  2479. ((Player*)spawn)->SetCharSheetChanged(true);
  2480. }
  2481. return 0;
  2482. }
  2483. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2484. if (!lua_interface)
  2485. return 0;
  2486. Spawn* spawn = lua_interface->GetSpawn(state);
  2487. int16 value = lua_interface->GetInt16Value(state, 2);
  2488. if (spawn && spawn->IsEntity()) {
  2489. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2490. if (spawn->IsPlayer())
  2491. ((Player*)spawn)->SetCharSheetChanged(true);
  2492. }
  2493. return 0;
  2494. }
  2495. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2496. if (!lua_interface)
  2497. return 0;
  2498. Spawn* spawn = lua_interface->GetSpawn(state);
  2499. int16 value = lua_interface->GetInt16Value(state, 2);
  2500. if (spawn && spawn->IsEntity()) {
  2501. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2502. if (spawn->IsPlayer())
  2503. ((Player*)spawn)->SetCharSheetChanged(true);
  2504. }
  2505. return 0;
  2506. }
  2507. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2508. if (!lua_interface)
  2509. return 0;
  2510. Spawn* spawn = lua_interface->GetSpawn(state);
  2511. int16 value = lua_interface->GetInt16Value(state, 2);
  2512. if (spawn && spawn->IsEntity()) {
  2513. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2514. if (spawn->IsPlayer())
  2515. ((Player*)spawn)->SetCharSheetChanged(true);
  2516. }
  2517. return 0;
  2518. }
  2519. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2520. if (!lua_interface)
  2521. return 0;
  2522. Spawn* spawn = lua_interface->GetSpawn(state);
  2523. int8 value = lua_interface->GetInt8Value(state, 2);
  2524. if (spawn && spawn->IsEntity()) {
  2525. ((Entity*)spawn)->SetDeity(value);
  2526. if (spawn->IsPlayer())
  2527. ((Player*)spawn)->SetCharSheetChanged(true);
  2528. }
  2529. lua_interface->ResetFunctionStack(state);
  2530. return 0;
  2531. }
  2532. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2533. if (!lua_interface)
  2534. return 0;
  2535. Spawn* spawn = lua_interface->GetSpawn(state);
  2536. if (spawn && spawn->IsEntity()) {
  2537. int8 deity = ((Entity*)spawn)->GetDeity();
  2538. lua_interface->SetInt32Value(state, deity);
  2539. return 1;
  2540. }
  2541. return 0;
  2542. }
  2543. int EQ2Emu_lua_SetInt(lua_State* state) {
  2544. if (!lua_interface)
  2545. return 0;
  2546. Spawn* spawn = lua_interface->GetSpawn(state);
  2547. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2548. if (spawn && spawn->IsEntity()) {
  2549. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2550. if (spawn->IsPlayer())
  2551. ((Player*)spawn)->SetCharSheetChanged(true);
  2552. }
  2553. return 0;
  2554. }
  2555. int EQ2Emu_lua_SetWis(lua_State* state) {
  2556. if (!lua_interface)
  2557. return 0;
  2558. Spawn* spawn = lua_interface->GetSpawn(state);
  2559. float value = lua_interface->GetFloatValue(state, 2);
  2560. if (spawn && spawn->IsEntity()) {
  2561. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2562. if (spawn->IsPlayer())
  2563. ((Player*)spawn)->SetCharSheetChanged(true);
  2564. }
  2565. return 0;
  2566. }
  2567. int EQ2Emu_lua_SetSta(lua_State* state) {
  2568. if (!lua_interface)
  2569. return 0;
  2570. Spawn* spawn = lua_interface->GetSpawn(state);
  2571. float value = lua_interface->GetFloatValue(state, 2);
  2572. if (spawn && spawn->IsEntity()) {
  2573. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2574. if (spawn->IsPlayer())
  2575. ((Player*)spawn)->SetCharSheetChanged(true);
  2576. }
  2577. return 0;
  2578. }
  2579. int EQ2Emu_lua_SetStr(lua_State* state) {
  2580. if (!lua_interface)
  2581. return 0;
  2582. Spawn* spawn = lua_interface->GetSpawn(state);
  2583. float value = lua_interface->GetFloatValue(state, 2);
  2584. if (spawn && spawn->IsEntity()) {
  2585. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2586. if (spawn->IsPlayer())
  2587. ((Player*)spawn)->SetCharSheetChanged(true);
  2588. }
  2589. return 0;
  2590. }
  2591. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2592. if (!lua_interface)
  2593. return 0;
  2594. Spawn* spawn = lua_interface->GetSpawn(state);
  2595. float value = lua_interface->GetFloatValue(state, 2);
  2596. if (spawn && spawn->IsEntity()) {
  2597. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2598. if (spawn->IsPlayer())
  2599. ((Player*)spawn)->SetCharSheetChanged(true);
  2600. }
  2601. return 0;
  2602. }
  2603. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2604. if (!lua_interface)
  2605. return 0;
  2606. Spawn* spawn = lua_interface->GetSpawn(state);
  2607. if (spawn) {
  2608. lua_interface->SetInt32Value(state, spawn->GetHP());
  2609. return 1;
  2610. }
  2611. return 0;
  2612. }
  2613. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2614. if (!lua_interface)
  2615. return 0;
  2616. Spawn* spawn = lua_interface->GetSpawn(state);
  2617. if (spawn) {
  2618. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2619. return 1;
  2620. }
  2621. return 0;
  2622. }
  2623. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2624. if (!lua_interface)
  2625. return 0;
  2626. Spawn* spawn = lua_interface->GetSpawn(state);
  2627. if (spawn) {
  2628. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2629. return 1;
  2630. }
  2631. return 0;
  2632. }
  2633. int EQ2Emu_lua_GetName(lua_State* state) {
  2634. if (!lua_interface)
  2635. return 0;
  2636. Spawn* spawn = lua_interface->GetSpawn(state);
  2637. if (spawn) {
  2638. lua_interface->SetStringValue(state, spawn->GetName());
  2639. return 1;
  2640. }
  2641. return 0;
  2642. }
  2643. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2644. Spawn* spawn = lua_interface->GetSpawn(state);
  2645. if (spawn) {
  2646. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2647. return 1;
  2648. }
  2649. return 0;
  2650. }
  2651. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2652. if (!lua_interface)
  2653. return 0;
  2654. Spawn* spawn = lua_interface->GetSpawn(state);
  2655. if (spawn) {
  2656. lua_interface->SetInt32Value(state, spawn->GetPower());
  2657. return 1;
  2658. }
  2659. return 0;
  2660. }
  2661. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2662. if (!lua_interface)
  2663. return 0;
  2664. Spawn* spawn = lua_interface->GetSpawn(state);
  2665. if (spawn) {
  2666. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2667. return 1;
  2668. }
  2669. return 0;
  2670. }
  2671. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2672. if (!lua_interface)
  2673. return 0;
  2674. Spawn* spawn = lua_interface->GetSpawn(state);
  2675. if (spawn) {
  2676. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2677. return 1;
  2678. }
  2679. return 0;
  2680. }
  2681. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2682. if (!lua_interface)
  2683. return 0;
  2684. Spawn* spawn = lua_interface->GetSpawn(state);
  2685. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2686. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2687. if (spawn && spawn2) {
  2688. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2689. lua_interface->SetFloatValue(state, distance);
  2690. return 1;
  2691. }
  2692. return 0;
  2693. }
  2694. int EQ2Emu_lua_GetX(lua_State* state) {
  2695. if (!lua_interface)
  2696. return 0;
  2697. Spawn* spawn = lua_interface->GetSpawn(state);
  2698. if (spawn) {
  2699. lua_interface->SetFloatValue(state, spawn->GetX());
  2700. return 1;
  2701. }
  2702. return 0;
  2703. }
  2704. int EQ2Emu_lua_GetY(lua_State* state) {
  2705. if (!lua_interface)
  2706. return 0;
  2707. Spawn* spawn = lua_interface->GetSpawn(state);
  2708. if (spawn) {
  2709. lua_interface->SetFloatValue(state, spawn->GetY());
  2710. return 1;
  2711. }
  2712. return 0;
  2713. }
  2714. int EQ2Emu_lua_GetZ(lua_State* state) {
  2715. if (!lua_interface)
  2716. return 0;
  2717. Spawn* spawn = lua_interface->GetSpawn(state);
  2718. if (spawn) {
  2719. lua_interface->SetFloatValue(state, spawn->GetZ());
  2720. return 1;
  2721. }
  2722. return 0;
  2723. }
  2724. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2725. if (!lua_interface)
  2726. return 0;
  2727. Spawn* spawn = lua_interface->GetSpawn(state);
  2728. if (spawn) {
  2729. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2730. return 1;
  2731. }
  2732. return 0;
  2733. }
  2734. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2735. if (!lua_interface)
  2736. return 0;
  2737. Spawn* spawn = lua_interface->GetSpawn(state);
  2738. if (spawn) {
  2739. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2740. return 1;
  2741. }
  2742. return 0;
  2743. }
  2744. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2745. if (!lua_interface)
  2746. return 0;
  2747. Spawn* spawn = lua_interface->GetSpawn(state);
  2748. if (spawn) {
  2749. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2750. return 1;
  2751. }
  2752. return 0;
  2753. }
  2754. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2755. if (!lua_interface)
  2756. return 0;
  2757. Spawn* spawn = lua_interface->GetSpawn(state);
  2758. if (spawn && spawn->IsEntity()) {
  2759. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2760. return 1;
  2761. }
  2762. return 0;
  2763. }
  2764. int EQ2Emu_lua_GetInt(lua_State* state) {
  2765. if (!lua_interface)
  2766. return 0;
  2767. Spawn* spawn = lua_interface->GetSpawn(state);
  2768. if (spawn && spawn->IsEntity()) {
  2769. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2770. return 1;
  2771. }
  2772. return 0;
  2773. }
  2774. int EQ2Emu_lua_GetWis(lua_State* state) {
  2775. if (!lua_interface)
  2776. return 0;
  2777. Spawn* spawn = lua_interface->GetSpawn(state);
  2778. if (spawn && spawn->IsEntity()) {
  2779. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2780. return 1;
  2781. }
  2782. return 0;
  2783. }
  2784. int EQ2Emu_lua_GetSta(lua_State* state) {
  2785. if (!lua_interface)
  2786. return 0;
  2787. Spawn* spawn = lua_interface->GetSpawn(state);
  2788. if (spawn && spawn->IsEntity()) {
  2789. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2790. return 1;
  2791. }
  2792. return 0;
  2793. }
  2794. int EQ2Emu_lua_GetStr(lua_State* state) {
  2795. if (!lua_interface)
  2796. return 0;
  2797. Spawn* spawn = lua_interface->GetSpawn(state);
  2798. if (spawn && spawn->IsEntity()) {
  2799. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2800. return 1;
  2801. }
  2802. return 0;
  2803. }
  2804. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2805. if (!lua_interface)
  2806. return 0;
  2807. Spawn* spawn = lua_interface->GetSpawn(state);
  2808. if (spawn && spawn->IsEntity()) {
  2809. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2810. return 1;
  2811. }
  2812. return 0;
  2813. }
  2814. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2815. if (!lua_interface)
  2816. return 0;
  2817. Spawn* spawn = lua_interface->GetSpawn(state);
  2818. if (spawn && spawn->IsEntity()) {
  2819. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2820. return 1;
  2821. }
  2822. return 0;
  2823. }
  2824. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2825. if (!lua_interface)
  2826. return 0;
  2827. Spawn* spawn = lua_interface->GetSpawn(state);
  2828. if (spawn && spawn->IsEntity()) {
  2829. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2830. return 1;
  2831. }
  2832. return 0;
  2833. }
  2834. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2835. if (!lua_interface)
  2836. return 0;
  2837. Spawn* spawn = lua_interface->GetSpawn(state);
  2838. if (spawn && spawn->IsEntity()) {
  2839. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2840. return 1;
  2841. }
  2842. return 0;
  2843. }
  2844. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2845. if (!lua_interface)
  2846. return 0;
  2847. Spawn* spawn = lua_interface->GetSpawn(state);
  2848. if (spawn && spawn->IsEntity()) {
  2849. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2850. return 1;
  2851. }
  2852. return 0;
  2853. }
  2854. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2855. if (!lua_interface)
  2856. return 0;
  2857. Spawn* spawn = lua_interface->GetSpawn(state);
  2858. if (spawn && spawn->IsEntity()) {
  2859. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2860. return 1;
  2861. }
  2862. return 0;
  2863. }
  2864. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2865. if (!lua_interface)
  2866. return 0;
  2867. Spawn* player = lua_interface->GetSpawn(state);
  2868. if (!player || !player->IsPlayer()) {
  2869. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2870. return 0;
  2871. }
  2872. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2873. if (quest_id <= 0) {
  2874. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2875. return 0;
  2876. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2877. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2878. return 0;
  2879. }
  2880. int32 step = lua_interface->GetInt32Value(state, 3);
  2881. if (step > 0) {
  2882. Client* client = player->GetZone()->GetClientBySpawn(player);
  2883. if (client)
  2884. client->AddPendingQuestUpdate(quest_id, step);
  2885. } else {
  2886. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2887. }
  2888. return 0;
  2889. }
  2890. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2891. Spawn* player = lua_interface->GetSpawn(state);
  2892. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2893. int32 step = lua_interface->GetInt32Value(state, 3);
  2894. int32 progress = lua_interface->GetInt32Value(state, 4);
  2895. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2896. Client* client = player->GetZone()->GetClientBySpawn(player);
  2897. if (client)
  2898. client->AddPendingQuestUpdate(quest_id, step, progress);
  2899. }
  2900. return 0;
  2901. }
  2902. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2903. if (!lua_interface)
  2904. return 0;
  2905. Spawn* player = lua_interface->GetSpawn(state);
  2906. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2907. if (player && player->IsPlayer() && quest_id > 0) {
  2908. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2909. return 1;
  2910. }
  2911. return 0;
  2912. }
  2913. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2914. if (!lua_interface)
  2915. return 0;
  2916. Spawn* player = lua_interface->GetSpawn(state);
  2917. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2918. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2919. if (player && player->IsPlayer() && quest_id > 0) {
  2920. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2921. return 1;
  2922. }
  2923. return 0;
  2924. }
  2925. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2926. if (!lua_interface)
  2927. return 0;
  2928. Spawn* player = lua_interface->GetSpawn(state);
  2929. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2930. if (player && player->IsPlayer() && quest_id > 0) {
  2931. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2932. return 1;
  2933. }
  2934. return 0;
  2935. }
  2936. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2937. if (!lua_interface)
  2938. return 0;
  2939. Quest* quest = lua_interface->GetQuest(state);
  2940. string name = lua_interface->GetStringValue(state, 2);
  2941. string type = lua_interface->GetStringValue(state, 3);
  2942. string zone = lua_interface->GetStringValue(state, 4);
  2943. int16 level = lua_interface->GetInt16Value(state, 5);
  2944. string description = lua_interface->GetStringValue(state, 6);
  2945. bool load = true;
  2946. if (!quest) {
  2947. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2948. load = false;
  2949. }
  2950. if (load && name.length() == 0) {
  2951. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2952. load = false;
  2953. }
  2954. if (load && type.length() == 0) {
  2955. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2956. load = false;
  2957. }
  2958. if (load && zone.length() == 0) {
  2959. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2960. load = false;
  2961. }
  2962. if (load && description.length() == 0) {
  2963. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2964. load = false;
  2965. }
  2966. if (load && level == 0) {
  2967. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2968. load = false;
  2969. }
  2970. if (load)
  2971. quest->RegisterQuest(name, type, zone, level, description);
  2972. return 0;
  2973. }
  2974. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2975. if (!lua_interface)
  2976. return 0;
  2977. Quest* quest = lua_interface->GetQuest(state);
  2978. if (quest) {
  2979. int8 level = lua_interface->GetInt16Value(state, 2);
  2980. quest->SetPrereqLevel(level);
  2981. }
  2982. return 0;
  2983. }
  2984. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2985. if (!lua_interface)
  2986. return 0;
  2987. Quest* quest = lua_interface->GetQuest(state);
  2988. if (quest) {
  2989. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2990. quest->AddPrereqQuest(quest_id);
  2991. }
  2992. return 0;
  2993. }
  2994. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2995. if (!lua_interface)
  2996. return 0;
  2997. Quest* quest = lua_interface->GetQuest(state);
  2998. if (quest) {
  2999. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3000. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3001. if (quantity == 0)
  3002. quantity = 1;
  3003. Item* master_item = master_item_list.GetItem(item_id);
  3004. if (master_item) {
  3005. Item* item = new Item(master_item);
  3006. item->details.count = quantity;
  3007. quest->AddPrereqItem(item);
  3008. }
  3009. }
  3010. return 0;
  3011. }
  3012. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3013. if (!lua_interface)
  3014. return 0;
  3015. Spawn* player = lua_interface->GetSpawn(state);
  3016. if(!player || !player->IsPlayer()) {
  3017. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3018. return 0;
  3019. }
  3020. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3021. if (quest_id > 0) {
  3022. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3023. return 1;
  3024. } else {
  3025. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3026. }
  3027. return 0;
  3028. }
  3029. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3030. if (!lua_interface)
  3031. return 0;
  3032. Quest* quest = lua_interface->GetQuest(state);
  3033. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3034. if (quest && spawn_id > 0)
  3035. quest->SetQuestReturnNPC(spawn_id);
  3036. return 0;
  3037. }
  3038. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3039. if (!lua_interface)
  3040. return 0;
  3041. Spawn* spawn = lua_interface->GetSpawn(state);
  3042. if (!spawn) {
  3043. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3044. return 0;
  3045. }
  3046. int32 time = lua_interface->GetInt32Value(state, 2);
  3047. if (time <= 0) {
  3048. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3049. return 0;
  3050. }
  3051. string function = lua_interface->GetStringValue(state, 3);
  3052. if (function.length() == 0) {
  3053. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3054. return 0;
  3055. }
  3056. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3057. Spawn* player = lua_interface->GetSpawn(state, 5);
  3058. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3059. timer->timer = Timer::GetCurrentTime2() + time;
  3060. timer->function = function;
  3061. timer->spawn = spawn->GetID();
  3062. timer->player = player ? player->GetID() : 0;
  3063. if (max_count == 0)
  3064. max_count = 1;
  3065. timer->max_count = max_count;
  3066. timer->current_count = 0;
  3067. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3068. return 0;
  3069. }
  3070. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3071. if (!lua_interface)
  3072. return 0;
  3073. Spawn* player = lua_interface->GetSpawn(state);
  3074. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3075. if (player && player->IsPlayer() && quest_id > 0) {
  3076. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3077. return 1;
  3078. }
  3079. return 0;
  3080. }
  3081. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3082. if (!lua_interface)
  3083. return 0;
  3084. Spawn* player = lua_interface->GetSpawn(state);
  3085. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3086. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3087. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3088. if (quest)
  3089. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3090. return 1;
  3091. }
  3092. return 0;
  3093. }
  3094. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3095. if (!lua_interface)
  3096. return 0;
  3097. Spawn* player = lua_interface->GetSpawn(state);
  3098. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3099. if (player && player->IsPlayer() && quest_id > 0) {
  3100. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3101. return 1;
  3102. }
  3103. return 0;
  3104. }
  3105. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3106. if (!lua_interface)
  3107. return 0;
  3108. Spawn* npc = lua_interface->GetSpawn(state);
  3109. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3110. if (npc && !npc->IsPlayer() && quest_id > 0)
  3111. npc->AddProvidedQuest(quest_id);
  3112. return 0;
  3113. }
  3114. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3115. if (!lua_interface)
  3116. return 0;
  3117. Spawn* npc = lua_interface->GetSpawn(state);
  3118. Spawn* player = lua_interface->GetSpawn(state, 2);
  3119. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3120. bool forced = lua_interface->GetBooleanValue(state, 4);
  3121. /* NPC is allowed to be null */
  3122. if (player && player->IsPlayer() && quest_id > 0) {
  3123. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3124. if (master_quest) {
  3125. Client* client = player->GetZone()->GetClientBySpawn(player);
  3126. if (!client) {
  3127. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3128. }
  3129. Quest* quest = new Quest(master_quest);
  3130. if (!quest) {
  3131. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3132. }
  3133. if (client && quest) {
  3134. if (npc)
  3135. quest->SetQuestGiver(npc->GetDatabaseID());
  3136. else
  3137. quest->SetQuestGiver(0);
  3138. client->AddPendingQuest(quest, forced);
  3139. }
  3140. }
  3141. else {
  3142. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3143. }
  3144. }
  3145. else {
  3146. 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);
  3147. }
  3148. return 0;
  3149. }
  3150. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3151. if (!lua_interface)
  3152. return 0;
  3153. Quest* quest = lua_interface->GetQuest(state);
  3154. if (quest) {
  3155. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3156. quest->AddPrereqClass(class_id);
  3157. }
  3158. return 0;
  3159. }
  3160. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3161. if (!lua_interface)
  3162. return 0;
  3163. Quest* quest = lua_interface->GetQuest(state);
  3164. if (quest) {
  3165. int8 race = lua_interface->GetInt8Value(state, 2);
  3166. quest->AddPrereqRace(race);
  3167. }
  3168. return 0;
  3169. }
  3170. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3171. if (!lua_interface)
  3172. return 0;
  3173. Quest* quest = lua_interface->GetQuest(state);
  3174. if (quest) {
  3175. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3176. quest->AddPrereqModelType(model_type);
  3177. }
  3178. return 0;
  3179. }
  3180. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3181. if (!lua_interface)
  3182. return 0;
  3183. Quest* quest = lua_interface->GetQuest(state);
  3184. if (!quest) {
  3185. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3186. return 0;
  3187. }
  3188. int8 level = lua_interface->GetInt8Value(state, 2);
  3189. quest->SetPrereqTSLevel(level);
  3190. return 0;
  3191. }
  3192. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3193. if (!lua_interface)
  3194. return 0;
  3195. Quest* quest = lua_interface->GetQuest(state);
  3196. if (!quest) {
  3197. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3198. return 0;
  3199. }
  3200. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3201. quest->AddPrereqTradeskillClass(class_id);
  3202. return 0;
  3203. }
  3204. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3205. if (!lua_interface)
  3206. return 0;
  3207. Quest* quest = lua_interface->GetQuest(state);
  3208. if (quest) {
  3209. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3210. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3211. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3212. quest->AddPrereqFaction(faction_id, min, max);
  3213. }
  3214. return 0;
  3215. }
  3216. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3217. if (!lua_interface)
  3218. return 0;
  3219. Quest* quest = lua_interface->GetQuest(state);
  3220. if (quest) {
  3221. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3222. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3223. if (quantity == 0)
  3224. quantity = 1;
  3225. Item* master_item = master_item_list.GetItem(item_id);
  3226. if (master_item) {
  3227. Item* item = new Item(master_item);
  3228. item->details.count = quantity;
  3229. quest->AddSelectableRewardItem(item);
  3230. }
  3231. }
  3232. return 0;
  3233. }
  3234. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3235. if (!lua_interface)
  3236. return 0;
  3237. Quest* quest = lua_interface->GetQuest(state);
  3238. if (quest) {
  3239. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3240. vector<Item*>* items = quest->GetRewardItems();
  3241. if (items) {
  3242. vector<Item*>::iterator itr;
  3243. for (itr = items->begin(); itr != items->end(); itr++) {
  3244. if (*itr && (*itr)->details.item_id == item_id) {
  3245. lua_interface->SetBooleanValue(state, true);
  3246. return 1;
  3247. }
  3248. }
  3249. }
  3250. }
  3251. lua_interface->SetBooleanValue(state, false);
  3252. return 1;
  3253. }
  3254. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3255. if (!lua_interface)
  3256. return 0;
  3257. Quest* quest = lua_interface->GetQuest(state);
  3258. if (quest) {
  3259. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3260. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3261. if (quantity == 0)
  3262. quantity = 1;
  3263. Item* master_item = master_item_list.GetItem(item_id);
  3264. if (master_item) {
  3265. Item* item = new Item(master_item);
  3266. item->details.count = quantity;
  3267. quest->AddRewardItem(item);
  3268. }
  3269. }
  3270. return 0;
  3271. }
  3272. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3273. if (!lua_interface)
  3274. return 0;
  3275. Quest* quest = lua_interface->GetQuest(state);
  3276. if (quest) {
  3277. int32 copper = lua_interface->GetInt32Value(state, 2);
  3278. int32 silver = lua_interface->GetInt32Value(state, 3);
  3279. int32 gold = lua_interface->GetInt32Value(state, 4);
  3280. int32 plat = lua_interface->GetInt32Value(state, 5);
  3281. quest->AddRewardCoins(copper, silver, gold, plat);
  3282. }
  3283. return 0;
  3284. }
  3285. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3286. if (!lua_interface)
  3287. return 0;
  3288. Quest* quest = lua_interface->GetQuest(state);
  3289. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3290. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3291. if (quest && faction_id > 0 && amount != 0)
  3292. quest->AddRewardFaction(faction_id, amount);
  3293. return 0;
  3294. }
  3295. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3296. if (!lua_interface)
  3297. return 0;
  3298. Quest* quest = lua_interface->GetQuest(state);
  3299. if (quest) {
  3300. int32 status = lua_interface->GetInt32Value(state, 2);
  3301. quest->SetRewardStatus(status);
  3302. }
  3303. return 0;
  3304. }
  3305. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3306. if (!lua_interface)
  3307. return 0;
  3308. Quest* quest = lua_interface->GetQuest(state);
  3309. if (quest) {
  3310. string comment = lua_interface->GetStringValue(state, 2);
  3311. quest->SetRewardComment(comment);
  3312. }
  3313. return 0;
  3314. }
  3315. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3316. if (!lua_interface)
  3317. return 0;
  3318. Quest* quest = lua_interface->GetQuest(state);
  3319. if (quest) {
  3320. int32 exp = lua_interface->GetInt32Value(state, 2);
  3321. quest->SetRewardXP(exp);
  3322. }
  3323. return 0;
  3324. }
  3325. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3326. Quest* quest = lua_interface->GetQuest(state);
  3327. if (quest) {
  3328. int32 step = lua_interface->GetInt32Value(state, 2);
  3329. string description = lua_interface->GetStringValue(state, 3);
  3330. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3331. float percentage = lua_interface->GetFloatValue(state, 5);
  3332. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3333. int16 icon = lua_interface->GetInt16Value(state, 7);
  3334. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3335. const char* taskgroup = 0;
  3336. if (str_taskgroup.length() > 0)
  3337. taskgroup = str_taskgroup.c_str();
  3338. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3339. if (quest_step && icon && quantity > 0)
  3340. quest_step->SetIcon(icon);
  3341. }
  3342. return 0;
  3343. }
  3344. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3345. if (!lua_interface)
  3346. return 0;
  3347. Quest* quest = lua_interface->GetQuest(state);
  3348. if (quest) {
  3349. int32 step = lua_interface->GetInt32Value(state, 2);
  3350. string description = lua_interface->GetStringValue(state, 3);
  3351. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3352. float percentage = lua_interface->GetFloatValue(state, 5);
  3353. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3354. int16 icon = lua_interface->GetInt16Value(state, 7);
  3355. const char* taskgroup = 0;
  3356. if (str_taskgroup.length() > 0)
  3357. taskgroup = str_taskgroup.c_str();
  3358. int32 npc_id = 0;
  3359. vector<int32>* ids = 0;
  3360. int i = 0;
  3361. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3362. if (ids == 0)
  3363. ids = new vector<int32>;
  3364. ids->push_back(npc_id);
  3365. i++;
  3366. }
  3367. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3368. if (quest_step && icon > 0 && quantity > 0)
  3369. quest_step->SetIcon(icon);
  3370. if (quest->GetPlayer()) {
  3371. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3372. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3373. }
  3374. }
  3375. return 0;
  3376. }
  3377. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3378. if (!lua_interface)
  3379. return 0;
  3380. Quest* quest = lua_interface->GetQuest(state);
  3381. if (quest) {
  3382. int32 step = lua_interface->GetInt32Value(state, 2);
  3383. string description = lua_interface->GetStringValue(state, 3);
  3384. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3385. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3386. int16 icon = lua_interface->GetInt16Value(state, 6);
  3387. const char* taskgroup = 0;
  3388. if (str_taskgroup.length() > 0)
  3389. taskgroup = str_taskgroup.c_str();
  3390. int32 npc_id = 0;
  3391. vector<int32>* ids = 0;
  3392. int i = 0;
  3393. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3394. if (ids == 0)
  3395. ids = new vector<int32>;
  3396. ids->push_back(npc_id);
  3397. i++;
  3398. }
  3399. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3400. if (quest_step && icon > 0)
  3401. quest_step->SetIcon(icon);
  3402. if (quest->GetPlayer()) {
  3403. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3404. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3405. }
  3406. }
  3407. return 0;
  3408. }
  3409. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3410. if (!lua_interface)
  3411. return 0;
  3412. Quest* quest = lua_interface->GetQuest(state);
  3413. if (quest) {
  3414. int32 step = lua_interface->GetInt32Value(state, 2);
  3415. string description = lua_interface->GetStringValue(state, 3);
  3416. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3417. float percentage = lua_interface->GetFloatValue(state, 5);
  3418. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3419. int16 icon = lua_interface->GetInt16Value(state, 7);
  3420. const char* taskgroup = 0;
  3421. if (str_taskgroup.length() > 0)
  3422. taskgroup = str_taskgroup.c_str();
  3423. int32 item_id = 0;
  3424. vector<int32>* ids = 0;
  3425. int i = 0;
  3426. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3427. if (ids == 0)
  3428. ids = new vector<int32>;
  3429. ids->push_back(item_id);
  3430. i++;
  3431. }
  3432. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3433. if (quest_step && icon > 0 && quantity > 0)
  3434. quest_step->SetIcon(icon);
  3435. if (quest->GetPlayer()) {
  3436. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3437. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3438. }
  3439. }
  3440. return 0;
  3441. }
  3442. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3443. if (!lua_interface)
  3444. return 0;
  3445. Quest* quest = lua_interface->GetQuest(state);
  3446. if (quest) {
  3447. int32 step = lua_interface->GetInt32Value(state, 2);
  3448. string description = lua_interface->GetStringValue(state, 3);
  3449. float max_variation = lua_interface->GetFloatValue(state, 4);
  3450. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3451. int16 icon = lua_interface->GetInt16Value(state, 6);
  3452. const char* taskgroup = 0;
  3453. if (str_taskgroup.length() > 0)
  3454. taskgroup = str_taskgroup.c_str();
  3455. vector<Location>* locations = 0;
  3456. int i = 7;
  3457. while (true) {
  3458. Location loc;
  3459. loc.x = lua_interface->GetFloatValue(state, i);
  3460. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3461. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3462. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3463. break;
  3464. if (locations == 0)
  3465. locations = new vector<Location>;
  3466. locations->push_back(loc);
  3467. i += 3;
  3468. }
  3469. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3470. if (quest_step && icon > 0)
  3471. quest_step->SetIcon(icon);
  3472. if (quest->GetPlayer()) {
  3473. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3474. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3475. }
  3476. }
  3477. return 0;
  3478. }
  3479. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3480. if (!lua_interface)
  3481. return 0;
  3482. Quest* quest = lua_interface->GetQuest(state);
  3483. if (quest) {
  3484. int32 step = lua_interface->GetInt32Value(state, 2);
  3485. string description = lua_interface->GetStringValue(state, 3);
  3486. float max_variation = lua_interface->GetFloatValue(state, 4);
  3487. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3488. int16 icon = lua_interface->GetInt16Value(state, 6);
  3489. const char* taskgroup = 0;
  3490. if (str_taskgroup.length() > 0)
  3491. taskgroup = str_taskgroup.c_str();
  3492. vector<Location>* locations = 0;
  3493. int i = 7;
  3494. while (true) {
  3495. Location loc;
  3496. loc.x = lua_interface->GetFloatValue(state, i);
  3497. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3498. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3499. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3500. break;
  3501. if (locations == 0)
  3502. locations = new vector<Location>;
  3503. locations->push_back(loc);
  3504. i += 3;
  3505. }
  3506. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3507. if (quest_step && icon > 0)
  3508. quest_step->SetIcon(icon);
  3509. if (quest->GetPlayer()) {
  3510. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3511. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3512. }
  3513. }
  3514. return 0;
  3515. }
  3516. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3517. Quest* quest = lua_interface->GetQuest(state);
  3518. if (quest) {
  3519. int32 step = lua_interface->GetInt32Value(state, 2);
  3520. string description = lua_interface->GetStringValue(state, 3);
  3521. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3522. float percentage = lua_interface->GetFloatValue(state, 5);
  3523. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3524. int16 icon = lua_interface->GetInt16Value(state, 7);
  3525. const char* taskgroup = 0;
  3526. if (str_taskgroup.length() > 0)
  3527. taskgroup = str_taskgroup.c_str();
  3528. int32 spell_id = 0;
  3529. vector<int32>* ids = 0;
  3530. int i = 0;
  3531. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3532. if (ids == 0)
  3533. ids = new vector<int32>;
  3534. ids->push_back(spell_id);
  3535. i++;
  3536. }
  3537. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3538. if (quest_step && icon > 0 && quantity > 0)
  3539. quest_step->SetIcon(icon);
  3540. if (quest->GetPlayer()) {
  3541. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3542. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3543. }
  3544. }
  3545. return 0;
  3546. }
  3547. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3548. if (!lua_interface)
  3549. return 0;
  3550. Quest* quest = lua_interface->GetQuest(state);
  3551. if (quest) {
  3552. int32 step = lua_interface->GetInt32Value(state, 2);
  3553. string description = lua_interface->GetStringValue(state, 3);
  3554. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3555. float percentage = lua_interface->GetFloatValue(state, 5);
  3556. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3557. int16 icon = lua_interface->GetInt16Value(state, 7);
  3558. const char* taskgroup = 0;
  3559. if (str_taskgroup.length() > 0)
  3560. taskgroup = str_taskgroup.c_str();
  3561. int32 item_id = 0;
  3562. vector<int32>* ids = 0;
  3563. int i = 0;
  3564. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3565. if (ids == 0)
  3566. ids = new vector<int32>;
  3567. ids->push_back(item_id);
  3568. i++;
  3569. }
  3570. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3571. if (quest_step && icon > 0 && quantity > 0)
  3572. quest_step->SetIcon(icon);
  3573. if (quest->GetPlayer()) {
  3574. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3575. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3576. }
  3577. }
  3578. return 0;
  3579. }
  3580. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3581. if (!lua_interface)
  3582. return 0;
  3583. Quest* quest = lua_interface->GetQuest(state);
  3584. if (quest) {
  3585. int32 step = lua_interface->GetInt32Value(state, 2);
  3586. string description = lua_interface->GetStringValue(state, 3);
  3587. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3588. float percentage = lua_interface->GetFloatValue(state, 5);
  3589. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3590. int16 icon = lua_interface->GetInt16Value(state, 7);
  3591. const char* taskgroup = 0;
  3592. if (str_taskgroup.length() > 0)
  3593. taskgroup = str_taskgroup.c_str();
  3594. int32 item_id = 0;
  3595. vector<int32>* ids = 0;
  3596. int i = 0;
  3597. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3598. if (ids == 0)
  3599. ids = new vector<int32>;
  3600. ids->push_back(item_id);
  3601. i++;
  3602. }
  3603. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3604. if (quest_step && icon > 0 && quantity > 0)
  3605. quest_step->SetIcon(icon);
  3606. if (quest->GetPlayer()) {
  3607. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3608. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3609. }
  3610. }
  3611. return 0;
  3612. }
  3613. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3614. if (!lua_interface)
  3615. return 0;
  3616. Quest* quest = lua_interface->GetQuest(state);
  3617. if (quest) {
  3618. string action = lua_interface->GetStringValue(state, 2);
  3619. if (action.length() > 0)
  3620. quest->SetCompleteAction(action);
  3621. }
  3622. return 0;
  3623. }
  3624. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3625. if (!lua_interface)
  3626. return 0;
  3627. Quest* quest = lua_interface->GetQuest(state);
  3628. if (quest) {
  3629. int32 step = lua_interface->GetInt32Value(state, 2);
  3630. string action = lua_interface->GetStringValue(state, 3);
  3631. if (step > 0 && action.length() > 0)
  3632. quest->AddCompleteAction(step, action);
  3633. }
  3634. return 0;
  3635. }
  3636. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3637. if (!lua_interface)
  3638. return 0;
  3639. Quest* quest = lua_interface->GetQuest(state);
  3640. if (quest) {
  3641. int32 step = lua_interface->GetInt32Value(state, 2);
  3642. string action = lua_interface->GetStringValue(state, 3);
  3643. if (step > 0 && action.length() > 0)
  3644. quest->AddProgressAction(step, action);
  3645. }
  3646. return 0;
  3647. }
  3648. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3649. if (!lua_interface)
  3650. return 0;
  3651. Quest* quest = lua_interface->GetQuest(state);
  3652. string description = lua_interface->GetStringValue(state, 2);
  3653. if (quest && description.length() > 0)
  3654. quest->SetDescription(description);
  3655. return 0;
  3656. }
  3657. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3658. if (!lua_interface)
  3659. return 0;
  3660. Quest* quest = lua_interface->GetQuest(state);
  3661. string description = lua_interface->GetStringValue(state, 2);
  3662. if (quest && description.length() > 0)
  3663. quest->SetCompletedDescription(description);
  3664. return 0;
  3665. }
  3666. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3667. if (!lua_interface)
  3668. return 0;
  3669. Quest* quest = lua_interface->GetQuest(state);
  3670. int32 step = lua_interface->GetInt32Value(state, 2);
  3671. string description = lua_interface->GetStringValue(state, 3);
  3672. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3673. if (quest && step > 0 && description.length() > 0) {
  3674. quest->SetTaskGroupDescription(step, description, display_bullets);
  3675. if (quest->GetPlayer()) {
  3676. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3677. if (client)
  3678. client->SendQuestUpdateStep(quest, step, false);
  3679. }
  3680. }
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Quest* quest = lua_interface->GetQuest(state);
  3687. int32 step = lua_interface->GetInt32Value(state, 2);
  3688. string description = lua_interface->GetStringValue(state, 3);
  3689. if (quest && step > 0 && description.length() > 0) {
  3690. quest->SetStepDescription(step, description);
  3691. if (quest->GetPlayer()) {
  3692. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3693. if (client)
  3694. client->SendQuestUpdateStepImmediately(quest, step);
  3695. }
  3696. }
  3697. return 0;
  3698. }
  3699. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3700. Quest* quest = lua_interface->GetQuest(state);
  3701. string zone = lua_interface->GetStringValue(state, 2);
  3702. if (quest && zone.length() > 0)
  3703. quest->SetZone(zone);
  3704. return 0;
  3705. }
  3706. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3707. if (!lua_interface)
  3708. return 0;
  3709. Quest* quest = lua_interface->GetQuest(state);
  3710. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3711. int32 coin = lua_interface->GetInt32Value(state, 3);
  3712. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3713. string rewards_str = lua_interface->GetStringValue(state, 5);
  3714. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3715. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3716. string text = lua_interface->GetStringValue(state, 8);
  3717. if (playerSpawn && playerSpawn->IsPlayer()) {
  3718. Player* player = (Player*)playerSpawn;
  3719. Client* client = player->GetZone()->GetClientBySpawn(player);
  3720. if (client) {
  3721. vector<Item*> reward_items;
  3722. vector<Item*> selectable_reward_items;
  3723. if (rewards_str.length() > 0) {
  3724. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3725. map<unsigned int, unsigned short>::iterator itr;
  3726. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3727. if (itr->first > 0) {
  3728. Item* item = new Item(master_item_list.GetItem(itr->first));
  3729. if (item) {
  3730. if (itr->second > 0)
  3731. item->details.count = itr->second;
  3732. reward_items.push_back(item);
  3733. }
  3734. }
  3735. }
  3736. }
  3737. if (select_rewards_str.length() > 0) {
  3738. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3739. map<unsigned int, unsigned short>::iterator itr;
  3740. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3741. if (itr->first > 0) {
  3742. Item* item = new Item(master_item_list.GetItem(itr->first));
  3743. if (item) {
  3744. if (itr->second > 0)
  3745. item->stack_count = itr->second;
  3746. selectable_reward_items.push_back(item);
  3747. }
  3748. }
  3749. }
  3750. }
  3751. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3752. const char* reward_type = "Quest Reward!";
  3753. if (!quest)
  3754. reward_type = "Reward!";
  3755. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3756. }
  3757. }
  3758. return 0;
  3759. }
  3760. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3761. if (!lua_interface)
  3762. return 0;
  3763. Quest* quest = lua_interface->GetQuest(state);
  3764. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3765. if (quest && spawn) {
  3766. if (spawn->IsPlayer()) {
  3767. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3768. if (client)
  3769. client->AddPendingQuestReward(quest);
  3770. }
  3771. }
  3772. return 0;
  3773. }
  3774. int EQ2Emu_lua_Harvest(lua_State* state) {
  3775. if (!lua_interface)
  3776. return 0;
  3777. Spawn* player = lua_interface->GetSpawn(state);
  3778. Spawn* node = lua_interface->GetSpawn(state, 2);
  3779. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3780. Client* client = player->GetZone()->GetClientBySpawn(player);
  3781. if (client) {
  3782. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3783. ((GroundSpawn*)node)->ProcessHarvest(client);
  3784. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3785. player->GetZone()->RemoveSpawn(node, true);
  3786. }
  3787. }
  3788. else if (player && player->IsPlayer()) {
  3789. Client* client = player->GetZone()->GetClientBySpawn(player);
  3790. if (client)
  3791. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3792. }
  3793. return 0;
  3794. }
  3795. int EQ2Emu_lua_Bind(lua_State* state) {
  3796. if (!lua_interface)
  3797. return 0;
  3798. Spawn* spawn = lua_interface->GetSpawn(state);
  3799. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3800. float x = lua_interface->GetFloatValue(state, 3);
  3801. float y = lua_interface->GetFloatValue(state, 4);
  3802. float z = lua_interface->GetFloatValue(state, 5);
  3803. float h = lua_interface->GetFloatValue(state, 6);
  3804. if (!spawn) {
  3805. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3806. return 0;
  3807. }
  3808. if (!spawn->IsPlayer()) {
  3809. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3810. return 0;
  3811. }
  3812. if (zone_id == 0) {
  3813. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3814. if (!client) {
  3815. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3816. return 0;
  3817. }
  3818. if (!client->Bind())
  3819. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3820. }
  3821. else {
  3822. Player* player = (Player*)spawn;
  3823. player->GetPlayerInfo()->SetBindZone(zone_id);
  3824. player->GetPlayerInfo()->SetBindX(x);
  3825. player->GetPlayerInfo()->SetBindY(y);
  3826. player->GetPlayerInfo()->SetBindZ(z);
  3827. player->GetPlayerInfo()->SetBindHeading(h);
  3828. }
  3829. return 0;
  3830. }
  3831. int EQ2Emu_lua_Gate(lua_State* state) {
  3832. if (!lua_interface)
  3833. return 0;
  3834. Spawn* spawn = lua_interface->GetSpawn(state);
  3835. if (spawn) {
  3836. if (spawn->IsPlayer()) {
  3837. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3838. if (client) {
  3839. if (!client->Gate())
  3840. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3841. }
  3842. }
  3843. }
  3844. return 0;
  3845. }
  3846. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3847. if (!lua_interface)
  3848. return 0;
  3849. bool ret = false;
  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. ret = client->BindAllowed();
  3856. }
  3857. }
  3858. lua_interface->SetBooleanValue(state, ret);
  3859. return 1;
  3860. }
  3861. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3862. if (!lua_interface)
  3863. return 0;
  3864. bool ret = false;
  3865. Spawn* spawn = lua_interface->GetSpawn(state);
  3866. if (spawn) {
  3867. if (spawn->IsPlayer()) {
  3868. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3869. if (client)
  3870. ret = client->GateAllowed();
  3871. }
  3872. }
  3873. lua_interface->SetBooleanValue(state, ret);
  3874. return 1;
  3875. }
  3876. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3877. Spawn* spawn = lua_interface->GetSpawn(state);
  3878. if (spawn) {
  3879. lua_interface->SetBooleanValue(state, spawn->Alive());
  3880. return 1;
  3881. }
  3882. return 0;
  3883. }
  3884. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3885. if (!lua_interface)
  3886. return 0;
  3887. Spawn* spawn = lua_interface->GetSpawn(state);
  3888. if (spawn && spawn->IsEntity()) {
  3889. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3890. return 1;
  3891. }
  3892. return 0;
  3893. }
  3894. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3895. Spawn* spawn = lua_interface->GetSpawn(state);
  3896. string message = lua_interface->GetStringValue(state, 2);
  3897. string color_str = lua_interface->GetStringValue(state, 3);
  3898. int8 color = CHANNEL_NARRATIVE;
  3899. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3900. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3901. if (client) {
  3902. if (color_str.length() > 0) {
  3903. // leave for backwards compat, but all future should just use the number
  3904. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3905. color = CHANNEL_COLOR_RED;
  3906. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3907. color = CHANNEL_COLOR_YELLOW;
  3908. else
  3909. {
  3910. // use a number to specify the channel as per Commands/Commands.h defines
  3911. color = (int8)atoul(color_str.c_str());
  3912. }
  3913. }
  3914. client->SimpleMessage(color, message.c_str());
  3915. }
  3916. }
  3917. return 0;
  3918. }
  3919. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3920. Spawn* spawn = lua_interface->GetSpawn(state);
  3921. string message = lua_interface->GetStringValue(state, 2);
  3922. int8 red = lua_interface->GetInt8Value(state, 3);
  3923. int8 green = lua_interface->GetInt8Value(state, 4);
  3924. int8 blue = lua_interface->GetInt8Value(state, 5);
  3925. if (!spawn) {
  3926. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3927. return 0;
  3928. }
  3929. int32 words = ::CountWordsInString(message.c_str());
  3930. if (words < 5)
  3931. words = 5;
  3932. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3933. if (client)
  3934. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3935. return 0;
  3936. }
  3937. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3938. Spawn* spawn = lua_interface->GetSpawn(state);
  3939. int8 param = lua_interface->GetInt8Value(state, 2);
  3940. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3941. int8 value = lua_interface->GetInt8Value(state, 4);
  3942. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3943. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3944. if (client) {
  3945. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3946. switch (param) {
  3947. case 1: {
  3948. packet->setDataByName("parameter1", param_value);
  3949. break;
  3950. }
  3951. case 2: {
  3952. packet->setDataByName("parameter2", param_value);
  3953. break;
  3954. }
  3955. case 3: {
  3956. packet->setDataByName("parameter3", param_value);
  3957. break;
  3958. }
  3959. case 4: {
  3960. packet->setDataByName("parameter4", param_value);
  3961. break;
  3962. }
  3963. case 5: {
  3964. packet->setDataByName("parameter5", param_value);
  3965. break;
  3966. }
  3967. }
  3968. packet->setDataByName("value", value);
  3969. client->QueuePacket(packet->serialize());
  3970. safe_delete(packet);
  3971. }
  3972. }
  3973. return 0;
  3974. }
  3975. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3976. Spawn* spawn = lua_interface->GetSpawn(state);
  3977. if (spawn && spawn->IsPlayer()) {
  3978. if (((Player*)spawn)->GetIsTracking())
  3979. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3980. else
  3981. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3982. }
  3983. return 0;
  3984. }
  3985. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3986. Spawn* player = lua_interface->GetSpawn(state);
  3987. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3988. string name = lua_interface->GetStringValue(state, 3);
  3989. float distance = lua_interface->GetFloatValue(state, 4);
  3990. string command = lua_interface->GetStringValue(state, 5);
  3991. string error_text = lua_interface->GetStringValue(state, 6);
  3992. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3993. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3994. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3995. if (spawn) {
  3996. if (distance == 0)
  3997. distance = 10.0f;
  3998. if (command.length() == 0)
  3999. command = name;
  4000. if (command.length() < 1 && name.length() < 1)
  4001. {
  4002. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4003. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4004. spawn->RemovePrimaryCommands();
  4005. }
  4006. else
  4007. {
  4008. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4009. }
  4010. }
  4011. return 0;
  4012. }
  4013. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4014. if (!lua_interface)
  4015. return 0;
  4016. Spawn* player = lua_interface->GetSpawn(state);
  4017. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4018. int16 tier = lua_interface->GetInt16Value(state, 3);
  4019. if (player && player->IsPlayer()) {
  4020. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4021. return 1;
  4022. }
  4023. return 0;
  4024. }
  4025. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4026. if (!lua_interface)
  4027. return 0;
  4028. Spawn* player = lua_interface->GetSpawn(state);
  4029. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4030. int16 tier = lua_interface->GetInt16Value(state, 3);
  4031. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4032. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4033. bool add_to_hotbar = true;
  4034. if (num_args > 4) {
  4035. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4036. }
  4037. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4038. if (player && spell && player->IsPlayer()) {
  4039. Client* client = player->GetClient();
  4040. if (client) {
  4041. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4042. {
  4043. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4044. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4045. client->GetPlayer()->UnlockSpell(spell);
  4046. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4047. }
  4048. else
  4049. {
  4050. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4051. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4052. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4053. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4054. client->GetPlayer()->UnlockSpell(spell);
  4055. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4056. }
  4057. //if (client ) {
  4058. // ((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);
  4059. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4060. if (outapp)
  4061. client->QueuePacket(outapp);
  4062. }
  4063. }
  4064. return 0;
  4065. }
  4066. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4067. if (!lua_interface)
  4068. return 0;
  4069. Spawn* player = lua_interface->GetSpawn(state);
  4070. if (player && player->IsPlayer()) {
  4071. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4072. return 1;
  4073. }
  4074. return 0;
  4075. }
  4076. int EQ2Emu_lua_Attack(lua_State* state) {
  4077. if (lua_interface) {
  4078. Spawn* npc = lua_interface->GetSpawn(state);
  4079. Spawn* player = lua_interface->GetSpawn(state, 2);
  4080. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4081. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4082. }
  4083. return 0;
  4084. }
  4085. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4086. if (lua_interface) {
  4087. Spawn* target = lua_interface->GetSpawn(state);
  4088. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4089. if (target && target->GetZone())
  4090. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4091. }
  4092. return 0;
  4093. }
  4094. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4095. Spawn* player;
  4096. if (lua_interface) {
  4097. player = lua_interface->GetSpawn(state);
  4098. if (player && player->IsPlayer()) {
  4099. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4100. return 1;
  4101. }
  4102. }
  4103. return 0;
  4104. }
  4105. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4106. Spawn* player;
  4107. Client* client;
  4108. if (lua_interface) {
  4109. player = lua_interface->GetSpawn(state);
  4110. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4111. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4112. client->HandInCollections();
  4113. }
  4114. return 0;
  4115. }
  4116. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4117. Spawn* widget;
  4118. if (lua_interface) {
  4119. widget = lua_interface->GetSpawn(state);
  4120. if (widget && widget->IsWidget())
  4121. ((Widget*)widget)->HandleUse(nullptr, "");
  4122. }
  4123. return 0;
  4124. }
  4125. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4126. Spawn* spawn = 0;
  4127. int32 primary_list = 0;
  4128. int32 secondary_list = 0;
  4129. if (lua_interface) {
  4130. spawn = lua_interface->GetSpawn(state);
  4131. primary_list = lua_interface->GetInt32Value(state, 2);
  4132. secondary_list = lua_interface->GetInt32Value(state, 3);
  4133. if (!spawn->IsNPC()) {
  4134. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4135. return 0;
  4136. }
  4137. NPC* npc = (NPC*)spawn;
  4138. npc->SetPrimarySpellList(primary_list);
  4139. npc->SetSecondarySpellList(secondary_list);
  4140. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4141. }
  4142. return 0;
  4143. }
  4144. int EQ2Emu_lua_GetPet(lua_State* state) {
  4145. if (!lua_interface)
  4146. return 0;
  4147. Spawn* spawn = lua_interface->GetSpawn(state);
  4148. if (spawn) {
  4149. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4150. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4151. return 1;
  4152. }
  4153. }
  4154. return 0;
  4155. }
  4156. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4157. if (!lua_interface)
  4158. return 0;
  4159. Spawn* spawn = lua_interface->GetSpawn(state);
  4160. if (spawn) {
  4161. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4162. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4163. return 1;
  4164. }
  4165. }
  4166. return 0;
  4167. }
  4168. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4169. if (!lua_interface)
  4170. return 0;
  4171. Spawn* spawn = lua_interface->GetSpawn(state);
  4172. if (spawn) {
  4173. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4174. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4175. return 1;
  4176. }
  4177. }
  4178. return 0;
  4179. }
  4180. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4181. if (!lua_interface)
  4182. return 0;
  4183. Spawn* spawn = lua_interface->GetSpawn(state);
  4184. if (spawn) {
  4185. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4186. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4187. return 1;
  4188. }
  4189. }
  4190. return 0;
  4191. }
  4192. int EQ2Emu_lua_Charm(lua_State* state) {
  4193. if (!lua_interface)
  4194. return 0;
  4195. Spawn* owner = lua_interface->GetSpawn(state);
  4196. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4197. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4198. if (!luaspell) {
  4199. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4200. return 0;
  4201. }
  4202. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4203. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4204. pet->SetPet(true);
  4205. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4206. ((NPC*)pet)->SetOwner((Entity*)owner);
  4207. // If owner is player and player does not have a summoned pet set the players charsheet
  4208. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4209. Player* player = (Player*)owner;
  4210. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4211. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4212. player->GetInfoStruct()->set_pet_movement(2);
  4213. player->GetInfoStruct()->set_pet_behavior(3);
  4214. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4215. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4216. // Make sure the values get sent to the client
  4217. player->SetCharSheetChanged(true);
  4218. }
  4219. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4220. pet->SetSpawnScript("");
  4221. // Set faction to the same as the owner
  4222. pet->SetFactionID(owner->GetFactionID());
  4223. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4224. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4225. // Clear hate list
  4226. ((NPC*)pet)->Brain()->ClearHate();
  4227. // Set the brain to a pet brain
  4228. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4229. }
  4230. return 0;
  4231. }
  4232. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4233. if (!lua_interface)
  4234. return 0;
  4235. Spawn* spawn = lua_interface->GetSpawn(state);
  4236. if (!spawn) {
  4237. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4238. return 0;
  4239. }
  4240. vector<Spawn*> groupMembers;
  4241. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4242. groupMembers = *spawn->GetSpawnGroup();
  4243. }
  4244. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4245. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4246. deque<GroupMemberInfo*>::iterator itr;
  4247. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4248. if (group)
  4249. {
  4250. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4251. deque<GroupMemberInfo*>* members = group->GetMembers();
  4252. GroupMemberInfo* info = 0;
  4253. for (itr = members->begin(); itr != members->end(); itr++) {
  4254. info = *itr;
  4255. if (info->client)
  4256. groupMembers.push_back(info->client->GetPlayer());
  4257. }
  4258. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4259. }
  4260. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4261. }
  4262. else
  4263. return 0;
  4264. lua_createtable(state, groupMembers.size(), 0);
  4265. int newTable = lua_gettop(state);
  4266. for (int32 i = 0; i < groupMembers.size(); i++) {
  4267. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4268. lua_rawseti(state, newTable, i + 1);
  4269. }
  4270. return 1;
  4271. }
  4272. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4273. if (!lua_interface)
  4274. return 0;
  4275. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4276. lua_interface->SetOptionWindowValue(state, option_window);
  4277. return 1;
  4278. }
  4279. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4280. if (!lua_interface)
  4281. return 0;
  4282. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4283. if (option_window) {
  4284. OptionWindowOption option_window_option;
  4285. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4286. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4287. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4288. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4289. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4290. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4291. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4292. option_window->push_back(option_window_option);
  4293. }
  4294. return 0;
  4295. }
  4296. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4297. if (!lua_interface)
  4298. return 0;
  4299. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4300. Spawn* player = lua_interface->GetSpawn(state, 2);
  4301. string window_title = lua_interface->GetStringValue(state, 3);
  4302. string cancel_command = lua_interface->GetStringValue(state, 4);
  4303. Client* client = player->GetZone()->GetClientBySpawn(player);
  4304. if (option_window && window_title.length() > 0 && client) {
  4305. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4306. if (!packet)
  4307. return 0;
  4308. packet->setDataByName("title_text", window_title.c_str());
  4309. if (cancel_command.length() > 0)
  4310. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4311. packet->setArrayLengthByName("num_selections", option_window->size());
  4312. vector<OptionWindowOption>::iterator itr;
  4313. int8 i = 0;
  4314. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4315. OptionWindowOption opt = *itr;
  4316. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4317. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4318. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4319. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4320. if (opt.optionCommand.length() > 0)
  4321. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4322. if (opt.optionConfirmTitle.length() > 0)
  4323. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4324. i++;
  4325. }
  4326. client->QueuePacket(packet->serialize());
  4327. safe_delete(option_window);
  4328. safe_delete(packet);
  4329. }
  4330. return 0;
  4331. }
  4332. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4333. if (!lua_interface)
  4334. return 0;
  4335. Spawn* spawn = lua_interface->GetSpawn(state);
  4336. if (spawn) {
  4337. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4338. return 1;
  4339. }
  4340. else
  4341. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4342. return 0;
  4343. }
  4344. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4345. if (!lua_interface)
  4346. return 0;
  4347. Spawn* spawn = lua_interface->GetSpawn(state);
  4348. if (spawn) {
  4349. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4350. return 1;
  4351. }
  4352. else
  4353. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4354. return 0;
  4355. }
  4356. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4357. if (!lua_interface)
  4358. return 0;
  4359. Spawn* spawn = lua_interface->GetSpawn(state);
  4360. if (spawn) {
  4361. int8 class_id = spawn->GetTradeskillClass();
  4362. // Need to add 42 for the offset in the array
  4363. class_id += 44;
  4364. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4365. return 1;
  4366. }
  4367. else
  4368. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4369. return 0;
  4370. }
  4371. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4372. if (!lua_interface)
  4373. return 0;
  4374. Spawn* spawn = lua_interface->GetSpawn(state);
  4375. int16 level = lua_interface->GetInt8Value(state, 2);
  4376. if (spawn) {
  4377. if (spawn->IsPlayer())
  4378. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4379. else
  4380. spawn->SetTSLevel(level);
  4381. }
  4382. else
  4383. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4384. return 0;
  4385. }
  4386. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4387. if (!lua_interface)
  4388. return 0;
  4389. Spawn* spawn = lua_interface->GetSpawn(state);
  4390. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4391. if (spawn) {
  4392. spawn->SetAttackable(attackable);
  4393. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4394. }
  4395. return 0;
  4396. }
  4397. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4398. // Check to see if we have a valid lua_interface
  4399. if (!lua_interface)
  4400. return 0;
  4401. // Get the spawn that is getting the pet
  4402. Spawn* spawn = lua_interface->GetSpawn(state);
  4403. // Get the DB ID of the pet
  4404. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4405. // The max level the pet can gain
  4406. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4407. // Get the spell that this command was called from
  4408. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4409. // Check to make sure the spawn pointer is valid
  4410. if (!spawn) {
  4411. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4412. return 0;
  4413. }
  4414. // Check to make sure the spawn is an entity
  4415. if (!spawn->IsEntity()) {
  4416. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4417. return 0;
  4418. }
  4419. // Check to make sure the spawn doesn't already have a pet of this type
  4420. if (((Entity*)spawn)->GetPet()) {
  4421. if (spawn->IsPlayer()) {
  4422. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4423. if (client)
  4424. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4425. }
  4426. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4427. return 0;
  4428. }
  4429. // Check to see if the DB ID for the pet is set
  4430. if (pet_id == 0) {
  4431. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4432. return 0;
  4433. }
  4434. // Check to see if the pointer to the spell is valid
  4435. if (!luaspell) {
  4436. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4437. return 0;
  4438. }
  4439. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4440. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4441. if (!pet) {
  4442. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4443. return 0;
  4444. }
  4445. // Check to make sure the pet is an npc
  4446. if (!pet->IsNPC()) {
  4447. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4448. return 0;
  4449. }
  4450. // Spawn the pet at the same location as the owner
  4451. pet->SetX(spawn->GetX());
  4452. pet->SetY(spawn->GetY());
  4453. pet->SetZ(spawn->GetZ());
  4454. pet->SetLocation(spawn->GetLocation());
  4455. pet->SetHeading(spawn->GetHeading());
  4456. spawn->GetZone()->AddSpawn(pet);
  4457. /*
  4458. const char* spawn_script = world.GetSpawnScript(pet_id);
  4459. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4460. spawn->SetSpawnScript(string(spawn_script));
  4461. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4462. }*/
  4463. // Get a random pet name
  4464. string random_pet_name;
  4465. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4466. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4467. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4468. // If player set various values for the char sheet (pet window)
  4469. if (spawn->IsPlayer()) {
  4470. Player* player = (Player*)spawn;
  4471. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4472. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4473. player->GetInfoStruct()->set_pet_movement(2);
  4474. player->GetInfoStruct()->set_pet_behavior(3);
  4475. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4476. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4477. // Make sure the values get sent to the client
  4478. player->SetCharSheetChanged(true);
  4479. }
  4480. // Set the pets name
  4481. pet->SetName(random_pet_name.c_str());
  4482. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4483. if (max_level > 0)
  4484. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4485. else
  4486. pet->SetLevel(spawn->GetLevel());
  4487. // Set the max level this pet can reach
  4488. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4489. // Set the faction of the pet to the same faction as the owner
  4490. pet->SetFactionID(spawn->GetFactionID());
  4491. // Set the spawn as a pet
  4492. pet->SetPet(true);
  4493. // Give a pointer of the owner to the pet
  4494. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4495. // Give a pointer of the pet to the owner
  4496. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4497. // Set the pet type
  4498. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4499. // Set the spell id used to create this pet
  4500. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4501. // Set the spell tier used to create this pet
  4502. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4503. // Set the pets spawn type to 6
  4504. pet->SetSpawnType(6);
  4505. // Set the pets brain
  4506. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4507. // Check to see if the pet has a subtitle
  4508. if (strlen(pet->GetSubTitle()) > 0) {
  4509. // Add the players name to the front of the sub title
  4510. string pet_subtitle;
  4511. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4512. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4513. // Set the pets subtitle to the new one
  4514. pet->SetSubTitle(pet_subtitle.c_str());
  4515. }
  4516. // Add the "Pet Options" entity command to the pet
  4517. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4518. // Set the pet as the return value for this function
  4519. lua_interface->SetSpawnValue(state, pet);
  4520. return 1;
  4521. }
  4522. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4523. if (!lua_interface)
  4524. return 0;
  4525. Spawn* spawn = lua_interface->GetSpawn(state);
  4526. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4527. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4528. if (!spawn) {
  4529. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4530. return 0;
  4531. }
  4532. if (!spawn->IsEntity()) {
  4533. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4534. return 0;
  4535. }
  4536. if (((Entity*)spawn)->GetDeityPet()) {
  4537. if (spawn->IsPlayer()) {
  4538. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4539. if (client)
  4540. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4541. }
  4542. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4543. return 0;
  4544. }
  4545. if (pet_id == 0) {
  4546. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4547. return 0;
  4548. }
  4549. if (!luaspell) {
  4550. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4551. return 0;
  4552. }
  4553. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4554. if (!pet) {
  4555. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4556. return 0;
  4557. }
  4558. if (!pet->IsNPC()) {
  4559. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4560. return 0;
  4561. }
  4562. pet->SetX(spawn->GetX());
  4563. pet->SetY(spawn->GetY());
  4564. pet->SetZ(spawn->GetZ());
  4565. pet->SetLocation(spawn->GetLocation());
  4566. pet->SetHeading(spawn->GetHeading());
  4567. spawn->GetZone()->AddSpawn(pet);
  4568. string random_pet_name;
  4569. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4570. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4571. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4572. pet->SetName(random_pet_name.c_str());
  4573. pet->SetLevel(spawn->GetLevel());
  4574. pet->SetFactionID(spawn->GetFactionID());
  4575. pet->SetPet(true);
  4576. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4577. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4578. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4579. pet->SetSpawnType(6);
  4580. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4581. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4582. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4583. if (strlen(pet->GetSubTitle()) > 0) {
  4584. string pet_subtitle;
  4585. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4586. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4587. pet->SetSubTitle(pet_subtitle.c_str());
  4588. }
  4589. // deity and cosmetic pets are not attackable
  4590. pet->SetAttackable(false);
  4591. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4592. lua_interface->SetSpawnValue(state, pet);
  4593. return 1;
  4594. }
  4595. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4596. if (!lua_interface)
  4597. return 0;
  4598. Spawn* spawn = lua_interface->GetSpawn(state);
  4599. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4600. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4601. if (!spawn) {
  4602. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4603. return 0;
  4604. }
  4605. if (!spawn->IsEntity()) {
  4606. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4607. return 0;
  4608. }
  4609. if (((Entity*)spawn)->GetCosmeticPet()) {
  4610. if (spawn->IsPlayer()) {
  4611. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4612. if (client)
  4613. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4614. }
  4615. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4616. return 0;
  4617. }
  4618. if (pet_id == 0) {
  4619. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4620. return 0;
  4621. }
  4622. if (!luaspell) {
  4623. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4624. return 0;
  4625. }
  4626. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4627. if (!pet) {
  4628. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4629. return 0;
  4630. }
  4631. if (!pet->IsNPC()) {
  4632. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4633. return 0;
  4634. }
  4635. pet->SetX(spawn->GetX());
  4636. pet->SetY(spawn->GetY());
  4637. pet->SetZ(spawn->GetZ());
  4638. pet->SetLocation(spawn->GetLocation());
  4639. pet->SetHeading(spawn->GetHeading());
  4640. spawn->GetZone()->AddSpawn(pet);
  4641. string random_pet_name;
  4642. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4643. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4644. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4645. pet->SetName(random_pet_name.c_str());
  4646. pet->SetLevel(spawn->GetLevel());
  4647. pet->SetFactionID(spawn->GetFactionID());
  4648. pet->SetPet(true);
  4649. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4650. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4651. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4652. pet->SetSpawnType(6);
  4653. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4654. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4655. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4656. if (strlen(pet->GetSubTitle()) > 0) {
  4657. string pet_subtitle;
  4658. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4659. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4660. pet->SetSubTitle(pet_subtitle.c_str());
  4661. }
  4662. pet->SetAttackable(false);
  4663. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4664. lua_interface->SetSpawnValue(state, pet);
  4665. return 1;
  4666. }
  4667. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4668. if (!lua_interface)
  4669. return 0;
  4670. Spawn* spawn = lua_interface->GetSpawn(state);
  4671. if (!spawn) {
  4672. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4673. return 0;
  4674. }
  4675. if (!spawn->IsPet()) {
  4676. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4677. return 0;
  4678. }
  4679. if (!((NPC*)spawn)->IsDismissing())
  4680. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4681. return 0;
  4682. }
  4683. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4684. if (!lua_interface)
  4685. return 0;
  4686. Quest* quest = lua_interface->GetQuest(state);
  4687. if (!quest) {
  4688. 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));
  4689. return 0;
  4690. }
  4691. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4692. if (feather_color > 0)
  4693. quest->SetFeatherColor(feather_color);
  4694. return 0;
  4695. }
  4696. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4697. if (!lua_interface)
  4698. return 0;
  4699. Spawn* spawn = lua_interface->GetSpawn(state);
  4700. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4701. if (!spawn) {
  4702. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4703. return 0;
  4704. }
  4705. if (!spawn2) {
  4706. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4707. return 0;
  4708. }
  4709. spawn->RemoveSpawnAccess(spawn2);
  4710. return 0;
  4711. }
  4712. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4713. if (!lua_interface)
  4714. return 0;
  4715. ZoneServer* zone = lua_interface->GetZone(state);
  4716. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4717. if (!zone) {
  4718. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4719. return 0;
  4720. }
  4721. if (location_id == 0) {
  4722. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4723. return 0;
  4724. }
  4725. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4726. if (!location) {
  4727. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4728. return 0;
  4729. }
  4730. Spawn* spawn = 0;
  4731. if (location->entities[0]) {
  4732. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4733. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4734. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4735. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4736. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4737. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4738. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4739. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4740. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4741. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4742. if (spawn) {
  4743. const char* script = 0;
  4744. for (int x = 0; x < 3; x++) {
  4745. switch (x) {
  4746. case 0:
  4747. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4748. break;
  4749. case 1:
  4750. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4751. break;
  4752. case 2:
  4753. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4754. break;
  4755. }
  4756. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4757. spawn->SetSpawnScript(string(script));
  4758. break;
  4759. }
  4760. }
  4761. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4762. lua_interface->SetSpawnValue(state, spawn);
  4763. return 1;
  4764. }
  4765. else {
  4766. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4767. safe_delete(spawn);
  4768. }
  4769. }
  4770. return 0;
  4771. }
  4772. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4773. if (!lua_interface)
  4774. return 0;
  4775. Spawn* caster = lua_interface->GetSpawn(state);
  4776. Spawn* target = lua_interface->GetSpawn(state, 2);
  4777. int32 id = lua_interface->GetInt32Value(state, 3);
  4778. string command = lua_interface->GetStringValue(state, 4);
  4779. if (!caster) {
  4780. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4781. return 0;
  4782. }
  4783. if (!target) {
  4784. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4785. return 0;
  4786. }
  4787. if (!caster->IsPlayer()) {
  4788. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4789. return 0;
  4790. }
  4791. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4792. if (!entity_command) {
  4793. 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());
  4794. return 0;
  4795. }
  4796. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4797. if (!client) {
  4798. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4799. return 0;
  4800. }
  4801. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4802. return 0;
  4803. }
  4804. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4805. if (!lua_interface)
  4806. return 0;
  4807. Spawn* spawn = lua_interface->GetSpawn(state);
  4808. if (!spawn) {
  4809. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4810. return 0;
  4811. }
  4812. if (!spawn->IsNPC()) {
  4813. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4814. return 0;
  4815. }
  4816. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4817. return 0;
  4818. }
  4819. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4820. if (!lua_interface)
  4821. return 0;
  4822. Spawn* spawn = lua_interface->GetSpawn(state);
  4823. int16 tick = lua_interface->GetInt16Value(state, 2);
  4824. if (!spawn) {
  4825. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4826. return 0;
  4827. }
  4828. if (!spawn->IsNPC()) {
  4829. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4830. return 0;
  4831. }
  4832. if (tick < 20) {
  4833. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4834. return 0;
  4835. }
  4836. ((NPC*)spawn)->Brain()->SetTick(tick);
  4837. return 0;
  4838. }
  4839. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4840. if (!lua_interface)
  4841. return 0;
  4842. Spawn* spawn = lua_interface->GetSpawn(state);
  4843. Spawn* target = lua_interface->GetSpawn(state, 2);
  4844. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4845. if (!spawn) {
  4846. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4847. return 0;
  4848. }
  4849. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4850. spawn->SetFollowTarget(target, follow_distance);
  4851. return 0;
  4852. }
  4853. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4854. if (!lua_interface)
  4855. return 0;
  4856. Spawn* spawn = lua_interface->GetSpawn(state);
  4857. if (!spawn) {
  4858. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4859. return 0;
  4860. }
  4861. Spawn* target = spawn->GetFollowTarget();
  4862. if (target) {
  4863. lua_interface->SetSpawnValue(state, target);
  4864. return 1;
  4865. }
  4866. return 0;
  4867. }
  4868. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4869. if (!lua_interface)
  4870. return 0;
  4871. Spawn* spawn = lua_interface->GetSpawn(state);
  4872. if (!spawn) {
  4873. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4874. return 0;
  4875. }
  4876. if (spawn->following)
  4877. spawn->following = false;
  4878. else
  4879. spawn->following = true;
  4880. return 0;
  4881. }
  4882. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4883. if (!lua_interface)
  4884. return 0;
  4885. Spawn* spawn = lua_interface->GetSpawn(state);
  4886. if (!spawn) {
  4887. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4888. return 0;
  4889. }
  4890. lua_interface->SetBooleanValue(state, spawn->following);
  4891. return 1;
  4892. }
  4893. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4894. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4895. // I will attempt to explain how this function works for future refrence
  4896. // Fist lets make sure lua_interface is valid, if not return out
  4897. if (!lua_interface)
  4898. return 0;
  4899. // Next we grab the first 2 params same as we usually would
  4900. Spawn* spawn = lua_interface->GetSpawn(state);
  4901. string var = lua_interface->GetStringValue(state, 2);
  4902. // 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
  4903. // 1 = Spawn
  4904. // 2 = Zone
  4905. // 3 = Item
  4906. // 4 = Quest
  4907. // 5 = String
  4908. // 6 = nil (null)
  4909. int8 dataType = 0;
  4910. // Define pointers for each potential type
  4911. Spawn* spawnVal = 0;
  4912. ZoneServer* zone = 0;
  4913. Item* item = 0;
  4914. Quest* quest = 0;
  4915. string val;
  4916. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4917. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4918. // options window are also light user data be we do not handle those.
  4919. // We check with lua_islightuserdata(lua_State*, index)
  4920. if (lua_islightuserdata(state, 3)) {
  4921. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4922. // and convert it to LUAUserData*
  4923. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4924. // Check to make sure the data we got is valid, if not give an error
  4925. if (!data || !data->IsCorrectlyInitialized()) {
  4926. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4927. }
  4928. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4929. else if (data->IsSpawn()) {
  4930. spawnVal = data->spawn;
  4931. dataType = 1;
  4932. }
  4933. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4934. else if (data->IsZone()) {
  4935. zone = data->zone;
  4936. dataType = 2;
  4937. }
  4938. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4939. else if (data->IsItem()) {
  4940. item = data->item;
  4941. dataType = 3;
  4942. }
  4943. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4944. else if (data->IsQuest()) {
  4945. quest = data->quest;
  4946. dataType = 4;
  4947. }
  4948. }
  4949. // Wasn't light user data, check if it is nil(null)
  4950. else if (lua_isnil(state, 3)) {
  4951. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4952. dataType = 6;
  4953. }
  4954. // Wasn't light user data or nil (null), must be a string
  4955. else {
  4956. // Set the string and dataType variable
  4957. val = lua_interface->GetStringValue(state, 3);
  4958. dataType = 5;
  4959. }
  4960. // We now have all the params, lets check to make sure they are valid
  4961. if (!spawn) {
  4962. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4963. return 0;
  4964. }
  4965. if (var.length() == 0) {
  4966. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4967. return 0;
  4968. }
  4969. if (dataType == 0) {
  4970. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4971. return 0;
  4972. }
  4973. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4974. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4975. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4976. switch (dataType) {
  4977. case 1:
  4978. // 1 = Spawn
  4979. spawn->AddTempVariable(var, spawnVal);
  4980. break;
  4981. case 2:
  4982. // 2 = Zone
  4983. spawn->AddTempVariable(var, zone);
  4984. break;
  4985. case 3:
  4986. // 3 = Item
  4987. spawn->AddTempVariable(var, item);
  4988. break;
  4989. case 4:
  4990. // 4 = Quest
  4991. spawn->AddTempVariable(var, quest);
  4992. break;
  4993. case 5:
  4994. // 5 = String
  4995. spawn->AddTempVariable(var, val);
  4996. break;
  4997. case 6:
  4998. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4999. spawn->DeleteTempVariable(var);
  5000. break;
  5001. }
  5002. // And we are done so return out
  5003. return 0;
  5004. }
  5005. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5006. if (!lua_interface)
  5007. return 0;
  5008. Spawn* spawn = lua_interface->GetSpawn(state);
  5009. string var = lua_interface->GetStringValue(state, 2);
  5010. if (!spawn) {
  5011. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5012. return 0;
  5013. }
  5014. if (var.length() == 0) {
  5015. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5016. return 0;
  5017. }
  5018. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5019. int8 type = spawn->GetTempVariableType(var);
  5020. Spawn* spawn2 = 0;
  5021. ZoneServer* zone = 0;
  5022. Item* item = 0;
  5023. Quest* quest = 0;
  5024. // Set the lua function return value based on the type of data the variable contains
  5025. switch (type) {
  5026. case 1:
  5027. spawn2 = spawn->GetTempVariableSpawn(var);
  5028. if (!spawn2)
  5029. return 0;
  5030. lua_interface->SetSpawnValue(state, spawn2);
  5031. break;
  5032. case 2:
  5033. zone = spawn->GetTempVariableZone(var);
  5034. if (!zone)
  5035. return 0;
  5036. lua_interface->SetZoneValue(state, zone);
  5037. break;
  5038. case 3:
  5039. item = spawn->GetTempVariableItem(var);
  5040. if (!item)
  5041. return 0;
  5042. lua_interface->SetItemValue(state, item);
  5043. break;
  5044. case 4:
  5045. quest = spawn->GetTempVariableQuest(var);
  5046. if (!quest)
  5047. return 0;
  5048. lua_interface->SetQuestValue(state, quest);
  5049. break;
  5050. case 5:
  5051. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5052. break;
  5053. default:
  5054. // Not a valid type then the variable was not set so return out
  5055. return 0;
  5056. }
  5057. // Return value was set so return out
  5058. return 1;
  5059. }
  5060. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5061. {
  5062. if (!lua_interface)
  5063. return 0;
  5064. Quest* quest = lua_interface->GetQuest(state);
  5065. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5066. string description = lua_interface->GetStringValue(state, 3);
  5067. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5068. if (!quest) {
  5069. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5070. lua_interface->SetBooleanValue(state, false);
  5071. return 1;
  5072. }
  5073. if (!spawn) {
  5074. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5075. lua_interface->SetBooleanValue(state, false);
  5076. return 1;
  5077. }
  5078. if (!spawn->IsPlayer()) {
  5079. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5080. lua_interface->SetBooleanValue(state, false);
  5081. return 1;
  5082. }
  5083. if (item_id == 0) {
  5084. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5085. lua_interface->SetBooleanValue(state, false);
  5086. return 1;
  5087. }
  5088. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5089. if (!client) {
  5090. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5091. lua_interface->SetBooleanValue(state, false);
  5092. return 1;
  5093. }
  5094. Item* item = master_item_list.GetItem(item_id);
  5095. if (!item) {
  5096. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5097. lua_interface->SetBooleanValue(state, false);
  5098. return 1;
  5099. }
  5100. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  5101. if (packet) {
  5102. packet->setDataByName("title", "Quest Reward!");
  5103. packet->setDataByName("name", quest->GetName());
  5104. packet->setDataByName("description", description.c_str());
  5105. packet->setDataByName("level", quest->GetLevel());
  5106. packet->setArrayLengthByName("num_rewards", 1);
  5107. packet->setArrayDataByName("reward_id", item->details.item_id);
  5108. if (client->GetVersion() < 860)
  5109. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  5110. else if (client->GetVersion() < 1193)
  5111. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  5112. else
  5113. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  5114. client->QueuePacket(packet->serialize());
  5115. safe_delete(packet);
  5116. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  5117. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  5118. return 1;
  5119. }
  5120. lua_interface->SetBooleanValue(state, false);
  5121. return 1;
  5122. }
  5123. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5124. if (!lua_interface)
  5125. return 0;
  5126. Quest* quest = lua_interface->GetQuest(state);
  5127. if (!quest) {
  5128. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5129. return 0;
  5130. }
  5131. quest->SetRepeatable(true);
  5132. return 0;
  5133. }
  5134. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5135. if (!lua_interface)
  5136. return 0;
  5137. Spawn* spawn = lua_interface->GetSpawn(state);
  5138. if (!spawn) {
  5139. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5140. return 0;
  5141. }
  5142. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5143. string ret = classes.GetClassNameCase(base_class);
  5144. if (ret.length() > 0) {
  5145. lua_interface->SetStringValue(state, ret.c_str());
  5146. return 1;
  5147. }
  5148. return 0;
  5149. }
  5150. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5151. if (!lua_interface)
  5152. return 0;
  5153. Spawn* player = lua_interface->GetSpawn(state);
  5154. if (player && player->IsPlayer()) {
  5155. Client* client = player->GetClient();
  5156. if (client)
  5157. client->SendWaypoints();
  5158. }
  5159. return 0;
  5160. }
  5161. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5162. if (!lua_interface)
  5163. return 0;
  5164. Spawn* player = lua_interface->GetSpawn(state);
  5165. string name = lua_interface->GetStringValue(state, 2);
  5166. int32 type = lua_interface->GetInt32Value(state, 3);
  5167. if (type == 0)
  5168. type = 2;
  5169. if (name.length() > 0) {
  5170. if (player && player->IsPlayer()) {
  5171. Client* client = player->GetClient();
  5172. if (client)
  5173. client->AddWaypoint(name, type);
  5174. }
  5175. }
  5176. return 0;
  5177. }
  5178. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5179. if (!lua_interface)
  5180. return 0;
  5181. Spawn* player = lua_interface->GetSpawn(state);
  5182. string name = lua_interface->GetStringValue(state, 2);
  5183. if (name.length() > 0) {
  5184. if (player && player->IsPlayer()) {
  5185. Client* client = player->GetClient();
  5186. if (client)
  5187. client->RemoveWaypoint(name);
  5188. }
  5189. }
  5190. return 0;
  5191. }
  5192. int EQ2Emu_lua_AddWard(lua_State* state) {
  5193. if (!lua_interface)
  5194. return 0;
  5195. int32 damage = lua_interface->GetInt32Value(state);
  5196. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5197. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5198. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5199. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5200. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5201. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5202. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5203. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5204. bool ward_was_added = false;
  5205. ZoneServer* zone = spell->caster->GetZone();
  5206. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5207. for (int32 i = 0; i < spell->targets.size(); i++) {
  5208. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5209. if (!target)
  5210. continue;
  5211. if (target->IsEntity()) {
  5212. // If the ward is already active remove it
  5213. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5214. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5215. // Create new ward info
  5216. WardInfo* ward = new WardInfo;
  5217. ward->Spell = spell;
  5218. ward->BaseDamage = damage;
  5219. ward->DamageLeft = damage;
  5220. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5221. ward->keepWard = keepWard;
  5222. ward->WardType = wardType;
  5223. if (damageAbsorptionPercent > 100)
  5224. damageAbsorptionPercent = 100;
  5225. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5226. if (damageAbsorptionMaxHealthPercent > 100)
  5227. damageAbsorptionMaxHealthPercent = 100;
  5228. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5229. ward->RedirectDamagePercent = redirectDamagePercent;
  5230. ward->LastRedirectDamage = 0;
  5231. ward->LastAbsorbedDamage = 0;
  5232. ward->HitCount = 0;
  5233. spell->num_triggers = maxHitCount;
  5234. spell->had_triggers = true;
  5235. spell->cancel_after_all_triggers = false;
  5236. ward->MaxHitCount = maxHitCount;
  5237. if (wardType == WARD_TYPE_MAGICAL)
  5238. ward->DamageType = damageTypes;
  5239. // Add the ward to the entity
  5240. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5241. ward_was_added = true;
  5242. }
  5243. }
  5244. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5245. if (ward_was_added && spell->caster->IsPlayer()) {
  5246. spell->had_dmg_remaining = true;
  5247. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5248. }
  5249. return 0;
  5250. }
  5251. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5252. if (!lua_interface)
  5253. return 0;
  5254. int32 amount = lua_interface->GetInt32Value(state);
  5255. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5256. WardInfo* ward = 0;
  5257. ZoneServer* zone = spell->caster->GetZone();
  5258. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5259. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5260. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5261. ward = target->GetWard(spell->spell->GetSpellID());
  5262. if (ward) {
  5263. ward->DamageLeft += amount;
  5264. if (ward->DamageLeft > ward->BaseDamage)
  5265. ward->DamageLeft = ward->BaseDamage;
  5266. for (int32 i = 0; i < spell->targets.size(); i++) {
  5267. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5268. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5269. }
  5270. }
  5271. }
  5272. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5273. if (ward && spell->caster->IsPlayer())
  5274. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5275. return 0;
  5276. }
  5277. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5278. if (!lua_interface)
  5279. return 0;
  5280. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5281. if (!spell) {
  5282. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5283. return 0;
  5284. }
  5285. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5286. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5287. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5288. if (ward) {
  5289. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5290. return 1;
  5291. }
  5292. }
  5293. return 0;
  5294. }
  5295. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5296. if (!lua_interface)
  5297. return 0;
  5298. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5299. if (!spell) {
  5300. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5301. return 0;
  5302. }
  5303. string type = lua_interface->GetStringValue(state, 2);
  5304. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5305. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5306. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5307. if (ward) {
  5308. if (boost::iequals(type, "damageleft"))
  5309. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5310. else if (boost::iequals(type, "basedamage"))
  5311. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5312. else if (boost::iequals(type, "keepward"))
  5313. lua_interface->SetBooleanValue(state, ward->keepWard);
  5314. else if (boost::iequals(type, "wardtype"))
  5315. lua_interface->SetInt32Value(state, ward->WardType);
  5316. else if (boost::iequals(type, "dmgabsorptionpct"))
  5317. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5318. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5319. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5320. else if (boost::iequals(type, "redirectdamagepercent"))
  5321. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5322. else if (boost::iequals(type, "lastredirectdamage"))
  5323. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5324. else if (boost::iequals(type, "lastabsorbeddamage"))
  5325. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5326. else if (boost::iequals(type, "hitcount"))
  5327. lua_interface->SetInt32Value(state, ward->HitCount);
  5328. else if (boost::iequals(type, "maxhitcount"))
  5329. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5330. else
  5331. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5332. return 1;
  5333. }
  5334. }
  5335. return 0;
  5336. }
  5337. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5338. if (!lua_interface)
  5339. return 0;
  5340. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5341. ZoneServer* zone = spell->caster->GetZone();
  5342. Spawn* target = 0;
  5343. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5344. for (int32 i = 0; i < spell->targets.size(); i++) {
  5345. target = zone->GetSpawnByID(spell->targets.at(i));
  5346. if (target && target->IsEntity()) {
  5347. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5348. }
  5349. }
  5350. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5351. return 0;
  5352. }
  5353. int EQ2Emu_lua_Interrupt(lua_State* state)
  5354. {
  5355. if (!lua_interface)
  5356. return 0;
  5357. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5358. Spawn* target = lua_interface->GetSpawn(state, 2);
  5359. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5360. if (!caster)
  5361. {
  5362. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5363. return 0;
  5364. }
  5365. if (!target)
  5366. {
  5367. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5368. return 0;
  5369. }
  5370. if (!spell) {
  5371. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5372. return 0;
  5373. }
  5374. if (!target->IsEntity() && !spell)
  5375. {
  5376. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5377. return 0;
  5378. }
  5379. if (!target && spell) {
  5380. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5381. for (int8 i = 0; i < spell->targets.size(); i++) {
  5382. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5383. if (!target || !target->IsEntity())
  5384. continue;
  5385. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5386. }
  5387. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5388. }
  5389. else
  5390. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5391. return 0;
  5392. }
  5393. int EQ2Emu_lua_Stealth(lua_State* state) {
  5394. if (!lua_interface)
  5395. return 0;
  5396. int8 type = lua_interface->GetInt8Value(state);
  5397. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5398. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5399. if (!spell) {
  5400. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5401. return 0;
  5402. }
  5403. ZoneServer* zone = spell->caster->GetZone();
  5404. if (spawn) {
  5405. if (spawn->IsEntity()) {
  5406. if (type == 1) {
  5407. ((Entity*)spawn)->AddStealthSpell(spell);
  5408. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5409. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5410. }
  5411. else if (type == 2) {
  5412. ((Entity*)spawn)->AddInvisSpell(spell);
  5413. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5414. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5415. }
  5416. return 0;
  5417. }
  5418. else {
  5419. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5420. return 0;
  5421. }
  5422. }
  5423. else {
  5424. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5425. for (int32 i = 0; i < spell->targets.size(); i++) {
  5426. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5427. if (!spawn || !spawn->IsEntity())
  5428. continue;
  5429. if (type == 1) {
  5430. ((Entity*)spawn)->AddStealthSpell(spell);
  5431. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5432. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5433. }
  5434. else if (type == 2) {
  5435. ((Entity*)spawn)->AddInvisSpell(spell);
  5436. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5437. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5438. }
  5439. else {
  5440. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5441. break;
  5442. }
  5443. }
  5444. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5445. }
  5446. return 0;
  5447. }
  5448. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5449. if (!lua_interface)
  5450. return 0;
  5451. Spawn* spawn = lua_interface->GetSpawn(state);
  5452. if (!spawn) {
  5453. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5454. return 0;
  5455. }
  5456. if (spawn->IsEntity()) {
  5457. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5458. return 1;
  5459. }
  5460. else
  5461. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5462. return 0;
  5463. }
  5464. int EQ2Emu_lua_IsInvis(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 IsInvis 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)->IsInvis());
  5474. return 1;
  5475. }
  5476. else
  5477. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5478. return 0;
  5479. }
  5480. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5481. if (!lua_interface)
  5482. return 0;
  5483. Spawn* player = lua_interface->GetSpawn(state);
  5484. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5485. lua_interface->ResetFunctionStack(state);
  5486. if (!player->IsPlayer()) {
  5487. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5488. return 0;
  5489. }
  5490. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5491. return 1;
  5492. }
  5493. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5494. if (!lua_interface)
  5495. return 0;
  5496. Spawn* player = lua_interface->GetSpawn(state);
  5497. int8 slot = lua_interface->GetInt8Value(state, 2);
  5498. lua_interface->ResetFunctionStack(state);
  5499. if (!player) {
  5500. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5501. return 0;
  5502. }
  5503. if (!player->IsPlayer()) {
  5504. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5505. return 0;
  5506. }
  5507. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5508. if (!item) {
  5509. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5510. return 0;
  5511. }
  5512. lua_interface->SetItemValue(state, item);
  5513. return 1;
  5514. }
  5515. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5516. if (!lua_interface)
  5517. return 0;
  5518. Spawn* player = lua_interface->GetSpawn(state);
  5519. int32 id = lua_interface->GetInt32Value(state, 2);
  5520. lua_interface->ResetFunctionStack(state);
  5521. if (!player) {
  5522. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5523. return 0;
  5524. }
  5525. if (!player->IsPlayer()) {
  5526. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5527. return 0;
  5528. }
  5529. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5530. if (!item) {
  5531. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5532. return 0;
  5533. }
  5534. lua_interface->SetItemValue(state, item);
  5535. return 1;
  5536. }
  5537. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5538. if (!lua_interface)
  5539. return 0;
  5540. Spawn* spawn = lua_interface->GetSpawn(state);
  5541. int8 slot = lua_interface->GetInt8Value(state, 2);
  5542. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5543. lua_interface->ResetFunctionStack(state);
  5544. if (!spawn) {
  5545. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5546. return 0;
  5547. }
  5548. if (!spawn->IsEntity()) {
  5549. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5550. return 0;
  5551. }
  5552. Item* item = master_item_list.GetItem(item_id);
  5553. if (!item) {
  5554. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5555. return 0;
  5556. }
  5557. Item* copy = new Item(item);
  5558. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5559. if(result)
  5560. {
  5561. ((Entity*)spawn)->SetEquipment(copy, slot);
  5562. spawn->vis_changed = true;
  5563. if(spawn->IsPlayer())
  5564. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5565. }
  5566. else
  5567. {
  5568. safe_delete(copy);
  5569. }
  5570. lua_interface->SetBooleanValue(state, result);
  5571. return 1;
  5572. }
  5573. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5574. if (!lua_interface)
  5575. return 0;
  5576. Spawn* spawn = lua_interface->GetSpawn(state);
  5577. int8 slot = lua_interface->GetInt8Value(state, 2);
  5578. Item* item = lua_interface->GetItem(state, 3);
  5579. lua_interface->ResetFunctionStack(state);
  5580. if (!spawn) {
  5581. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5582. return 0;
  5583. }
  5584. if (!spawn->IsEntity()) {
  5585. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5586. return 0;
  5587. }
  5588. if (!item) {
  5589. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5590. return 0;
  5591. }
  5592. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5593. if(result)
  5594. {
  5595. ((Entity*)spawn)->SetEquipment(item, slot);
  5596. spawn->vis_changed = true;
  5597. if(spawn->IsPlayer())
  5598. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5599. }
  5600. lua_interface->SetBooleanValue(state, result);
  5601. return 1;
  5602. }
  5603. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5604. if (!lua_interface)
  5605. return 0;
  5606. Spawn* spawn = lua_interface->GetSpawn(state);
  5607. int8 slot = lua_interface->GetInt8Value(state, 2);
  5608. 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
  5609. lua_interface->ResetFunctionStack(state);
  5610. if (!spawn) {
  5611. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5612. return 0;
  5613. }
  5614. if (!spawn->IsEntity()) {
  5615. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5616. return 0;
  5617. }
  5618. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5619. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5620. spawn->vis_changed = true;
  5621. if(spawn->IsPlayer())
  5622. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5623. lua_interface->SetBooleanValue(state, true);
  5624. return 1;
  5625. }
  5626. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5627. if (!lua_interface)
  5628. return 0;
  5629. Spawn* spawn = lua_interface->GetSpawn(state);
  5630. int8 slot = lua_interface->GetInt8Value(state, 2);
  5631. int16 type = lua_interface->GetInt16Value(state, 3);
  5632. int8 r = lua_interface->GetInt8Value(state, 4);
  5633. int8 g = lua_interface->GetInt8Value(state, 5);
  5634. int8 b = lua_interface->GetInt8Value(state, 6);
  5635. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5636. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5637. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5638. lua_interface->ResetFunctionStack(state);
  5639. if (!spawn) {
  5640. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5641. return 0;
  5642. }
  5643. if (!spawn->IsEntity()) {
  5644. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5645. return 0;
  5646. }
  5647. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5648. spawn->vis_changed = true;
  5649. lua_interface->SetBooleanValue(state, true);
  5650. return 1;
  5651. }
  5652. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5653. if (!lua_interface)
  5654. return 0;
  5655. Spawn* player = lua_interface->GetSpawn(state);
  5656. int32 id = lua_interface->GetInt32Value(state, 2);
  5657. int8 count = lua_interface->GetInt8Value(state, 3);
  5658. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5659. lua_interface->ResetFunctionStack(state);
  5660. if (!player) {
  5661. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5662. return 0;
  5663. }
  5664. if (!player->IsPlayer()) {
  5665. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5666. return 0;
  5667. }
  5668. if (!count)
  5669. count = 1;
  5670. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5671. if (!item) {
  5672. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5673. return 0;
  5674. }
  5675. lua_interface->SetItemValue(state, item);
  5676. return 1;
  5677. }
  5678. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5679. if (!lua_interface)
  5680. return 0;
  5681. Spawn* spawn = lua_interface->GetSpawn(state);
  5682. int32 anim = lua_interface->GetInt32Value(state, 2);
  5683. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5684. int8 type = lua_interface->GetInt8Value(state, 4);
  5685. if (!spawn) {
  5686. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5687. return 0;
  5688. }
  5689. if (spawn2) {
  5690. if (spawn2->IsPlayer()) {
  5691. if (type != 1 && type != 2)
  5692. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5693. else
  5694. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5695. return 0;
  5696. }
  5697. else {
  5698. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5699. return 0;
  5700. }
  5701. }
  5702. else
  5703. spawn->GetZone()->PlayAnimation(spawn, anim);
  5704. return 0;
  5705. }
  5706. int EQ2Emu_lua_IsPet(lua_State* state) {
  5707. if (!lua_interface)
  5708. return 0;
  5709. Spawn* spawn = lua_interface->GetSpawn(state);
  5710. if (!spawn) {
  5711. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5712. return 0;
  5713. }
  5714. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5715. return 1;
  5716. }
  5717. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5718. if (!lua_interface)
  5719. return 0;
  5720. Spawn* spawn = lua_interface->GetSpawn(state);
  5721. if (!spawn) {
  5722. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5723. return 0;
  5724. }
  5725. if (!spawn->IsNPC()) {
  5726. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5727. return 0;
  5728. }
  5729. if (((NPC*)spawn)->GetOwner()) {
  5730. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5731. return 1;
  5732. }
  5733. return 0;
  5734. }
  5735. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5736. if (!lua_interface)
  5737. return 0;
  5738. Spawn* spawn = lua_interface->GetSpawn(state);
  5739. Spawn* target = lua_interface->GetSpawn(state, 2);
  5740. if (!spawn) {
  5741. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5742. return 0;
  5743. }
  5744. if (!spawn) {
  5745. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5746. return 0;
  5747. }
  5748. spawn->SetTarget(target);
  5749. return 0;
  5750. }
  5751. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5752. if (!lua_interface)
  5753. return 0;
  5754. Spawn* spawn = lua_interface->GetSpawn(state);
  5755. bool val = lua_interface->GetBooleanValue(state, 2);
  5756. if (!spawn) {
  5757. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5758. return 0;
  5759. }
  5760. if (!spawn->IsEntity()) {
  5761. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5762. return 0;
  5763. }
  5764. ((Entity*)spawn)->InCombat(val);
  5765. if (val) {
  5766. spawn->ClearRunningLocations();
  5767. spawn->CalculateRunningLocation(true);
  5768. }
  5769. return 0;
  5770. }
  5771. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5772. if (!lua_interface)
  5773. return 0;
  5774. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5775. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5776. if (!spawn1) {
  5777. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. if (!spawn2) {
  5781. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5782. return 0;
  5783. }
  5784. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5785. return 1;
  5786. }
  5787. int EQ2Emu_lua_Runback(lua_State* state) {
  5788. if (!lua_interface)
  5789. return 0;
  5790. Spawn* spawn = lua_interface->GetSpawn(state);
  5791. if (!spawn) {
  5792. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5793. return 0;
  5794. }
  5795. if (!spawn->IsNPC()) {
  5796. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5797. return 0;
  5798. }
  5799. ((NPC*)spawn)->Runback();
  5800. return 0;
  5801. }
  5802. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5803. if (!lua_interface)
  5804. return 0;
  5805. Spawn* spawn = lua_interface->GetSpawn(state);
  5806. if (!spawn) {
  5807. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5808. return 0;
  5809. }
  5810. if (!spawn->IsNPC()) {
  5811. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5812. return 0;
  5813. }
  5814. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5815. return 1;
  5816. }
  5817. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5818. if (!lua_interface)
  5819. return 0;
  5820. Spawn* spawn = lua_interface->GetSpawn(state);
  5821. if (!spawn) {
  5822. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5823. return 0;
  5824. }
  5825. if (!spawn->IsEntity()) {
  5826. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5827. return 0;
  5828. }
  5829. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5830. return 1;
  5831. }
  5832. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5833. if (!lua_interface)
  5834. return 0;
  5835. Spawn* spawn = lua_interface->GetSpawn(state);
  5836. if (!spawn) {
  5837. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5838. return 0;
  5839. }
  5840. if (!spawn->IsEntity()) {
  5841. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5842. return 0;
  5843. }
  5844. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5845. return 1;
  5846. }
  5847. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5848. if (!lua_interface)
  5849. return 0;
  5850. Spawn* spawn = lua_interface->GetSpawn(state);
  5851. if (!spawn) {
  5852. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5853. return 0;
  5854. }
  5855. if (!spawn->IsEntity()) {
  5856. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5857. return 0;
  5858. }
  5859. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5860. return 1;
  5861. }
  5862. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5863. if (!lua_interface)
  5864. return 0;
  5865. Spawn* spawn = lua_interface->GetSpawn(state);
  5866. if (!spawn) {
  5867. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5868. return 0;
  5869. }
  5870. if (!spawn->IsEntity()) {
  5871. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5872. return 0;
  5873. }
  5874. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5875. return 1;
  5876. }
  5877. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5878. if (!lua_interface)
  5879. return 0;
  5880. Spawn* spawn = lua_interface->GetSpawn(state);
  5881. Spawn* target = lua_interface->GetSpawn(state, 2);
  5882. float distance = lua_interface->GetFloatValue(state, 3);
  5883. if (!spawn) {
  5884. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5885. return 0;
  5886. }
  5887. if (!target) {
  5888. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5889. return 0;
  5890. }
  5891. if (!spawn->IsNPC()) {
  5892. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5893. return 0;
  5894. }
  5895. if (!target->IsEntity()) {
  5896. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5897. return 0;
  5898. }
  5899. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5900. return 1;
  5901. }
  5902. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5903. if (!lua_interface)
  5904. return 0;
  5905. Spawn* spawn = lua_interface->GetSpawn(state);
  5906. Spawn* target = lua_interface->GetSpawn(state, 2);
  5907. float distance = lua_interface->GetFloatValue(state, 3);
  5908. if (!spawn) {
  5909. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5910. return 0;
  5911. }
  5912. if (!target) {
  5913. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5914. return 0;
  5915. }
  5916. if (!spawn->IsNPC()) {
  5917. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5918. return 0;
  5919. }
  5920. if (!target->IsEntity()) {
  5921. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5922. return 0;
  5923. }
  5924. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5925. return 0;
  5926. }
  5927. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5928. if (!lua_interface)
  5929. return 0;
  5930. Spawn* spawn = lua_interface->GetSpawn(state);
  5931. if (!spawn) {
  5932. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5933. return 0;
  5934. }
  5935. if (!spawn->IsNPC()) {
  5936. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5937. return 0;
  5938. }
  5939. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5940. return 1;
  5941. }
  5942. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5943. if (!lua_interface)
  5944. return 0;
  5945. Spawn* spawn = lua_interface->GetSpawn(state);
  5946. if (!spawn) {
  5947. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5948. return 0;
  5949. }
  5950. if (!spawn->IsNPC()) {
  5951. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5952. return 0;
  5953. }
  5954. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5955. return 1;
  5956. }
  5957. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5958. if (!lua_interface)
  5959. return 0;
  5960. Spawn* spawn = lua_interface->GetSpawn(state);
  5961. if (!spawn) {
  5962. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5963. return 0;
  5964. }
  5965. if (!spawn->IsNPC()) {
  5966. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5967. return 0;
  5968. }
  5969. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5970. if (hated) {
  5971. lua_interface->SetSpawnValue(state, hated);
  5972. return 1;
  5973. }
  5974. return 0;
  5975. }
  5976. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5977. if (!lua_interface)
  5978. return 0;
  5979. Spawn* spawn = lua_interface->GetSpawn(state);
  5980. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5981. if (!spawn) {
  5982. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5983. return 0;
  5984. }
  5985. if (!spawn->IsNPC()) {
  5986. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5987. return 0;
  5988. }
  5989. if (!hated) {
  5990. ((NPC*)spawn)->Brain()->ClearHate();
  5991. return 0;
  5992. }
  5993. else
  5994. {
  5995. if (!hated->IsEntity()) {
  5996. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5997. return 0;
  5998. }
  5999. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6000. return 0;
  6001. }
  6002. return 0;
  6003. }
  6004. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6005. if (!lua_interface)
  6006. return 0;
  6007. Spawn* spawn = lua_interface->GetSpawn(state);
  6008. if (!spawn) {
  6009. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6010. return 0;
  6011. }
  6012. if (!spawn->IsNPC()) {
  6013. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6014. return 0;
  6015. }
  6016. ((NPC*)spawn)->Brain()->ClearEncounter();
  6017. return 0;
  6018. }
  6019. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6020. if (!lua_interface)
  6021. return 0;
  6022. Spawn* spawn = lua_interface->GetSpawn(state);
  6023. if (!spawn) {
  6024. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6025. return 0;
  6026. }
  6027. if (!spawn->IsNPC()) {
  6028. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6029. return 0;
  6030. }
  6031. // Temp list to store hate list
  6032. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6033. if (encounterList->size() == 0) {
  6034. safe_delete(encounterList);
  6035. return 0;
  6036. }
  6037. lua_createtable(state, encounterList->size(), 0);
  6038. int newTable = lua_gettop(state);
  6039. for (int32 i = 0; i < encounterList->size(); i++) {
  6040. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6041. if (temp)
  6042. lua_interface->SetSpawnValue(state, temp);
  6043. lua_rawseti(state, newTable, i + 1);
  6044. }
  6045. safe_delete(encounterList);
  6046. return 1;
  6047. }
  6048. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6049. if (!lua_interface)
  6050. return 0;
  6051. Spawn* spawn = lua_interface->GetSpawn(state);
  6052. if (!spawn) {
  6053. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6054. return 0;
  6055. }
  6056. if (!spawn->IsNPC()) {
  6057. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6058. return 0;
  6059. }
  6060. // Temp list to store hate list
  6061. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6062. if (hateList->size() == 0) {
  6063. safe_delete(hateList);
  6064. return 0;
  6065. }
  6066. lua_createtable(state, hateList->size(), 0);
  6067. int newTable = lua_gettop(state);
  6068. for (int32 i = 0; i < hateList->size(); i++) {
  6069. lua_interface->SetSpawnValue(state, hateList->at(i));
  6070. lua_rawseti(state, newTable, i + 1);
  6071. }
  6072. safe_delete(hateList);
  6073. return 1;
  6074. }
  6075. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6076. if (!lua_interface)
  6077. return 0;
  6078. Spawn* spawn = lua_interface->GetSpawn(state);
  6079. if (!spawn) {
  6080. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6081. return 0;
  6082. }
  6083. if (spawn->IsPlayer()) {
  6084. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6085. lua_interface->SetBooleanValue(state, true);
  6086. else
  6087. lua_interface->SetBooleanValue(state, false);
  6088. return 1;
  6089. }
  6090. else {
  6091. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6092. return 1;
  6093. }
  6094. }
  6095. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6096. if (!lua_interface)
  6097. return 0;
  6098. Quest* quest = lua_interface->GetQuest(state);
  6099. if (!quest) {
  6100. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6101. return 0;
  6102. }
  6103. quest->SetCompletedFlag(true);
  6104. return 0;
  6105. }
  6106. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6107. if (!lua_interface)
  6108. return 0;
  6109. Spawn* spawn = lua_interface->GetSpawn(state);
  6110. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6111. int8 tier = lua_interface->GetInt8Value(state, 3);
  6112. if (!spawn) {
  6113. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6114. return 0;
  6115. }
  6116. if (!spawn->IsEntity()) {
  6117. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6118. return 0;
  6119. }
  6120. if (spellID == 0) {
  6121. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6122. return 0;
  6123. }
  6124. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6125. if (effect) {
  6126. if (tier > 0) {
  6127. // If a tier was passed chec to see if it is the same as the effect
  6128. if (tier == effect->tier)
  6129. lua_interface->SetBooleanValue(state, true);
  6130. else
  6131. lua_interface->SetBooleanValue(state, false);
  6132. return 1;
  6133. }
  6134. else {
  6135. // Have an effect but no tier was passed so return true
  6136. lua_interface->SetBooleanValue(state, true);
  6137. }
  6138. return 1;
  6139. }
  6140. // no effect so return false
  6141. lua_interface->SetBooleanValue(state, false);
  6142. return 1;
  6143. }
  6144. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6145. if (!lua_interface)
  6146. return 0;
  6147. Spawn* spawn = lua_interface->GetSpawn(state);
  6148. int32 id = lua_interface->GetInt32Value(state, 2);
  6149. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6150. Spawn* spawn2 = 0;
  6151. vector<Spawn*> list;
  6152. if (!spawn) {
  6153. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6154. return 0;
  6155. }
  6156. //If zone not provided, use spawn's zone
  6157. if (!zone)
  6158. zone = spawn->GetZone();
  6159. list = zone->GetSpawnsByID(id);
  6160. if (list.size() == 0) {
  6161. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. vector<Spawn*>::iterator itr = list.begin();
  6165. for (int8 i = 0; i < list.size(); i++) {
  6166. spawn2 = itr[i];
  6167. if (spawn2)
  6168. spawn2->AddAllowAccessSpawn(spawn);
  6169. }
  6170. return 0;
  6171. }
  6172. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6173. if (!lua_interface)
  6174. return 0;
  6175. Spawn* spawn = lua_interface->GetSpawn(state);
  6176. int32 id = lua_interface->GetInt32Value(state, 2);
  6177. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6178. Spawn* spawn2 = 0;
  6179. if (!spawn) {
  6180. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6181. return 0;
  6182. }
  6183. //If zone not provided, use spawn's zone
  6184. if (!zone)
  6185. zone = spawn->GetZone();
  6186. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6187. vector<Spawn*>::iterator itr = list.begin();
  6188. if (list.size() == 0) {
  6189. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6190. return 0;
  6191. }
  6192. for (int8 i = 0; i < list.size(); i++) {
  6193. spawn2 = itr[i];
  6194. if (spawn2)
  6195. spawn2->RemoveSpawnAccess(spawn);
  6196. }
  6197. return 0;
  6198. }
  6199. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6200. if (!lua_interface)
  6201. return 0;
  6202. Quest* quest = lua_interface->GetQuest(state);
  6203. if (!quest) {
  6204. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6205. return 0;
  6206. }
  6207. quest->SetYellowName(true);
  6208. return 0;
  6209. }
  6210. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6211. if (!lua_interface)
  6212. return 0;
  6213. Spawn* spawn = lua_interface->GetSpawn(state);
  6214. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6215. if (!spawn) {
  6216. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6217. return 0;
  6218. }
  6219. if (!spawn->IsPlayer()) {
  6220. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6221. return 0;
  6222. }
  6223. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6224. return 1;
  6225. }
  6226. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6227. if (!lua_interface)
  6228. return 0;
  6229. Spawn* spawn = lua_interface->GetSpawn(state);
  6230. if (!spawn) {
  6231. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6232. return 0;
  6233. }
  6234. if (!spawn->IsPlayer()) {
  6235. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. ZoneServer* zone = spawn->GetZone();
  6239. if (!zone) {
  6240. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6241. return 0;
  6242. }
  6243. Instance_Type iType = zone->GetInstanceType();
  6244. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6245. iType == GROUP_LOCKOUT_INSTANCE ||
  6246. iType == RAID_LOCKOUT_INSTANCE ||
  6247. iType == SOLO_PERSIST_INSTANCE ||
  6248. iType == GROUP_PERSIST_INSTANCE ||
  6249. iType == RAID_PERSIST_INSTANCE) {
  6250. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6251. if (data) {
  6252. // Check to see if the timer has already been set, if it has return out.
  6253. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6254. return 0;
  6255. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6256. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6257. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6258. if (client) {
  6259. string time_msg = "";
  6260. int32 time = data->success_lockout_time;
  6261. int16 hour;
  6262. int8 min;
  6263. int8 sec;
  6264. hour = time / 3600;
  6265. time = time % 3600;
  6266. min = time / 60;
  6267. time = time % 60;
  6268. sec = time;
  6269. if (hour > 0) {
  6270. char temp[10];
  6271. sprintf(temp, " %i", hour);
  6272. time_msg.append(temp);
  6273. time_msg.append(" hour");
  6274. time_msg.append((hour > 1) ? "s" : "");
  6275. }
  6276. if (min > 0) {
  6277. char temp[5];
  6278. sprintf(temp, " %i", min);
  6279. time_msg.append(temp);
  6280. time_msg.append(" minute");
  6281. time_msg.append((min > 1) ? "s" : "");
  6282. }
  6283. // Only add seconds if minutes and hours are 0
  6284. if (hour == 0 && min == 0 && sec > 0) {
  6285. char temp[5];
  6286. sprintf(temp, " %i", sec);
  6287. time_msg.append(temp);
  6288. time_msg.append(" second");
  6289. time_msg.append((sec > 1) ? "s" : "");
  6290. }
  6291. 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());
  6292. }
  6293. }
  6294. else
  6295. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6296. }
  6297. else
  6298. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6299. return 0;
  6300. }
  6301. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6302. if (!lua_interface)
  6303. return 0;
  6304. Spawn* spawn = lua_interface->GetSpawn(state);
  6305. if (!spawn) {
  6306. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6307. return 0;
  6308. }
  6309. if (!spawn->IsPlayer()) {
  6310. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6311. return 0;
  6312. }
  6313. ZoneServer* zone = spawn->GetZone();
  6314. if (!zone) {
  6315. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6316. return 0;
  6317. }
  6318. Instance_Type iType = zone->GetInstanceType();
  6319. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6320. iType == GROUP_LOCKOUT_INSTANCE ||
  6321. iType == RAID_LOCKOUT_INSTANCE ||
  6322. iType == SOLO_PERSIST_INSTANCE ||
  6323. iType == GROUP_PERSIST_INSTANCE ||
  6324. iType == RAID_PERSIST_INSTANCE) {
  6325. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6326. if (data) {
  6327. // Check to see if the timer has already been set, if it has return out.
  6328. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6329. return 0;
  6330. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6331. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6332. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6333. if (client) {
  6334. string time_msg = "";
  6335. int32 time = data->failure_lockout_time;
  6336. int16 hour;
  6337. int8 min;
  6338. int8 sec;
  6339. hour = time / 3600;
  6340. time = time % 3600;
  6341. min = time / 60;
  6342. time = time % 60;
  6343. sec = time;
  6344. if (hour > 0) {
  6345. char temp[10];
  6346. sprintf(temp, " %i", hour);
  6347. time_msg.append(temp);
  6348. time_msg.append(" hour");
  6349. time_msg.append((hour > 1) ? "s" : "");
  6350. }
  6351. if (min > 0) {
  6352. char temp[5];
  6353. sprintf(temp, " %i", min);
  6354. time_msg.append(temp);
  6355. time_msg.append(" minute");
  6356. time_msg.append((min > 1) ? "s" : "");
  6357. }
  6358. // Only add seconds if minutes and hours are 0
  6359. if (hour == 0 && min == 0 && sec > 0) {
  6360. char temp[5];
  6361. sprintf(temp, " %i", sec);
  6362. time_msg.append(temp);
  6363. time_msg.append(" second");
  6364. time_msg.append((sec > 1) ? "s" : "");
  6365. }
  6366. 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());
  6367. }
  6368. }
  6369. else
  6370. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6371. }
  6372. else
  6373. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6374. return 0;
  6375. }
  6376. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6377. if (!lua_interface)
  6378. return 0;
  6379. Spawn* spawn = lua_interface->GetSpawn(state);
  6380. if (!spawn) {
  6381. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6382. return 0;
  6383. }
  6384. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6385. return 1;
  6386. }
  6387. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6388. if (!lua_interface)
  6389. return 0;
  6390. Spawn* player = lua_interface->GetSpawn(state);
  6391. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6392. if (!player) {
  6393. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6394. return 0;
  6395. }
  6396. if (!player->IsPlayer()) {
  6397. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6398. return 0;
  6399. }
  6400. if (!ground) {
  6401. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6402. return 0;
  6403. }
  6404. if (!ground->IsGroundSpawn()) {
  6405. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6406. return 0;
  6407. }
  6408. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6409. if (!groundspawn_entries) {
  6410. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6411. return 0;
  6412. }
  6413. Skill* skill = 0;
  6414. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6415. if (collection_skill == "Collecting")
  6416. skill = ((Player*)player)->GetSkillByName("Gathering");
  6417. else
  6418. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6419. if (!skill) {
  6420. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6421. return 0;
  6422. }
  6423. vector<GroundSpawnEntry*>::iterator itr;
  6424. GroundSpawnEntry* entry = 0;
  6425. bool can_harvest = false;
  6426. sint32 min_skill = -1;
  6427. int16 totalSkill = skill->current_val;
  6428. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6429. if(skillID != 0xFFFFFFFF)
  6430. {
  6431. ((Entity*)player)->MStats.lock();
  6432. totalSkill += ((Entity*)player)->stats[skillID];
  6433. ((Entity*)player)->MStats.unlock();
  6434. }
  6435. // first, iterate through groundspawn_entries, discard tables player cannot use
  6436. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6437. {
  6438. entry = *itr;
  6439. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6440. min_skill = entry->min_skill_level;
  6441. // if player lacks skill, skip table
  6442. if (entry->min_skill_level > totalSkill)
  6443. continue;
  6444. // if bonus, but player lacks level, skip table
  6445. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6446. continue;
  6447. can_harvest = true;
  6448. break;
  6449. }
  6450. lua_interface->SetBooleanValue(state, can_harvest);
  6451. // If false, send the message to the client
  6452. if (!can_harvest) {
  6453. Client* client = player->GetZone()->GetClientBySpawn(player);
  6454. if (client) {
  6455. string msg = "You do not have enough skill to ";
  6456. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6457. msg.append("gather");
  6458. else if (collection_skill == "Mining")
  6459. msg.append("mine");
  6460. else if (collection_skill == "Trapping")
  6461. msg.append("trap");
  6462. else if (collection_skill == "Foresting")
  6463. msg.append("forest");
  6464. else if (collection_skill == "Fishing")
  6465. msg.append("catch");
  6466. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6467. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6468. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6469. }
  6470. }
  6471. return 1;
  6472. }
  6473. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6474. if (!lua_interface)
  6475. return 0;
  6476. Spawn* player = lua_interface->GetSpawn(state);
  6477. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6478. if (!player) {
  6479. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6480. return 0;
  6481. }
  6482. if (!player->IsPlayer()) {
  6483. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6484. return 0;
  6485. }
  6486. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6487. lua_interface->SetBooleanValue(state, ret);
  6488. return 1;
  6489. }
  6490. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6491. // Check to see if we have a valid lua_interface
  6492. if (!lua_interface)
  6493. return 0;
  6494. // Get the spawn that is getting the pet
  6495. Spawn* spawn = lua_interface->GetSpawn(state);
  6496. Spawn* target = lua_interface->GetSpawn(state, 2);
  6497. // Get the DB ID of the pet
  6498. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6499. float x = lua_interface->GetFloatValue(state, 4);
  6500. float y = lua_interface->GetFloatValue(state, 5);
  6501. float z = lua_interface->GetFloatValue(state, 6);
  6502. // Get the spell that this command was called from
  6503. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6504. // Check to make sure the spawn pointer is valid
  6505. if (!spawn) {
  6506. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6507. return 0;
  6508. }
  6509. // Check to make sure the spawn is an entity
  6510. if (!spawn->IsEntity()) {
  6511. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6512. return 0;
  6513. }
  6514. if (!target) {
  6515. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6516. return 0;
  6517. }
  6518. if (!target->IsEntity()) {
  6519. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6520. return 0;
  6521. }
  6522. // Check to see if the DB ID for the pet is set
  6523. if (pet_id == 0) {
  6524. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6525. return 0;
  6526. }
  6527. // Check to see if the pointer to the spell is valid
  6528. if (!luaspell) {
  6529. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6530. return 0;
  6531. }
  6532. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6533. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6534. if (!pet) {
  6535. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6536. return 0;
  6537. }
  6538. // Check to make sure the pet is an npc
  6539. if (!pet->IsNPC()) {
  6540. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6541. return 0;
  6542. }
  6543. if (x == 0)
  6544. x = spawn->GetX();
  6545. if (y == 0)
  6546. y = spawn->GetY();
  6547. if (z == 0)
  6548. z = spawn->GetZ();
  6549. // Spawn the pet at the same location as the owner
  6550. pet->SetX(x);
  6551. pet->SetY(y);
  6552. pet->SetZ(z);
  6553. pet->SetLocation(spawn->GetLocation());
  6554. pet->SetHeading(spawn->GetHeading());
  6555. spawn->GetZone()->AddSpawn(pet);
  6556. /*
  6557. const char* spawn_script = world.GetSpawnScript(pet_id);
  6558. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6559. spawn->SetSpawnScript(string(spawn_script));
  6560. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6561. }*/
  6562. // Get a random pet name
  6563. string random_pet_name;
  6564. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6565. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6566. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6567. // Set the pets name
  6568. pet->SetName(random_pet_name.c_str());
  6569. // Set the level of the pet to the owners level
  6570. pet->SetLevel(spawn->GetLevel());
  6571. // Set the faction of the pet to the same faction as the owner
  6572. pet->SetFactionID(spawn->GetFactionID());
  6573. // Set the spawn as a pet
  6574. pet->SetPet(true);
  6575. // Give a pointer of the owner to the pet
  6576. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6577. // Set the pet type
  6578. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6579. // Set the spell id used to create this pet
  6580. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6581. // Set the spell tier used to create this pet
  6582. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6583. // Set the pets spawn type to 6
  6584. pet->SetSpawnType(6);
  6585. // Set the pets brain
  6586. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6587. // Check to see if the pet has a subtitle
  6588. if (strlen(pet->GetSubTitle()) > 0) {
  6589. // Add the players name to the front of the sub title
  6590. string pet_subtitle;
  6591. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6592. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6593. // Set the pets subtitle to the new one
  6594. pet->SetSubTitle(pet_subtitle.c_str());
  6595. }
  6596. // Set the pet as the return value for this function
  6597. lua_interface->SetSpawnValue(state, pet);
  6598. return 1;
  6599. }
  6600. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6601. if (!lua_interface)
  6602. return 0;
  6603. Spawn* spawn = lua_interface->GetSpawn(state);
  6604. Spawn* player = lua_interface->GetSpawn(state, 2);
  6605. float max_distance = lua_interface->GetFloatValue(state, 3);
  6606. string type = lua_interface->GetStringValue(state, 4);
  6607. if (!spawn || (spawn && spawn->IsPlayer())) {
  6608. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6609. return 0;
  6610. }
  6611. if (!player || (player && !player->IsPlayer())) {
  6612. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6613. return 0;
  6614. }
  6615. Client* client = 0;
  6616. if (player->GetZone())
  6617. client = player->GetZone()->GetClientBySpawn(player);
  6618. if (!client) {
  6619. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6620. return 0;
  6621. }
  6622. //Set max_distance to default if not set or not proper value
  6623. if (max_distance <= 0)
  6624. max_distance = 500;
  6625. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6626. if (packet) {
  6627. float unknown2_3 = 0;
  6628. int8 placement_mode = 0;
  6629. if (type == "wall") {
  6630. placement_mode = 2;
  6631. unknown2_3 = 150;
  6632. }
  6633. else if (type == "ceiling")
  6634. placement_mode = 1;
  6635. packet->setDataByName("placement_mode", placement_mode);
  6636. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6637. packet->setDataByName("model_type", spawn->GetModelType());
  6638. packet->setDataByName("unknown", 1); //size
  6639. packet->setDataByName("unknown2", 1); //size 2
  6640. packet->setDataByName("unknown2", .5, 1); //size 3
  6641. packet->setDataByName("unknown2", 3, 2);
  6642. packet->setDataByName("unknown2", unknown2_3, 3);
  6643. packet->setDataByName("max_distance", max_distance);
  6644. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6645. client->QueuePacket(packet->serialize());
  6646. safe_delete(packet);
  6647. }
  6648. return 0;
  6649. }
  6650. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6651. if (!lua_interface)
  6652. return 0;
  6653. Item* item = lua_interface->GetItem(state);
  6654. if (!item) {
  6655. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6656. return 0;
  6657. }
  6658. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6659. return 1;
  6660. }
  6661. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6662. if (!lua_interface)
  6663. return 0;
  6664. Spawn* spawn = lua_interface->GetSpawn(state);
  6665. if (!spawn) {
  6666. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6667. return 0;
  6668. }
  6669. if (spawn->GetZone())
  6670. spawn->GetZone()->AddTransportSpawn(spawn);
  6671. return 0;
  6672. }
  6673. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6674. if (!lua_interface)
  6675. return 0;
  6676. Skill* skill = lua_interface->GetSkill(state);
  6677. if (!skill) {
  6678. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6679. return 0;
  6680. }
  6681. lua_interface->SetInt32Value(state, skill->current_val);
  6682. return 1;
  6683. }
  6684. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6685. if (!lua_interface)
  6686. return 0;
  6687. Skill* skill = lua_interface->GetSkill(state);
  6688. if (!skill) {
  6689. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6690. return 0;
  6691. }
  6692. lua_interface->SetInt32Value(state, skill->max_val);
  6693. return 1;
  6694. }
  6695. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6696. if (!lua_interface)
  6697. return 0;
  6698. Skill* skill = lua_interface->GetSkill(state);
  6699. if (!skill) {
  6700. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6701. return 0;
  6702. }
  6703. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6704. return 1;
  6705. }
  6706. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6707. if (!lua_interface)
  6708. return 0;
  6709. Skill* skill = lua_interface->GetSkill(state);
  6710. int16 value = lua_interface->GetInt16Value(state, 2);
  6711. if (!skill) {
  6712. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6713. return 0;
  6714. }
  6715. skill->max_val = value;
  6716. if (skill->max_val < skill->current_val)
  6717. skill->current_val = skill->max_val;
  6718. return 0;
  6719. }
  6720. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6721. if (!lua_interface)
  6722. return 0;
  6723. Skill* skill = lua_interface->GetSkill(state);
  6724. int16 value = lua_interface->GetInt16Value(state, 2);
  6725. if (!skill) {
  6726. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6727. return 0;
  6728. }
  6729. if (value > skill->max_val)
  6730. skill->current_val = skill->max_val;
  6731. else
  6732. skill->current_val = value;
  6733. return 0;
  6734. }
  6735. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6736. if (!lua_interface)
  6737. return 0;
  6738. Spawn* player = lua_interface->GetSpawn(state);
  6739. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6740. if (skill_id > 0 && player && player->IsPlayer()) {
  6741. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6742. return 1;
  6743. }
  6744. return 0;
  6745. }
  6746. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6747. if (!lua_interface)
  6748. return 0;
  6749. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6750. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6751. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6752. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6753. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6754. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6755. if (player_spawn && player_spawn->IsPlayer()) {
  6756. Player* player = (Player*)player_spawn;
  6757. bool added = false;
  6758. if (!player->skill_list.HasSkill(skill_id)) {
  6759. player->AddSkill(skill_id, current_val, max_val, true);
  6760. added = true;
  6761. }
  6762. 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
  6763. Client* client = player->GetClient();
  6764. if (client) {
  6765. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6766. if (packet)
  6767. client->QueuePacket(packet);
  6768. }
  6769. }
  6770. if (added) {
  6771. lua_interface->SetBooleanValue(state, true);
  6772. return 1;
  6773. }
  6774. }
  6775. else {
  6776. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6777. }
  6778. }
  6779. else {
  6780. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6781. }
  6782. lua_interface->SetBooleanValue(state, false);
  6783. return 1;
  6784. }
  6785. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6786. if (!lua_interface)
  6787. return 0;
  6788. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6789. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6790. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6791. if (skill_id > 0) {
  6792. if (player_spawn && player_spawn->IsPlayer()) {
  6793. Player* player = (Player*)player_spawn;
  6794. if (player->skill_list.HasSkill(skill_id)) {
  6795. player->RemovePlayerSkill(skill_id);
  6796. if (!more_to_remove) {
  6797. Client* client = player->GetClient();
  6798. if (client) {
  6799. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6800. if (packet)
  6801. client->QueuePacket(packet);
  6802. }
  6803. }
  6804. }
  6805. }
  6806. else {
  6807. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6808. }
  6809. }
  6810. else {
  6811. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6812. }
  6813. return 0;
  6814. }
  6815. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6816. if (!lua_interface)
  6817. return 0;
  6818. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6819. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6820. int16 amount = lua_interface->GetInt8Value(state, 3);
  6821. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6822. if (amount > 0 && skill_type < 100) {
  6823. if (player_spawn && player_spawn->IsPlayer()) {
  6824. Player* player = (Player*)player_spawn;
  6825. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6826. if (!more_to_increase) {
  6827. Client* client = player->GetClient();
  6828. if (client) {
  6829. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6830. if (packet)
  6831. client->QueuePacket(packet);
  6832. }
  6833. }
  6834. }
  6835. else {
  6836. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6837. }
  6838. }
  6839. else {
  6840. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6841. }
  6842. return 0;
  6843. }
  6844. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6845. if (!lua_interface)
  6846. return 0;
  6847. Spawn* spawn = lua_interface->GetSpawn(state);
  6848. string name = lua_interface->GetStringValue(state, 2);
  6849. if (!spawn) {
  6850. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6851. return 0;
  6852. }
  6853. if (!spawn->IsEntity()) {
  6854. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6855. return 0;
  6856. }
  6857. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6858. if (skill) {
  6859. lua_interface->SetSkillValue(state, skill);
  6860. return 1;
  6861. }
  6862. return 0;
  6863. }
  6864. int EQ2Emu_lua_AddProc(lua_State* state) {
  6865. if (!lua_interface)
  6866. return 0;
  6867. Spawn* spawn = lua_interface->GetSpawn(state);
  6868. int8 type = lua_interface->GetInt8Value(state, 2);
  6869. float chance = lua_interface->GetFloatValue(state, 3);
  6870. Item* item = lua_interface->GetItem(state, 4);
  6871. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6872. LuaSpell* spell = 0;
  6873. if (!spawn && (!spell || !use_all_spelltargets)) {
  6874. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6875. return 0;
  6876. }
  6877. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6878. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6879. return 0;
  6880. }
  6881. if (!item)
  6882. spell = lua_interface->GetCurrentSpell(state);
  6883. if (!item && !spell) {
  6884. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6885. return 0;
  6886. }
  6887. if (spell && use_all_spelltargets) {
  6888. Spawn* target;
  6889. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6890. for (int8 i = 0; i < spell->targets.size(); i++) {
  6891. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6892. if (!target || !target->IsEntity())
  6893. continue;
  6894. ((Entity*)target)->AddProc(type, chance, item, spell);
  6895. }
  6896. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6897. }
  6898. else
  6899. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6900. return 0;
  6901. }
  6902. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6903. if (!lua_interface)
  6904. return 0;
  6905. Spawn* spawn = lua_interface->GetSpawn(state);
  6906. Item* item = lua_interface->GetItem(state, 2);
  6907. LuaSpell* spell = 0;
  6908. if (!spawn) {
  6909. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6910. return 0;
  6911. }
  6912. if (!spawn->IsEntity()) {
  6913. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6914. return 0;
  6915. }
  6916. if (!item)
  6917. spell = lua_interface->GetCurrentSpell(state);
  6918. if (!item && !spell) {
  6919. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6920. return 0;
  6921. }
  6922. if (spell) {
  6923. Spawn* target;
  6924. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6925. for (int8 i = 0; i < spell->targets.size(); i++) {
  6926. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6927. if (!target || !target->IsEntity())
  6928. continue;
  6929. ((Entity*)target)->RemoveProc(item, spell);
  6930. }
  6931. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6932. spell->caster->RemoveProc(item, spell);
  6933. }
  6934. else
  6935. ((Entity*)spawn)->RemoveProc(item, spell);
  6936. return 0;
  6937. }
  6938. int EQ2Emu_lua_Knockback(lua_State* state) {
  6939. if (!lua_interface)
  6940. return 0;
  6941. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6942. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6943. int32 duration = lua_interface->GetInt32Value(state, 3);
  6944. float vertical = lua_interface->GetFloatValue(state, 4);
  6945. float horizontal = lua_interface->GetFloatValue(state, 5);
  6946. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6947. if (!target_spawn) {
  6948. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6949. return 0;
  6950. }
  6951. if (!spawn) {
  6952. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6953. return 0;
  6954. }
  6955. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6956. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6957. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6958. if (packet) {
  6959. packet->setDataByName("target_x", target_spawn->GetX());
  6960. packet->setDataByName("target_y", target_spawn->GetY());
  6961. packet->setDataByName("target_z", target_spawn->GetZ());
  6962. packet->setDataByName("vertical_movement", vertical);
  6963. packet->setDataByName("horizontal_movement", horizontal);
  6964. if (use_heading)
  6965. packet->setDataByName("use_player_heading", 1);
  6966. client->QueuePacket(packet->serialize());
  6967. }
  6968. safe_delete(packet);
  6969. }
  6970. return 0;
  6971. }
  6972. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6973. if (!lua_interface)
  6974. return 0;
  6975. Spawn* spawn = lua_interface->GetSpawn(state);
  6976. if (!spawn) {
  6977. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6978. return 0;
  6979. }
  6980. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6981. return 1;
  6982. }
  6983. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6984. if (!lua_interface)
  6985. return 0;
  6986. Spawn* caster = lua_interface->GetSpawn(state);
  6987. Spawn* target = lua_interface->GetSpawn(state, 2);
  6988. string name = lua_interface->GetStringValue(state, 3);
  6989. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6990. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6991. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6992. string success_msg = lua_interface->GetStringValue(state, 7);
  6993. string effect_msg = lua_interface->GetStringValue(state, 8);
  6994. if (!caster) {
  6995. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6996. return 0;
  6997. }
  6998. if (!caster->IsEntity()) {
  6999. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7000. return 0;
  7001. }
  7002. if (!target) {
  7003. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7004. return 0;
  7005. }
  7006. if (!target->IsEntity()) {
  7007. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7008. return 0;
  7009. }
  7010. if (name.length() == 0) {
  7011. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7012. return 0;
  7013. }
  7014. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7015. return 0;
  7016. }
  7017. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7018. if (!lua_interface)
  7019. return 0;
  7020. string name = lua_interface->GetStringValue(state);
  7021. if (name.length() == 0) {
  7022. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7023. return 0;
  7024. }
  7025. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7026. if (!skill) {
  7027. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7028. return 0;
  7029. }
  7030. lua_interface->SetInt32Value(state, skill->skill_id);
  7031. return 1;
  7032. }
  7033. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7034. if (!lua_interface)
  7035. return 0;
  7036. Spawn* spawn = lua_interface->GetSpawn(state);
  7037. if (!spawn) {
  7038. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7039. return 0;
  7040. }
  7041. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7042. return 1;
  7043. }
  7044. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7045. if (!lua_interface)
  7046. return 0;
  7047. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7048. if (!luaspell) {
  7049. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7050. return 0;
  7051. }
  7052. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7053. return 1;
  7054. }
  7055. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7056. if (!lua_interface)
  7057. return 0;
  7058. Spawn* spawn = lua_interface->GetSpawn(state);
  7059. Spawn* target = lua_interface->GetSpawn(state, 2);
  7060. if (!spawn) {
  7061. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7062. return 0;
  7063. }
  7064. if (!spawn->IsEntity()) {
  7065. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7066. return 0;
  7067. }
  7068. if (!target) {
  7069. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7070. return 0;
  7071. }
  7072. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7073. return 1;
  7074. }
  7075. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7076. if (!lua_interface)
  7077. return 0;
  7078. Spawn* spawn = lua_interface->GetSpawn(state);
  7079. Spawn* target = lua_interface->GetSpawn(state, 2);
  7080. if (!spawn) {
  7081. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7082. return 0;
  7083. }
  7084. if (!spawn->IsEntity()) {
  7085. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7086. return 0;
  7087. }
  7088. if (!target) {
  7089. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7090. return 0;
  7091. }
  7092. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7093. return 1;
  7094. }
  7095. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7096. if (!lua_interface)
  7097. return 0;
  7098. Item* item = lua_interface->GetItem(state);
  7099. if (!item) {
  7100. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7101. return 0;
  7102. }
  7103. lua_interface->SetInt32Value(state, item->details.count);
  7104. return 1;
  7105. }
  7106. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7107. if (!lua_interface)
  7108. return 0;
  7109. Item* item = lua_interface->GetItem(state);
  7110. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7111. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7112. if (!item) {
  7113. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7114. return 0;
  7115. }
  7116. if (!owner) {
  7117. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7118. return 0;
  7119. }
  7120. if (!owner->IsPlayer()) {
  7121. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7122. return 0;
  7123. }
  7124. if (item->stack_count < new_count) {
  7125. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7126. return 0;
  7127. }
  7128. if (new_count > 0) {
  7129. item->details.count = new_count;
  7130. item->save_needed = true;
  7131. }
  7132. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7133. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7134. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7135. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7136. else
  7137. {
  7138. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7139. return 0;
  7140. }
  7141. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7142. if (!client)
  7143. return 0;
  7144. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7145. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  7146. if (app)
  7147. client->QueuePacket(app);
  7148. return 0;
  7149. }
  7150. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7151. if (!lua_interface)
  7152. return 0;
  7153. int32 time = lua_interface->GetInt32Value(state);
  7154. string function = lua_interface->GetStringValue(state, 2);
  7155. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7156. Spawn* target = lua_interface->GetSpawn(state, 4);
  7157. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7158. if (time == 0) {
  7159. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7160. return 0;
  7161. }
  7162. if (function.length() == 0) {
  7163. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7164. return 0;
  7165. }
  7166. if (!spell) {
  7167. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7168. return 0;
  7169. }
  7170. SpellScriptTimer* timer = new SpellScriptTimer;
  7171. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7172. #ifdef WIN32
  7173. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7174. #else
  7175. bzero(timer, sizeof(SpellScriptTimer));
  7176. #endif*/
  7177. timer->caster = 0;
  7178. timer->deleteWhenDone = false;
  7179. timer->target = 0;
  7180. timer->time = Timer::GetCurrentTime2() + time;
  7181. timer->customFunction = function;
  7182. timer->spell = spell;
  7183. if (caster)
  7184. timer->caster = caster->GetID();
  7185. if (target)
  7186. timer->target = target->GetID();
  7187. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7188. return 0;
  7189. }
  7190. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7191. if (!lua_interface)
  7192. return 0;
  7193. float hp_perc = lua_interface->GetFloatValue(state);
  7194. float power_perc = lua_interface->GetFloatValue(state, 2);
  7195. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7196. Spawn* target = lua_interface->GetSpawn(state, 4);
  7197. string heal_name = lua_interface->GetStringValue(state, 5);
  7198. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7199. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7200. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7201. if (!spell) {
  7202. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7203. return 0;
  7204. }
  7205. Entity* caster = spell->caster;
  7206. if (!caster) {
  7207. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7208. return 0;
  7209. }
  7210. Client* client = 0;
  7211. PendingResurrection* rez = 0;
  7212. ZoneServer* zone = spell->caster->GetZone();
  7213. if (!target) {
  7214. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7215. if (spell->targets.size() > 0) {
  7216. vector<int32> spell_targets = spell->targets;
  7217. for (int8 i = 0; i < spell_targets.size(); i++) {
  7218. target = zone->GetSpawnByID(spell_targets.at(i));
  7219. if (!target)
  7220. continue;
  7221. if (!target->IsPlayer())
  7222. continue;
  7223. client = target->GetZone()->GetClientBySpawn(target);
  7224. if (!client)
  7225. continue;
  7226. rez = client->GetCurrentRez();
  7227. if (rez->active)
  7228. continue;
  7229. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7230. rez->active = true;
  7231. rez->caster = caster;
  7232. rez->expire_timer = new Timer;
  7233. int32 duration = spell->spell->GetSpellDuration();
  7234. rez->expire_timer->Start(duration * 100);
  7235. rez->hp_perc = hp_perc;
  7236. rez->mp_perc = power_perc;
  7237. rez->range = spell->spell->GetSpellData()->range;
  7238. rez->spell_name = spell->spell->GetName();
  7239. if (heal_name.length() > 0)
  7240. rez->heal_name = heal_name;
  7241. else
  7242. rez->heal_name = rez->spell_name;
  7243. rez->no_calcs = no_calcs;
  7244. rez->crit_mod = crit_mod;
  7245. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7246. if (send_window)
  7247. client->SendResurrectionWindow();
  7248. else {
  7249. target->GetZone()->ResurrectSpawn(target, client);
  7250. rez->should_delete = true;
  7251. }
  7252. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7253. }
  7254. }
  7255. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7256. }
  7257. else {
  7258. client = target->GetZone()->GetClientBySpawn(target);
  7259. if (!client)
  7260. return 0;
  7261. rez = client->GetCurrentRez();
  7262. if (rez->active)
  7263. return 0;
  7264. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7265. rez->active = true;
  7266. rez->caster = caster;
  7267. rez->expire_timer = new Timer;
  7268. int32 duration = spell->spell->GetSpellDuration();
  7269. rez->expire_timer->Start(duration * 100);
  7270. rez->hp_perc = hp_perc;
  7271. rez->mp_perc = power_perc;
  7272. rez->range = spell->spell->GetSpellData()->range;
  7273. rez->spell_name = spell->spell->GetName();
  7274. if (heal_name.length() > 0)
  7275. rez->heal_name = heal_name;
  7276. else
  7277. rez->heal_name = rez->spell_name;
  7278. rez->no_calcs = no_calcs;
  7279. rez->crit_mod = crit_mod;
  7280. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7281. if (send_window)
  7282. client->SendResurrectionWindow();
  7283. else {
  7284. target->GetZone()->ResurrectSpawn(target, client);
  7285. rez->should_delete = true;
  7286. }
  7287. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7288. }
  7289. return 0;
  7290. }
  7291. int EQ2Emu_lua_SetVision(lua_State* state) {
  7292. if (!lua_interface)
  7293. return 0;
  7294. Spawn* spawn = lua_interface->GetSpawn(state);
  7295. int8 vision = lua_interface->GetInt8Value(state, 2);
  7296. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7297. if (!spawn) {
  7298. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7299. return 0;
  7300. }
  7301. if (!spawn->IsEntity()) {
  7302. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7303. return 0;
  7304. }
  7305. if (spell && spell->targets.size() > 0) {
  7306. ZoneServer* zone = spell->caster->GetZone();
  7307. for (int8 i = 0; i < spell->targets.size(); i++) {
  7308. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7309. if (target->IsEntity()) {
  7310. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7311. if (target->IsPlayer())
  7312. ((Player*)target)->SetCharSheetChanged(true);
  7313. }
  7314. }
  7315. }
  7316. else {
  7317. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7318. if (spawn->IsPlayer())
  7319. ((Player*)spawn)->SetCharSheetChanged(true);
  7320. }
  7321. return 0;
  7322. }
  7323. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7324. if (!lua_interface)
  7325. return 0;
  7326. Spawn* spawn = lua_interface->GetSpawn(state);
  7327. float intensity = lua_interface->GetFloatValue(state, 2);
  7328. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7329. if (!spawn) {
  7330. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7331. return 0;
  7332. }
  7333. if (!spawn->IsEntity()) {
  7334. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7335. return 0;
  7336. }
  7337. if (spell && spell->targets.size() > 0) {
  7338. ZoneServer* zone = spell->caster->GetZone();
  7339. for (int8 i = 0; i < spell->targets.size(); i++) {
  7340. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7341. if (target && target->IsEntity()) {
  7342. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7343. if (target->IsPlayer())
  7344. ((Player*)target)->SetCharSheetChanged(true);
  7345. }
  7346. }
  7347. }
  7348. else {
  7349. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7350. if (spawn->IsPlayer())
  7351. ((Player*)spawn)->SetCharSheetChanged(true);
  7352. }
  7353. return 0;
  7354. }
  7355. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7356. if (!lua_interface)
  7357. return 0;
  7358. Spawn* spawn = lua_interface->GetSpawn(state);
  7359. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7360. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7361. if (!spawn) {
  7362. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7363. return 0;
  7364. }
  7365. if (!spawn->IsEntity()) {
  7366. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7367. return 0;
  7368. }
  7369. if (spell && spell->targets.size() > 0) {
  7370. ZoneServer* zone = spell->caster->GetZone();
  7371. for (int8 i = 0; i < spell->targets.size(); i++) {
  7372. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7373. if (target->IsEntity()) {
  7374. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7375. if (target->IsPlayer())
  7376. ((Player*)target)->SetCharSheetChanged(true);
  7377. }
  7378. }
  7379. }
  7380. else {
  7381. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7382. if (spawn->IsPlayer())
  7383. ((Player*)spawn)->SetCharSheetChanged(true);
  7384. }
  7385. return 0;
  7386. }
  7387. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7388. if (!lua_interface)
  7389. return 0;
  7390. Item* item = lua_interface->GetItem(state);
  7391. int8 type = lua_interface->GetInt32Value(state, 2);
  7392. if (!item) {
  7393. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7394. return 0;
  7395. }
  7396. if (type == 1)
  7397. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7398. else if (type == 2)
  7399. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7400. return 1;
  7401. }
  7402. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7403. if (!lua_interface)
  7404. return 0;
  7405. Spawn* target = lua_interface->GetSpawn(state);
  7406. float val = lua_interface->GetFloatValue(state, 2);
  7407. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7408. // Added from Gangrenous post
  7409. if (spell && spell->resisted)
  7410. return 0;
  7411. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7412. if (val > 1.0f)
  7413. val = 1.0f - (val / 100.0f);
  7414. if (spell && spell->spell && spell->targets.size() > 0) {
  7415. ZoneServer* zone = spell->caster->GetZone();
  7416. for (int32 i = 0; i != spell->targets.size(); i++) {
  7417. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7418. if (spawn && spawn->IsEntity()) {
  7419. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7420. if (spawn->IsPlayer())
  7421. ((Player*)spawn)->SetCharSheetChanged(true);
  7422. }
  7423. }
  7424. }
  7425. else {
  7426. if (target && target->IsEntity()) {
  7427. ((Entity*)target)->SetSpeedMultiplier(val);
  7428. if (target->IsPlayer())
  7429. ((Player*)target)->SetCharSheetChanged(true);
  7430. }
  7431. }
  7432. return 0;
  7433. }
  7434. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7435. if (!lua_interface)
  7436. return 0;
  7437. Spawn* spawn = lua_interface->GetSpawn(state);
  7438. int16 model = lua_interface->GetInt16Value(state, 2);
  7439. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7440. if (spell && spell->spell && spell->targets.size() > 0) {
  7441. ZoneServer* zone = spell->caster->GetZone();
  7442. for (int32 i = 0; i < spell->targets.size(); i++) {
  7443. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7444. if (target)
  7445. target->SetIllusionModel(model);
  7446. }
  7447. }
  7448. else {
  7449. if (!spawn) {
  7450. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7451. return 0;
  7452. }
  7453. spawn->SetIllusionModel(model);
  7454. }
  7455. return 0;
  7456. }
  7457. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7458. if (!lua_interface)
  7459. return 0;
  7460. Spawn* spawn = lua_interface->GetSpawn(state);
  7461. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7462. if (spell && spell->spell && spell->targets.size() > 0) {
  7463. ZoneServer* zone = spell->caster->GetZone();
  7464. for (int32 i = 0; i < spell->targets.size(); i++) {
  7465. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7466. if (target)
  7467. target->SetIllusionModel(0);
  7468. }
  7469. }
  7470. else {
  7471. if (!spawn) {
  7472. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7473. return 0;
  7474. }
  7475. spawn->SetIllusionModel(0);
  7476. }
  7477. return 0;
  7478. }
  7479. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7480. if (!lua_interface)
  7481. return 0;
  7482. Spawn* caster = lua_interface->GetSpawn(state);
  7483. Spawn* target = lua_interface->GetSpawn(state, 2);
  7484. float chance = lua_interface->GetFloatValue(state, 3);
  7485. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7486. if (!caster) {
  7487. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7488. return 0;
  7489. }
  7490. if (!caster->IsEntity()) {
  7491. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7492. return 0;
  7493. }
  7494. if (!target) {
  7495. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7496. return 0;
  7497. }
  7498. if (!target->IsEntity()) {
  7499. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7500. return 0;
  7501. }
  7502. if (chance <= 0) {
  7503. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7504. return 0;
  7505. }
  7506. if (!spell) {
  7507. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7508. return 0;
  7509. }
  7510. if (((Entity*)caster)->GetThreatTransfer()) {
  7511. return 0;
  7512. }
  7513. ThreatTransfer* transfer = new ThreatTransfer;
  7514. transfer->Target = target->GetID();
  7515. transfer->Amount = chance;
  7516. transfer->Spell = spell;
  7517. ((Entity*)caster)->SetThreatTransfer(transfer);
  7518. return 0;
  7519. }
  7520. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7521. if (!lua_interface)
  7522. return 0;
  7523. Spawn* spawn = lua_interface->GetSpawn(state);
  7524. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7525. if (!spawn) {
  7526. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7527. return 0;
  7528. }
  7529. if (!spell) {
  7530. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7531. return 0;
  7532. }
  7533. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7534. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7535. ((Entity*)spawn)->SetThreatTransfer(0);
  7536. safe_delete(transfer);
  7537. }
  7538. return 0;
  7539. }
  7540. int EQ2Emu_lua_CureByType(lua_State* state) {
  7541. if (!lua_interface)
  7542. return 0;
  7543. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7544. if (!spell) {
  7545. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7546. return 0;
  7547. }
  7548. int8 cure_count = lua_interface->GetInt8Value(state);
  7549. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7550. string cure_name = lua_interface->GetStringValue(state, 3);
  7551. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7552. Spawn* target = lua_interface->GetSpawn(state, 5);
  7553. if (target) {
  7554. if (!target->IsEntity()) {
  7555. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7556. return 0;
  7557. }
  7558. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7559. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7560. }
  7561. else {
  7562. ZoneServer* zone = spell->caster->GetZone();
  7563. vector<int32> targets = spell->targets;
  7564. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7565. for (int8 i = 0; i < targets.size(); i++) {
  7566. target = zone->GetSpawnByID(targets.at(i));
  7567. if (!target || !target->IsEntity())
  7568. continue;
  7569. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7570. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7571. }
  7572. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7573. }
  7574. return 0;
  7575. }
  7576. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7577. if (!lua_interface)
  7578. return 0;
  7579. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7580. if (!spell) {
  7581. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7582. return 0;
  7583. }
  7584. int8 cure_count = lua_interface->GetInt8Value(state);
  7585. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7586. string cure_name = lua_interface->GetStringValue(state, 3);
  7587. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7588. Spawn* target = lua_interface->GetSpawn(state, 5);
  7589. if (target) {
  7590. if (!target->IsEntity()) {
  7591. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7592. return 0;
  7593. }
  7594. if (((Entity*)target)->GetDetCount() > 0)
  7595. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7596. }
  7597. else {
  7598. ZoneServer* zone = spell->caster->GetZone();
  7599. vector<int32> targets = spell->targets;
  7600. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7601. for (int8 i = 0; i < targets.size(); i++) {
  7602. target = zone->GetSpawnByID(targets.at(i));
  7603. if (!target || !target->IsEntity())
  7604. continue;
  7605. if (((Entity*)target)->GetDetCount() > 0)
  7606. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7607. }
  7608. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7609. }
  7610. return 0;
  7611. }
  7612. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7613. if (!lua_interface)
  7614. return 0;
  7615. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7616. if (!spell) {
  7617. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7618. return 0;
  7619. }
  7620. if (!spell->caster) {
  7621. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7622. return 0;
  7623. }
  7624. if (!spell->caster->GetZone()) {
  7625. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7626. return 0;
  7627. }
  7628. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7629. return 0;
  7630. }
  7631. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7632. if (!lua_interface)
  7633. return 0;
  7634. Spawn* spawn = lua_interface->GetSpawn(state);
  7635. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7636. if (!spell) {
  7637. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7638. return 0;
  7639. }
  7640. if (spawn && spawn->IsEntity())
  7641. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7642. else {
  7643. ZoneServer* zone = spell->caster->GetZone();
  7644. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7645. for (int32 i = 0; i < spell->targets.size(); i++) {
  7646. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7647. if (!spawn || !spawn->IsEntity())
  7648. continue;
  7649. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7650. }
  7651. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7652. }
  7653. return 0;
  7654. }
  7655. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7656. if (!lua_interface)
  7657. return 0;
  7658. Spawn* spawn = lua_interface->GetSpawn(state);
  7659. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7660. if (!spell) {
  7661. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7662. return 0;
  7663. }
  7664. if (spawn && spawn->IsEntity())
  7665. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7666. else {
  7667. ZoneServer* zone = spell->caster->GetZone();
  7668. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7669. for (int32 i = 0; i < spell->targets.size(); i++) {
  7670. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7671. if (!spawn || !spawn->IsEntity())
  7672. continue;
  7673. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7674. }
  7675. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7676. }
  7677. return 0;
  7678. }
  7679. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7680. if (!lua_interface)
  7681. return 0;
  7682. Spawn* caster = lua_interface->GetSpawn(state);
  7683. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7684. if (!caster) {
  7685. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7686. return 0;
  7687. }
  7688. if (!caster->IsPlayer()) {
  7689. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7690. return 0;
  7691. }
  7692. Spawn* target = caster->GetTarget();
  7693. if (!target) {
  7694. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7695. return 0;
  7696. }
  7697. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7698. if (!client) {
  7699. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7700. return 0;
  7701. }
  7702. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7703. if (ho) {
  7704. ho->SetTarget(target->GetID());
  7705. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7706. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7707. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7708. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7709. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7710. deque<GroupMemberInfo*>::iterator itr;
  7711. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7712. if (group)
  7713. {
  7714. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7715. deque<GroupMemberInfo*>* members = group->GetMembers();
  7716. for (itr = members->begin(); itr != members->end(); itr++) {
  7717. if ((*itr)->client)
  7718. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7719. }
  7720. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7721. }
  7722. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7723. }
  7724. else
  7725. safe_delete(ho);
  7726. }
  7727. else {
  7728. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7729. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7730. }
  7731. else
  7732. safe_delete(ho);
  7733. }
  7734. }
  7735. return 0;
  7736. }
  7737. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7738. if (!lua_interface)
  7739. return 0;
  7740. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7741. if (!spell) {
  7742. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7743. return 0;
  7744. }
  7745. int16 triggerCount = lua_interface->GetInt16Value(state);
  7746. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7747. if (!triggerCount) {
  7748. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7749. return 0;
  7750. }
  7751. spell->num_triggers = triggerCount;
  7752. spell->had_triggers = true;
  7753. spell->cancel_after_all_triggers = cancel_after_triggers;
  7754. return 0;
  7755. }
  7756. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7757. if (!lua_interface)
  7758. return 0;
  7759. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7760. if (!spell) {
  7761. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7762. return 0;
  7763. }
  7764. lua_interface->SetInt32Value(state, spell->num_triggers);
  7765. return 1;
  7766. }
  7767. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7768. if (!lua_interface)
  7769. return 0;
  7770. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7771. if (!spell) {
  7772. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7773. return 0;
  7774. }
  7775. int16 remove_count = lua_interface->GetInt16Value(state);
  7776. if (!remove_count)
  7777. remove_count = 1;
  7778. if (remove_count >= spell->num_triggers) {
  7779. spell->num_triggers = 0;
  7780. if (spell->cancel_after_all_triggers)
  7781. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7782. }
  7783. else {
  7784. spell->num_triggers -= remove_count;
  7785. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7786. }
  7787. return 0;
  7788. }
  7789. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7790. if (!lua_interface)
  7791. return 0;
  7792. Spawn* spawn = lua_interface->GetSpawn(state);
  7793. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7794. if (!spawn) {
  7795. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7796. return 0;
  7797. }
  7798. if (!copy_spawn) {
  7799. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7800. return 0;
  7801. }
  7802. spawn->CopySpawnAppearance(copy_spawn);
  7803. return 0;
  7804. }
  7805. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7806. Spawn* spawn = lua_interface->GetSpawn(state);
  7807. int8 type = lua_interface->GetInt8Value(state, 2);
  7808. if (!spawn) {
  7809. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7810. return 0;
  7811. }
  7812. else if (!spawn->IsEntity()) {
  7813. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7814. return 0;
  7815. }
  7816. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7817. return 1;
  7818. }
  7819. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7820. if (!lua_interface)
  7821. return 0;
  7822. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7823. int8 type = lua_interface->GetInt8Value(state);
  7824. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7825. if (!spell) {
  7826. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7827. return 0;
  7828. }
  7829. if (spawn) {
  7830. if (!spawn->IsEntity()) {
  7831. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7832. return 0;
  7833. }
  7834. Entity* entity = ((Entity*)spawn);
  7835. entity->AddImmunity(spell, type);
  7836. }
  7837. else {
  7838. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7839. for (int8 i = 0; i < spell->targets.size(); i++) {
  7840. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7841. if (!spawn || !spawn->IsEntity())
  7842. continue;
  7843. Entity* entity = ((Entity*)spawn);
  7844. entity->AddImmunity(spell, type);
  7845. }
  7846. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7847. }
  7848. return 0;
  7849. }
  7850. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7851. if (!lua_interface)
  7852. return 0;
  7853. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7854. int8 type = lua_interface->GetInt8Value(state);
  7855. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7856. if (!spell) {
  7857. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7858. return 0;
  7859. }
  7860. if (spawn) {
  7861. if (!spawn->IsEntity()) {
  7862. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7863. return 0;
  7864. }
  7865. Entity* entity = ((Entity*)spawn);
  7866. entity->RemoveImmunity(spell, type);
  7867. }
  7868. else {
  7869. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7870. for (int8 i = 0; i < spell->targets.size(); i++) {
  7871. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7872. if (!spawn || !spawn->IsEntity())
  7873. continue;
  7874. Entity* entity = ((Entity*)spawn);
  7875. entity->RemoveImmunity(spell, type);
  7876. }
  7877. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7878. }
  7879. return 0;
  7880. }
  7881. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7882. if (!lua_interface)
  7883. return 0;
  7884. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7885. if (!spell) {
  7886. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7887. return 0;
  7888. }
  7889. float snare = lua_interface->GetFloatValue(state);
  7890. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7891. // convert the val to the speed multipler value (100 - val)
  7892. float val = 100.0 - snare;
  7893. val /= 100.0;
  7894. if (spawn) {
  7895. if (!spawn->IsEntity()) {
  7896. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7897. return 0;
  7898. }
  7899. ((Entity*)spawn)->SetSnareValue(spell, val);
  7900. }
  7901. else {
  7902. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7903. for (int8 i = 0; i < spell->targets.size(); i++) {
  7904. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7905. if (!spawn || !spawn->IsEntity())
  7906. continue;
  7907. ((Entity*)spawn)->SetSnareValue(spell, val);
  7908. }
  7909. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7910. }
  7911. return 0;
  7912. }
  7913. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7914. if (!lua_interface)
  7915. return 0;
  7916. Spawn* spawn = lua_interface->GetSpawn(state);
  7917. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7918. if (!spawn) {
  7919. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7920. return 0;
  7921. }
  7922. if (race_id == 0) {
  7923. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7924. return 0;
  7925. }
  7926. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7927. return 1;
  7928. }
  7929. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7930. if (!lua_interface)
  7931. return 0;
  7932. Spawn* spawn = lua_interface->GetSpawn(state);
  7933. if (!spawn) {
  7934. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7935. return 0;
  7936. }
  7937. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7938. return 1;
  7939. }
  7940. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7941. if (!lua_interface)
  7942. return 0;
  7943. Spawn* spawn = lua_interface->GetSpawn(state);
  7944. if (!spawn) {
  7945. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7946. return 0;
  7947. }
  7948. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7949. return 1;
  7950. }
  7951. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7952. if (!lua_interface)
  7953. return 0;
  7954. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7955. if (!spell) {
  7956. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7957. return 0;
  7958. }
  7959. lua_interface->SetStringValue(state, spell->spell->GetName());
  7960. return 1;
  7961. }
  7962. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7963. if (!lua_interface)
  7964. return 0;
  7965. Quest* quest = lua_interface->GetQuest(state);
  7966. if (!quest) {
  7967. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7968. return 0;
  7969. }
  7970. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7971. return 1;
  7972. }
  7973. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7974. if (!lua_interface)
  7975. return 0;
  7976. Quest* quest = lua_interface->GetQuest(state);
  7977. int32 flags = lua_interface->GetInt32Value(state, 2);
  7978. if (!quest) {
  7979. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7980. return 0;
  7981. }
  7982. quest->SetQuestFlags(flags);
  7983. return 0;
  7984. }
  7985. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7986. if (!lua_interface)
  7987. return 0;
  7988. Quest* quest = lua_interface->GetQuest(state);
  7989. Spawn* player = lua_interface->GetSpawn(state, 2);
  7990. int32 step = lua_interface->GetInt32Value(state, 3);
  7991. int32 duration = lua_interface->GetInt32Value(state, 4);
  7992. string action = lua_interface->GetStringValue(state, 5);
  7993. if (!quest) {
  7994. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7995. return 0;
  7996. }
  7997. if (!player) {
  7998. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7999. return 0;
  8000. }
  8001. if (!player->IsPlayer()) {
  8002. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8003. return 0;
  8004. }
  8005. if (step == 0) {
  8006. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8007. return 0;
  8008. }
  8009. if (duration == 0) {
  8010. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8011. return 0;
  8012. }
  8013. if (action.length() == 0) {
  8014. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8015. return 0;
  8016. }
  8017. Client* client = player->GetZone()->GetClientBySpawn(player);
  8018. if (!client) {
  8019. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8020. return 0;
  8021. }
  8022. quest->SetTimerStep(step);
  8023. quest->AddFailedAction(step, action);
  8024. quest->SetStepTimer(duration);
  8025. client->AddQuestTimer(quest->GetQuestID());
  8026. return 0;
  8027. }
  8028. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8029. if (!lua_interface)
  8030. return 0;
  8031. Quest* quest = lua_interface->GetQuest(state);
  8032. Spawn* player = lua_interface->GetSpawn(state, 2);
  8033. if (!quest) {
  8034. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8035. return 0;
  8036. }
  8037. if (!player) {
  8038. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8039. return 0;
  8040. }
  8041. if (!player->IsPlayer()) {
  8042. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8043. return 0;
  8044. }
  8045. Client* client = player->GetZone()->GetClientBySpawn(player);
  8046. if (!client) {
  8047. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8048. return 0;
  8049. }
  8050. quest->SetTimerStep(0);
  8051. quest->SetStepTimer(0);
  8052. client->RemoveQuestTimer(quest->GetQuestID());
  8053. return 0;
  8054. }
  8055. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8056. if (!lua_interface)
  8057. return 0;
  8058. Spawn* player = lua_interface->GetSpawn(state);
  8059. Quest* quest = lua_interface->GetQuest(state, 2);
  8060. int32 step = lua_interface->GetInt32Value(state, 3);
  8061. if (!player) {
  8062. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8063. return 0;
  8064. }
  8065. if (!player->IsPlayer()) {
  8066. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8067. return 0;
  8068. }
  8069. if (!quest) {
  8070. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8071. return 0;
  8072. }
  8073. if (step == 0) {
  8074. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8075. return 0;
  8076. }
  8077. Client* client = player->GetZone()->GetClientBySpawn(player);
  8078. if (!client) {
  8079. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8080. return 0;
  8081. }
  8082. if (quest->RemoveQuestStep(step, client)) {
  8083. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8084. client->GetCurrentZone()->SendQuestUpdates(client);
  8085. }
  8086. else
  8087. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8088. return 0;
  8089. }
  8090. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8091. if (!lua_interface)
  8092. return 0;
  8093. Quest* quest = lua_interface->GetQuest(state, 1);
  8094. int32 step = lua_interface->GetInt32Value(state, 2);
  8095. string desc = lua_interface->GetStringValue(state, 3);
  8096. string task_group = lua_interface->GetStringValue(state, 4);
  8097. if (!quest) {
  8098. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8099. return 0;
  8100. }
  8101. if (step == 0) {
  8102. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8103. return 0;
  8104. }
  8105. QuestStep* quest_step = quest->GetQuestStep(step);
  8106. if (!quest_step) {
  8107. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8108. return 0;
  8109. }
  8110. quest_step->SetStepProgress(0);
  8111. quest_step->SetTaskGroup(task_group);
  8112. quest_step->SetDescription(desc);
  8113. return 0;
  8114. }
  8115. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8116. if (!lua_interface)
  8117. return 0;
  8118. Quest* quest = lua_interface->GetQuest(state);
  8119. int32 step = lua_interface->GetInt32Value(state, 2);
  8120. string action = lua_interface->GetStringValue(state, 3);
  8121. if (!quest) {
  8122. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8123. return 0;
  8124. }
  8125. if (step == 0) {
  8126. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8127. return 0;
  8128. }
  8129. if (action.length() == 0) {
  8130. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8131. return 0;
  8132. }
  8133. quest->AddFailedAction(step, action);
  8134. return 0;
  8135. }
  8136. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8137. if (!lua_interface)
  8138. return 0;
  8139. Spawn* player = lua_interface->GetSpawn(state);
  8140. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8141. int32 step = lua_interface->GetInt32Value(state, 3);
  8142. if (!player) {
  8143. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8144. return 0;
  8145. }
  8146. if (!player->IsPlayer()) {
  8147. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8148. return 0;
  8149. }
  8150. if (quest_id == 0) {
  8151. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8152. return 0;
  8153. }
  8154. if (step == 0) {
  8155. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8156. return 0;
  8157. }
  8158. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8159. if (!quest) {
  8160. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8161. return 0;
  8162. }
  8163. quest->StepFailed(step);
  8164. return 0;
  8165. }
  8166. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8167. if (!lua_interface)
  8168. return 0;
  8169. Spawn* player = lua_interface->GetSpawn(state);
  8170. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8171. if (!player) {
  8172. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8173. return 0;
  8174. }
  8175. if (!player->IsPlayer()) {
  8176. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8177. return 0;
  8178. }
  8179. if (quest_id == 0) {
  8180. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8181. return 0;
  8182. }
  8183. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8184. if (!quest) {
  8185. lua_interface->SetInt32Value(state, 0);
  8186. return 1;
  8187. }
  8188. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8189. return 1;
  8190. }
  8191. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8192. if (!lua_interface)
  8193. return 0;
  8194. string name = lua_interface->GetStringValue(state);
  8195. string value = lua_interface->GetStringValue(state, 2);
  8196. string comment = lua_interface->GetStringValue(state, 3);
  8197. if (name.length() == 0) {
  8198. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8199. return 0;
  8200. }
  8201. if (value.length() == 0) {
  8202. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8203. return 0;
  8204. }
  8205. string varname = string("lua_").append(name);
  8206. Variable* var = variables.FindVariable(varname);
  8207. if (var)
  8208. var->SetValue(value.c_str());
  8209. else {
  8210. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8211. variables.AddVariable(var);
  8212. }
  8213. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8214. return 0;
  8215. }
  8216. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8217. if (!lua_interface)
  8218. return 0;
  8219. string name = lua_interface->GetStringValue(state);
  8220. if (name.length() == 0) {
  8221. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8222. return 0;
  8223. }
  8224. string varname = string("lua_").append(name);
  8225. Variable* var = variables.FindVariable(varname);
  8226. if (var)
  8227. lua_interface->SetStringValue(state, var->GetValue());
  8228. else
  8229. lua_interface->SetStringValue(state, "NULL");
  8230. return 1;
  8231. }
  8232. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8233. if (!lua_interface)
  8234. return 0;
  8235. Spawn* player = lua_interface->GetSpawn(state);
  8236. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8237. if (!player) {
  8238. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8239. return 0;
  8240. }
  8241. if (!player->IsPlayer()) {
  8242. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8243. return 0;
  8244. }
  8245. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8246. return 1;
  8247. }
  8248. int EQ2Emu_lua_AddLanguage(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 AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8255. return 0;
  8256. }
  8257. if (!player->IsPlayer()) {
  8258. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8259. return 0;
  8260. }
  8261. Language* language = master_languages_list.GetLanguage(language_id);
  8262. if (language)
  8263. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8264. return 0;
  8265. }
  8266. int EQ2Emu_lua_IsNight(lua_State* state) {
  8267. if (!lua_interface)
  8268. return 0;
  8269. ZoneServer* zone = lua_interface->GetZone(state);
  8270. if (!zone) {
  8271. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8272. return 0;
  8273. }
  8274. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8275. return 1;
  8276. }
  8277. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8278. if (!lua_interface)
  8279. return 0;
  8280. Spawn* spawn = lua_interface->GetSpawn(state);
  8281. if (!spawn) {
  8282. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8283. return 0;
  8284. }
  8285. if (!spawn->IsWidget()) {
  8286. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8287. return 0;
  8288. }
  8289. ((Widget*)spawn)->SetMultiFloorLift(true);
  8290. if (spawn->GetZone())
  8291. spawn->GetZone()->AddTransportSpawn(spawn);
  8292. return 0;
  8293. }
  8294. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8295. if (!lua_interface)
  8296. return 0;
  8297. Spawn* player = lua_interface->GetSpawn(state);
  8298. int32 path = lua_interface->GetInt32Value(state, 2);
  8299. if (!player) {
  8300. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8301. return 0;
  8302. }
  8303. if (!player->IsPlayer()) {
  8304. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8305. return 0;
  8306. }
  8307. if (path == 0) {
  8308. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8309. return 0;
  8310. }
  8311. Client* client = player->GetZone()->GetClientBySpawn(player);
  8312. if (!client) {
  8313. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8314. return 0;
  8315. }
  8316. client->SendFlightAutoMount(path);
  8317. return 0;
  8318. }
  8319. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8320. if (!lua_interface)
  8321. return 0;
  8322. Spawn* player = lua_interface->GetSpawn(state);
  8323. if (!player) {
  8324. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8325. return 0;
  8326. }
  8327. if (!player->IsPlayer()) {
  8328. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8329. return 0;
  8330. }
  8331. Client* client = player->GetZone()->GetClientBySpawn(player);
  8332. if (!client) {
  8333. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8334. return 0;
  8335. }
  8336. client->EndAutoMount();
  8337. return 0;
  8338. }
  8339. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8340. if (!lua_interface)
  8341. return 0;
  8342. Spawn* player = lua_interface->GetSpawn(state);
  8343. if (!player) {
  8344. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8345. return 0;
  8346. }
  8347. if (!player->IsPlayer()) {
  8348. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8349. return 0;
  8350. }
  8351. Client* client = player->GetZone()->GetClientBySpawn(player);
  8352. if (!client) {
  8353. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8354. return 0;
  8355. }
  8356. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8357. return 1;
  8358. }
  8359. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8360. if (!lua_interface)
  8361. return 0;
  8362. Spawn* player = lua_interface->GetSpawn(state);
  8363. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8364. int32 value = lua_interface->GetInt32Value(state, 3);
  8365. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8366. if (!player) {
  8367. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8368. return 0;
  8369. }
  8370. if (!player->IsPlayer()) {
  8371. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8372. return 0;
  8373. }
  8374. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8375. return 0;
  8376. }
  8377. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8378. if (!lua_interface)
  8379. return 0;
  8380. Spawn* player = lua_interface->GetSpawn(state);
  8381. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8382. if (!player) {
  8383. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8384. return 0;
  8385. }
  8386. if (!player->IsPlayer()) {
  8387. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8388. return 0;
  8389. }
  8390. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8391. if (!hd)
  8392. return 0;
  8393. lua_interface->SetInt32Value(state, hd->Value);
  8394. lua_interface->SetInt32Value(state, hd->Value2);
  8395. return 2;
  8396. }
  8397. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8398. if (!lua_interface)
  8399. return 0;
  8400. Spawn* spawn = lua_interface->GetSpawn(state);
  8401. int32 grid = lua_interface->GetInt32Value(state, 2);
  8402. if (!spawn) {
  8403. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8404. return 0;
  8405. }
  8406. if (grid == 0) {
  8407. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8408. return 0;
  8409. }
  8410. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8411. return 0;
  8412. }
  8413. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8414. if (!lua_interface)
  8415. return 0;
  8416. Spawn* spawn = lua_interface->GetSpawn(state);
  8417. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8418. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8419. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8420. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8421. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8422. if (!spawn) {
  8423. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8424. return 0;
  8425. }
  8426. //Add this quest to the list of required quests for this spawn
  8427. spawn->SetRequiredHistory(event_id, value1, value2);
  8428. //If private spawn value set
  8429. if (private_spawn) {
  8430. //Set the spawn to be private when not granted access via history
  8431. spawn->AddAllowAccessSpawn(spawn);
  8432. spawn->SetPrivateQuestSpawn(true);
  8433. }
  8434. //This value will override vis_flags in the vis packet
  8435. if (flag_override > 0)
  8436. spawn->SetQuestsRequiredOverride(flag_override);
  8437. return 0;
  8438. }
  8439. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8440. if (!lua_interface)
  8441. return 0;
  8442. Spawn* player = lua_interface->GetSpawn(state);
  8443. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8444. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8445. if (!player) {
  8446. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8447. return 0;
  8448. }
  8449. if (!player->IsPlayer()) {
  8450. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8451. return 0;
  8452. }
  8453. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8454. return 1;
  8455. }
  8456. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8457. if (!lua_interface)
  8458. return 0;
  8459. Spawn* player = lua_interface->GetSpawn(state);
  8460. int8 level = lua_interface->GetInt8Value(state, 2);
  8461. if (!player) {
  8462. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8463. return 0;
  8464. }
  8465. if (!player->IsPlayer()) {
  8466. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8467. return 0;
  8468. }
  8469. if (level == 0) {
  8470. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8471. return 0;
  8472. }
  8473. Client* client = player->GetZone()->GetClientBySpawn(player);
  8474. if (!client) {
  8475. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8476. return 0;
  8477. }
  8478. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8479. return 0;
  8480. }
  8481. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8482. if (!lua_interface)
  8483. return 0;
  8484. Spawn* player = lua_interface->GetSpawn(state);
  8485. int32 amount = lua_interface->GetInt32Value(state, 2);
  8486. if (!player) {
  8487. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8488. return 0;
  8489. }
  8490. if (!player->IsPlayer()) {
  8491. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8492. return 0;
  8493. }
  8494. if (amount == 0) {
  8495. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8496. return 0;
  8497. }
  8498. ((Player*)player)->AddCoins(amount);
  8499. return 0;
  8500. }
  8501. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8502. if (!lua_interface)
  8503. return 0;
  8504. Spawn* player = lua_interface->GetSpawn(state);
  8505. int32 amount = lua_interface->GetInt32Value(state, 2);
  8506. if (!player) {
  8507. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8508. return 0;
  8509. }
  8510. if (!player->IsPlayer()) {
  8511. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8512. return 0;
  8513. }
  8514. if (amount == 0) {
  8515. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8516. return 0;
  8517. }
  8518. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8519. return 1;
  8520. }
  8521. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8522. if (!lua_interface)
  8523. return 0;
  8524. ZoneServer* zone = lua_interface->GetZone(state);
  8525. if (!zone) {
  8526. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8527. return 0;
  8528. }
  8529. vector<Entity*> players = zone->GetPlayers();
  8530. if (players.size() == 0)
  8531. return 0;
  8532. lua_createtable(state, players.size(), 0);
  8533. int newTable = lua_gettop(state);
  8534. for (int32 i = 0; i < players.size(); i++) {
  8535. lua_interface->SetSpawnValue(state, players.at(i));
  8536. lua_rawseti(state, newTable, i + 1);
  8537. }
  8538. return 1;
  8539. }
  8540. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8541. if (!lua_interface)
  8542. return 0;
  8543. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8544. if (!zone) {
  8545. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8546. return 0;
  8547. }
  8548. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8549. //Map of <placement_id, location_id>
  8550. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8551. map<int32, int32>::iterator itr;
  8552. vector<Spawn*> group;
  8553. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8554. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8555. if (!location) {
  8556. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8557. return 0;
  8558. }
  8559. Spawn* spawn = 0;
  8560. if (location->entities[0]) {
  8561. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8562. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8563. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8564. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8565. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8566. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8567. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8568. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8569. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8570. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8571. if (spawn) {
  8572. const char* script = 0;
  8573. for (int x = 0; x < 3; x++) {
  8574. switch (x) {
  8575. case 0:
  8576. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8577. break;
  8578. case 1:
  8579. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8580. break;
  8581. case 2:
  8582. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8583. break;
  8584. }
  8585. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8586. spawn->SetSpawnScript(string(script));
  8587. break;
  8588. }
  8589. }
  8590. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8591. lua_interface->SetSpawnValue(state, spawn);
  8592. group.push_back(spawn);
  8593. }
  8594. else {
  8595. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8596. safe_delete(spawn);
  8597. }
  8598. }
  8599. }
  8600. if (!group.empty()) {
  8601. lua_createtable(state, group.size(), 0);
  8602. int newTable = lua_gettop(state);
  8603. for (int32 i = 0; i < group.size(); i++) {
  8604. lua_interface->SetSpawnValue(state, group[i]);
  8605. lua_rawseti(state, newTable, i + 1);
  8606. }
  8607. }
  8608. else
  8609. lua_pushnil(state);
  8610. return 1;
  8611. }
  8612. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8613. if (!lua_interface)
  8614. return 0;
  8615. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8616. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8617. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8618. if (!spawn) {
  8619. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8620. return 0;
  8621. }
  8622. if (anim_id == 0) {
  8623. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8624. return 0;
  8625. }
  8626. if (leeway == 0)
  8627. leeway = 5000;
  8628. spawn->SetSpawnAnim(anim_id);
  8629. spawn->SetSpawnAnimLeeway(leeway);
  8630. return 0;
  8631. }
  8632. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8633. if (!lua_interface)
  8634. return 0;
  8635. Spawn* player = lua_interface->GetSpawn(state);
  8636. if (!player) {
  8637. return 0;
  8638. }
  8639. Client* client = player->GetZone()->GetClientBySpawn(player);
  8640. if (!client) {
  8641. return 0;
  8642. }
  8643. lua_interface->SetInt32Value(state, client->GetVersion());
  8644. return 1;
  8645. }
  8646. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8647. if (!lua_interface)
  8648. return 0;
  8649. Item* item = lua_interface->GetItem(state);
  8650. if (!item) {
  8651. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8652. return 0;
  8653. }
  8654. lua_interface->SetInt32Value(state, item->details.item_id);
  8655. return 1;
  8656. }
  8657. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8658. if (!lua_interface)
  8659. return 0;
  8660. Spawn* spawn = lua_interface->GetSpawn(state);
  8661. if (!spawn) {
  8662. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8663. return 0;
  8664. }
  8665. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8666. return 1;
  8667. }
  8668. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8669. if (!lua_interface)
  8670. return 0;
  8671. Spawn* spawn = lua_interface->GetSpawn(state);
  8672. if (!spawn) {
  8673. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8674. return 0;
  8675. }
  8676. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8677. return 1;
  8678. }
  8679. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8680. if (!lua_interface)
  8681. return 0;
  8682. Spawn* spawn = lua_interface->GetSpawn(state);
  8683. if (!spawn) {
  8684. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8685. return 0;
  8686. }
  8687. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8688. return 1;
  8689. }
  8690. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8691. if (!lua_interface)
  8692. return 0;
  8693. Spawn* spawn = lua_interface->GetSpawn(state);
  8694. if (!spawn) {
  8695. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8696. return 0;
  8697. }
  8698. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8699. return 1;
  8700. }
  8701. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8702. if (!lua_interface)
  8703. return 0;
  8704. Spawn* spawn = lua_interface->GetSpawn(state);
  8705. float pct = lua_interface->GetFloatValue(state, 2);
  8706. if (!spawn) {
  8707. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8708. return 0;
  8709. }
  8710. if (pct == 0) {
  8711. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8712. return 0;
  8713. }
  8714. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8715. lua_interface->SetInt32Value(state, amount);
  8716. return 1;
  8717. }
  8718. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8719. if (!lua_interface)
  8720. return 0;
  8721. Spawn* spawn = lua_interface->GetSpawn(state);
  8722. float pct = lua_interface->GetFloatValue(state, 2);
  8723. if (!spawn) {
  8724. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8725. return 0;
  8726. }
  8727. if (pct == 0) {
  8728. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8729. return 0;
  8730. }
  8731. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8732. lua_interface->SetInt32Value(state, amount);
  8733. return 1;
  8734. }
  8735. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8736. if (!lua_interface)
  8737. return 0;
  8738. Spawn* spawn = lua_interface->GetSpawn(state);
  8739. if (!spawn) {
  8740. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8741. return 0;
  8742. }
  8743. if (!spawn->IsPlayer()) {
  8744. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8745. return 0;
  8746. }
  8747. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8748. return 1;
  8749. }
  8750. int EQ2Emu_lua_Evac(lua_State* state) {
  8751. if (!lua_interface)
  8752. return 0;
  8753. Spawn* target = lua_interface->GetSpawn(state);
  8754. if (target) {
  8755. float x = target->GetZone()->GetSafeX();
  8756. float y = target->GetZone()->GetSafeY();
  8757. float z = target->GetZone()->GetSafeZ();
  8758. float h = target->GetZone()->GetSafeHeading();
  8759. target->SetX(x);
  8760. target->SetY(y);
  8761. target->SetZ(z);
  8762. target->SetHeading(h);
  8763. target->SetSpawnOrigX(target->GetX());
  8764. target->SetSpawnOrigY(target->GetY());
  8765. target->SetSpawnOrigZ(target->GetZ());
  8766. target->SetSpawnOrigHeading(target->GetHeading());
  8767. if (target->IsPlayer()) {
  8768. Client* client = target->GetZone()->GetClientBySpawn(target);
  8769. if (client) {
  8770. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8771. if (packet)
  8772. {
  8773. packet->setDataByName("x", x);
  8774. packet->setDataByName("y", y);
  8775. packet->setDataByName("z", z);
  8776. client->QueuePacket(packet->serialize());
  8777. safe_delete(packet);
  8778. }
  8779. }
  8780. }
  8781. }
  8782. else {
  8783. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8784. ZoneServer* zone = spell->caster->GetZone();
  8785. float x = spell->caster->GetZone()->GetSafeX();
  8786. float y = spell->caster->GetZone()->GetSafeY();
  8787. float z = spell->caster->GetZone()->GetSafeZ();
  8788. float h = spell->caster->GetZone()->GetSafeHeading();
  8789. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8790. for (int32 i = 0; i < spell->targets.size(); i++) {
  8791. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8792. if (!target2)
  8793. continue;
  8794. target2->SetX(x);
  8795. target2->SetY(y);
  8796. target2->SetZ(z);
  8797. target2->SetHeading(h);
  8798. target2->SetSpawnOrigX(target2->GetX());
  8799. target2->SetSpawnOrigY(target2->GetY());
  8800. target2->SetSpawnOrigZ(target2->GetZ());
  8801. target2->SetSpawnOrigHeading(target2->GetHeading());
  8802. if (target2->IsPlayer()) {
  8803. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8804. if (client) {
  8805. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8806. if (packet)
  8807. {
  8808. client->SetReloadingZone(true);
  8809. packet->setDataByName("x", x);
  8810. packet->setDataByName("y", y);
  8811. packet->setDataByName("z", z);
  8812. client->QueuePacket(packet->serialize());
  8813. safe_delete(packet);
  8814. }
  8815. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8816. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8817. }
  8818. }
  8819. }
  8820. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8821. }
  8822. return 0;
  8823. }
  8824. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8825. if (!lua_interface)
  8826. return 0;
  8827. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8828. if (!luaspell) {
  8829. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8830. return 0;
  8831. }
  8832. int8 tier = luaspell->spell->GetSpellTier();
  8833. lua_interface->SetInt32Value(state, tier);
  8834. return 1;
  8835. }
  8836. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8837. if (!lua_interface)
  8838. return 0;
  8839. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8840. if (!luaspell) {
  8841. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8842. return 0;
  8843. }
  8844. int32 spell_id = luaspell->spell->GetSpellID();
  8845. lua_interface->SetInt32Value(state, spell_id);
  8846. return 1;
  8847. }
  8848. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8849. if (!lua_interface)
  8850. return 0;
  8851. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8852. if (!spawn) {
  8853. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8854. return 0;
  8855. }
  8856. if (!spawn->IsPlayer()) {
  8857. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8858. return 0;
  8859. }
  8860. ZoneServer* zone = spawn->GetZone();
  8861. if (!zone) {
  8862. return 0;
  8863. }
  8864. Client* client = zone->GetClientBySpawn(spawn);
  8865. if (!client) {
  8866. return 0;
  8867. }
  8868. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8869. return 0;
  8870. }
  8871. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8872. if (!lua_interface)
  8873. return 0;
  8874. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8875. if (!spawn) {
  8876. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8877. return 0;
  8878. }
  8879. if (!spawn->IsPlayer()) {
  8880. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8881. return 0;
  8882. }
  8883. ZoneServer* zone = spawn->GetZone();
  8884. if (!zone) {
  8885. return 0;
  8886. }
  8887. Client* client = zone->GetClientBySpawn(spawn);
  8888. if (!client) {
  8889. return 0;
  8890. }
  8891. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8892. return 0;
  8893. }
  8894. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8895. if (!lua_interface)
  8896. return 0;
  8897. Spawn* caster = lua_interface->GetSpawn(state);
  8898. Spawn* target = lua_interface->GetSpawn(state, 2);
  8899. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8900. string spell_name = lua_interface->GetStringValue(state, 4);
  8901. if (!caster) {
  8902. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8903. return 0;
  8904. }
  8905. if (!caster->IsEntity()) {
  8906. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8907. return 0;
  8908. }
  8909. if (!target) {
  8910. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8911. return 0;
  8912. }
  8913. if (!target->IsEntity()) {
  8914. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8915. return 0;
  8916. }
  8917. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8918. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8919. return 0;
  8920. }
  8921. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8922. if (!lua_interface)
  8923. return 0;
  8924. Spawn* player = lua_interface->GetSpawn(state);
  8925. int32 amount = lua_interface->GetInt32Value(state, 2);
  8926. if (player && player->IsPlayer() && amount > 0) {
  8927. ((Player*)player)->AddXP(amount);
  8928. ((Player*)player)->SetCharSheetChanged(true);
  8929. Client* client = player->GetZone()->GetClientBySpawn(player);
  8930. if (client) {
  8931. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8932. }
  8933. }
  8934. return 0;
  8935. }
  8936. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8937. if (!lua_interface)
  8938. return 0;
  8939. Spawn* player = lua_interface->GetSpawn(state);
  8940. int8 type = lua_interface->GetInt8Value(state, 2);
  8941. string text = lua_interface->GetStringValue(state, 3);
  8942. Client* client = 0;
  8943. if (player && player->IsPlayer())
  8944. client = player->GetZone()->GetClientBySpawn(player);
  8945. if (!client || text.length() == 0) {
  8946. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8947. return 0;
  8948. }
  8949. client->SimpleMessage(type, text.c_str());
  8950. return 0;
  8951. }
  8952. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8953. if (!lua_interface)
  8954. return 0;
  8955. Spawn* player = lua_interface->GetSpawn(state);
  8956. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8957. Client* client = 0;
  8958. if (player && player->IsPlayer())
  8959. client = player->GetZone()->GetClientBySpawn(player);
  8960. if (!client || !spawn) {
  8961. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8962. return 0;
  8963. }
  8964. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8965. if (!items) {
  8966. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8967. return 0;
  8968. }
  8969. client->Loot(spawn->GetLootCoins(), items, spawn);
  8970. return 0;
  8971. }
  8972. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8973. if (!lua_interface)
  8974. return 0;
  8975. Spawn* spawnref = lua_interface->GetSpawn(state);
  8976. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8977. if (spawn_id > 0 && spawnref) {
  8978. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8979. if (spawns.size() == 0) {
  8980. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8981. return 0;
  8982. }
  8983. Spawn* spawn = 0;
  8984. int16 index = MakeRandomInt(0, spawns.size());
  8985. if (index >= spawns.size() || index < 0)
  8986. index = 0;
  8987. spawn = spawns[index];
  8988. lua_interface->SetSpawnValue(state, spawn);
  8989. return 1;
  8990. }
  8991. else {
  8992. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8993. }
  8994. return 0;
  8995. }
  8996. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8997. Spawn* player = lua_interface->GetSpawn(state);
  8998. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8999. string name = lua_interface->GetStringValue(state, 3);
  9000. float distance = lua_interface->GetFloatValue(state, 4);
  9001. string command = lua_interface->GetStringValue(state, 5);
  9002. string error_text = lua_interface->GetStringValue(state, 6);
  9003. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9004. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9005. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9006. if (distance == 0)
  9007. distance = 10.0f;
  9008. if (command.length() == 0)
  9009. command = name;
  9010. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9011. if (spawns.size() == 0) {
  9012. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9013. return 0;
  9014. }
  9015. Spawn* spawn = 0;
  9016. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9017. spawn = *itr;
  9018. if (spawn) {
  9019. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9020. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9021. }
  9022. }
  9023. }
  9024. return 0;
  9025. }
  9026. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9027. if (!lua_interface)
  9028. return 0;
  9029. Client* client = 0;
  9030. Spawn* player = lua_interface->GetSpawn(state);
  9031. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9032. if (player && player->IsPlayer() && player->GetZone())
  9033. client = player->GetZone()->GetClientBySpawn(player);
  9034. else{
  9035. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9036. return 0;
  9037. }
  9038. if (client) {
  9039. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9040. if (packet) {
  9041. packet->setDataByName("goal_num", goal_num);
  9042. client->QueuePacket(packet->serialize());
  9043. safe_delete(packet);
  9044. }
  9045. }
  9046. return 0;
  9047. }
  9048. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9049. if (!lua_interface)
  9050. return 0;
  9051. Client* client = 0;
  9052. Spawn* player = lua_interface->GetSpawn(state);
  9053. if (player && player->IsPlayer() && player->GetZone())
  9054. client = player->GetZone()->GetClientBySpawn(player);
  9055. else {
  9056. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9057. return 0;
  9058. }
  9059. if (client) {
  9060. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9061. }
  9062. return 0;
  9063. }
  9064. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9065. if (!lua_interface)
  9066. return 0;
  9067. Client* client = 0;
  9068. Spawn* player = lua_interface->GetSpawn(state);
  9069. float duration = lua_interface->GetFloatValue(state, 2);
  9070. string text = lua_interface->GetStringValue(state, 3);
  9071. string voice = lua_interface->GetStringValue(state, 4);
  9072. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9073. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9074. string signal = lua_interface->GetStringValue(state, 7);
  9075. string goal1 = lua_interface->GetStringValue(state, 8);
  9076. string task1 = lua_interface->GetStringValue(state, 9);
  9077. string goal2 = lua_interface->GetStringValue(state, 10);
  9078. string task2 = lua_interface->GetStringValue(state, 11);
  9079. string goal3 = lua_interface->GetStringValue(state, 12);
  9080. string task3 = lua_interface->GetStringValue(state, 13);
  9081. string goal4 = lua_interface->GetStringValue(state, 14);
  9082. string task4 = lua_interface->GetStringValue(state, 15);
  9083. if (!player) {
  9084. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9085. return 0;
  9086. }
  9087. if (!player->IsPlayer()) {
  9088. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9089. return 0;
  9090. }
  9091. else
  9092. client = ((Player*)player)->GetClient();
  9093. if (!client) {
  9094. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9095. return 0;
  9096. }
  9097. if (text.length() == 0) {
  9098. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9099. return 0;
  9100. }
  9101. if (duration >= 0 && duration < 2)
  9102. duration = 2;
  9103. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9104. if (packet) {
  9105. packet->setDataByName("open_seconds_max", duration);
  9106. packet->setDataByName("text", text.c_str());
  9107. packet->setDataByName("voice", voice.c_str());
  9108. int8 num_goals = 1;
  9109. if (task2.length() > 0)
  9110. num_goals++;
  9111. if (task3.length() > 0)
  9112. num_goals++;
  9113. if (task4.length() > 0)
  9114. num_goals++;
  9115. packet->setArrayLengthByName("num_goals", num_goals);
  9116. for (int8 i = 0; i < num_goals; i++) {
  9117. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9118. }
  9119. if (goal1.length() > 0)
  9120. packet->setArrayDataByName("goal_text", goal1.c_str());
  9121. if (goal2.length() > 0)
  9122. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9123. if (goal3.length() > 0)
  9124. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9125. if (goal4.length() > 0)
  9126. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9127. packet->setSubArrayDataByName("task_text", task1.c_str());
  9128. if (task2.length() > 0)
  9129. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9130. if (task3.length() > 0)
  9131. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9132. if (task4.length() > 0)
  9133. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9134. packet->setDataByName("complete_sound", "click");
  9135. packet->setDataByName("signal", signal.c_str());
  9136. packet->setDataByName("voice_key1", voice_key1);
  9137. packet->setDataByName("voice_key2", voice_key2);
  9138. client->QueuePacket(packet->serialize());
  9139. safe_delete(packet);
  9140. }
  9141. return 0;
  9142. }
  9143. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9144. if (!lua_interface)
  9145. return 0;
  9146. Client* client = 0;
  9147. Spawn* player = lua_interface->GetSpawn(state);
  9148. string window = lua_interface->GetStringValue(state, 2);
  9149. int8 show = lua_interface->GetInt8Value(state, 3);
  9150. if (!player) {
  9151. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9152. return 0;
  9153. }
  9154. if (!player->IsPlayer()) {
  9155. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9156. return 0;
  9157. }
  9158. else
  9159. client = ((Player*)player)->GetClient();
  9160. if (!client) {
  9161. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9162. return 0;
  9163. }
  9164. if (window.length() == 0) {
  9165. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9166. return 0;
  9167. }
  9168. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9169. if (packet) {
  9170. packet->setDataByName("window", window.c_str());
  9171. packet->setDataByName("show", show);
  9172. client->QueuePacket(packet->serialize());
  9173. safe_delete(packet);
  9174. }
  9175. return 0;
  9176. }
  9177. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9178. //See GameEvents.txt for options that can be used for this function
  9179. if (!lua_interface)
  9180. return 0;
  9181. Client* client = 0;
  9182. Spawn* player = lua_interface->GetSpawn(state);
  9183. string event_name = lua_interface->GetStringValue(state, 2);
  9184. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9185. if (!player || !player->IsPlayer()) {
  9186. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9187. return 0;
  9188. }
  9189. if (player->GetZone())
  9190. client = player->GetZone()->GetClientBySpawn(player);
  9191. if (!client) {
  9192. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9193. return 0;
  9194. }
  9195. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9196. if (packet) {
  9197. packet->setDataByName("event_name", event_name.c_str());
  9198. packet->setDataByName("enabled", enabled);
  9199. client->QueuePacket(packet->serialize());
  9200. safe_delete(packet);
  9201. }
  9202. return 0;
  9203. }
  9204. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9205. if (!lua_interface)
  9206. return 0;
  9207. Spawn* player = lua_interface->GetSpawn(state);
  9208. if (player && player->IsPlayer()) {
  9209. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9210. return 1;
  9211. }
  9212. return 0;
  9213. }
  9214. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9215. if (!lua_interface)
  9216. return 0;
  9217. Spawn* player = lua_interface->GetSpawn(state);
  9218. int8 step = lua_interface->GetInt8Value(state, 2);
  9219. if (player && player->IsPlayer() && step > 0) {
  9220. ((Player*)player)->SetTutorialStep(step);
  9221. }
  9222. return 0;
  9223. }
  9224. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9225. if (!lua_interface)
  9226. return 0;
  9227. Client* client = 0;
  9228. Spawn* player = lua_interface->GetSpawn(state);
  9229. string window = lua_interface->GetStringValue(state, 2);
  9230. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9231. if (!player) {
  9232. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9233. return 0;
  9234. }
  9235. if (!player->IsPlayer()) {
  9236. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9237. return 0;
  9238. }
  9239. else
  9240. client = ((Player*)player)->GetClient();
  9241. if (!client) {
  9242. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9243. return 0;
  9244. }
  9245. if (window.length() == 0) {
  9246. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9247. return 0;
  9248. }
  9249. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9250. if (packet) {
  9251. packet->setDataByName("window", window.c_str());
  9252. packet->setDataByName("flash_seconds", flash_seconds);
  9253. client->QueuePacket(packet->serialize());
  9254. safe_delete(packet);
  9255. }
  9256. return 0;
  9257. }
  9258. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9259. if (!lua_interface)
  9260. return 0;
  9261. Spawn* spawn = lua_interface->GetSpawn(state);
  9262. Spawn* target = lua_interface->GetSpawn(state, 2);
  9263. if (spawn && target)
  9264. return spawn->CheckLoS(target);
  9265. return 0;
  9266. }
  9267. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9268. if (!lua_interface)
  9269. return 0;
  9270. Spawn* spawn = lua_interface->GetSpawn(state);
  9271. float x = lua_interface->GetFloatValue(state, 2);
  9272. float y = lua_interface->GetFloatValue(state, 3);
  9273. float z = lua_interface->GetFloatValue(state, 4);
  9274. if (spawn)
  9275. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9276. return 0;
  9277. }
  9278. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9279. if (!lua_interface)
  9280. return 0;
  9281. ZoneServer* zone = lua_interface->GetZone(state);
  9282. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9283. if (zone)
  9284. zone->SetExpansionFlag(xpackFlag);
  9285. return 0;
  9286. }
  9287. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9288. if (!lua_interface)
  9289. return 0;
  9290. ZoneServer* zone = lua_interface->GetZone(state);
  9291. if (zone) {
  9292. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9293. return 1;
  9294. }
  9295. return 0;
  9296. }
  9297. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9298. if (!lua_interface)
  9299. return 0;
  9300. ZoneServer* zone = lua_interface->GetZone(state);
  9301. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9302. if (zone)
  9303. zone->SetHolidayFlag(holidayFlag);
  9304. return 0;
  9305. }
  9306. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9307. if (!lua_interface)
  9308. return 0;
  9309. ZoneServer* zone = lua_interface->GetZone(state);
  9310. if (zone) {
  9311. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9312. return 1;
  9313. }
  9314. return 0;
  9315. }
  9316. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9317. if (!lua_interface)
  9318. return 0;
  9319. Spawn* spawn = lua_interface->GetSpawn(state);
  9320. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9321. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9322. float distance = lua_interface->GetFloatValue(state, 4);
  9323. string in_range_function = lua_interface->GetStringValue(state, 5);
  9324. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9325. if (spawn && distance > 0 && in_range_function.length() > 0)
  9326. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9327. return 0;
  9328. }
  9329. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9330. if (!lua_interface)
  9331. return 0;
  9332. Spawn* spawn = lua_interface->GetSpawn(state);
  9333. Spawn* target = lua_interface->GetSpawn(state, 2);
  9334. if (spawn && target)
  9335. {
  9336. if (spawn->IsPlayer() && target->IsEntity())
  9337. {
  9338. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9339. return 1;
  9340. }
  9341. else if (spawn->IsEntity() && target->IsEntity())
  9342. {
  9343. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9344. return 1;
  9345. }
  9346. }
  9347. return 0;
  9348. }
  9349. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9350. if (!lua_interface)
  9351. return 0;
  9352. Spawn* spawn = lua_interface->GetSpawn(state);
  9353. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9354. if (spawn && spawn->IsEntity())
  9355. {
  9356. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9357. if (spawn->IsPlayer())
  9358. {
  9359. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9360. if (client)
  9361. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9362. }
  9363. }
  9364. return 0;
  9365. }
  9366. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9367. if (!lua_interface)
  9368. return 0;
  9369. Spawn* spawn = lua_interface->GetSpawn(state);
  9370. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9371. if (spawn && spawn->IsEntity())
  9372. {
  9373. ((Entity*)spawn)->SetSeeHideSpell(val);
  9374. if (spawn->IsPlayer())
  9375. {
  9376. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9377. if (client)
  9378. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9379. }
  9380. }
  9381. return 0;
  9382. }
  9383. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9384. {
  9385. if (!lua_interface)
  9386. return 0;
  9387. Spawn* player = lua_interface->GetSpawn(state);
  9388. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9389. string command = lua_interface->GetStringValue(state, 3);
  9390. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9391. lua_interface->ResetFunctionStack(state);
  9392. if (spawn && player && player->IsPlayer())
  9393. {
  9394. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9395. bool res = false;
  9396. if (cmd)
  9397. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9398. lua_interface->SetBooleanValue(state, res);
  9399. return 1;
  9400. }
  9401. return 0;
  9402. }
  9403. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9404. {
  9405. if (!lua_interface)
  9406. return 0;
  9407. Spawn* spawn = lua_interface->GetSpawn(state);
  9408. int32 charID = lua_interface->GetInt32Value(state, 2);
  9409. string command = lua_interface->GetStringValue(state, 3);
  9410. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9411. lua_interface->ResetFunctionStack(state);
  9412. if (spawn && charID)
  9413. {
  9414. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9415. bool res = false;
  9416. if (cmd)
  9417. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9418. lua_interface->SetBooleanValue(state, res);
  9419. return 1;
  9420. }
  9421. return 0;
  9422. }
  9423. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9424. {
  9425. if (!lua_interface)
  9426. return 0;
  9427. Spawn* spawn = lua_interface->GetSpawn(state);
  9428. string command = lua_interface->GetStringValue(state, 2);
  9429. lua_interface->ResetFunctionStack(state);
  9430. if (spawn && command.length() > 0)
  9431. spawn->RemovePrimaryEntityCommand(command.c_str());
  9432. return 0;
  9433. }
  9434. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9435. if (!lua_interface)
  9436. return 0;
  9437. Spawn* spawn = lua_interface->GetSpawn(state);
  9438. float distance = lua_interface->GetFloatValue(state, 2);
  9439. string command = lua_interface->GetStringValue(state, 3);
  9440. Spawn* player = lua_interface->GetSpawn(state, 4);
  9441. lua_interface->ResetFunctionStack(state);
  9442. if (spawn) {
  9443. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9444. }
  9445. return 0;
  9446. }
  9447. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9448. if (!lua_interface)
  9449. return 0;
  9450. Spawn* spawn = lua_interface->GetSpawn(state);
  9451. Spawn* player = lua_interface->GetSpawn(state, 2);
  9452. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9453. lua_interface->ResetFunctionStack(state);
  9454. if (spawn && player && transport_id && player->IsPlayer()) {
  9455. Client* client = 0;
  9456. if (player && player->IsPlayer())
  9457. client = player->GetZone()->GetClientBySpawn(player);
  9458. if (!client)
  9459. return 0;
  9460. vector<TransportDestination*> destinations;
  9461. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9462. if (destinations.size())
  9463. {
  9464. client->SetTemporaryTransportID(transport_id);
  9465. client->ProcessTeleport(spawn, &destinations, transport_id);
  9466. }
  9467. else
  9468. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9469. }
  9470. return 0;
  9471. }
  9472. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9473. if (!lua_interface)
  9474. return 0;
  9475. Spawn* player = lua_interface->GetSpawn(state);
  9476. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9477. lua_interface->ResetFunctionStack(state);
  9478. if (player && player->IsPlayer()) {
  9479. Client* client = 0;
  9480. if (player && player->IsPlayer())
  9481. client = player->GetZone()->GetClientBySpawn(player);
  9482. if (!client)
  9483. return 0;
  9484. client->SetTemporaryTransportID(transport_id);
  9485. }
  9486. return 0;
  9487. }
  9488. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9489. if (!lua_interface)
  9490. return 0;
  9491. Spawn* player = lua_interface->GetSpawn(state);
  9492. lua_interface->ResetFunctionStack(state);
  9493. if (player && player->IsPlayer()) {
  9494. Client* client = 0;
  9495. if (player && player->IsPlayer())
  9496. client = player->GetZone()->GetClientBySpawn(player);
  9497. if (!client)
  9498. return 0;
  9499. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9500. return 1;
  9501. }
  9502. return 0;
  9503. }
  9504. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9505. if (!lua_interface)
  9506. return 0;
  9507. Spawn* spawn = lua_interface->GetSpawn(state);
  9508. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9509. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9510. if (!spawn) {
  9511. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9512. return 0;
  9513. }
  9514. if (!spawn->IsEntity()) {
  9515. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9516. return 0;
  9517. }
  9518. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9519. {
  9520. 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);
  9521. return 0;
  9522. }
  9523. lua_interface->ResetFunctionStack(state);
  9524. if (spell && spell->targets.size() > 0) {
  9525. ZoneServer* zone = spell->caster->GetZone();
  9526. for (int8 i = 0; i < spell->targets.size(); i++) {
  9527. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9528. if (target->IsEntity()) {
  9529. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9530. if (target->IsPlayer())
  9531. ((Player*)target)->SetCharSheetChanged(true);
  9532. }
  9533. }
  9534. }
  9535. else {
  9536. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9537. if (spawn->IsPlayer())
  9538. ((Player*)spawn)->SetCharSheetChanged(true);
  9539. }
  9540. return 0;
  9541. }
  9542. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9543. if (!lua_interface)
  9544. return 0;
  9545. Spawn* spawn = lua_interface->GetSpawn(state);
  9546. lua_interface->ResetFunctionStack(state);
  9547. if (!spawn) {
  9548. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9549. return 0;
  9550. }
  9551. if (!spawn->IsEntity()) {
  9552. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9553. return 0;
  9554. }
  9555. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9556. return 1;
  9557. }
  9558. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9559. if (!lua_interface)
  9560. return 0;
  9561. int32 spell_id = lua_interface->GetInt32Value(state);
  9562. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9563. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9564. if (spell_id > 0) {
  9565. if (spell_tier == 0)
  9566. spell_tier = 1;
  9567. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9568. LuaSpell* lua_spell = 0;
  9569. if(custom_lua_script.size() > 0)
  9570. {
  9571. // attempt to load the custom script since it isn't already loaded
  9572. // we will re-obtain the lua_spell further below
  9573. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9574. {
  9575. 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());
  9576. lua_interface->LoadLuaSpell(custom_lua_script);
  9577. }
  9578. }
  9579. else
  9580. custom_lua_script = spell->GetSpellData()->lua_script;
  9581. if (!lua_spell && lua_interface)
  9582. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9583. if (!lua_spell)
  9584. {
  9585. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9586. return 0;
  9587. }
  9588. lua_spell->spell = new Spell(spell);
  9589. lua_interface->AddCustomSpell(lua_spell);
  9590. lua_interface->SetSpellValue(state, lua_spell);
  9591. return 1;
  9592. }
  9593. return 0;
  9594. }
  9595. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9596. if (!lua_interface)
  9597. return 0;
  9598. LuaSpell* spell = lua_interface->GetSpell(state);
  9599. string field = lua_interface->GetStringValue(state, 2);
  9600. if (!spell) {
  9601. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9602. return 0;
  9603. }
  9604. if (!spell->spell || !spell->spell->GetSpellData()) {
  9605. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9606. return 0;
  9607. }
  9608. boost::to_lower(field);
  9609. return spell->spell->GetSpellData(state, field);
  9610. }
  9611. int EQ2Emu_lua_SetSpellData(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. int8 fieldArg = 3; // field value after the initial set
  9617. if (!spell) {
  9618. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9619. return 0;
  9620. }
  9621. if (!spell->spell || !spell->spell->GetSpellData()) {
  9622. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9623. return 0;
  9624. }
  9625. boost::to_lower(field);
  9626. bool valSet = false;
  9627. spell->spell->SetSpellData(state, field, fieldArg);
  9628. return valSet;
  9629. }
  9630. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9631. if (!lua_interface)
  9632. return 0;
  9633. LuaSpell* spell = lua_interface->GetSpell(state);
  9634. int8 idx = lua_interface->GetInt32Value(state, 2);
  9635. if (!spell) {
  9636. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9637. return 0;
  9638. }
  9639. if (!spell->spell || !spell->spell->GetSpellData()) {
  9640. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9641. return 0;
  9642. }
  9643. if (spell->spell->lua_data.size() <= idx)
  9644. {
  9645. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9646. return 0;
  9647. }
  9648. bool setVal = true;
  9649. LUAData* data = spell->spell->lua_data[idx];
  9650. switch (data->type)
  9651. {
  9652. case 0:
  9653. {
  9654. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9655. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9656. data->int_value = value;
  9657. data->int_value2 = value2;
  9658. break;
  9659. }
  9660. case 1:
  9661. {
  9662. float value = lua_interface->GetFloatValue(state, 3);
  9663. float value2 = lua_interface->GetFloatValue(state, 4);
  9664. data->float_value = value;
  9665. data->float_value2 = value2;
  9666. break;
  9667. }
  9668. case 2:
  9669. {
  9670. bool value = lua_interface->GetBooleanValue(state, 3);
  9671. data->bool_value = value;
  9672. break;
  9673. }
  9674. case 3:
  9675. {
  9676. string value = lua_interface->GetStringValue(state, 3);
  9677. string value2 = lua_interface->GetStringValue(state, 4);
  9678. data->string_value = value;
  9679. data->string_value2 = value2;
  9680. break;
  9681. }
  9682. default:
  9683. setVal = false;
  9684. }
  9685. return setVal;
  9686. }
  9687. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9688. if (!lua_interface)
  9689. return 0;
  9690. LuaSpell* spell = lua_interface->GetSpell(state);
  9691. int8 idx = lua_interface->GetInt32Value(state, 2);
  9692. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9693. if (!spell) {
  9694. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9695. return 0;
  9696. }
  9697. if (!spell->spell || !spell->spell->GetSpellData()) {
  9698. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9699. return 0;
  9700. }
  9701. if (spell->spell->lua_data.size() <= idx)
  9702. {
  9703. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9704. return 0;
  9705. }
  9706. bool setVal = true;
  9707. LUAData* data = spell->spell->lua_data[idx];
  9708. switch (data->type)
  9709. {
  9710. case 0:
  9711. {
  9712. if(!secondfield)
  9713. lua_interface->SetSInt32Value(state, data->int_value);
  9714. else
  9715. lua_interface->SetSInt32Value(state, data->int_value2);
  9716. break;
  9717. }
  9718. case 1:
  9719. {
  9720. if (!secondfield)
  9721. lua_interface->SetFloatValue(state, data->float_value);
  9722. else
  9723. lua_interface->SetFloatValue(state, data->float_value2);
  9724. break;
  9725. }
  9726. case 2:
  9727. {
  9728. lua_interface->SetBooleanValue(state, data->bool_value);
  9729. break;
  9730. }
  9731. case 3:
  9732. {
  9733. if (!secondfield)
  9734. lua_interface->SetStringValue(state, data->string_value.c_str());
  9735. else
  9736. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9737. break;
  9738. }
  9739. default:
  9740. setVal = false;
  9741. }
  9742. return setVal;
  9743. }
  9744. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9745. if (!lua_interface)
  9746. return 0;
  9747. LuaSpell* spell = lua_interface->GetSpell(state);
  9748. int8 idx = lua_interface->GetInt32Value(state, 2);
  9749. string field = lua_interface->GetStringValue(state, 3);
  9750. boost::to_lower(field);
  9751. if (!spell) {
  9752. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9753. return 0;
  9754. }
  9755. if (!spell->spell || !spell->spell->GetSpellData()) {
  9756. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9757. return 0;
  9758. }
  9759. if (spell->spell->effects.size() <= idx)
  9760. {
  9761. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9762. return 0;
  9763. }
  9764. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9765. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9766. if (field == "description")
  9767. effect->description = string(lua_interface->GetStringValue(state, 4));
  9768. else if (field == "bullet")
  9769. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9770. else if (field == "percentage")
  9771. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9772. else // no match
  9773. return 0;
  9774. return 1;
  9775. }
  9776. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9777. if (!lua_interface)
  9778. return 0;
  9779. LuaSpell* spell = lua_interface->GetSpell(state);
  9780. int8 idx = lua_interface->GetInt32Value(state, 2);
  9781. string field = lua_interface->GetStringValue(state, 3);
  9782. boost::to_lower(field);
  9783. if (!spell) {
  9784. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9785. return 0;
  9786. }
  9787. if (!spell->spell || !spell->spell->GetSpellData()) {
  9788. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9789. return 0;
  9790. }
  9791. if (spell->spell->effects.size() <= idx)
  9792. {
  9793. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9794. return 0;
  9795. }
  9796. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9797. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9798. if (field == "description")
  9799. lua_interface->SetStringValue(state, effect->description.c_str());
  9800. else if (field == "bullet")
  9801. lua_interface->SetInt32Value(state, effect->subbullet);
  9802. else if (field == "percentage")
  9803. lua_interface->SetInt32Value(state, effect->percentage);
  9804. else // no match
  9805. return 0;
  9806. return 1;
  9807. }
  9808. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9809. if (!lua_interface)
  9810. return 0;
  9811. LuaSpell* spell = lua_interface->GetSpell(state);
  9812. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9813. Spawn* target = lua_interface->GetSpawn(state, 3);
  9814. if (!target) {
  9815. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9816. return 0;
  9817. }
  9818. if (!target->IsEntity()) {
  9819. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9820. return 0;
  9821. }
  9822. if (!spell) {
  9823. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9824. return 0;
  9825. }
  9826. if (caster && !caster->IsEntity()) {
  9827. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9828. return 0;
  9829. }
  9830. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9831. return 0;
  9832. }
  9833. int EQ2Emu_lua_InWater(lua_State* state) {
  9834. if (!lua_interface)
  9835. return 0;
  9836. Spawn* spawn = lua_interface->GetSpawn(state);
  9837. lua_interface->ResetFunctionStack(state);
  9838. if (spawn) {
  9839. lua_interface->SetBooleanValue(state, spawn->InWater());
  9840. return 1;
  9841. }
  9842. return 0;
  9843. }
  9844. int EQ2Emu_lua_InLava(lua_State* state) {
  9845. if (!lua_interface)
  9846. return 0;
  9847. Spawn* spawn = lua_interface->GetSpawn(state);
  9848. lua_interface->ResetFunctionStack(state);
  9849. if (spawn) {
  9850. lua_interface->SetBooleanValue(state, spawn->InLava());
  9851. return 1;
  9852. }
  9853. return 0;
  9854. }
  9855. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9856. if (!lua_interface)
  9857. return 0;
  9858. Spawn* attacker = lua_interface->GetSpawn(state);
  9859. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9860. int8 type = lua_interface->GetInt8Value(state, 3);
  9861. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9862. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9863. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9864. string spell_name = lua_interface->GetStringValue(state, 7);
  9865. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9866. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9867. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9868. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9869. lua_interface->ResetFunctionStack(state);
  9870. if (!attacker) {
  9871. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9872. return 0;
  9873. }
  9874. if (!attacker->IsEntity()) {
  9875. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9876. return 0;
  9877. }
  9878. if (!victim) {
  9879. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9880. return 0;
  9881. }
  9882. if (!victim->IsEntity()) {
  9883. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9884. return 0;
  9885. }
  9886. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9887. return 0;
  9888. }
  9889. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9890. if (!lua_interface)
  9891. return 0;
  9892. Spawn* spawn = lua_interface->GetSpawn(state);
  9893. lua_interface->ResetFunctionStack(state);
  9894. if (spawn) {
  9895. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9896. return 1;
  9897. }
  9898. return 0;
  9899. }
  9900. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9901. if (!lua_interface)
  9902. return 0;
  9903. Spawn* spawn = lua_interface->GetSpawn(state);
  9904. bool invul = lua_interface->GetBooleanValue(state, 2);
  9905. lua_interface->ResetFunctionStack(state);
  9906. if (spawn) {
  9907. spawn->SetInvulnerable(invul);
  9908. }
  9909. return 0;
  9910. }
  9911. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  9912. if (!lua_interface)
  9913. return 0;
  9914. string category = lua_interface->GetStringValue(state);
  9915. string name = lua_interface->GetStringValue(state, 2);
  9916. lua_interface->ResetFunctionStack(state);
  9917. Rule *ret = 0;
  9918. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9919. lua_interface->SetBooleanValue(state, ret->GetBool());
  9920. return 1;
  9921. }
  9922. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9923. return 0;
  9924. }
  9925. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9926. if (!lua_interface)
  9927. return 0;
  9928. string category = lua_interface->GetStringValue(state);
  9929. string name = lua_interface->GetStringValue(state, 2);
  9930. lua_interface->ResetFunctionStack(state);
  9931. Rule *ret = 0;
  9932. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9933. lua_interface->SetInt32Value(state, ret->GetInt32());
  9934. return 1;
  9935. }
  9936. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9937. return 0;
  9938. }
  9939. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  9940. if (!lua_interface)
  9941. return 0;
  9942. string category = lua_interface->GetStringValue(state);
  9943. string name = lua_interface->GetStringValue(state, 2);
  9944. lua_interface->ResetFunctionStack(state);
  9945. Rule *ret = 0;
  9946. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9947. lua_interface->SetFloatValue(state, ret->GetFloat());
  9948. return 1;
  9949. }
  9950. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9951. return 0;
  9952. }
  9953. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  9954. if (!lua_interface)
  9955. return 0;
  9956. Spawn* spawn = lua_interface->GetSpawn(state);
  9957. string type = lua_interface->GetStringValue(state, 2);
  9958. lua_interface->ResetFunctionStack(state);
  9959. if (spawn) {
  9960. int res = 1;
  9961. boost::to_lower(type);
  9962. if(type == "assigned_aa")
  9963. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  9964. else if ( type == "unassigned_aa")
  9965. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  9966. else if ( type == "assigned_tradeskill_aa")
  9967. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  9968. else if ( type == "unassigned_tradeskill_aa")
  9969. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  9970. else if ( type == "assigned_prestige_aa")
  9971. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  9972. else if ( type == "unassigned_prestige_aa")
  9973. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  9974. else if ( type == "assigned_tradeskill_prestige_aa")
  9975. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  9976. else if ( type == "unassigned_tradeskill_prestige_aa")
  9977. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  9978. else
  9979. res = 0;
  9980. return res;
  9981. }
  9982. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  9983. return 0;
  9984. }
  9985. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  9986. if (!lua_interface)
  9987. return 0;
  9988. Spawn* spawn = lua_interface->GetSpawn(state);
  9989. string type = lua_interface->GetStringValue(state, 2);
  9990. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9991. lua_interface->ResetFunctionStack(state);
  9992. if (spawn) {
  9993. boost::to_lower(type);
  9994. if(type == "assigned_aa")
  9995. spawn->SetAssignedAA((sint16)value);
  9996. else if ( type == "unassigned_aa")
  9997. spawn->SetUnassignedAA((sint16)value);
  9998. else if ( type == "assigned_tradeskill_aa")
  9999. spawn->SetTradeskillAA((sint16)value);
  10000. else if ( type == "unassigned_tradeskill_aa")
  10001. spawn->SetUnassignedTradeskillAA((sint16)value);
  10002. else if ( type == "assigned_prestige_aa")
  10003. spawn->SetPrestigeAA((sint16)value);
  10004. else if ( type == "unassigned_prestige_aa")
  10005. spawn->SetUnassignedPrestigeAA((sint16)value);
  10006. else if ( type == "assigned_tradeskill_prestige_aa")
  10007. spawn->SetTradeskillPrestigeAA((sint16)value);
  10008. else if ( type == "unassigned_tradeskill_prestige_aa")
  10009. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10010. if(spawn->IsPlayer())
  10011. ((Player*)spawn)->SetCharSheetChanged(true);
  10012. }
  10013. return 0;
  10014. }
  10015. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10016. if (!lua_interface)
  10017. return 0;
  10018. string titleName = lua_interface->GetStringValue(state);
  10019. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10020. lua_interface->ResetFunctionStack(state);
  10021. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10022. lua_interface->SetSInt32Value(state, index);
  10023. return 1;
  10024. }
  10025. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10026. if (!lua_interface)
  10027. return 0;
  10028. Spawn* spawn = lua_interface->GetSpawn(state);
  10029. string titleName = lua_interface->GetStringValue(state, 2);
  10030. lua_interface->ResetFunctionStack(state);
  10031. if(!spawn->IsPlayer())
  10032. {
  10033. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10034. lua_interface->SetSInt32Value(state, -1);
  10035. return 1;
  10036. }
  10037. Player* player = (Player*)spawn;
  10038. // check if player already has the title, don't need to add twice
  10039. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10040. if ( playerHasTitle)
  10041. {
  10042. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10043. return 1;
  10044. }
  10045. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10046. if(!title)
  10047. {
  10048. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10049. lua_interface->SetSInt32Value(state, -1);
  10050. return 1;
  10051. }
  10052. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10053. if(returnIdx < 0)
  10054. {
  10055. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10056. }
  10057. lua_interface->SetSInt32Value(state, returnIdx);
  10058. player->GetClient()->SendTitleUpdate();
  10059. return 1;
  10060. }
  10061. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10062. if (!lua_interface)
  10063. return 0;
  10064. Spawn* spawn = lua_interface->GetSpawn(state);
  10065. string titleName = lua_interface->GetStringValue(state, 2);
  10066. lua_interface->ResetFunctionStack(state);
  10067. if(!spawn->IsPlayer())
  10068. {
  10069. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10070. return 0;
  10071. }
  10072. Player* player = (Player*)spawn;
  10073. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10074. if(!title)
  10075. {
  10076. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10077. return 0;
  10078. }
  10079. if(title->GetPrefix())
  10080. {
  10081. 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());
  10082. return 0;
  10083. }
  10084. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10085. player->GetClient()->SendTitleUpdate();
  10086. return 1;
  10087. }
  10088. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10089. if (!lua_interface)
  10090. return 0;
  10091. Spawn* spawn = lua_interface->GetSpawn(state);
  10092. string titleName = lua_interface->GetStringValue(state, 2);
  10093. lua_interface->ResetFunctionStack(state);
  10094. if(!spawn->IsPlayer())
  10095. {
  10096. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10097. return 0;
  10098. }
  10099. Player* player = (Player*)spawn;
  10100. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10101. if(!title)
  10102. {
  10103. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10104. return 0;
  10105. }
  10106. if(!title->GetPrefix())
  10107. {
  10108. 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());
  10109. return 0;
  10110. }
  10111. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10112. player->GetClient()->SendTitleUpdate();
  10113. return 1;
  10114. }
  10115. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10116. if (!lua_interface)
  10117. return 0;
  10118. Spawn* spawn = lua_interface->GetSpawn(state);
  10119. lua_interface->ResetFunctionStack(state);
  10120. if(!spawn->IsPlayer())
  10121. {
  10122. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10123. return 0;
  10124. }
  10125. Player* player = (Player*)spawn;
  10126. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10127. player->GetClient()->SendTitleUpdate();
  10128. return 1;
  10129. }
  10130. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10131. if (!lua_interface)
  10132. return 0;
  10133. Spawn* spawn = lua_interface->GetSpawn(state);
  10134. lua_interface->ResetFunctionStack(state);
  10135. if(!spawn->IsPlayer())
  10136. {
  10137. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10138. return 0;
  10139. }
  10140. Player* player = (Player*)spawn;
  10141. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10142. player->GetClient()->SendTitleUpdate();
  10143. return 1;
  10144. }
  10145. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10146. if (!lua_interface)
  10147. return 0;
  10148. Spawn* spawn = lua_interface->GetSpawn(state);
  10149. string field = lua_interface->GetStringValue(state, 2);
  10150. lua_interface->ResetFunctionStack(state);
  10151. if(!spawn || !spawn->IsEntity())
  10152. {
  10153. 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));
  10154. return 0;
  10155. }
  10156. Entity* ent = (Entity*)spawn;
  10157. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10158. return 1;
  10159. }
  10160. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10161. if (!lua_interface)
  10162. return 0;
  10163. Spawn* spawn = lua_interface->GetSpawn(state);
  10164. string field = lua_interface->GetStringValue(state, 2);
  10165. lua_interface->ResetFunctionStack(state);
  10166. if(!spawn || !spawn->IsEntity())
  10167. {
  10168. 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));
  10169. return 0;
  10170. }
  10171. Entity* ent = (Entity*)spawn;
  10172. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10173. return 1;
  10174. }
  10175. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10176. if (!lua_interface)
  10177. return 0;
  10178. Spawn* spawn = lua_interface->GetSpawn(state);
  10179. string field = lua_interface->GetStringValue(state, 2);
  10180. lua_interface->ResetFunctionStack(state);
  10181. if(!spawn || !spawn->IsEntity())
  10182. {
  10183. 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));
  10184. return 0;
  10185. }
  10186. Entity* ent = (Entity*)spawn;
  10187. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10188. return 1;
  10189. }
  10190. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10191. if (!lua_interface)
  10192. return 0;
  10193. Spawn* spawn = lua_interface->GetSpawn(state);
  10194. string field = lua_interface->GetStringValue(state, 2);
  10195. lua_interface->ResetFunctionStack(state);
  10196. if(!spawn || !spawn->IsEntity())
  10197. {
  10198. 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));
  10199. return 0;
  10200. }
  10201. Entity* ent = (Entity*)spawn;
  10202. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10203. return 1;
  10204. }
  10205. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10206. if (!lua_interface)
  10207. return 0;
  10208. Spawn* spawn = lua_interface->GetSpawn(state);
  10209. string field = lua_interface->GetStringValue(state, 2);
  10210. string value = lua_interface->GetStringValue(state, 3);
  10211. lua_interface->ResetFunctionStack(state);
  10212. if(!spawn || !spawn->IsEntity())
  10213. {
  10214. 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));
  10215. return 0;
  10216. }
  10217. Entity* ent = (Entity*)spawn;
  10218. bool set_ = ent->SetInfoStructString(field, value);
  10219. lua_interface->SetBooleanValue(state, set_);
  10220. return 1;
  10221. }
  10222. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10223. if (!lua_interface)
  10224. return 0;
  10225. Spawn* spawn = lua_interface->GetSpawn(state);
  10226. string field = lua_interface->GetStringValue(state, 2);
  10227. int64 value = lua_interface->GetInt64Value(state, 3);
  10228. lua_interface->ResetFunctionStack(state);
  10229. if(!spawn || !spawn->IsEntity())
  10230. {
  10231. 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));
  10232. return 0;
  10233. }
  10234. Entity* ent = (Entity*)spawn;
  10235. bool set_ = ent->SetInfoStructUInt(field, value);
  10236. lua_interface->SetBooleanValue(state, set_);
  10237. return 1;
  10238. }
  10239. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10240. if (!lua_interface)
  10241. return 0;
  10242. Spawn* spawn = lua_interface->GetSpawn(state);
  10243. string field = lua_interface->GetStringValue(state, 2);
  10244. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10245. lua_interface->ResetFunctionStack(state);
  10246. if(!spawn || !spawn->IsEntity())
  10247. {
  10248. 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));
  10249. return 0;
  10250. }
  10251. Entity* ent = (Entity*)spawn;
  10252. bool set_ = ent->SetInfoStructSInt(field, value);
  10253. lua_interface->SetBooleanValue(state, set_);
  10254. return 1;
  10255. }
  10256. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10257. if (!lua_interface)
  10258. return 0;
  10259. Spawn* spawn = lua_interface->GetSpawn(state);
  10260. string field = lua_interface->GetStringValue(state, 2);
  10261. float value = lua_interface->GetFloatValue(state, 3);
  10262. lua_interface->ResetFunctionStack(state);
  10263. if(!spawn || !spawn->IsEntity())
  10264. {
  10265. 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));
  10266. return 0;
  10267. }
  10268. Entity* ent = (Entity*)spawn;
  10269. bool set_ = ent->SetInfoStructFloat(field, value);
  10270. lua_interface->SetBooleanValue(state, set_);
  10271. return 1;
  10272. }
  10273. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10274. if (!lua_interface)
  10275. return 0;
  10276. Spawn* spawn = lua_interface->GetSpawn(state);
  10277. bool value = lua_interface->GetBooleanValue(state, 2);
  10278. lua_interface->ResetFunctionStack(state);
  10279. if(!spawn || !spawn->IsPlayer())
  10280. {
  10281. 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));
  10282. return 0;
  10283. }
  10284. ((Player*)spawn)->SetCharSheetChanged(value);
  10285. return 0;
  10286. }
  10287. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10288. if (!lua_interface)
  10289. return 0;
  10290. Spawn* spawn = lua_interface->GetSpawn(state);
  10291. std::string fromName = lua_interface->GetStringValue(state, 2);
  10292. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10293. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10294. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10295. int32 copper = lua_interface->GetInt32Value(state, 6);
  10296. int32 silver = lua_interface->GetInt32Value(state, 7);
  10297. int32 gold = lua_interface->GetInt32Value(state, 8);
  10298. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10299. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10300. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10301. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10302. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10303. lua_interface->ResetFunctionStack(state);
  10304. if(!spawn || !spawn->IsPlayer())
  10305. {
  10306. 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));
  10307. lua_interface->SetBooleanValue(state, false);
  10308. return 1;
  10309. }
  10310. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10311. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10312. lua_interface->SetBooleanValue(state, true);
  10313. return 1;
  10314. }
  10315. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10316. if (!lua_interface)
  10317. return 0;
  10318. int32 char_id = lua_interface->GetInt32Value(state);
  10319. std::string fromName = lua_interface->GetStringValue(state, 2);
  10320. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10321. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10322. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10323. int32 copper = lua_interface->GetInt32Value(state, 6);
  10324. int32 silver = lua_interface->GetInt32Value(state, 7);
  10325. int32 gold = lua_interface->GetInt32Value(state, 8);
  10326. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10327. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10328. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10329. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10330. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10331. lua_interface->ResetFunctionStack(state);
  10332. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10333. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10334. lua_interface->SetBooleanValue(state, true);
  10335. return 1;
  10336. }
  10337. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10338. Spawn* widget;
  10339. if (lua_interface) {
  10340. widget = lua_interface->GetSpawn(state);
  10341. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10342. lua_interface->ResetFunctionStack(state);
  10343. if (widget && widget->IsWidget())
  10344. {
  10345. ((Widget*)widget)->OpenDoor();
  10346. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10347. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10348. }
  10349. else
  10350. 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));
  10351. }
  10352. return 0;
  10353. }
  10354. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10355. Spawn* widget;
  10356. if (lua_interface) {
  10357. widget = lua_interface->GetSpawn(state);
  10358. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10359. lua_interface->ResetFunctionStack(state);
  10360. if (widget && widget->IsWidget())
  10361. {
  10362. ((Widget*)widget)->CloseDoor();
  10363. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10364. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10365. }
  10366. else
  10367. 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));
  10368. }
  10369. return 0;
  10370. }
  10371. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10372. if (!lua_interface)
  10373. return 0;
  10374. Spawn* widget = lua_interface->GetSpawn(state);
  10375. lua_interface->ResetFunctionStack(state);
  10376. if (widget && widget->IsWidget())
  10377. {
  10378. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10379. return 1;
  10380. }
  10381. return 0;
  10382. }
  10383. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10384. if (!lua_interface)
  10385. return 0;
  10386. sint32 min = lua_interface->GetSInt32Value(state);
  10387. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10388. lua_interface->ResetFunctionStack(state);
  10389. sint32 result = MakeRandomInt(min, max);
  10390. lua_interface->SetSInt32Value(state, result);
  10391. return 1;
  10392. }
  10393. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10394. if (!lua_interface)
  10395. return 0;
  10396. float min = lua_interface->GetFloatValue(state);
  10397. float max = lua_interface->GetFloatValue(state, 2);
  10398. lua_interface->ResetFunctionStack(state);
  10399. float result = MakeRandomFloat(min, max);
  10400. lua_interface->SetFloatValue(state, result);
  10401. return 1;
  10402. }
  10403. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10404. if (!lua_interface)
  10405. return 0;
  10406. Spawn* spawn = lua_interface->GetSpawn(state);
  10407. int32 value = lua_interface->GetInt32Value(state, 2);
  10408. lua_interface->ResetFunctionStack(state);
  10409. if(!spawn)
  10410. {
  10411. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10412. lua_interface->SetBooleanValue(state, false);
  10413. return 1;
  10414. }
  10415. spawn->AddIconValue(value);
  10416. lua_interface->SetBooleanValue(state, true);
  10417. return 1;
  10418. }
  10419. int EQ2Emu_lua_RemoveIconValue(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 RemoveIconValue 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->RemoveIconValue(value);
  10432. lua_interface->SetBooleanValue(state, true);
  10433. return 1;
  10434. }
  10435. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10436. Spawn* npc = lua_interface->GetSpawn(state);
  10437. lua_interface->ResetFunctionStack(state);
  10438. if (npc && npc->IsNPC()) {
  10439. NPC* shard = (NPC*)npc;
  10440. int32 shardid = shard->GetShardID();
  10441. lua_interface->SetInt32Value(state, shardid);
  10442. return 1;
  10443. }
  10444. lua_interface->SetInt32Value(state, 0);
  10445. return 1;
  10446. }
  10447. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10448. Spawn* npc = lua_interface->GetSpawn(state);
  10449. lua_interface->ResetFunctionStack(state);
  10450. if (npc && npc->IsNPC()) {
  10451. NPC* shard = (NPC*)npc;
  10452. int32 charid = shard->GetShardCharID();
  10453. lua_interface->SetInt32Value(state, charid);
  10454. return 1;
  10455. }
  10456. lua_interface->SetInt32Value(state, 0);
  10457. return 1;
  10458. }
  10459. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10460. Spawn* npc = lua_interface->GetSpawn(state);
  10461. lua_interface->ResetFunctionStack(state);
  10462. if (npc && npc->IsNPC()) {
  10463. NPC* shard = (NPC*)npc;
  10464. int64 timestamp = shard->GetShardCreatedTimestamp();
  10465. lua_interface->SetSInt64Value(state, timestamp);
  10466. return 1;
  10467. }
  10468. lua_interface->SetSInt64Value(state, 0);
  10469. return 1;
  10470. }
  10471. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10472. if (!lua_interface)
  10473. return 0;
  10474. int32 shardid = lua_interface->GetInt32Value(state);
  10475. lua_interface->ResetFunctionStack(state);
  10476. if(shardid < 1)
  10477. lua_interface->SetBooleanValue(state, false);
  10478. else
  10479. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10480. return 1;
  10481. }
  10482. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10483. if (!lua_interface)
  10484. return 0;
  10485. Spawn* spawn = lua_interface->GetSpawn(state);
  10486. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10487. if (spawn) {
  10488. spawn->PauseMovement(delay_in_ms);
  10489. }
  10490. lua_interface->ResetFunctionStack(state);
  10491. return 0;
  10492. }