LuaFunctions.cpp 412 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 546 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  685. lua_interface->SetBooleanValue(state, true);
  686. return 1;
  687. }
  688. lua_interface->SetBooleanValue(state, false);
  689. return 1;
  690. }
  691. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  692. Spawn* spawn = lua_interface->GetSpawn(state);
  693. lua_interface->ResetFunctionStack(state);
  694. if (spawn) {
  695. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  701. Spawn* spawn = lua_interface->GetSpawn(state);
  702. lua_interface->ResetFunctionStack(state);
  703. if (spawn) {
  704. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  705. return 1;
  706. }
  707. return 0;
  708. }
  709. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  710. Player* player = (Player*)lua_interface->GetSpawn(state);
  711. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  712. lua_interface->ResetFunctionStack(state);
  713. if (player && player->IsPlayer() && faction_id > 0) {
  714. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  715. return 1;
  716. }
  717. return 0;
  718. }
  719. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  720. if (!lua_interface)
  721. return 0;
  722. Spawn* spawn = lua_interface->GetSpawn(state);
  723. int32 value = lua_interface->GetInt32Value(state, 2);
  724. lua_interface->ResetFunctionStack(state);
  725. if (spawn) {
  726. spawn->SetFactionID(value);
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  731. Spawn* spawn = lua_interface->GetSpawn(state);
  732. lua_interface->ResetFunctionStack(state);
  733. if (spawn) {
  734. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  735. return 1;
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_GetGender(lua_State* state) {
  740. Spawn* spawn = lua_interface->GetSpawn(state);
  741. lua_interface->ResetFunctionStack(state);
  742. if (spawn) {
  743. lua_interface->SetInt32Value(state, spawn->GetGender());
  744. return 1;
  745. }
  746. return 0;
  747. }
  748. int EQ2Emu_lua_GetTarget(lua_State* state) {
  749. Spawn* spawn = lua_interface->GetSpawn(state);
  750. lua_interface->ResetFunctionStack(state);
  751. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  752. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  753. return 1;
  754. }
  755. return 0;
  756. }
  757. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  758. if (!lua_interface)
  759. return 0;
  760. Spawn* spawn = lua_interface->GetSpawn(state);
  761. string mp3_string = lua_interface->GetStringValue(state, 2);
  762. int32 key1 = lua_interface->GetInt32Value(state, 3);
  763. int32 key2 = lua_interface->GetInt32Value(state, 4);
  764. Spawn* player = lua_interface->GetSpawn(state, 5);
  765. lua_interface->ResetFunctionStack(state);
  766. if (spawn && mp3_string.length() > 0) {
  767. Client* client = 0;
  768. if (player && player->IsPlayer())
  769. client = ((Player*)player)->GetClient();
  770. if (client) {
  771. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  772. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  773. }
  774. else
  775. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* spawn = lua_interface->GetSpawn(state);
  783. lua_interface->ResetFunctionStack(state);
  784. if (spawn) {
  785. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  786. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  788. return 3;
  789. }
  790. return 0;
  791. }
  792. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  793. if (!lua_interface)
  794. return 0;
  795. Spawn* spawn = lua_interface->GetSpawn(state);
  796. if (spawn) {
  797. int32 item_id = lua_interface->GetInt32Value(state, 2);
  798. lua_interface->ResetFunctionStack(state);
  799. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  800. return 1;
  801. }
  802. lua_interface->ResetFunctionStack(state);
  803. return 0;
  804. }
  805. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  806. if (!lua_interface)
  807. return 0;
  808. Spawn* spawn = lua_interface->GetSpawn(state);
  809. if (spawn && spawn->IsEntity()) {
  810. int32 item_id = lua_interface->GetInt32Value(state, 2);
  811. int16 charges = lua_interface->GetInt16Value(state, 3);
  812. if (charges == 0)
  813. charges = 1;
  814. ((Entity*)spawn)->AddLootItem(item_id, charges);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* spawn = lua_interface->GetSpawn(state);
  823. if (spawn && spawn->IsEntity()) {
  824. int32 item_id = lua_interface->GetInt32Value(state, 2);
  825. Item* item = spawn->LootItem(item_id);
  826. lua_interface->SetLuaUserDataStale(item);
  827. safe_delete(item);
  828. }
  829. lua_interface->ResetFunctionStack(state);
  830. return 0;
  831. }
  832. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  833. if (!lua_interface)
  834. return 0;
  835. Spawn* spawn = lua_interface->GetSpawn(state);
  836. if (spawn) {
  837. int32 val = lua_interface->GetInt32Value(state, 2);
  838. spawn->AddLootCoins(val);
  839. }
  840. lua_interface->ResetFunctionStack(state);
  841. return 0;
  842. }
  843. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  844. if (!lua_interface)
  845. return 0;
  846. Spawn* entity = lua_interface->GetSpawn(state);
  847. Spawn* player = lua_interface->GetSpawn(state, 2);
  848. if (entity && player && player->IsPlayer()) {
  849. int32 coins = lua_interface->GetInt32Value(state, 3);
  850. vector<Item*>* items = 0;
  851. int i = 0;
  852. int32 item_id = 0;
  853. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  854. if (items == 0)
  855. items = new vector<Item*>;
  856. if (master_item_list.GetItem(item_id))
  857. items->push_back(master_item_list.GetItem(item_id));
  858. i++;
  859. }
  860. Client* client = 0;
  861. client = ((Player*)player)->GetClient();
  862. if (client)
  863. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  864. if(coins > 0)
  865. entity->AddLootCoins(coins);
  866. safe_delete(items);
  867. }
  868. lua_interface->ResetFunctionStack(state);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* entity = lua_interface->GetSpawn(state);
  875. Spawn* player = lua_interface->GetSpawn(state, 2);
  876. int32 item_id = lua_interface->GetInt32Value(state, 3);
  877. lua_interface->ResetFunctionStack(state);
  878. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  879. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  880. return 1;
  881. }
  882. return 0;
  883. }
  884. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  885. if (!lua_interface)
  886. return 0;
  887. Spawn* entity = lua_interface->GetSpawn(state);
  888. Spawn* player = lua_interface->GetSpawn(state, 2);
  889. lua_interface->ResetFunctionStack(state);
  890. if (entity && player && player->IsPlayer()) {
  891. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  892. return 1;
  893. }
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  900. lua_interface->SetLuaUserDataStale(conversation);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = ((Player*)player)->GetClient();
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = ((Player*)player)->GetClient();
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = ((Player*)player)->GetClient();
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. lua_interface->SetLuaUserDataStale(conversation);
  994. safe_delete(conversation);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = ((Player*)player)->GetClient();
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. lua_interface->SetLuaUserDataStale(conversation);
  1020. safe_delete(conversation);
  1021. }
  1022. else
  1023. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = ((Player*)player)->GetClient();
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = ((Player*)player)->GetClient();
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = ((Player*)player)->GetClient();
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = ((Player*)player)->GetClient();
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. return 0;
  1247. }
  1248. Spawn* caster = luaspell->caster;
  1249. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1250. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1251. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1252. Spawn* target = lua_interface->GetSpawn(state, 4);
  1253. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1254. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1255. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1256. lua_interface->ResetFunctionStack(state);
  1257. boost::to_lower(heal_type);
  1258. if (caster && caster->IsEntity()) {
  1259. bool success = false;
  1260. luaspell->resisted = false;
  1261. if (target) {
  1262. float distance = caster->GetDistance(target, true);
  1263. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1264. success = true;
  1265. }
  1266. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1267. Spawn* target = 0;
  1268. ZoneServer* zone = luaspell->caster->GetZone();
  1269. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1270. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1271. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1272. float distance = caster->GetDistance(target, true);
  1273. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1274. }
  1275. }
  1276. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1277. success = true;
  1278. }
  1279. if (success) {
  1280. if (caster->GetZone())
  1281. caster->GetZone()->TriggerCharSheetTimer();
  1282. }
  1283. }
  1284. return 0;
  1285. }
  1286. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1287. if (!lua_interface)
  1288. return 0;
  1289. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1290. if(!luaspell || luaspell->resisted) {
  1291. return 0;
  1292. }
  1293. Spawn* caster = luaspell->caster;
  1294. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1295. float percentage = lua_interface->GetFloatValue(state, 2);
  1296. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1297. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1298. Spawn* target = lua_interface->GetSpawn(state, 5);
  1299. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1300. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1301. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1302. lua_interface->ResetFunctionStack(state);
  1303. boost::to_lower(heal_type);
  1304. int32 min_heal = 0, max_heal = 0;
  1305. if (caster && caster->IsEntity() && target) {
  1306. if(percentage <= 0.0f)
  1307. {
  1308. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1309. return 0;
  1310. }
  1311. if(heal_type == "power")
  1312. {
  1313. if(current_value)
  1314. {
  1315. if(caster_value)
  1316. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1317. else
  1318. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1319. }
  1320. else
  1321. {
  1322. if(caster_value)
  1323. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1324. else
  1325. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1326. }
  1327. }
  1328. else
  1329. {
  1330. if(current_value)
  1331. {
  1332. if(caster_value)
  1333. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1334. else
  1335. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1336. }
  1337. else
  1338. {
  1339. if(caster_value)
  1340. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1341. else
  1342. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1343. }
  1344. }
  1345. bool success = false;
  1346. luaspell->resisted = false;
  1347. if (target) {
  1348. float distance = caster->GetDistance(target, true);
  1349. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1350. success = true;
  1351. }
  1352. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1353. Spawn* target = 0;
  1354. ZoneServer* zone = luaspell->caster->GetZone();
  1355. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1356. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1357. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1358. float distance = caster->GetDistance(target, true);
  1359. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1360. }
  1361. }
  1362. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1363. success = true;
  1364. }
  1365. if (success) {
  1366. if (caster->GetZone())
  1367. caster->GetZone()->TriggerCharSheetTimer();
  1368. }
  1369. }
  1370. return 0;
  1371. }
  1372. int EQ2Emu_lua_AddItem(lua_State* state) {
  1373. if (!lua_interface)
  1374. return 0;
  1375. Spawn* spawn = lua_interface->GetSpawn(state);
  1376. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1377. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1378. lua_interface->ResetFunctionStack(state);
  1379. // default of 1 quantity to add
  1380. if (quantity == 0)
  1381. quantity = 1;
  1382. if (spawn && spawn->IsPlayer()) {
  1383. Client* client = ((Player*)spawn)->GetClient();
  1384. if (client && item_id > 0) {
  1385. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1386. return 1;
  1387. }
  1388. }
  1389. lua_interface->SetBooleanValue(state, false);
  1390. return 1;
  1391. }
  1392. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1393. if (!lua_interface)
  1394. return 0;
  1395. Spawn* spawn = lua_interface->GetSpawn(state);
  1396. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1397. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1398. string location = lua_interface->GetStringValue(state, 4);
  1399. int16 item_count = lua_interface->GetInt16Value(state,5);
  1400. //devn00b: if we dont have a count, assume 1 item.
  1401. if(!item_count) {
  1402. item_count = 1;
  1403. }
  1404. lua_interface->ResetFunctionStack(state);
  1405. if (spawn && spawn->IsPlayer()) {
  1406. Client* client = ((Player*)spawn)->GetClient();
  1407. if (client && item_id > 0) {
  1408. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1409. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1410. else
  1411. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1412. if (send_messages) {
  1413. Item* item = master_item_list.GetItem(item_id);
  1414. if (item) {
  1415. if(item_count > 1) {
  1416. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1417. string popup_text1 = "You receive "+ item_count;
  1418. string popup_text2 = " " + item->name;
  1419. string popup_text = popup_text1 + popup_text2;
  1420. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1421. // return 1;
  1422. } else {
  1423. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1424. string popup_text = "You receive " + item->name;
  1425. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1426. }
  1427. }
  1428. }
  1429. return 1;
  1430. }
  1431. }
  1432. lua_interface->SetBooleanValue(state, false);
  1433. return 1;
  1434. }
  1435. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1436. Spawn* spawn = lua_interface->GetSpawn(state);
  1437. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1438. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1439. lua_interface->ResetFunctionStack(state);
  1440. // default of 1 to remove
  1441. if (quantity == 0)
  1442. quantity = 1;
  1443. Client* client;
  1444. Item* item;
  1445. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1446. if ((client = ((Player*)spawn)->GetClient())) {
  1447. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1448. if (client->RemoveItem(item, quantity)) {
  1449. lua_interface->SetBooleanValue(state, true);
  1450. return 1;
  1451. }
  1452. }
  1453. }
  1454. }
  1455. lua_interface->SetBooleanValue(state, false);
  1456. return 1;
  1457. }
  1458. int EQ2Emu_lua_HasItem(lua_State* state) {
  1459. Spawn* player = lua_interface->GetSpawn(state);
  1460. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1461. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1462. lua_interface->ResetFunctionStack(state);
  1463. if (player && player->IsPlayer()) {
  1464. bool hasItem = false;
  1465. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1466. if (!hasItem)
  1467. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1468. lua_interface->SetBooleanValue(state, hasItem);
  1469. return 1;
  1470. }
  1471. lua_interface->SetBooleanValue(state, false);
  1472. return 1;
  1473. }
  1474. int EQ2Emu_lua_Spawn(lua_State* state) {
  1475. if (!lua_interface)
  1476. return 0;
  1477. ZoneServer* zone = lua_interface->GetZone(state);
  1478. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1479. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1480. float x = lua_interface->GetFloatValue(state, 4);
  1481. float y = lua_interface->GetFloatValue(state, 5);
  1482. float z = lua_interface->GetFloatValue(state, 6);
  1483. float heading = lua_interface->GetFloatValue(state, 7);
  1484. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1485. Spawn* spawn = zone->GetSpawn(spawn_id);
  1486. if (!spawn)
  1487. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1488. else {
  1489. spawn->SetX(x);
  1490. spawn->SetZ(z);
  1491. spawn->SetY(y,true,true);
  1492. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1493. spawn->SetHeading(heading);
  1494. if (restricted_npc)
  1495. spawn->AddAllowAccessSpawn(spawn);
  1496. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1497. bool scriptActive = false;
  1498. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1499. scriptActive = true;
  1500. spawn->SetSpawnScript(string(spawn_script));
  1501. }
  1502. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1503. zone->AddSpawn(spawn);
  1504. if (scriptActive) {
  1505. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1506. }
  1507. lua_interface->ResetFunctionStack(state);
  1508. lua_interface->SetSpawnValue(state, spawn);
  1509. return 1;
  1510. }
  1511. }
  1512. else {
  1513. string output = "Invalid paramaters to LUA Spawn command: \n";
  1514. if (!zone)
  1515. output = output.append("\t").append("Missing zone reference. \n");
  1516. if (spawn_id == 0)
  1517. output = output.append("\t").append("Missing spawn_id.");
  1518. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1519. }
  1520. lua_interface->ResetFunctionStack(state);
  1521. return 0;
  1522. }
  1523. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1524. if (!lua_interface)
  1525. return 0;
  1526. ZoneServer* zone = lua_interface->GetZone(state);
  1527. lua_interface->ResetFunctionStack(state);
  1528. if (zone) {
  1529. lua_interface->SetStringValue(state, zone->GetZoneName());
  1530. return 1;
  1531. }
  1532. return 0;
  1533. }
  1534. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1535. if (!lua_interface)
  1536. return 0;
  1537. ZoneServer* zone = lua_interface->GetZone(state);
  1538. lua_interface->ResetFunctionStack(state);
  1539. if (zone) {
  1540. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1541. return 1;
  1542. }
  1543. return 0;
  1544. }
  1545. int EQ2Emu_lua_GetZone(lua_State* state) {
  1546. if (!lua_interface)
  1547. return 0;
  1548. int32 zone_id = lua_interface->GetInt32Value(state);
  1549. ZoneServer* zone = 0;
  1550. if (zone_id > 0)
  1551. zone = zone_list.Get(zone_id);
  1552. else {
  1553. string zone_name = lua_interface->GetStringValue(state);
  1554. if (zone_name.length() > 0) {
  1555. zone = zone_list.Get(zone_name.c_str());
  1556. }
  1557. else {
  1558. Spawn* spawn = lua_interface->GetSpawn(state);
  1559. if (spawn)
  1560. zone = spawn->GetZone();
  1561. }
  1562. }
  1563. lua_interface->ResetFunctionStack(state);
  1564. if (zone) {
  1565. lua_interface->SetZoneValue(state, zone);
  1566. return 1;
  1567. }
  1568. return 0;
  1569. }
  1570. int EQ2Emu_lua_AddHate(lua_State* state) {
  1571. Spawn* entity = lua_interface->GetSpawn(state);
  1572. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1573. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1574. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1575. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1576. if(!luaspell || luaspell->resisted) {
  1577. return 0;
  1578. }
  1579. if (entity && entity->IsEntity() && amount != 0) {
  1580. if (luaspell) {
  1581. ZoneServer* zone = luaspell->caster->GetZone();
  1582. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1583. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1584. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1585. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1586. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1587. if (send_packet)
  1588. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1589. }
  1590. }
  1591. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1592. }
  1593. else if (npc && npc->IsNPC() && npc->GetZone())
  1594. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1595. }
  1596. lua_interface->ResetFunctionStack(state);
  1597. return 0;
  1598. }
  1599. int EQ2Emu_lua_Zone(lua_State* state) {
  1600. if (!lua_interface)
  1601. return 0;
  1602. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1603. ZoneServer* zone = lua_interface->GetZone(state);
  1604. Spawn* player = lua_interface->GetSpawn(state, 2);
  1605. Client* client = 0;
  1606. if (player && player->IsPlayer())
  1607. client = ((Player*)player)->GetClient();
  1608. float x = lua_interface->GetFloatValue(state, 3);
  1609. float y = lua_interface->GetFloatValue(state, 4);
  1610. float z = lua_interface->GetFloatValue(state, 5);
  1611. float heading = lua_interface->GetFloatValue(state, 6);
  1612. if (zone && client) {
  1613. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1614. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1615. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1616. {
  1617. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1618. return 0;
  1619. }
  1620. if (x != 0 || y != 0 || z != 0) {
  1621. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1622. player->SetX(x);
  1623. player->SetY(y);
  1624. player->SetZ(z);
  1625. player->SetHeading(heading);
  1626. client->Zone(zone->GetZoneName(), false);
  1627. }
  1628. else
  1629. client->Zone(zone->GetZoneName());
  1630. }
  1631. else
  1632. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1633. lua_interface->ResetFunctionStack(state);
  1634. return 0;
  1635. }
  1636. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1637. if (!lua_interface)
  1638. return 0;
  1639. Spawn* spawn = lua_interface->GetSpawn(state);
  1640. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1641. if (spawn && spawn2)
  1642. spawn->AddAllowAccessSpawn(spawn2);
  1643. lua_interface->ResetFunctionStack(state);
  1644. return 0;
  1645. }
  1646. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1647. if (!lua_interface)
  1648. return 0;
  1649. Spawn* target = lua_interface->GetSpawn(state);
  1650. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1651. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1652. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1653. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1654. lua_interface->ResetFunctionStack(state);
  1655. if (!target) {
  1656. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1657. return 0;
  1658. }
  1659. if (!target->IsEntity()) {
  1660. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1661. return 0;
  1662. }
  1663. if (spell_id <= 0) {
  1664. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1665. return 0;
  1666. }
  1667. if (caster && !caster->IsEntity()) {
  1668. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1669. return 0;
  1670. }
  1671. if (spell_tier == 0)
  1672. spell_tier = 1;
  1673. if (!caster)
  1674. caster = target;
  1675. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1676. return 0;
  1677. }
  1678. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1679. if (!lua_interface)
  1680. return 0;
  1681. Spawn* target = lua_interface->GetSpawn(state);
  1682. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1683. if(!luaspell || luaspell->resisted) {
  1684. return 0;
  1685. }
  1686. Spawn* caster = luaspell->caster;
  1687. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1688. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1689. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1690. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1691. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1692. //lua_interface->ResetFunctionStack(state);
  1693. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1694. vector<int16> faction_req;
  1695. vector<int16> race_req;
  1696. int32 class_req = 0;
  1697. int32 i = 0;
  1698. int8 f = 0;
  1699. int8 r = 0;
  1700. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1701. if (class_id < 100) {
  1702. class_req += pow(2.0, double(class_id - 1));
  1703. }
  1704. else if (class_id > 100 && class_id < 1000) {
  1705. race_req.push_back(class_id);
  1706. r++;
  1707. }
  1708. else {
  1709. faction_req.push_back(class_id);
  1710. f++;
  1711. }
  1712. i++;
  1713. }
  1714. lua_interface->ResetFunctionStack(state);
  1715. if (caster && caster->IsEntity()) {
  1716. bool race_match = false;
  1717. bool success = false;
  1718. luaspell->resisted = false;
  1719. if (luaspell->targets.size() > 0) {
  1720. ZoneServer* zone = luaspell->caster->GetZone();
  1721. Spawn* target = 0;
  1722. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1723. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1724. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1725. if (race_req.size() > 0) {
  1726. for (int8 i = 0; i < race_req.size(); i++) {
  1727. if(race_req[i] == target->GetRace() ||
  1728. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1729. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1730. race_match = true;
  1731. }
  1732. }
  1733. }
  1734. else
  1735. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1736. if (race_match == true) {
  1737. float distance = caster->GetDistance(target, true);
  1738. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1739. }
  1740. }
  1741. }
  1742. success = true;
  1743. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1744. }
  1745. else if (target) {
  1746. //check class and race/faction here
  1747. if (race_req.size() > 0) {
  1748. for (int8 i = 0; i < race_req.size(); i++) {
  1749. if(race_req[i] == target->GetRace() ||
  1750. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1751. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1752. race_match = true;
  1753. }
  1754. }
  1755. }
  1756. else
  1757. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1758. if (race_match == true) {
  1759. float distance = caster->GetDistance(target, true);
  1760. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1761. success = true;
  1762. }
  1763. }
  1764. if (success) {
  1765. Spell* spell = luaspell->spell;
  1766. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1767. ((Player*)caster)->InCombat(true);
  1768. if (caster->GetZone())
  1769. caster->GetZone()->TriggerCharSheetTimer();
  1770. }
  1771. }
  1772. }
  1773. return 0;
  1774. }
  1775. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1776. if (!lua_interface)
  1777. return 0;
  1778. Spawn* spawn = lua_interface->GetSpawn(state);
  1779. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1780. lua_interface->ResetFunctionStack(state);
  1781. if (spawn && value != 0) {
  1782. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1783. spawn->SetPower(spawn->GetTotalPower());
  1784. else
  1785. spawn->SetPower(spawn->GetPower() + value);
  1786. }
  1787. return 0;
  1788. }
  1789. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1790. if (!lua_interface)
  1791. return 0;
  1792. Spawn* spawn = lua_interface->GetSpawn(state);
  1793. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1794. lua_interface->ResetFunctionStack(state);
  1795. if (spawn && value != 0) {
  1796. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1797. spawn->SetHP(spawn->GetTotalHP());
  1798. else
  1799. spawn->SetHP(spawn->GetHP() + value);
  1800. }
  1801. return 0;
  1802. }
  1803. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1804. if (!lua_interface)
  1805. return 0;
  1806. Spawn* spawn = lua_interface->GetSpawn(state);
  1807. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1808. lua_interface->ResetFunctionStack(state);
  1809. if (spawn && value != 0) {
  1810. spawn->SetPower(spawn->GetPower() + value);
  1811. if (value > spawn->GetTotalHPBase())
  1812. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1813. }
  1814. return 0;
  1815. }
  1816. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1817. if (!lua_interface)
  1818. return 0;
  1819. Spawn* spawn = lua_interface->GetSpawn(state);
  1820. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1821. lua_interface->ResetFunctionStack(state);
  1822. if (spawn && value != 0) {
  1823. spawn->SetHP(spawn->GetHP() + value);
  1824. if (value > spawn->GetTotalHPBase())
  1825. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1826. }
  1827. return 0;
  1828. }
  1829. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1830. if (!lua_interface)
  1831. return 0;
  1832. Spawn* spawn = lua_interface->GetSpawn(state);
  1833. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1834. lua_interface->ResetFunctionStack(state);
  1835. if (spawn) {
  1836. spawn->SetHP(value);
  1837. if (value > spawn->GetTotalHPBase())
  1838. spawn->SetTotalHP(value);
  1839. }
  1840. return 0;
  1841. }
  1842. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1843. if (!lua_interface)
  1844. return 0;
  1845. Spawn* spawn = lua_interface->GetSpawn(state);
  1846. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1847. float value = lua_interface->GetFloatValue(state, 2);
  1848. lua_interface->ResetFunctionStack(state);
  1849. if (spawn && spawn->IsEntity() && value > 0)
  1850. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1851. if (spawn && spawn->IsPlayer())
  1852. ((Player*)spawn)->SetCharSheetChanged(true);
  1853. return 0;
  1854. }
  1855. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1856. if (!lua_interface)
  1857. return 0;
  1858. Spawn* spawn = lua_interface->GetSpawn(state);
  1859. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1860. lua_interface->ResetFunctionStack(state);
  1861. if (spawn && spawn->IsEntity() && value > 0)
  1862. ((Entity*)spawn)->SetTotalHPBase(value);
  1863. return 0;
  1864. }
  1865. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1866. if (!lua_interface)
  1867. return 0;
  1868. Spawn* spawn = lua_interface->GetSpawn(state);
  1869. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1870. lua_interface->ResetFunctionStack(state);
  1871. if (spawn && value > 0) {
  1872. spawn->SetPower(value);
  1873. if (value > spawn->GetTotalPowerBase())
  1874. spawn->SetTotalPower(value);
  1875. }
  1876. return 0;
  1877. }
  1878. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1879. if (!lua_interface)
  1880. return 0;
  1881. Spawn* spawn = lua_interface->GetSpawn(state);
  1882. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1883. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1884. lua_interface->ResetFunctionStack(state);
  1885. if (spawn && spawn->IsEntity() && value > 0)
  1886. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1887. return 0;
  1888. }
  1889. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1890. if (!lua_interface)
  1891. return 0;
  1892. Spawn* spawn = lua_interface->GetSpawn(state);
  1893. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1894. lua_interface->ResetFunctionStack(state);
  1895. if (spawn && spawn->IsEntity() && value > 0)
  1896. ((Entity*)spawn)->SetTotalPowerBase(value);
  1897. return 0;
  1898. }
  1899. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1900. if (!lua_interface)
  1901. return 0;
  1902. Spawn* spawn = lua_interface->GetSpawn(state);
  1903. float x = lua_interface->GetFloatValue(state, 2);
  1904. float y = lua_interface->GetFloatValue(state, 3);
  1905. float z = lua_interface->GetFloatValue(state, 4);
  1906. float heading = lua_interface->GetFloatValue(state, 5);
  1907. lua_interface->ResetFunctionStack(state);
  1908. if (spawn) {
  1909. spawn->SetX(x);
  1910. spawn->SetY(y);
  1911. spawn->SetZ(z);
  1912. if (heading != 0)
  1913. spawn->SetHeading(heading);
  1914. spawn->SetSpawnOrigX(spawn->GetX());
  1915. spawn->SetSpawnOrigY(spawn->GetY());
  1916. spawn->SetSpawnOrigZ(spawn->GetZ());
  1917. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1918. if (spawn->IsPlayer()) {
  1919. Client* client = ((Player*)spawn)->GetClient();
  1920. if (client) {
  1921. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1922. client->QueuePacket(packet);
  1923. }
  1924. }
  1925. }
  1926. return 0;
  1927. }
  1928. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1929. if (!lua_interface)
  1930. return 0;
  1931. Spawn* spawn = lua_interface->GetSpawn(state);
  1932. float value = lua_interface->GetFloatValue(state, 2);
  1933. lua_interface->ResetFunctionStack(state);
  1934. if (spawn) {
  1935. spawn->SetHeading(value);
  1936. if (spawn->IsPlayer()) {
  1937. Client* client = ((Player*)spawn)->GetClient();
  1938. if (client) {
  1939. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1940. client->QueuePacket(packet);
  1941. }
  1942. }
  1943. }
  1944. return 0;
  1945. }
  1946. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1947. if (!lua_interface)
  1948. return 0;
  1949. Spawn* spawn = lua_interface->GetSpawn(state);
  1950. int16 value = lua_interface->GetInt16Value(state, 2);
  1951. lua_interface->ResetFunctionStack(state);
  1952. if (spawn)
  1953. spawn->SetModelType(value);
  1954. return 0;
  1955. }
  1956. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1957. if (!lua_interface)
  1958. return 0;
  1959. Spawn* spawn = lua_interface->GetSpawn(state);
  1960. int8 value = lua_interface->GetInt8Value(state, 2);
  1961. lua_interface->ResetFunctionStack(state);
  1962. if (spawn) {
  1963. if (spawn->IsPlayer())
  1964. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1965. else
  1966. spawn->SetAdventureClass(value);
  1967. }
  1968. return 0;
  1969. }
  1970. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1971. if (!lua_interface)
  1972. return 0;
  1973. Spawn* spawn = lua_interface->GetSpawn(state);
  1974. int8 value = lua_interface->GetInt8Value(state, 2);
  1975. lua_interface->ResetFunctionStack(state);
  1976. if (spawn) {
  1977. spawn->SetTradeskillClass(value);
  1978. if (spawn->IsEntity()) {
  1979. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1980. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1981. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1982. }
  1983. if (spawn->IsPlayer())
  1984. ((Player*)spawn)->SetCharSheetChanged(true);
  1985. }
  1986. return 0;
  1987. }
  1988. int EQ2Emu_lua_SetMount(lua_State* state) {
  1989. if (!lua_interface)
  1990. return 0;
  1991. Spawn* spawn = lua_interface->GetSpawn(state);
  1992. int16 value = lua_interface->GetInt16Value(state, 2);
  1993. if (spawn && spawn->IsEntity()) {
  1994. ((Entity*)spawn)->SetMount(value);
  1995. EQ2_Color color;
  1996. color.red = 255;
  1997. color.green = 255;
  1998. color.blue = 255;
  1999. ((Entity*)spawn)->SetMountColor(&color);
  2000. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2001. }
  2002. return 0;
  2003. }
  2004. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2005. if (!lua_interface)
  2006. return 0;
  2007. Spawn* spawn = lua_interface->GetSpawn(state);
  2008. EQ2_Color mount_color;
  2009. EQ2_Color saddle_color;
  2010. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2011. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2012. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2013. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2014. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2015. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2016. if (spawn && spawn->IsEntity()) {
  2017. ((Entity*)spawn)->SetMountColor(&mount_color);
  2018. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2019. }
  2020. return 0;
  2021. }
  2022. int EQ2Emu_lua_GetMount(lua_State* state) {
  2023. if (!lua_interface)
  2024. return 0;
  2025. Spawn* spawn = lua_interface->GetSpawn(state);
  2026. if (spawn && spawn->IsEntity()) {
  2027. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2028. return 1;
  2029. }
  2030. return 0;
  2031. }
  2032. int EQ2Emu_lua_GetRace(lua_State* state) {
  2033. if (!lua_interface)
  2034. return 0;
  2035. Spawn* spawn = lua_interface->GetSpawn(state);
  2036. if (spawn)
  2037. {
  2038. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2039. lua_interface->SetInt32Value(state, spawn->GetRace());
  2040. return 1;
  2041. }
  2042. return 0;
  2043. }
  2044. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2045. if (!lua_interface)
  2046. return 0;
  2047. Spawn* spawn = lua_interface->GetSpawn(state);
  2048. if (spawn) {
  2049. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2050. return 1;
  2051. }
  2052. return 0;
  2053. }
  2054. int EQ2Emu_lua_GetClass(lua_State* state) {
  2055. Spawn* spawn = lua_interface->GetSpawn(state);
  2056. if (spawn) {
  2057. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2058. return 1;
  2059. }
  2060. return 0;
  2061. }
  2062. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2063. Spawn* spawn = lua_interface->GetSpawn(state);
  2064. if (spawn) {
  2065. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2066. return 1;
  2067. }
  2068. return 0;
  2069. }
  2070. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2071. if (!lua_interface)
  2072. return 0;
  2073. Spawn* spawn = lua_interface->GetSpawn(state);
  2074. float value = lua_interface->GetFloatValue(state, 2);
  2075. lua_interface->ResetFunctionStack(state);
  2076. if (spawn) {
  2077. spawn->SetSpeed(value);
  2078. if(spawn->IsEntity())
  2079. ((Entity*)spawn)->SetSpeed(value);
  2080. if (spawn->IsPlayer()) {
  2081. Client* client = ((Player*)spawn)->GetClient();
  2082. if (client) {
  2083. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2084. if (packet) {
  2085. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2086. packet->setDataByName("speed", value);
  2087. packet->setDataByName("size", 0.51);
  2088. EQ2Packet* app = packet->serialize();
  2089. client->QueuePacket(app);
  2090. safe_delete(packet);
  2091. }
  2092. }
  2093. }
  2094. }
  2095. return 0;
  2096. }
  2097. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2098. if (!lua_interface)
  2099. return 0;
  2100. Spawn* spawn = lua_interface->GetSpawn(state);
  2101. const int16 type = lua_interface->GetInt16Value(state, 2);
  2102. const float value = lua_interface->GetFloatValue(state, 3);
  2103. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2104. if(!luaspell || luaspell->resisted) {
  2105. return 0;
  2106. }
  2107. int64 class_req = 0;
  2108. int32 class_id = 0;
  2109. vector<int16> faction_req;
  2110. vector<int16> race_req;
  2111. int32 i = 0;
  2112. int8 f = 0;
  2113. int8 r = 0;
  2114. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2115. if (class_id < 100) {
  2116. class_req += pow(2.0, double(class_id - 1));
  2117. }
  2118. else if (class_id > 100 && class_id < 1000) {
  2119. race_req.push_back(class_id);
  2120. r++;
  2121. }
  2122. else {
  2123. faction_req.push_back(class_id);
  2124. f++;
  2125. }
  2126. i++;
  2127. }
  2128. if (value != 0 && type >= 0) {
  2129. if (luaspell && luaspell->spell && luaspell->caster) {
  2130. ZoneServer* zone = luaspell->caster->GetZone();
  2131. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2132. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2133. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2134. if (target) {
  2135. if (target->IsPlayer()) {
  2136. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2137. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2138. if (((Player*)target)->GetGroupMemberInfo())
  2139. ((Player*)target)->UpdateGroupMemberInfo();
  2140. ((Player*)target)->SetCharSheetChanged(true);
  2141. }
  2142. else if (target->IsNPC())
  2143. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2144. else
  2145. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2146. }
  2147. }
  2148. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2149. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2150. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2151. }
  2152. else if (spawn && spawn->IsEntity()) {
  2153. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2154. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2155. if (spawn->IsPlayer())
  2156. ((Player*)spawn)->SetCharSheetChanged(true);
  2157. }
  2158. else
  2159. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2160. }
  2161. else
  2162. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2163. return 0;
  2164. }
  2165. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2166. if (!lua_interface)
  2167. return 0;
  2168. Spawn* spawn = lua_interface->GetSpawn(state);
  2169. int16 type = lua_interface->GetInt16Value(state, 2);
  2170. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2171. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2172. if (!spawn) {
  2173. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2174. return 0;
  2175. }
  2176. if (!spawn->IsEntity()) {
  2177. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2178. return 0;
  2179. }
  2180. if (value == 0) {
  2181. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2182. return 0;
  2183. }
  2184. if (!luaspell || !luaspell->spell) {
  2185. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2186. return 0;
  2187. }
  2188. if(luaspell->resisted) {
  2189. return 0;
  2190. }
  2191. int32 class_req = 0;
  2192. vector<int16> faction_req;
  2193. vector<int16> race_req;
  2194. int32 class_id = 0;
  2195. int32 i = 0;
  2196. int8 f = 0;
  2197. int8 r = 0;
  2198. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2199. if (class_id < 100) {
  2200. class_req += pow(2.0, double(class_id - 1));
  2201. }
  2202. else if (class_id > 100 && class_id < 1000) {
  2203. race_req.push_back(class_id);
  2204. r++;
  2205. }
  2206. else {
  2207. faction_req.push_back(class_id);
  2208. f++;
  2209. }
  2210. i++;
  2211. }
  2212. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2213. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2214. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2215. if (spawn->IsPlayer())
  2216. ((Player*)spawn)->SetCharSheetChanged(true);
  2217. return 0;
  2218. }
  2219. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2220. if (!lua_interface)
  2221. return 0;
  2222. Spawn* spawn = lua_interface->GetSpawn(state);
  2223. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2224. if (!spawn) {
  2225. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2226. return 0;
  2227. }
  2228. if (!spawn->IsEntity()) {
  2229. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2230. return 0;
  2231. }
  2232. if (!luaspell || !luaspell->spell) {
  2233. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2234. return 0;
  2235. }
  2236. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2237. if (spawn->IsPlayer())
  2238. ((Player*)spawn)->SetCharSheetChanged(true);
  2239. return 0;
  2240. }
  2241. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2242. if (!lua_interface)
  2243. return 0;
  2244. Spawn* spawn = lua_interface->GetSpawn(state);
  2245. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2246. if (luaspell && luaspell->spell) {
  2247. ZoneServer* zone = luaspell->caster->GetZone();
  2248. Spawn* target = 0;
  2249. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2250. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2251. target = zone->GetSpawnByID(luaspell->targets[i]);
  2252. if (target && target->IsEntity()) {
  2253. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2254. if (target->IsPlayer())
  2255. ((Player*)target)->SetCharSheetChanged(true);
  2256. }
  2257. }
  2258. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2259. }
  2260. else if (spawn && spawn->IsEntity()) {
  2261. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2262. if (spawn->IsPlayer())
  2263. ((Player*)spawn)->SetCharSheetChanged(true);
  2264. }
  2265. return 0;
  2266. }
  2267. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2268. if (!lua_interface)
  2269. return 0;
  2270. Spawn* spawn = lua_interface->GetSpawn(state);
  2271. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2272. float value = lua_interface->GetFloatValue(state, 3);
  2273. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2274. if (value != 0) {
  2275. int32 spell_id = 0;
  2276. if (luaspell && luaspell->spell && luaspell->caster) {
  2277. if(luaspell->resisted) {
  2278. return 0;
  2279. }
  2280. spell_id = luaspell->spell->GetSpellID();
  2281. ZoneServer* zone = luaspell->caster->GetZone();
  2282. Spawn* target = 0;
  2283. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2284. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2285. target = zone->GetSpawnByID(luaspell->targets[i]);
  2286. if (target && target->Alive()) {
  2287. if (target->IsPlayer()) {
  2288. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2289. Client* client = ((Player*)target)->GetClient();
  2290. if (client) {
  2291. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2292. if (packet)
  2293. client->QueuePacket(packet);
  2294. }
  2295. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2296. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2297. }
  2298. else if (target->IsNPC()) {
  2299. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2300. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2301. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2302. }
  2303. else
  2304. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2305. }
  2306. }
  2307. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2308. }
  2309. else if (spawn) {
  2310. if (spawn->IsPlayer()) {
  2311. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2312. Client* client = ((Player*)spawn)->GetClient();
  2313. if (client) {
  2314. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2315. if (packet)
  2316. client->QueuePacket(packet);
  2317. }
  2318. }
  2319. else if (spawn->IsNPC())
  2320. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2321. else
  2322. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2323. }
  2324. }
  2325. else
  2326. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2327. return 0;
  2328. }
  2329. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2330. if (!lua_interface)
  2331. return 0;
  2332. Spawn* spawn = lua_interface->GetSpawn(state);
  2333. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2334. if (spawn && spawn->IsPlayer()) {
  2335. int32 spell_id = 0;
  2336. if (luaspell && luaspell->spell) {
  2337. if(luaspell->resisted) {
  2338. return 0;
  2339. }
  2340. spell_id = luaspell->spell->GetSpellID();
  2341. ZoneServer* zone = luaspell->caster->GetZone();
  2342. Spawn* target = 0;
  2343. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2344. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2345. target = zone->GetSpawnByID(luaspell->targets[i]);
  2346. if (target) {
  2347. if (target->IsPlayer()) {
  2348. ((Player*)target)->RemoveSkillBonus(spell_id);
  2349. Client* client = ((Player*)target)->GetClient();
  2350. if (client) {
  2351. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2352. if (packet)
  2353. client->QueuePacket(packet);
  2354. }
  2355. }
  2356. else if (target->IsNPC())
  2357. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2358. else
  2359. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2360. }
  2361. }
  2362. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2363. }
  2364. else if (spawn) {
  2365. if (spawn->IsPlayer()) {
  2366. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2367. Client* client = ((Player*)spawn)->GetClient();
  2368. if (client) {
  2369. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2370. if (packet)
  2371. client->QueuePacket(packet);
  2372. }
  2373. }
  2374. else if (spawn->IsNPC())
  2375. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2376. else
  2377. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2378. }
  2379. }
  2380. return 0;
  2381. }
  2382. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2383. if (!lua_interface)
  2384. return 0;
  2385. Spawn* spawn = lua_interface->GetSpawn(state);
  2386. int8 type = lua_interface->GetInt32Value(state, 2);
  2387. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2388. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2389. if(luaspell && luaspell->resisted) {
  2390. return 0;
  2391. }
  2392. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2393. ZoneServer* zone = luaspell->caster->GetZone();
  2394. Spawn* target = 0;
  2395. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2396. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2397. target = zone->GetSpawnByID(luaspell->targets[i]);
  2398. if (target && target->IsEntity()) {
  2399. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2400. ((Entity*)target)->AddMezSpell(luaspell);
  2401. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2402. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2403. if (target->IsNPC())
  2404. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2405. }
  2406. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2407. ((Entity*)target)->AddStifleSpell(luaspell);
  2408. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2409. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2410. if (target->IsNPC())
  2411. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2412. }
  2413. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2414. ((Entity*)target)->AddDazeSpell(luaspell);
  2415. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2416. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2417. if (target->IsNPC())
  2418. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2419. }
  2420. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2421. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2422. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2423. ((Entity*)target)->AddStunSpell(luaspell);
  2424. if (target->IsNPC())
  2425. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2426. }
  2427. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2428. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2429. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2430. ((Entity*)target)->AddRootSpell(luaspell);
  2431. if (target->IsNPC())
  2432. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2433. }
  2434. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2435. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2436. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2437. ((Entity*)target)->AddFearSpell(luaspell);
  2438. if (target->IsNPC())
  2439. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2440. }
  2441. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2442. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2443. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2444. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2445. }
  2446. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2447. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2448. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2449. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2450. }
  2451. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2452. ((Entity*)target)->AddSnareSpell(luaspell);
  2453. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2454. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2455. if (target->IsNPC())
  2456. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2457. }
  2458. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2459. ((Entity*)target)->AddFlightSpell(luaspell);
  2460. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2461. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2462. }
  2463. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2464. ((Entity*)target)->AddGlideSpell(luaspell);
  2465. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2466. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2467. }
  2468. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2469. ((Entity*)target)->AddSafefallSpell(luaspell);
  2470. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2471. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2472. }
  2473. else
  2474. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2475. }
  2476. else
  2477. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2478. }
  2479. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2480. }
  2481. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2482. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2483. ((Entity*)spawn)->AddMezSpell(luaspell);
  2484. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2485. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2486. }
  2487. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2488. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2489. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2490. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2491. }
  2492. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2493. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2494. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2495. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2496. }
  2497. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2498. ((Entity*)spawn)->AddStunSpell(luaspell);
  2499. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2500. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2501. }
  2502. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2503. ((Entity*)spawn)->AddRootSpell(luaspell);
  2504. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2505. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2506. }
  2507. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2508. ((Entity*)spawn)->AddFearSpell(luaspell);
  2509. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2510. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2511. }
  2512. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2513. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2514. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2515. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2516. }
  2517. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2518. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2519. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2520. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2521. }
  2522. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2523. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2524. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2525. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2526. }
  2527. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2528. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2529. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2530. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2531. }
  2532. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2533. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2534. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2535. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2536. }
  2537. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2538. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2539. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2540. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2541. }
  2542. else
  2543. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2544. }
  2545. else
  2546. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2547. return 0;
  2548. }
  2549. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2550. if (!lua_interface)
  2551. return 0;
  2552. Spawn* spawn = lua_interface->GetSpawn(state);
  2553. int8 type = lua_interface->GetInt8Value(state, 2);
  2554. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2555. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2556. if (spawn && spawn->IsEntity()) {
  2557. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2558. ZoneServer* zone = luaspell->caster->GetZone();
  2559. Spawn* target = 0;
  2560. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2561. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2562. target = zone->GetSpawnByID(luaspell->targets[i]);
  2563. if (target) {
  2564. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2565. ((Entity*)target)->RemoveMezSpell(luaspell);
  2566. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2567. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2568. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2569. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2570. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2571. ((Entity*)target)->RemoveStunSpell(luaspell);
  2572. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2573. ((Entity*)target)->RemoveRootSpell(luaspell);
  2574. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2575. ((Entity*)target)->RemoveFearSpell(luaspell);
  2576. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2577. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2579. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2581. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2583. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2584. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2585. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2586. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2587. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2588. else
  2589. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2590. }
  2591. }
  2592. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2593. }
  2594. else if (only_remove_spawn) {
  2595. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2596. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2597. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2598. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2599. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2600. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2601. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2602. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2603. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2604. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2605. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2606. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2607. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2608. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2609. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2610. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2611. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2612. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2613. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2614. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2615. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2616. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2617. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2618. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2619. else
  2620. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2621. }
  2622. }
  2623. return 0;
  2624. }
  2625. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2626. if (!lua_interface)
  2627. return 0;
  2628. Spawn* spawn = lua_interface->GetSpawn(state);
  2629. int8 type = lua_interface->GetInt8Value(state, 2);
  2630. bool hasEffect = false;
  2631. if (!spawn)
  2632. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2633. else if (!spawn->IsEntity())
  2634. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2635. else if (type < CONTROL_MAX_EFFECTS)
  2636. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2637. else
  2638. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2639. lua_interface->SetBooleanValue(state, hasEffect);
  2640. return 1;
  2641. }
  2642. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2643. if (!lua_interface)
  2644. return 0;
  2645. Spawn* spawn = lua_interface->GetSpawn(state);
  2646. float distance = 0.0f;
  2647. if (!spawn)
  2648. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2649. else if (!spawn->IsNPC())
  2650. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2651. else
  2652. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2653. lua_interface->SetFloatValue(state, distance);
  2654. return 1;
  2655. }
  2656. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2657. if (!lua_interface)
  2658. return 0;
  2659. Spawn* spawn = lua_interface->GetSpawn(state);
  2660. float distance = 0.0f;
  2661. if (!spawn)
  2662. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2663. else if (!spawn->IsNPC())
  2664. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2665. else
  2666. distance = ((NPC*)spawn)->GetAggroRadius();
  2667. lua_interface->SetFloatValue(state, distance);
  2668. return 1;
  2669. }
  2670. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2671. if (!lua_interface)
  2672. return 0;
  2673. Spawn* spawn = lua_interface->GetSpawn(state);
  2674. float distance = lua_interface->GetFloatValue(state, 2);
  2675. bool override = lua_interface->GetBooleanValue(state, 3);
  2676. bool result = false;
  2677. lua_interface->ResetFunctionStack(state);
  2678. if (!spawn)
  2679. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2680. else if (!spawn->IsNPC())
  2681. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2682. else
  2683. {
  2684. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2685. result = true;
  2686. }
  2687. lua_interface->SetBooleanValue(state, result);
  2688. return 1;
  2689. }
  2690. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2691. if (!lua_interface)
  2692. return 0;
  2693. Spawn* spawn = lua_interface->GetSpawn(state);
  2694. int16 value = lua_interface->GetInt16Value(state, 2);
  2695. if (spawn && spawn->IsEntity()) {
  2696. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2697. if (spawn->IsPlayer())
  2698. ((Player*)spawn)->SetCharSheetChanged(true);
  2699. }
  2700. return 0;
  2701. }
  2702. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2703. if (!lua_interface)
  2704. return 0;
  2705. Spawn* spawn = lua_interface->GetSpawn(state);
  2706. int16 value = lua_interface->GetInt16Value(state, 2);
  2707. if (spawn && spawn->IsEntity()) {
  2708. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2709. if (spawn->IsPlayer())
  2710. ((Player*)spawn)->SetCharSheetChanged(true);
  2711. }
  2712. return 0;
  2713. }
  2714. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2715. if (!lua_interface)
  2716. return 0;
  2717. Spawn* spawn = lua_interface->GetSpawn(state);
  2718. int16 value = lua_interface->GetInt16Value(state, 2);
  2719. if (spawn && spawn->IsEntity()) {
  2720. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2721. if (spawn->IsPlayer())
  2722. ((Player*)spawn)->SetCharSheetChanged(true);
  2723. }
  2724. return 0;
  2725. }
  2726. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2727. if (!lua_interface)
  2728. return 0;
  2729. Spawn* spawn = lua_interface->GetSpawn(state);
  2730. int16 value = lua_interface->GetInt16Value(state, 2);
  2731. if (spawn && spawn->IsEntity()) {
  2732. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2733. if (spawn->IsPlayer())
  2734. ((Player*)spawn)->SetCharSheetChanged(true);
  2735. }
  2736. return 0;
  2737. }
  2738. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2739. if (!lua_interface)
  2740. return 0;
  2741. Spawn* spawn = lua_interface->GetSpawn(state);
  2742. int16 value = lua_interface->GetInt16Value(state, 2);
  2743. if (spawn && spawn->IsEntity()) {
  2744. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2745. if (spawn->IsPlayer())
  2746. ((Player*)spawn)->SetCharSheetChanged(true);
  2747. }
  2748. return 0;
  2749. }
  2750. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2751. if (!lua_interface)
  2752. return 0;
  2753. Spawn* spawn = lua_interface->GetSpawn(state);
  2754. int8 value = lua_interface->GetInt8Value(state, 2);
  2755. if (spawn && spawn->IsEntity()) {
  2756. ((Entity*)spawn)->SetDeity(value);
  2757. if (spawn->IsPlayer())
  2758. ((Player*)spawn)->SetCharSheetChanged(true);
  2759. }
  2760. lua_interface->ResetFunctionStack(state);
  2761. return 0;
  2762. }
  2763. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2764. if (!lua_interface)
  2765. return 0;
  2766. Spawn* spawn = lua_interface->GetSpawn(state);
  2767. if (spawn && spawn->IsEntity()) {
  2768. int8 deity = ((Entity*)spawn)->GetDeity();
  2769. lua_interface->SetInt32Value(state, deity);
  2770. return 1;
  2771. }
  2772. return 0;
  2773. }
  2774. int EQ2Emu_lua_SetInt(lua_State* state) {
  2775. if (!lua_interface)
  2776. return 0;
  2777. Spawn* spawn = lua_interface->GetSpawn(state);
  2778. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2779. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2780. if (spawn && spawn->IsEntity()) {
  2781. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2782. if (spawn->IsPlayer())
  2783. ((Player*)spawn)->SetCharSheetChanged(true);
  2784. }
  2785. return 0;
  2786. }
  2787. int EQ2Emu_lua_SetWis(lua_State* state) {
  2788. if (!lua_interface)
  2789. return 0;
  2790. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2791. Spawn* spawn = lua_interface->GetSpawn(state);
  2792. float value = lua_interface->GetFloatValue(state, 2);
  2793. if (spawn && spawn->IsEntity()) {
  2794. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2795. if (spawn->IsPlayer())
  2796. ((Player*)spawn)->SetCharSheetChanged(true);
  2797. }
  2798. return 0;
  2799. }
  2800. int EQ2Emu_lua_SetSta(lua_State* state) {
  2801. if (!lua_interface)
  2802. return 0;
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. float value = lua_interface->GetFloatValue(state, 2);
  2805. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2806. if (spawn && spawn->IsEntity()) {
  2807. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2808. if (spawn->IsPlayer())
  2809. ((Player*)spawn)->SetCharSheetChanged(true);
  2810. }
  2811. return 0;
  2812. }
  2813. int EQ2Emu_lua_SetStr(lua_State* state) {
  2814. if (!lua_interface)
  2815. return 0;
  2816. Spawn* spawn = lua_interface->GetSpawn(state);
  2817. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2818. float value = lua_interface->GetFloatValue(state, 2);
  2819. if (spawn && spawn->IsEntity()) {
  2820. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2821. if (spawn->IsPlayer())
  2822. ((Player*)spawn)->SetCharSheetChanged(true);
  2823. }
  2824. return 0;
  2825. }
  2826. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2827. if (!lua_interface)
  2828. return 0;
  2829. Spawn* spawn = lua_interface->GetSpawn(state);
  2830. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2831. float value = lua_interface->GetFloatValue(state, 2);
  2832. if (spawn && spawn->IsEntity()) {
  2833. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2834. if (spawn->IsPlayer())
  2835. ((Player*)spawn)->SetCharSheetChanged(true);
  2836. }
  2837. return 0;
  2838. }
  2839. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2840. if (!lua_interface)
  2841. return 0;
  2842. Spawn* spawn = lua_interface->GetSpawn(state);
  2843. if (spawn) {
  2844. lua_interface->SetInt32Value(state, spawn->GetHP());
  2845. return 1;
  2846. }
  2847. return 0;
  2848. }
  2849. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2850. if (!lua_interface)
  2851. return 0;
  2852. Spawn* spawn = lua_interface->GetSpawn(state);
  2853. if (spawn) {
  2854. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2855. return 1;
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. if (spawn) {
  2864. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2865. return 1;
  2866. }
  2867. return 0;
  2868. }
  2869. int EQ2Emu_lua_GetName(lua_State* state) {
  2870. if (!lua_interface)
  2871. return 0;
  2872. Spawn* spawn = lua_interface->GetSpawn(state);
  2873. if (spawn) {
  2874. lua_interface->SetStringValue(state, spawn->GetName());
  2875. return 1;
  2876. }
  2877. return 0;
  2878. }
  2879. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2880. Spawn* spawn = lua_interface->GetSpawn(state);
  2881. if (spawn) {
  2882. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2883. return 1;
  2884. }
  2885. return 0;
  2886. }
  2887. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2888. if (!lua_interface)
  2889. return 0;
  2890. Spawn* spawn = lua_interface->GetSpawn(state);
  2891. if (spawn) {
  2892. lua_interface->SetInt32Value(state, spawn->GetPower());
  2893. return 1;
  2894. }
  2895. return 0;
  2896. }
  2897. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2898. if (!lua_interface)
  2899. return 0;
  2900. Spawn* spawn = lua_interface->GetSpawn(state);
  2901. if (spawn) {
  2902. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2903. return 1;
  2904. }
  2905. return 0;
  2906. }
  2907. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2908. if (!lua_interface)
  2909. return 0;
  2910. Spawn* spawn = lua_interface->GetSpawn(state);
  2911. if (spawn) {
  2912. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2913. return 1;
  2914. }
  2915. return 0;
  2916. }
  2917. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2918. if (!lua_interface)
  2919. return 0;
  2920. Spawn* spawn = lua_interface->GetSpawn(state);
  2921. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2922. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2923. if (spawn && spawn2) {
  2924. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2925. lua_interface->SetFloatValue(state, distance);
  2926. return 1;
  2927. }
  2928. return 0;
  2929. }
  2930. int EQ2Emu_lua_GetX(lua_State* state) {
  2931. if (!lua_interface)
  2932. return 0;
  2933. Spawn* spawn = lua_interface->GetSpawn(state);
  2934. if (spawn) {
  2935. lua_interface->SetFloatValue(state, spawn->GetX());
  2936. return 1;
  2937. }
  2938. return 0;
  2939. }
  2940. int EQ2Emu_lua_GetY(lua_State* state) {
  2941. if (!lua_interface)
  2942. return 0;
  2943. Spawn* spawn = lua_interface->GetSpawn(state);
  2944. if (spawn) {
  2945. lua_interface->SetFloatValue(state, spawn->GetY());
  2946. return 1;
  2947. }
  2948. return 0;
  2949. }
  2950. int EQ2Emu_lua_GetZ(lua_State* state) {
  2951. if (!lua_interface)
  2952. return 0;
  2953. Spawn* spawn = lua_interface->GetSpawn(state);
  2954. if (spawn) {
  2955. lua_interface->SetFloatValue(state, spawn->GetZ());
  2956. return 1;
  2957. }
  2958. return 0;
  2959. }
  2960. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2961. if (!lua_interface)
  2962. return 0;
  2963. Spawn* spawn = lua_interface->GetSpawn(state);
  2964. if (spawn) {
  2965. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2966. return 1;
  2967. }
  2968. return 0;
  2969. }
  2970. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2971. if (!lua_interface)
  2972. return 0;
  2973. Spawn* spawn = lua_interface->GetSpawn(state);
  2974. if (spawn) {
  2975. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2976. return 1;
  2977. }
  2978. return 0;
  2979. }
  2980. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2981. if (!lua_interface)
  2982. return 0;
  2983. Spawn* spawn = lua_interface->GetSpawn(state);
  2984. if (spawn) {
  2985. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2986. return 1;
  2987. }
  2988. return 0;
  2989. }
  2990. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2991. if (!lua_interface)
  2992. return 0;
  2993. Spawn* spawn = lua_interface->GetSpawn(state);
  2994. if (spawn && spawn->IsEntity()) {
  2995. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2996. return 1;
  2997. }
  2998. return 0;
  2999. }
  3000. int EQ2Emu_lua_GetInt(lua_State* state) {
  3001. if (!lua_interface)
  3002. return 0;
  3003. Spawn* spawn = lua_interface->GetSpawn(state);
  3004. if (spawn && spawn->IsEntity()) {
  3005. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3006. return 1;
  3007. }
  3008. return 0;
  3009. }
  3010. int EQ2Emu_lua_GetWis(lua_State* state) {
  3011. if (!lua_interface)
  3012. return 0;
  3013. Spawn* spawn = lua_interface->GetSpawn(state);
  3014. if (spawn && spawn->IsEntity()) {
  3015. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3016. return 1;
  3017. }
  3018. return 0;
  3019. }
  3020. int EQ2Emu_lua_GetSta(lua_State* state) {
  3021. if (!lua_interface)
  3022. return 0;
  3023. Spawn* spawn = lua_interface->GetSpawn(state);
  3024. if (spawn && spawn->IsEntity()) {
  3025. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3026. return 1;
  3027. }
  3028. return 0;
  3029. }
  3030. int EQ2Emu_lua_GetStr(lua_State* state) {
  3031. if (!lua_interface)
  3032. return 0;
  3033. Spawn* spawn = lua_interface->GetSpawn(state);
  3034. if (spawn && spawn->IsEntity()) {
  3035. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3036. return 1;
  3037. }
  3038. return 0;
  3039. }
  3040. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3041. if (!lua_interface)
  3042. return 0;
  3043. Spawn* spawn = lua_interface->GetSpawn(state);
  3044. if (spawn && spawn->IsEntity()) {
  3045. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3046. return 1;
  3047. }
  3048. return 0;
  3049. }
  3050. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3051. if (!lua_interface)
  3052. return 0;
  3053. Spawn* spawn = lua_interface->GetSpawn(state);
  3054. if (spawn && spawn->IsEntity()) {
  3055. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3056. return 1;
  3057. }
  3058. return 0;
  3059. }
  3060. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3061. if (!lua_interface)
  3062. return 0;
  3063. Spawn* spawn = lua_interface->GetSpawn(state);
  3064. if (spawn && spawn->IsEntity()) {
  3065. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3066. return 1;
  3067. }
  3068. return 0;
  3069. }
  3070. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3071. if (!lua_interface)
  3072. return 0;
  3073. Spawn* spawn = lua_interface->GetSpawn(state);
  3074. if (spawn && spawn->IsEntity()) {
  3075. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3076. return 1;
  3077. }
  3078. return 0;
  3079. }
  3080. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3081. if (!lua_interface)
  3082. return 0;
  3083. Spawn* spawn = lua_interface->GetSpawn(state);
  3084. if (spawn && spawn->IsEntity()) {
  3085. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3086. return 1;
  3087. }
  3088. return 0;
  3089. }
  3090. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3091. if (!lua_interface)
  3092. return 0;
  3093. Spawn* spawn = lua_interface->GetSpawn(state);
  3094. if (spawn && spawn->IsEntity()) {
  3095. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3096. return 1;
  3097. }
  3098. return 0;
  3099. }
  3100. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3101. if (!lua_interface)
  3102. return 0;
  3103. Spawn* player = lua_interface->GetSpawn(state);
  3104. if (!player || !player->IsPlayer()) {
  3105. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3106. return 0;
  3107. }
  3108. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3109. if (quest_id <= 0) {
  3110. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3111. return 0;
  3112. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3113. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3114. return 0;
  3115. }
  3116. int32 step = lua_interface->GetInt32Value(state, 3);
  3117. if (step > 0) {
  3118. Client* client = ((Player*)player)->GetClient();
  3119. if (client)
  3120. client->AddPendingQuestUpdate(quest_id, step);
  3121. } else {
  3122. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3123. }
  3124. return 0;
  3125. }
  3126. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3127. Spawn* player = lua_interface->GetSpawn(state);
  3128. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3129. int32 step = lua_interface->GetInt32Value(state, 3);
  3130. int32 progress = lua_interface->GetInt32Value(state, 4);
  3131. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3132. Client* client = ((Player*)player)->GetClient();
  3133. if (client)
  3134. client->AddPendingQuestUpdate(quest_id, step, progress);
  3135. }
  3136. return 0;
  3137. }
  3138. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3139. if (!lua_interface)
  3140. return 0;
  3141. Spawn* player = lua_interface->GetSpawn(state);
  3142. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3143. if (player && player->IsPlayer() && quest_id > 0) {
  3144. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3145. return 1;
  3146. }
  3147. return 0;
  3148. }
  3149. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3150. if (!lua_interface)
  3151. return 0;
  3152. Spawn* player = lua_interface->GetSpawn(state);
  3153. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3154. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3155. if (player && player->IsPlayer() && quest_id > 0) {
  3156. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3157. return 1;
  3158. }
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Spawn* player = lua_interface->GetSpawn(state);
  3165. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3166. if (player && player->IsPlayer() && quest_id > 0) {
  3167. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3168. return 1;
  3169. }
  3170. return 0;
  3171. }
  3172. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3173. if (!lua_interface)
  3174. return 0;
  3175. Quest* quest = lua_interface->GetQuest(state);
  3176. string name = lua_interface->GetStringValue(state, 2);
  3177. string type = lua_interface->GetStringValue(state, 3);
  3178. string zone = lua_interface->GetStringValue(state, 4);
  3179. int16 level = lua_interface->GetInt16Value(state, 5);
  3180. string description = lua_interface->GetStringValue(state, 6);
  3181. bool load = true;
  3182. if (!quest) {
  3183. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3184. load = false;
  3185. }
  3186. if (load && name.length() == 0) {
  3187. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3188. load = false;
  3189. }
  3190. if (load && type.length() == 0) {
  3191. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3192. load = false;
  3193. }
  3194. if (load && zone.length() == 0) {
  3195. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3196. load = false;
  3197. }
  3198. if (load && description.length() == 0) {
  3199. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3200. load = false;
  3201. }
  3202. if (load && level == 0) {
  3203. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3204. load = false;
  3205. }
  3206. if (load)
  3207. quest->RegisterQuest(name, type, zone, level, description);
  3208. return 0;
  3209. }
  3210. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3211. if (!lua_interface)
  3212. return 0;
  3213. Quest* quest = lua_interface->GetQuest(state);
  3214. if (quest) {
  3215. int8 level = lua_interface->GetInt16Value(state, 2);
  3216. quest->SetPrereqLevel(level);
  3217. }
  3218. return 0;
  3219. }
  3220. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3221. if (!lua_interface)
  3222. return 0;
  3223. Quest* quest = lua_interface->GetQuest(state);
  3224. if (quest) {
  3225. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3226. quest->AddPrereqQuest(quest_id);
  3227. }
  3228. return 0;
  3229. }
  3230. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3231. if (!lua_interface)
  3232. return 0;
  3233. Quest* quest = lua_interface->GetQuest(state);
  3234. if (quest) {
  3235. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3236. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3237. if (quantity == 0)
  3238. quantity = 1;
  3239. Item* master_item = master_item_list.GetItem(item_id);
  3240. if (master_item) {
  3241. Item* item = new Item(master_item);
  3242. item->details.count = quantity;
  3243. quest->AddPrereqItem(item);
  3244. }
  3245. }
  3246. return 0;
  3247. }
  3248. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3249. if (!lua_interface)
  3250. return 0;
  3251. Spawn* player = lua_interface->GetSpawn(state);
  3252. if(!player || !player->IsPlayer()) {
  3253. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3254. return 0;
  3255. }
  3256. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3257. if (quest_id > 0) {
  3258. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3259. return 1;
  3260. } else {
  3261. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3262. }
  3263. return 0;
  3264. }
  3265. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3266. if (!lua_interface)
  3267. return 0;
  3268. Quest* quest = lua_interface->GetQuest(state);
  3269. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3270. lua_interface->ResetFunctionStack(state);
  3271. if (quest && spawn_id > 0)
  3272. quest->SetQuestReturnNPC(spawn_id);
  3273. return 0;
  3274. }
  3275. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3276. if (!lua_interface)
  3277. return 0;
  3278. Spawn* spawn = lua_interface->GetSpawn(state);
  3279. int32 time = lua_interface->GetInt32Value(state, 2);
  3280. string function = lua_interface->GetStringValue(state, 3);
  3281. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3282. Spawn* player = lua_interface->GetSpawn(state, 5);
  3283. lua_interface->ResetFunctionStack(state);
  3284. if (!spawn) {
  3285. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3286. return 0;
  3287. }
  3288. if (time <= 0) {
  3289. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3290. return 0;
  3291. }
  3292. if (function.length() == 0) {
  3293. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3294. return 0;
  3295. }
  3296. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3297. if ( time < 10)
  3298. time = 10;
  3299. timer->timer = Timer::GetCurrentTime2() + time;
  3300. timer->function = function;
  3301. timer->spawn = spawn->GetID();
  3302. timer->player = player ? player->GetID() : 0;
  3303. if (max_count == 0)
  3304. max_count = 1;
  3305. timer->max_count = max_count;
  3306. timer->current_count = 0;
  3307. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3308. return 0;
  3309. }
  3310. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3311. if (!lua_interface)
  3312. return 0;
  3313. Spawn* spawn = lua_interface->GetSpawn(state);
  3314. string function = lua_interface->GetStringValue(state, 2);
  3315. lua_interface->ResetFunctionStack(state);
  3316. if (!spawn) {
  3317. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3318. return 0;
  3319. }
  3320. if(!spawn->GetZone()) {
  3321. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3322. return 0;
  3323. }
  3324. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3325. return 0;
  3326. }
  3327. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3328. if (!lua_interface)
  3329. return 0;
  3330. Spawn* player = lua_interface->GetSpawn(state);
  3331. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3332. lua_interface->ResetFunctionStack(state);
  3333. if (player && player->IsPlayer() && quest_id > 0) {
  3334. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3335. return 1;
  3336. }
  3337. return 0;
  3338. }
  3339. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3340. if (!lua_interface)
  3341. return 0;
  3342. Spawn* player = lua_interface->GetSpawn(state);
  3343. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3344. lua_interface->ResetFunctionStack(state);
  3345. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3346. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3347. if (quest)
  3348. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3349. return 1;
  3350. }
  3351. return 0;
  3352. }
  3353. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3354. if (!lua_interface)
  3355. return 0;
  3356. Spawn* player = lua_interface->GetSpawn(state);
  3357. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3358. lua_interface->ResetFunctionStack(state);
  3359. if (player && player->IsPlayer() && quest_id > 0) {
  3360. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3361. return 1;
  3362. }
  3363. return 0;
  3364. }
  3365. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3366. if (!lua_interface)
  3367. return 0;
  3368. Spawn* npc = lua_interface->GetSpawn(state);
  3369. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3370. lua_interface->ResetFunctionStack(state);
  3371. if (npc && !npc->IsPlayer() && quest_id > 0)
  3372. npc->AddProvidedQuest(quest_id);
  3373. return 0;
  3374. }
  3375. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3376. if (!lua_interface)
  3377. return 0;
  3378. Spawn* npc = lua_interface->GetSpawn(state);
  3379. Spawn* player = lua_interface->GetSpawn(state, 2);
  3380. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3381. bool forced = lua_interface->GetBooleanValue(state, 4);
  3382. lua_interface->ResetFunctionStack(state);
  3383. /* NPC is allowed to be null */
  3384. if (player && player->IsPlayer() && quest_id > 0) {
  3385. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3386. if (master_quest) {
  3387. Client* client = ((Player*)player)->GetClient();
  3388. if (!client) {
  3389. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3390. }
  3391. Quest* quest = new Quest(master_quest);
  3392. if (!quest) {
  3393. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3394. }
  3395. if (client && quest) {
  3396. if (npc)
  3397. quest->SetQuestGiver(npc->GetDatabaseID());
  3398. else
  3399. quest->SetQuestGiver(0);
  3400. client->AddPendingQuest(quest, forced);
  3401. }
  3402. }
  3403. else {
  3404. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3405. }
  3406. }
  3407. else {
  3408. 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);
  3409. }
  3410. return 0;
  3411. }
  3412. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3413. if (!lua_interface)
  3414. return 0;
  3415. Quest* quest = lua_interface->GetQuest(state);
  3416. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3417. lua_interface->ResetFunctionStack(state);
  3418. if (quest) {
  3419. quest->AddPrereqClass(class_id);
  3420. }
  3421. return 0;
  3422. }
  3423. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3424. if (!lua_interface)
  3425. return 0;
  3426. Quest* quest = lua_interface->GetQuest(state);
  3427. int8 race = lua_interface->GetInt8Value(state, 2);
  3428. lua_interface->ResetFunctionStack(state);
  3429. if (quest) {
  3430. quest->AddPrereqRace(race);
  3431. }
  3432. return 0;
  3433. }
  3434. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3435. if (!lua_interface)
  3436. return 0;
  3437. Quest* quest = lua_interface->GetQuest(state);
  3438. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3439. lua_interface->ResetFunctionStack(state);
  3440. if (quest) {
  3441. quest->AddPrereqModelType(model_type);
  3442. }
  3443. return 0;
  3444. }
  3445. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3446. if (!lua_interface)
  3447. return 0;
  3448. Quest* quest = lua_interface->GetQuest(state);
  3449. int8 level = lua_interface->GetInt8Value(state, 2);
  3450. lua_interface->ResetFunctionStack(state);
  3451. if (!quest) {
  3452. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3453. return 0;
  3454. }
  3455. quest->SetPrereqTSLevel(level);
  3456. return 0;
  3457. }
  3458. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3459. if (!lua_interface)
  3460. return 0;
  3461. Quest* quest = lua_interface->GetQuest(state);
  3462. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3463. lua_interface->ResetFunctionStack(state);
  3464. if (!quest) {
  3465. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3466. return 0;
  3467. }
  3468. quest->AddPrereqTradeskillClass(class_id);
  3469. return 0;
  3470. }
  3471. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3472. if (!lua_interface)
  3473. return 0;
  3474. Quest* quest = lua_interface->GetQuest(state);
  3475. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3476. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3477. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3478. lua_interface->ResetFunctionStack(state);
  3479. if (quest) {
  3480. quest->AddPrereqFaction(faction_id, min, max);
  3481. }
  3482. return 0;
  3483. }
  3484. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3485. if (!lua_interface)
  3486. return 0;
  3487. Quest* quest = lua_interface->GetQuest(state);
  3488. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3489. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3490. lua_interface->ResetFunctionStack(state);
  3491. if (quest) {
  3492. if (quantity == 0)
  3493. quantity = 1;
  3494. Item* master_item = master_item_list.GetItem(item_id);
  3495. if (master_item) {
  3496. Item* item = new Item(master_item);
  3497. item->details.count = quantity;
  3498. quest->AddSelectableRewardItem(item);
  3499. }
  3500. }
  3501. return 0;
  3502. }
  3503. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3504. if (!lua_interface)
  3505. return 0;
  3506. Quest* quest = lua_interface->GetQuest(state);
  3507. if (quest) {
  3508. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3509. vector<Item*>* items = quest->GetRewardItems();
  3510. if (items) {
  3511. vector<Item*>::iterator itr;
  3512. for (itr = items->begin(); itr != items->end(); itr++) {
  3513. if (*itr && (*itr)->details.item_id == item_id) {
  3514. lua_interface->SetBooleanValue(state, true);
  3515. return 1;
  3516. }
  3517. }
  3518. }
  3519. }
  3520. lua_interface->SetBooleanValue(state, false);
  3521. return 1;
  3522. }
  3523. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3524. if (!lua_interface)
  3525. return 0;
  3526. Quest* quest = lua_interface->GetQuest(state);
  3527. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3528. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3529. lua_interface->ResetFunctionStack(state);
  3530. if (quest) {
  3531. if (quantity == 0)
  3532. quantity = 1;
  3533. Item* master_item = master_item_list.GetItem(item_id);
  3534. if (master_item) {
  3535. Item* item = new Item(master_item);
  3536. item->details.count = quantity;
  3537. quest->AddRewardItem(item);
  3538. }
  3539. }
  3540. return 0;
  3541. }
  3542. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3543. if (!lua_interface)
  3544. return 0;
  3545. Quest* quest = lua_interface->GetQuest(state);
  3546. int32 copper = lua_interface->GetInt32Value(state, 2);
  3547. int32 silver = lua_interface->GetInt32Value(state, 3);
  3548. int32 gold = lua_interface->GetInt32Value(state, 4);
  3549. int32 plat = lua_interface->GetInt32Value(state, 5);
  3550. lua_interface->ResetFunctionStack(state);
  3551. if (quest) {
  3552. quest->AddRewardCoins(copper, silver, gold, plat);
  3553. }
  3554. return 0;
  3555. }
  3556. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3557. if (!lua_interface)
  3558. return 0;
  3559. Quest* quest = lua_interface->GetQuest(state);
  3560. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3561. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3562. lua_interface->ResetFunctionStack(state);
  3563. if (quest && faction_id > 0 && amount != 0)
  3564. quest->AddRewardFaction(faction_id, amount);
  3565. return 0;
  3566. }
  3567. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3568. if (!lua_interface)
  3569. return 0;
  3570. Quest* quest = lua_interface->GetQuest(state);
  3571. int32 status = lua_interface->GetInt32Value(state, 2);
  3572. lua_interface->ResetFunctionStack(state);
  3573. if (quest) {
  3574. quest->SetRewardStatus(status);
  3575. }
  3576. return 0;
  3577. }
  3578. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3579. if (!lua_interface)
  3580. return 0;
  3581. Quest* quest = lua_interface->GetQuest(state);
  3582. int32 status = lua_interface->GetInt32Value(state, 2);
  3583. lua_interface->ResetFunctionStack(state);
  3584. if (quest) {
  3585. quest->SetStatusTmpReward(status);
  3586. }
  3587. return 0;
  3588. }
  3589. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3590. if (!lua_interface)
  3591. return 0;
  3592. Quest* quest = lua_interface->GetQuest(state);
  3593. int64 coins = lua_interface->GetInt64Value(state, 2);
  3594. lua_interface->ResetFunctionStack(state);
  3595. if (quest) {
  3596. quest->SetCoinTmpReward(coins);
  3597. }
  3598. return 0;
  3599. }
  3600. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3601. if (!lua_interface)
  3602. return 0;
  3603. Quest* quest = lua_interface->GetQuest(state);
  3604. string comment = lua_interface->GetStringValue(state, 2);
  3605. lua_interface->ResetFunctionStack(state);
  3606. if (quest) {
  3607. quest->SetRewardComment(comment);
  3608. }
  3609. return 0;
  3610. }
  3611. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3612. if (!lua_interface)
  3613. return 0;
  3614. Quest* quest = lua_interface->GetQuest(state);
  3615. int32 exp = lua_interface->GetInt32Value(state, 2);
  3616. lua_interface->ResetFunctionStack(state);
  3617. if (quest) {
  3618. quest->SetRewardXP(exp);
  3619. }
  3620. return 0;
  3621. }
  3622. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3623. Quest* quest = lua_interface->GetQuest(state);
  3624. int32 step = lua_interface->GetInt32Value(state, 2);
  3625. string description = lua_interface->GetStringValue(state, 3);
  3626. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3627. float percentage = lua_interface->GetFloatValue(state, 5);
  3628. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3629. int16 icon = lua_interface->GetInt16Value(state, 7);
  3630. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3631. if (quest) {
  3632. const char* taskgroup = 0;
  3633. if (str_taskgroup.length() > 0)
  3634. taskgroup = str_taskgroup.c_str();
  3635. int32 id = 0;
  3636. vector<int32>* ids = 0;
  3637. int i = 0;
  3638. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3639. if (ids == 0)
  3640. ids = new vector<int32>;
  3641. ids->push_back(id);
  3642. i++;
  3643. }
  3644. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3645. if (quest_step && icon && quantity > 0)
  3646. quest_step->SetIcon(icon);
  3647. if (quest->GetPlayer()) {
  3648. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3649. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3650. }
  3651. }
  3652. lua_interface->ResetFunctionStack(state);
  3653. return 0;
  3654. }
  3655. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3656. {
  3657. if (!lua_interface)
  3658. return 0;
  3659. Quest* quest = lua_interface->GetQuest(state);
  3660. int32 step = lua_interface->GetInt32Value(state, 2);
  3661. string description = lua_interface->GetStringValue(state, 3);
  3662. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3663. float percentage = lua_interface->GetFloatValue(state, 5);
  3664. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3665. int16 icon = lua_interface->GetInt16Value(state, 7);
  3666. if (quest) {
  3667. const char* taskgroup = 0;
  3668. if (str_taskgroup.length() > 0)
  3669. taskgroup = str_taskgroup.c_str();
  3670. int32 id = 0;
  3671. vector<int32>* ids = 0;
  3672. int i = 0;
  3673. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3674. if (ids == 0)
  3675. ids = new vector<int32>;
  3676. ids->push_back(id);
  3677. i++;
  3678. }
  3679. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3680. if (quest_step && icon > 0 && quantity > 0)
  3681. quest_step->SetIcon(icon);
  3682. if (quest->GetPlayer()) {
  3683. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3684. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3685. }
  3686. safe_delete(ids);
  3687. }
  3688. lua_interface->ResetFunctionStack(state);
  3689. return 0;
  3690. }
  3691. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3692. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3693. }
  3694. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3695. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3696. }
  3697. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3698. if (!lua_interface)
  3699. return 0;
  3700. Quest* quest = lua_interface->GetQuest(state);
  3701. int32 step = lua_interface->GetInt32Value(state, 2);
  3702. string description = lua_interface->GetStringValue(state, 3);
  3703. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3704. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3705. int16 icon = lua_interface->GetInt16Value(state, 6);
  3706. if (quest) {
  3707. const char* taskgroup = 0;
  3708. if (str_taskgroup.length() > 0)
  3709. taskgroup = str_taskgroup.c_str();
  3710. int32 npc_id = 0;
  3711. vector<int32>* ids = 0;
  3712. int i = 0;
  3713. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3714. if (ids == 0)
  3715. ids = new vector<int32>;
  3716. ids->push_back(npc_id);
  3717. i++;
  3718. }
  3719. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3720. if (quest_step && icon > 0)
  3721. quest_step->SetIcon(icon);
  3722. if (quest->GetPlayer()) {
  3723. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3724. if(client)
  3725. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3726. }
  3727. safe_delete(ids);
  3728. }
  3729. lua_interface->ResetFunctionStack(state);
  3730. return 0;
  3731. }
  3732. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3733. if (!lua_interface)
  3734. return 0;
  3735. Quest* quest = lua_interface->GetQuest(state);
  3736. int32 step = lua_interface->GetInt32Value(state, 2);
  3737. string description = lua_interface->GetStringValue(state, 3);
  3738. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3739. float percentage = lua_interface->GetFloatValue(state, 5);
  3740. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3741. int16 icon = lua_interface->GetInt16Value(state, 7);
  3742. if (quest) {
  3743. const char* taskgroup = 0;
  3744. if (str_taskgroup.length() > 0)
  3745. taskgroup = str_taskgroup.c_str();
  3746. int32 item_id = 0;
  3747. vector<int32>* ids = 0;
  3748. int i = 0;
  3749. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3750. if (ids == 0)
  3751. ids = new vector<int32>;
  3752. ids->push_back(item_id);
  3753. i++;
  3754. }
  3755. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3756. if (quest_step && icon > 0 && quantity > 0)
  3757. quest_step->SetIcon(icon);
  3758. if (quest->GetPlayer()) {
  3759. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3760. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3761. }
  3762. safe_delete(ids);
  3763. }
  3764. lua_interface->ResetFunctionStack(state);
  3765. return 0;
  3766. }
  3767. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3768. if (!lua_interface)
  3769. return 0;
  3770. Quest* quest = lua_interface->GetQuest(state);
  3771. int32 step = lua_interface->GetInt32Value(state, 2);
  3772. string description = lua_interface->GetStringValue(state, 3);
  3773. float max_variation = lua_interface->GetFloatValue(state, 4);
  3774. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3775. int16 icon = lua_interface->GetInt16Value(state, 6);
  3776. if (quest) {
  3777. const char* taskgroup = 0;
  3778. if (str_taskgroup.length() > 0)
  3779. taskgroup = str_taskgroup.c_str();
  3780. vector<Location>* locations = 0;
  3781. int8 i = 7;
  3782. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3783. while (true) {
  3784. Location loc;
  3785. loc.x = lua_interface->GetFloatValue(state, i);
  3786. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3787. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3788. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3789. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3790. break;
  3791. if (locations == 0)
  3792. locations = new vector<Location>;
  3793. locations->push_back(loc);
  3794. i += 4;
  3795. }
  3796. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3797. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3798. if (quest_step && icon > 0)
  3799. quest_step->SetIcon(icon);
  3800. if (quest->GetPlayer()) {
  3801. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3802. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3803. }
  3804. }
  3805. lua_interface->ResetFunctionStack(state);
  3806. return 0;
  3807. }
  3808. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3809. if (!lua_interface)
  3810. return 0;
  3811. Quest* quest = lua_interface->GetQuest(state);
  3812. int32 step = lua_interface->GetInt32Value(state, 2);
  3813. string description = lua_interface->GetStringValue(state, 3);
  3814. float max_variation = lua_interface->GetFloatValue(state, 4);
  3815. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3816. int16 icon = lua_interface->GetInt16Value(state, 6);
  3817. if (quest) {
  3818. const char* taskgroup = 0;
  3819. if (str_taskgroup.length() > 0)
  3820. taskgroup = str_taskgroup.c_str();
  3821. vector<Location>* locations = 0;
  3822. int8 i = 7;
  3823. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3824. while (true) {
  3825. Location loc;
  3826. loc.x = lua_interface->GetFloatValue(state, i);
  3827. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3828. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3829. loc.zone_id = 0;
  3830. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3831. break;
  3832. if (locations == 0)
  3833. locations = new vector<Location>;
  3834. locations->push_back(loc);
  3835. i += 3;
  3836. }
  3837. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3838. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3839. if (quest_step && icon > 0)
  3840. quest_step->SetIcon(icon);
  3841. if (quest->GetPlayer()) {
  3842. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3843. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3844. }
  3845. }
  3846. lua_interface->ResetFunctionStack(state);
  3847. return 0;
  3848. }
  3849. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3850. if (!lua_interface)
  3851. return 0;
  3852. Quest* quest = lua_interface->GetQuest(state);
  3853. int32 step = lua_interface->GetInt32Value(state, 2);
  3854. string description = lua_interface->GetStringValue(state, 3);
  3855. float max_variation = lua_interface->GetFloatValue(state, 4);
  3856. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3857. int16 icon = lua_interface->GetInt16Value(state, 6);
  3858. if (quest) {
  3859. const char* taskgroup = 0;
  3860. if (str_taskgroup.length() > 0)
  3861. taskgroup = str_taskgroup.c_str();
  3862. vector<Location>* locations = 0;
  3863. int i = 7;
  3864. while (true) {
  3865. Location loc;
  3866. loc.x = lua_interface->GetFloatValue(state, i);
  3867. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3868. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3869. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3870. break;
  3871. if (locations == 0)
  3872. locations = new vector<Location>;
  3873. locations->push_back(loc);
  3874. i += 3;
  3875. }
  3876. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3877. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3878. if (quest_step && icon > 0)
  3879. quest_step->SetIcon(icon);
  3880. if (quest->GetPlayer()) {
  3881. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3882. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3883. }
  3884. }
  3885. lua_interface->ResetFunctionStack(state);
  3886. return 0;
  3887. }
  3888. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3889. Quest* quest = lua_interface->GetQuest(state);
  3890. int32 step = lua_interface->GetInt32Value(state, 2);
  3891. string description = lua_interface->GetStringValue(state, 3);
  3892. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3893. float percentage = lua_interface->GetFloatValue(state, 5);
  3894. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3895. int16 icon = lua_interface->GetInt16Value(state, 7);
  3896. if (quest) {
  3897. const char* taskgroup = 0;
  3898. if (str_taskgroup.length() > 0)
  3899. taskgroup = str_taskgroup.c_str();
  3900. int32 spell_id = 0;
  3901. vector<int32>* ids = 0;
  3902. int i = 0;
  3903. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3904. if (ids == 0)
  3905. ids = new vector<int32>;
  3906. ids->push_back(spell_id);
  3907. i++;
  3908. }
  3909. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3910. if (quest_step && icon > 0 && quantity > 0)
  3911. quest_step->SetIcon(icon);
  3912. if (quest->GetPlayer()) {
  3913. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3914. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3915. }
  3916. safe_delete(ids);
  3917. }
  3918. lua_interface->ResetFunctionStack(state);
  3919. return 0;
  3920. }
  3921. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3922. if (!lua_interface)
  3923. return 0;
  3924. Quest* quest = lua_interface->GetQuest(state);
  3925. int32 step = lua_interface->GetInt32Value(state, 2);
  3926. string description = lua_interface->GetStringValue(state, 3);
  3927. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3928. float percentage = lua_interface->GetFloatValue(state, 5);
  3929. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3930. int16 icon = lua_interface->GetInt16Value(state, 7);
  3931. if (quest) {
  3932. const char* taskgroup = 0;
  3933. if (str_taskgroup.length() > 0)
  3934. taskgroup = str_taskgroup.c_str();
  3935. int32 item_id = 0;
  3936. vector<int32>* ids = 0;
  3937. int i = 0;
  3938. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3939. if (ids == 0)
  3940. ids = new vector<int32>;
  3941. ids->push_back(item_id);
  3942. i++;
  3943. }
  3944. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3945. if (quest_step && icon > 0 && quantity > 0)
  3946. quest_step->SetIcon(icon);
  3947. if (quest->GetPlayer()) {
  3948. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3949. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3950. }
  3951. safe_delete(ids);
  3952. }
  3953. lua_interface->ResetFunctionStack(state);
  3954. return 0;
  3955. }
  3956. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3957. if (!lua_interface)
  3958. return 0;
  3959. Quest* quest = lua_interface->GetQuest(state);
  3960. int32 step = lua_interface->GetInt32Value(state, 2);
  3961. string description = lua_interface->GetStringValue(state, 3);
  3962. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3963. float percentage = lua_interface->GetFloatValue(state, 5);
  3964. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3965. int16 icon = lua_interface->GetInt16Value(state, 7);
  3966. if (quest) {
  3967. const char* taskgroup = 0;
  3968. if (str_taskgroup.length() > 0)
  3969. taskgroup = str_taskgroup.c_str();
  3970. int32 item_id = 0;
  3971. vector<int32>* ids = 0;
  3972. int i = 0;
  3973. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3974. if (ids == 0)
  3975. ids = new vector<int32>;
  3976. ids->push_back(item_id);
  3977. i++;
  3978. }
  3979. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3980. if (quest_step && icon > 0 && quantity > 0)
  3981. quest_step->SetIcon(icon);
  3982. if (quest->GetPlayer()) {
  3983. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3984. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3985. }
  3986. safe_delete(ids);
  3987. }
  3988. lua_interface->ResetFunctionStack(state);
  3989. return 0;
  3990. }
  3991. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3992. if (!lua_interface)
  3993. return 0;
  3994. Quest* quest = lua_interface->GetQuest(state);
  3995. string action = lua_interface->GetStringValue(state, 2);
  3996. lua_interface->ResetFunctionStack(state);
  3997. if (quest) {
  3998. if (action.length() > 0)
  3999. quest->SetCompleteAction(action);
  4000. }
  4001. return 0;
  4002. }
  4003. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4004. if (!lua_interface)
  4005. return 0;
  4006. Quest* quest = lua_interface->GetQuest(state);
  4007. int32 step = lua_interface->GetInt32Value(state, 2);
  4008. string action = lua_interface->GetStringValue(state, 3);
  4009. lua_interface->ResetFunctionStack(state);
  4010. if (quest) {
  4011. if (step > 0 && action.length() > 0)
  4012. quest->AddCompleteAction(step, action);
  4013. }
  4014. return 0;
  4015. }
  4016. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4017. if (!lua_interface)
  4018. return 0;
  4019. Quest* quest = lua_interface->GetQuest(state);
  4020. int32 step = lua_interface->GetInt32Value(state, 2);
  4021. string action = lua_interface->GetStringValue(state, 3);
  4022. lua_interface->ResetFunctionStack(state);
  4023. if (quest) {
  4024. if (step > 0 && action.length() > 0)
  4025. quest->AddProgressAction(step, action);
  4026. }
  4027. return 0;
  4028. }
  4029. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4030. if (!lua_interface)
  4031. return 0;
  4032. Quest* quest = lua_interface->GetQuest(state);
  4033. string description = lua_interface->GetStringValue(state, 2);
  4034. lua_interface->ResetFunctionStack(state);
  4035. if (quest && description.length() > 0)
  4036. quest->SetDescription(description);
  4037. return 0;
  4038. }
  4039. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4040. if (!lua_interface)
  4041. return 0;
  4042. Quest* quest = lua_interface->GetQuest(state);
  4043. string description = lua_interface->GetStringValue(state, 2);
  4044. lua_interface->ResetFunctionStack(state);
  4045. if (quest && description.length() > 0)
  4046. quest->SetCompletedDescription(description);
  4047. return 0;
  4048. }
  4049. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4050. if (!lua_interface)
  4051. return 0;
  4052. Quest* quest = lua_interface->GetQuest(state);
  4053. int32 step = lua_interface->GetInt32Value(state, 2);
  4054. string description = lua_interface->GetStringValue(state, 3);
  4055. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4056. lua_interface->ResetFunctionStack(state);
  4057. if (quest && step > 0 && description.length() > 0) {
  4058. quest->SetTaskGroupDescription(step, description, display_bullets);
  4059. /* if (quest->GetPlayer()) {
  4060. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4061. if (client)
  4062. client->SendQuestUpdateStep(quest, step, false);
  4063. }*/
  4064. }
  4065. return 0;
  4066. }
  4067. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4068. if (!lua_interface)
  4069. return 0;
  4070. Quest* quest = lua_interface->GetQuest(state);
  4071. int32 step = lua_interface->GetInt32Value(state, 2);
  4072. string description = lua_interface->GetStringValue(state, 3);
  4073. lua_interface->ResetFunctionStack(state);
  4074. if (quest && step > 0 && description.length() > 0) {
  4075. quest->SetStepDescription(step, description);
  4076. /*if (quest->GetPlayer()) {
  4077. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4078. if (client)
  4079. client->SendQuestUpdateStepImmediately(quest, step);
  4080. }*/
  4081. }
  4082. return 0;
  4083. }
  4084. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4085. Quest* quest = lua_interface->GetQuest(state);
  4086. string zone = lua_interface->GetStringValue(state, 2);
  4087. lua_interface->ResetFunctionStack(state);
  4088. if (quest && zone.length() > 0)
  4089. quest->SetZone(zone);
  4090. return 0;
  4091. }
  4092. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4093. if (!lua_interface)
  4094. return 0;
  4095. Quest* quest = lua_interface->GetQuest(state);
  4096. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4097. lua_interface->ResetFunctionStack(state);
  4098. if (quest && spawn) {
  4099. if (spawn->IsPlayer()) {
  4100. Client* client = ((Player*)spawn)->GetClient();
  4101. if (client) {
  4102. client->AddPendingQuestReward(quest);
  4103. }
  4104. }
  4105. }
  4106. return 0;
  4107. }
  4108. int EQ2Emu_lua_Harvest(lua_State* state) {
  4109. if (!lua_interface)
  4110. return 0;
  4111. Spawn* player = lua_interface->GetSpawn(state);
  4112. Spawn* node = lua_interface->GetSpawn(state, 2);
  4113. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4114. Client* client = ((Player*)player)->GetClient();
  4115. if (client) {
  4116. ((GroundSpawn*)node)->ProcessHarvest(client);
  4117. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4118. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4119. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4120. }
  4121. }
  4122. }
  4123. else if (player && player->IsPlayer()) {
  4124. Client* client = ((Player*)player)->GetClient();
  4125. if (client)
  4126. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4127. }
  4128. lua_interface->ResetFunctionStack(state);
  4129. return 0;
  4130. }
  4131. int EQ2Emu_lua_Bind(lua_State* state) {
  4132. if (!lua_interface)
  4133. return 0;
  4134. Spawn* spawn = lua_interface->GetSpawn(state);
  4135. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4136. float x = lua_interface->GetFloatValue(state, 3);
  4137. float y = lua_interface->GetFloatValue(state, 4);
  4138. float z = lua_interface->GetFloatValue(state, 5);
  4139. float h = lua_interface->GetFloatValue(state, 6);
  4140. lua_interface->ResetFunctionStack(state);
  4141. if (!spawn) {
  4142. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4143. return 0;
  4144. }
  4145. if (!spawn->IsPlayer()) {
  4146. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4147. return 0;
  4148. }
  4149. if (zone_id == 0) {
  4150. Client* client = ((Player*)spawn)->GetClient();
  4151. if (!client) {
  4152. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4153. return 0;
  4154. }
  4155. if (!client->Bind())
  4156. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4157. }
  4158. else {
  4159. Player* player = (Player*)spawn;
  4160. player->GetPlayerInfo()->SetBindZone(zone_id);
  4161. player->GetPlayerInfo()->SetBindX(x);
  4162. player->GetPlayerInfo()->SetBindY(y);
  4163. player->GetPlayerInfo()->SetBindZ(z);
  4164. player->GetPlayerInfo()->SetBindHeading(h);
  4165. }
  4166. return 0;
  4167. }
  4168. int EQ2Emu_lua_Gate(lua_State* state) {
  4169. if (!lua_interface)
  4170. return 0;
  4171. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4172. Spawn* spawn = lua_interface->GetSpawn(state);
  4173. lua_interface->ResetFunctionStack(state);
  4174. if (spawn) {
  4175. if (spawn->IsPlayer()) {
  4176. Client* client = ((Player*)spawn)->GetClient();
  4177. if (client) {
  4178. if (!client->Gate((spell != nullptr) ? true : false))
  4179. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4180. }
  4181. }
  4182. }
  4183. return 0;
  4184. }
  4185. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4186. if (!lua_interface)
  4187. return 0;
  4188. bool ret = false;
  4189. Spawn* spawn = lua_interface->GetSpawn(state);
  4190. lua_interface->ResetFunctionStack(state);
  4191. if (spawn) {
  4192. if (spawn->IsPlayer()) {
  4193. Client* client = ((Player*)spawn)->GetClient();
  4194. if (client)
  4195. ret = client->BindAllowed();
  4196. }
  4197. }
  4198. lua_interface->SetBooleanValue(state, ret);
  4199. return 1;
  4200. }
  4201. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4202. if (!lua_interface)
  4203. return 0;
  4204. bool ret = false;
  4205. Spawn* spawn = lua_interface->GetSpawn(state);
  4206. lua_interface->ResetFunctionStack(state);
  4207. if (spawn) {
  4208. if (spawn->IsPlayer()) {
  4209. Client* client = ((Player*)spawn)->GetClient();
  4210. ZoneServer* zone = lua_interface->GetZone(state);
  4211. if (client && zone){
  4212. ret = zone->GetCanGate();
  4213. }
  4214. }
  4215. }
  4216. lua_interface->SetBooleanValue(state, ret);
  4217. return 1;
  4218. }
  4219. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4220. Spawn* spawn = lua_interface->GetSpawn(state);
  4221. lua_interface->ResetFunctionStack(state);
  4222. if (spawn) {
  4223. lua_interface->SetBooleanValue(state, spawn->Alive());
  4224. return 1;
  4225. }
  4226. return 0;
  4227. }
  4228. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4229. if (!lua_interface)
  4230. return 0;
  4231. Spawn* spawn = lua_interface->GetSpawn(state);
  4232. lua_interface->ResetFunctionStack(state);
  4233. if (spawn && spawn->IsEntity()) {
  4234. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4235. return 1;
  4236. }
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4240. Spawn* spawn = lua_interface->GetSpawn(state);
  4241. string message = lua_interface->GetStringValue(state, 2);
  4242. string color_str = lua_interface->GetStringValue(state, 3);
  4243. lua_interface->ResetFunctionStack(state);
  4244. int8 color = CHANNEL_NARRATIVE;
  4245. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4246. Client* client = ((Player*)spawn)->GetClient();
  4247. if (client) {
  4248. if (color_str.length() > 0) {
  4249. // leave for backwards compat, but all future should just use the number
  4250. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4251. color = CHANNEL_COLOR_RED;
  4252. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4253. color = CHANNEL_COLOR_YELLOW;
  4254. else
  4255. {
  4256. // use a number to specify the channel as per Commands/Commands.h defines
  4257. color = (int8)atoul(color_str.c_str());
  4258. }
  4259. }
  4260. client->SimpleMessage(color, message.c_str());
  4261. }
  4262. }
  4263. return 0;
  4264. }
  4265. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4266. Spawn* spawn = lua_interface->GetSpawn(state);
  4267. string message = lua_interface->GetStringValue(state, 2);
  4268. int8 red = lua_interface->GetInt8Value(state, 3);
  4269. int8 green = lua_interface->GetInt8Value(state, 4);
  4270. int8 blue = lua_interface->GetInt8Value(state, 5);
  4271. lua_interface->ResetFunctionStack(state);
  4272. if (!spawn) {
  4273. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4274. return 0;
  4275. }
  4276. if (!spawn->IsPlayer()) {
  4277. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4278. return 0;
  4279. }
  4280. int32 words = ::CountWordsInString(message.c_str());
  4281. if (words < 5)
  4282. words = 5;
  4283. Client* client = ((Player*)spawn)->GetClient();
  4284. if (client)
  4285. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4286. return 0;
  4287. }
  4288. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4289. Spawn* spawn = lua_interface->GetSpawn(state);
  4290. int8 param = lua_interface->GetInt8Value(state, 2);
  4291. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4292. int8 value = lua_interface->GetInt8Value(state, 4);
  4293. lua_interface->ResetFunctionStack(state);
  4294. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4295. Client* client = ((Player*)spawn)->GetClient();
  4296. if (client) {
  4297. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4298. switch (param) {
  4299. case 1: {
  4300. packet->setDataByName("parameter1", param_value);
  4301. break;
  4302. }
  4303. case 2: {
  4304. packet->setDataByName("parameter2", param_value);
  4305. break;
  4306. }
  4307. case 3: {
  4308. packet->setDataByName("parameter3", param_value);
  4309. break;
  4310. }
  4311. case 4: {
  4312. packet->setDataByName("parameter4", param_value);
  4313. break;
  4314. }
  4315. case 5: {
  4316. packet->setDataByName("parameter5", param_value);
  4317. break;
  4318. }
  4319. }
  4320. packet->setDataByName("value", value);
  4321. client->QueuePacket(packet->serialize());
  4322. safe_delete(packet);
  4323. }
  4324. }
  4325. return 0;
  4326. }
  4327. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4328. Spawn* spawn = lua_interface->GetSpawn(state);
  4329. lua_interface->ResetFunctionStack(state);
  4330. if (spawn && spawn->IsPlayer()) {
  4331. if (((Player*)spawn)->GetIsTracking())
  4332. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4333. else
  4334. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4335. }
  4336. return 0;
  4337. }
  4338. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4339. Spawn* player = lua_interface->GetSpawn(state);
  4340. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4341. string name = lua_interface->GetStringValue(state, 3);
  4342. float distance = lua_interface->GetFloatValue(state, 4);
  4343. string command = lua_interface->GetStringValue(state, 5);
  4344. string error_text = lua_interface->GetStringValue(state, 6);
  4345. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4346. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4347. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4348. lua_interface->ResetFunctionStack(state);
  4349. if (spawn) {
  4350. if (distance == 0)
  4351. distance = 10.0f;
  4352. if (command.length() == 0)
  4353. command = name;
  4354. if (command.length() < 1 && name.length() < 1)
  4355. {
  4356. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4357. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4358. spawn->RemovePrimaryCommands();
  4359. }
  4360. else
  4361. {
  4362. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4363. }
  4364. }
  4365. return 0;
  4366. }
  4367. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4368. if (!lua_interface)
  4369. return 0;
  4370. Spawn* player = lua_interface->GetSpawn(state);
  4371. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4372. int16 tier = lua_interface->GetInt16Value(state, 3);
  4373. lua_interface->ResetFunctionStack(state);
  4374. if (player && player->IsPlayer()) {
  4375. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4376. return 1;
  4377. }
  4378. return 0;
  4379. }
  4380. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4381. if (!lua_interface)
  4382. return 0;
  4383. Spawn* player = lua_interface->GetSpawn(state);
  4384. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4385. int16 tier = lua_interface->GetInt16Value(state, 3);
  4386. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4387. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4388. bool add_to_hotbar = true;
  4389. if (num_args > 4) {
  4390. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4391. }
  4392. lua_interface->ResetFunctionStack(state);
  4393. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4394. if (player && spell && player->IsPlayer()) {
  4395. Client* client = player->GetClient();
  4396. if (client) {
  4397. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4398. {
  4399. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4400. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4401. client->GetPlayer()->UnlockSpell(spell);
  4402. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4403. }
  4404. else
  4405. {
  4406. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4407. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4408. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4409. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4410. client->GetPlayer()->UnlockSpell(spell);
  4411. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4412. }
  4413. //if (client ) {
  4414. // ((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);
  4415. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4416. if (outapp)
  4417. client->QueuePacket(outapp);
  4418. }
  4419. }
  4420. return 0;
  4421. }
  4422. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4423. if (!lua_interface)
  4424. return 0;
  4425. Spawn* player = lua_interface->GetSpawn(state);
  4426. lua_interface->ResetFunctionStack(state);
  4427. if (player && player->IsPlayer()) {
  4428. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4429. return 1;
  4430. }
  4431. return 0;
  4432. }
  4433. int EQ2Emu_lua_Attack(lua_State* state) {
  4434. if (lua_interface) {
  4435. Spawn* npc = lua_interface->GetSpawn(state);
  4436. Spawn* player = lua_interface->GetSpawn(state, 2);
  4437. lua_interface->ResetFunctionStack(state);
  4438. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4439. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4440. }
  4441. return 0;
  4442. }
  4443. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4444. if (lua_interface) {
  4445. Spawn* target = lua_interface->GetSpawn(state);
  4446. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4447. lua_interface->ResetFunctionStack(state);
  4448. if (target && target->GetZone())
  4449. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4450. }
  4451. return 0;
  4452. }
  4453. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4454. Spawn* player;
  4455. if (lua_interface) {
  4456. player = lua_interface->GetSpawn(state);
  4457. lua_interface->ResetFunctionStack(state);
  4458. if (player && player->IsPlayer()) {
  4459. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4460. return 1;
  4461. }
  4462. }
  4463. return 0;
  4464. }
  4465. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4466. Spawn* player;
  4467. Client* client;
  4468. if (lua_interface) {
  4469. player = lua_interface->GetSpawn(state);
  4470. lua_interface->ResetFunctionStack(state);
  4471. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4472. if ((client = ((Player*)player)->GetClient()))
  4473. client->HandInCollections();
  4474. }
  4475. return 0;
  4476. }
  4477. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4478. Spawn* widget;
  4479. if (lua_interface) {
  4480. widget = lua_interface->GetSpawn(state);
  4481. lua_interface->ResetFunctionStack(state);
  4482. if (widget && widget->IsWidget())
  4483. ((Widget*)widget)->HandleUse(nullptr, "");
  4484. }
  4485. return 0;
  4486. }
  4487. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4488. Spawn* spawn = 0;
  4489. int32 primary_list = 0;
  4490. int32 secondary_list = 0;
  4491. if (lua_interface) {
  4492. spawn = lua_interface->GetSpawn(state);
  4493. primary_list = lua_interface->GetInt32Value(state, 2);
  4494. secondary_list = lua_interface->GetInt32Value(state, 3);
  4495. lua_interface->ResetFunctionStack(state);
  4496. if (!spawn->IsNPC()) {
  4497. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4498. return 0;
  4499. }
  4500. NPC* npc = (NPC*)spawn;
  4501. npc->SetPrimarySpellList(primary_list);
  4502. npc->SetSecondarySpellList(secondary_list);
  4503. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4504. }
  4505. return 0;
  4506. }
  4507. int EQ2Emu_lua_GetPet(lua_State* state) {
  4508. if (!lua_interface)
  4509. return 0;
  4510. Spawn* spawn = lua_interface->GetSpawn(state);
  4511. lua_interface->ResetFunctionStack(state);
  4512. if (spawn) {
  4513. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4514. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4515. return 1;
  4516. }
  4517. }
  4518. return 0;
  4519. }
  4520. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4521. if (!lua_interface)
  4522. return 0;
  4523. Spawn* spawn = lua_interface->GetSpawn(state);
  4524. lua_interface->ResetFunctionStack(state);
  4525. if (spawn) {
  4526. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4527. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4528. return 1;
  4529. }
  4530. }
  4531. return 0;
  4532. }
  4533. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4534. if (!lua_interface)
  4535. return 0;
  4536. Spawn* spawn = lua_interface->GetSpawn(state);
  4537. lua_interface->ResetFunctionStack(state);
  4538. if (spawn) {
  4539. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4540. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4541. return 1;
  4542. }
  4543. }
  4544. return 0;
  4545. }
  4546. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4547. if (!lua_interface)
  4548. return 0;
  4549. Spawn* spawn = lua_interface->GetSpawn(state);
  4550. lua_interface->ResetFunctionStack(state);
  4551. if (spawn) {
  4552. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4553. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4554. return 1;
  4555. }
  4556. }
  4557. return 0;
  4558. }
  4559. int EQ2Emu_lua_Charm(lua_State* state) {
  4560. if (!lua_interface)
  4561. return 0;
  4562. Spawn* owner = lua_interface->GetSpawn(state);
  4563. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4564. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4565. lua_interface->ResetFunctionStack(state);
  4566. if (!luaspell) {
  4567. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4568. return 0;
  4569. }
  4570. if(luaspell->resisted) {
  4571. return 0;
  4572. }
  4573. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4574. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4575. pet->SetPet(true);
  4576. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4577. ((NPC*)pet)->SetOwner((Entity*)owner);
  4578. // If owner is player and player does not have a summoned pet set the players charsheet
  4579. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4580. Player* player = (Player*)owner;
  4581. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4582. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4583. player->GetInfoStruct()->set_pet_movement(2);
  4584. player->GetInfoStruct()->set_pet_behavior(3);
  4585. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4586. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4587. // Make sure the values get sent to the client
  4588. player->SetCharSheetChanged(true);
  4589. }
  4590. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4591. pet->SetSpawnScript("");
  4592. // Set faction to the same as the owner
  4593. pet->SetFactionID(owner->GetFactionID());
  4594. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4595. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4596. // Clear hate list
  4597. ((NPC*)pet)->Brain()->ClearHate();
  4598. // Set the brain to a pet brain
  4599. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4600. }
  4601. return 0;
  4602. }
  4603. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4604. if (!lua_interface)
  4605. return 0;
  4606. Spawn* spawn = lua_interface->GetSpawn(state);
  4607. lua_interface->ResetFunctionStack(state);
  4608. if (!spawn) {
  4609. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4610. return 0;
  4611. }
  4612. vector<Spawn*> groupMembers;
  4613. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4614. groupMembers = *spawn->GetSpawnGroup();
  4615. }
  4616. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4617. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4618. deque<GroupMemberInfo*>::iterator itr;
  4619. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4620. if (group)
  4621. {
  4622. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4623. deque<GroupMemberInfo*>* members = group->GetMembers();
  4624. GroupMemberInfo* info = 0;
  4625. for (itr = members->begin(); itr != members->end(); itr++) {
  4626. info = *itr;
  4627. if (info->client)
  4628. groupMembers.push_back(info->client->GetPlayer());
  4629. }
  4630. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4631. }
  4632. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4633. }
  4634. else
  4635. return 0;
  4636. lua_createtable(state, groupMembers.size(), 0);
  4637. int newTable = lua_gettop(state);
  4638. for (int32 i = 0; i < groupMembers.size(); i++) {
  4639. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4640. lua_rawseti(state, newTable, i + 1);
  4641. }
  4642. return 1;
  4643. }
  4644. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4645. if (!lua_interface)
  4646. return 0;
  4647. lua_interface->ResetFunctionStack(state);
  4648. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4649. lua_interface->SetOptionWindowValue(state, option_window);
  4650. return 1;
  4651. }
  4652. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4653. if (!lua_interface)
  4654. return 0;
  4655. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4656. if (option_window) {
  4657. OptionWindowOption option_window_option;
  4658. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4659. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4660. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4661. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4662. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4663. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4664. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4665. option_window->push_back(option_window_option);
  4666. }
  4667. lua_interface->ResetFunctionStack(state);
  4668. return 0;
  4669. }
  4670. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4671. if (!lua_interface)
  4672. return 0;
  4673. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4674. Spawn* player = lua_interface->GetSpawn(state, 2);
  4675. string window_title = lua_interface->GetStringValue(state, 3);
  4676. string cancel_command = lua_interface->GetStringValue(state, 4);
  4677. lua_interface->ResetFunctionStack(state);
  4678. if (!player->IsPlayer()) {
  4679. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4680. return 0;
  4681. }
  4682. Client* client = ((Player*)player)->GetClient();
  4683. if (option_window && window_title.length() > 0 && client) {
  4684. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4685. if (!packet)
  4686. return 0;
  4687. packet->setDataByName("title_text", window_title.c_str());
  4688. if (cancel_command.length() > 0)
  4689. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4690. packet->setArrayLengthByName("num_selections", option_window->size());
  4691. vector<OptionWindowOption>::iterator itr;
  4692. int8 i = 0;
  4693. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4694. OptionWindowOption opt = *itr;
  4695. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4696. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4697. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4698. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4699. if (opt.optionCommand.length() > 0)
  4700. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4701. if (opt.optionConfirmTitle.length() > 0)
  4702. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4703. i++;
  4704. }
  4705. client->QueuePacket(packet->serialize());
  4706. lua_interface->SetLuaUserDataStale(option_window);
  4707. safe_delete(option_window);
  4708. safe_delete(packet);
  4709. }
  4710. return 0;
  4711. }
  4712. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4713. if (!lua_interface)
  4714. return 0;
  4715. Spawn* spawn = lua_interface->GetSpawn(state);
  4716. lua_interface->ResetFunctionStack(state);
  4717. if (spawn) {
  4718. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4719. return 1;
  4720. }
  4721. else
  4722. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4723. return 0;
  4724. }
  4725. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4726. if (!lua_interface)
  4727. return 0;
  4728. Spawn* spawn = lua_interface->GetSpawn(state);
  4729. lua_interface->ResetFunctionStack(state);
  4730. if (spawn) {
  4731. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4732. return 1;
  4733. }
  4734. else
  4735. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4736. return 0;
  4737. }
  4738. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4739. if (!lua_interface)
  4740. return 0;
  4741. Spawn* spawn = lua_interface->GetSpawn(state);
  4742. lua_interface->ResetFunctionStack(state);
  4743. if (spawn) {
  4744. int8 class_id = spawn->GetTradeskillClass();
  4745. // Need to add 42 for the offset in the array
  4746. class_id += 44;
  4747. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4748. return 1;
  4749. }
  4750. else
  4751. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4752. return 0;
  4753. }
  4754. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4755. if (!lua_interface)
  4756. return 0;
  4757. Spawn* spawn = lua_interface->GetSpawn(state);
  4758. int16 level = lua_interface->GetInt8Value(state, 2);
  4759. lua_interface->ResetFunctionStack(state);
  4760. if (spawn) {
  4761. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4762. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4763. else
  4764. spawn->SetTSLevel(level);
  4765. }
  4766. else
  4767. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4768. return 0;
  4769. }
  4770. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4771. if (!lua_interface)
  4772. return 0;
  4773. Spawn* spawn = lua_interface->GetSpawn(state);
  4774. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4775. lua_interface->ResetFunctionStack(state);
  4776. if (spawn) {
  4777. spawn->SetAttackable(attackable);
  4778. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4779. }
  4780. return 0;
  4781. }
  4782. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4783. // Check to see if we have a valid lua_interface
  4784. if (!lua_interface)
  4785. return 0;
  4786. // Get the spawn that is getting the pet
  4787. Spawn* spawn = lua_interface->GetSpawn(state);
  4788. // Get the DB ID of the pet
  4789. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4790. // The max level the pet can gain
  4791. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4792. // Get the spell that this command was called from
  4793. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4794. lua_interface->ResetFunctionStack(state);
  4795. // Check to make sure the spawn pointer is valid
  4796. if (!spawn) {
  4797. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4798. return 0;
  4799. }
  4800. // Check to make sure the spawn is an entity
  4801. if (!spawn->IsEntity()) {
  4802. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4803. return 0;
  4804. }
  4805. // Check to make sure the spawn doesn't already have a pet of this type
  4806. if (((Entity*)spawn)->GetPet()) {
  4807. if (spawn->IsPlayer()) {
  4808. Client* client = ((Player*)spawn)->GetClient();
  4809. if (client)
  4810. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4811. }
  4812. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4813. return 0;
  4814. }
  4815. // Check to see if the DB ID for the pet is set
  4816. if (pet_id == 0) {
  4817. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4818. return 0;
  4819. }
  4820. // Check to see if the pointer to the spell is valid
  4821. if (!luaspell) {
  4822. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4823. return 0;
  4824. }
  4825. if(luaspell->resisted) {
  4826. return 0;
  4827. }
  4828. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4829. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4830. if (!pet) {
  4831. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4832. return 0;
  4833. }
  4834. // Check to make sure the pet is an npc
  4835. if (!pet->IsNPC()) {
  4836. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4837. return 0;
  4838. }
  4839. // Spawn the pet at the same location as the owner
  4840. pet->SetX(spawn->GetX());
  4841. pet->SetY(spawn->GetY());
  4842. pet->SetZ(spawn->GetZ());
  4843. pet->SetLocation(spawn->GetLocation());
  4844. pet->SetHeading(spawn->GetHeading());
  4845. spawn->GetZone()->AddSpawn(pet);
  4846. const char* spawn_script = world.GetSpawnScript(pet_id);
  4847. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4848. spawn->SetSpawnScript(string(spawn_script));
  4849. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4850. }
  4851. std::string petName = std::string("");
  4852. if(spawn->IsEntity()) {
  4853. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  4854. }
  4855. if(petName.size() < 1) {
  4856. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4857. petName = spawn->GetZone()->pet_names.at(rand_index);
  4858. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  4859. }
  4860. // If player set various values for the char sheet (pet window)
  4861. if (spawn->IsPlayer()) {
  4862. Player* player = (Player*)spawn;
  4863. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4864. player->GetInfoStruct()->set_pet_name(petName);
  4865. player->GetInfoStruct()->set_pet_movement(2);
  4866. player->GetInfoStruct()->set_pet_behavior(3);
  4867. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4868. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4869. // Make sure the values get sent to the client
  4870. player->SetCharSheetChanged(true);
  4871. }
  4872. // Set the pets name
  4873. pet->SetName(petName.c_str());
  4874. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4875. if (max_level > 0)
  4876. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4877. else
  4878. pet->SetLevel(spawn->GetLevel());
  4879. // Set the max level this pet can reach
  4880. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4881. // Set the faction of the pet to the same faction as the owner
  4882. pet->SetFactionID(spawn->GetFactionID());
  4883. // Set the spawn as a pet
  4884. pet->SetPet(true);
  4885. // Give a pointer of the owner to the pet
  4886. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4887. // Give a pointer of the pet to the owner
  4888. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4889. // Set the pet type
  4890. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4891. // Set the spell id used to create this pet
  4892. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4893. // Set the spell tier used to create this pet
  4894. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4895. // Set the pets spawn type to 6
  4896. pet->SetSpawnType(6);
  4897. // Set the pets brain
  4898. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4899. // Check to see if the pet has a subtitle
  4900. if (strlen(pet->GetSubTitle()) > 0) {
  4901. // Add the players name to the front of the sub title
  4902. string pet_subtitle;
  4903. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4904. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4905. // Set the pets subtitle to the new one
  4906. pet->SetSubTitle(pet_subtitle.c_str());
  4907. }
  4908. // Add the "Pet Options" entity command to the pet
  4909. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4910. // Set the pet as the return value for this function
  4911. lua_interface->SetSpawnValue(state, pet);
  4912. return 1;
  4913. }
  4914. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4915. if (!lua_interface)
  4916. return 0;
  4917. Spawn* spawn = lua_interface->GetSpawn(state);
  4918. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4919. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4920. lua_interface->ResetFunctionStack(state);
  4921. if (!spawn) {
  4922. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4923. return 0;
  4924. }
  4925. if (!spawn->IsEntity()) {
  4926. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4927. return 0;
  4928. }
  4929. if (((Entity*)spawn)->GetDeityPet()) {
  4930. if (spawn->IsPlayer()) {
  4931. Client* client = ((Player*)spawn)->GetClient();
  4932. if (client)
  4933. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4934. }
  4935. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4936. return 0;
  4937. }
  4938. if (pet_id == 0) {
  4939. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4940. return 0;
  4941. }
  4942. if (!luaspell) {
  4943. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4944. return 0;
  4945. }
  4946. if(luaspell->resisted) {
  4947. return 0;
  4948. }
  4949. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4950. if (!pet) {
  4951. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4952. return 0;
  4953. }
  4954. if (!pet->IsNPC()) {
  4955. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4956. return 0;
  4957. }
  4958. pet->SetX(spawn->GetX());
  4959. pet->SetY(spawn->GetY());
  4960. pet->SetZ(spawn->GetZ());
  4961. pet->SetLocation(spawn->GetLocation());
  4962. pet->SetHeading(spawn->GetHeading());
  4963. spawn->GetZone()->AddSpawn(pet);
  4964. string random_pet_name;
  4965. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4966. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4967. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4968. pet->SetName(random_pet_name.c_str());
  4969. pet->SetLevel(spawn->GetLevel());
  4970. pet->SetFactionID(spawn->GetFactionID());
  4971. pet->SetPet(true);
  4972. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4973. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4974. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4975. pet->SetSpawnType(6);
  4976. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4977. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4978. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4979. if (strlen(pet->GetSubTitle()) > 0) {
  4980. string pet_subtitle;
  4981. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4982. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4983. pet->SetSubTitle(pet_subtitle.c_str());
  4984. }
  4985. // deity and cosmetic pets are not attackable
  4986. pet->SetAttackable(false);
  4987. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4988. lua_interface->SetSpawnValue(state, pet);
  4989. return 1;
  4990. }
  4991. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4992. if (!lua_interface)
  4993. return 0;
  4994. Spawn* spawn = lua_interface->GetSpawn(state);
  4995. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4996. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4997. lua_interface->ResetFunctionStack(state);
  4998. if (!spawn) {
  4999. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5000. return 0;
  5001. }
  5002. if (!spawn->IsEntity()) {
  5003. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5004. return 0;
  5005. }
  5006. if (((Entity*)spawn)->GetCosmeticPet()) {
  5007. if (spawn->IsPlayer()) {
  5008. Client* client = ((Player*)spawn)->GetClient();
  5009. if (client)
  5010. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5011. }
  5012. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5013. return 0;
  5014. }
  5015. if (pet_id == 0) {
  5016. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5017. return 0;
  5018. }
  5019. if (!luaspell) {
  5020. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5021. return 0;
  5022. }
  5023. if(luaspell->resisted) {
  5024. return 0;
  5025. }
  5026. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5027. if (!pet) {
  5028. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5029. return 0;
  5030. }
  5031. if (!pet->IsNPC()) {
  5032. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5033. return 0;
  5034. }
  5035. pet->SetX(spawn->GetX());
  5036. pet->SetY(spawn->GetY());
  5037. pet->SetZ(spawn->GetZ());
  5038. pet->SetLocation(spawn->GetLocation());
  5039. pet->SetHeading(spawn->GetHeading());
  5040. spawn->GetZone()->AddSpawn(pet);
  5041. string random_pet_name;
  5042. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5043. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5044. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5045. pet->SetName(random_pet_name.c_str());
  5046. pet->SetLevel(spawn->GetLevel());
  5047. pet->SetFactionID(spawn->GetFactionID());
  5048. pet->SetPet(true);
  5049. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5050. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5051. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5052. pet->SetSpawnType(6);
  5053. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5054. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5055. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5056. if (strlen(pet->GetSubTitle()) > 0) {
  5057. string pet_subtitle;
  5058. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5059. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5060. pet->SetSubTitle(pet_subtitle.c_str());
  5061. }
  5062. pet->SetAttackable(false);
  5063. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5064. lua_interface->SetSpawnValue(state, pet);
  5065. return 1;
  5066. }
  5067. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5068. if (!lua_interface)
  5069. return 0;
  5070. Spawn* spawn = lua_interface->GetSpawn(state);
  5071. lua_interface->ResetFunctionStack(state);
  5072. if (!spawn) {
  5073. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5074. return 0;
  5075. }
  5076. if (!spawn->IsPet()) {
  5077. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5078. return 0;
  5079. }
  5080. if (!((NPC*)spawn)->IsDismissing())
  5081. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5082. return 0;
  5083. }
  5084. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5085. if (!lua_interface)
  5086. return 0;
  5087. Quest* quest = lua_interface->GetQuest(state);
  5088. if (!quest) {
  5089. 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));
  5090. lua_interface->ResetFunctionStack(state);
  5091. return 0;
  5092. }
  5093. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5094. lua_interface->ResetFunctionStack(state);
  5095. if (feather_color > 0)
  5096. quest->SetFeatherColor(feather_color);
  5097. return 0;
  5098. }
  5099. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5100. if (!lua_interface)
  5101. return 0;
  5102. Spawn* spawn = lua_interface->GetSpawn(state);
  5103. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5104. lua_interface->ResetFunctionStack(state);
  5105. if (!spawn) {
  5106. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5107. return 0;
  5108. }
  5109. if (!spawn2) {
  5110. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5111. return 0;
  5112. }
  5113. spawn->RemoveSpawnAccess(spawn2);
  5114. return 0;
  5115. }
  5116. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5117. if (!lua_interface)
  5118. return 0;
  5119. ZoneServer* zone = lua_interface->GetZone(state);
  5120. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5121. lua_interface->ResetFunctionStack(state);
  5122. if (!zone) {
  5123. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5124. return 0;
  5125. }
  5126. if (location_id == 0) {
  5127. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5128. return 0;
  5129. }
  5130. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5131. if (!location) {
  5132. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5133. return 0;
  5134. }
  5135. Spawn* spawn = 0;
  5136. if (location->entities[0]) {
  5137. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5138. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5139. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5140. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5141. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5142. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5143. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5144. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5145. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5146. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5147. if(spawn && spawn->IsOmittedByDBFlag())
  5148. {
  5149. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5150. safe_delete(spawn);
  5151. spawn = 0;
  5152. return 0;
  5153. }
  5154. if (spawn) {
  5155. const char* script = 0;
  5156. for (int x = 0; x < 3; x++) {
  5157. switch (x) {
  5158. case 0:
  5159. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5160. break;
  5161. case 1:
  5162. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5163. break;
  5164. case 2:
  5165. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5166. break;
  5167. }
  5168. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5169. spawn->SetSpawnScript(string(script));
  5170. break;
  5171. }
  5172. }
  5173. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5174. lua_interface->SetSpawnValue(state, spawn);
  5175. return 1;
  5176. }
  5177. else {
  5178. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5179. safe_delete(spawn);
  5180. }
  5181. }
  5182. return 0;
  5183. }
  5184. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5185. if (!lua_interface)
  5186. return 0;
  5187. Spawn* caster = lua_interface->GetSpawn(state);
  5188. Spawn* target = lua_interface->GetSpawn(state, 2);
  5189. int32 id = lua_interface->GetInt32Value(state, 3);
  5190. string command = lua_interface->GetStringValue(state, 4);
  5191. lua_interface->ResetFunctionStack(state);
  5192. if (!caster) {
  5193. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5194. return 0;
  5195. }
  5196. if (!target) {
  5197. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5198. return 0;
  5199. }
  5200. if (!caster->IsPlayer()) {
  5201. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5202. return 0;
  5203. }
  5204. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5205. if (!entity_command) {
  5206. 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());
  5207. return 0;
  5208. }
  5209. Client* client = ((Player*)caster)->GetClient();
  5210. if (!client) {
  5211. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5212. return 0;
  5213. }
  5214. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5215. return 0;
  5216. }
  5217. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5218. if (!lua_interface)
  5219. return 0;
  5220. Spawn* spawn = lua_interface->GetSpawn(state);
  5221. lua_interface->ResetFunctionStack(state);
  5222. if (!spawn) {
  5223. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5224. return 0;
  5225. }
  5226. if (!spawn->IsNPC()) {
  5227. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5228. return 0;
  5229. }
  5230. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5231. return 0;
  5232. }
  5233. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5234. if (!lua_interface)
  5235. return 0;
  5236. Spawn* spawn = lua_interface->GetSpawn(state);
  5237. int16 tick = lua_interface->GetInt16Value(state, 2);
  5238. lua_interface->ResetFunctionStack(state);
  5239. if (!spawn) {
  5240. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5241. return 0;
  5242. }
  5243. if (!spawn->IsNPC()) {
  5244. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5245. return 0;
  5246. }
  5247. if (tick < 20) {
  5248. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5249. return 0;
  5250. }
  5251. ((NPC*)spawn)->Brain()->SetTick(tick);
  5252. return 0;
  5253. }
  5254. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5255. if (!lua_interface)
  5256. return 0;
  5257. Spawn* spawn = lua_interface->GetSpawn(state);
  5258. Spawn* target = lua_interface->GetSpawn(state, 2);
  5259. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5260. lua_interface->ResetFunctionStack(state);
  5261. if (!spawn) {
  5262. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5263. return 0;
  5264. }
  5265. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5266. spawn->SetFollowTarget(target, follow_distance);
  5267. return 0;
  5268. }
  5269. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5270. if (!lua_interface)
  5271. return 0;
  5272. Spawn* spawn = lua_interface->GetSpawn(state);
  5273. lua_interface->ResetFunctionStack(state);
  5274. if (!spawn) {
  5275. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5276. return 0;
  5277. }
  5278. Spawn* target = spawn->GetFollowTarget();
  5279. if (target) {
  5280. lua_interface->SetSpawnValue(state, target);
  5281. return 1;
  5282. }
  5283. return 0;
  5284. }
  5285. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5286. if (!lua_interface)
  5287. return 0;
  5288. Spawn* spawn = lua_interface->GetSpawn(state);
  5289. lua_interface->ResetFunctionStack(state);
  5290. if (!spawn) {
  5291. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5292. return 0;
  5293. }
  5294. if (spawn->following)
  5295. spawn->following = false;
  5296. else
  5297. spawn->following = true;
  5298. return 0;
  5299. }
  5300. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5301. if (!lua_interface)
  5302. return 0;
  5303. Spawn* spawn = lua_interface->GetSpawn(state);
  5304. lua_interface->ResetFunctionStack(state);
  5305. if (!spawn) {
  5306. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5307. return 0;
  5308. }
  5309. lua_interface->SetBooleanValue(state, spawn->following);
  5310. return 1;
  5311. }
  5312. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5313. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5314. // I will attempt to explain how this function works for future refrence
  5315. // Fist lets make sure lua_interface is valid, if not return out
  5316. if (!lua_interface)
  5317. return 0;
  5318. // Next we grab the first 2 params same as we usually would
  5319. Spawn* spawn = lua_interface->GetSpawn(state);
  5320. string var = lua_interface->GetStringValue(state, 2);
  5321. // 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
  5322. // 1 = Spawn
  5323. // 2 = Zone
  5324. // 3 = Item
  5325. // 4 = Quest
  5326. // 5 = String
  5327. // 6 = nil (null)
  5328. int8 dataType = 0;
  5329. // Define pointers for each potential type
  5330. Spawn* spawnVal = 0;
  5331. ZoneServer* zone = 0;
  5332. Item* item = 0;
  5333. Quest* quest = 0;
  5334. string val;
  5335. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5336. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5337. // options window are also light user data be we do not handle those.
  5338. // We check with lua_islightuserdata(lua_State*, index)
  5339. if (lua_islightuserdata(state, 3)) {
  5340. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5341. // and convert it to LUAUserData*
  5342. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5343. // Check to make sure the data we got is valid, if not give an error
  5344. if (!data || !data->IsCorrectlyInitialized()) {
  5345. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5346. }
  5347. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5348. else if (data->IsSpawn()) {
  5349. spawnVal = data->spawn;
  5350. dataType = 1;
  5351. }
  5352. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5353. else if (data->IsZone()) {
  5354. zone = data->zone;
  5355. dataType = 2;
  5356. }
  5357. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5358. else if (data->IsItem()) {
  5359. item = data->item;
  5360. dataType = 3;
  5361. }
  5362. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5363. else if (data->IsQuest()) {
  5364. quest = data->quest;
  5365. dataType = 4;
  5366. }
  5367. }
  5368. // Wasn't light user data, check if it is nil(null)
  5369. else if (lua_isnil(state, 3)) {
  5370. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5371. dataType = 6;
  5372. }
  5373. // Wasn't light user data or nil (null), must be a string
  5374. else {
  5375. // Set the string and dataType variable
  5376. val = lua_interface->GetStringValue(state, 3);
  5377. dataType = 5;
  5378. }
  5379. lua_interface->ResetFunctionStack(state);
  5380. // We now have all the params, lets check to make sure they are valid
  5381. if (!spawn) {
  5382. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5383. return 0;
  5384. }
  5385. if (var.length() == 0) {
  5386. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5387. return 0;
  5388. }
  5389. if (dataType == 0) {
  5390. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5391. return 0;
  5392. }
  5393. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5394. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5395. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5396. switch (dataType) {
  5397. case 1:
  5398. // 1 = Spawn
  5399. spawn->AddTempVariable(var, spawnVal);
  5400. break;
  5401. case 2:
  5402. // 2 = Zone
  5403. spawn->AddTempVariable(var, zone);
  5404. break;
  5405. case 3:
  5406. // 3 = Item
  5407. spawn->AddTempVariable(var, item);
  5408. break;
  5409. case 4:
  5410. // 4 = Quest
  5411. spawn->AddTempVariable(var, quest);
  5412. break;
  5413. case 5:
  5414. // 5 = String
  5415. spawn->AddTempVariable(var, val);
  5416. break;
  5417. case 6:
  5418. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5419. spawn->DeleteTempVariable(var);
  5420. break;
  5421. }
  5422. // And we are done so return out
  5423. return 0;
  5424. }
  5425. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5426. if (!lua_interface)
  5427. return 0;
  5428. Spawn* spawn = lua_interface->GetSpawn(state);
  5429. string var = lua_interface->GetStringValue(state, 2);
  5430. lua_interface->ResetFunctionStack(state);
  5431. if (!spawn) {
  5432. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5433. return 0;
  5434. }
  5435. if (var.length() == 0) {
  5436. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5437. return 0;
  5438. }
  5439. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5440. int8 type = spawn->GetTempVariableType(var);
  5441. Spawn* spawn2 = 0;
  5442. ZoneServer* zone = 0;
  5443. Item* item = 0;
  5444. Quest* quest = 0;
  5445. // Set the lua function return value based on the type of data the variable contains
  5446. switch (type) {
  5447. case 1:
  5448. spawn2 = spawn->GetTempVariableSpawn(var);
  5449. if (!spawn2)
  5450. return 0;
  5451. lua_interface->SetSpawnValue(state, spawn2);
  5452. break;
  5453. case 2:
  5454. zone = spawn->GetTempVariableZone(var);
  5455. if (!zone)
  5456. return 0;
  5457. lua_interface->SetZoneValue(state, zone);
  5458. break;
  5459. case 3:
  5460. item = spawn->GetTempVariableItem(var);
  5461. if (!item)
  5462. return 0;
  5463. lua_interface->SetItemValue(state, item);
  5464. break;
  5465. case 4:
  5466. quest = spawn->GetTempVariableQuest(var);
  5467. if (!quest)
  5468. return 0;
  5469. lua_interface->SetQuestValue(state, quest);
  5470. break;
  5471. case 5:
  5472. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5473. break;
  5474. default:
  5475. // Not a valid type then the variable was not set so return out
  5476. return 0;
  5477. }
  5478. // Return value was set so return out
  5479. return 1;
  5480. }
  5481. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5482. {
  5483. if (!lua_interface)
  5484. return 0;
  5485. Quest* quest = lua_interface->GetQuest(state);
  5486. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5487. string description = lua_interface->GetStringValue(state, 3);
  5488. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5489. if (!quest) {
  5490. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5491. lua_interface->ResetFunctionStack(state);
  5492. lua_interface->SetBooleanValue(state, false);
  5493. return 1;
  5494. }
  5495. if (!spawn) {
  5496. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5497. lua_interface->ResetFunctionStack(state);
  5498. lua_interface->SetBooleanValue(state, false);
  5499. return 1;
  5500. }
  5501. if (!spawn->IsPlayer()) {
  5502. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5503. lua_interface->ResetFunctionStack(state);
  5504. lua_interface->SetBooleanValue(state, false);
  5505. return 1;
  5506. }
  5507. if (item_id == 0) {
  5508. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5509. lua_interface->ResetFunctionStack(state);
  5510. lua_interface->SetBooleanValue(state, false);
  5511. return 1;
  5512. }
  5513. Client* client = ((Player*)spawn)->GetClient();
  5514. if (!client) {
  5515. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5516. lua_interface->ResetFunctionStack(state);
  5517. lua_interface->SetBooleanValue(state, false);
  5518. return 1;
  5519. }
  5520. Item* item = master_item_list.GetItem(item_id);
  5521. if (!item) {
  5522. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5523. lua_interface->ResetFunctionStack(state);
  5524. lua_interface->SetBooleanValue(state, false);
  5525. return 1;
  5526. }
  5527. Item* firstItem = new Item(item);
  5528. quest->AddTmpRewardItem(firstItem);
  5529. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5530. bool itemsAddedSuccessfully = true;
  5531. if(num_args > 4)
  5532. {
  5533. for(int8 n=5;n<num_args+1;n++)
  5534. {
  5535. int32 new_item = lua_interface->GetInt32Value(state, n);
  5536. Item* tmpItem = master_item_list.GetItem(new_item);
  5537. if(tmpItem)
  5538. {
  5539. Item* newTmpItem = new Item(tmpItem);
  5540. quest->AddTmpRewardItem(newTmpItem);
  5541. }
  5542. else
  5543. itemsAddedSuccessfully = false;
  5544. }
  5545. }
  5546. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5547. lua_interface->ResetFunctionStack(state);
  5548. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5549. return 1;
  5550. }
  5551. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5552. if (!lua_interface)
  5553. return 0;
  5554. Quest* quest = lua_interface->GetQuest(state);
  5555. lua_interface->ResetFunctionStack(state);
  5556. if (!quest) {
  5557. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5558. return 0;
  5559. }
  5560. quest->SetRepeatable(true);
  5561. return 0;
  5562. }
  5563. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5564. if (!lua_interface)
  5565. return 0;
  5566. Spawn* spawn = lua_interface->GetSpawn(state);
  5567. lua_interface->ResetFunctionStack(state);
  5568. if (!spawn) {
  5569. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5570. return 0;
  5571. }
  5572. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5573. string ret = classes.GetClassNameCase(base_class);
  5574. if (ret.length() > 0) {
  5575. lua_interface->SetStringValue(state, ret.c_str());
  5576. return 1;
  5577. }
  5578. return 0;
  5579. }
  5580. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5581. if (!lua_interface)
  5582. return 0;
  5583. Spawn* player = lua_interface->GetSpawn(state);
  5584. lua_interface->ResetFunctionStack(state);
  5585. if (player && player->IsPlayer()) {
  5586. Client* client = player->GetClient();
  5587. if (client)
  5588. client->SendWaypoints();
  5589. }
  5590. return 0;
  5591. }
  5592. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5593. if (!lua_interface)
  5594. return 0;
  5595. Spawn* player = lua_interface->GetSpawn(state);
  5596. string name = lua_interface->GetStringValue(state, 2);
  5597. int32 type = lua_interface->GetInt32Value(state, 3);
  5598. lua_interface->ResetFunctionStack(state);
  5599. if (type == 0)
  5600. type = 2;
  5601. if (name.length() > 0) {
  5602. if (player && player->IsPlayer()) {
  5603. Client* client = player->GetClient();
  5604. if (client)
  5605. client->AddWaypoint(name, type);
  5606. }
  5607. }
  5608. return 0;
  5609. }
  5610. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5611. if (!lua_interface)
  5612. return 0;
  5613. Spawn* player = lua_interface->GetSpawn(state);
  5614. string name = lua_interface->GetStringValue(state, 2);
  5615. lua_interface->ResetFunctionStack(state);
  5616. if (name.length() > 0) {
  5617. if (player && player->IsPlayer()) {
  5618. Client* client = player->GetClient();
  5619. if (client)
  5620. client->RemoveWaypoint(name);
  5621. }
  5622. }
  5623. return 0;
  5624. }
  5625. int EQ2Emu_lua_AddWard(lua_State* state) {
  5626. if (!lua_interface)
  5627. return 0;
  5628. int32 damage = lua_interface->GetInt32Value(state);
  5629. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5630. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5631. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5632. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5633. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5634. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5635. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5636. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5637. lua_interface->ResetFunctionStack(state);
  5638. if(!spell || spell->resisted) {
  5639. return 0;
  5640. }
  5641. bool ward_was_added = false;
  5642. ZoneServer* zone = spell->caster->GetZone();
  5643. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5644. for (int32 i = 0; i < spell->targets.size(); i++) {
  5645. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5646. if (!target)
  5647. continue;
  5648. if (target->IsEntity()) {
  5649. // If the ward is already active remove it
  5650. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5651. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5652. // Create new ward info
  5653. WardInfo* ward = new WardInfo;
  5654. ward->Spell = spell;
  5655. ward->BaseDamage = damage;
  5656. ward->DamageLeft = damage;
  5657. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5658. ward->keepWard = keepWard;
  5659. ward->WardType = wardType;
  5660. if (damageAbsorptionPercent > 100)
  5661. damageAbsorptionPercent = 100;
  5662. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5663. if (damageAbsorptionMaxHealthPercent > 100)
  5664. damageAbsorptionMaxHealthPercent = 100;
  5665. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5666. ward->RedirectDamagePercent = redirectDamagePercent;
  5667. ward->LastRedirectDamage = 0;
  5668. ward->LastAbsorbedDamage = 0;
  5669. ward->HitCount = 0;
  5670. spell->num_triggers = maxHitCount;
  5671. spell->had_triggers = true;
  5672. spell->cancel_after_all_triggers = false;
  5673. ward->MaxHitCount = maxHitCount;
  5674. if (wardType == WARD_TYPE_MAGICAL)
  5675. ward->DamageType = damageTypes;
  5676. // Add the ward to the entity
  5677. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5678. ward_was_added = true;
  5679. }
  5680. }
  5681. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5682. if (ward_was_added && spell->caster->IsPlayer()) {
  5683. spell->had_dmg_remaining = true;
  5684. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5685. }
  5686. return 0;
  5687. }
  5688. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5689. if (!lua_interface)
  5690. return 0;
  5691. int32 amount = lua_interface->GetInt32Value(state);
  5692. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5693. lua_interface->ResetFunctionStack(state);
  5694. WardInfo* ward = 0;
  5695. if(!spell || spell->resisted) {
  5696. return 0;
  5697. }
  5698. ZoneServer* zone = spell->caster->GetZone();
  5699. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5700. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5701. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5702. ward = target->GetWard(spell->spell->GetSpellID());
  5703. if (target && ward) {
  5704. ward->DamageLeft += amount;
  5705. if (ward->DamageLeft > ward->BaseDamage)
  5706. ward->DamageLeft = ward->BaseDamage;
  5707. for (int32 i = 0; i < spell->targets.size(); i++) {
  5708. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5709. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5710. }
  5711. }
  5712. }
  5713. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5714. if (ward && spell->caster->IsPlayer())
  5715. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5716. return 0;
  5717. }
  5718. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5719. if (!lua_interface)
  5720. return 0;
  5721. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5722. lua_interface->ResetFunctionStack(state);
  5723. if (!spell) {
  5724. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5725. return 0;
  5726. }
  5727. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5728. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5729. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5730. if (ward) {
  5731. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5732. return 1;
  5733. }
  5734. }
  5735. return 0;
  5736. }
  5737. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5738. if (!lua_interface)
  5739. return 0;
  5740. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5741. if (!spell) {
  5742. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5743. lua_interface->ResetFunctionStack(state);
  5744. return 0;
  5745. }
  5746. string type = lua_interface->GetStringValue(state, 2);
  5747. lua_interface->ResetFunctionStack(state);
  5748. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5749. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5750. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5751. if (ward) {
  5752. if (boost::iequals(type, "damageleft"))
  5753. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5754. else if (boost::iequals(type, "basedamage"))
  5755. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5756. else if (boost::iequals(type, "keepward"))
  5757. lua_interface->SetBooleanValue(state, ward->keepWard);
  5758. else if (boost::iequals(type, "wardtype"))
  5759. lua_interface->SetInt32Value(state, ward->WardType);
  5760. else if (boost::iequals(type, "dmgabsorptionpct"))
  5761. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5762. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5763. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5764. else if (boost::iequals(type, "redirectdamagepercent"))
  5765. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5766. else if (boost::iequals(type, "lastredirectdamage"))
  5767. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5768. else if (boost::iequals(type, "lastabsorbeddamage"))
  5769. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5770. else if (boost::iequals(type, "hitcount"))
  5771. lua_interface->SetInt32Value(state, ward->HitCount);
  5772. else if (boost::iequals(type, "maxhitcount"))
  5773. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5774. else
  5775. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5776. return 1;
  5777. }
  5778. }
  5779. return 0;
  5780. }
  5781. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5782. if (!lua_interface)
  5783. return 0;
  5784. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5785. lua_interface->ResetFunctionStack(state);
  5786. if(!spell) {
  5787. return 0;
  5788. }
  5789. ZoneServer* zone = spell->caster->GetZone();
  5790. Spawn* target = 0;
  5791. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5792. for (int32 i = 0; i < spell->targets.size(); i++) {
  5793. target = zone->GetSpawnByID(spell->targets.at(i));
  5794. if (target && target->IsEntity()) {
  5795. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5796. }
  5797. }
  5798. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5799. return 0;
  5800. }
  5801. int EQ2Emu_lua_Interrupt(lua_State* state)
  5802. {
  5803. if (!lua_interface)
  5804. return 0;
  5805. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5806. Spawn* target = lua_interface->GetSpawn(state, 2);
  5807. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5808. lua_interface->ResetFunctionStack(state);
  5809. if (!caster)
  5810. {
  5811. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5812. return 0;
  5813. }
  5814. if (!target)
  5815. {
  5816. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5817. return 0;
  5818. }
  5819. if (!spell) {
  5820. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5821. return 0;
  5822. }
  5823. if (!target->IsEntity() && !spell)
  5824. {
  5825. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5826. return 0;
  5827. }
  5828. if (!target && spell) {
  5829. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5830. for (int8 i = 0; i < spell->targets.size(); i++) {
  5831. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5832. if (!target || !target->IsEntity())
  5833. continue;
  5834. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5835. }
  5836. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5837. }
  5838. else
  5839. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5840. return 0;
  5841. }
  5842. int EQ2Emu_lua_Stealth(lua_State* state) {
  5843. if (!lua_interface)
  5844. return 0;
  5845. int8 type = lua_interface->GetInt8Value(state);
  5846. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5847. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5848. lua_interface->ResetFunctionStack(state);
  5849. if (!spell) {
  5850. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5851. return 0;
  5852. }
  5853. ZoneServer* zone = spell->caster->GetZone();
  5854. if (spawn) {
  5855. if (spawn->IsEntity()) {
  5856. if (type == 1) {
  5857. ((Entity*)spawn)->AddStealthSpell(spell);
  5858. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5859. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5860. }
  5861. else if (type == 2) {
  5862. ((Entity*)spawn)->AddInvisSpell(spell);
  5863. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5864. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5865. }
  5866. return 0;
  5867. }
  5868. else {
  5869. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5870. return 0;
  5871. }
  5872. }
  5873. else {
  5874. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5875. for (int32 i = 0; i < spell->targets.size(); i++) {
  5876. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5877. if (!spawn || !spawn->IsEntity())
  5878. continue;
  5879. if (type == 1) {
  5880. ((Entity*)spawn)->AddStealthSpell(spell);
  5881. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5882. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5883. }
  5884. else if (type == 2) {
  5885. ((Entity*)spawn)->AddInvisSpell(spell);
  5886. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5887. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5888. }
  5889. else {
  5890. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5891. break;
  5892. }
  5893. }
  5894. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5895. }
  5896. return 0;
  5897. }
  5898. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5899. if (!lua_interface)
  5900. return 0;
  5901. Spawn* spawn = lua_interface->GetSpawn(state);
  5902. lua_interface->ResetFunctionStack(state);
  5903. if (!spawn) {
  5904. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5905. return 0;
  5906. }
  5907. if (spawn->IsEntity()) {
  5908. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5909. return 1;
  5910. }
  5911. else
  5912. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5913. return 0;
  5914. }
  5915. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5916. if (!lua_interface)
  5917. return 0;
  5918. Spawn* spawn = lua_interface->GetSpawn(state);
  5919. lua_interface->ResetFunctionStack(state);
  5920. if (!spawn) {
  5921. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5922. return 0;
  5923. }
  5924. if (spawn->IsEntity()) {
  5925. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5926. return 1;
  5927. }
  5928. else
  5929. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5930. return 0;
  5931. }
  5932. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5933. if (!lua_interface)
  5934. return 0;
  5935. Spawn* player = lua_interface->GetSpawn(state);
  5936. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5937. lua_interface->ResetFunctionStack(state);
  5938. if (!player->IsPlayer()) {
  5939. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5940. return 0;
  5941. }
  5942. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5943. return 1;
  5944. }
  5945. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5946. if (!lua_interface)
  5947. return 0;
  5948. Spawn* spawn = lua_interface->GetSpawn(state);
  5949. int8 slot = lua_interface->GetInt8Value(state, 2);
  5950. lua_interface->ResetFunctionStack(state);
  5951. if (!spawn) {
  5952. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5953. return 0;
  5954. }
  5955. if (!spawn->IsEntity()) {
  5956. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5957. return 0;
  5958. }
  5959. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  5960. if (!item) {
  5961. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5962. return 0;
  5963. }
  5964. lua_interface->SetItemValue(state, item);
  5965. return 1;
  5966. }
  5967. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5968. if (!lua_interface)
  5969. return 0;
  5970. Spawn* player = lua_interface->GetSpawn(state);
  5971. int32 id = lua_interface->GetInt32Value(state, 2);
  5972. lua_interface->ResetFunctionStack(state);
  5973. if (!player) {
  5974. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5975. return 0;
  5976. }
  5977. if (!player->IsPlayer()) {
  5978. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5979. return 0;
  5980. }
  5981. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5982. if (!item) {
  5983. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5984. return 0;
  5985. }
  5986. lua_interface->SetItemValue(state, item);
  5987. return 1;
  5988. }
  5989. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5990. if (!lua_interface)
  5991. return 0;
  5992. Spawn* spawn = lua_interface->GetSpawn(state);
  5993. int8 slot = lua_interface->GetInt8Value(state, 2);
  5994. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5995. lua_interface->ResetFunctionStack(state);
  5996. if (!spawn) {
  5997. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5998. return 0;
  5999. }
  6000. if (!spawn->IsEntity()) {
  6001. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6002. return 0;
  6003. }
  6004. Item* item = master_item_list.GetItem(item_id);
  6005. if (!item) {
  6006. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6007. return 0;
  6008. }
  6009. Item* copy = new Item(item);
  6010. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6011. if(result)
  6012. {
  6013. ((Entity*)spawn)->SetEquipment(copy, slot);
  6014. spawn->vis_changed = true;
  6015. if(spawn->IsPlayer())
  6016. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6017. }
  6018. else
  6019. {
  6020. safe_delete(copy);
  6021. }
  6022. lua_interface->SetBooleanValue(state, result);
  6023. return 1;
  6024. }
  6025. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6026. if (!lua_interface)
  6027. return 0;
  6028. Spawn* spawn = lua_interface->GetSpawn(state);
  6029. int8 slot = lua_interface->GetInt8Value(state, 2);
  6030. Item* item = lua_interface->GetItem(state, 3);
  6031. lua_interface->ResetFunctionStack(state);
  6032. if (!spawn) {
  6033. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6034. return 0;
  6035. }
  6036. if (!spawn->IsEntity()) {
  6037. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6038. return 0;
  6039. }
  6040. if (!item) {
  6041. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6042. return 0;
  6043. }
  6044. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6045. if(result)
  6046. {
  6047. ((Entity*)spawn)->SetEquipment(item, slot);
  6048. spawn->vis_changed = true;
  6049. if(spawn->IsPlayer())
  6050. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6051. }
  6052. lua_interface->SetBooleanValue(state, result);
  6053. return 1;
  6054. }
  6055. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6056. if (!lua_interface)
  6057. return 0;
  6058. Spawn* spawn = lua_interface->GetSpawn(state);
  6059. int8 slot = lua_interface->GetInt8Value(state, 2);
  6060. bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  6061. lua_interface->ResetFunctionStack(state);
  6062. if (!spawn) {
  6063. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6064. return 0;
  6065. }
  6066. if (!spawn->IsEntity()) {
  6067. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6068. return 0;
  6069. }
  6070. if(slot >= NUM_SLOTS) {
  6071. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6072. return 0;
  6073. }
  6074. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6075. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6076. if(item) {
  6077. item->save_needed = true;
  6078. if(no_delete_item) {
  6079. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6080. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6081. }
  6082. else{
  6083. Client* client = ((Player*)spawn)->GetClient();
  6084. client->UnequipItem(item->details.index);
  6085. }
  6086. }
  6087. }
  6088. else
  6089. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6090. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6091. spawn->vis_changed = true;
  6092. if(spawn->IsPlayer())
  6093. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6094. lua_interface->SetBooleanValue(state, true);
  6095. return 1;
  6096. }
  6097. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6098. if (!lua_interface)
  6099. return 0;
  6100. Spawn* spawn = lua_interface->GetSpawn(state);
  6101. int8 slot = lua_interface->GetInt8Value(state, 2);
  6102. int16 type = lua_interface->GetInt16Value(state, 3);
  6103. int8 r = lua_interface->GetInt8Value(state, 4);
  6104. int8 g = lua_interface->GetInt8Value(state, 5);
  6105. int8 b = lua_interface->GetInt8Value(state, 6);
  6106. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6107. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6108. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6109. lua_interface->ResetFunctionStack(state);
  6110. if (!spawn) {
  6111. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6112. return 0;
  6113. }
  6114. if (!spawn->IsEntity()) {
  6115. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6116. return 0;
  6117. }
  6118. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6119. spawn->vis_changed = true;
  6120. lua_interface->SetBooleanValue(state, true);
  6121. return 1;
  6122. }
  6123. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6124. if (!lua_interface)
  6125. return 0;
  6126. Spawn* player = lua_interface->GetSpawn(state);
  6127. int32 id = lua_interface->GetInt32Value(state, 2);
  6128. int8 count = lua_interface->GetInt8Value(state, 3);
  6129. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6130. lua_interface->ResetFunctionStack(state);
  6131. if (!player) {
  6132. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6133. return 0;
  6134. }
  6135. if (!player->IsPlayer()) {
  6136. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6137. return 0;
  6138. }
  6139. if (!count)
  6140. count = 1;
  6141. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6142. if (!item) {
  6143. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. lua_interface->SetItemValue(state, item);
  6147. return 1;
  6148. }
  6149. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6150. if (!lua_interface)
  6151. return 0;
  6152. Spawn* spawn = lua_interface->GetSpawn(state);
  6153. int32 anim = lua_interface->GetInt32Value(state, 2);
  6154. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6155. int8 type = lua_interface->GetInt8Value(state, 4);
  6156. lua_interface->ResetFunctionStack(state);
  6157. if (!spawn) {
  6158. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6159. return 0;
  6160. }
  6161. if (spawn2) {
  6162. if (spawn2->IsPlayer()) {
  6163. if (type != 1 && type != 2)
  6164. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6165. else
  6166. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6167. return 0;
  6168. }
  6169. else {
  6170. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6171. return 0;
  6172. }
  6173. }
  6174. else
  6175. spawn->GetZone()->PlayAnimation(spawn, anim);
  6176. return 0;
  6177. }
  6178. int EQ2Emu_lua_IsPet(lua_State* state) {
  6179. if (!lua_interface)
  6180. return 0;
  6181. Spawn* spawn = lua_interface->GetSpawn(state);
  6182. lua_interface->ResetFunctionStack(state);
  6183. if (!spawn) {
  6184. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6185. return 0;
  6186. }
  6187. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6188. return 1;
  6189. }
  6190. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6191. if (!lua_interface)
  6192. return 0;
  6193. Spawn* spawn = lua_interface->GetSpawn(state);
  6194. lua_interface->ResetFunctionStack(state);
  6195. if (!spawn) {
  6196. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6197. return 0;
  6198. }
  6199. if (!spawn->IsNPC()) {
  6200. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6201. return 0;
  6202. }
  6203. if (((NPC*)spawn)->GetOwner()) {
  6204. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6205. return 1;
  6206. }
  6207. return 0;
  6208. }
  6209. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6210. if (!lua_interface)
  6211. return 0;
  6212. Spawn* spawn = lua_interface->GetSpawn(state);
  6213. Spawn* target = lua_interface->GetSpawn(state, 2);
  6214. lua_interface->ResetFunctionStack(state);
  6215. if (!spawn) {
  6216. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6217. return 0;
  6218. }
  6219. if (!spawn) {
  6220. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6221. return 0;
  6222. }
  6223. spawn->SetTarget(target);
  6224. return 0;
  6225. }
  6226. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6227. if (!lua_interface)
  6228. return 0;
  6229. Spawn* spawn = lua_interface->GetSpawn(state);
  6230. bool val = lua_interface->GetBooleanValue(state, 2);
  6231. lua_interface->ResetFunctionStack(state);
  6232. if (!spawn) {
  6233. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6234. return 0;
  6235. }
  6236. if (!spawn->IsEntity()) {
  6237. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. ((Entity*)spawn)->InCombat(val);
  6241. if (val) {
  6242. spawn->ClearRunningLocations();
  6243. spawn->CalculateRunningLocation(true);
  6244. }
  6245. return 0;
  6246. }
  6247. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6248. if (!lua_interface)
  6249. return 0;
  6250. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6251. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6252. lua_interface->ResetFunctionStack(state);
  6253. if (!spawn1) {
  6254. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6255. return 0;
  6256. }
  6257. if (!spawn2) {
  6258. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6259. return 0;
  6260. }
  6261. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6262. return 1;
  6263. }
  6264. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6265. if (!lua_interface)
  6266. return 0;
  6267. Spawn* spawn = lua_interface->GetSpawn(state);
  6268. lua_interface->ResetFunctionStack(state);
  6269. if (!spawn) {
  6270. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6271. return 0;
  6272. }
  6273. if (!spawn->IsNPC()) {
  6274. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6275. return 0;
  6276. }
  6277. ((NPC*)spawn)->ClearRunback();
  6278. return 0;
  6279. }
  6280. int EQ2Emu_lua_Runback(lua_State* state) {
  6281. if (!lua_interface)
  6282. return 0;
  6283. Spawn* spawn = lua_interface->GetSpawn(state);
  6284. lua_interface->ResetFunctionStack(state);
  6285. if (!spawn) {
  6286. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6287. return 0;
  6288. }
  6289. if (!spawn->IsNPC()) {
  6290. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. ((NPC*)spawn)->Runback();
  6294. return 0;
  6295. }
  6296. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6297. if (!lua_interface)
  6298. return 0;
  6299. Spawn* spawn = lua_interface->GetSpawn(state);
  6300. lua_interface->ResetFunctionStack(state);
  6301. if (!spawn) {
  6302. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6303. return 0;
  6304. }
  6305. if (!spawn->IsNPC()) {
  6306. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6307. return 0;
  6308. }
  6309. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6310. return 1;
  6311. }
  6312. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6313. if (!lua_interface)
  6314. return 0;
  6315. Spawn* spawn = lua_interface->GetSpawn(state);
  6316. lua_interface->ResetFunctionStack(state);
  6317. if (!spawn) {
  6318. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6319. return 0;
  6320. }
  6321. if (!spawn->IsEntity()) {
  6322. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6323. return 0;
  6324. }
  6325. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6326. return 1;
  6327. }
  6328. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6329. if (!lua_interface)
  6330. return 0;
  6331. Spawn* spawn = lua_interface->GetSpawn(state);
  6332. lua_interface->ResetFunctionStack(state);
  6333. if (!spawn) {
  6334. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6335. return 0;
  6336. }
  6337. if (!spawn->IsEntity()) {
  6338. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6339. return 0;
  6340. }
  6341. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6342. return 1;
  6343. }
  6344. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6345. if (!lua_interface)
  6346. return 0;
  6347. Spawn* spawn = lua_interface->GetSpawn(state);
  6348. lua_interface->ResetFunctionStack(state);
  6349. if (!spawn) {
  6350. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6351. return 0;
  6352. }
  6353. if (!spawn->IsEntity()) {
  6354. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6355. return 0;
  6356. }
  6357. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6358. return 1;
  6359. }
  6360. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6361. if (!lua_interface)
  6362. return 0;
  6363. Spawn* spawn = lua_interface->GetSpawn(state);
  6364. lua_interface->ResetFunctionStack(state);
  6365. if (!spawn) {
  6366. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6367. return 0;
  6368. }
  6369. if (!spawn->IsEntity()) {
  6370. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6371. return 0;
  6372. }
  6373. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6374. return 1;
  6375. }
  6376. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6377. if (!lua_interface)
  6378. return 0;
  6379. Spawn* spawn = lua_interface->GetSpawn(state);
  6380. Spawn* target = lua_interface->GetSpawn(state, 2);
  6381. float distance = lua_interface->GetFloatValue(state, 3);
  6382. lua_interface->ResetFunctionStack(state);
  6383. if (!spawn) {
  6384. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6385. return 0;
  6386. }
  6387. if (!target) {
  6388. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6389. return 0;
  6390. }
  6391. if (!spawn->IsNPC()) {
  6392. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6393. return 0;
  6394. }
  6395. if (!target->IsEntity()) {
  6396. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6397. return 0;
  6398. }
  6399. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6400. return 1;
  6401. }
  6402. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6403. if (!lua_interface)
  6404. return 0;
  6405. Spawn* spawn = lua_interface->GetSpawn(state);
  6406. Spawn* target = lua_interface->GetSpawn(state, 2);
  6407. float distance = lua_interface->GetFloatValue(state, 3);
  6408. lua_interface->ResetFunctionStack(state);
  6409. if (!spawn) {
  6410. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6411. return 0;
  6412. }
  6413. if (!target) {
  6414. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6415. return 0;
  6416. }
  6417. if (!spawn->IsNPC()) {
  6418. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6419. return 0;
  6420. }
  6421. if (!target->IsEntity()) {
  6422. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6423. return 0;
  6424. }
  6425. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6426. return 0;
  6427. }
  6428. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6429. if (!lua_interface)
  6430. return 0;
  6431. Spawn* spawn = lua_interface->GetSpawn(state);
  6432. lua_interface->ResetFunctionStack(state);
  6433. if (!spawn) {
  6434. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6435. return 0;
  6436. }
  6437. if (!spawn->IsNPC()) {
  6438. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6439. return 0;
  6440. }
  6441. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6442. return 1;
  6443. }
  6444. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6445. if (!lua_interface)
  6446. return 0;
  6447. Spawn* spawn = lua_interface->GetSpawn(state);
  6448. lua_interface->ResetFunctionStack(state);
  6449. if (!spawn) {
  6450. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6451. return 0;
  6452. }
  6453. if (!spawn->IsNPC()) {
  6454. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6455. return 0;
  6456. }
  6457. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6458. return 1;
  6459. }
  6460. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6461. if (!lua_interface)
  6462. return 0;
  6463. Spawn* spawn = lua_interface->GetSpawn(state);
  6464. lua_interface->ResetFunctionStack(state);
  6465. if (!spawn) {
  6466. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6467. return 0;
  6468. }
  6469. if (!spawn->IsNPC()) {
  6470. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6471. return 0;
  6472. }
  6473. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6474. if (hated) {
  6475. lua_interface->SetSpawnValue(state, hated);
  6476. return 1;
  6477. }
  6478. return 0;
  6479. }
  6480. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6481. if (!lua_interface)
  6482. return 0;
  6483. Spawn* spawn = lua_interface->GetSpawn(state);
  6484. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6485. lua_interface->ResetFunctionStack(state);
  6486. if (!spawn) {
  6487. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6488. return 0;
  6489. }
  6490. if (!spawn->IsNPC()) {
  6491. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6492. return 0;
  6493. }
  6494. if (!hated) {
  6495. ((NPC*)spawn)->Brain()->ClearHate();
  6496. return 0;
  6497. }
  6498. else
  6499. {
  6500. if (!hated->IsEntity()) {
  6501. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6502. return 0;
  6503. }
  6504. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6505. return 0;
  6506. }
  6507. return 0;
  6508. }
  6509. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6510. if (!lua_interface)
  6511. return 0;
  6512. Spawn* spawn = lua_interface->GetSpawn(state);
  6513. lua_interface->ResetFunctionStack(state);
  6514. if (!spawn) {
  6515. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6516. return 0;
  6517. }
  6518. if (!spawn->IsNPC()) {
  6519. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6520. return 0;
  6521. }
  6522. ((NPC*)spawn)->Brain()->ClearEncounter();
  6523. return 0;
  6524. }
  6525. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6526. if (!lua_interface)
  6527. return 0;
  6528. Spawn* spawn = lua_interface->GetSpawn(state);
  6529. lua_interface->ResetFunctionStack(state);
  6530. if (!spawn) {
  6531. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6532. return 0;
  6533. }
  6534. if (!spawn->IsNPC()) {
  6535. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6536. return 0;
  6537. }
  6538. // Temp list to store hate list
  6539. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6540. if (encounterList->size() == 0) {
  6541. safe_delete(encounterList);
  6542. return 0;
  6543. }
  6544. lua_createtable(state, encounterList->size(), 0);
  6545. int newTable = lua_gettop(state);
  6546. for (int32 i = 0; i < encounterList->size(); i++) {
  6547. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6548. if (temp)
  6549. lua_interface->SetSpawnValue(state, temp);
  6550. lua_rawseti(state, newTable, i + 1);
  6551. }
  6552. safe_delete(encounterList);
  6553. return 1;
  6554. }
  6555. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6556. if (!lua_interface)
  6557. return 0;
  6558. Spawn* spawn = lua_interface->GetSpawn(state);
  6559. lua_interface->ResetFunctionStack(state);
  6560. if (!spawn) {
  6561. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6562. return 0;
  6563. }
  6564. if (!spawn->IsNPC()) {
  6565. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6566. return 0;
  6567. }
  6568. // Temp list to store hate list
  6569. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6570. if (hateList->size() == 0) {
  6571. safe_delete(hateList);
  6572. return 0;
  6573. }
  6574. lua_createtable(state, hateList->size(), 0);
  6575. int newTable = lua_gettop(state);
  6576. for (int32 i = 0; i < hateList->size(); i++) {
  6577. lua_interface->SetSpawnValue(state, hateList->at(i));
  6578. lua_rawseti(state, newTable, i + 1);
  6579. }
  6580. safe_delete(hateList);
  6581. return 1;
  6582. }
  6583. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6584. if (!lua_interface)
  6585. return 0;
  6586. Spawn* spawn = lua_interface->GetSpawn(state);
  6587. lua_interface->ResetFunctionStack(state);
  6588. if (!spawn) {
  6589. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6590. return 0;
  6591. }
  6592. if (spawn->IsPlayer()) {
  6593. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6594. lua_interface->SetBooleanValue(state, true);
  6595. else
  6596. lua_interface->SetBooleanValue(state, false);
  6597. return 1;
  6598. }
  6599. else {
  6600. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6601. return 1;
  6602. }
  6603. }
  6604. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6605. if (!lua_interface)
  6606. return 0;
  6607. Quest* quest = lua_interface->GetQuest(state);
  6608. lua_interface->ResetFunctionStack(state);
  6609. if (!quest) {
  6610. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6611. return 0;
  6612. }
  6613. quest->SetCompletedFlag(true);
  6614. return 0;
  6615. }
  6616. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6617. if (!lua_interface)
  6618. return 0;
  6619. Spawn* spawn = lua_interface->GetSpawn(state);
  6620. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6621. int8 tier = lua_interface->GetInt8Value(state, 3);
  6622. lua_interface->ResetFunctionStack(state);
  6623. if (!spawn) {
  6624. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6625. return 0;
  6626. }
  6627. if (!spawn->IsEntity()) {
  6628. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6629. return 0;
  6630. }
  6631. if (spellID == 0) {
  6632. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6633. return 0;
  6634. }
  6635. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6636. if (effect) {
  6637. if (tier > 0) {
  6638. // If a tier was passed chec to see if it is the same as the effect
  6639. if (tier == effect->tier)
  6640. lua_interface->SetBooleanValue(state, true);
  6641. else
  6642. lua_interface->SetBooleanValue(state, false);
  6643. return 1;
  6644. }
  6645. else {
  6646. // Have an effect but no tier was passed so return true
  6647. lua_interface->SetBooleanValue(state, true);
  6648. }
  6649. return 1;
  6650. }
  6651. // no effect so return false
  6652. lua_interface->SetBooleanValue(state, false);
  6653. return 1;
  6654. }
  6655. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6656. if (!lua_interface)
  6657. return 0;
  6658. Spawn* spawn = lua_interface->GetSpawn(state);
  6659. int32 id = lua_interface->GetInt32Value(state, 2);
  6660. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6661. lua_interface->ResetFunctionStack(state);
  6662. Spawn* spawn2 = 0;
  6663. vector<Spawn*> list;
  6664. if (!spawn) {
  6665. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6666. return 0;
  6667. }
  6668. //If zone not provided, use spawn's zone
  6669. if (!zone)
  6670. zone = spawn->GetZone();
  6671. list = zone->GetSpawnsByID(id);
  6672. if (list.size() == 0) {
  6673. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6674. return 0;
  6675. }
  6676. vector<Spawn*>::iterator itr = list.begin();
  6677. for (int8 i = 0; i < list.size(); i++) {
  6678. spawn2 = itr[i];
  6679. if (spawn2)
  6680. spawn2->AddAllowAccessSpawn(spawn);
  6681. }
  6682. return 0;
  6683. }
  6684. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6685. if (!lua_interface)
  6686. return 0;
  6687. Spawn* spawn = lua_interface->GetSpawn(state);
  6688. int32 id = lua_interface->GetInt32Value(state, 2);
  6689. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6690. lua_interface->ResetFunctionStack(state);
  6691. Spawn* spawn2 = 0;
  6692. if (!spawn) {
  6693. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6694. return 0;
  6695. }
  6696. //If zone not provided, use spawn's zone
  6697. if (!zone)
  6698. zone = spawn->GetZone();
  6699. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6700. vector<Spawn*>::iterator itr = list.begin();
  6701. if (list.size() == 0) {
  6702. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6703. return 0;
  6704. }
  6705. for (int8 i = 0; i < list.size(); i++) {
  6706. spawn2 = itr[i];
  6707. if (spawn2)
  6708. spawn2->RemoveSpawnAccess(spawn);
  6709. }
  6710. return 0;
  6711. }
  6712. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6713. if (!lua_interface)
  6714. return 0;
  6715. Quest* quest = lua_interface->GetQuest(state);
  6716. lua_interface->ResetFunctionStack(state);
  6717. if (!quest) {
  6718. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6719. return 0;
  6720. }
  6721. quest->SetYellowName(true);
  6722. return 0;
  6723. }
  6724. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6725. if (!lua_interface)
  6726. return 0;
  6727. Spawn* spawn = lua_interface->GetSpawn(state);
  6728. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6729. lua_interface->ResetFunctionStack(state);
  6730. if (!spawn) {
  6731. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6732. return 0;
  6733. }
  6734. if (!spawn->IsPlayer()) {
  6735. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6736. return 0;
  6737. }
  6738. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6739. return 1;
  6740. }
  6741. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6742. if (!lua_interface)
  6743. return 0;
  6744. Spawn* spawn = lua_interface->GetSpawn(state);
  6745. lua_interface->ResetFunctionStack(state);
  6746. if (!spawn) {
  6747. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6748. return 0;
  6749. }
  6750. if (!spawn->IsPlayer()) {
  6751. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6752. return 0;
  6753. }
  6754. ZoneServer* zone = spawn->GetZone();
  6755. if (!zone) {
  6756. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6757. return 0;
  6758. }
  6759. Instance_Type iType = zone->GetInstanceType();
  6760. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6761. iType == GROUP_LOCKOUT_INSTANCE ||
  6762. iType == RAID_LOCKOUT_INSTANCE ||
  6763. iType == SOLO_PERSIST_INSTANCE ||
  6764. iType == GROUP_PERSIST_INSTANCE ||
  6765. iType == RAID_PERSIST_INSTANCE) {
  6766. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6767. if (data) {
  6768. // Check to see if the timer has already been set, if it has return out.
  6769. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6770. return 0;
  6771. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6772. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6773. if(spawn->IsPlayer()) {
  6774. Client* client = ((Player*)spawn)->GetClient();
  6775. if (client) {
  6776. string time_msg = "";
  6777. int32 time = data->success_lockout_time;
  6778. int16 hour;
  6779. int8 min;
  6780. int8 sec;
  6781. hour = time / 3600;
  6782. time = time % 3600;
  6783. min = time / 60;
  6784. time = time % 60;
  6785. sec = time;
  6786. if (hour > 0) {
  6787. char temp[10];
  6788. sprintf(temp, " %i", hour);
  6789. time_msg.append(temp);
  6790. time_msg.append(" hour");
  6791. time_msg.append((hour > 1) ? "s" : "");
  6792. }
  6793. if (min > 0) {
  6794. char temp[5];
  6795. sprintf(temp, " %i", min);
  6796. time_msg.append(temp);
  6797. time_msg.append(" minute");
  6798. time_msg.append((min > 1) ? "s" : "");
  6799. }
  6800. // Only add seconds if minutes and hours are 0
  6801. if (hour == 0 && min == 0 && sec > 0) {
  6802. char temp[5];
  6803. sprintf(temp, " %i", sec);
  6804. time_msg.append(temp);
  6805. time_msg.append(" second");
  6806. time_msg.append((sec > 1) ? "s" : "");
  6807. }
  6808. 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());
  6809. }
  6810. else {
  6811. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6812. }
  6813. }
  6814. }
  6815. else
  6816. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6817. }
  6818. else
  6819. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6820. return 0;
  6821. }
  6822. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6823. if (!lua_interface)
  6824. return 0;
  6825. Spawn* spawn = lua_interface->GetSpawn(state);
  6826. lua_interface->ResetFunctionStack(state);
  6827. if (!spawn) {
  6828. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6829. return 0;
  6830. }
  6831. if (!spawn->IsPlayer()) {
  6832. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6833. return 0;
  6834. }
  6835. ZoneServer* zone = spawn->GetZone();
  6836. if (!zone) {
  6837. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. Instance_Type iType = zone->GetInstanceType();
  6841. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6842. iType == GROUP_LOCKOUT_INSTANCE ||
  6843. iType == RAID_LOCKOUT_INSTANCE ||
  6844. iType == SOLO_PERSIST_INSTANCE ||
  6845. iType == GROUP_PERSIST_INSTANCE ||
  6846. iType == RAID_PERSIST_INSTANCE) {
  6847. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6848. if (data) {
  6849. // Check to see if the timer has already been set, if it has return out.
  6850. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6851. return 0;
  6852. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6853. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6854. if(spawn->IsPlayer()) {
  6855. Client* client = ((Player*)spawn)->GetClient();
  6856. if (client) {
  6857. string time_msg = "";
  6858. int32 time = data->failure_lockout_time;
  6859. int16 hour;
  6860. int8 min;
  6861. int8 sec;
  6862. hour = time / 3600;
  6863. time = time % 3600;
  6864. min = time / 60;
  6865. time = time % 60;
  6866. sec = time;
  6867. if (hour > 0) {
  6868. char temp[10];
  6869. sprintf(temp, " %i", hour);
  6870. time_msg.append(temp);
  6871. time_msg.append(" hour");
  6872. time_msg.append((hour > 1) ? "s" : "");
  6873. }
  6874. if (min > 0) {
  6875. char temp[5];
  6876. sprintf(temp, " %i", min);
  6877. time_msg.append(temp);
  6878. time_msg.append(" minute");
  6879. time_msg.append((min > 1) ? "s" : "");
  6880. }
  6881. // Only add seconds if minutes and hours are 0
  6882. if (hour == 0 && min == 0 && sec > 0) {
  6883. char temp[5];
  6884. sprintf(temp, " %i", sec);
  6885. time_msg.append(temp);
  6886. time_msg.append(" second");
  6887. time_msg.append((sec > 1) ? "s" : "");
  6888. }
  6889. 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());
  6890. }
  6891. }
  6892. else {
  6893. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6894. }
  6895. }
  6896. else
  6897. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6898. }
  6899. else
  6900. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6901. return 0;
  6902. }
  6903. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6904. if (!lua_interface)
  6905. return 0;
  6906. Spawn* spawn = lua_interface->GetSpawn(state);
  6907. lua_interface->ResetFunctionStack(state);
  6908. if (!spawn) {
  6909. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6910. return 0;
  6911. }
  6912. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6913. return 1;
  6914. }
  6915. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6916. if (!lua_interface)
  6917. return 0;
  6918. Spawn* player = lua_interface->GetSpawn(state);
  6919. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6920. if (!player) {
  6921. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6922. lua_interface->ResetFunctionStack(state);
  6923. return 0;
  6924. }
  6925. if (!player->IsPlayer()) {
  6926. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6927. lua_interface->ResetFunctionStack(state);
  6928. return 0;
  6929. }
  6930. if (!ground) {
  6931. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6932. lua_interface->ResetFunctionStack(state);
  6933. return 0;
  6934. }
  6935. if (!ground->IsGroundSpawn()) {
  6936. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6937. lua_interface->ResetFunctionStack(state);
  6938. return 0;
  6939. }
  6940. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6941. if (!groundspawn_entries) {
  6942. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6943. lua_interface->ResetFunctionStack(state);
  6944. return 0;
  6945. }
  6946. Skill* skill = 0;
  6947. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6948. if (collection_skill == "Collecting")
  6949. skill = ((Player*)player)->GetSkillByName("Gathering");
  6950. else
  6951. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6952. if (!skill) {
  6953. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6954. lua_interface->ResetFunctionStack(state);
  6955. return 0;
  6956. }
  6957. vector<GroundSpawnEntry*>::iterator itr;
  6958. GroundSpawnEntry* entry = 0;
  6959. bool can_harvest = false;
  6960. sint32 min_skill = -1;
  6961. int16 totalSkill = skill->current_val;
  6962. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6963. if(skillID != 0xFFFFFFFF)
  6964. {
  6965. ((Entity*)player)->MStats.lock();
  6966. totalSkill += ((Entity*)player)->stats[skillID];
  6967. ((Entity*)player)->MStats.unlock();
  6968. }
  6969. // first, iterate through groundspawn_entries, discard tables player cannot use
  6970. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6971. {
  6972. entry = *itr;
  6973. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6974. min_skill = entry->min_skill_level;
  6975. // if player lacks skill, skip table
  6976. if (entry->min_skill_level > totalSkill)
  6977. continue;
  6978. // if bonus, but player lacks level, skip table
  6979. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6980. continue;
  6981. can_harvest = true;
  6982. break;
  6983. }
  6984. lua_interface->SetBooleanValue(state, can_harvest);
  6985. // If false, send the message to the client
  6986. if (!can_harvest) {
  6987. Client* client = ((Player*)player)->GetClient();
  6988. if (client) {
  6989. string msg = "You do not have enough skill to ";
  6990. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6991. msg.append("gather");
  6992. else if (collection_skill == "Mining")
  6993. msg.append("mine");
  6994. else if (collection_skill == "Trapping")
  6995. msg.append("trap");
  6996. else if (collection_skill == "Foresting")
  6997. msg.append("forest");
  6998. else if (collection_skill == "Fishing")
  6999. msg.append("catch");
  7000. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7001. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7002. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7003. }
  7004. }
  7005. lua_interface->ResetFunctionStack(state);
  7006. return 1;
  7007. }
  7008. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7009. if (!lua_interface)
  7010. return 0;
  7011. Spawn* player = lua_interface->GetSpawn(state);
  7012. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7013. lua_interface->ResetFunctionStack(state);
  7014. if (!player) {
  7015. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7016. return 0;
  7017. }
  7018. if (!player->IsPlayer()) {
  7019. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7020. return 0;
  7021. }
  7022. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7023. lua_interface->SetBooleanValue(state, ret);
  7024. return 1;
  7025. }
  7026. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7027. // Check to see if we have a valid lua_interface
  7028. if (!lua_interface)
  7029. return 0;
  7030. // Get the spawn that is getting the pet
  7031. Spawn* spawn = lua_interface->GetSpawn(state);
  7032. Spawn* target = lua_interface->GetSpawn(state, 2);
  7033. // Get the DB ID of the pet
  7034. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7035. float x = lua_interface->GetFloatValue(state, 4);
  7036. float y = lua_interface->GetFloatValue(state, 5);
  7037. float z = lua_interface->GetFloatValue(state, 6);
  7038. // Get the spell that this command was called from
  7039. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7040. lua_interface->ResetFunctionStack(state);
  7041. // Check to make sure the spawn pointer is valid
  7042. if (!spawn) {
  7043. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7044. return 0;
  7045. }
  7046. // Check to make sure the spawn is an entity
  7047. if (!spawn->IsEntity()) {
  7048. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7049. return 0;
  7050. }
  7051. if (!target) {
  7052. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7053. return 0;
  7054. }
  7055. if (!target->IsEntity()) {
  7056. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7057. return 0;
  7058. }
  7059. // Check to see if the DB ID for the pet is set
  7060. if (pet_id == 0) {
  7061. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7062. return 0;
  7063. }
  7064. // Check to see if the pointer to the spell is valid
  7065. if (!luaspell) {
  7066. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7067. return 0;
  7068. }
  7069. if(luaspell->resisted) {
  7070. return 0;
  7071. }
  7072. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7073. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7074. if (!pet) {
  7075. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7076. return 0;
  7077. }
  7078. // Check to make sure the pet is an npc
  7079. if (!pet->IsNPC()) {
  7080. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7081. return 0;
  7082. }
  7083. if (x == 0)
  7084. x = spawn->GetX();
  7085. if (y == 0)
  7086. y = spawn->GetY();
  7087. if (z == 0)
  7088. z = spawn->GetZ();
  7089. // Spawn the pet at the same location as the owner
  7090. pet->SetX(x);
  7091. pet->SetY(y);
  7092. pet->SetZ(z);
  7093. pet->SetLocation(spawn->GetLocation());
  7094. pet->SetHeading(spawn->GetHeading());
  7095. spawn->GetZone()->AddSpawn(pet);
  7096. const char* spawn_script = world.GetSpawnScript(pet_id);
  7097. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7098. spawn->SetSpawnScript(string(spawn_script));
  7099. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7100. }
  7101. std::string petName = std::string("");
  7102. if(spawn->IsEntity()) {
  7103. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7104. }
  7105. if(petName.size() < 1) {
  7106. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7107. petName = spawn->GetZone()->pet_names.at(rand_index);
  7108. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7109. }
  7110. // Set the pets name
  7111. pet->SetName(petName.c_str());
  7112. // Set the level of the pet to the owners level
  7113. pet->SetLevel(spawn->GetLevel());
  7114. // Set the faction of the pet to the same faction as the owner
  7115. pet->SetFactionID(spawn->GetFactionID());
  7116. // Set the spawn as a pet
  7117. pet->SetPet(true);
  7118. // Give a pointer of the owner to the pet
  7119. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7120. // Set the pet type
  7121. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7122. // Set the spell id used to create this pet
  7123. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7124. // Set the spell tier used to create this pet
  7125. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7126. // Set the pets spawn type to 6
  7127. pet->SetSpawnType(6);
  7128. // Set the pets brain
  7129. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7130. // Check to see if the pet has a subtitle
  7131. if (strlen(pet->GetSubTitle()) > 0) {
  7132. // Add the players name to the front of the sub title
  7133. string pet_subtitle;
  7134. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7135. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7136. // Set the pets subtitle to the new one
  7137. pet->SetSubTitle(pet_subtitle.c_str());
  7138. }
  7139. // Set the pet as the return value for this function
  7140. lua_interface->SetSpawnValue(state, pet);
  7141. return 1;
  7142. }
  7143. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7144. if (!lua_interface)
  7145. return 0;
  7146. Spawn* spawn = lua_interface->GetSpawn(state);
  7147. Spawn* player = lua_interface->GetSpawn(state, 2);
  7148. float max_distance = lua_interface->GetFloatValue(state, 3);
  7149. string type = lua_interface->GetStringValue(state, 4);
  7150. lua_interface->ResetFunctionStack(state);
  7151. if (!spawn || (spawn && spawn->IsPlayer())) {
  7152. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7153. return 0;
  7154. }
  7155. if (!player || !player->IsPlayer()) {
  7156. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7157. return 0;
  7158. }
  7159. Client* client = ((Player*)player)->GetClient();
  7160. if (!client) {
  7161. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7162. return 0;
  7163. }
  7164. //Set max_distance to default if not set or not proper value
  7165. if (max_distance <= 0)
  7166. max_distance = 500;
  7167. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7168. if (packet) {
  7169. float unknown2_3 = 0;
  7170. int8 placement_mode = 0;
  7171. if (type == "wall") {
  7172. placement_mode = 2;
  7173. unknown2_3 = 150;
  7174. }
  7175. else if (type == "ceiling")
  7176. placement_mode = 1;
  7177. packet->setDataByName("placement_mode", placement_mode);
  7178. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7179. packet->setDataByName("model_type", spawn->GetModelType());
  7180. packet->setDataByName("unknown", 1); //size
  7181. packet->setDataByName("unknown2", 1); //size 2
  7182. packet->setDataByName("unknown2", .5, 1); //size 3
  7183. packet->setDataByName("unknown2", 3, 2);
  7184. packet->setDataByName("unknown2", unknown2_3, 3);
  7185. packet->setDataByName("max_distance", max_distance);
  7186. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7187. client->QueuePacket(packet->serialize());
  7188. safe_delete(packet);
  7189. }
  7190. return 0;
  7191. }
  7192. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7193. if (!lua_interface)
  7194. return 0;
  7195. Item* item = lua_interface->GetItem(state);
  7196. lua_interface->ResetFunctionStack(state);
  7197. if (!item) {
  7198. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7199. return 0;
  7200. }
  7201. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7202. return 1;
  7203. }
  7204. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7205. if (!lua_interface)
  7206. return 0;
  7207. Item* item = lua_interface->GetItem(state);
  7208. lua_interface->ResetFunctionStack(state);
  7209. if (!item) {
  7210. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7211. return 0;
  7212. }
  7213. lua_interface->SetInt32Value(state, item->effect_type);
  7214. return 1;
  7215. }
  7216. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7217. if (!lua_interface)
  7218. return 0;
  7219. Spawn* spawn = lua_interface->GetSpawn(state);
  7220. lua_interface->ResetFunctionStack(state);
  7221. if (!spawn) {
  7222. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7223. return 0;
  7224. }
  7225. if (spawn->GetZone())
  7226. spawn->GetZone()->AddTransportSpawn(spawn);
  7227. return 0;
  7228. }
  7229. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7230. if (!lua_interface)
  7231. return 0;
  7232. Spawn* spawn = lua_interface->GetSpawn(state);
  7233. lua_interface->ResetFunctionStack(state);
  7234. if (!spawn) {
  7235. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7236. return 0;
  7237. }
  7238. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7239. return 1;
  7240. }
  7241. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7242. if (!lua_interface)
  7243. return 0;
  7244. Skill* skill = lua_interface->GetSkill(state);
  7245. lua_interface->ResetFunctionStack(state);
  7246. if (!skill) {
  7247. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7248. return 0;
  7249. }
  7250. lua_interface->SetInt32Value(state, skill->current_val);
  7251. return 1;
  7252. }
  7253. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7254. if (!lua_interface)
  7255. return 0;
  7256. Skill* skill = lua_interface->GetSkill(state);
  7257. lua_interface->ResetFunctionStack(state);
  7258. if (!skill) {
  7259. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7260. return 0;
  7261. }
  7262. lua_interface->SetInt32Value(state, skill->max_val);
  7263. return 1;
  7264. }
  7265. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7266. if (!lua_interface)
  7267. return 0;
  7268. Skill* skill = lua_interface->GetSkill(state);
  7269. lua_interface->ResetFunctionStack(state);
  7270. if (!skill) {
  7271. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7272. return 0;
  7273. }
  7274. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7275. return 1;
  7276. }
  7277. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7278. if (!lua_interface)
  7279. return 0;
  7280. Skill* skill = lua_interface->GetSkill(state);
  7281. int16 value = lua_interface->GetInt16Value(state, 2);
  7282. lua_interface->ResetFunctionStack(state);
  7283. if (!skill) {
  7284. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7285. return 0;
  7286. }
  7287. skill->max_val = value;
  7288. if (skill->max_val < skill->current_val)
  7289. skill->current_val = skill->max_val;
  7290. return 0;
  7291. }
  7292. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7293. if (!lua_interface)
  7294. return 0;
  7295. Skill* skill = lua_interface->GetSkill(state);
  7296. int16 value = lua_interface->GetInt16Value(state, 2);
  7297. lua_interface->ResetFunctionStack(state);
  7298. if (!skill) {
  7299. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7300. return 0;
  7301. }
  7302. if (value > skill->max_val)
  7303. skill->current_val = skill->max_val;
  7304. else
  7305. skill->current_val = value;
  7306. return 0;
  7307. }
  7308. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7309. if (!lua_interface)
  7310. return 0;
  7311. Spawn* player = lua_interface->GetSpawn(state);
  7312. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7313. lua_interface->ResetFunctionStack(state);
  7314. if (skill_id > 0 && player && player->IsPlayer()) {
  7315. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7316. return 1;
  7317. }
  7318. return 0;
  7319. }
  7320. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7321. if (!lua_interface)
  7322. return 0;
  7323. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7324. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7325. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7326. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7327. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7328. lua_interface->ResetFunctionStack(state);
  7329. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7330. if (player_spawn && player_spawn->IsPlayer()) {
  7331. Player* player = (Player*)player_spawn;
  7332. bool added = false;
  7333. if (!player->skill_list.HasSkill(skill_id)) {
  7334. player->AddSkill(skill_id, current_val, max_val, true);
  7335. added = true;
  7336. }
  7337. 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
  7338. Client* client = player->GetClient();
  7339. if (client) {
  7340. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7341. if (packet)
  7342. client->QueuePacket(packet);
  7343. }
  7344. }
  7345. if (added) {
  7346. lua_interface->SetBooleanValue(state, true);
  7347. return 1;
  7348. }
  7349. }
  7350. else {
  7351. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7352. }
  7353. }
  7354. else {
  7355. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7356. }
  7357. lua_interface->SetBooleanValue(state, false);
  7358. return 1;
  7359. }
  7360. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7361. if (!lua_interface)
  7362. return 0;
  7363. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7364. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7365. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7366. lua_interface->ResetFunctionStack(state);
  7367. if (skill_id > 0) {
  7368. if (player_spawn && player_spawn->IsPlayer()) {
  7369. Player* player = (Player*)player_spawn;
  7370. if (player->skill_list.HasSkill(skill_id)) {
  7371. player->RemovePlayerSkill(skill_id);
  7372. if (!more_to_remove) {
  7373. Client* client = player->GetClient();
  7374. if (client) {
  7375. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7376. if (packet)
  7377. client->QueuePacket(packet);
  7378. }
  7379. }
  7380. }
  7381. }
  7382. else {
  7383. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7384. }
  7385. }
  7386. else {
  7387. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7388. }
  7389. return 0;
  7390. }
  7391. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7392. if (!lua_interface)
  7393. return 0;
  7394. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7395. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7396. int16 amount = lua_interface->GetInt8Value(state, 3);
  7397. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7398. lua_interface->ResetFunctionStack(state);
  7399. if (amount > 0 && skill_type < 100) {
  7400. if (player_spawn && player_spawn->IsPlayer()) {
  7401. Player* player = (Player*)player_spawn;
  7402. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7403. if (!more_to_increase) {
  7404. Client* client = player->GetClient();
  7405. if (client) {
  7406. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7407. if (packet)
  7408. client->QueuePacket(packet);
  7409. }
  7410. }
  7411. }
  7412. else {
  7413. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7414. }
  7415. }
  7416. else {
  7417. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7418. }
  7419. return 0;
  7420. }
  7421. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7422. if (!lua_interface)
  7423. return 0;
  7424. Spawn* spawn = lua_interface->GetSpawn(state);
  7425. string name = lua_interface->GetStringValue(state, 2);
  7426. lua_interface->ResetFunctionStack(state);
  7427. if (!spawn) {
  7428. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7429. return 0;
  7430. }
  7431. if (!spawn->IsEntity()) {
  7432. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7433. return 0;
  7434. }
  7435. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7436. if (skill) {
  7437. lua_interface->SetSkillValue(state, skill);
  7438. return 1;
  7439. }
  7440. return 0;
  7441. }
  7442. int EQ2Emu_lua_AddProc(lua_State* state) {
  7443. if (!lua_interface)
  7444. return 0;
  7445. Spawn* spawn = lua_interface->GetSpawn(state);
  7446. int8 type = lua_interface->GetInt8Value(state, 2);
  7447. float chance = lua_interface->GetFloatValue(state, 3);
  7448. Item* item = lua_interface->GetItem(state, 4);
  7449. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7450. LuaSpell* spell = 0;
  7451. if (!spawn && (!spell || !use_all_spelltargets)) {
  7452. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7453. return 0;
  7454. }
  7455. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7456. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7457. return 0;
  7458. }
  7459. if (!item)
  7460. spell = lua_interface->GetCurrentSpell(state);
  7461. if (!item && !spell) {
  7462. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7463. return 0;
  7464. }
  7465. if(spell && spell->resisted) {
  7466. return 0;
  7467. }
  7468. if (spell && use_all_spelltargets) {
  7469. Spawn* target;
  7470. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7471. for (int8 i = 0; i < spell->targets.size(); i++) {
  7472. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7473. if (!target || !target->IsEntity())
  7474. continue;
  7475. ((Entity*)target)->AddProc(type, chance, item, spell);
  7476. }
  7477. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7478. }
  7479. else
  7480. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7481. return 0;
  7482. }
  7483. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7484. if (!lua_interface)
  7485. return 0;
  7486. Spawn* spawn = lua_interface->GetSpawn(state);
  7487. Item* item = lua_interface->GetItem(state, 2);
  7488. LuaSpell* spell = 0;
  7489. if (!spawn) {
  7490. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7491. lua_interface->ResetFunctionStack(state);
  7492. return 0;
  7493. }
  7494. if (!spawn->IsEntity()) {
  7495. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7496. lua_interface->ResetFunctionStack(state);
  7497. return 0;
  7498. }
  7499. if (!item)
  7500. spell = lua_interface->GetCurrentSpell(state);
  7501. lua_interface->ResetFunctionStack(state);
  7502. if (!item && !spell) {
  7503. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7504. return 0;
  7505. }
  7506. if (spell) {
  7507. Spawn* target;
  7508. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7509. for (int8 i = 0; i < spell->targets.size(); i++) {
  7510. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7511. if (!target || !target->IsEntity())
  7512. continue;
  7513. ((Entity*)target)->RemoveProc(item, spell);
  7514. }
  7515. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7516. spell->caster->RemoveProc(item, spell);
  7517. }
  7518. else
  7519. ((Entity*)spawn)->RemoveProc(item, spell);
  7520. return 0;
  7521. }
  7522. int EQ2Emu_lua_Knockback(lua_State* state) {
  7523. if (!lua_interface)
  7524. return 0;
  7525. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7526. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7527. int32 duration = lua_interface->GetInt32Value(state, 3);
  7528. float vertical = lua_interface->GetFloatValue(state, 4);
  7529. float horizontal = lua_interface->GetFloatValue(state, 5);
  7530. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7531. lua_interface->ResetFunctionStack(state);
  7532. if (!target_spawn) {
  7533. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7534. return 0;
  7535. }
  7536. if (!spawn) {
  7537. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7538. return 0;
  7539. }
  7540. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7541. Client* client = ((Player*)spawn)->GetClient();
  7542. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7543. if (packet) {
  7544. packet->setDataByName("target_x", target_spawn->GetX());
  7545. packet->setDataByName("target_y", target_spawn->GetY());
  7546. packet->setDataByName("target_z", target_spawn->GetZ());
  7547. packet->setDataByName("vertical_movement", vertical);
  7548. packet->setDataByName("horizontal_movement", horizontal);
  7549. if (use_heading)
  7550. packet->setDataByName("use_player_heading", 1);
  7551. client->QueuePacket(packet->serialize());
  7552. }
  7553. safe_delete(packet);
  7554. }
  7555. return 0;
  7556. }
  7557. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7558. if (!lua_interface)
  7559. return 0;
  7560. Spawn* spawn = lua_interface->GetSpawn(state);
  7561. lua_interface->ResetFunctionStack(state);
  7562. if (!spawn) {
  7563. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7564. return 0;
  7565. }
  7566. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7567. return 1;
  7568. }
  7569. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7570. if (!lua_interface)
  7571. return 0;
  7572. Spawn* caster = lua_interface->GetSpawn(state);
  7573. Spawn* target = lua_interface->GetSpawn(state, 2);
  7574. string name = lua_interface->GetStringValue(state, 3);
  7575. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7576. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7577. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7578. string success_msg = lua_interface->GetStringValue(state, 7);
  7579. string effect_msg = lua_interface->GetStringValue(state, 8);
  7580. lua_interface->ResetFunctionStack(state);
  7581. if (!caster) {
  7582. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7583. return 0;
  7584. }
  7585. if (!caster->IsEntity()) {
  7586. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7587. return 0;
  7588. }
  7589. if (!target) {
  7590. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7591. return 0;
  7592. }
  7593. if (!target->IsEntity()) {
  7594. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7595. return 0;
  7596. }
  7597. if (name.length() == 0) {
  7598. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7599. return 0;
  7600. }
  7601. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7602. return 0;
  7603. }
  7604. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7605. if (!lua_interface)
  7606. return 0;
  7607. string name = lua_interface->GetStringValue(state);
  7608. lua_interface->ResetFunctionStack(state);
  7609. if (name.length() == 0) {
  7610. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7611. return 0;
  7612. }
  7613. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7614. if (!skill) {
  7615. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7616. return 0;
  7617. }
  7618. lua_interface->SetInt32Value(state, skill->skill_id);
  7619. return 1;
  7620. }
  7621. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7622. if (!lua_interface)
  7623. return 0;
  7624. Spawn* spawn = lua_interface->GetSpawn(state);
  7625. lua_interface->ResetFunctionStack(state);
  7626. if (!spawn) {
  7627. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7628. return 0;
  7629. }
  7630. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7631. return 1;
  7632. }
  7633. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7634. if (!lua_interface)
  7635. return 0;
  7636. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7637. lua_interface->ResetFunctionStack(state);
  7638. if (!luaspell) {
  7639. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7640. return 0;
  7641. }
  7642. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7643. return 1;
  7644. }
  7645. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7646. if (!lua_interface)
  7647. return 0;
  7648. Spawn* spawn = lua_interface->GetSpawn(state);
  7649. Spawn* target = lua_interface->GetSpawn(state, 2);
  7650. lua_interface->ResetFunctionStack(state);
  7651. if (!spawn) {
  7652. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7653. return 0;
  7654. }
  7655. if (!spawn->IsEntity()) {
  7656. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7657. return 0;
  7658. }
  7659. if (!target) {
  7660. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7661. return 0;
  7662. }
  7663. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7664. return 1;
  7665. }
  7666. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7667. if (!lua_interface)
  7668. return 0;
  7669. Spawn* spawn = lua_interface->GetSpawn(state);
  7670. Spawn* target = lua_interface->GetSpawn(state, 2);
  7671. lua_interface->ResetFunctionStack(state);
  7672. if (!spawn) {
  7673. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7674. return 0;
  7675. }
  7676. if (!spawn->IsEntity()) {
  7677. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7678. return 0;
  7679. }
  7680. if (!target) {
  7681. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7682. return 0;
  7683. }
  7684. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7685. return 1;
  7686. }
  7687. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7688. if (!lua_interface)
  7689. return 0;
  7690. Item* item = lua_interface->GetItem(state);
  7691. lua_interface->ResetFunctionStack(state);
  7692. if (!item) {
  7693. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7694. return 0;
  7695. }
  7696. lua_interface->SetInt32Value(state, item->details.count);
  7697. return 1;
  7698. }
  7699. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7700. if (!lua_interface)
  7701. return 0;
  7702. Item* item = lua_interface->GetItem(state);
  7703. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7704. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7705. lua_interface->ResetFunctionStack(state);
  7706. if (!item) {
  7707. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7708. return 0;
  7709. }
  7710. if (!owner) {
  7711. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7712. return 0;
  7713. }
  7714. if (!owner->IsPlayer()) {
  7715. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7716. return 0;
  7717. }
  7718. if (item->stack_count < new_count) {
  7719. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7720. return 0;
  7721. }
  7722. if (new_count > 0) {
  7723. item->details.count = new_count;
  7724. item->save_needed = true;
  7725. }
  7726. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7727. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7728. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7729. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7730. else
  7731. {
  7732. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7733. return 0;
  7734. }
  7735. Client* client = ((Player*)owner)->GetClient();
  7736. if (!client)
  7737. return 0;
  7738. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7739. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7740. if (app)
  7741. client->QueuePacket(app);
  7742. return 0;
  7743. }
  7744. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7745. if (!lua_interface)
  7746. return 0;
  7747. int32 time = lua_interface->GetInt32Value(state);
  7748. string function = lua_interface->GetStringValue(state, 2);
  7749. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7750. Spawn* target = lua_interface->GetSpawn(state, 4);
  7751. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7752. lua_interface->ResetFunctionStack(state);
  7753. if (time == 0) {
  7754. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7755. return 0;
  7756. }
  7757. if (function.length() == 0) {
  7758. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7759. return 0;
  7760. }
  7761. if (!spell) {
  7762. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7763. return 0;
  7764. }
  7765. SpellScriptTimer* timer = new SpellScriptTimer;
  7766. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7767. #ifdef WIN32
  7768. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7769. #else
  7770. bzero(timer, sizeof(SpellScriptTimer));
  7771. #endif*/
  7772. timer->caster = 0;
  7773. timer->deleteWhenDone = false;
  7774. timer->target = 0;
  7775. timer->time = Timer::GetCurrentTime2() + time;
  7776. timer->customFunction = function;
  7777. timer->spell = spell;
  7778. if (caster)
  7779. timer->caster = caster->GetID();
  7780. if (target)
  7781. timer->target = target->GetID();
  7782. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7783. return 0;
  7784. }
  7785. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7786. if (!lua_interface)
  7787. return 0;
  7788. float hp_perc = lua_interface->GetFloatValue(state);
  7789. float power_perc = lua_interface->GetFloatValue(state, 2);
  7790. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7791. Spawn* target = lua_interface->GetSpawn(state, 4);
  7792. string heal_name = lua_interface->GetStringValue(state, 5);
  7793. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7794. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7795. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7796. lua_interface->ResetFunctionStack(state);
  7797. if (!spell) {
  7798. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7799. return 0;
  7800. }
  7801. Entity* caster = spell->caster;
  7802. if (!caster) {
  7803. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7804. return 0;
  7805. }
  7806. Client* client = 0;
  7807. PendingResurrection* rez = 0;
  7808. ZoneServer* zone = spell->caster->GetZone();
  7809. if (!target) {
  7810. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7811. if (spell->targets.size() > 0) {
  7812. vector<int32> spell_targets = spell->targets;
  7813. for (int8 i = 0; i < spell_targets.size(); i++) {
  7814. target = zone->GetSpawnByID(spell_targets.at(i));
  7815. if (!target)
  7816. continue;
  7817. if (!target->IsPlayer())
  7818. continue;
  7819. client = ((Player*)target)->GetClient();
  7820. if (!client)
  7821. continue;
  7822. rez = client->GetCurrentRez();
  7823. if (rez->active)
  7824. continue;
  7825. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7826. rez->active = true;
  7827. rez->caster = caster;
  7828. rez->expire_timer = new Timer;
  7829. int32 duration = spell->spell->GetSpellDuration();
  7830. rez->expire_timer->Start(duration * 100);
  7831. rez->hp_perc = hp_perc;
  7832. rez->mp_perc = power_perc;
  7833. rez->range = spell->spell->GetSpellData()->range;
  7834. rez->spell_name = spell->spell->GetName();
  7835. if (heal_name.length() > 0)
  7836. rez->heal_name = heal_name;
  7837. else
  7838. rez->heal_name = rez->spell_name;
  7839. rez->no_calcs = no_calcs;
  7840. rez->crit_mod = crit_mod;
  7841. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7842. if (send_window)
  7843. client->SendResurrectionWindow();
  7844. else {
  7845. target->GetZone()->ResurrectSpawn(target, client);
  7846. rez->should_delete = true;
  7847. }
  7848. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7849. }
  7850. }
  7851. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7852. }
  7853. else {
  7854. if(!target->IsPlayer())
  7855. return 0;
  7856. client = ((Player*)target)->GetClient();
  7857. if (!client)
  7858. return 0;
  7859. rez = client->GetCurrentRez();
  7860. if (rez->active)
  7861. return 0;
  7862. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7863. rez->active = true;
  7864. rez->caster = caster;
  7865. rez->expire_timer = new Timer;
  7866. int32 duration = spell->spell->GetSpellDuration();
  7867. rez->expire_timer->Start(duration * 100);
  7868. rez->hp_perc = hp_perc;
  7869. rez->mp_perc = power_perc;
  7870. rez->range = spell->spell->GetSpellData()->range;
  7871. rez->spell_name = spell->spell->GetName();
  7872. if (heal_name.length() > 0)
  7873. rez->heal_name = heal_name;
  7874. else
  7875. rez->heal_name = rez->spell_name;
  7876. rez->no_calcs = no_calcs;
  7877. rez->crit_mod = crit_mod;
  7878. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7879. if (send_window)
  7880. client->SendResurrectionWindow();
  7881. else {
  7882. target->GetZone()->ResurrectSpawn(target, client);
  7883. rez->should_delete = true;
  7884. }
  7885. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7886. }
  7887. return 0;
  7888. }
  7889. int EQ2Emu_lua_SetVision(lua_State* state) {
  7890. if (!lua_interface)
  7891. return 0;
  7892. Spawn* spawn = lua_interface->GetSpawn(state);
  7893. int32 vision = lua_interface->GetInt32Value(state, 2);
  7894. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7895. lua_interface->ResetFunctionStack(state);
  7896. if (!spawn) {
  7897. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7898. return 0;
  7899. }
  7900. if (!spawn->IsEntity()) {
  7901. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7902. return 0;
  7903. }
  7904. if (spell && spell->targets.size() > 0) {
  7905. ZoneServer* zone = spell->caster->GetZone();
  7906. for (int8 i = 0; i < spell->targets.size(); i++) {
  7907. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7908. if (target && target->IsEntity()) {
  7909. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7910. if (target->IsPlayer())
  7911. ((Player*)target)->SetCharSheetChanged(true);
  7912. }
  7913. }
  7914. }
  7915. else {
  7916. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7917. if (spawn->IsPlayer())
  7918. ((Player*)spawn)->SetCharSheetChanged(true);
  7919. }
  7920. return 0;
  7921. }
  7922. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7923. if (!lua_interface)
  7924. return 0;
  7925. Spawn* spawn = lua_interface->GetSpawn(state);
  7926. float intensity = lua_interface->GetFloatValue(state, 2);
  7927. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7928. lua_interface->ResetFunctionStack(state);
  7929. if (!spawn) {
  7930. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7931. return 0;
  7932. }
  7933. if (!spawn->IsEntity()) {
  7934. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7935. return 0;
  7936. }
  7937. if (spell && spell->targets.size() > 0) {
  7938. ZoneServer* zone = spell->caster->GetZone();
  7939. for (int8 i = 0; i < spell->targets.size(); i++) {
  7940. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7941. if (target && target->IsEntity()) {
  7942. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7943. if (target->IsPlayer())
  7944. ((Player*)target)->SetCharSheetChanged(true);
  7945. }
  7946. }
  7947. }
  7948. else {
  7949. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7950. if (spawn->IsPlayer())
  7951. ((Player*)spawn)->SetCharSheetChanged(true);
  7952. }
  7953. return 0;
  7954. }
  7955. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7956. if (!lua_interface)
  7957. return 0;
  7958. Spawn* spawn = lua_interface->GetSpawn(state);
  7959. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7960. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7961. lua_interface->ResetFunctionStack(state);
  7962. if (!spawn) {
  7963. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7964. return 0;
  7965. }
  7966. if (!spawn->IsEntity()) {
  7967. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7968. return 0;
  7969. }
  7970. if (spell && spell->targets.size() > 0) {
  7971. ZoneServer* zone = spell->caster->GetZone();
  7972. for (int8 i = 0; i < spell->targets.size(); i++) {
  7973. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7974. if (target && target->IsEntity()) {
  7975. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7976. if (target->IsPlayer())
  7977. ((Player*)target)->SetCharSheetChanged(true);
  7978. }
  7979. }
  7980. }
  7981. else {
  7982. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7983. if (spawn->IsPlayer())
  7984. ((Player*)spawn)->SetCharSheetChanged(true);
  7985. }
  7986. return 0;
  7987. }
  7988. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7989. if (!lua_interface)
  7990. return 0;
  7991. Item* item = lua_interface->GetItem(state);
  7992. int8 type = lua_interface->GetInt32Value(state, 2);
  7993. lua_interface->ResetFunctionStack(state);
  7994. if (!item) {
  7995. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7996. return 0;
  7997. }
  7998. if (type == 1)
  7999. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8000. else if (type == 2)
  8001. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8002. return 1;
  8003. }
  8004. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8005. if (!lua_interface)
  8006. return 0;
  8007. Spawn* target = lua_interface->GetSpawn(state);
  8008. float val = lua_interface->GetFloatValue(state, 2);
  8009. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8010. lua_interface->ResetFunctionStack(state);
  8011. // Added from Gangrenous post
  8012. if (spell && spell->resisted)
  8013. return 0;
  8014. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8015. if (val > 1.0f)
  8016. val = 1.0f - (val / 100.0f);
  8017. if (spell && spell->spell && spell->targets.size() > 0) {
  8018. ZoneServer* zone = spell->caster->GetZone();
  8019. for (int32 i = 0; i != spell->targets.size(); i++) {
  8020. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8021. if (spawn && spawn->IsEntity()) {
  8022. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8023. if (spawn->IsPlayer())
  8024. ((Player*)spawn)->SetCharSheetChanged(true);
  8025. }
  8026. }
  8027. }
  8028. else {
  8029. if (target && target->IsEntity()) {
  8030. ((Entity*)target)->SetSpeedMultiplier(val);
  8031. if (target->IsPlayer())
  8032. ((Player*)target)->SetCharSheetChanged(true);
  8033. }
  8034. }
  8035. return 0;
  8036. }
  8037. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8038. if (!lua_interface)
  8039. return 0;
  8040. Spawn* spawn = lua_interface->GetSpawn(state);
  8041. int16 model = lua_interface->GetInt16Value(state, 2);
  8042. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8043. lua_interface->ResetFunctionStack(state);
  8044. if (spell && spell->spell && spell->targets.size() > 0) {
  8045. ZoneServer* zone = spell->caster->GetZone();
  8046. for (int32 i = 0; i < spell->targets.size(); i++) {
  8047. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8048. if (target)
  8049. target->SetIllusionModel(model);
  8050. }
  8051. }
  8052. else {
  8053. if (!spawn) {
  8054. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8055. return 0;
  8056. }
  8057. spawn->SetIllusionModel(model);
  8058. }
  8059. return 0;
  8060. }
  8061. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8062. if (!lua_interface)
  8063. return 0;
  8064. Spawn* spawn = lua_interface->GetSpawn(state);
  8065. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8066. lua_interface->ResetFunctionStack(state);
  8067. if (spell && spell->spell && spell->targets.size() > 0) {
  8068. ZoneServer* zone = spell->caster->GetZone();
  8069. for (int32 i = 0; i < spell->targets.size(); i++) {
  8070. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8071. if (target)
  8072. target->SetIllusionModel(0);
  8073. }
  8074. }
  8075. else {
  8076. if (!spawn) {
  8077. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8078. return 0;
  8079. }
  8080. spawn->SetIllusionModel(0);
  8081. }
  8082. return 0;
  8083. }
  8084. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8085. if (!lua_interface)
  8086. return 0;
  8087. Spawn* caster = lua_interface->GetSpawn(state);
  8088. Spawn* target = lua_interface->GetSpawn(state, 2);
  8089. float chance = lua_interface->GetFloatValue(state, 3);
  8090. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8091. lua_interface->ResetFunctionStack(state);
  8092. if (!caster) {
  8093. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8094. return 0;
  8095. }
  8096. if (!caster->IsEntity()) {
  8097. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8098. return 0;
  8099. }
  8100. if (!target) {
  8101. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8102. return 0;
  8103. }
  8104. if (!target->IsEntity()) {
  8105. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8106. return 0;
  8107. }
  8108. if (chance <= 0) {
  8109. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8110. return 0;
  8111. }
  8112. if (!spell) {
  8113. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8114. return 0;
  8115. }
  8116. if(spell->resisted) {
  8117. return 0;
  8118. }
  8119. if (((Entity*)caster)->GetThreatTransfer()) {
  8120. return 0;
  8121. }
  8122. ThreatTransfer* transfer = new ThreatTransfer;
  8123. transfer->Target = target->GetID();
  8124. transfer->Amount = chance;
  8125. transfer->Spell = spell;
  8126. ((Entity*)caster)->SetThreatTransfer(transfer);
  8127. return 0;
  8128. }
  8129. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8130. if (!lua_interface)
  8131. return 0;
  8132. Spawn* spawn = lua_interface->GetSpawn(state);
  8133. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8134. lua_interface->ResetFunctionStack(state);
  8135. if (!spawn) {
  8136. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8137. return 0;
  8138. }
  8139. if (!spell) {
  8140. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8141. return 0;
  8142. }
  8143. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8144. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8145. if(transfer && transfer->Spell != spell) {
  8146. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8147. return 0;
  8148. }
  8149. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8150. }
  8151. return 0;
  8152. }
  8153. int EQ2Emu_lua_CureByType(lua_State* state) {
  8154. if (!lua_interface)
  8155. return 0;
  8156. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8157. int8 cure_count = lua_interface->GetInt8Value(state);
  8158. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8159. string cure_name = lua_interface->GetStringValue(state, 3);
  8160. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8161. Spawn* target = lua_interface->GetSpawn(state, 5);
  8162. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8163. lua_interface->ResetFunctionStack(state);
  8164. if(spell && spell->resisted) {
  8165. return 0;
  8166. }
  8167. if (target) {
  8168. if (!target->IsEntity()) {
  8169. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8170. return 0;
  8171. }
  8172. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8173. std::string alternate_name = "item";
  8174. if(spell)
  8175. alternate_name = std::string(spell->spell->GetName());
  8176. if(!caster && spell)
  8177. caster = (Spawn*)spell->caster;
  8178. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8179. }
  8180. }
  8181. else {
  8182. ZoneServer* zone = spell->caster->GetZone();
  8183. vector<int32> targets = spell->targets;
  8184. vector<Entity*> targets_to_cure;
  8185. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8186. for (int8 i = 0; i < targets.size(); i++) {
  8187. target = zone->GetSpawnByID(targets.at(i));
  8188. if (!target || !target->IsEntity())
  8189. continue;
  8190. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8191. targets_to_cure.push_back((Entity*)target);
  8192. }
  8193. }
  8194. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8195. vector<Entity*>::iterator itr;
  8196. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8197. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8198. }
  8199. }
  8200. return 0;
  8201. }
  8202. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8203. if (!lua_interface)
  8204. return 0;
  8205. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8206. if (!spell) {
  8207. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8208. lua_interface->ResetFunctionStack(state);
  8209. return 0;
  8210. }
  8211. if(spell->resisted) {
  8212. lua_interface->ResetFunctionStack(state);
  8213. return 0;
  8214. }
  8215. int8 cure_count = lua_interface->GetInt8Value(state);
  8216. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8217. string cure_name = lua_interface->GetStringValue(state, 3);
  8218. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8219. Spawn* target = lua_interface->GetSpawn(state, 5);
  8220. lua_interface->ResetFunctionStack(state);
  8221. if (target) {
  8222. if (!target->IsEntity()) {
  8223. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8224. return 0;
  8225. }
  8226. if (((Entity*)target)->GetDetCount() > 0)
  8227. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8228. }
  8229. else {
  8230. ZoneServer* zone = spell->caster->GetZone();
  8231. vector<int32> targets = spell->targets;
  8232. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8233. for (int8 i = 0; i < targets.size(); i++) {
  8234. target = zone->GetSpawnByID(targets.at(i));
  8235. if (!target || !target->IsEntity())
  8236. continue;
  8237. if (((Entity*)target)->GetDetCount() > 0)
  8238. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8239. }
  8240. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8241. }
  8242. return 0;
  8243. }
  8244. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8245. if (!lua_interface)
  8246. return 0;
  8247. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8248. lua_interface->ResetFunctionStack(state);
  8249. if (!spell) {
  8250. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8251. return 0;
  8252. }
  8253. if (!spell->caster) {
  8254. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8255. return 0;
  8256. }
  8257. if (!spell->caster->GetZone()) {
  8258. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8259. return 0;
  8260. }
  8261. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8262. return 0;
  8263. }
  8264. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8265. if (!lua_interface)
  8266. return 0;
  8267. Spawn* spawn = lua_interface->GetSpawn(state);
  8268. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8269. lua_interface->ResetFunctionStack(state);
  8270. if (!spell) {
  8271. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8272. return 0;
  8273. }
  8274. if (spawn && spawn->IsEntity())
  8275. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8276. else {
  8277. ZoneServer* zone = spell->caster->GetZone();
  8278. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8279. for (int32 i = 0; i < spell->targets.size(); i++) {
  8280. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8281. if (!spawn || !spawn->IsEntity())
  8282. continue;
  8283. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8284. }
  8285. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8286. }
  8287. return 0;
  8288. }
  8289. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8290. if (!lua_interface)
  8291. return 0;
  8292. Spawn* spawn = lua_interface->GetSpawn(state);
  8293. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8294. lua_interface->ResetFunctionStack(state);
  8295. if (!spell) {
  8296. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8297. return 0;
  8298. }
  8299. if (spawn && spawn->IsEntity())
  8300. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8301. else {
  8302. ZoneServer* zone = spell->caster->GetZone();
  8303. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8304. for (int32 i = 0; i < spell->targets.size(); i++) {
  8305. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8306. if (!spawn || !spawn->IsEntity())
  8307. continue;
  8308. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8309. }
  8310. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8311. }
  8312. return 0;
  8313. }
  8314. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8315. if (!lua_interface)
  8316. return 0;
  8317. Spawn* caster = lua_interface->GetSpawn(state);
  8318. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8319. lua_interface->ResetFunctionStack(state);
  8320. if (!caster) {
  8321. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. if (!caster->IsPlayer()) {
  8325. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. Spawn* target = caster->GetTarget();
  8329. if (!target) {
  8330. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8331. return 0;
  8332. }
  8333. Client* client = ((Player*)caster)->GetClient();
  8334. if (!client) {
  8335. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8336. return 0;
  8337. }
  8338. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8339. if (ho) {
  8340. ho->SetTarget(target->GetID());
  8341. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8342. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8343. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8344. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8345. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8346. deque<GroupMemberInfo*>::iterator itr;
  8347. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8348. if (group)
  8349. {
  8350. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8351. deque<GroupMemberInfo*>* members = group->GetMembers();
  8352. for (itr = members->begin(); itr != members->end(); itr++) {
  8353. if ((*itr)->client)
  8354. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8355. }
  8356. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8357. }
  8358. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8359. }
  8360. else
  8361. safe_delete(ho);
  8362. }
  8363. else {
  8364. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8365. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8366. }
  8367. else
  8368. safe_delete(ho);
  8369. }
  8370. }
  8371. return 0;
  8372. }
  8373. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8374. if (!lua_interface)
  8375. return 0;
  8376. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8377. if (!spell) {
  8378. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8379. return 0;
  8380. }
  8381. int16 triggerCount = lua_interface->GetInt16Value(state);
  8382. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8383. if (!triggerCount) {
  8384. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8385. return 0;
  8386. }
  8387. spell->num_triggers = triggerCount;
  8388. spell->had_triggers = true;
  8389. spell->cancel_after_all_triggers = cancel_after_triggers;
  8390. return 0;
  8391. }
  8392. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8393. if (!lua_interface)
  8394. return 0;
  8395. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8396. lua_interface->ResetFunctionStack(state);
  8397. if (!spell) {
  8398. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8399. return 0;
  8400. }
  8401. lua_interface->SetInt32Value(state, spell->num_triggers);
  8402. return 1;
  8403. }
  8404. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8405. if (!lua_interface)
  8406. return 0;
  8407. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8408. if (!spell) {
  8409. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8410. lua_interface->ResetFunctionStack(state);
  8411. return 0;
  8412. }
  8413. int16 remove_count = lua_interface->GetInt16Value(state);
  8414. lua_interface->ResetFunctionStack(state);
  8415. if (!remove_count)
  8416. remove_count = 1;
  8417. if (remove_count >= spell->num_triggers) {
  8418. spell->num_triggers = 0;
  8419. if (spell->cancel_after_all_triggers)
  8420. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8421. }
  8422. else {
  8423. spell->num_triggers -= remove_count;
  8424. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8425. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8426. }
  8427. return 0;
  8428. }
  8429. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8430. if (!lua_interface)
  8431. return 0;
  8432. Spawn* spawn = lua_interface->GetSpawn(state);
  8433. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8434. lua_interface->ResetFunctionStack(state);
  8435. if (!spawn) {
  8436. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8437. return 0;
  8438. }
  8439. if (!copy_spawn) {
  8440. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8441. return 0;
  8442. }
  8443. spawn->CopySpawnAppearance(copy_spawn);
  8444. return 0;
  8445. }
  8446. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8447. Spawn* spawn = lua_interface->GetSpawn(state);
  8448. int8 type = lua_interface->GetInt8Value(state, 2);
  8449. lua_interface->ResetFunctionStack(state);
  8450. if (!spawn) {
  8451. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8452. return 0;
  8453. }
  8454. else if (!spawn->IsEntity()) {
  8455. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8456. return 0;
  8457. }
  8458. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8459. return 1;
  8460. }
  8461. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8462. if (!lua_interface)
  8463. return 0;
  8464. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8465. int8 type = lua_interface->GetInt8Value(state);
  8466. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8467. lua_interface->ResetFunctionStack(state);
  8468. if (!spell) {
  8469. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8470. return 0;
  8471. }
  8472. if(spell->resisted) {
  8473. return 0;
  8474. }
  8475. if (spawn) {
  8476. if (!spawn->IsEntity()) {
  8477. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8478. return 0;
  8479. }
  8480. Entity* entity = ((Entity*)spawn);
  8481. entity->AddImmunity(spell, type);
  8482. }
  8483. else {
  8484. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8485. for (int8 i = 0; i < spell->targets.size(); i++) {
  8486. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8487. if (!spawn || !spawn->IsEntity())
  8488. continue;
  8489. Entity* entity = ((Entity*)spawn);
  8490. entity->AddImmunity(spell, type);
  8491. }
  8492. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8493. }
  8494. return 0;
  8495. }
  8496. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8497. if (!lua_interface)
  8498. return 0;
  8499. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8500. int8 type = lua_interface->GetInt8Value(state);
  8501. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8502. lua_interface->ResetFunctionStack(state);
  8503. if (!spell) {
  8504. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8505. return 0;
  8506. }
  8507. if (spawn) {
  8508. if (!spawn->IsEntity()) {
  8509. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8510. return 0;
  8511. }
  8512. Entity* entity = ((Entity*)spawn);
  8513. entity->RemoveImmunity(spell, type);
  8514. }
  8515. else {
  8516. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8517. for (int8 i = 0; i < spell->targets.size(); i++) {
  8518. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8519. if (!spawn || !spawn->IsEntity())
  8520. continue;
  8521. Entity* entity = ((Entity*)spawn);
  8522. entity->RemoveImmunity(spell, type);
  8523. }
  8524. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8525. }
  8526. return 0;
  8527. }
  8528. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8529. if (!lua_interface)
  8530. return 0;
  8531. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8532. if (!spell) {
  8533. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8534. lua_interface->ResetFunctionStack(state);
  8535. return 0;
  8536. }
  8537. if(spell->resisted) {
  8538. lua_interface->ResetFunctionStack(state);
  8539. return 0;
  8540. }
  8541. float snare = lua_interface->GetFloatValue(state);
  8542. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8543. lua_interface->ResetFunctionStack(state);
  8544. // convert the val to the speed multipler value (100 - val)
  8545. float val = 100.0 - snare;
  8546. val /= 100.0;
  8547. if (spawn) {
  8548. if (!spawn->IsEntity()) {
  8549. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8550. return 0;
  8551. }
  8552. ((Entity*)spawn)->SetSnareValue(spell, val);
  8553. }
  8554. else {
  8555. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8556. for (int8 i = 0; i < spell->targets.size(); i++) {
  8557. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8558. if (!spawn || !spawn->IsEntity())
  8559. continue;
  8560. ((Entity*)spawn)->SetSnareValue(spell, val);
  8561. }
  8562. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8563. }
  8564. return 0;
  8565. }
  8566. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8567. if (!lua_interface)
  8568. return 0;
  8569. Spawn* spawn = lua_interface->GetSpawn(state);
  8570. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8571. lua_interface->ResetFunctionStack(state);
  8572. if (!spawn) {
  8573. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8574. return 0;
  8575. }
  8576. if (race_id == 0) {
  8577. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8578. return 0;
  8579. }
  8580. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8581. return 1;
  8582. }
  8583. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8584. if (!lua_interface)
  8585. return 0;
  8586. Spawn* spawn = lua_interface->GetSpawn(state);
  8587. lua_interface->ResetFunctionStack(state);
  8588. if (!spawn) {
  8589. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8590. return 0;
  8591. }
  8592. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8593. return 1;
  8594. }
  8595. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8596. if (!lua_interface)
  8597. return 0;
  8598. Spawn* spawn = lua_interface->GetSpawn(state);
  8599. lua_interface->ResetFunctionStack(state);
  8600. if (!spawn) {
  8601. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8602. return 0;
  8603. }
  8604. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8605. return 1;
  8606. }
  8607. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8608. if (!lua_interface)
  8609. return 0;
  8610. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8611. lua_interface->ResetFunctionStack(state);
  8612. if (!spell) {
  8613. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8614. return 0;
  8615. }
  8616. lua_interface->SetStringValue(state, spell->spell->GetName());
  8617. return 1;
  8618. }
  8619. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8620. if (!lua_interface)
  8621. return 0;
  8622. Quest* quest = lua_interface->GetQuest(state);
  8623. lua_interface->ResetFunctionStack(state);
  8624. if (!quest) {
  8625. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8626. return 0;
  8627. }
  8628. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8629. return 1;
  8630. }
  8631. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8632. if (!lua_interface)
  8633. return 0;
  8634. Quest* quest = lua_interface->GetQuest(state);
  8635. int32 flags = lua_interface->GetInt32Value(state, 2);
  8636. lua_interface->ResetFunctionStack(state);
  8637. if (!quest) {
  8638. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8639. return 0;
  8640. }
  8641. quest->SetQuestFlags(flags);
  8642. return 0;
  8643. }
  8644. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8645. if (!lua_interface)
  8646. return 0;
  8647. Quest* quest = lua_interface->GetQuest(state);
  8648. Spawn* player = lua_interface->GetSpawn(state, 2);
  8649. int32 step = lua_interface->GetInt32Value(state, 3);
  8650. int32 duration = lua_interface->GetInt32Value(state, 4);
  8651. string action = lua_interface->GetStringValue(state, 5);
  8652. lua_interface->ResetFunctionStack(state);
  8653. if (!quest) {
  8654. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8655. return 0;
  8656. }
  8657. if (!player) {
  8658. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8659. return 0;
  8660. }
  8661. if (!player->IsPlayer()) {
  8662. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8663. return 0;
  8664. }
  8665. if (step == 0) {
  8666. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. if (duration == 0) {
  8670. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8671. return 0;
  8672. }
  8673. if (action.length() == 0) {
  8674. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8675. return 0;
  8676. }
  8677. Client* client = ((Player*)player)->GetClient();
  8678. if (!client) {
  8679. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8680. return 0;
  8681. }
  8682. quest->SetTimerStep(step);
  8683. quest->AddFailedAction(step, action);
  8684. quest->SetStepTimer(duration);
  8685. client->AddQuestTimer(quest->GetQuestID());
  8686. return 0;
  8687. }
  8688. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8689. if (!lua_interface)
  8690. return 0;
  8691. Quest* quest = lua_interface->GetQuest(state);
  8692. Spawn* player = lua_interface->GetSpawn(state, 2);
  8693. lua_interface->ResetFunctionStack(state);
  8694. if (!quest) {
  8695. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8696. return 0;
  8697. }
  8698. if (!player) {
  8699. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8700. return 0;
  8701. }
  8702. if (!player->IsPlayer()) {
  8703. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8704. return 0;
  8705. }
  8706. Client* client = ((Player*)player)->GetClient();
  8707. if (!client) {
  8708. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8709. return 0;
  8710. }
  8711. quest->SetTimerStep(0);
  8712. quest->SetStepTimer(0);
  8713. client->RemoveQuestTimer(quest->GetQuestID());
  8714. return 0;
  8715. }
  8716. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8717. if (!lua_interface)
  8718. return 0;
  8719. Spawn* player = lua_interface->GetSpawn(state);
  8720. Quest* quest = lua_interface->GetQuest(state, 2);
  8721. int32 step = lua_interface->GetInt32Value(state, 3);
  8722. lua_interface->ResetFunctionStack(state);
  8723. if (!player) {
  8724. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8725. return 0;
  8726. }
  8727. if (!player->IsPlayer()) {
  8728. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8729. return 0;
  8730. }
  8731. if (!quest) {
  8732. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8733. return 0;
  8734. }
  8735. if (step == 0) {
  8736. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8737. return 0;
  8738. }
  8739. Client* client = ((Player*)player)->GetClient();
  8740. if (!client) {
  8741. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8742. return 0;
  8743. }
  8744. if (quest->RemoveQuestStep(step, client)) {
  8745. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8746. client->GetCurrentZone()->SendQuestUpdates(client);
  8747. }
  8748. else
  8749. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8750. return 0;
  8751. }
  8752. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8753. if (!lua_interface)
  8754. return 0;
  8755. Quest* quest = lua_interface->GetQuest(state, 1);
  8756. int32 step = lua_interface->GetInt32Value(state, 2);
  8757. string desc = lua_interface->GetStringValue(state, 3);
  8758. string task_group = lua_interface->GetStringValue(state, 4);
  8759. lua_interface->ResetFunctionStack(state);
  8760. if (!quest) {
  8761. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8762. return 0;
  8763. }
  8764. if (step == 0) {
  8765. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8766. return 0;
  8767. }
  8768. QuestStep* quest_step = quest->GetQuestStep(step);
  8769. if (!quest_step) {
  8770. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8771. return 0;
  8772. }
  8773. quest_step->SetStepProgress(0);
  8774. quest_step->SetTaskGroup(task_group);
  8775. quest_step->SetDescription(desc);
  8776. return 0;
  8777. }
  8778. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8779. if (!lua_interface)
  8780. return 0;
  8781. Quest* quest = lua_interface->GetQuest(state);
  8782. int32 step = lua_interface->GetInt32Value(state, 2);
  8783. string action = lua_interface->GetStringValue(state, 3);
  8784. lua_interface->ResetFunctionStack(state);
  8785. if (!quest) {
  8786. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8787. return 0;
  8788. }
  8789. if (step == 0) {
  8790. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8791. return 0;
  8792. }
  8793. if (action.length() == 0) {
  8794. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8795. return 0;
  8796. }
  8797. quest->AddFailedAction(step, action);
  8798. return 0;
  8799. }
  8800. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8801. if (!lua_interface)
  8802. return 0;
  8803. Spawn* player = lua_interface->GetSpawn(state);
  8804. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8805. int32 step = lua_interface->GetInt32Value(state, 3);
  8806. lua_interface->ResetFunctionStack(state);
  8807. if (!player) {
  8808. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8809. return 0;
  8810. }
  8811. if (!player->IsPlayer()) {
  8812. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8813. return 0;
  8814. }
  8815. if (quest_id == 0) {
  8816. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8817. return 0;
  8818. }
  8819. if (step == 0) {
  8820. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8821. return 0;
  8822. }
  8823. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8824. if (!quest) {
  8825. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8826. return 0;
  8827. }
  8828. quest->StepFailed(step);
  8829. return 0;
  8830. }
  8831. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8832. if (!lua_interface)
  8833. return 0;
  8834. Spawn* player = lua_interface->GetSpawn(state);
  8835. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8836. lua_interface->ResetFunctionStack(state);
  8837. if (!player) {
  8838. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8839. return 0;
  8840. }
  8841. if (!player->IsPlayer()) {
  8842. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8843. return 0;
  8844. }
  8845. if (quest_id == 0) {
  8846. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8847. return 0;
  8848. }
  8849. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8850. if (!quest) {
  8851. lua_interface->SetInt32Value(state, 0);
  8852. return 1;
  8853. }
  8854. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8855. return 1;
  8856. }
  8857. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8858. if (!lua_interface)
  8859. return 0;
  8860. string name = lua_interface->GetStringValue(state);
  8861. string value = lua_interface->GetStringValue(state, 2);
  8862. string comment = lua_interface->GetStringValue(state, 3);
  8863. lua_interface->ResetFunctionStack(state);
  8864. if (name.length() == 0) {
  8865. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8866. return 0;
  8867. }
  8868. if (value.length() == 0) {
  8869. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8870. return 0;
  8871. }
  8872. string varname = string("lua_").append(name);
  8873. Variable* var = variables.FindVariable(varname);
  8874. if (var)
  8875. var->SetValue(value.c_str());
  8876. else {
  8877. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8878. variables.AddVariable(var);
  8879. }
  8880. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8881. return 0;
  8882. }
  8883. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8884. if (!lua_interface)
  8885. return 0;
  8886. string name = lua_interface->GetStringValue(state);
  8887. lua_interface->ResetFunctionStack(state);
  8888. if (name.length() == 0) {
  8889. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8890. return 0;
  8891. }
  8892. string varname = string("lua_").append(name);
  8893. Variable* var = variables.FindVariable(varname);
  8894. if (var)
  8895. lua_interface->SetStringValue(state, var->GetValue());
  8896. else
  8897. lua_interface->SetStringValue(state, "NULL");
  8898. return 1;
  8899. }
  8900. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8901. if (!lua_interface)
  8902. return 0;
  8903. Spawn* player = lua_interface->GetSpawn(state);
  8904. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8905. lua_interface->ResetFunctionStack(state);
  8906. if (!player) {
  8907. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8908. return 0;
  8909. }
  8910. if (!player->IsPlayer()) {
  8911. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8912. return 0;
  8913. }
  8914. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8915. return 1;
  8916. }
  8917. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8918. if (!lua_interface)
  8919. return 0;
  8920. Spawn* player = lua_interface->GetSpawn(state);
  8921. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8922. lua_interface->ResetFunctionStack(state);
  8923. if (!player) {
  8924. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8925. return 0;
  8926. }
  8927. if (!player->IsPlayer()) {
  8928. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8929. return 0;
  8930. }
  8931. Language* language = master_languages_list.GetLanguage(language_id);
  8932. if (language)
  8933. {
  8934. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8935. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  8936. }
  8937. return 0;
  8938. }
  8939. int EQ2Emu_lua_IsNight(lua_State* state) {
  8940. if (!lua_interface)
  8941. return 0;
  8942. ZoneServer* zone = lua_interface->GetZone(state);
  8943. lua_interface->ResetFunctionStack(state);
  8944. if (!zone) {
  8945. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8946. return 0;
  8947. }
  8948. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8949. return 1;
  8950. }
  8951. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8952. if (!lua_interface)
  8953. return 0;
  8954. Spawn* spawn = lua_interface->GetSpawn(state);
  8955. lua_interface->ResetFunctionStack(state);
  8956. if (!spawn) {
  8957. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8958. return 0;
  8959. }
  8960. if (!spawn->IsWidget()) {
  8961. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8962. return 0;
  8963. }
  8964. ((Widget*)spawn)->SetMultiFloorLift(true);
  8965. if (spawn->GetZone())
  8966. spawn->GetZone()->AddTransportSpawn(spawn);
  8967. return 0;
  8968. }
  8969. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8970. if (!lua_interface)
  8971. return 0;
  8972. Spawn* player = lua_interface->GetSpawn(state);
  8973. int32 path = lua_interface->GetInt32Value(state, 2);
  8974. lua_interface->ResetFunctionStack(state);
  8975. if (!player) {
  8976. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8977. return 0;
  8978. }
  8979. if (!player->IsPlayer()) {
  8980. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8981. return 0;
  8982. }
  8983. if (path == 0) {
  8984. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8985. return 0;
  8986. }
  8987. Client* client = ((Player*)player)->GetClient();
  8988. if (!client) {
  8989. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8990. return 0;
  8991. }
  8992. client->SendFlightAutoMount(path);
  8993. return 0;
  8994. }
  8995. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8996. if (!lua_interface)
  8997. return 0;
  8998. Spawn* player = lua_interface->GetSpawn(state);
  8999. if (!player) {
  9000. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9001. return 0;
  9002. }
  9003. if (!player->IsPlayer()) {
  9004. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9005. return 0;
  9006. }
  9007. Client* client = ((Player*)player)->GetClient();
  9008. if (!client) {
  9009. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9010. return 0;
  9011. }
  9012. client->EndAutoMount();
  9013. return 0;
  9014. }
  9015. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9016. if (!lua_interface)
  9017. return 0;
  9018. Spawn* player = lua_interface->GetSpawn(state);
  9019. lua_interface->ResetFunctionStack(state);
  9020. if (!player) {
  9021. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9022. return 0;
  9023. }
  9024. if (!player->IsPlayer()) {
  9025. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9026. return 0;
  9027. }
  9028. Client* client = ((Player*)player)->GetClient();
  9029. if (!client) {
  9030. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9031. return 0;
  9032. }
  9033. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9034. return 1;
  9035. }
  9036. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9037. if (!lua_interface)
  9038. return 0;
  9039. Spawn* player = lua_interface->GetSpawn(state);
  9040. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9041. int32 value = lua_interface->GetInt32Value(state, 3);
  9042. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9043. lua_interface->ResetFunctionStack(state);
  9044. if (!player) {
  9045. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9046. return 0;
  9047. }
  9048. if (!player->IsPlayer()) {
  9049. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9050. return 0;
  9051. }
  9052. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9053. return 0;
  9054. }
  9055. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9056. if (!lua_interface)
  9057. return 0;
  9058. Spawn* player = lua_interface->GetSpawn(state);
  9059. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9060. lua_interface->ResetFunctionStack(state);
  9061. if (!player) {
  9062. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9063. return 0;
  9064. }
  9065. if (!player->IsPlayer()) {
  9066. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9067. return 0;
  9068. }
  9069. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9070. if (!hd)
  9071. return 0;
  9072. lua_interface->SetInt32Value(state, hd->Value);
  9073. lua_interface->SetInt32Value(state, hd->Value2);
  9074. return 2;
  9075. }
  9076. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9077. if (!lua_interface)
  9078. return 0;
  9079. Spawn* spawn = lua_interface->GetSpawn(state);
  9080. int32 grid = lua_interface->GetInt32Value(state, 2);
  9081. lua_interface->ResetFunctionStack(state);
  9082. if (!spawn) {
  9083. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9084. return 0;
  9085. }
  9086. if (grid == 0) {
  9087. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9088. return 0;
  9089. }
  9090. spawn->SetLocation(grid);
  9091. return 0;
  9092. }
  9093. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9094. if (!lua_interface)
  9095. return 0;
  9096. Spawn* spawn = lua_interface->GetSpawn(state);
  9097. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9098. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9099. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9100. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9101. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9102. lua_interface->ResetFunctionStack(state);
  9103. if (!spawn) {
  9104. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9105. return 0;
  9106. }
  9107. //Add this quest to the list of required quests for this spawn
  9108. spawn->SetRequiredHistory(event_id, value1, value2);
  9109. //If private spawn value set
  9110. if (private_spawn) {
  9111. //Set the spawn to be private when not granted access via history
  9112. spawn->AddAllowAccessSpawn(spawn);
  9113. spawn->SetPrivateQuestSpawn(true);
  9114. }
  9115. //This value will override vis_flags in the vis packet
  9116. if (flag_override > 0)
  9117. spawn->SetQuestsRequiredOverride(flag_override);
  9118. return 0;
  9119. }
  9120. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9121. if (!lua_interface)
  9122. return 0;
  9123. Spawn* player = lua_interface->GetSpawn(state);
  9124. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9125. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9126. lua_interface->ResetFunctionStack(state);
  9127. if (!player) {
  9128. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9129. return 0;
  9130. }
  9131. if (!player->IsPlayer()) {
  9132. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9133. return 0;
  9134. }
  9135. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9136. return 1;
  9137. }
  9138. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9139. if (!lua_interface)
  9140. return 0;
  9141. Spawn* player = lua_interface->GetSpawn(state);
  9142. int8 level = lua_interface->GetInt8Value(state, 2);
  9143. lua_interface->ResetFunctionStack(state);
  9144. if (!player) {
  9145. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9146. return 0;
  9147. }
  9148. if (!player->IsPlayer()) {
  9149. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9150. return 0;
  9151. }
  9152. if (level == 0) {
  9153. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9154. return 0;
  9155. }
  9156. Client* client = ((Player*)player)->GetClient();
  9157. if (!client) {
  9158. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9159. return 0;
  9160. }
  9161. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9162. return 0;
  9163. }
  9164. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9165. if (!lua_interface)
  9166. return 0;
  9167. Spawn* player = lua_interface->GetSpawn(state);
  9168. int32 amount = lua_interface->GetInt32Value(state, 2);
  9169. lua_interface->ResetFunctionStack(state);
  9170. if (!player) {
  9171. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9172. return 0;
  9173. }
  9174. if (!player->IsPlayer()) {
  9175. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9176. return 0;
  9177. }
  9178. if (amount == 0) {
  9179. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9180. return 0;
  9181. }
  9182. ((Player*)player)->AddCoins(amount);
  9183. return 0;
  9184. }
  9185. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9186. if (!lua_interface)
  9187. return 0;
  9188. Spawn* player = lua_interface->GetSpawn(state);
  9189. int32 amount = lua_interface->GetInt32Value(state, 2);
  9190. lua_interface->ResetFunctionStack(state);
  9191. if (!player) {
  9192. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9193. return 0;
  9194. }
  9195. if (!player->IsPlayer()) {
  9196. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9197. return 0;
  9198. }
  9199. if (amount == 0) {
  9200. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9201. return 0;
  9202. }
  9203. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9204. return 1;
  9205. }
  9206. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9207. if (!lua_interface)
  9208. return 0;
  9209. ZoneServer* zone = lua_interface->GetZone(state);
  9210. lua_interface->ResetFunctionStack(state);
  9211. if (!zone) {
  9212. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9213. return 0;
  9214. }
  9215. vector<Entity*> players = zone->GetPlayers();
  9216. if (players.size() == 0)
  9217. return 0;
  9218. lua_createtable(state, players.size(), 0);
  9219. int newTable = lua_gettop(state);
  9220. for (int32 i = 0; i < players.size(); i++) {
  9221. lua_interface->SetSpawnValue(state, players.at(i));
  9222. lua_rawseti(state, newTable, i + 1);
  9223. }
  9224. return 1;
  9225. }
  9226. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9227. if (!lua_interface)
  9228. return 0;
  9229. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9230. if (!zone) {
  9231. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9232. return 0;
  9233. }
  9234. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9235. lua_interface->ResetFunctionStack(state);
  9236. //Map of <placement_id, location_id>
  9237. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9238. map<int32, int32>::iterator itr;
  9239. vector<Spawn*> group;
  9240. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9241. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9242. if (!location) {
  9243. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9244. return 0;
  9245. }
  9246. Spawn* spawn = 0;
  9247. if (location->entities[0]) {
  9248. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9249. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9250. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9251. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9252. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9253. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9254. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9255. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9256. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9257. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9258. if(spawn && spawn->IsOmittedByDBFlag())
  9259. {
  9260. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  9261. safe_delete(spawn);
  9262. continue;
  9263. }
  9264. if (spawn) {
  9265. const char* script = 0;
  9266. for (int x = 0; x < 3; x++) {
  9267. switch (x) {
  9268. case 0:
  9269. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9270. break;
  9271. case 1:
  9272. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9273. break;
  9274. case 2:
  9275. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9276. break;
  9277. }
  9278. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9279. spawn->SetSpawnScript(string(script));
  9280. break;
  9281. }
  9282. }
  9283. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9284. lua_interface->SetSpawnValue(state, spawn);
  9285. group.push_back(spawn);
  9286. }
  9287. else {
  9288. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9289. safe_delete(spawn);
  9290. }
  9291. }
  9292. }
  9293. if (!group.empty()) {
  9294. lua_createtable(state, group.size(), 0);
  9295. int newTable = lua_gettop(state);
  9296. for (int32 i = 0; i < group.size(); i++) {
  9297. lua_interface->SetSpawnValue(state, group[i]);
  9298. lua_rawseti(state, newTable, i + 1);
  9299. }
  9300. }
  9301. else
  9302. lua_pushnil(state);
  9303. return 1;
  9304. }
  9305. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9306. if (!lua_interface)
  9307. return 0;
  9308. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9309. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9310. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9311. lua_interface->ResetFunctionStack(state);
  9312. if (!spawn) {
  9313. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9314. return 0;
  9315. }
  9316. if (anim_id == 0) {
  9317. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9318. return 0;
  9319. }
  9320. if (leeway == 0)
  9321. leeway = 5000;
  9322. spawn->SetSpawnAnim(anim_id);
  9323. spawn->SetSpawnAnimLeeway(leeway);
  9324. return 0;
  9325. }
  9326. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9327. if (!lua_interface)
  9328. return 0;
  9329. Spawn* player = lua_interface->GetSpawn(state);
  9330. lua_interface->ResetFunctionStack(state);
  9331. if (!player || !player->IsPlayer()) {
  9332. return 0;
  9333. }
  9334. Client* client = ((Player*)player)->GetClient();
  9335. if (!client) {
  9336. return 0;
  9337. }
  9338. lua_interface->SetInt32Value(state, client->GetVersion());
  9339. return 1;
  9340. }
  9341. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9342. if (!lua_interface)
  9343. return 0;
  9344. Item* item = lua_interface->GetItem(state);
  9345. lua_interface->ResetFunctionStack(state);
  9346. if (!item) {
  9347. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9348. return 0;
  9349. }
  9350. lua_interface->SetInt32Value(state, item->details.item_id);
  9351. return 1;
  9352. }
  9353. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9354. if (!lua_interface)
  9355. return 0;
  9356. Spawn* spawn = lua_interface->GetSpawn(state);
  9357. lua_interface->ResetFunctionStack(state);
  9358. if (!spawn) {
  9359. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9360. return 0;
  9361. }
  9362. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9363. return 1;
  9364. }
  9365. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9366. if (!lua_interface)
  9367. return 0;
  9368. Spawn* spawn = lua_interface->GetSpawn(state);
  9369. lua_interface->ResetFunctionStack(state);
  9370. if (!spawn) {
  9371. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9372. return 0;
  9373. }
  9374. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9375. return 1;
  9376. }
  9377. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9378. if (!lua_interface)
  9379. return 0;
  9380. Spawn* spawn = lua_interface->GetSpawn(state);
  9381. lua_interface->ResetFunctionStack(state);
  9382. if (!spawn) {
  9383. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9384. return 0;
  9385. }
  9386. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9387. return 1;
  9388. }
  9389. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9390. if (!lua_interface)
  9391. return 0;
  9392. Spawn* spawn = lua_interface->GetSpawn(state);
  9393. lua_interface->ResetFunctionStack(state);
  9394. if (!spawn) {
  9395. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9396. return 0;
  9397. }
  9398. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9399. return 1;
  9400. }
  9401. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9402. if (!lua_interface)
  9403. return 0;
  9404. Spawn* spawn = lua_interface->GetSpawn(state);
  9405. float pct = lua_interface->GetFloatValue(state, 2);
  9406. lua_interface->ResetFunctionStack(state);
  9407. if (!spawn) {
  9408. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9409. return 0;
  9410. }
  9411. if (pct == 0) {
  9412. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9413. return 0;
  9414. }
  9415. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9416. lua_interface->SetInt32Value(state, amount);
  9417. return 1;
  9418. }
  9419. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9420. if (!lua_interface)
  9421. return 0;
  9422. Spawn* spawn = lua_interface->GetSpawn(state);
  9423. float pct = lua_interface->GetFloatValue(state, 2);
  9424. lua_interface->ResetFunctionStack(state);
  9425. if (!spawn) {
  9426. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9427. return 0;
  9428. }
  9429. if (pct == 0) {
  9430. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9431. return 0;
  9432. }
  9433. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9434. lua_interface->SetInt32Value(state, amount);
  9435. return 1;
  9436. }
  9437. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9438. if (!lua_interface)
  9439. return 0;
  9440. Spawn* spawn = lua_interface->GetSpawn(state);
  9441. lua_interface->ResetFunctionStack(state);
  9442. if (!spawn) {
  9443. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9444. return 0;
  9445. }
  9446. if (!spawn->IsPlayer()) {
  9447. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9448. return 0;
  9449. }
  9450. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9451. return 1;
  9452. }
  9453. int EQ2Emu_lua_Evac(lua_State* state) {
  9454. if (!lua_interface)
  9455. return 0;
  9456. Spawn* target = lua_interface->GetSpawn(state);
  9457. if (target) {
  9458. float x = target->GetZone()->GetSafeX();
  9459. float y = target->GetZone()->GetSafeY();
  9460. float z = target->GetZone()->GetSafeZ();
  9461. float h = target->GetZone()->GetSafeHeading();
  9462. target->SetX(x);
  9463. target->SetY(y);
  9464. target->SetZ(z);
  9465. target->SetHeading(h);
  9466. target->SetSpawnOrigX(x);
  9467. target->SetSpawnOrigY(y);
  9468. target->SetSpawnOrigZ(z);
  9469. target->SetSpawnOrigHeading(h);
  9470. if (target->IsPlayer()) {
  9471. Client* client = ((Player*)target)->GetClient();
  9472. if (client) {
  9473. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9474. int numargs = lua_interface->GetNumberOfArgs(state);
  9475. if(numargs == 4) {
  9476. x = lua_interface->GetFloatValue(state,1);
  9477. y = lua_interface->GetFloatValue(state,2);
  9478. z = lua_interface->GetFloatValue(state,3);
  9479. h = lua_interface->GetFloatValue(state,4);
  9480. }
  9481. client->SetReloadingZone(true);
  9482. target->SetX(x);
  9483. target->SetY(y);
  9484. target->SetZ(z);
  9485. target->SetHeading(h);
  9486. target->SetSpawnOrigX(x);
  9487. target->SetSpawnOrigY(y);
  9488. target->SetSpawnOrigZ(z);
  9489. target->SetSpawnOrigHeading(h);
  9490. target->SetAppearancePosition(x,y,z);
  9491. client->SetZoningCoords(x,y,z,h);
  9492. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9493. if (packet)
  9494. {
  9495. packet->setDataByName("x", x);
  9496. packet->setDataByName("y", y);
  9497. packet->setDataByName("z", z);
  9498. client->QueuePacket(packet->serialize());
  9499. safe_delete(packet);
  9500. }
  9501. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9502. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9503. }
  9504. }
  9505. lua_interface->ResetFunctionStack(state);
  9506. }
  9507. else {
  9508. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9509. if(!spell) {
  9510. lua_interface->ResetFunctionStack(state);
  9511. return 0;
  9512. }
  9513. ZoneServer* zone = spell->caster->GetZone();
  9514. float x = spell->caster->GetZone()->GetSafeX();
  9515. float y = spell->caster->GetZone()->GetSafeY();
  9516. float z = spell->caster->GetZone()->GetSafeZ();
  9517. float h = spell->caster->GetZone()->GetSafeHeading();
  9518. int numargs = lua_interface->GetNumberOfArgs(state);
  9519. if(numargs == 4) {
  9520. x = lua_interface->GetFloatValue(state,1);
  9521. y = lua_interface->GetFloatValue(state,2);
  9522. z = lua_interface->GetFloatValue(state,3);
  9523. h = lua_interface->GetFloatValue(state,4);
  9524. }
  9525. lua_interface->ResetFunctionStack(state);
  9526. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9527. for (int32 i = 0; i < spell->targets.size(); i++) {
  9528. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9529. if (!target2)
  9530. continue;
  9531. if (target2->IsPlayer()) {
  9532. Client* client = ((Player*)target2)->GetClient();
  9533. if (client) {
  9534. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9535. client->SetReloadingZone(true);
  9536. target2->SetX(x);
  9537. target2->SetY(y);
  9538. target2->SetZ(z);
  9539. target2->SetHeading(h);
  9540. target2->SetSpawnOrigX(x);
  9541. target2->SetSpawnOrigY(y);
  9542. target2->SetSpawnOrigZ(z);
  9543. target2->SetSpawnOrigHeading(h);
  9544. target2->SetAppearancePosition(x,y,z);
  9545. client->SetZoningCoords(x,y,z,h);
  9546. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9547. if (packet)
  9548. {
  9549. packet->setDataByName("x", x);
  9550. packet->setDataByName("y", y);
  9551. packet->setDataByName("z", z);
  9552. client->QueuePacket(packet->serialize());
  9553. safe_delete(packet);
  9554. }
  9555. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9556. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9557. }
  9558. }
  9559. }
  9560. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9561. }
  9562. return 0;
  9563. }
  9564. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9565. if (!lua_interface)
  9566. return 0;
  9567. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9568. lua_interface->ResetFunctionStack(state);
  9569. if (!luaspell) {
  9570. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9571. return 0;
  9572. }
  9573. int8 tier = luaspell->spell->GetSpellTier();
  9574. lua_interface->SetInt32Value(state, tier);
  9575. return 1;
  9576. }
  9577. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9578. if (!lua_interface)
  9579. return 0;
  9580. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9581. lua_interface->ResetFunctionStack(state);
  9582. if (!luaspell) {
  9583. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9584. return 0;
  9585. }
  9586. int32 spell_id = luaspell->spell->GetSpellID();
  9587. lua_interface->SetInt32Value(state, spell_id);
  9588. return 1;
  9589. }
  9590. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9591. if (!lua_interface)
  9592. return 0;
  9593. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9594. lua_interface->ResetFunctionStack(state);
  9595. if (!spawn) {
  9596. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9597. return 0;
  9598. }
  9599. if (!spawn->IsPlayer()) {
  9600. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9601. return 0;
  9602. }
  9603. ZoneServer* zone = spawn->GetZone();
  9604. if (!zone) {
  9605. return 0;
  9606. }
  9607. Client* client = ((Player*)spawn)->GetClient();
  9608. if (!client) {
  9609. return 0;
  9610. }
  9611. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9612. return 0;
  9613. }
  9614. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9615. if (!lua_interface)
  9616. return 0;
  9617. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9618. lua_interface->ResetFunctionStack(state);
  9619. if (!spawn) {
  9620. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9621. return 0;
  9622. }
  9623. if (!spawn->IsPlayer()) {
  9624. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9625. return 0;
  9626. }
  9627. ZoneServer* zone = spawn->GetZone();
  9628. if (!zone) {
  9629. return 0;
  9630. }
  9631. Client* client = ((Player*)spawn)->GetClient();
  9632. if (!client) {
  9633. return 0;
  9634. }
  9635. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9636. return 0;
  9637. }
  9638. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9639. if (!lua_interface)
  9640. return 0;
  9641. Spawn* caster = lua_interface->GetSpawn(state);
  9642. Spawn* target = lua_interface->GetSpawn(state, 2);
  9643. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9644. string spell_name = lua_interface->GetStringValue(state, 4);
  9645. lua_interface->ResetFunctionStack(state);
  9646. if (!caster) {
  9647. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9648. return 0;
  9649. }
  9650. if (!caster->IsEntity()) {
  9651. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9652. return 0;
  9653. }
  9654. if (!target) {
  9655. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9656. return 0;
  9657. }
  9658. if (!target->IsEntity()) {
  9659. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9660. return 0;
  9661. }
  9662. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9663. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9664. return 0;
  9665. }
  9666. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9667. if (!lua_interface)
  9668. return 0;
  9669. Spawn* player = lua_interface->GetSpawn(state);
  9670. int32 amount = lua_interface->GetInt32Value(state, 2);
  9671. lua_interface->ResetFunctionStack(state);
  9672. if (player && player->IsPlayer() && amount > 0) {
  9673. ((Player*)player)->AddXP(amount);
  9674. }
  9675. return 0;
  9676. }
  9677. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9678. if (!lua_interface)
  9679. return 0;
  9680. Spawn* player = lua_interface->GetSpawn(state);
  9681. int8 type = lua_interface->GetInt8Value(state, 2);
  9682. string text = lua_interface->GetStringValue(state, 3);
  9683. lua_interface->ResetFunctionStack(state);
  9684. Client* client = 0;
  9685. if (player && player->IsPlayer())
  9686. client = ((Player*)player)->GetClient();
  9687. if (!client || text.length() == 0) {
  9688. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9689. return 0;
  9690. }
  9691. client->SimpleMessage(type, text.c_str());
  9692. return 0;
  9693. }
  9694. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9695. if (!lua_interface)
  9696. return 0;
  9697. Spawn* player = lua_interface->GetSpawn(state);
  9698. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9699. lua_interface->ResetFunctionStack(state);
  9700. Client* client = 0;
  9701. if (player && player->IsPlayer())
  9702. client = ((Player*)player)->GetClient();
  9703. if (!client || !spawn) {
  9704. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9705. return 0;
  9706. }
  9707. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9708. if (!items) {
  9709. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9710. return 0;
  9711. }
  9712. client->Loot(spawn->GetLootCoins(), items, spawn);
  9713. return 0;
  9714. }
  9715. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9716. if (!lua_interface)
  9717. return 0;
  9718. Spawn* spawnref = lua_interface->GetSpawn(state);
  9719. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9720. lua_interface->ResetFunctionStack(state);
  9721. if (spawn_id > 0 && spawnref) {
  9722. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9723. if (spawns.size() == 0) {
  9724. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9725. return 0;
  9726. }
  9727. Spawn* spawn = 0;
  9728. int16 index = MakeRandomInt(0, spawns.size());
  9729. if (index >= spawns.size() || index < 0)
  9730. index = 0;
  9731. spawn = spawns[index];
  9732. lua_interface->SetSpawnValue(state, spawn);
  9733. return 1;
  9734. }
  9735. else {
  9736. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9737. }
  9738. return 0;
  9739. }
  9740. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9741. Spawn* player = lua_interface->GetSpawn(state);
  9742. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9743. string name = lua_interface->GetStringValue(state, 3);
  9744. float distance = lua_interface->GetFloatValue(state, 4);
  9745. string command = lua_interface->GetStringValue(state, 5);
  9746. string error_text = lua_interface->GetStringValue(state, 6);
  9747. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9748. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9749. lua_interface->ResetFunctionStack(state);
  9750. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9751. if (distance == 0)
  9752. distance = 10.0f;
  9753. if (command.length() == 0)
  9754. command = name;
  9755. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9756. if (spawns.size() == 0) {
  9757. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9758. return 0;
  9759. }
  9760. Spawn* spawn = 0;
  9761. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9762. spawn = *itr;
  9763. if (spawn) {
  9764. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9765. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9766. }
  9767. }
  9768. }
  9769. return 0;
  9770. }
  9771. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9772. if (!lua_interface)
  9773. return 0;
  9774. Client* client = 0;
  9775. Spawn* player = lua_interface->GetSpawn(state);
  9776. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9777. lua_interface->ResetFunctionStack(state);
  9778. if (player && player->IsPlayer() && player->GetZone())
  9779. client = ((Player*)player)->GetClient();
  9780. else{
  9781. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9782. return 0;
  9783. }
  9784. if (client) {
  9785. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9786. if (packet) {
  9787. packet->setDataByName("goal_num", goal_num);
  9788. client->QueuePacket(packet->serialize());
  9789. safe_delete(packet);
  9790. }
  9791. }
  9792. return 0;
  9793. }
  9794. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9795. if (!lua_interface)
  9796. return 0;
  9797. Client* client = 0;
  9798. Spawn* player = lua_interface->GetSpawn(state);
  9799. lua_interface->ResetFunctionStack(state);
  9800. if (player && player->IsPlayer() && player->GetZone())
  9801. client = ((Player*)player)->GetClient();
  9802. else {
  9803. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9804. return 0;
  9805. }
  9806. if (client) {
  9807. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9808. }
  9809. return 0;
  9810. }
  9811. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9812. if (!lua_interface)
  9813. return 0;
  9814. Client* client = 0;
  9815. Spawn* player = lua_interface->GetSpawn(state);
  9816. float duration = lua_interface->GetFloatValue(state, 2);
  9817. string text = lua_interface->GetStringValue(state, 3);
  9818. string voice = lua_interface->GetStringValue(state, 4);
  9819. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9820. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9821. string signal = lua_interface->GetStringValue(state, 7);
  9822. string goal1 = lua_interface->GetStringValue(state, 8);
  9823. string task1 = lua_interface->GetStringValue(state, 9);
  9824. string goal2 = lua_interface->GetStringValue(state, 10);
  9825. string task2 = lua_interface->GetStringValue(state, 11);
  9826. string goal3 = lua_interface->GetStringValue(state, 12);
  9827. string task3 = lua_interface->GetStringValue(state, 13);
  9828. string goal4 = lua_interface->GetStringValue(state, 14);
  9829. string task4 = lua_interface->GetStringValue(state, 15);
  9830. lua_interface->ResetFunctionStack(state);
  9831. if (!player) {
  9832. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9833. return 0;
  9834. }
  9835. if (!player->IsPlayer()) {
  9836. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9837. return 0;
  9838. }
  9839. else
  9840. client = ((Player*)player)->GetClient();
  9841. if (!client) {
  9842. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9843. return 0;
  9844. }
  9845. if (text.length() == 0) {
  9846. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9847. return 0;
  9848. }
  9849. if (duration >= 0 && duration < 2)
  9850. duration = 2;
  9851. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9852. if (packet) {
  9853. packet->setDataByName("open_seconds_max", duration);
  9854. packet->setDataByName("text", text.c_str());
  9855. packet->setDataByName("voice", voice.c_str());
  9856. int8 num_goals = 1;
  9857. if (task2.length() > 0)
  9858. num_goals++;
  9859. if (task3.length() > 0)
  9860. num_goals++;
  9861. if (task4.length() > 0)
  9862. num_goals++;
  9863. packet->setArrayLengthByName("num_goals", num_goals);
  9864. for (int8 i = 0; i < num_goals; i++) {
  9865. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9866. }
  9867. if (goal1.length() > 0)
  9868. packet->setArrayDataByName("goal_text", goal1.c_str());
  9869. if (goal2.length() > 0)
  9870. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9871. if (goal3.length() > 0)
  9872. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9873. if (goal4.length() > 0)
  9874. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9875. packet->setSubArrayDataByName("task_text", task1.c_str());
  9876. if (task2.length() > 0)
  9877. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9878. if (task3.length() > 0)
  9879. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9880. if (task4.length() > 0)
  9881. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9882. packet->setDataByName("complete_sound", "click");
  9883. packet->setDataByName("signal", signal.c_str());
  9884. packet->setDataByName("voice_key1", voice_key1);
  9885. packet->setDataByName("voice_key2", voice_key2);
  9886. client->QueuePacket(packet->serialize());
  9887. safe_delete(packet);
  9888. }
  9889. return 0;
  9890. }
  9891. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9892. if (!lua_interface)
  9893. return 0;
  9894. Client* client = 0;
  9895. Spawn* player = lua_interface->GetSpawn(state);
  9896. string window = lua_interface->GetStringValue(state, 2);
  9897. int8 show = lua_interface->GetInt8Value(state, 3);
  9898. lua_interface->ResetFunctionStack(state);
  9899. if (!player) {
  9900. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9901. return 0;
  9902. }
  9903. if (!player->IsPlayer()) {
  9904. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9905. return 0;
  9906. }
  9907. else
  9908. client = ((Player*)player)->GetClient();
  9909. if (!client) {
  9910. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9911. return 0;
  9912. }
  9913. if (window.length() == 0) {
  9914. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9915. return 0;
  9916. }
  9917. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9918. if (packet) {
  9919. packet->setDataByName("window", window.c_str());
  9920. packet->setDataByName("show", show);
  9921. client->QueuePacket(packet->serialize());
  9922. safe_delete(packet);
  9923. }
  9924. return 0;
  9925. }
  9926. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9927. //See GameEvents.txt for options that can be used for this function
  9928. if (!lua_interface)
  9929. return 0;
  9930. Client* client = 0;
  9931. Spawn* player = lua_interface->GetSpawn(state);
  9932. string event_name = lua_interface->GetStringValue(state, 2);
  9933. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9934. lua_interface->ResetFunctionStack(state);
  9935. if (!player || !player->IsPlayer()) {
  9936. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9937. return 0;
  9938. }
  9939. client = ((Player*)player)->GetClient();
  9940. if (!client) {
  9941. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9942. return 0;
  9943. }
  9944. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9945. if (packet) {
  9946. packet->setDataByName("event_name", event_name.c_str());
  9947. packet->setDataByName("enabled", enabled);
  9948. client->QueuePacket(packet->serialize());
  9949. safe_delete(packet);
  9950. }
  9951. return 0;
  9952. }
  9953. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9954. if (!lua_interface)
  9955. return 0;
  9956. Spawn* player = lua_interface->GetSpawn(state);
  9957. lua_interface->ResetFunctionStack(state);
  9958. if (player && player->IsPlayer()) {
  9959. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9960. return 1;
  9961. }
  9962. return 0;
  9963. }
  9964. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9965. if (!lua_interface)
  9966. return 0;
  9967. Spawn* player = lua_interface->GetSpawn(state);
  9968. int8 step = lua_interface->GetInt8Value(state, 2);
  9969. lua_interface->ResetFunctionStack(state);
  9970. if (player && player->IsPlayer() && step > 0) {
  9971. ((Player*)player)->SetTutorialStep(step);
  9972. }
  9973. return 0;
  9974. }
  9975. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9976. if (!lua_interface)
  9977. return 0;
  9978. Client* client = 0;
  9979. Spawn* player = lua_interface->GetSpawn(state);
  9980. string window = lua_interface->GetStringValue(state, 2);
  9981. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9982. lua_interface->ResetFunctionStack(state);
  9983. if (!player) {
  9984. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9985. return 0;
  9986. }
  9987. if (!player->IsPlayer()) {
  9988. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9989. return 0;
  9990. }
  9991. else
  9992. client = ((Player*)player)->GetClient();
  9993. if (!client) {
  9994. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9995. return 0;
  9996. }
  9997. if (window.length() == 0) {
  9998. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9999. return 0;
  10000. }
  10001. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10002. if (packet) {
  10003. packet->setDataByName("window", window.c_str());
  10004. packet->setDataByName("flash_seconds", flash_seconds);
  10005. client->QueuePacket(packet->serialize());
  10006. safe_delete(packet);
  10007. }
  10008. return 0;
  10009. }
  10010. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10011. if (!lua_interface)
  10012. return 0;
  10013. Spawn* spawn = lua_interface->GetSpawn(state);
  10014. Spawn* target = lua_interface->GetSpawn(state, 2);
  10015. lua_interface->ResetFunctionStack(state);
  10016. if (spawn && target)
  10017. return spawn->CheckLoS(target);
  10018. return 0;
  10019. }
  10020. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10021. if (!lua_interface)
  10022. return 0;
  10023. Spawn* spawn = lua_interface->GetSpawn(state);
  10024. float x = lua_interface->GetFloatValue(state, 2);
  10025. float y = lua_interface->GetFloatValue(state, 3);
  10026. float z = lua_interface->GetFloatValue(state, 4);
  10027. lua_interface->ResetFunctionStack(state);
  10028. if (spawn)
  10029. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10030. return 0;
  10031. }
  10032. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10033. if (!lua_interface)
  10034. return 0;
  10035. ZoneServer* zone = lua_interface->GetZone(state);
  10036. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10037. lua_interface->ResetFunctionStack(state);
  10038. if (zone)
  10039. zone->SetExpansionFlag(xpackFlag);
  10040. return 0;
  10041. }
  10042. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10043. if (!lua_interface)
  10044. return 0;
  10045. ZoneServer* zone = lua_interface->GetZone(state);
  10046. lua_interface->ResetFunctionStack(state);
  10047. if (zone) {
  10048. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10049. return 1;
  10050. }
  10051. return 0;
  10052. }
  10053. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10054. if (!lua_interface)
  10055. return 0;
  10056. ZoneServer* zone = lua_interface->GetZone(state);
  10057. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10058. lua_interface->ResetFunctionStack(state);
  10059. if (zone)
  10060. zone->SetHolidayFlag(holidayFlag);
  10061. return 0;
  10062. }
  10063. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10064. if (!lua_interface)
  10065. return 0;
  10066. ZoneServer* zone = lua_interface->GetZone(state);
  10067. lua_interface->ResetFunctionStack(state);
  10068. if (zone) {
  10069. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10070. return 1;
  10071. }
  10072. return 0;
  10073. }
  10074. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10075. if (!lua_interface)
  10076. return 0;
  10077. Spawn* player = lua_interface->GetSpawn(state);
  10078. ZoneServer* zone = player->GetZone();
  10079. bool canbind = lua_interface->GetInt32Value(state, 2);
  10080. lua_interface->ResetFunctionStack(state);
  10081. if (zone)
  10082. zone->SetCanBind(canbind);
  10083. return 0;
  10084. }
  10085. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10086. if (!lua_interface)
  10087. return 0;
  10088. Spawn* player = lua_interface->GetSpawn(state);
  10089. ZoneServer* zone = player->GetZone();
  10090. lua_interface->ResetFunctionStack(state);
  10091. if (zone) {
  10092. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10093. return 1;
  10094. }
  10095. return 0;
  10096. }
  10097. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10098. if (!lua_interface)
  10099. return 0;
  10100. Spawn* player = lua_interface->GetSpawn(state);
  10101. ZoneServer* zone = player->GetZone();
  10102. bool cangate = lua_interface->GetInt32Value(state, 2);
  10103. lua_interface->ResetFunctionStack(state);
  10104. if (zone)
  10105. zone->SetCanGate(cangate);
  10106. return 0;
  10107. }
  10108. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10109. if (!lua_interface)
  10110. return 0;
  10111. Spawn* player = lua_interface->GetSpawn(state);
  10112. ZoneServer* zone = player->GetZone();
  10113. lua_interface->ResetFunctionStack(state);
  10114. if (zone) {
  10115. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10116. return 1;
  10117. }
  10118. return 0;
  10119. }
  10120. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10121. if (!lua_interface)
  10122. return 0;
  10123. Spawn* spawn = lua_interface->GetSpawn(state);
  10124. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10125. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10126. float distance = lua_interface->GetFloatValue(state, 4);
  10127. string in_range_function = lua_interface->GetStringValue(state, 5);
  10128. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10129. lua_interface->ResetFunctionStack(state);
  10130. if (spawn && distance > 0 && in_range_function.length() > 0)
  10131. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10132. return 0;
  10133. }
  10134. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10135. if (!lua_interface)
  10136. return 0;
  10137. Spawn* spawn = lua_interface->GetSpawn(state);
  10138. Spawn* target = lua_interface->GetSpawn(state, 2);
  10139. lua_interface->ResetFunctionStack(state);
  10140. if (spawn && target)
  10141. {
  10142. if (spawn->IsPlayer() && target->IsEntity())
  10143. {
  10144. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10145. return 1;
  10146. }
  10147. else if (spawn->IsEntity() && target->IsEntity())
  10148. {
  10149. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10150. return 1;
  10151. }
  10152. }
  10153. return 0;
  10154. }
  10155. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10156. if (!lua_interface)
  10157. return 0;
  10158. Spawn* spawn = lua_interface->GetSpawn(state);
  10159. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10160. lua_interface->ResetFunctionStack(state);
  10161. if (spawn && spawn->IsEntity())
  10162. {
  10163. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10164. if (spawn->IsPlayer())
  10165. {
  10166. Client* client = ((Player*)spawn)->GetClient();
  10167. if (client)
  10168. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10169. }
  10170. }
  10171. return 0;
  10172. }
  10173. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10174. if (!lua_interface)
  10175. return 0;
  10176. Spawn* spawn = lua_interface->GetSpawn(state);
  10177. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10178. lua_interface->ResetFunctionStack(state);
  10179. if (spawn && spawn->IsEntity())
  10180. {
  10181. ((Entity*)spawn)->SetSeeHideSpell(val);
  10182. if (spawn->IsPlayer())
  10183. {
  10184. Client* client = ((Player*)spawn)->GetClient();
  10185. if (client)
  10186. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10187. }
  10188. }
  10189. return 0;
  10190. }
  10191. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10192. {
  10193. if (!lua_interface)
  10194. return 0;
  10195. Spawn* player = lua_interface->GetSpawn(state);
  10196. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10197. string command = lua_interface->GetStringValue(state, 3);
  10198. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10199. lua_interface->ResetFunctionStack(state);
  10200. if (spawn && player && player->IsPlayer())
  10201. {
  10202. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10203. bool res = false;
  10204. if (cmd)
  10205. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10206. lua_interface->SetBooleanValue(state, res);
  10207. return 1;
  10208. }
  10209. return 0;
  10210. }
  10211. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10212. {
  10213. if (!lua_interface)
  10214. return 0;
  10215. Spawn* spawn = lua_interface->GetSpawn(state);
  10216. int32 charID = lua_interface->GetInt32Value(state, 2);
  10217. string command = lua_interface->GetStringValue(state, 3);
  10218. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10219. lua_interface->ResetFunctionStack(state);
  10220. if (spawn && charID)
  10221. {
  10222. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10223. bool res = false;
  10224. if (cmd)
  10225. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10226. lua_interface->SetBooleanValue(state, res);
  10227. return 1;
  10228. }
  10229. return 0;
  10230. }
  10231. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10232. {
  10233. if (!lua_interface)
  10234. return 0;
  10235. Spawn* spawn = lua_interface->GetSpawn(state);
  10236. string command = lua_interface->GetStringValue(state, 2);
  10237. lua_interface->ResetFunctionStack(state);
  10238. if (spawn && command.length() > 0)
  10239. spawn->RemovePrimaryEntityCommand(command.c_str());
  10240. return 0;
  10241. }
  10242. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10243. if (!lua_interface)
  10244. return 0;
  10245. Spawn* spawn = lua_interface->GetSpawn(state);
  10246. float distance = lua_interface->GetFloatValue(state, 2);
  10247. string command = lua_interface->GetStringValue(state, 3);
  10248. Spawn* player = lua_interface->GetSpawn(state, 4);
  10249. lua_interface->ResetFunctionStack(state);
  10250. if (spawn) {
  10251. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10252. }
  10253. return 0;
  10254. }
  10255. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10256. if (!lua_interface)
  10257. return 0;
  10258. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10259. Spawn* spawn = lua_interface->GetSpawn(state);
  10260. Spawn* player = lua_interface->GetSpawn(state, 2);
  10261. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10262. lua_interface->ResetFunctionStack(state);
  10263. if (spawn && player && transport_id && player->IsPlayer()) {
  10264. Client* client = 0;
  10265. if (player && player->IsPlayer())
  10266. client = ((Player*)player)->GetClient();
  10267. if (!client)
  10268. return 0;
  10269. vector<TransportDestination*> destinations;
  10270. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10271. if (destinations.size())
  10272. {
  10273. client->SetTemporaryTransportID(transport_id);
  10274. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10275. }
  10276. else
  10277. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10278. }
  10279. return 0;
  10280. }
  10281. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10282. if (!lua_interface)
  10283. return 0;
  10284. Spawn* player = lua_interface->GetSpawn(state);
  10285. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10286. lua_interface->ResetFunctionStack(state);
  10287. if (player && player->IsPlayer()) {
  10288. Client* client = 0;
  10289. if (player && player->IsPlayer())
  10290. client = ((Player*)player)->GetClient();
  10291. if (!client)
  10292. return 0;
  10293. client->SetTemporaryTransportID(transport_id);
  10294. }
  10295. return 0;
  10296. }
  10297. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10298. if (!lua_interface)
  10299. return 0;
  10300. Spawn* player = lua_interface->GetSpawn(state);
  10301. lua_interface->ResetFunctionStack(state);
  10302. if (player && player->IsPlayer()) {
  10303. Client* client = 0;
  10304. if (player && player->IsPlayer())
  10305. client = ((Player*)player)->GetClient();
  10306. if (!client)
  10307. return 0;
  10308. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10309. return 1;
  10310. }
  10311. return 0;
  10312. }
  10313. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10314. if (!lua_interface)
  10315. return 0;
  10316. Spawn* spawn = lua_interface->GetSpawn(state);
  10317. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10318. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10319. if (!spawn) {
  10320. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10321. return 0;
  10322. }
  10323. if (!spawn->IsEntity()) {
  10324. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10325. return 0;
  10326. }
  10327. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10328. {
  10329. 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);
  10330. return 0;
  10331. }
  10332. lua_interface->ResetFunctionStack(state);
  10333. if (spell && spell->targets.size() > 0) {
  10334. ZoneServer* zone = spell->caster->GetZone();
  10335. for (int8 i = 0; i < spell->targets.size(); i++) {
  10336. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10337. if (target && target->IsEntity()) {
  10338. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10339. if (target->IsPlayer())
  10340. ((Player*)target)->SetCharSheetChanged(true);
  10341. }
  10342. }
  10343. }
  10344. else {
  10345. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10346. if (spawn->IsPlayer())
  10347. ((Player*)spawn)->SetCharSheetChanged(true);
  10348. }
  10349. return 0;
  10350. }
  10351. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10352. if (!lua_interface)
  10353. return 0;
  10354. Spawn* spawn = lua_interface->GetSpawn(state);
  10355. lua_interface->ResetFunctionStack(state);
  10356. if (!spawn) {
  10357. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10358. return 0;
  10359. }
  10360. if (!spawn->IsEntity()) {
  10361. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10362. return 0;
  10363. }
  10364. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10365. return 1;
  10366. }
  10367. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10368. if (!lua_interface)
  10369. return 0;
  10370. int32 spell_id = lua_interface->GetInt32Value(state);
  10371. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10372. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10373. if (spell_id > 0) {
  10374. if (spell_tier == 0)
  10375. spell_tier = 1;
  10376. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10377. LuaSpell* lua_spell = 0;
  10378. if(custom_lua_script.size() > 0)
  10379. {
  10380. // attempt to load the custom script since it isn't already loaded
  10381. // we will re-obtain the lua_spell further below
  10382. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10383. {
  10384. 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());
  10385. lua_interface->LoadLuaSpell(custom_lua_script);
  10386. }
  10387. }
  10388. else
  10389. custom_lua_script = spell->GetSpellData()->lua_script;
  10390. if (!lua_spell && lua_interface)
  10391. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10392. if (!lua_spell)
  10393. {
  10394. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10395. return 0;
  10396. }
  10397. lua_spell->spell = new Spell(spell);
  10398. lua_interface->AddCustomSpell(lua_spell);
  10399. lua_interface->SetSpellValue(state, lua_spell);
  10400. return 1;
  10401. }
  10402. return 0;
  10403. }
  10404. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10405. if (!lua_interface)
  10406. return 0;
  10407. LuaSpell* spell = lua_interface->GetSpell(state);
  10408. string field = lua_interface->GetStringValue(state, 2);
  10409. if (!spell) {
  10410. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10411. return 0;
  10412. }
  10413. if (!spell->spell || !spell->spell->GetSpellData()) {
  10414. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10415. return 0;
  10416. }
  10417. boost::to_lower(field);
  10418. return spell->spell->GetSpellData(state, field);
  10419. }
  10420. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10421. if (!lua_interface)
  10422. return 0;
  10423. LuaSpell* spell = lua_interface->GetSpell(state);
  10424. string field = lua_interface->GetStringValue(state, 2);
  10425. int8 fieldArg = 3; // field value after the initial set
  10426. if (!spell) {
  10427. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10428. return 0;
  10429. }
  10430. if (!spell->spell || !spell->spell->GetSpellData()) {
  10431. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10432. return 0;
  10433. }
  10434. boost::to_lower(field);
  10435. bool valSet = false;
  10436. spell->spell->SetSpellData(state, field, fieldArg);
  10437. return valSet;
  10438. }
  10439. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10440. if (!lua_interface)
  10441. return 0;
  10442. LuaSpell* spell = lua_interface->GetSpell(state);
  10443. int8 idx = lua_interface->GetInt32Value(state, 2);
  10444. if (!spell) {
  10445. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10446. return 0;
  10447. }
  10448. if (!spell->spell || !spell->spell->GetSpellData()) {
  10449. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10450. return 0;
  10451. }
  10452. if (spell->spell->lua_data.size() <= idx)
  10453. {
  10454. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10455. return 0;
  10456. }
  10457. bool setVal = true;
  10458. LUAData* data = spell->spell->lua_data[idx];
  10459. switch (data->type)
  10460. {
  10461. case 0:
  10462. {
  10463. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10464. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10465. data->int_value = value;
  10466. data->int_value2 = value2;
  10467. break;
  10468. }
  10469. case 1:
  10470. {
  10471. float value = lua_interface->GetFloatValue(state, 3);
  10472. float value2 = lua_interface->GetFloatValue(state, 4);
  10473. data->float_value = value;
  10474. data->float_value2 = value2;
  10475. break;
  10476. }
  10477. case 2:
  10478. {
  10479. bool value = lua_interface->GetBooleanValue(state, 3);
  10480. data->bool_value = value;
  10481. break;
  10482. }
  10483. case 3:
  10484. {
  10485. string value = lua_interface->GetStringValue(state, 3);
  10486. string value2 = lua_interface->GetStringValue(state, 4);
  10487. data->string_value = value;
  10488. data->string_value2 = value2;
  10489. break;
  10490. }
  10491. default:
  10492. setVal = false;
  10493. }
  10494. return setVal;
  10495. }
  10496. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10497. if (!lua_interface)
  10498. return 0;
  10499. LuaSpell* spell = lua_interface->GetSpell(state);
  10500. int8 idx = lua_interface->GetInt32Value(state, 2);
  10501. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10502. if (!spell) {
  10503. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10504. return 0;
  10505. }
  10506. if (!spell->spell || !spell->spell->GetSpellData()) {
  10507. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10508. return 0;
  10509. }
  10510. if (spell->spell->lua_data.size() <= idx)
  10511. {
  10512. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10513. return 0;
  10514. }
  10515. bool setVal = true;
  10516. LUAData* data = spell->spell->lua_data[idx];
  10517. switch (data->type)
  10518. {
  10519. case 0:
  10520. {
  10521. if(!secondfield)
  10522. lua_interface->SetSInt32Value(state, data->int_value);
  10523. else
  10524. lua_interface->SetSInt32Value(state, data->int_value2);
  10525. break;
  10526. }
  10527. case 1:
  10528. {
  10529. if (!secondfield)
  10530. lua_interface->SetFloatValue(state, data->float_value);
  10531. else
  10532. lua_interface->SetFloatValue(state, data->float_value2);
  10533. break;
  10534. }
  10535. case 2:
  10536. {
  10537. lua_interface->SetBooleanValue(state, data->bool_value);
  10538. break;
  10539. }
  10540. case 3:
  10541. {
  10542. if (!secondfield)
  10543. lua_interface->SetStringValue(state, data->string_value.c_str());
  10544. else
  10545. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10546. break;
  10547. }
  10548. default:
  10549. setVal = false;
  10550. }
  10551. return setVal;
  10552. }
  10553. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10554. if (!lua_interface)
  10555. return 0;
  10556. LuaSpell* spell = lua_interface->GetSpell(state);
  10557. int8 idx = lua_interface->GetInt32Value(state, 2);
  10558. string field = lua_interface->GetStringValue(state, 3);
  10559. boost::to_lower(field);
  10560. if (!spell) {
  10561. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10562. return 0;
  10563. }
  10564. if (!spell->spell || !spell->spell->GetSpellData()) {
  10565. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10566. return 0;
  10567. }
  10568. if (spell->spell->effects.size() <= idx)
  10569. {
  10570. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10571. return 0;
  10572. }
  10573. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10574. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10575. if (field == "description")
  10576. effect->description = string(lua_interface->GetStringValue(state, 4));
  10577. else if (field == "bullet")
  10578. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10579. else if (field == "percentage")
  10580. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10581. else // no match
  10582. return 0;
  10583. return 1;
  10584. }
  10585. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10586. if (!lua_interface)
  10587. return 0;
  10588. LuaSpell* spell = lua_interface->GetSpell(state);
  10589. int8 idx = lua_interface->GetInt32Value(state, 2);
  10590. string field = lua_interface->GetStringValue(state, 3);
  10591. boost::to_lower(field);
  10592. if (!spell) {
  10593. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10594. return 0;
  10595. }
  10596. if (!spell->spell || !spell->spell->GetSpellData()) {
  10597. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10598. return 0;
  10599. }
  10600. if (spell->spell->effects.size() <= idx)
  10601. {
  10602. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10603. return 0;
  10604. }
  10605. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10606. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10607. if (field == "description")
  10608. lua_interface->SetStringValue(state, effect->description.c_str());
  10609. else if (field == "bullet")
  10610. lua_interface->SetInt32Value(state, effect->subbullet);
  10611. else if (field == "percentage")
  10612. lua_interface->SetInt32Value(state, effect->percentage);
  10613. else // no match
  10614. return 0;
  10615. return 1;
  10616. }
  10617. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10618. if (!lua_interface)
  10619. return 0;
  10620. LuaSpell* spell = lua_interface->GetSpell(state);
  10621. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10622. Spawn* target = lua_interface->GetSpawn(state, 3);
  10623. if (!target) {
  10624. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10625. return 0;
  10626. }
  10627. if (!target->IsEntity()) {
  10628. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10629. return 0;
  10630. }
  10631. if (!spell) {
  10632. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10633. return 0;
  10634. }
  10635. if (caster && !caster->IsEntity()) {
  10636. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10637. return 0;
  10638. }
  10639. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10640. return 0;
  10641. }
  10642. int EQ2Emu_lua_InWater(lua_State* state) {
  10643. if (!lua_interface)
  10644. return 0;
  10645. Spawn* spawn = lua_interface->GetSpawn(state);
  10646. lua_interface->ResetFunctionStack(state);
  10647. if (spawn) {
  10648. lua_interface->SetBooleanValue(state, spawn->InWater());
  10649. return 1;
  10650. }
  10651. return 0;
  10652. }
  10653. int EQ2Emu_lua_InLava(lua_State* state) {
  10654. if (!lua_interface)
  10655. return 0;
  10656. Spawn* spawn = lua_interface->GetSpawn(state);
  10657. lua_interface->ResetFunctionStack(state);
  10658. if (spawn) {
  10659. lua_interface->SetBooleanValue(state, spawn->InLava());
  10660. return 1;
  10661. }
  10662. return 0;
  10663. }
  10664. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10665. if (!lua_interface)
  10666. return 0;
  10667. Spawn* attacker = lua_interface->GetSpawn(state);
  10668. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10669. int8 type = lua_interface->GetInt8Value(state, 3);
  10670. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10671. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10672. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10673. string spell_name = lua_interface->GetStringValue(state, 7);
  10674. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10675. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10676. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10677. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10678. lua_interface->ResetFunctionStack(state);
  10679. if (!attacker) {
  10680. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10681. return 0;
  10682. }
  10683. if (!attacker->IsEntity()) {
  10684. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10685. return 0;
  10686. }
  10687. if (!victim) {
  10688. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10689. return 0;
  10690. }
  10691. if (!victim->IsEntity()) {
  10692. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10693. return 0;
  10694. }
  10695. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10696. return 0;
  10697. }
  10698. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10699. if (!lua_interface)
  10700. return 0;
  10701. Spawn* spawn = lua_interface->GetSpawn(state);
  10702. lua_interface->ResetFunctionStack(state);
  10703. if (spawn) {
  10704. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10705. return 1;
  10706. }
  10707. return 0;
  10708. }
  10709. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10710. if (!lua_interface)
  10711. return 0;
  10712. Spawn* spawn = lua_interface->GetSpawn(state);
  10713. bool invul = lua_interface->GetBooleanValue(state, 2);
  10714. lua_interface->ResetFunctionStack(state);
  10715. if (spawn) {
  10716. spawn->SetInvulnerable(invul);
  10717. }
  10718. return 0;
  10719. }
  10720. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10721. if (!lua_interface)
  10722. return 0;
  10723. string category = lua_interface->GetStringValue(state);
  10724. string name = lua_interface->GetStringValue(state, 2);
  10725. lua_interface->ResetFunctionStack(state);
  10726. Rule *ret = 0;
  10727. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10728. lua_interface->SetBooleanValue(state, ret->GetBool());
  10729. return 1;
  10730. }
  10731. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10732. return 0;
  10733. }
  10734. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10735. if (!lua_interface)
  10736. return 0;
  10737. string category = lua_interface->GetStringValue(state);
  10738. string name = lua_interface->GetStringValue(state, 2);
  10739. lua_interface->ResetFunctionStack(state);
  10740. Rule *ret = 0;
  10741. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10742. lua_interface->SetInt32Value(state, ret->GetInt32());
  10743. return 1;
  10744. }
  10745. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10746. return 0;
  10747. }
  10748. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10749. if (!lua_interface)
  10750. return 0;
  10751. string category = lua_interface->GetStringValue(state);
  10752. string name = lua_interface->GetStringValue(state, 2);
  10753. lua_interface->ResetFunctionStack(state);
  10754. Rule *ret = 0;
  10755. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10756. lua_interface->SetFloatValue(state, ret->GetFloat());
  10757. return 1;
  10758. }
  10759. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10760. return 0;
  10761. }
  10762. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10763. if (!lua_interface)
  10764. return 0;
  10765. Spawn* spawn = lua_interface->GetSpawn(state);
  10766. string type = lua_interface->GetStringValue(state, 2);
  10767. lua_interface->ResetFunctionStack(state);
  10768. if (spawn) {
  10769. int res = 1;
  10770. boost::to_lower(type);
  10771. if(type == "assigned_aa")
  10772. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10773. else if ( type == "unassigned_aa")
  10774. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10775. else if ( type == "assigned_tradeskill_aa")
  10776. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10777. else if ( type == "unassigned_tradeskill_aa")
  10778. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10779. else if ( type == "assigned_prestige_aa")
  10780. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10781. else if ( type == "unassigned_prestige_aa")
  10782. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10783. else if ( type == "assigned_tradeskill_prestige_aa")
  10784. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10785. else if ( type == "unassigned_tradeskill_prestige_aa")
  10786. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10787. else
  10788. res = 0;
  10789. return res;
  10790. }
  10791. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10792. return 0;
  10793. }
  10794. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10795. if (!lua_interface)
  10796. return 0;
  10797. Spawn* spawn = lua_interface->GetSpawn(state);
  10798. string type = lua_interface->GetStringValue(state, 2);
  10799. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10800. lua_interface->ResetFunctionStack(state);
  10801. if (spawn) {
  10802. boost::to_lower(type);
  10803. if(type == "assigned_aa")
  10804. spawn->SetAssignedAA((sint16)value);
  10805. else if ( type == "unassigned_aa")
  10806. spawn->SetUnassignedAA((sint16)value);
  10807. else if ( type == "assigned_tradeskill_aa")
  10808. spawn->SetTradeskillAA((sint16)value);
  10809. else if ( type == "unassigned_tradeskill_aa")
  10810. spawn->SetUnassignedTradeskillAA((sint16)value);
  10811. else if ( type == "assigned_prestige_aa")
  10812. spawn->SetPrestigeAA((sint16)value);
  10813. else if ( type == "unassigned_prestige_aa")
  10814. spawn->SetUnassignedPrestigeAA((sint16)value);
  10815. else if ( type == "assigned_tradeskill_prestige_aa")
  10816. spawn->SetTradeskillPrestigeAA((sint16)value);
  10817. else if ( type == "unassigned_tradeskill_prestige_aa")
  10818. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10819. if(spawn->IsPlayer())
  10820. ((Player*)spawn)->SetCharSheetChanged(true);
  10821. }
  10822. return 0;
  10823. }
  10824. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10825. if (!lua_interface)
  10826. return 0;
  10827. string titleName = lua_interface->GetStringValue(state);
  10828. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10829. lua_interface->ResetFunctionStack(state);
  10830. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10831. lua_interface->SetSInt32Value(state, index);
  10832. return 1;
  10833. }
  10834. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10835. if (!lua_interface)
  10836. return 0;
  10837. Spawn* spawn = lua_interface->GetSpawn(state);
  10838. string titleName = lua_interface->GetStringValue(state, 2);
  10839. lua_interface->ResetFunctionStack(state);
  10840. if(!spawn->IsPlayer())
  10841. {
  10842. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10843. lua_interface->SetSInt32Value(state, -1);
  10844. return 1;
  10845. }
  10846. Player* player = (Player*)spawn;
  10847. // check if player already has the title, don't need to add twice
  10848. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10849. if ( playerHasTitle)
  10850. {
  10851. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10852. return 1;
  10853. }
  10854. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10855. if(!title)
  10856. {
  10857. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10858. lua_interface->SetSInt32Value(state, -1);
  10859. return 1;
  10860. }
  10861. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10862. if(returnIdx < 0)
  10863. {
  10864. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10865. }
  10866. lua_interface->SetSInt32Value(state, returnIdx);
  10867. player->GetClient()->SendTitleUpdate();
  10868. return 1;
  10869. }
  10870. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10871. if (!lua_interface)
  10872. return 0;
  10873. Spawn* spawn = lua_interface->GetSpawn(state);
  10874. string titleName = lua_interface->GetStringValue(state, 2);
  10875. lua_interface->ResetFunctionStack(state);
  10876. if(!spawn->IsPlayer())
  10877. {
  10878. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10879. return 0;
  10880. }
  10881. Player* player = (Player*)spawn;
  10882. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10883. if(!title)
  10884. {
  10885. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10886. return 0;
  10887. }
  10888. if(title->GetPrefix())
  10889. {
  10890. 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());
  10891. return 0;
  10892. }
  10893. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10894. player->GetClient()->SendTitleUpdate();
  10895. return 1;
  10896. }
  10897. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10898. if (!lua_interface)
  10899. return 0;
  10900. Spawn* spawn = lua_interface->GetSpawn(state);
  10901. string titleName = lua_interface->GetStringValue(state, 2);
  10902. lua_interface->ResetFunctionStack(state);
  10903. if(!spawn->IsPlayer())
  10904. {
  10905. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10906. return 0;
  10907. }
  10908. Player* player = (Player*)spawn;
  10909. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10910. if(!title)
  10911. {
  10912. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10913. return 0;
  10914. }
  10915. if(!title->GetPrefix())
  10916. {
  10917. 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());
  10918. return 0;
  10919. }
  10920. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10921. player->GetClient()->SendTitleUpdate();
  10922. return 1;
  10923. }
  10924. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10925. if (!lua_interface)
  10926. return 0;
  10927. Spawn* spawn = lua_interface->GetSpawn(state);
  10928. lua_interface->ResetFunctionStack(state);
  10929. if(!spawn->IsPlayer())
  10930. {
  10931. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10932. return 0;
  10933. }
  10934. Player* player = (Player*)spawn;
  10935. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10936. player->GetClient()->SendTitleUpdate();
  10937. return 1;
  10938. }
  10939. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10940. if (!lua_interface)
  10941. return 0;
  10942. Spawn* spawn = lua_interface->GetSpawn(state);
  10943. lua_interface->ResetFunctionStack(state);
  10944. if(!spawn->IsPlayer())
  10945. {
  10946. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10947. return 0;
  10948. }
  10949. Player* player = (Player*)spawn;
  10950. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10951. player->GetClient()->SendTitleUpdate();
  10952. return 1;
  10953. }
  10954. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10955. if (!lua_interface)
  10956. return 0;
  10957. Spawn* spawn = lua_interface->GetSpawn(state);
  10958. string field = lua_interface->GetStringValue(state, 2);
  10959. lua_interface->ResetFunctionStack(state);
  10960. if(!spawn || !spawn->IsEntity())
  10961. {
  10962. 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));
  10963. return 0;
  10964. }
  10965. Entity* ent = (Entity*)spawn;
  10966. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10967. return 1;
  10968. }
  10969. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10970. if (!lua_interface)
  10971. return 0;
  10972. Spawn* spawn = lua_interface->GetSpawn(state);
  10973. string field = lua_interface->GetStringValue(state, 2);
  10974. lua_interface->ResetFunctionStack(state);
  10975. if(!spawn || !spawn->IsEntity())
  10976. {
  10977. 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));
  10978. return 0;
  10979. }
  10980. Entity* ent = (Entity*)spawn;
  10981. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10982. return 1;
  10983. }
  10984. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10985. if (!lua_interface)
  10986. return 0;
  10987. Spawn* spawn = lua_interface->GetSpawn(state);
  10988. string field = lua_interface->GetStringValue(state, 2);
  10989. lua_interface->ResetFunctionStack(state);
  10990. if(!spawn || !spawn->IsEntity())
  10991. {
  10992. 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));
  10993. return 0;
  10994. }
  10995. Entity* ent = (Entity*)spawn;
  10996. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10997. return 1;
  10998. }
  10999. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11000. if (!lua_interface)
  11001. return 0;
  11002. Spawn* spawn = lua_interface->GetSpawn(state);
  11003. string field = lua_interface->GetStringValue(state, 2);
  11004. lua_interface->ResetFunctionStack(state);
  11005. if(!spawn || !spawn->IsEntity())
  11006. {
  11007. 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));
  11008. return 0;
  11009. }
  11010. Entity* ent = (Entity*)spawn;
  11011. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11012. return 1;
  11013. }
  11014. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11015. if (!lua_interface)
  11016. return 0;
  11017. Spawn* spawn = lua_interface->GetSpawn(state);
  11018. string field = lua_interface->GetStringValue(state, 2);
  11019. string value = lua_interface->GetStringValue(state, 3);
  11020. lua_interface->ResetFunctionStack(state);
  11021. if(!spawn || !spawn->IsEntity())
  11022. {
  11023. 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));
  11024. return 0;
  11025. }
  11026. Entity* ent = (Entity*)spawn;
  11027. bool set_ = ent->SetInfoStructString(field, value);
  11028. lua_interface->SetBooleanValue(state, set_);
  11029. return 1;
  11030. }
  11031. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11032. if (!lua_interface)
  11033. return 0;
  11034. Spawn* spawn = lua_interface->GetSpawn(state);
  11035. string field = lua_interface->GetStringValue(state, 2);
  11036. int64 value = lua_interface->GetInt64Value(state, 3);
  11037. lua_interface->ResetFunctionStack(state);
  11038. if(!spawn || !spawn->IsEntity())
  11039. {
  11040. 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));
  11041. return 0;
  11042. }
  11043. Entity* ent = (Entity*)spawn;
  11044. bool set_ = ent->SetInfoStructUInt(field, value);
  11045. lua_interface->SetBooleanValue(state, set_);
  11046. return 1;
  11047. }
  11048. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11049. if (!lua_interface)
  11050. return 0;
  11051. Spawn* spawn = lua_interface->GetSpawn(state);
  11052. string field = lua_interface->GetStringValue(state, 2);
  11053. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11054. lua_interface->ResetFunctionStack(state);
  11055. if(!spawn || !spawn->IsEntity())
  11056. {
  11057. 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));
  11058. return 0;
  11059. }
  11060. Entity* ent = (Entity*)spawn;
  11061. bool set_ = ent->SetInfoStructSInt(field, value);
  11062. lua_interface->SetBooleanValue(state, set_);
  11063. return 1;
  11064. }
  11065. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11066. if (!lua_interface)
  11067. return 0;
  11068. Spawn* spawn = lua_interface->GetSpawn(state);
  11069. string field = lua_interface->GetStringValue(state, 2);
  11070. float value = lua_interface->GetFloatValue(state, 3);
  11071. lua_interface->ResetFunctionStack(state);
  11072. if(!spawn || !spawn->IsEntity())
  11073. {
  11074. 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));
  11075. return 0;
  11076. }
  11077. Entity* ent = (Entity*)spawn;
  11078. bool set_ = ent->SetInfoStructFloat(field, value);
  11079. lua_interface->SetBooleanValue(state, set_);
  11080. return 1;
  11081. }
  11082. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11083. if (!lua_interface)
  11084. return 0;
  11085. Spawn* spawn = lua_interface->GetSpawn(state);
  11086. bool value = lua_interface->GetBooleanValue(state, 2);
  11087. lua_interface->ResetFunctionStack(state);
  11088. if(!spawn || !spawn->IsPlayer())
  11089. {
  11090. 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));
  11091. return 0;
  11092. }
  11093. ((Player*)spawn)->SetCharSheetChanged(value);
  11094. return 0;
  11095. }
  11096. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11097. if (!lua_interface)
  11098. return 0;
  11099. Spawn* spawn = lua_interface->GetSpawn(state);
  11100. std::string fromName = lua_interface->GetStringValue(state, 2);
  11101. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11102. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11103. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11104. int32 copper = lua_interface->GetInt32Value(state, 6);
  11105. int32 silver = lua_interface->GetInt32Value(state, 7);
  11106. int32 gold = lua_interface->GetInt32Value(state, 8);
  11107. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11108. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11109. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11110. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11111. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11112. lua_interface->ResetFunctionStack(state);
  11113. if(!spawn || !spawn->IsPlayer())
  11114. {
  11115. 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));
  11116. lua_interface->SetBooleanValue(state, false);
  11117. return 1;
  11118. }
  11119. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11120. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11121. lua_interface->SetBooleanValue(state, true);
  11122. return 1;
  11123. }
  11124. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11125. if (!lua_interface)
  11126. return 0;
  11127. int32 char_id = lua_interface->GetInt32Value(state);
  11128. std::string fromName = lua_interface->GetStringValue(state, 2);
  11129. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11130. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11131. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11132. int32 copper = lua_interface->GetInt32Value(state, 6);
  11133. int32 silver = lua_interface->GetInt32Value(state, 7);
  11134. int32 gold = lua_interface->GetInt32Value(state, 8);
  11135. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11136. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11137. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11138. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11139. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11140. lua_interface->ResetFunctionStack(state);
  11141. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11142. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11143. lua_interface->SetBooleanValue(state, true);
  11144. return 1;
  11145. }
  11146. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11147. Spawn* widget;
  11148. if (lua_interface) {
  11149. widget = lua_interface->GetSpawn(state);
  11150. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11151. lua_interface->ResetFunctionStack(state);
  11152. if (widget && widget->IsWidget())
  11153. {
  11154. ((Widget*)widget)->OpenDoor();
  11155. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11156. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11157. }
  11158. else
  11159. 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));
  11160. }
  11161. return 0;
  11162. }
  11163. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11164. Spawn* widget;
  11165. if (lua_interface) {
  11166. widget = lua_interface->GetSpawn(state);
  11167. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11168. lua_interface->ResetFunctionStack(state);
  11169. if (widget && widget->IsWidget())
  11170. {
  11171. ((Widget*)widget)->CloseDoor();
  11172. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11173. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11174. }
  11175. else
  11176. 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));
  11177. }
  11178. return 0;
  11179. }
  11180. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11181. if (!lua_interface)
  11182. return 0;
  11183. Spawn* widget = lua_interface->GetSpawn(state);
  11184. lua_interface->ResetFunctionStack(state);
  11185. if (widget && widget->IsWidget())
  11186. {
  11187. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11188. return 1;
  11189. }
  11190. return 0;
  11191. }
  11192. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11193. if (!lua_interface)
  11194. return 0;
  11195. sint32 min = lua_interface->GetSInt32Value(state);
  11196. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11197. lua_interface->ResetFunctionStack(state);
  11198. sint32 result = MakeRandomInt(min, max);
  11199. lua_interface->SetSInt32Value(state, result);
  11200. return 1;
  11201. }
  11202. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11203. if (!lua_interface)
  11204. return 0;
  11205. float min = lua_interface->GetFloatValue(state);
  11206. float max = lua_interface->GetFloatValue(state, 2);
  11207. lua_interface->ResetFunctionStack(state);
  11208. float result = MakeRandomFloat(min, max);
  11209. lua_interface->SetFloatValue(state, result);
  11210. return 1;
  11211. }
  11212. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11213. if (!lua_interface)
  11214. return 0;
  11215. Spawn* spawn = lua_interface->GetSpawn(state);
  11216. int32 value = lua_interface->GetInt32Value(state, 2);
  11217. lua_interface->ResetFunctionStack(state);
  11218. if(!spawn)
  11219. {
  11220. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11221. lua_interface->SetBooleanValue(state, false);
  11222. return 1;
  11223. }
  11224. spawn->AddIconValue(value);
  11225. lua_interface->SetBooleanValue(state, true);
  11226. return 1;
  11227. }
  11228. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11229. if (!lua_interface)
  11230. return 0;
  11231. Spawn* spawn = lua_interface->GetSpawn(state);
  11232. int32 value = lua_interface->GetInt32Value(state, 2);
  11233. lua_interface->ResetFunctionStack(state);
  11234. if(!spawn)
  11235. {
  11236. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11237. lua_interface->SetBooleanValue(state, false);
  11238. return 1;
  11239. }
  11240. spawn->RemoveIconValue(value);
  11241. lua_interface->SetBooleanValue(state, true);
  11242. return 1;
  11243. }
  11244. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11245. Spawn* npc = lua_interface->GetSpawn(state);
  11246. lua_interface->ResetFunctionStack(state);
  11247. if (npc && npc->IsNPC()) {
  11248. NPC* shard = (NPC*)npc;
  11249. int32 shardid = shard->GetShardID();
  11250. lua_interface->SetInt32Value(state, shardid);
  11251. return 1;
  11252. }
  11253. lua_interface->SetInt32Value(state, 0);
  11254. return 1;
  11255. }
  11256. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11257. Spawn* npc = lua_interface->GetSpawn(state);
  11258. lua_interface->ResetFunctionStack(state);
  11259. if (npc && npc->IsNPC()) {
  11260. NPC* shard = (NPC*)npc;
  11261. int32 charid = shard->GetShardCharID();
  11262. lua_interface->SetInt32Value(state, charid);
  11263. return 1;
  11264. }
  11265. lua_interface->SetInt32Value(state, 0);
  11266. return 1;
  11267. }
  11268. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11269. Spawn* npc = lua_interface->GetSpawn(state);
  11270. lua_interface->ResetFunctionStack(state);
  11271. if (npc && npc->IsNPC()) {
  11272. NPC* shard = (NPC*)npc;
  11273. int64 timestamp = shard->GetShardCreatedTimestamp();
  11274. lua_interface->SetSInt64Value(state, timestamp);
  11275. return 1;
  11276. }
  11277. lua_interface->SetSInt64Value(state, 0);
  11278. return 1;
  11279. }
  11280. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11281. if (!lua_interface)
  11282. return 0;
  11283. int32 shardid = lua_interface->GetInt32Value(state);
  11284. lua_interface->ResetFunctionStack(state);
  11285. if(shardid < 1)
  11286. lua_interface->SetBooleanValue(state, false);
  11287. else
  11288. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11289. return 1;
  11290. }
  11291. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11292. if (!lua_interface)
  11293. return 0;
  11294. Spawn* spawn = lua_interface->GetSpawn(state);
  11295. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11296. if (spawn) {
  11297. spawn->PauseMovement(delay_in_ms);
  11298. }
  11299. lua_interface->ResetFunctionStack(state);
  11300. return 0;
  11301. }
  11302. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11303. if (!lua_interface)
  11304. return 0;
  11305. Spawn* spawn = lua_interface->GetSpawn(state);
  11306. if (spawn) {
  11307. spawn->StopMovement();
  11308. }
  11309. lua_interface->ResetFunctionStack(state);
  11310. return 0;
  11311. }
  11312. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11313. Player* player = (Player*)lua_interface->GetSpawn(state);
  11314. int8 level = lua_interface->GetInt8Value(state, 2);
  11315. lua_interface->ResetFunctionStack(state);
  11316. if (player && player->IsPlayer() && level > 0) {
  11317. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11318. return 1;
  11319. }
  11320. return 0;
  11321. }
  11322. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11323. Player* player = (Player*)lua_interface->GetSpawn(state);
  11324. int8 level = lua_interface->GetInt8Value(state, 2);
  11325. lua_interface->ResetFunctionStack(state);
  11326. if (player && player->IsPlayer() && level > 0) {
  11327. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11328. return 1;
  11329. }
  11330. return 0;
  11331. }
  11332. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11333. ZoneServer* zone = lua_interface->GetZone(state);
  11334. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11335. lua_interface->ResetFunctionStack(state);
  11336. if (zone) {
  11337. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11338. if (spawn) {
  11339. lua_interface->SetSpawnValue(state, spawn);
  11340. return 1;
  11341. }
  11342. }
  11343. return 0;
  11344. }
  11345. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11346. if (!lua_interface)
  11347. return 0;
  11348. Spawn* spawn = lua_interface->GetSpawn(state);
  11349. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11350. lua_interface->ResetFunctionStack(state);
  11351. bool res = false;
  11352. if(spawn && spawn->IsTransportSpawn())
  11353. {
  11354. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11355. spawn->SetRailID(rail_id);
  11356. res = true;
  11357. }
  11358. else if (!spawn) {
  11359. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11360. }
  11361. else if(!spawn->IsTransportSpawn()) {
  11362. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  11363. }
  11364. lua_interface->SetBooleanValue(state, res);
  11365. return 1;
  11366. }
  11367. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11368. if (!lua_interface)
  11369. return 0;
  11370. ZoneServer* zone = lua_interface->GetZone(state);
  11371. lua_interface->ResetFunctionStack(state);
  11372. if (zone) {
  11373. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11374. return 1;
  11375. }
  11376. return 0;
  11377. }
  11378. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11379. if (!lua_interface)
  11380. return 0;
  11381. Spawn* spawn = lua_interface->GetSpawn(state);
  11382. lua_interface->ResetFunctionStack(state);
  11383. if (spawn) {
  11384. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11385. return 1;
  11386. }
  11387. return 0;
  11388. }
  11389. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11390. if (!lua_interface)
  11391. return 0;
  11392. Spawn* player = lua_interface->GetSpawn(state);
  11393. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11394. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11395. lua_interface->ResetFunctionStack(state);
  11396. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11397. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11398. }
  11399. else if(!zoneID) {
  11400. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11401. }
  11402. else
  11403. {
  11404. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11405. return 1;
  11406. }
  11407. return 0;
  11408. }
  11409. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11410. if (!lua_interface)
  11411. return 0;
  11412. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11413. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11414. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11415. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11416. lua_interface->ResetFunctionStack(state);
  11417. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11418. world.GetWorldTimeStruct()->year = newYear;
  11419. world.GetWorldTimeStruct()->month = newMonth;
  11420. world.GetWorldTimeStruct()->hour = newHour;
  11421. world.GetWorldTimeStruct()->minute = newMinute;
  11422. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11423. return 0;
  11424. }
  11425. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11426. if (!lua_interface)
  11427. return 0;
  11428. lua_interface->ResetFunctionStack(state);
  11429. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11430. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11431. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11432. return 1;
  11433. }
  11434. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11435. if (!lua_interface)
  11436. return 0;
  11437. lua_interface->ResetFunctionStack(state);
  11438. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11439. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11440. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11441. return 1;
  11442. }
  11443. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11444. if (!lua_interface)
  11445. return 0;
  11446. lua_interface->ResetFunctionStack(state);
  11447. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11448. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11449. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11450. return 1;
  11451. }
  11452. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11453. if (!lua_interface)
  11454. return 0;
  11455. lua_interface->ResetFunctionStack(state);
  11456. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11457. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11458. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11459. return 1;
  11460. }
  11461. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11462. if (!lua_interface)
  11463. return 0;
  11464. lua_interface->ResetFunctionStack(state);
  11465. world.SendTimeUpdate();
  11466. return 0;
  11467. }
  11468. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11469. bool update_result = false;
  11470. Faction* faction = 0;
  11471. Spawn* spawn = lua_interface->GetSpawn(state);
  11472. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11473. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11474. lua_interface->ResetFunctionStack(state);
  11475. if(!spawn || !spawn->IsPlayer()) {
  11476. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11477. return 0;
  11478. }
  11479. Player* player = (Player*)spawn;
  11480. Client* client = player->GetClient();
  11481. if (faction_id > 0) {
  11482. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11483. if(hasfaction == 0) {
  11484. //they do not have the faction. Lets get the default value and feed it in.
  11485. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11486. //add the default faction for the player.
  11487. player->SetFactionValue(faction_id, defaultfaction);
  11488. }
  11489. if(increase >= 0) {
  11490. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11491. faction = master_faction_list.GetFaction(faction_id);
  11492. if(faction && update_result)
  11493. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11494. else if(faction)
  11495. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11496. lua_interface->SetBooleanValue(state, true);
  11497. return 1;
  11498. }
  11499. if(increase < 0){
  11500. //change the negative to a positive, since thats how decreasefaction() likes it.
  11501. increase *= -1;
  11502. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11503. faction = master_faction_list.GetFaction(faction_id);
  11504. if(faction && update_result)
  11505. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11506. else if(faction)
  11507. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11508. lua_interface->SetBooleanValue(state, true);
  11509. return 1;
  11510. }
  11511. }
  11512. lua_interface->SetBooleanValue(state, false);
  11513. return 1;
  11514. }
  11515. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11516. bool hascoin = 0;
  11517. Player* player = (Player*)lua_interface->GetSpawn(state);
  11518. int32 coins = lua_interface->GetInt32Value(state, 2);
  11519. lua_interface->ResetFunctionStack(state);
  11520. if (player && player->IsPlayer()) {
  11521. hascoin = player->HasCoins(coins);
  11522. if(hascoin == 0) {
  11523. lua_interface->SetBooleanValue(state, false);
  11524. return 1;
  11525. }
  11526. if(hascoin == 1) {
  11527. lua_interface->SetBooleanValue(state, true);
  11528. return 1;
  11529. }
  11530. }
  11531. return 0;
  11532. }
  11533. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11534. int32 loot_tier = 0;
  11535. Spawn* spawn = lua_interface->GetSpawn(state);
  11536. lua_interface->ResetFunctionStack(state);
  11537. if (spawn) {
  11538. loot_tier = spawn->GetLootTier();
  11539. lua_interface->SetInt32Value(state, loot_tier);
  11540. return 1;
  11541. }
  11542. return 0;
  11543. }
  11544. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11545. if (!lua_interface)
  11546. return 0;
  11547. Spawn* spawn = lua_interface->GetSpawn(state);
  11548. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11549. lua_interface->ResetFunctionStack(state);
  11550. if (spawn) {
  11551. spawn->SetLootTier(loot_tier);
  11552. lua_interface->SetBooleanValue(state, true);
  11553. return 1;
  11554. }
  11555. lua_interface->SetBooleanValue(state, false);
  11556. return 1;
  11557. }
  11558. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11559. int32 loot_drop_type = 0;
  11560. Spawn* spawn = lua_interface->GetSpawn(state);
  11561. lua_interface->ResetFunctionStack(state);
  11562. if (spawn) {
  11563. loot_drop_type = spawn->GetLootDropType();
  11564. lua_interface->SetInt32Value(state, loot_drop_type);
  11565. return 1;
  11566. }
  11567. return 0;
  11568. }
  11569. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11570. if (!lua_interface)
  11571. return 0;
  11572. Spawn* spawn = lua_interface->GetSpawn(state);
  11573. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11574. lua_interface->ResetFunctionStack(state);
  11575. if (spawn) {
  11576. spawn->SetLootDropType(loot_drop_type);
  11577. lua_interface->SetBooleanValue(state, true);
  11578. return 1;
  11579. }
  11580. lua_interface->SetBooleanValue(state, false);
  11581. return 1;
  11582. }
  11583. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11584. if (!lua_interface)
  11585. return 0;
  11586. Spawn* spawn = lua_interface->GetSpawn(state);
  11587. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11588. if(damage_amount > 100) {
  11589. damage_amount = 100;
  11590. }
  11591. if (!spawn) {
  11592. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11593. return 0;
  11594. }
  11595. if (spawn->IsPlayer()) {
  11596. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11597. lua_interface->SetBooleanValue(state, true);
  11598. else
  11599. lua_interface->SetBooleanValue(state, false);
  11600. }
  11601. else {
  11602. lua_interface->SetBooleanValue(state, false);
  11603. }
  11604. return 1;
  11605. }
  11606. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11607. ZoneServer* zone = lua_interface->GetZone(state);
  11608. int32 version = lua_interface->GetInt32Value(state, 2);
  11609. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11610. if(region_map == nullptr) {
  11611. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11612. return 0;
  11613. }
  11614. string region_name = lua_interface->GetStringValue(state, 3);
  11615. string env_name = lua_interface->GetStringValue(state, 4);
  11616. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11617. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11618. float dist = lua_interface->GetFloatValue(state, 7);
  11619. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11620. lua_interface->ResetFunctionStack(state);
  11621. lua_interface->SetBooleanValue(state, true);
  11622. return 1;
  11623. }
  11624. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11625. ZoneServer* zone = lua_interface->GetZone(state);
  11626. int32 version = lua_interface->GetInt32Value(state, 2);
  11627. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11628. if(region_map == nullptr) {
  11629. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11630. return 0;
  11631. }
  11632. string region_name = lua_interface->GetStringValue(state, 3);
  11633. region_map->RemoveRegionNode(region_name);
  11634. lua_interface->ResetFunctionStack(state);
  11635. lua_interface->SetBooleanValue(state, true);
  11636. return 1;
  11637. }
  11638. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11639. Client* client = nullptr;
  11640. Spawn* player = lua_interface->GetSpawn(state);
  11641. if (!player) {
  11642. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11643. lua_interface->SetBooleanValue(state, false);
  11644. return 1;
  11645. }
  11646. if (!player->IsPlayer()) {
  11647. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11648. lua_interface->SetBooleanValue(state, false);
  11649. return 1;
  11650. }
  11651. client = player->GetClient();
  11652. if (!client) {
  11653. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11654. lua_interface->SetBooleanValue(state, false);
  11655. return 1;
  11656. }
  11657. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11658. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11659. lua_interface->ResetFunctionStack(state);
  11660. lua_interface->SetBooleanValue(state, success_sight);
  11661. return 1;
  11662. }
  11663. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11664. if (!lua_interface)
  11665. return 0;
  11666. bool result = false;
  11667. Spawn* spawn = lua_interface->GetSpawn(state);
  11668. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11669. lua_interface->ResetFunctionStack(state);
  11670. if (!spawn)
  11671. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11672. else if (!spawn->IsNPC())
  11673. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11674. else
  11675. {
  11676. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11677. result = true;
  11678. }
  11679. lua_interface->SetBooleanValue(state, result);
  11680. return 1;
  11681. }
  11682. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11683. if (!lua_interface)
  11684. return 0;
  11685. bool result = false;
  11686. Spawn* spawn = lua_interface->GetSpawn(state);
  11687. lua_interface->ResetFunctionStack(state);
  11688. if (!spawn)
  11689. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11690. else if (!spawn->IsNPC())
  11691. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11692. else
  11693. {
  11694. if(((NPC*)spawn)->cast_on_aggro_completed)
  11695. result = true;
  11696. }
  11697. lua_interface->SetBooleanValue(state, result);
  11698. return 1;
  11699. }