12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272 |
- /*
- EQ2Emulator: Everquest II Server Emulator
- Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
- This file is part of EQ2Emulator.
- EQ2Emulator is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- EQ2Emulator is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "LuaFunctions.h"
- #include "Spawn.h"
- #include "WorldDatabase.h"
- #include "LuaInterface.h"
- #include "../common/ConfigReader.h"
- #include "client.h"
- #include "World.h"
- #include "Commands/Commands.h"
- #include "races.h"
- #include "classes.h"
- #include "Variables.h"
- #include "SpellProcess.h"
- #include "Rules/Rules.h"
- #include "../common/Log.h"
- #include <math.h>
- #include "HeroicOp/HeroicOp.h"
- #include "RaceTypes/RaceTypes.h"
- #include "ClientPacketFunctions.h"
- #include "Transmute.h"
- #include "Titles.h"
- #include <boost/algorithm/string/predicate.hpp>
- #include <sstream>
- #include <boost/algorithm/string.hpp>
- extern MasterFactionList master_faction_list;
- extern WorldDatabase database;
- extern LuaInterface* lua_interface;
- extern ConfigReader configReader;
- extern MasterQuestList master_quest_list;
- extern MasterItemList master_item_list;
- extern MasterSpellList master_spell_list;
- extern World world;
- extern Commands commands;
- extern ZoneList zone_list;
- extern Races races;
- extern Classes classes;
- extern Variables variables;
- extern MasterSkillList master_skill_list;
- extern MasterHeroicOPList master_ho_list;
- extern MasterRaceTypeList race_types_list;
- extern MasterLanguagesList master_languages_list;
- extern MasterTitlesList master_titles_list;
- extern RuleManager rule_manager;
- vector<string> ParseString(string strVal, char delim) {
- stringstream ss(strVal);
- vector<string> ret;
- while (ss.good())
- {
- string substr;
- getline(ss, substr, delim);
- ret.push_back(substr);
- }
- return ret;
- }
- vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
- stringstream ss(strVal);
- vector<unsigned int> ret;
- while (ss.good())
- {
- string substr;
- getline(ss, substr, delim);
- stringstream valss(substr);
- unsigned int val = 0;
- valss >> val;
- ret.push_back(val);
- }
- return ret;
- }
- map<string, signed int> ParseStringMap(string strVal, char delim) {
- vector<string> pairs = ParseString(strVal, delim);
- vector<string>::iterator itr;
- map<string, signed int> ret;
- for (itr = pairs.begin(); itr != pairs.end(); itr++) {
- vector<string> keyvaluepair = ParseString(*itr, ':');
- if (keyvaluepair.size() == 2) {
- stringstream valss(keyvaluepair[1]);
- int32 val = 0;
- valss >> val;
- ret[keyvaluepair[0]] = val;
- }
- }
-
- return ret;
- }
- map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
- vector<string> pairs = ParseString(strVal, delim);
- vector<string>::iterator itr;
- map<unsigned int, unsigned short> ret;
- for (itr = pairs.begin(); itr != pairs.end(); itr++) {
- vector<string> keyvaluepair = ParseString(*itr, ':');
- int32 key = 0;
- if (keyvaluepair.size() > 0) {
- stringstream keyss(keyvaluepair[0]);
- keyss >> key;
- }
- if (keyvaluepair.size() == 1) {
- ret[key] = 1;
- }
- else if (keyvaluepair.size() == 2) {
- stringstream valss(keyvaluepair[1]);
- unsigned short val = 0;
- valss >> val;
- ret[key] = val;
- }
- }
- return ret;
- }
- map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
- vector<string> pairs = ParseString(strVal, delim);
- vector<string>::iterator itr;
- map<unsigned int, signed int> ret;
- for (itr = pairs.begin(); itr != pairs.end(); itr++) {
- vector<string> keyvaluepair = ParseString(*itr, ':');
- int32 key = 0;
- if (keyvaluepair.size() > 0) {
- stringstream keyss(keyvaluepair[0]);
- keyss >> key;
- }
- if (keyvaluepair.size() == 1) {
- ret[key] = 1;
- }
- else if (keyvaluepair.size() == 2) {
- stringstream valss(keyvaluepair[1]);
- signed int val = 0;
- valss >> val;
- ret[key] = val;
- }
- }
- return ret;
- }
- int EQ2Emu_lua_PlayFlavor(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string mp3_string = lua_interface->GetStringValue(state, 2);
- string text_string = lua_interface->GetStringValue(state, 3);
- string emote_string = lua_interface->GetStringValue(state, 4);
- int32 key1 = lua_interface->GetInt32Value(state, 5);
- int32 key2 = lua_interface->GetInt32Value(state, 6);
- Spawn* player = lua_interface->GetSpawn(state, 7);
- int8 language = lua_interface->GetInt8Value(state, 8);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- const char* mp3 = 0;
- const char* text = 0;
- const char* emote = 0;
- if (mp3_string.length() > 0)
- mp3 = mp3_string.c_str();
- if (text_string.length() > 0)
- text = text_string.c_str();
- if (emote_string.length() > 0)
- emote = emote_string.c_str();
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client) {
- if (((Player*)player)->WasSentSpawn(spawn->GetID()))
- spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
- }
- else
- spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
- }
- return 0;
- }
- int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
-
- int8 type = lua_interface->GetInt8Value(state, 2);
- int32 id = lua_interface->GetInt32Value(state, 3);
- int16 index = lua_interface->GetInt16Value(state, 4);
- Spawn* player = lua_interface->GetSpawn(state, 5);
- int8 language = lua_interface->GetInt8Value(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client) {
- VoiceOverStruct non_garble, garble;
- bool garble_success = false;
- bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
- client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
- }
- else
- spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
- }
- return 0;
- }
- int EQ2Emu_lua_PlaySound(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string sound_string = lua_interface->GetStringValue(state, 2);
- float x = lua_interface->GetFloatValue(state, 3);
- float y = lua_interface->GetFloatValue(state, 4);
- float z = lua_interface->GetFloatValue(state, 5);
- Spawn* player = lua_interface->GetSpawn(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (spawn && sound_string.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client)
- spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
- else
- spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
- }
- return 0;
- }
- int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int16 quest_step = lua_interface->GetInt16Value(state, 3);
- bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
- bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
- int16 flag_override = lua_interface->GetInt16Value(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (quest_id > 0) {
- //Add this quest to the list of required quests for this spawn
- spawn->SetQuestsRequired(quest_id, quest_step);
- //If private spawn value set
- if (private_spawn) {
- //Set the spawn to be private when not granted access through this quest
- spawn->AddAllowAccessSpawn(spawn);
- spawn->SetPrivateQuestSpawn(true);
- }
- //This value allows access after a quest step, or the whole quest has been completed
- if (continued_access)
- spawn->SetQuestsRequiredContinuedAccess(true);
- //This value will override vis_flags in the vis packet
- if (flag_override > 0)
- spawn->SetQuestsRequiredOverride(flag_override);
- }
- return 0;
- }
- int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float max_distance = lua_interface->GetFloatValue(state, 2);
- string variable = lua_interface->GetStringValue(state, 3);
- string value = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
- spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
- return 0;
- }
- int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- float intensity = lua_interface->GetFloatValue(state, 2);
- int8 direction = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
- return 0;
- }
- if (player->GetZone())
- client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
- return 0;
- }
- PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
- if (packet) {
- /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
- v1 = *(float *)(a1 + 4);
- if ( v1 > 0.0 )
- v2 = fminf(v1, 1.0);
- else
- v2 = 0.1;
- */
- packet->setDataByName("intensity", intensity);
- if ( client->GetVersion() > 561 )
- packet->setDataByName("direction", direction);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_KillSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* dead = lua_interface->GetSpawn(state);
- Spawn* killer = lua_interface->GetSpawn(state, 2);
- bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
- lua_interface->ResetFunctionStack(state);
- if (dead && dead->Alive() && dead->GetZone())
- dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
- return 0;
- }
- int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float max_distance = lua_interface->GetFloatValue(state, 2);
- bool include_players = lua_interface->GetInt8Value(state, 3);
- bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
- lua_interface->ResetFunctionStack(state);
- if (max_distance > 0 && spawn && spawn->GetZone())
- spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
- return 0;
- }
- int EQ2Emu_lua_Despawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 delay = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->GetZone())
- spawn->GetZone()->Despawn(spawn, delay);
- return 0;
- }
- int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->info_changed = true;
- spawn->SetShowHandIcon(displayHandIcon);
- }
- return 0;
- }
- //this function is used to force an update packet to be sent.
- //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
- int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->vis_changed = true;
- spawn->GetZone()->AddChangedSpawn(spawn);
- }
- return 0;
- }
- //this function is used to force an update packet to be sent.
- //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
- int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->info_changed = true;
- spawn->GetZone()->AddChangedSpawn(spawn);
- }
- return 0;
- }
- int EQ2Emu_lua_SendStateCommand(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 new_state = lua_interface->GetInt32Value(state, 2);
- Spawn* player = lua_interface->GetSpawn(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if(player)
- {
- if(player->IsPlayer())
- {
- Client* client = ((Player*)player)->GetClient();
- if(client)
- {
- ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- else
- 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());
- }
- else
- 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());
- }
- else
- {
- spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_SpawnSet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string variable = lua_interface->GetStringValue(state, 2);
- string value = lua_interface->GetStringValue(state, 3);
- 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.
- bool temporary_flag = true;
-
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- int8 index = 0;
- if(num_args >= 5)
- {
- 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
-
- index = lua_interface->GetInt8Value(state, 6);
- }
-
- lua_interface->ResetFunctionStack(state);
- int32 type = commands.GetSpawnSetType(variable);
- if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
- commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
- return 0;
- }
- int EQ2Emu_lua_GetSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn_id > 0) {
- Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
- if (closest_spawn) {
- lua_interface->SetSpawnValue(state, closest_spawn);
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- vector<Spawn*> spawns;
- int32 position = 0;
-
- if(lua_istable(state, 1)) {
- size_t len = lua_rawlen(state, 1);
- for(int i=1;i <= len; i++)
- {
- // get the entry to stack
- lua_rawgeti(state, 1, i);
- int Top = lua_gettop(state);
-
- if(lua_islightuserdata(state,Top)) {
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
- if(data->IsSpawn()) {
- spawns.push_back(data->spawn);
- }
- }
- // remove entry from stack
- lua_pop(state,1);
- }
- }
-
- position = lua_interface->GetInt32Value(state, 2);
-
- lua_interface->ResetFunctionStack(state);
-
- Spawn* spawn = 0;
- if(position < spawns.size()) {
- spawn = spawns.at(position);
- }
-
- if(spawn) {
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- vector<Spawn*> spawns;
-
- if(lua_istable(state, 1)) {
- size_t len = lua_rawlen(state, 1);
- for(int i=1;i <= len; i++)
- {
- // get the entry to stack
- lua_rawgeti(state, 1, i);
- int Top = lua_gettop(state);
-
- if(lua_islightuserdata(state,Top)) {
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
- if(data->IsSpawn()) {
- spawns.push_back(data->spawn);
- }
- }
- // remove entry from stack
- lua_pop(state,1);
- }
- }
-
- lua_interface->ResetFunctionStack(state);
-
- lua_interface->SetInt32Value(state, spawns.size());
- return 1;
- }
- int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
- if (spawns.size() > 0) {
- lua_createtable(state, spawns.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < spawns.size(); i++) {
- lua_interface->SetSpawnValue(state, spawns.at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
- if (spawns.size() > 0) {
- lua_createtable(state, spawns.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < spawns.size(); i++) {
- lua_interface->SetSpawnValue(state, spawns.at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- vector<Spawn*> spawns = spawn->GetPassengersOnRail();
- if (spawns.size() > 0) {
- lua_createtable(state, spawns.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < spawns.size(); i++) {
- lua_interface->SetSpawnValue(state, spawns.at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetVariableValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- string variable_name = lua_interface->GetStringValue(state);
- lua_interface->ResetFunctionStack(state);
- Variable* var = variables.FindVariable(variable_name);
- if (var) {
- lua_interface->SetStringValue(state, var->GetValue());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 total_coins = lua_interface->GetInt32Value(state);
- lua_interface->ResetFunctionStack(state);
- if (total_coins == 0) {
- lua_interface->SetStringValue(state, "0 copper");
- return 1;
- }
- char tmp[64] = { 0 };
- string message = "";
- int32 val = 0;
- if (total_coins >= 1000000) {
- val = total_coins / 1000000;
- total_coins -= 1000000 * val;
- sprintf(tmp, " %u Platinum", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins >= 10000) {
- val = total_coins / 10000;
- total_coins -= 10000 * val;
- sprintf(tmp, " %u Gold", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins >= 100) {
- val = total_coins / 100;
- total_coins -= 100 * val;
- sprintf(tmp, " %u Silver", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins > 0) {
- sprintf(tmp, " %u Copper", (int32)total_coins);
- message.append(tmp);
- }
- lua_interface->SetStringValue(state, message.c_str());
- return 1;
- }
- int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 group_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- Spawn* spawn = zone->GetSpawnGroup(group_id);
- if (spawn) {
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 location_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- Spawn* spawn = zone->GetSpawnByLocationID(location_id);
- if (spawn) {
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnID(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 new_group_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetSpawnGroupID(new_group_id);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 new_group_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if(spawn->GetSpawnGroupID() == new_group_id) {
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
- Player* player = (Player*)lua_interface->GetSpawn(state);
- int32 faction_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && faction_id > 0) {
- lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetFactionID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 value = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetFactionID(value);
- }
- return 0;
- }
- int EQ2Emu_lua_GetFactionID(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetFactionID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetGender(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetGender());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetTarget(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
- lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_PlayVoice(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string mp3_string = lua_interface->GetStringValue(state, 2);
- int32 key1 = lua_interface->GetInt32Value(state, 3);
- int32 key2 = lua_interface->GetInt32Value(state, 4);
- Spawn* player = lua_interface->GetSpawn(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (spawn && mp3_string.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client) {
- if (((Player*)player)->WasSentSpawn(spawn->GetID()))
- spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
- }
- else
- spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
- }
- return 0;
- }
- int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
- lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
- lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
- return 3;
- }
- return 0;
- }
- int EQ2Emu_lua_HasLootItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
- return 1;
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddLootItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int16 charges = lua_interface->GetInt16Value(state, 3);
- if (charges == 0)
- charges = 1;
- ((Entity*)spawn)->AddLootItem(item_id, charges);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- Item* item = spawn->LootItem(item_id);
- lua_interface->SetLuaUserDataStale(item);
- safe_delete(item);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddLootCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- int32 val = lua_interface->GetInt32Value(state, 2);
- spawn->AddLootCoins(val);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_GiveLoot(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* entity = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- if (entity && player && player->IsPlayer()) {
- int32 coins = lua_interface->GetInt32Value(state, 3);
- vector<Item*>* items = 0;
- int i = 0;
- int32 item_id = 0;
- while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
- if (items == 0)
- items = new vector<Item*>;
- if (master_item_list.GetItem(item_id))
- items->push_back(master_item_list.GetItem(item_id));
- i++;
- }
- Client* client = 0;
- client = ((Player*)player)->GetClient();
- if (client)
- ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
- if(coins > 0)
- entity->AddLootCoins(coins);
- safe_delete(items);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* entity = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- int32 item_id = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* entity = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (entity && player && player->IsPlayer()) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_CreateConversation(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
- lua_interface->SetLuaUserDataStale(conversation);
- safe_delete(conversation);
- lua_interface->ResetFunctionStack(state);
- conversation = new vector<ConversationOption>();
- lua_interface->SetConversationValue(state, conversation);
- return 1;
- }
- int EQ2Emu_lua_AddConversationOption(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
- if (conversation) {
- ConversationOption conv_option;
- conv_option.option = lua_interface->GetStringValue(state, 2);
- conv_option.function = lua_interface->GetStringValue(state, 3);
- if (conv_option.option.length() > 0)
- conversation->push_back(conv_option);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_CloseConversation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* npc = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (npc && player && player->IsPlayer() && player->GetZone()) {
- Client* client = ((Player*)player)->GetClient();
- if (client) {
- int32 conversation_id = client->GetConversationID(npc, 0);
- client->CloseDialog(conversation_id);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (item && player && player->IsPlayer() && player->GetZone()) {
- Client* client = ((Player*)player)->GetClient();
- if (client) {
- int32 conversation_id = client->GetConversationID(0, item);
- client->CloseDialog(conversation_id);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
- Spawn* spawn = 0;
- Item* item = 0;
- int8 type = lua_interface->GetInt8Value(state, 2);
- if (type == 1 || type == 3)
- spawn = lua_interface->GetSpawn(state, 3);
- else if (type == 2 || type == 4)
- item = lua_interface->GetItem(state, 3);
- Spawn* player = lua_interface->GetSpawn(state, 4);
- string text = lua_interface->GetStringValue(state, 5);
- string mp3 = lua_interface->GetStringValue(state, 6);
- int32 key1 = lua_interface->GetInt32Value(state, 7);
- int32 key2 = lua_interface->GetInt32Value(state, 8);
- int8 language = lua_interface->GetInt8Value(state, 9);
-
- int numargs = lua_interface->GetNumberOfArgs(state);
- int8 can_close = 1;
- if(numargs > 9)
- can_close = lua_interface->GetInt32Value(state, 10);
- lua_interface->ResetFunctionStack(state);
- if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
- Client* client = ((Player*)player)->GetClient();
- if (client) {
- if (spawn) {
- // Need to do this so the function works the same as it did before
- if (type == 1)
- type++;
- if (mp3.length() > 0)
- client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
- else
- client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
- }
- else {
- if (mp3.length() > 0)
- client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
- else
- client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
- }
- }
- }
- lua_interface->SetLuaUserDataStale(conversation);
- safe_delete(conversation);
- return 0;
- }
- int EQ2Emu_lua_StartConversation(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
- Spawn* source = lua_interface->GetSpawn(state, 2);
- Spawn* player = lua_interface->GetSpawn(state, 3);
- string text = lua_interface->GetStringValue(state, 4);
- string mp3 = lua_interface->GetStringValue(state, 5);
- int32 key1 = lua_interface->GetInt32Value(state, 6);
- int32 key2 = lua_interface->GetInt32Value(state, 7);
- int8 language = lua_interface->GetInt32Value(state, 8);
-
- int numargs = lua_interface->GetNumberOfArgs(state);
- int8 can_close = 1;
- if(numargs > 8)
- can_close = lua_interface->GetInt32Value(state, 9);
-
- lua_interface->ResetFunctionStack(state);
- if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
- Client* client = ((Player*)player)->GetClient();
- if (mp3.length() > 0)
- client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
- else
- client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
- lua_interface->SetLuaUserDataStale(conversation);
- safe_delete(conversation);
- }
- else
- 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);
- return 0;
- }
- int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float distance = lua_interface->GetFloatValue(state, 2);
- string in_range_function = lua_interface->GetStringValue(state, 3);
- string leaving_range_function = lua_interface->GetStringValue(state, 4);
- if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
- spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
- return 0;
- }
- int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- float x = lua_interface->GetFloatValue(state, 2);
- float y = lua_interface->GetFloatValue(state, 3);
- float z = lua_interface->GetFloatValue(state, 4);
- float max_variation = lua_interface->GetFloatValue(state, 5);
- string in_range_function = lua_interface->GetStringValue(state, 6);
- string leaving_range_function = lua_interface->GetStringValue(state, 7);
- lua_interface->ResetFunctionStack(state);
- if (zone && in_range_function.length() > 0)
- zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
- return 0;
- }
- int EQ2Emu_lua_SetLootCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- int32 val = lua_interface->GetInt32Value(state, 2);
- ((Entity*)spawn)->SetLootCoins(val);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_GetLootCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float x = lua_interface->GetFloatValue(state, 2);
- float y = lua_interface->GetFloatValue(state, 3);
- float z = lua_interface->GetFloatValue(state, 4);
- float speed = lua_interface->GetFloatValue(state, 5);
- int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
- string function = lua_interface->GetStringValue(state, 7);
-
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- float heading = lua_interface->GetFloatValue(state, 8);
- if (spawn) {
- spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
- spawn->GetZone()->AddMovementNPC(spawn);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_IsPlayer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->IsPlayer());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetCharacterID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsPlayer()) {
- lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
- return 1;
- }
- lua_interface->SetInt32Value(state, 0);
- return 1;
- }
- int EQ2Emu_lua_FaceTarget(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
-
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- bool reset_action_state = true;
- if(num_args > 2)
- reset_action_state = lua_interface->GetBooleanValue(state, 3);
-
- if (spawn && target) {
- if (spawn->IsEntity())
- // ((Entity*)spawn)->FaceTarget(target);
- static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_MoveToLocation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float x = lua_interface->GetFloatValue(state, 2);
- float y = lua_interface->GetFloatValue(state, 3);
- float z = lua_interface->GetFloatValue(state, 4);
- float speed = lua_interface->GetFloatValue(state, 5);
- string lua_function = lua_interface->GetStringValue(state, 6);
- bool more_points = lua_interface->GetBooleanValue(state, 7);
- if (spawn) {
- if (speed == 0)
- speed = spawn->GetSpeed();
- spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->ClearRunningLocations();
- }
- return 0;
- }
- int EQ2Emu_lua_Say(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- Spawn* player = lua_interface->GetSpawn(state, 3);
- float dist = lua_interface->GetFloatValue(state, 4);
- int32 language = lua_interface->GetInt32Value(state, 5);
- if (spawn && message.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client)
- spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- else
- spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_Shout(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- Spawn* player = lua_interface->GetSpawn(state, 3);
- float dist = lua_interface->GetFloatValue(state, 4);
- int32 language = lua_interface->GetInt32Value(state, 5);
- if (spawn && message.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client)
- spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- else
- spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_SayOOC(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- Spawn* player = lua_interface->GetSpawn(state, 3);
- float dist = lua_interface->GetFloatValue(state, 4);
- int32 language = lua_interface->GetInt32Value(state, 5);
- if (spawn && message.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client)
- spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- else
- spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_Emote(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
- Spawn* player = lua_interface->GetSpawn(state, 4);
- char* to = 0;
- if (spawn2)
- to = spawn2->GetName();
- if (spawn && message.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client)
- spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
- else
- spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_SpellHeal(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if(!luaspell || luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- Spawn* caster = luaspell->caster;
- string heal_type = lua_interface->GetStringValue(state);//power, heal ect
- int32 min_heal = lua_interface->GetInt32Value(state, 2);
- int32 max_heal = lua_interface->GetInt32Value(state, 3);
- Spawn* target = lua_interface->GetSpawn(state, 4);
- int8 crit_mod = lua_interface->GetInt32Value(state, 5);
- bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
- string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
- lua_interface->ResetFunctionStack(state);
-
- boost::to_lower(heal_type);
- if (caster && caster->IsEntity()) {
- bool success = false;
- luaspell->resisted = false;
- if (target) {
- float distance = caster->GetDistance(target, true);
- if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
- success = true;
- }
- if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
- Spawn* target = 0;
- ZoneServer* zone = luaspell->caster->GetZone();
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
- float distance = caster->GetDistance(target, true);
- ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- success = true;
- }
- if (success) {
- if (caster->GetZone())
- caster->GetZone()->TriggerCharSheetTimer();
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SpellHealPct(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if(!luaspell || luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- Spawn* caster = luaspell->caster;
- string heal_type = lua_interface->GetStringValue(state);//power, heal ect
- float percentage = lua_interface->GetFloatValue(state, 2);
- bool current_value = lua_interface->GetBooleanValue(state, 3);
- bool caster_value = lua_interface->GetBooleanValue(state, 4);
- Spawn* target = lua_interface->GetSpawn(state, 5);
- int8 crit_mod = lua_interface->GetInt32Value(state, 6);
- bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
- string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
- lua_interface->ResetFunctionStack(state);
- boost::to_lower(heal_type);
- int32 min_heal = 0, max_heal = 0;
- if (caster && caster->IsEntity() && target) {
- if(percentage <= 0.0f)
- {
- LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
- return 0;
- }
- if(heal_type == "power")
- {
- if(current_value)
- {
- if(caster_value)
- min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
- else
- min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
- }
- else
- {
- if(caster_value)
- min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
- else
- min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
- }
- }
- else
- {
- if(current_value)
- {
- if(caster_value)
- min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
- else
- min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
- }
- else
- {
- if(caster_value)
- min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
- else
- min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
- }
- }
- bool success = false;
- luaspell->resisted = false;
- if (target) {
- float distance = caster->GetDistance(target, true);
- if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
- success = true;
- }
- if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
- Spawn* target = 0;
- ZoneServer* zone = luaspell->caster->GetZone();
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
- float distance = caster->GetDistance(target, true);
- ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- success = true;
- }
- if (success) {
- if (caster->GetZone())
- caster->GetZone()->TriggerCharSheetTimer();
- }
- }
- return 0;
- }
- int EQ2Emu_lua_AddItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int16 quantity = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- // default of 1 quantity to add
- if (quantity == 0)
- quantity = 1;
- if (spawn && spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client && item_id > 0) {
- lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
- return 1;
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_SummonItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
- string location = lua_interface->GetStringValue(state, 4);
- int16 item_count = lua_interface->GetInt16Value(state,5);
-
- //devn00b: if we dont have a count, assume 1 item.
- if(!item_count) {
- item_count = 1;
- }
-
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client && item_id > 0) {
- if (strncasecmp(location.c_str(), "bank", 4) == 0)
- lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
- else
- lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
- if (send_messages) {
- Item* item = master_item_list.GetItem(item_id);
- if (item) {
- if(item_count > 1) {
- client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
- string popup_text1 = "You receive "+ item_count;
- string popup_text2 = " " + item->name;
- string popup_text = popup_text1 + popup_text2;
- client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
- // return 1;
- } else {
- client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
- string popup_text = "You receive " + item->name;
- client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
- }
- }
- }
- return 1;
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_RemoveItem(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int16 quantity = lua_interface->GetInt16Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- // default of 1 to remove
- if (quantity == 0)
- quantity = 1;
- Client* client;
- Item* item;
- if (spawn && spawn->IsPlayer() && item_id > 0) {
- if ((client = ((Player*)spawn)->GetClient())) {
- if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
- if (client->RemoveItem(item, quantity)) {
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_HasItem(lua_State* state) {
- Spawn* player = lua_interface->GetSpawn(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- bool include_bank = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- bool hasItem = false;
- hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
- if (!hasItem)
- hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
- lua_interface->SetBooleanValue(state, hasItem);
- return 1;
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_Spawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
- float x = lua_interface->GetFloatValue(state, 4);
- float y = lua_interface->GetFloatValue(state, 5);
- float z = lua_interface->GetFloatValue(state, 6);
- float heading = lua_interface->GetFloatValue(state, 7);
- if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
- Spawn* spawn = zone->GetSpawn(spawn_id);
- if (!spawn)
- lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
- else {
- spawn->SetX(x);
- spawn->SetZ(z);
- spawn->SetY(y,true,true);
- spawn->SetLocation(zone->GetClosestLocation(spawn));
- spawn->SetHeading(heading);
- if (restricted_npc)
- spawn->AddAllowAccessSpawn(spawn);
- const char* spawn_script = world.GetSpawnScript(spawn_id);
- bool scriptActive = false;
- if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
- scriptActive = true;
- spawn->SetSpawnScript(string(spawn_script));
- }
- zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
- zone->AddSpawn(spawn);
- if (scriptActive) {
- zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- }
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- }
- else {
- string output = "Invalid paramaters to LUA Spawn command: \n";
- if (!zone)
- output = output.append("\t").append("Missing zone reference. \n");
- if (spawn_id == 0)
- output = output.append("\t").append("Missing spawn_id.");
- lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_GetZoneName(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetStringValue(state, zone->GetZoneName());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetZoneID(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetZoneID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetZone(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 zone_id = lua_interface->GetInt32Value(state);
- ZoneServer* zone = 0;
- if (zone_id > 0)
- zone = zone_list.Get(zone_id, true, false, false);
- else {
- string zone_name = lua_interface->GetStringValue(state);
- if (zone_name.length() > 0) {
- zone = zone_list.Get(zone_name.c_str(), true, false, false);
- }
- else {
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn)
- zone = spawn->GetZone();
- }
- }
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetZoneValue(state, zone);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_AddHate(lua_State* state) {
- Spawn* entity = lua_interface->GetSpawn(state);
- Spawn* npc = lua_interface->GetSpawn(state, 2);
- sint32 amount = lua_interface->GetSInt32Value(state, 3);
- bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
-
- if(luaspell && luaspell->resisted) {
- return 0;
- }
-
- if (entity && entity->IsEntity() && amount != 0) {
- if (luaspell && luaspell->caster) {
- ZoneServer* zone = luaspell->caster->GetZone();
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
- if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
- entity->CheckEncounterState((Entity*)spawn);
- ((NPC*)spawn)->AddHate((Entity*)entity, amount);
- if (send_packet)
- entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (npc && npc->IsNPC() && npc->GetZone()) {
- entity->CheckEncounterState((Entity*)npc);
- ((NPC*)npc)->AddHate((Entity*)entity, amount);
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_Zone(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- float x = lua_interface->GetFloatValue(state, 3);
- float y = lua_interface->GetFloatValue(state, 4);
- float z = lua_interface->GetFloatValue(state, 5);
- float heading = lua_interface->GetFloatValue(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (zone && client) {
- LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
- LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
- if (!client->CheckZoneAccess(zone->GetZoneName()))
- {
- LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
- return 0;
- }
- if (x != 0 || y != 0 || z != 0) {
- LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
- player->SetX(x);
- player->SetY(y);
- player->SetZ(z);
- player->SetHeading(heading);
- client->Zone(zone->GetZoneName(), false);
- }
- else
- client->Zone(zone->GetZoneName());
- }
- else
- lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if (spawn && spawn2)
- spawn->AddAllowAccessSpawn(spawn2);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_CastSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target = lua_interface->GetSpawn(state);
- int32 spell_id = lua_interface->GetInt32Value(state, 2);
- int8 spell_tier = lua_interface->GetInt8Value(state, 3);
- Spawn* caster = lua_interface->GetSpawn(state, 4);
- int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (!target) {
- lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
- return 0;
- }
- if (spell_id <= 0) {
- lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (caster && !caster->IsEntity()) {
- lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
- return 0;
- }
- if (spell_tier == 0)
- spell_tier = 1;
- if (!caster)
- caster = target;
- target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
- return 0;
- }
- int EQ2Emu_lua_SpellDamage(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if(!luaspell || luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- Spawn* caster = luaspell->caster;
- sint32 type = lua_interface->GetSInt32Value(state, 2);
- int32 min_damage = lua_interface->GetInt32Value(state, 3);
- int32 max_damage = lua_interface->GetInt32Value(state, 4);
- int8 crit_mod = lua_interface->GetInt32Value(state, 5);
- bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
- //lua_interface->ResetFunctionStack(state);
- int32 class_id = lua_interface->GetInt32Value(state, 7);
- vector<int16> faction_req;
- vector<int16> race_req;
- int32 class_req = 0;
- int32 i = 0;
- int8 f = 0;
- int8 r = 0;
- while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
- if (class_id < 100) {
- class_req += pow(2.0, double(class_id - 1));
- }
- else if (class_id > 100 && class_id < 1000) {
- race_req.push_back(class_id);
- r++;
- }
- else {
- faction_req.push_back(class_id);
- f++;
- }
- i++;
- }
- lua_interface->ResetFunctionStack(state);
- if (caster && caster->IsEntity()) {
- bool race_match = false;
- bool success = false;
- luaspell->resisted = false;
- if (luaspell->targets.size() > 0) {
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
- if (race_req.size() > 0) {
- for (int8 i = 0; i < race_req.size(); i++) {
- if(race_req[i] == target->GetRace() ||
- race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
- race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
- race_match = true;
- }
- }
- }
- else
- race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
- if (race_match == true) {
- float distance = caster->GetDistance(target, true);
- ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
- }
- }
- }
- success = true;
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (target) {
- //check class and race/faction here
- if (race_req.size() > 0) {
- for (int8 i = 0; i < race_req.size(); i++) {
- if(race_req[i] == target->GetRace() ||
- race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
- race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
- race_match = true;
- }
- }
- }
- else
- race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
- if (race_match == true) {
- float distance = caster->GetDistance(target, true);
- if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
- success = true;
- }
- }
- lua_interface->SetBooleanValue(state, luaspell->has_damaged);
- if (success) {
- Spell* spell = luaspell->spell;
- if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
- ((Player*)caster)->InCombat(true);
- if (caster->GetZone())
- caster->GetZone()->TriggerCharSheetTimer();
- }
- }
- }
- else {
- lua_interface->SetBooleanValue(state, false);
- }
- return 1;
- }
- int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if(!luaspell || luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- Spawn* caster = luaspell->caster;
- sint32 type = lua_interface->GetSInt32Value(state, 2);
- int32 min_damage = lua_interface->GetInt32Value(state, 3);
- int32 max_damage = lua_interface->GetInt32Value(state, 4);
- int8 crit_mod = lua_interface->GetInt32Value(state, 5);
- bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
- int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
- bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
- //lua_interface->ResetFunctionStack(state);
- int32 class_id = lua_interface->GetInt32Value(state, 9);
- vector<int16> faction_req;
- vector<int16> race_req;
- int32 class_req = 0;
- int32 i = 0;
- int8 f = 0;
- int8 r = 0;
- while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
- if (class_id < 100) {
- class_req += pow(2.0, double(class_id - 1));
- }
- else if (class_id > 100 && class_id < 1000) {
- race_req.push_back(class_id);
- r++;
- }
- else {
- faction_req.push_back(class_id);
- f++;
- }
- i++;
- }
- lua_interface->ResetFunctionStack(state);
- if (caster && caster->IsEntity()) {
- bool race_match = false;
- bool success = false;
- luaspell->resisted = false;
- if (luaspell->targets.size() > 0) {
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
- if (race_req.size() > 0) {
- for (int8 i = 0; i < race_req.size(); i++) {
- if(race_req[i] == target->GetRace() ||
- race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
- race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
- race_match = true;
- }
- }
- }
- else
- race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
- if (race_match == true) {
- float distance = caster->GetDistance(target, true);
- ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
- }
- }
- }
- success = true;
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (target) {
- //check class and race/faction here
- if (race_req.size() > 0) {
- for (int8 i = 0; i < race_req.size(); i++) {
- if(race_req[i] == target->GetRace() ||
- race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
- race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
- race_match = true;
- }
- }
- }
- else
- race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
- if (race_match == true) {
- float distance = caster->GetDistance(target, true);
- if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
- success = true;
- }
- }
- lua_interface->SetBooleanValue(state, luaspell->has_damaged);
- if (success) {
- Spell* spell = luaspell->spell;
- if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
- ((Player*)caster)->InCombat(true);
- if (caster->GetZone())
- caster->GetZone()->TriggerCharSheetTimer();
- }
- }
- }
- else {
- lua_interface->SetBooleanValue(state, false);
- }
- return 1;
- }
- int EQ2Emu_lua_ModifyPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && value != 0) {
- if (spawn->GetPower() + value > spawn->GetTotalPower())
- spawn->SetPower(spawn->GetTotalPower());
- else
- spawn->SetPower(spawn->GetPower() + value);
- }
- return 0;
- }
- int EQ2Emu_lua_ModifyHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && value != 0) {
- if (spawn->GetHP() + value > spawn->GetTotalHP())
- spawn->SetHP(spawn->GetTotalHP());
- else
- spawn->SetHP(spawn->GetHP() + value);
- }
- return 0;
- }
- int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && value != 0) {
- spawn->SetTotalPower(value);
- spawn->SetTotalPowerBaseInstance(value);
- }
- return 0;
- }
- int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && value != 0) {
- spawn->SetTotalHP(value);
- spawn->SetTotalHPBaseInstance(value);
- }
- return 0;
- }
- int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetHP(value);
- if (value > spawn->GetTotalHPBase())
- spawn->SetTotalHP(value);
- }
- return 0;
- }
- int EQ2Emu_lua_SetMaxHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && value > 0)
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
- if (spawn && spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- return 0;
- }
- int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && value > 0)
- ((Entity*)spawn)->SetTotalHPBase(value);
- return 0;
- }
- int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && value > 0) {
- spawn->SetPower(value);
- if (value > spawn->GetTotalPowerBase())
- spawn->SetTotalPower(value);
- }
- return 0;
- }
- int EQ2Emu_lua_SetMaxPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && value > 0)
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
- return 0;
- }
- int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && value > 0)
- ((Entity*)spawn)->SetTotalPowerBase(value);
- return 0;
- }
- int EQ2Emu_lua_SetPosition(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float x = lua_interface->GetFloatValue(state, 2);
- float y = lua_interface->GetFloatValue(state, 3);
- float z = lua_interface->GetFloatValue(state, 4);
- float heading = lua_interface->GetFloatValue(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetX(x);
- spawn->SetY(y);
- spawn->SetZ(z);
- if (heading != 0)
- spawn->SetHeading(heading);
- spawn->SetSpawnOrigX(spawn->GetX());
- spawn->SetSpawnOrigY(spawn->GetY());
- spawn->SetSpawnOrigZ(spawn->GetZ());
- spawn->SetSpawnOrigHeading(spawn->GetHeading());
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
- client->QueuePacket(packet);
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetHeading(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float value = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetHeading(value);
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
- client->QueuePacket(packet);
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetModelType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn)
- spawn->SetModelType(value);
- return 0;
- }
- int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 value = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetPlayerAdventureClass(value);
- else
- spawn->SetAdventureClass(value);
- }
- return 0;
- }
- int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 value = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetTradeskillClass(value);
- if (spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
- ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
- ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
- }
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetMount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->SetMount(value);
- EQ2_Color color;
- color.red = 255;
- color.green = 255;
- color.blue = 255;
- ((Entity*)spawn)->SetMountColor(&color);
- ((Entity*)spawn)->SetMountSaddleColor(&color);
- }
- return 0;
- }
- int EQ2Emu_lua_SetMountColor(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- EQ2_Color mount_color;
- EQ2_Color saddle_color;
- mount_color.red = lua_interface->GetInt8Value(state, 2);
- mount_color.green = lua_interface->GetInt8Value(state, 3);
- mount_color.blue = lua_interface->GetInt8Value(state, 4);
- saddle_color.red = lua_interface->GetInt8Value(state, 5);
- saddle_color.green = lua_interface->GetInt8Value(state, 6);
- saddle_color.blue = lua_interface->GetInt8Value(state, 7);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->SetMountColor(&mount_color);
- ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
- }
- return 0;
- }
- int EQ2Emu_lua_GetMount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetRace(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn)
- {
- LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
- lua_interface->SetInt32Value(state, spawn->GetRace());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetRaceName(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetClass(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetClassName(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetSpeed(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float value = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetSpeed(value);
-
- if(spawn->IsEntity())
- ((Entity*)spawn)->SetSpeed(value);
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", 0xFFFFFFFF);
- packet->setDataByName("speed", value);
- packet->setDataByName("size", 0.51);
- EQ2Packet* app = packet->serialize();
- client->QueuePacket(app);
- safe_delete(packet);
- }
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- const int16 type = lua_interface->GetInt16Value(state, 2);
- const float value = lua_interface->GetFloatValue(state, 3);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!luaspell || luaspell->resisted) {
- return 0;
- }
- int64 class_req = 0;
- int32 class_id = 0;
- vector<int16> faction_req;
- vector<int16> race_req;
- int32 i = 0;
- int8 f = 0;
- int8 r = 0;
- while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
- if (class_id < 100) {
- class_req += pow(2.0, double(class_id - 1));
- }
- else if (class_id > 100 && class_id < 1000) {
- race_req.push_back(class_id);
- r++;
- }
- else {
- faction_req.push_back(class_id);
- f++;
- }
- i++;
- }
- if (value != 0 && type >= 0) {
- if (luaspell && luaspell->spell && luaspell->caster) {
- ZoneServer* zone = luaspell->caster->GetZone();
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target) {
- if (target->IsPlayer()) {
- ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
- LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
- if (((Player*)target)->GetGroupMemberInfo())
- ((Player*)target)->UpdateGroupMemberInfo();
- ((Player*)target)->SetCharSheetChanged(true);
- }
- else if (target->IsNPC())
- ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
- else
- lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
- luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
- }
- else if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
- LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- else
- lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
- }
- else
- lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 type = lua_interface->GetInt16Value(state, 2);
- sint32 value = lua_interface->GetSInt32Value(state, 3);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (value == 0) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!luaspell || !luaspell->spell) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
- int32 class_req = 0;
- vector<int16> faction_req;
- vector<int16> race_req;
- int32 class_id = 0;
- int32 i = 0;
- int8 f = 0;
- int8 r = 0;
- while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
- if (class_id < 100) {
- class_req += pow(2.0, double(class_id - 1));
- }
- else if (class_id > 100 && class_id < 1000) {
- race_req.push_back(class_id);
- r++;
- }
- else {
- faction_req.push_back(class_id);
- f++;
- }
- i++;
- }
- ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
- luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- return 0;
- }
- int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
-
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!luaspell || !luaspell->spell) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ((Entity*)spawn)->RemoveSpellBonus(luaspell);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
-
- return 0;
- }
- int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (luaspell && luaspell->spell) {
- ZoneServer* zone = nullptr;
- if (luaspell->caster != nullptr)
- zone = luaspell->caster->GetZone();
- if(!zone && spawn) {
- zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
- }
- Spawn* target = 0;
- if(zone) {
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target && target->IsEntity()) {
- ((Entity*)target)->RemoveSpellBonus(luaspell);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else {
- LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn->GetName());
- }
- }
- else if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->RemoveSpellBonus(luaspell);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 skill_id = lua_interface->GetInt32Value(state, 2);
- float value = lua_interface->GetFloatValue(state, 3);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if (value != 0) {
- int32 spell_id = 0;
- if (luaspell && luaspell->spell && luaspell->caster) {
- if(luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- spell_id = luaspell->spell->GetSpellID();
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target && target->Alive()) {
- if (target->IsPlayer()) {
- ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
- Client* client = ((Player*)target)->GetClient();
- if (client) {
- EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
- luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
- }
- else if (target->IsNPC()) {
- ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
- luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
- }
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (spawn) {
- if (spawn->IsPlayer()) {
- ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- else if (spawn->IsNPC())
- ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
- }
- }
- else
- lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- int32 spell_id = 0;
- if (luaspell && luaspell->spell && luaspell->caster) {
- if(luaspell->resisted) {
- return 0;
- }
- spell_id = luaspell->spell->GetSpellID();
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target) {
- if (target->IsPlayer()) {
- ((Player*)target)->RemoveSkillBonus(spell_id);
- Client* client = ((Player*)target)->GetClient();
- if (client) {
- EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- else if (target->IsNPC())
- ((NPC*)target)->RemoveSkillBonus(spell_id);
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (spawn) {
- if (spawn->IsPlayer()) {
- ((Player*)spawn)->RemoveSkillBonus(spell_id);
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- else if (spawn->IsNPC())
- ((NPC*)spawn)->RemoveSkillBonus(spell_id);
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
- }
- return 0;
- }
- int EQ2Emu_lua_AddControlEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt32Value(state, 2);
- bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!luaspell || luaspell->resisted) {
- return 0;
- }
-
- if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target && target->IsEntity()) {
- if (type == CONTROL_EFFECT_TYPE_MEZ) {
- ((Entity*)target)->AddMezSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
- luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
- ((Entity*)target)->AddStifleSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
- luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_DAZE) {
- ((Entity*)target)->AddDazeSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
- luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_STUN) {
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
- luaspell->effect_bitmask += EFFECT_FLAG_STUN;
- ((Entity*)target)->AddStunSpell(luaspell);
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_ROOT) {
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
- luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
- ((Entity*)target)->AddRootSpell(luaspell);
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_FEAR) {
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
- luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
- ((Entity*)target)->AddFearSpell(luaspell);
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
- ((Entity*)target)->AddWaterwalkSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
- luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
- }
- else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
- ((Entity*)target)->AddWaterjumpSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
- luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
- }
- else if (type == CONTROL_EFFECT_TYPE_SNARE) {
- ((Entity*)target)->AddSnareSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
- luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
- ((Entity*)target)->AddFlightSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
- luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
- }
- else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
- ((Entity*)target)->AddGlideSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
- luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
- }
- else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
- ((Entity*)target)->AddSafefallSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
- luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
- }
- else
- lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
- }
- else
- lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (only_add_spawn && spawn && spawn->IsEntity()) {
- if (type == CONTROL_EFFECT_TYPE_MEZ) {
- ((Entity*)spawn)->AddMezSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
- luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
- }
- else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
- ((Entity*)spawn)->AddStifleSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
- luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
- }
- else if (type == CONTROL_EFFECT_TYPE_DAZE) {
- ((Entity*)spawn)->AddDazeSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
- luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
- }
- else if (type == CONTROL_EFFECT_TYPE_STUN) {
- ((Entity*)spawn)->AddStunSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
- luaspell->effect_bitmask += EFFECT_FLAG_STUN;
- }
- else if (type == CONTROL_EFFECT_TYPE_ROOT) {
- ((Entity*)spawn)->AddRootSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
- luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
- }
- else if (type == CONTROL_EFFECT_TYPE_FEAR) {
- ((Entity*)spawn)->AddFearSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
- luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
- }
- else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
- ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
- luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
- }
- else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
- ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
- luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
- }
- else if (type == CONTROL_EFFECT_TYPE_SNARE) {
- ((Entity*)spawn)->AddSnareSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
- luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
- }
- else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
- ((Entity*)spawn)->AddFlightSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
- luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
- }
- else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
- ((Entity*)spawn)->AddGlideSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
- luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
- }
- else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
- ((Entity*)spawn)->AddSafefallSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
- luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
- }
- else
- lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
- }
- else
- lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
- return 0;
- }
- int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target) {
- if (type == CONTROL_EFFECT_TYPE_MEZ)
- ((Entity*)target)->RemoveMezSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_STIFLE)
- ((Entity*)target)->RemoveStifleSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_DAZE)
- ((Entity*)target)->RemoveDazeSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_STUN)
- ((Entity*)target)->RemoveStunSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_ROOT)
- ((Entity*)target)->RemoveRootSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_FEAR)
- ((Entity*)target)->RemoveFearSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
- ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
- ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_SNARE)
- ((Entity*)target)->RemoveSnareSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
- ((Entity*)target)->RemoveFlightSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_GLIDE)
- ((Entity*)target)->RemoveGlideSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
- ((Entity*)target)->RemoveGlideSpell(luaspell);
- else
- lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (only_remove_spawn) {
- if (type == CONTROL_EFFECT_TYPE_MEZ)
- ((Entity*)spawn)->RemoveMezSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_STIFLE)
- ((Entity*)spawn)->RemoveStifleSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_DAZE)
- ((Entity*)spawn)->RemoveDazeSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_STUN)
- ((Entity*)spawn)->RemoveStunSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_ROOT)
- ((Entity*)spawn)->RemoveRootSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_FEAR)
- ((Entity*)spawn)->RemoveFearSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
- ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
- ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_SNARE)
- ((Entity*)spawn)->RemoveSnareSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
- ((Entity*)spawn)->RemoveFlightSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_GLIDE)
- ((Entity*)spawn)->RemoveGlideSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
- ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
- else
- lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HasControlEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- bool hasEffect = false;
- if (!spawn)
- lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsEntity())
- lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
- else if (type < CONTROL_MAX_EFFECTS)
- hasEffect = ((Entity*)spawn)->HasControlEffect(type);
- else
- lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
- lua_interface->SetBooleanValue(state, hasEffect);
- return 1;
- }
- int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float distance = 0.0f;
- lua_interface->ResetFunctionStack(state);
-
- if (!spawn)
- lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsNPC())
- lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
- else
- distance = ((NPC*)spawn)->GetBaseAggroRadius();
- lua_interface->SetFloatValue(state, distance);
- return 1;
- }
- int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float distance = 0.0f;
-
- lua_interface->ResetFunctionStack(state);
- if (!spawn)
- lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsNPC())
- lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
- else
- distance = ((NPC*)spawn)->GetAggroRadius();
- lua_interface->SetFloatValue(state, distance);
- return 1;
- }
- int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float distance = lua_interface->GetFloatValue(state, 2);
- bool override_ = lua_interface->GetBooleanValue(state, 3);
- bool result = false;
- lua_interface->ResetFunctionStack(state);
- if (!spawn)
- lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsNPC())
- lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
- else
- {
- ((NPC*)spawn)->SetAggroRadius(distance, override_);
- result = true;
- }
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_SetIntBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetAgiBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetWisBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetStaBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetStrBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetDeity(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 value = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->SetDeity(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_GetDeity(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- int8 deity = ((Entity*)spawn)->GetDeity();
- lua_interface->SetInt32Value(state, deity);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetWis(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- Spawn* spawn = lua_interface->GetSpawn(state);
- float value = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetSta(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float value = lua_interface->GetFloatValue(state, 2);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetStr(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- float value = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetAgi(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- float value = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetHP());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetMaxHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTotalHP());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetName(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetStringValue(state, spawn->GetName());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetLevel(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetLevel());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetDifficulty(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetDifficulty());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetPower());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetMaxPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTotalPower());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetDistance(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
- bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn2) {
- float distance = spawn->GetDistance(spawn2, false, include_radius);
- lua_interface->SetFloatValue(state, distance);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetX(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetX());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetY(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetY());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetZ(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetZ());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetHeading(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetHeading());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetModelType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetModelType());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpeed(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetSpeed());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_HasMoved(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetWis(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSta(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetStr(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetAgi(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetIntBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetWisBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetStaBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetStrBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetAgiBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetStepComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int32 step = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player || !player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (quest_id <= 0) {
- lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
- return 0;
- } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
- lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step > 0) {
- Client* client = ((Player*)player)->GetClient();
- if (client)
- client->AddPendingQuestUpdate(quest_id, step);
- } else {
- lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_AddStepProgress(lua_State* state) {
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int32 step = lua_interface->GetInt32Value(state, 3);
- int32 progress = lua_interface->GetInt32Value(state, 4);
- if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
- Client* client = ((Player*)player)->GetClient();
- if (client)
- client->AddPendingQuestUpdate(quest_id, step, progress);
- }
- return 0;
- }
- int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- if (player && player->IsPlayer() && quest_id > 0) {
- lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int32 step_id = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && quest_id > 0) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetQuestStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && quest_id > 0) {
- lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_RegisterQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- string name = lua_interface->GetStringValue(state, 2);
- string type = lua_interface->GetStringValue(state, 3);
- string zone = lua_interface->GetStringValue(state, 4);
- int16 level = lua_interface->GetInt16Value(state, 5);
- string description = lua_interface->GetStringValue(state, 6);
- lua_interface->ResetFunctionStack(state);
- bool load = true;
- if (!quest) {
- lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
- load = false;
- }
- if (load && name.length() == 0) {
- lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
- load = false;
- }
- if (load && type.length() == 0) {
- lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
- load = false;
- }
- if (load && zone.length() == 0) {
- lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
- load = false;
- }
- if (load && description.length() == 0) {
- lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
- load = false;
- }
- if (load && level == 0) {
- lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
- load = false;
- }
- if (load)
- quest->RegisterQuest(name, type, zone, level, description);
- return 0;
- }
- int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int8 level = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetPrereqLevel(level);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddPrereqQuest(quest_id);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int8 quantity = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (quantity == 0)
- quantity = 1;
- Item* master_item = master_item_list.GetItem(item_id);
- if (master_item) {
- Item* item = new Item(master_item);
- item->details.count = quantity;
- quest->AddPrereqItem(item);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HasQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if(!player || !player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (quest_id > 0) {
- lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) == TRUE));
- return 1;
- } else {
- lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest && spawn_id > 0)
- quest->SetQuestReturnNPC(spawn_id);
- return 0;
- }
- int EQ2Emu_lua_AddTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 time = lua_interface->GetInt32Value(state, 2);
- string function = lua_interface->GetStringValue(state, 3);
- int32 max_count = lua_interface->GetInt32Value(state, 4);
- Spawn* player = lua_interface->GetSpawn(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (time <= 0) {
- lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
- return 0;
- }
- if (function.length() == 0) {
- lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
- return 0;
- }
- SpawnScriptTimer* timer = new SpawnScriptTimer;
- if ( time < 10)
- time = 10;
-
- timer->timer = Timer::GetCurrentTime2() + time;
- timer->function = function;
- timer->spawn = spawn->GetID();
- timer->player = player ? player->GetID() : 0;
- if (max_count == 0)
- max_count = 1;
- timer->max_count = max_count;
- timer->current_count = 0;
- spawn->GetZone()->AddSpawnScriptTimer(timer);
- return 0;
- }
- int EQ2Emu_lua_StopTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string function = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if(!spawn->GetZone()) {
- lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
- return 0;
- }
- int EQ2Emu_lua_GetQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && quest_id > 0) {
- lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
- Quest* quest = ((Player*)player)->player_quests[quest_id];
- if (quest)
- lua_interface->SetBooleanValue(state, quest->GetCompleted());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && quest_id > 0) {
- lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* npc = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (npc && !npc->IsPlayer() && quest_id > 0)
- npc->AddProvidedQuest(quest_id);
- return 0;
- }
- int EQ2Emu_lua_OfferQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* npc = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- int32 quest_id = lua_interface->GetInt32Value(state, 3);
- bool forced = lua_interface->GetBooleanValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- /* NPC is allowed to be null */
- if (player && player->IsPlayer() && quest_id > 0) {
- Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
- if (master_quest) {
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
- }
- Quest* quest = new Quest(master_quest);
- if (!quest) {
- lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
- }
- if (client && quest) {
- if (npc)
- quest->SetQuestGiver(npc->GetDatabaseID());
- else
- quest->SetQuestGiver(0);
- client->AddPendingQuest(quest, forced);
- }
- }
- else {
- lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
- }
- }
- else {
- 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);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int8 class_id = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddPrereqClass(class_id);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int8 race = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddPrereqRace(race);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int16 model_type = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddPrereqModelType(model_type);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int8 level = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetPrereqTSLevel(level);
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int8 class_id = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->AddPrereqTradeskillClass(class_id);
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 faction_id = lua_interface->GetInt32Value(state, 2);
- sint32 min = lua_interface->GetSInt32Value(state, 3);
- sint32 max = lua_interface->GetSInt32Value(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddPrereqFaction(faction_id, min, max);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int8 quantity = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (quantity == 0)
- quantity = 1;
- Item* master_item = master_item_list.GetItem(item_id);
- if (master_item) {
- Item* item = new Item(master_item);
- item->details.count = quantity;
- quest->AddSelectableRewardItem(item);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- if (quest) {
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- vector<Item*>* items = quest->GetRewardItems();
- if (items) {
- vector<Item*>::iterator itr;
- for (itr = items->begin(); itr != items->end(); itr++) {
- if (*itr && (*itr)->details.item_id == item_id) {
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int8 quantity = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (quantity == 0)
- quantity = 1;
- Item* master_item = master_item_list.GetItem(item_id);
- if (master_item) {
- Item* item = new Item(master_item);
- item->details.count = quantity;
- quest->AddRewardItem(item);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 copper = lua_interface->GetInt32Value(state, 2);
- int32 silver = lua_interface->GetInt32Value(state, 3);
- int32 gold = lua_interface->GetInt32Value(state, 4);
- int32 plat = lua_interface->GetInt32Value(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddRewardCoins(copper, silver, gold, plat);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 faction_id = lua_interface->GetInt32Value(state, 2);
- sint32 amount = lua_interface->GetSInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest && faction_id > 0 && amount != 0)
- quest->AddRewardFaction(faction_id, amount);
- return 0;
- }
- int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 status = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetRewardStatus(status);
- }
- return 0;
- }
- int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 status = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetStatusTmpReward(status);
- }
- return 0;
- }
- int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int64 coins = lua_interface->GetInt64Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetCoinTmpReward(coins);
- }
- return 0;
- }
- int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- string comment = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetRewardComment(comment);
- }
- return 0;
- }
- int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 exp = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetRewardXP(exp);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestStep(lua_State* state) {
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- int32 usableitemid = lua_interface->GetInt32Value(state, 8);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
-
-
- int32 id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
- if (quest_step && icon && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
- {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
-
- int32 id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
- if (quest_step && icon > 0 && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
- return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
- }
- int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
- return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
- }
- int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- string str_taskgroup = lua_interface->GetStringValue(state, 5);
- int16 icon = lua_interface->GetInt16Value(state, 6);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- int32 npc_id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(npc_id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
- if (quest_step && icon > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- if(client)
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- int32 item_id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(item_id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
- if (quest_step && icon > 0 && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- float max_variation = lua_interface->GetFloatValue(state, 4);
- string str_taskgroup = lua_interface->GetStringValue(state, 5);
- int16 icon = lua_interface->GetInt16Value(state, 6);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- vector<Location>* locations = 0;
- int8 i = 7;
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- while (true) {
- Location loc;
- loc.x = lua_interface->GetFloatValue(state, i);
- loc.y = lua_interface->GetFloatValue(state, i + 1);
- loc.z = lua_interface->GetFloatValue(state, i + 2);
- loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
- if (loc.x == 0 && loc.y == 0 && loc.z == 0)
- break;
- if (locations == 0)
- locations = new vector<Location>;
- locations->push_back(loc);
- i += 4;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
- safe_delete(locations); // gets duplicated into new table in QuestStep constructor
- if (quest_step && icon > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- float max_variation = lua_interface->GetFloatValue(state, 4);
- string str_taskgroup = lua_interface->GetStringValue(state, 5);
- int16 icon = lua_interface->GetInt16Value(state, 6);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- vector<Location>* locations = 0;
- int8 i = 7;
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- while (true) {
- Location loc;
- loc.x = lua_interface->GetFloatValue(state, i);
- loc.y = lua_interface->GetFloatValue(state, i + 1);
- loc.z = lua_interface->GetFloatValue(state, i + 2);
- loc.zone_id = 0;
-
- if (loc.x == 0 && loc.y == 0 && loc.z == 0)
- break;
- if (locations == 0)
- locations = new vector<Location>;
- locations->push_back(loc);
- i += 3;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
- safe_delete(locations); // gets duplicated into new table in QuestStep constructor
- if (quest_step && icon > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- float max_variation = lua_interface->GetFloatValue(state, 4);
- string str_taskgroup = lua_interface->GetStringValue(state, 5);
- int16 icon = lua_interface->GetInt16Value(state, 6);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- vector<Location>* locations = 0;
- int i = 7;
- while (true) {
- Location loc;
- loc.x = lua_interface->GetFloatValue(state, i);
- loc.y = lua_interface->GetFloatValue(state, i + 1);
- loc.z = lua_interface->GetFloatValue(state, i + 2);
- if (loc.x == 0 && loc.y == 0 && loc.z == 0)
- break;
- if (locations == 0)
- locations = new vector<Location>;
- locations->push_back(loc);
- i += 3;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
- safe_delete(locations); // gets duplicated into new table in QuestStep constructor
- if (quest_step && icon > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- int32 spell_id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(spell_id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
- if (quest_step && icon > 0 && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- int32 item_id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(item_id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
- if (quest_step && icon > 0 && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- int32 item_id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(item_id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
- if (quest_step && icon > 0 && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- string action = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (action.length() > 0)
- quest->SetCompleteAction(action);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string action = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (step > 0 && action.length() > 0)
- quest->AddCompleteAction(step, action);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string action = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (step > 0 && action.length() > 0)
- quest->AddProgressAction(step, action);
- }
- return 0;
- }
- int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- string description = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest && description.length() > 0)
- quest->SetDescription(description);
- return 0;
- }
- int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- string description = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest && description.length() > 0)
- quest->SetCompletedDescription(description);
- return 0;
- }
- int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
- lua_interface->ResetFunctionStack(state);
- if (quest && step > 0 && description.length() > 0) {
- quest->SetTaskGroupDescription(step, description, display_bullets);
- }
- return 0;
- }
- int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest && step > 0 && description.length() > 0) {
- quest->SetStepDescription(step, description);
- }
- return 0;
- }
- int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
- Quest* quest = lua_interface->GetQuest(state);
- string zone = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest && zone.length() > 0)
- quest->SetZone(zone);
- return 0;
- }
- int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest && spawn) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- client->AddPendingQuestReward(quest);
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_Harvest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- Spawn* node = lua_interface->GetSpawn(state, 2);
- if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
- Client* client = ((Player*)player)->GetClient();
- if (client) {
- ((GroundSpawn*)node)->ProcessHarvest(client);
- if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
- }
- }
- }
- else if (player && player->IsPlayer()) {
- Client* client = ((Player*)player)->GetClient();
- if (client)
- client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_Bind(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 zone_id = lua_interface->GetInt32Value(state, 2);
- float x = lua_interface->GetFloatValue(state, 3);
- float y = lua_interface->GetFloatValue(state, 4);
- float z = lua_interface->GetFloatValue(state, 5);
- float h = lua_interface->GetFloatValue(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (zone_id == 0) {
- Client* client = ((Player*)spawn)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!client->Bind())
- client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
- }
- else {
- Player* player = (Player*)spawn;
- player->GetPlayerInfo()->SetBindZone(zone_id);
- player->GetPlayerInfo()->SetBindX(x);
- player->GetPlayerInfo()->SetBindY(y);
- player->GetPlayerInfo()->SetBindZ(z);
- player->GetPlayerInfo()->SetBindHeading(h);
- }
- return 0;
- }
- int EQ2Emu_lua_Gate(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- if (!client->Gate((spell != nullptr) ? true : false))
- client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
- if (!lua_interface)
- return 0;
- bool ret = false;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- ret = client->BindAllowed();
- }
- }
- lua_interface->SetBooleanValue(state, ret);
- return 1;
- }
- int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
- if (!lua_interface)
- return 0;
- bool ret = false;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- ZoneServer* zone = lua_interface->GetZone(state);
- if (client && zone){
- ret = zone->GetCanGate();
- }
- }
- }
- lua_interface->SetBooleanValue(state, ret);
- return 1;
- }
- int EQ2Emu_lua_IsAlive(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->Alive());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_IsSpawnGroupAlive(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 group_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetBooleanValue(state, zone->IsSpawnGroupAlive(group_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_IsInCombat(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SendMessage(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- string color_str = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- int8 color = CHANNEL_NARRATIVE;
- if (spawn && spawn->IsPlayer() && message.length() > 0) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- if (color_str.length() > 0) {
- // leave for backwards compat, but all future should just use the number
- if (strncasecmp(color_str.c_str(), "red", 3) == 0)
- color = CHANNEL_COLOR_RED;
- else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
- color = CHANNEL_COLOR_YELLOW;
- else
- {
- // use a number to specify the channel as per Commands/Commands.h defines
- color = (int8)atoul(color_str.c_str());
- }
- }
- client->SimpleMessage(color, message.c_str());
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- int8 red = lua_interface->GetInt8Value(state, 3);
- int8 green = lua_interface->GetInt8Value(state, 4);
- int8 blue = lua_interface->GetInt8Value(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 words = ::CountWordsInString(message.c_str());
- if (words < 5)
- words = 5;
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
- return 0;
- }
- int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 param = lua_interface->GetInt8Value(state, 2);
- int8 param_value = lua_interface->GetInt8Value(state, 3);
- int8 value = lua_interface->GetInt8Value(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
- switch (param) {
- case 1: {
- packet->setDataByName("parameter1", param_value);
- break;
- }
- case 2: {
- packet->setDataByName("parameter2", param_value);
- break;
- }
- case 3: {
- packet->setDataByName("parameter3", param_value);
- break;
- }
- case 4: {
- packet->setDataByName("parameter4", param_value);
- break;
- }
- case 5: {
- packet->setDataByName("parameter5", param_value);
- break;
- }
- }
- packet->setDataByName("value", value);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_ToggleTracking(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsPlayer()) {
- if (((Player*)spawn)->GetIsTracking())
- spawn->GetZone()->AddPlayerTracking((Player*)spawn);
- else
- spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
- }
- return 0;
- }
- int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
- Spawn* player = lua_interface->GetSpawn(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- string name = lua_interface->GetStringValue(state, 3);
- float distance = lua_interface->GetFloatValue(state, 4);
- string command = lua_interface->GetStringValue(state, 5);
- string error_text = lua_interface->GetStringValue(state, 6);
- int16 cast_time = lua_interface->GetInt16Value(state, 7);
- int32 spell_visual = lua_interface->GetInt32Value(state, 8);
- bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (distance == 0)
- distance = 10.0f;
- if (command.length() == 0)
- command = name;
- if (command.length() < 1 && name.length() < 1)
- {
- // have to run this first to send a 'blank' default command, then remove all commands from the list
- spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
- spawn->RemovePrimaryCommands();
- }
- else
- {
- spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HasSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 spellid = lua_interface->GetInt32Value(state, 2);
- int16 tier = lua_interface->GetInt16Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 spellid = lua_interface->GetInt32Value(state, 2);
- int16 tier = lua_interface->GetInt16Value(state, 3);
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- bool add_silently = lua_interface->GetBooleanValue(state, 4);
- bool add_to_hotbar = true;
- if (num_args > 4) {
- add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
- }
- lua_interface->ResetFunctionStack(state);
- Spell* spell = master_spell_list.GetSpell(spellid, tier);
- if (player && spell && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client) {
- if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
- {
- Spell* spell = master_spell_list.GetSpell(spellid, tier);
- client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
- client->GetPlayer()->UnlockSpell(spell);
- client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
- }
- else
- {
- Spell* spell = master_spell_list.GetSpell(spellid, tier);
- int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
- client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
- client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
- client->GetPlayer()->UnlockSpell(spell);
- client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
- }
- //if (client ) {
- // ((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);
- EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
- if (outapp)
- client->QueuePacket(outapp);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int8 type_selection = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client) {
- ((Player*)player)->DeleteSpellBook(type_selection);
- EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
- if (outapp)
- client->QueuePacket(outapp);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client) {
- client->SendNewAdventureSpells();
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client) {
- client->SendNewTradeskillSpells();
- }
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 spellid = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
- Client* client = player->GetClient();
- if (sbe && client) {
- ((Player*)player)->RemoveSpellBookEntry(spellid);
- EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
- if (outapp)
- client->QueuePacket(outapp);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_Attack(lua_State* state) {
- if (lua_interface) {
- Spawn* npc = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (npc && player && npc->IsNPC() && player->IsEntity())
- ((NPC*)npc)->AddHate((Entity*)player, 100);
- }
- return 0;
- }
- int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
- if (lua_interface) {
- Spawn* target = lua_interface->GetSpawn(state);
- int32 spell_visual = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (target && target->GetZone())
- target->GetZone()->SendCastSpellPacket(spell_visual, target);
- }
- return 0;
- }
- int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
- Spawn* player;
- if (lua_interface) {
- player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HandInCollections(lua_State* state) {
- Spawn* player;
- Client* client;
- if (lua_interface) {
- player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
- if ((client = ((Player*)player)->GetClient()))
- client->HandInCollections();
- }
- return 0;
- }
- int EQ2Emu_lua_UseWidget(lua_State* state) {
- Spawn* widget;
- if (lua_interface) {
- widget = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (widget && widget->IsWidget())
- ((Widget*)widget)->HandleUse(nullptr, "");
- }
- return 0;
- }
- int EQ2Emu_lua_SetSpellList(lua_State* state) {
- Spawn* spawn = 0;
- int32 primary_list = 0;
- int32 secondary_list = 0;
- if (lua_interface) {
- spawn = lua_interface->GetSpawn(state);
- primary_list = lua_interface->GetInt32Value(state, 2);
- secondary_list = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- NPC* npc = (NPC*)spawn;
- npc->SetPrimarySpellList(primary_list);
- npc->SetSecondarySpellList(secondary_list);
- npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
- }
- return 0;
- }
- int EQ2Emu_lua_GetPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
- lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
- lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetDeityPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
- lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
- lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_Charm(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* owner = lua_interface->GetSpawn(state);
- Spawn* pet = lua_interface->GetSpawn(state, 2);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!luaspell) {
- lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
- if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
- ((Entity*)owner)->SetCharmedPet((Entity*)pet);
- pet->SetPet(true);
- ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
- ((NPC*)pet)->SetOwner((Entity*)owner);
- // If owner is player and player does not have a summoned pet set the players charsheet
- if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
- Player* player = (Player*)owner;
- player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
- player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
- player->GetInfoStruct()->set_pet_movement(2);
- player->GetInfoStruct()->set_pet_behavior(3);
- player->GetInfoStruct()->set_pet_health_pct(1.0f);
- player->GetInfoStruct()->set_pet_power_pct(1.0f);
- // Make sure the values get sent to the client
- player->SetCharSheetChanged(true);
- }
- // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
- pet->SetSpawnScript("");
- // Set faction to the same as the owner
- pet->SetFactionID(owner->GetFactionID());
- ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
- ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
- // Clear hate list
- ((NPC*)pet)->Brain()->ClearHate();
- // Set the brain to a pet brain
- ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
- }
- return 0;
- }
- int EQ2Emu_lua_GetGroup(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- vector<Spawn*> groupMembers;
- if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
- groupMembers = *spawn->GetSpawnGroup();
- }
- else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>::iterator itr;
- PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
- if (group)
- {
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- GroupMemberInfo* info = 0;
- for (itr = members->begin(); itr != members->end(); itr++) {
- info = *itr;
- if (info->client)
- groupMembers.push_back(info->client->GetPlayer());
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- else
- return 0;
- lua_createtable(state, groupMembers.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < groupMembers.size(); i++) {
- lua_interface->SetSpawnValue(state, groupMembers.at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- return 1;
- }
- int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- lua_interface->ResetFunctionStack(state);
- vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
- lua_interface->SetOptionWindowValue(state, option_window);
- return 1;
- }
- int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
- if (option_window) {
- OptionWindowOption option_window_option;
- option_window_option.optionName = lua_interface->GetStringValue(state, 2);
- option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
- option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
- option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
- option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
- option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
- if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
- option_window->push_back(option_window_option);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- string window_title = lua_interface->GetStringValue(state, 3);
- string cancel_command = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
-
- if (option_window && window_title.length() > 0 && client) {
- PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
- if (!packet)
- return 0;
- packet->setDataByName("title_text", window_title.c_str());
- if (cancel_command.length() > 0)
- packet->setDataByName("command_text_cancel", cancel_command.c_str());
- packet->setArrayLengthByName("num_selections", option_window->size());
- vector<OptionWindowOption>::iterator itr;
- int8 i = 0;
- for (itr = option_window->begin(); itr != option_window->end(); itr++) {
- OptionWindowOption opt = *itr;
- packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
- packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
- packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
- packet->setArrayDataByName("icon_id", opt.optionIconID, i);
- if (opt.optionCommand.length() > 0)
- packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
- if (opt.optionConfirmTitle.length() > 0)
- packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
- i++;
- }
- client->QueuePacket(packet->serialize());
- lua_interface->SetLuaUserDataStale(option_window);
- safe_delete(option_window);
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
- return 1;
- }
- else
- lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTSLevel());
- return 1;
- }
- else
- lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- int8 class_id = spawn->GetTradeskillClass();
- // Need to add 42 for the offset in the array
- class_id += 44;
- lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
- return 1;
- }
- else
- lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 level = lua_interface->GetInt8Value(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
- ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
- else
- spawn->SetTSLevel(level);
- }
- else
- lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_SetAttackable(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 attackable = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetAttackable(attackable);
- spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
- }
- return 0;
- }
- int EQ2Emu_lua_SummonPet(lua_State* state) {
- // Check to see if we have a valid lua_interface
- if (!lua_interface)
- return 0;
- // Get the spawn that is getting the pet
- Spawn* spawn = lua_interface->GetSpawn(state);
- // Get the DB ID of the pet
- int32 pet_id = lua_interface->GetInt32Value(state, 2);
- // The max level the pet can gain
- int8 max_level = lua_interface->GetInt8Value(state, 3);
- // Get the spell that this command was called from
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- // Check to make sure the spawn pointer is valid
- if (!spawn) {
- lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to make sure the spawn is an entity
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to make sure the spawn doesn't already have a pet of this type
- if (((Entity*)spawn)->GetPet()) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
- }
- lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to see if the DB ID for the pet is set
- if (pet_id == 0) {
- lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to see if the pointer to the spell is valid
- if (!luaspell) {
- lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
-
- // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
- Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
- if (!pet) {
- lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- // Check to make sure the pet is an npc
- if (!pet->IsNPC()) {
- lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- // Spawn the pet at the same location as the owner
- pet->SetX(spawn->GetX());
- pet->SetY(spawn->GetY());
- pet->SetZ(spawn->GetZ());
- pet->SetLocation(spawn->GetLocation());
- pet->SetHeading(spawn->GetHeading());
- std::string petName = std::string("");
- if(spawn->IsEntity()) {
- petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
- }
-
- if(petName.size() < 1) {
- int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
- petName = spawn->GetZone()->pet_names.at(rand_index);
- LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
- }
- // If player set various values for the char sheet (pet window)
- if (spawn->IsPlayer()) {
- Player* player = (Player*)spawn;
-
- player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
- player->GetInfoStruct()->set_pet_name(petName);
- player->GetInfoStruct()->set_pet_movement(2);
- player->GetInfoStruct()->set_pet_behavior(3);
- player->GetInfoStruct()->set_pet_health_pct(1.0f);
- player->GetInfoStruct()->set_pet_power_pct(1.0f);
- // Make sure the values get sent to the client
- player->SetCharSheetChanged(true);
- }
- // Set the pets name
- pet->SetName(petName.c_str());
- // Set the level of the pet to the owners level or max level(if set) if owners level is greater
- if (max_level > 0)
- pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
- else
- pet->SetLevel(spawn->GetLevel());
- // Set the max level this pet can reach
- ((NPC*)pet)->SetMaxPetLevel(max_level);
-
- ((NPC*)pet)->UpdateWeapons();
-
- // Set the faction of the pet to the same faction as the owner
- pet->SetFactionID(spawn->GetFactionID());
- // Set the spawn as a pet
- pet->SetPet(true);
- // Give a pointer of the owner to the pet
- ((NPC*)pet)->SetOwner((Entity*)spawn);
- // Give a pointer of the pet to the owner
- ((Entity*)spawn)->SetCombatPet((Entity*)pet);
- // Set the pet type
- ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
- // Set the spell id used to create this pet
- ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
- // Set the spell tier used to create this pet
- ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
- // Set the pets spawn type to 6
- pet->SetSpawnType(6);
- // Set the pets brain
- ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
- // Check to see if the pet has a subtitle
- if (strlen(pet->GetSubTitle()) > 0) {
- // Add the players name to the front of the sub title
- string pet_subtitle;
- pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
- LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
- // Set the pets subtitle to the new one
- pet->SetSubTitle(pet_subtitle.c_str());
- }
- // Add the "Pet Options" entity command to the pet
- pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
-
- const char* spawn_script = world.GetSpawnScript(pet_id);
- bool runScript = false;
- if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
- runScript = true;
- pet->SetSpawnScript(string(spawn_script));
- spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
- }
-
- spawn->GetZone()->AddSpawn(pet);
-
- if(runScript){
- spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
- }
-
- // Set the pet as the return value for this function
- lua_interface->SetSpawnValue(state, pet);
- return 1;
- }
- int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 pet_id = lua_interface->GetInt32Value(state, 2);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((Entity*)spawn)->GetDeityPet()) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
- }
- lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
- return 0;
- }
- if (pet_id == 0) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!luaspell) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
- Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
- if (!pet) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- if (!pet->IsNPC()) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- pet->SetX(spawn->GetX());
- pet->SetY(spawn->GetY());
- pet->SetZ(spawn->GetZ());
- pet->SetLocation(spawn->GetLocation());
- pet->SetHeading(spawn->GetHeading());
- spawn->GetZone()->AddSpawn(pet);
- string random_pet_name;
- int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
- random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
- LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
- pet->SetName(random_pet_name.c_str());
- pet->SetLevel(spawn->GetLevel());
- pet->SetFactionID(spawn->GetFactionID());
- pet->SetPet(true);
- ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
- ((NPC*)pet)->SetOwner((Entity*)spawn);
- ((Entity*)spawn)->SetDeityPet((Entity*)pet);
- pet->SetSpawnType(6);
- ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
- ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
- ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
- if (strlen(pet->GetSubTitle()) > 0) {
- string pet_subtitle;
- pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
- LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
- pet->SetSubTitle(pet_subtitle.c_str());
- }
- // deity and cosmetic pets are not attackable
- pet->SetAttackable(false);
- pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
- lua_interface->SetSpawnValue(state, pet);
- return 1;
- }
- int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 pet_id = lua_interface->GetInt32Value(state, 2);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((Entity*)spawn)->GetCosmeticPet()) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
- }
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
- return 0;
- }
- if (pet_id == 0) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!luaspell) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
-
- Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
- if (!pet) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- if (!pet->IsNPC()) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- pet->SetX(spawn->GetX());
- pet->SetY(spawn->GetY());
- pet->SetZ(spawn->GetZ());
- pet->SetLocation(spawn->GetLocation());
- pet->SetHeading(spawn->GetHeading());
- spawn->GetZone()->AddSpawn(pet);
- string random_pet_name;
- int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
- random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
- LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
- pet->SetName(random_pet_name.c_str());
- pet->SetLevel(spawn->GetLevel());
- pet->SetFactionID(spawn->GetFactionID());
- pet->SetPet(true);
- ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
- ((NPC*)pet)->SetOwner((Entity*)spawn);
- ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
- pet->SetSpawnType(6);
- ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
- ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
- ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
- if (strlen(pet->GetSubTitle()) > 0) {
- string pet_subtitle;
- pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
- LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
- pet->SetSubTitle(pet_subtitle.c_str());
- }
- pet->SetAttackable(false);
- pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
- lua_interface->SetSpawnValue(state, pet);
- return 1;
- }
- int EQ2Emu_lua_DismissPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPet()) {
- lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
- ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
- return 0;
- }
- int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- if (!quest) {
- 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));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int8 feather_color = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (feather_color > 0)
- quest->SetFeatherColor(feather_color);
- return 0;
- }
- int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn2) {
- lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->RemoveSpawnAccess(spawn2);
- return 0;
- }
- int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 location_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!zone) {
- lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (location_id == 0) {
- lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
- return 0;
- }
- SpawnLocation* location = zone->GetSpawnLocation(location_id);
- if (!location) {
- lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
- return 0;
- }
-
- int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
- Spawn* spawn = 0;
- if (location->entities[rand_number]) {
- if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
- spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
- spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
- spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
- spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
- spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
- if(spawn && spawn->IsOmittedByDBFlag())
- {
- LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
- safe_delete(spawn);
- spawn = 0;
- return 0;
- }
- if (spawn) {
- const char* script = 0;
- for (int x = 0; x < 3; x++) {
- switch (x) {
- case 0:
- script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
- break;
- case 1:
- script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
- break;
- case 2:
- script = world.GetSpawnScript(location->entities[0]->spawn_id);
- break;
- }
- if (script && lua_interface->GetSpawnScript(script) != 0) {
- spawn->SetSpawnScript(string(script));
- break;
- }
- }
- zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- else {
- LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
- safe_delete(spawn);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- int32 id = lua_interface->GetInt32Value(state, 3);
- string command = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!caster) {
- lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!caster->IsPlayer()) {
- lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
- if (!entity_command) {
- 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());
- return 0;
- }
- Client* client = ((Player*)caster)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
- return 0;
- }
- client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
- return 0;
- }
- int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
- return 0;
- }
- int EQ2Emu_lua_SetBrainTick(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 tick = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
- return 0;
- }
- if (tick < 20) {
- lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->Brain()->SetTick(tick);
- return 0;
- }
- int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- int32 follow_distance = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
- spawn->SetFollowTarget(target, follow_distance);
- return 0;
- }
- int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- Spawn* target = spawn->GetFollowTarget();
- if (target) {
- lua_interface->SetSpawnValue(state, target);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_ToggleFollow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn->following)
- spawn->following = false;
- else
- spawn->following = true;
- return 0;
- }
- int EQ2Emu_lua_IsFollowing(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->following);
- return 1;
- }
- int EQ2Emu_lua_SetTempVariable(lua_State* state) {
- // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
- // I will attempt to explain how this function works for future refrence
- // Fist lets make sure lua_interface is valid, if not return out
- if (!lua_interface)
- return 0;
- // Next we grab the first 2 params same as we usually would
- Spawn* spawn = lua_interface->GetSpawn(state);
- string var = lua_interface->GetStringValue(state, 2);
- // 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
- // 1 = Spawn
- // 2 = Zone
- // 3 = Item
- // 4 = Quest
- // 5 = String
- // 6 = nil (null)
- int8 dataType = 0;
- // Define pointers for each potential type
- Spawn* spawnVal = 0;
- ZoneServer* zone = 0;
- Item* item = 0;
- Quest* quest = 0;
- string val;
- // Finally we get to grabbing the third param, we will first check to see if it is light user data
- // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
- // options window are also light user data be we do not handle those.
- // We check with lua_islightuserdata(lua_State*, index)
- if (lua_islightuserdata(state, 3)) {
- // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
- // and convert it to LUAUserData*
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
- // Check to make sure the data we got is valid, if not give an error
- if (!data || !data->IsCorrectlyInitialized()) {
- lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
- }
- // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
- else if (data->IsSpawn()) {
- spawnVal = data->spawn;
- dataType = 1;
- }
- // Check if data is a Zone, if so set our Zone pointer and the dataType variable
- else if (data->IsZone()) {
- zone = data->zone;
- dataType = 2;
- }
- // Check if data is a Item, if so set our Item pointer and the dataType variable
- else if (data->IsItem()) {
- item = data->item;
- dataType = 3;
- }
- // Check if data is a Ques, if so set our Quest pointer and the dataType variable
- else if (data->IsQuest()) {
- quest = data->quest;
- dataType = 4;
- }
- }
- // Wasn't light user data, check if it is nil(null)
- else if (lua_isnil(state, 3)) {
- // It is nil (null) set the dataType variable, no need to set a pointer in this case
- dataType = 6;
- }
- // Wasn't light user data or nil (null), must be a string
- else {
- // Set the string and dataType variable
- val = lua_interface->GetStringValue(state, 3);
- dataType = 5;
- }
-
- lua_interface->ResetFunctionStack(state);
- // We now have all the params, lets check to make sure they are valid
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (var.length() == 0) {
- lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- if (dataType == 0) {
- lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
- return 0;
- }
- // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
- // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
- // param gets sent to the correct list so we check the value of dataType to know where it should go.
- switch (dataType) {
- case 1:
- // 1 = Spawn
- spawn->AddTempVariable(var, spawnVal);
- break;
- case 2:
- // 2 = Zone
- spawn->AddTempVariable(var, zone);
- break;
- case 3:
- // 3 = Item
- spawn->AddTempVariable(var, item);
- break;
- case 4:
- // 4 = Quest
- spawn->AddTempVariable(var, quest);
- break;
- case 5:
- // 5 = String
- spawn->AddTempVariable(var, val);
- break;
- case 6:
- // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
- spawn->DeleteTempVariable(var);
- break;
- }
- // And we are done so return out
- return 0;
- }
- int EQ2Emu_lua_GetTempVariable(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string var = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (var.length() == 0) {
- lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- // This will tell us the type of data this variable contains, uses the same values as the previous function
- int8 type = spawn->GetTempVariableType(var);
- Spawn* spawn2 = 0;
- ZoneServer* zone = 0;
- Item* item = 0;
- Quest* quest = 0;
- // Set the lua function return value based on the type of data the variable contains
- switch (type) {
- case 1:
- spawn2 = spawn->GetTempVariableSpawn(var);
- if (!spawn2)
- return 0;
- lua_interface->SetSpawnValue(state, spawn2);
- break;
- case 2:
- zone = spawn->GetTempVariableZone(var);
- if (!zone)
- return 0;
- lua_interface->SetZoneValue(state, zone);
- break;
- case 3:
- item = spawn->GetTempVariableItem(var);
- if (!item)
- return 0;
- lua_interface->SetItemValue(state, item);
- break;
- case 4:
- quest = spawn->GetTempVariableQuest(var);
- if (!quest)
- return 0;
- lua_interface->SetQuestValue(state, quest);
- break;
- case 5:
- lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
- break;
- default:
- // Not a valid type then the variable was not set so return out
- return 0;
- }
- // Return value was set so return out
- return 1;
- }
- int EQ2Emu_lua_GiveQuestItem(lua_State* state)
- {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 item_id = lua_interface->GetInt32Value(state, 4);
- if (!quest) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!spawn) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (item_id == 0) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- Client* client = ((Player*)spawn)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- Item* item = master_item_list.GetItem(item_id);
- if (!item) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- Item* firstItem = new Item(item);
- quest->AddTmpRewardItem(firstItem);
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- bool itemsAddedSuccessfully = true;
- if(num_args > 4)
- {
- for(int8 n=5;n<num_args+1;n++)
- {
- int32 new_item = lua_interface->GetInt32Value(state, n);
- Item* tmpItem = master_item_list.GetItem(new_item);
- if(tmpItem)
- {
- Item* newTmpItem = new Item(tmpItem);
- quest->AddTmpRewardItem(newTmpItem);
- }
- else
- itemsAddedSuccessfully = false;
- }
- }
- client->AddPendingQuestReward(quest, true, true, description); // queue for display
-
- lua_interface->ResetFunctionStack(state);
-
- lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
- return 1;
- }
- int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetRepeatable(true);
- return 0;
- }
- int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
- string ret = classes.GetClassNameCase(base_class);
- if (ret.length() > 0) {
- lua_interface->SetStringValue(state, ret.c_str());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SendWaypoints(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client)
- client->SendWaypoints();
- }
- return 0;
- }
- int EQ2Emu_lua_AddWaypoint(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- string name = lua_interface->GetStringValue(state, 2);
- int32 type = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (type == 0)
- type = 2;
- if (name.length() > 0) {
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client)
- client->AddWaypoint(name, type);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- string name = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (name.length() > 0) {
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client)
- client->RemoveWaypoint(name);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_AddWard(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 damage = lua_interface->GetInt32Value(state);
- bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
- int8 wardType = lua_interface->GetInt8Value(state, 3);
- int8 damageTypes = lua_interface->GetInt8Value(state, 4);
- int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
- int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
- int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
- int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!spell || spell->resisted) {
- return 0;
- }
-
- bool ward_was_added = false;
- ZoneServer* zone = spell->caster->GetZone();
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (!target)
- continue;
- if (target->IsEntity()) {
- // If the ward is already active remove it
- if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
- ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
- // Create new ward info
- WardInfo* ward = new WardInfo;
- ward->Spell = spell;
- ward->BaseDamage = damage;
- ward->DamageLeft = damage;
- ward->AbsorbAllDamage = (damage == 0) ? true : false;
- ward->keepWard = keepWard;
- ward->WardType = wardType;
- if (damageAbsorptionPercent > 100)
- damageAbsorptionPercent = 100;
- ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
- if (damageAbsorptionMaxHealthPercent > 100)
- damageAbsorptionMaxHealthPercent = 100;
- ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
- ward->RedirectDamagePercent = redirectDamagePercent;
- ward->LastRedirectDamage = 0;
- ward->LastAbsorbedDamage = 0;
- ward->HitCount = 0;
- spell->num_triggers = maxHitCount;
- spell->had_triggers = true;
- spell->cancel_after_all_triggers = false;
- ward->MaxHitCount = maxHitCount;
- ward->RoundTriggered = false;
- if (wardType == WARD_TYPE_MAGICAL)
- ward->DamageType = damageTypes;
- // Add the ward to the entity
- ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
- ward_was_added = true;
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- if (ward_was_added && spell->caster->IsPlayer()) {
- spell->had_dmg_remaining = true;
- ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
- }
- return 0;
- }
- int EQ2Emu_lua_AddToWard(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 amount = lua_interface->GetInt32Value(state);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- WardInfo* ward = 0;
-
- if(!spell || spell->resisted) {
- return 0;
- }
- ZoneServer* zone = spell->caster->GetZone();
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
- Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
- ward = target->GetWard(spell->spell->GetSpellID());
- if (target && ward) {
- ward->DamageLeft += amount;
- if (ward->DamageLeft > ward->BaseDamage)
- ward->DamageLeft = ward->BaseDamage;
- for (int32 i = 0; i < spell->targets.size(); i++) {
- if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
- zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
- }
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- if (ward && spell->caster->IsPlayer())
- ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
- return 0;
- }
- int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
- Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
- WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
- if (ward) {
- lua_interface->SetInt32Value(state, ward->DamageLeft);
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- return 1;
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- return 0;
- }
- int EQ2Emu_lua_GetWardValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- string type = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
- Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
- WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
- if (ward) {
- if (boost::iequals(type, "damageleft"))
- lua_interface->SetInt32Value(state, ward->DamageLeft);
- else if (boost::iequals(type, "basedamage"))
- lua_interface->SetInt32Value(state, ward->BaseDamage);
- else if (boost::iequals(type, "keepward"))
- lua_interface->SetBooleanValue(state, ward->keepWard);
- else if (boost::iequals(type, "wardtype"))
- lua_interface->SetInt32Value(state, ward->WardType);
- else if (boost::iequals(type, "dmgabsorptionpct"))
- lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
- else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
- lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
- else if (boost::iequals(type, "redirectdamagepercent"))
- lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
- else if (boost::iequals(type, "lastredirectdamage"))
- lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
- else if (boost::iequals(type, "lastabsorbeddamage"))
- lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
- else if (boost::iequals(type, "hitcount"))
- lua_interface->SetInt32Value(state, ward->HitCount);
- else if (boost::iequals(type, "maxhitcount"))
- lua_interface->SetInt32Value(state, ward->MaxHitCount);
- else
- lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
-
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- return 1;
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- return 0;
- }
- int EQ2Emu_lua_RemoveWard(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!spell) {
- return 0;
- }
-
- ZoneServer* zone = spell->caster->GetZone();
- Spawn* target = 0;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- target = zone->GetSpawnByID(spell->targets.at(i));
- if (target && target->IsEntity()) {
- ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- return 0;
- }
- int EQ2Emu_lua_Interrupt(lua_State* state)
- {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
- Spawn* target = lua_interface->GetSpawn(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!caster)
- {
- lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target)
- {
- lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell) {
- lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity() && !spell)
- {
- lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target && spell) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else
- caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
- return 0;
- }
- int EQ2Emu_lua_Stealth(lua_State* state) {
- if (!lua_interface)
- return 0;
- int8 type = lua_interface->GetInt8Value(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- ZoneServer* zone = spell->caster->GetZone();
- if (spawn) {
- if (spawn->IsEntity()) {
- if (type == 1) {
- ((Entity*)spawn)->AddStealthSpell(spell);
- if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
- spell->effect_bitmask += EFFECT_FLAG_STEALTH;
- }
- else if (type == 2) {
- ((Entity*)spawn)->AddInvisSpell(spell);
- if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
- spell->effect_bitmask += EFFECT_FLAG_INVIS;
- }
- return 0;
- }
- else {
- lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
- return 0;
- }
- }
- else {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- spawn = zone->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- if (type == 1) {
- ((Entity*)spawn)->AddStealthSpell(spell);
- if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
- spell->effect_bitmask += EFFECT_FLAG_STEALTH;
- }
- else if (type == 2) {
- ((Entity*)spawn)->AddInvisSpell(spell);
- if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
- spell->effect_bitmask += EFFECT_FLAG_INVIS;
- }
- else {
- lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
- break;
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_IsStealthed(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn->IsEntity()) {
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
- return 1;
- }
- else
- lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_IsInvis(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn->IsEntity()) {
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
- return 1;
- }
- else
- lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
- return 1;
- }
- int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
- if (!item) {
- lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetItemValue(state, item);
- return 1;
- }
- int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
- if (!item) {
- lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetItemValue(state, item);
- return 1;
- }
- int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- int32 item_id = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
-
- Item* item = master_item_list.GetItem(item_id);
- if (!item) {
- lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
- return 0;
- }
-
- Item* copy = new Item(item);
- bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
- if(result)
- {
- ((Entity*)spawn)->SetEquipment(copy, slot);
- spawn->vis_changed = true;
- if(spawn->IsPlayer())
- ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
- }
- else
- {
- safe_delete(copy);
- }
-
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- Item* item = lua_interface->GetItem(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!item) {
- lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
- return 0;
- }
-
- bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
- if(result)
- {
- ((Entity*)spawn)->SetEquipment(item, slot);
- spawn->vis_changed = true;
- if(spawn->IsPlayer())
- ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
- }
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_UnequipSlot(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- 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
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if(slot >= NUM_SLOTS) {
- lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
- return 0;
- }
-
- if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
- Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
- if(item) {
- item->save_needed = true;
- if(no_delete_item) {
- database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
- ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
- }
- else{
- Client* client = ((Player*)spawn)->GetClient();
- client->UnequipItem(item->details.index);
- }
- }
- }
- else
- ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
-
- ((Entity*)spawn)->SetEquipment(nullptr, slot);
- spawn->vis_changed = true;
- if(spawn->IsPlayer())
- ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_SetEquipment(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- int16 type = lua_interface->GetInt16Value(state, 3);
- int8 r = lua_interface->GetInt8Value(state, 4);
- int8 g = lua_interface->GetInt8Value(state, 5);
- int8 b = lua_interface->GetInt8Value(state, 6);
- int8 h_r = lua_interface->GetInt8Value(state, 7);
- int8 h_g = lua_interface->GetInt8Value(state, 8);
- int8 h_b = lua_interface->GetInt8Value(state, 9);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
- spawn->vis_changed = true;
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_GetItemByID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 id = lua_interface->GetInt32Value(state, 2);
- int8 count = lua_interface->GetInt8Value(state, 3);
- bool include_bank = lua_interface->GetInt8Value(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!count)
- count = 1;
- Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetItemValue(state, item);
- return 1;
- }
- int EQ2Emu_lua_PlayAnimation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 anim = lua_interface->GetInt32Value(state, 2);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
- int8 type = lua_interface->GetInt8Value(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn2) {
- if (spawn2->IsPlayer()) {
- if (type != 1 && type != 2)
- spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
- else
- spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
- return 0;
- }
- else {
- lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- }
- else
- spawn->GetZone()->PlayAnimation(spawn, anim);
- return 0;
- }
- int EQ2Emu_lua_IsPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->IsPet());
- return 1;
- }
- int EQ2Emu_lua_GetOwner(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((NPC*)spawn)->GetOwner()) {
- lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetTarget(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->SetTarget(target);
- return 0;
- }
- int EQ2Emu_lua_SetInCombat(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool val = lua_interface->GetBooleanValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Entity*)spawn)->InCombat(val);
- if (val) {
- spawn->ClearRunningLocations();
- spawn->CalculateRunningLocation(true);
- }
- return 0;
- }
- int EQ2Emu_lua_CompareSpawns(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn1 = lua_interface->GetSpawn(state);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn1) {
- lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn2) {
- lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
- return 1;
- }
- int EQ2Emu_lua_ClearRunback(lua_State* state){
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->ClearRunback();
- return 0;
- }
- int EQ2Emu_lua_Runback(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->Runback();
- return 0;
- }
- int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
- return 1;
- }
- int EQ2Emu_lua_IsCasting(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
- return 1;
- }
- int EQ2Emu_lua_IsMezzed(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
- return 1;
- }
- int EQ2Emu_lua_IsStunned(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
- return 1;
- }
- int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
- return 1;
- }
- int EQ2Emu_lua_ProcessSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- float distance = lua_interface->GetFloatValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
- return 1;
- }
- int EQ2Emu_lua_ProcessMelee(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- float distance = lua_interface->GetFloatValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
- return 0;
- }
- int EQ2Emu_lua_HasRecovered(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
- return 1;
- }
- int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
- return 1;
- }
- int EQ2Emu_lua_GetMostHated(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
- if (hated) {
- lua_interface->SetSpawnValue(state, hated);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_ClearHate(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* hated = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!hated) {
- ((NPC*)spawn)->Brain()->ClearHate();
- return 0;
- }
- else
- {
- if (!hated->IsEntity()) {
- lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
- return 0;
- }
- return 0;
- }
- int EQ2Emu_lua_ClearEncounter(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->Brain()->ClearEncounter();
- return 0;
- }
- int EQ2Emu_lua_GetEncounter(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- // Temp list to store hate list
- vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
- if (encounterList->size() == 0) {
- safe_delete(encounterList);
- return 0;
- }
- lua_createtable(state, encounterList->size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < encounterList->size(); i++) {
- Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
- if (temp)
- lua_interface->SetSpawnValue(state, temp);
- lua_rawseti(state, newTable, i + 1);
- }
- safe_delete(encounterList);
- return 1;
- }
- int EQ2Emu_lua_GetHateList(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- // Temp list to store hate list
- vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
- if (hateList->size() == 0) {
- safe_delete(hateList);
- return 0;
- }
- lua_createtable(state, hateList->size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < hateList->size(); i++) {
- lua_interface->SetSpawnValue(state, hateList->at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- safe_delete(hateList);
- return 1;
- }
- int EQ2Emu_lua_HasGroup(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn->IsPlayer()) {
- if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
- lua_interface->SetBooleanValue(state, true);
- else
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- else {
- lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
- return 1;
- }
- }
- int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetCompletedFlag(true);
- return 0;
- }
- int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 spellID = lua_interface->GetInt32Value(state, 2);
- int8 tier = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spellID == 0) {
- lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
- if (effect) {
- if (tier > 0) {
- // If a tier was passed chec to see if it is the same as the effect
- if (tier == effect->tier)
- lua_interface->SetBooleanValue(state, true);
- else
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- else {
- // Have an effect but no tier was passed so return true
- lua_interface->SetBooleanValue(state, true);
- }
- return 1;
- }
- // no effect so return false
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 id = lua_interface->GetInt32Value(state, 2);
- ZoneServer* zone = lua_interface->GetZone(state, 3);
- lua_interface->ResetFunctionStack(state);
- Spawn* spawn2 = 0;
- vector<Spawn*> list;
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- //If zone not provided, use spawn's zone
- if (!zone)
- zone = spawn->GetZone();
- list = zone->GetSpawnsByID(id);
- if (list.size() == 0) {
- lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
- return 0;
- }
- vector<Spawn*>::iterator itr = list.begin();
- for (int8 i = 0; i < list.size(); i++) {
- spawn2 = itr[i];
- if (spawn2)
- spawn2->AddAllowAccessSpawn(spawn);
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 id = lua_interface->GetInt32Value(state, 2);
- ZoneServer* zone = lua_interface->GetZone(state, 3);
- lua_interface->ResetFunctionStack(state);
- Spawn* spawn2 = 0;
- if (!spawn) {
- lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- //If zone not provided, use spawn's zone
- if (!zone)
- zone = spawn->GetZone();
- vector<Spawn*> list = zone->GetSpawnsByID(id);
- vector<Spawn*>::iterator itr = list.begin();
- if (list.size() == 0) {
- lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
- return 0;
- }
- for (int8 i = 0; i < list.size(); i++) {
- spawn2 = itr[i];
- if (spawn2)
- spawn2->RemoveSpawnAccess(spawn);
- }
- return 0;
- }
- int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetYellowName(true);
- return 0;
- }
- int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
- return 1;
- }
- int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ZoneServer* zone = spawn->GetZone();
- if (!zone) {
- lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- Instance_Type iType = zone->GetInstanceType();
- if (iType == SOLO_LOCKOUT_INSTANCE ||
- iType == GROUP_LOCKOUT_INSTANCE ||
- iType == RAID_LOCKOUT_INSTANCE ||
- iType == SOLO_PERSIST_INSTANCE ||
- iType == GROUP_PERSIST_INSTANCE ||
- iType == RAID_PERSIST_INSTANCE) {
- InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
- if (data) {
- // Check to see if the timer has already been set, if it has return out.
- if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
- return 0;
- database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
- data->last_success_timestamp = Timer::GetUnixTimeStamp();
-
- if(spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- string time_msg = "";
- int32 time = data->success_lockout_time;
- int16 hour;
- int8 min;
- int8 sec;
- hour = time / 3600;
- time = time % 3600;
- min = time / 60;
- time = time % 60;
- sec = time;
- if (hour > 0) {
- char temp[10];
- sprintf(temp, " %i", hour);
- time_msg.append(temp);
- time_msg.append(" hour");
- time_msg.append((hour > 1) ? "s" : "");
- }
- if (min > 0) {
- char temp[5];
- sprintf(temp, " %i", min);
- time_msg.append(temp);
- time_msg.append(" minute");
- time_msg.append((min > 1) ? "s" : "");
- }
- // Only add seconds if minutes and hours are 0
- if (hour == 0 && min == 0 && sec > 0) {
- char temp[5];
- sprintf(temp, " %i", sec);
- time_msg.append(temp);
- time_msg.append(" second");
- time_msg.append((sec > 1) ? "s" : "");
- }
- 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());
- }
- else {
- lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
- }
- }
- }
- else
- lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
- }
- else
- lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ZoneServer* zone = spawn->GetZone();
- if (!zone) {
- lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- Instance_Type iType = zone->GetInstanceType();
- if (iType == SOLO_LOCKOUT_INSTANCE ||
- iType == GROUP_LOCKOUT_INSTANCE ||
- iType == RAID_LOCKOUT_INSTANCE ||
- iType == SOLO_PERSIST_INSTANCE ||
- iType == GROUP_PERSIST_INSTANCE ||
- iType == RAID_PERSIST_INSTANCE) {
- InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
- if (data) {
- // Check to see if the timer has already been set, if it has return out.
- if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
- return 0;
- database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
- data->last_failure_timestamp = Timer::GetUnixTimeStamp();
-
- if(spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- string time_msg = "";
- int32 time = data->failure_lockout_time;
- int16 hour;
- int8 min;
- int8 sec;
- hour = time / 3600;
- time = time % 3600;
- min = time / 60;
- time = time % 60;
- sec = time;
- if (hour > 0) {
- char temp[10];
- sprintf(temp, " %i", hour);
- time_msg.append(temp);
- time_msg.append(" hour");
- time_msg.append((hour > 1) ? "s" : "");
- }
- if (min > 0) {
- char temp[5];
- sprintf(temp, " %i", min);
- time_msg.append(temp);
- time_msg.append(" minute");
- time_msg.append((min > 1) ? "s" : "");
- }
- // Only add seconds if minutes and hours are 0
- if (hour == 0 && min == 0 && sec > 0) {
- char temp[5];
- sprintf(temp, " %i", sec);
- time_msg.append(temp);
- time_msg.append(" second");
- time_msg.append((sec > 1) ? "s" : "");
- }
- 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());
- }
- }
- else {
- lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
- }
- }
- else
- lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
- }
- else
- lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
- return 1;
- }
- int EQ2Emu_lua_CanHarvest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- Spawn* ground = lua_interface->GetSpawn(state, 2);
- if (!player) {
- lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!ground) {
- lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!ground->IsGroundSpawn()) {
- lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
- if (!groundspawn_entries) {
- lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- Skill* skill = 0;
- string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
- if (collection_skill == "Collecting")
- skill = ((Player*)player)->GetSkillByName("Gathering");
- else
- skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
- if (!skill) {
- lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- vector<GroundSpawnEntry*>::iterator itr;
- GroundSpawnEntry* entry = 0;
- bool can_harvest = false;
- sint32 min_skill = -1;
- int16 totalSkill = skill->current_val;
- int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
- if(skillID != 0xFFFFFFFF)
- {
- ((Entity*)player)->MStats.lock();
- totalSkill += ((Entity*)player)->stats[skillID];
- ((Entity*)player)->MStats.unlock();
- }
-
- // first, iterate through groundspawn_entries, discard tables player cannot use
- for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
- {
- entry = *itr;
- if (min_skill == -1 || entry->min_skill_level < min_skill)
- min_skill = entry->min_skill_level;
- // if player lacks skill, skip table
- if (entry->min_skill_level > totalSkill)
- continue;
- // if bonus, but player lacks level, skip table
- if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
- continue;
- can_harvest = true;
- break;
- }
- lua_interface->SetBooleanValue(state, can_harvest);
- // If false, send the message to the client
- if (!can_harvest) {
- Client* client = ((Player*)player)->GetClient();
- if (client) {
- string msg = "You do not have enough skill to ";
- if (collection_skill == "Gathering" || collection_skill == "Collecting")
- msg.append("gather");
- else if (collection_skill == "Mining")
- msg.append("mine");
- else if (collection_skill == "Trapping")
- msg.append("trap");
- else if (collection_skill == "Foresting")
- msg.append("forest");
- else if (collection_skill == "Fishing")
- msg.append("catch");
- msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
- client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
- // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 1;
- }
- int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 recipe_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
- lua_interface->SetBooleanValue(state, ret);
- return 1;
- }
- int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
- // Check to see if we have a valid lua_interface
- if (!lua_interface)
- return 0;
- // Get the spawn that is getting the pet
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- // Get the DB ID of the pet
- int32 pet_id = lua_interface->GetInt32Value(state, 3);
- float x = lua_interface->GetFloatValue(state, 4);
- float y = lua_interface->GetFloatValue(state, 5);
- float z = lua_interface->GetFloatValue(state, 6);
- // Get the spell that this command was called from
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- // Check to make sure the spawn pointer is valid
- if (!spawn) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to make sure the spawn is an entity
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to see if the DB ID for the pet is set
- if (pet_id == 0) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to see if the pointer to the spell is valid
- if (!luaspell) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
- // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
- Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
- if (!pet) {
- lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
- return 0;
- }
- // Check to make sure the pet is an npc
- if (!pet->IsNPC()) {
- lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
- return 0;
- }
- if (x == 0)
- x = spawn->GetX();
- if (y == 0)
- y = spawn->GetY();
- if (z == 0)
- z = spawn->GetZ();
- // Spawn the pet at the same location as the owner
- pet->SetX(x);
- pet->SetY(y);
- pet->SetZ(z);
- pet->SetLocation(spawn->GetLocation());
- pet->SetHeading(spawn->GetHeading());
- spawn->GetZone()->AddSpawn(pet);
-
- const char* spawn_script = world.GetSpawnScript(pet_id);
- if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
- spawn->SetSpawnScript(string(spawn_script));
- spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- }
- std::string petName = std::string("");
- if(spawn->IsEntity()) {
- petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
- }
-
- if(petName.size() < 1) {
- int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
- petName = spawn->GetZone()->pet_names.at(rand_index);
- LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
- }
-
- // Set the pets name
- pet->SetName(petName.c_str());
-
- // Set the level of the pet to the owners level
- pet->SetLevel(spawn->GetLevel());
- // Set the faction of the pet to the same faction as the owner
- pet->SetFactionID(spawn->GetFactionID());
- // Set the spawn as a pet
- pet->SetPet(true);
- // Give a pointer of the owner to the pet
- ((NPC*)pet)->SetOwner((Entity*)spawn);
- // Set the pet type
- ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
- // Set the spell id used to create this pet
- ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
- // Set the spell tier used to create this pet
- ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
- // Set the pets spawn type to 6
- pet->SetSpawnType(6);
- // Set the pets brain
- ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
- // Check to see if the pet has a subtitle
- if (strlen(pet->GetSubTitle()) > 0) {
- // Add the players name to the front of the sub title
- string pet_subtitle;
- pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
- LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
- // Set the pets subtitle to the new one
- pet->SetSubTitle(pet_subtitle.c_str());
- }
- // Set the pet as the return value for this function
- lua_interface->SetSpawnValue(state, pet);
- return 1;
- }
- int EQ2Emu_lua_SpawnMove(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- float max_distance = lua_interface->GetFloatValue(state, 3);
- string type = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!spawn || (spawn && spawn->IsPlayer())) {
- lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player || !player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
- return 0;
- }
- //Set max_distance to default if not set or not proper value
- if (max_distance <= 0)
- max_distance = 500;
- PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
- if (packet) {
- float unknown2_3 = 0;
- int8 placement_mode = 0;
- if (type == "wall") {
- placement_mode = 2;
- unknown2_3 = 150;
- }
- else if (type == "ceiling")
- placement_mode = 1;
- packet->setDataByName("placement_mode", placement_mode);
- packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("model_type", spawn->GetModelType());
- packet->setDataByName("unknown", 1); //size
- packet->setDataByName("unknown2", 1); //size 2
- packet->setDataByName("unknown2", .5, 1); //size 3
- packet->setDataByName("unknown2", 3, 2);
- packet->setDataByName("unknown2", unknown2_3, 3);
- packet->setDataByName("max_distance", max_distance);
- packet->setDataByName("CoEunknown", 0xFFFFFFFF);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_GetItemType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, item->generic_info.item_type);
- return 1;
- }
- int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, item->effect_type);
- return 1;
- }
- int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn->GetZone())
- spawn->GetZone()->AddTransportSpawn(spawn);
- return 0;
- }
- int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
- return 1;
- }
- int EQ2Emu_lua_GetSkillValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Skill* skill = lua_interface->GetSkill(state);
- lua_interface->ResetFunctionStack(state);
- if (!skill) {
- lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, skill->current_val);
- return 1;
- }
- int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Skill* skill = lua_interface->GetSkill(state);
- lua_interface->ResetFunctionStack(state);
- if (!skill) {
- lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, skill->max_val);
- return 1;
- }
- int EQ2Emu_lua_GetSkillName(lua_State* state) {
- if (!lua_interface)
- return 0;
- Skill* skill = lua_interface->GetSkill(state);
- lua_interface->ResetFunctionStack(state);
- if (!skill) {
- lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetStringValue(state, skill->name.data.c_str());
- return 1;
- }
- int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Skill* skill = lua_interface->GetSkill(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!skill) {
- lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- skill->max_val = value;
- if (skill->max_val < skill->current_val)
- skill->current_val = skill->max_val;
- return 0;
- }
- int EQ2Emu_lua_SetSkillValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Skill* skill = lua_interface->GetSkill(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!skill) {
- lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (value > skill->max_val)
- skill->current_val = skill->max_val;
- else
- skill->current_val = value;
- return 0;
- }
- int EQ2Emu_lua_HasSkill(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 skill_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (skill_id > 0 && player && player->IsPlayer()) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_AddSkill(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player_spawn = lua_interface->GetSpawn(state);
- int32 skill_id = lua_interface->GetInt32Value(state, 2);
- int16 current_val = lua_interface->GetInt16Value(state, 3);
- int16 max_val = lua_interface->GetInt16Value(state, 4);
- bool more_to_add = lua_interface->GetBooleanValue(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (skill_id > 0 && current_val > 0 && max_val > 0) {
- if (player_spawn && player_spawn->IsPlayer()) {
- Player* player = (Player*)player_spawn;
- bool added = false;
- if (!player->skill_list.HasSkill(skill_id)) {
- player->AddSkill(skill_id, current_val, max_val, true);
- added = true;
- }
- 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
- Client* client = player->GetClient();
- if (client) {
- EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- if (added) {
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- else {
- lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
- }
- }
- else {
- lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_RemoveSkill(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player_spawn = lua_interface->GetSpawn(state);
- int32 skill_id = lua_interface->GetInt32Value(state, 2);
- bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (skill_id > 0) {
- if (player_spawn && player_spawn->IsPlayer()) {
- Player* player = (Player*)player_spawn;
- if (player->skill_list.HasSkill(skill_id)) {
- player->RemovePlayerSkill(skill_id, true);
- if (!more_to_remove) {
- Client* client = player->GetClient();
- if (client) {
- EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- }
- }
- else {
- lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
- }
- }
- else {
- lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player_spawn = lua_interface->GetSpawn(state);
- int8 skill_type = lua_interface->GetInt8Value(state, 2);
- int16 amount = lua_interface->GetInt8Value(state, 3);
- bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (amount > 0 && skill_type < 100) {
- if (player_spawn && player_spawn->IsPlayer()) {
- Player* player = (Player*)player_spawn;
- player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
- if (!more_to_increase) {
- Client* client = player->GetClient();
- if (client) {
- EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- }
- else {
- lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
- }
- }
- else {
- lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_GetSkill(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string name = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
- if (skill) {
- lua_interface->SetSkillValue(state, skill);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_AddProc(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- float chance = lua_interface->GetFloatValue(state, 3);
- Item* item = lua_interface->GetItem(state, 4);
- bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
- LuaSpell* spell = 0;
- if (!item)
- spell = lua_interface->GetCurrentSpell(state);
-
- if (!spawn && (!spell || !use_all_spelltargets)) {
- lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!item && !spell) {
- lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(spell && spell->resisted) {
- return 0;
- }
-
- if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
- Spawn* target;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- ((Entity*)target)->AddProc(type, chance, item, spell);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else
- ((Entity*)spawn)->AddProc(type, chance, item, spell);
- return 0;
- }
- int EQ2Emu_lua_AddProcExt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- int8 damage_type = lua_interface->GetInt8Value(state, 3);
- float chance = lua_interface->GetFloatValue(state, 4);
- int8 hp_ratio = lua_interface->GetInt8Value(state, 5);
- bool below_health = lua_interface->GetBooleanValue(state, 6);
- bool target_health = lua_interface->GetBooleanValue(state, 7);
- Item* item = lua_interface->GetItem(state, 8);
- bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 9) == 1);
- bool extended_version = true;
- LuaSpell* spell = 0;
- if (!item)
- spell = lua_interface->GetCurrentSpell(state);
- if (!spawn && (!spell || !use_all_spelltargets)) {
- lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!item && !spell) {
- lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(spell && spell->resisted) {
- return 0;
- }
-
- if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
- Spawn* target;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- ((Entity*)target)->AddProc(type, chance, item, spell, damage_type, hp_ratio, below_health, target_health, extended_version);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else
- ((Entity*)spawn)->AddProc(type, chance, item, spell);
- return 0;
- }
- int EQ2Emu_lua_RemoveProc(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Item* item = lua_interface->GetItem(state, 2);
- LuaSpell* spell = 0;
- if (!item)
- spell = lua_interface->GetCurrentSpell(state);
-
- lua_interface->ResetFunctionStack(state);
- if (!item && !spell) {
- lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell && spell->caster && spell->caster->GetZone()) {
- Spawn* target;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- ((Entity*)target)->RemoveProc(item, spell);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- spell->caster->RemoveProc(item, spell);
- }
- else if (!spawn) {
- lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- else if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
- return 0;
- }
- else {
- ((Entity*)spawn)->RemoveProc(item, spell);
- }
- return 0;
- }
- int EQ2Emu_lua_Knockback(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target_spawn = lua_interface->GetSpawn(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- int32 duration = lua_interface->GetInt32Value(state, 3);
- float vertical = lua_interface->GetFloatValue(state, 4);
- float horizontal = lua_interface->GetFloatValue(state, 5);
- bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
- lua_interface->ResetFunctionStack(state);
- if (!target_spawn) {
- lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn) {
- lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if ((vertical != 0 || horizontal != 0)) {
- if(spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
- if (packet) {
- packet->setDataByName("target_x", target_spawn->GetX());
- packet->setDataByName("target_y", target_spawn->GetY());
- packet->setDataByName("target_z", target_spawn->GetZ());
- packet->setDataByName("vertical_movement", vertical);
- packet->setDataByName("horizontal_movement", horizontal);
- if (use_heading)
- packet->setDataByName("use_player_heading", 1);
- client->QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- }
- else {
- spawn->SetKnockback(target_spawn, duration, vertical, horizontal);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_IsEpic(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
- return 1;
- }
- int EQ2Emu_lua_ProcDamage(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- string name = lua_interface->GetStringValue(state, 3);
- int8 dmg_type = lua_interface->GetInt8Value(state, 4);
- int32 low_damage = lua_interface->GetInt32Value(state, 5);
- int32 high_damage = lua_interface->GetInt32Value(state, 6);
- string success_msg = lua_interface->GetStringValue(state, 7);
- string effect_msg = lua_interface->GetStringValue(state, 8);
- lua_interface->ResetFunctionStack(state);
- if (!caster) {
- lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!caster->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (name.length() == 0) {
- lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
- return 0;
- }
- int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
- if (!lua_interface)
- return 0;
- string name = lua_interface->GetStringValue(state);
- lua_interface->ResetFunctionStack(state);
- if (name.length() == 0) {
- lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
- return 0;
- }
- Skill* skill = master_skill_list.GetSkillByName(name.c_str());
- if (!skill) {
- lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
- return 0;
- }
- lua_interface->SetInt32Value(state, skill->skill_id);
- return 1;
- }
- int EQ2Emu_lua_IsHeroic(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
- return 1;
- }
- int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!luaspell) {
- lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
- return 1;
- }
- int EQ2Emu_lua_IsBehind(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
- return 1;
- }
- int EQ2Emu_lua_IsFlanking(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
- return 1;
- }
- int EQ2Emu_lua_InFront(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
- return 1;
- }
- int EQ2Emu_lua_GetItemCount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, item->details.count);
- return 1;
- }
- int EQ2Emu_lua_SetItemCount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- Spawn* owner = lua_interface->GetSpawn(state, 2);
- int16 new_count = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!owner) {
- lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!owner->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (item->stack_count < new_count) {
- lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
- return 0;
- }
- if (new_count > 0) {
- item->details.count = new_count;
- item->save_needed = true;
- }
- else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
- ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
- else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
- ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
- else
- {
- lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)owner)->GetClient();
- if (!client)
- return 0;
- ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
- EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
- if (app)
- client->QueuePacket(app);
- return 0;
- }
- int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 time = lua_interface->GetInt32Value(state);
- string function = lua_interface->GetStringValue(state, 2);
- Spawn* caster = lua_interface->GetSpawn(state, 3);
- Spawn* target = lua_interface->GetSpawn(state, 4);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (time == 0) {
- lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- if (function.length() == 0) {
- lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell || (!spell->caster || !spell->caster->GetZone())) {
- lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- SpellScriptTimer* timer = new SpellScriptTimer;
- /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
- #ifdef WIN32
- ZeroMemory(timer, sizeof(SpellScriptTimer));
- #else
- bzero(timer, sizeof(SpellScriptTimer));
- #endif*/
- timer->caster = 0;
- timer->deleteWhenDone = false;
- timer->target = 0;
- timer->time = Timer::GetCurrentTime2() + time;
- timer->customFunction = function;
- timer->spell = spell;
- if (caster)
- timer->caster = caster->GetID();
- if (target)
- timer->target = target->GetID();
- spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
- return 0;
- }
- int EQ2Emu_lua_Resurrect(lua_State* state) {
- if (!lua_interface)
- return 0;
- float hp_perc = lua_interface->GetFloatValue(state);
- float power_perc = lua_interface->GetFloatValue(state, 2);
- bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
- Spawn* target = lua_interface->GetSpawn(state, 4);
- string heal_name = lua_interface->GetStringValue(state, 5);
- int8 crit_mod = lua_interface->GetInt32Value(state, 6);
- bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* caster = spell->caster;
- if (!caster) {
- lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = 0;
- PendingResurrection* rez = 0;
- ZoneServer* zone = spell->caster->GetZone();
- if (!target) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- if (spell->targets.size() > 0) {
- vector<int32> spell_targets = spell->targets;
- for (int8 i = 0; i < spell_targets.size(); i++) {
- target = zone->GetSpawnByID(spell_targets.at(i));
- if (!target)
- continue;
- if (!target->IsPlayer())
- continue;
- client = ((Player*)target)->GetClient();
- if (!client)
- continue;
- rez = client->GetCurrentRez();
- if (rez->active)
- continue;
- client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
- rez->active = true;
- rez->caster = caster;
- rez->expire_timer = new Timer;
- int32 duration = spell->spell->GetSpellDuration();
- rez->expire_timer->Start(duration * 100);
- rez->hp_perc = hp_perc;
- rez->mp_perc = power_perc;
- rez->range = spell->spell->GetSpellData()->range;
- rez->spell_name = spell->spell->GetName();
- if (heal_name.length() > 0)
- rez->heal_name = heal_name;
- else
- rez->heal_name = rez->spell_name;
- rez->no_calcs = no_calcs;
- rez->crit_mod = crit_mod;
- rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
- if (send_window)
- client->SendResurrectionWindow();
- else {
- target->GetZone()->ResurrectSpawn(target, client);
- rez->should_delete = true;
- }
- client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else {
- if(!target->IsPlayer())
- return 0;
-
- client = ((Player*)target)->GetClient();
- if (!client)
- return 0;
- rez = client->GetCurrentRez();
- if (rez->active)
- return 0;
- client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
- rez->active = true;
- rez->caster = caster;
- rez->expire_timer = new Timer;
- int32 duration = spell->spell->GetSpellDuration();
- rez->expire_timer->Start(duration * 100);
- rez->hp_perc = hp_perc;
- rez->mp_perc = power_perc;
- rez->range = spell->spell->GetSpellData()->range;
- rez->spell_name = spell->spell->GetName();
- if (heal_name.length() > 0)
- rez->heal_name = heal_name;
- else
- rez->heal_name = rez->spell_name;
- rez->no_calcs = no_calcs;
- rez->crit_mod = crit_mod;
- rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
- if (send_window)
- client->SendResurrectionWindow();
- else {
- target->GetZone()->ResurrectSpawn(target, client);
- rez->should_delete = true;
- }
- client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_SetVision(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 vision = lua_interface->GetInt32Value(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int8 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target && target->IsEntity()) {
- ((Entity*)target)->GetInfoStruct()->set_vision(vision);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- }
- else {
- ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_BlurVision(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float intensity = lua_interface->GetFloatValue(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int8 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target && target->IsEntity()) {
- ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- }
- else {
- ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int8 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target && target->IsEntity()) {
- ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- }
- else {
- ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- int8 type = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (type == 1)
- lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
- else if (type == 2)
- lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
- return 1;
- }
- int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target = lua_interface->GetSpawn(state);
- float val = lua_interface->GetFloatValue(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- // Added from Gangrenous post
- if (spell && spell->resisted)
- return 0;
- // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
- if (val > 1.0f)
- val = 1.0f - (val / 100.0f);
- if (spell && spell->spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int32 i = 0; i != spell->targets.size(); i++) {
- Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->SetSpeedMultiplier(val);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- }
- }
- else {
- if (target && target->IsEntity()) {
- ((Entity*)target)->SetSpeedMultiplier(val);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetIllusion(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 model = lua_interface->GetInt16Value(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (spell && spell->spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int32 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target)
- target->SetIllusionModel(model);
- }
- }
- else {
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->SetIllusionModel(model);
- }
- return 0;
- }
- int EQ2Emu_lua_ResetIllusion(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (spell && spell->spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int32 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target)
- target->SetIllusionModel(0);
- }
- }
- else {
- if (!spawn) {
- lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->SetIllusionModel(0);
- }
- return 0;
- }
- int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- float chance = lua_interface->GetFloatValue(state, 3);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!caster) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!caster->IsEntity()) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (chance <= 0) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(spell->resisted) {
- return 0;
- }
- if (((Entity*)caster)->GetThreatTransfer()) {
- return 0;
- }
- ThreatTransfer* transfer = new ThreatTransfer;
- transfer->Target = target->GetID();
- transfer->Amount = chance;
- transfer->Spell = spell;
- ((Entity*)caster)->SetThreatTransfer(transfer);
- return 0;
- }
- int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn || !spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell) {
- lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
- ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
- if(transfer && transfer->Spell != spell) {
- lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Entity*)spawn)->SetThreatTransfer(nullptr);
- }
- return 0;
- }
- int EQ2Emu_lua_CureByType(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- int8 cure_count = lua_interface->GetInt8Value(state);
- int8 cure_type = lua_interface->GetInt8Value(state, 2);
- string cure_name = lua_interface->GetStringValue(state, 3);
- int8 cure_level = lua_interface->GetInt8Value(state, 4);
- Spawn* target = lua_interface->GetSpawn(state, 5);
- Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
- lua_interface->ResetFunctionStack(state);
-
- if(spell && spell->resisted) {
- return 0;
- }
-
- if (target) {
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
- std::string alternate_name = "item";
- if(spell)
- alternate_name = std::string(spell->spell->GetName());
-
- if(!caster && spell)
- caster = (Spawn*)spell->caster;
-
- ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
- }
- }
- else {
- ZoneServer* zone = spell->caster->GetZone();
- vector<int32> targets = spell->targets;
- vector<Entity*> targets_to_cure;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < targets.size(); i++) {
- target = zone->GetSpawnByID(targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
- targets_to_cure.push_back((Entity*)target);
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
-
- vector<Entity*>::iterator itr;
- for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
- ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
-
- if(spell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- int8 cure_count = lua_interface->GetInt8Value(state);
- int8 cure_type = lua_interface->GetInt8Value(state, 2);
- string cure_name = lua_interface->GetStringValue(state, 3);
- int8 cure_level = lua_interface->GetInt8Value(state, 4);
- Spawn* target = lua_interface->GetSpawn(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (target) {
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((Entity*)target)->GetDetCount() > 0)
- ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
- }
- else {
- ZoneServer* zone = spell->caster->GetZone();
- vector<int32> targets = spell->targets;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < targets.size(); i++) {
- target = zone->GetSpawnByID(targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- if (((Entity*)target)->GetDetCount() > 0)
- ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_CancelSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell->caster) {
- lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell->caster->GetZone()) {
- lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
- return 0;
- }
- spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
- return 0;
- }
- int EQ2Emu_lua_RemoveStealth(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn && spawn->IsEntity())
- ((Entity*)spawn)->RemoveStealthSpell(spell);
- else {
- ZoneServer* zone = spell->caster->GetZone();
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- spawn = zone->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- ((Entity*)spawn)->RemoveStealthSpell(spell);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveInvis(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn && spawn->IsEntity())
- ((Entity*)spawn)->RemoveInvisSpell(spell);
- else {
- ZoneServer* zone = spell->caster->GetZone();
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- spawn = zone->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- ((Entity*)spawn)->RemoveInvisSpell(spell);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state);
- int8 class_id = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!caster) {
- lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!caster->IsPlayer()) {
- lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
- return 0;
- }
- Spawn* target = caster->GetTarget();
- if (!target) {
- lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)caster)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
- return 0;
- }
- HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
- if (ho) {
- ho->SetTarget(target->GetID());
- LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
- LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
- if (((Entity*)caster)->GetGroupMemberInfo()) {
- if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>::iterator itr;
- PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
- if (group)
- {
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- for (itr = members->begin(); itr != members->end(); itr++) {
- if ((*itr)->client)
- ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- else
- safe_delete(ho);
- }
- else {
- if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
- ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
- }
- else
- safe_delete(ho);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
- return 0;
- }
- int16 triggerCount = lua_interface->GetInt16Value(state);
- bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
- if (!triggerCount) {
- lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
- return 0;
- }
- spell->num_triggers = triggerCount;
- spell->had_triggers = true;
- spell->cancel_after_all_triggers = cancel_after_triggers;
- return 0;
- }
- int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, spell->num_triggers);
- return 1;
- }
- int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- if (!spell->caster || !spell->caster->GetZone()) {
- lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int16 remove_count = lua_interface->GetInt16Value(state);
- lua_interface->ResetFunctionStack(state);
-
- if (!remove_count)
- remove_count = 1;
- if (remove_count >= spell->num_triggers) {
- spell->num_triggers = 0;
- if (spell->cancel_after_all_triggers)
- spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
- }
- else {
- spell->num_triggers -= remove_count;
- Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
- ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
- }
- return 0;
- }
- int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!copy_spawn) {
- lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->CopySpawnAppearance(copy_spawn);
- return 0;
- }
- int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
- return 0;
- }
- else if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
- return 0;
- }
-
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
- return 1;
- }
- int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- int8 type = lua_interface->GetInt8Value(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(spell->resisted) {
- return 0;
- }
- if (spawn) {
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* entity = ((Entity*)spawn);
- entity->AddImmunity(spell, type);
- }
- else if(spell->caster && spell->caster->GetZone()) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- Entity* entity = ((Entity*)spawn);
- entity->AddImmunity(spell, type);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- int8 type = lua_interface->GetInt8Value(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn) {
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* entity = ((Entity*)spawn);
- entity->RemoveImmunity(spell, type);
- }
- else if(spell->caster && spell->caster->GetZone()) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- Entity* entity = ((Entity*)spawn);
- entity->RemoveImmunity(spell, type);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if(spell && spell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- float snare = lua_interface->GetFloatValue(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- // convert the val to the speed multipler value (100 - val)
- float val = 100.0 - snare;
- val /= 100.0;
- if (spawn) {
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Entity*)spawn)->SetSnareValue(spell, val);
- }
- else if(spell && spell->caster && spell->caster->GetZone()) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- ((Entity*)spawn)->SetSnareValue(spell, val);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_CheckRaceType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 race_id = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (race_id == 0) {
- lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
- return 1;
- }
- int EQ2Emu_lua_GetRaceType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
- return 1;
- }
- int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
- return 1;
- }
- int EQ2Emu_lua_GetSpellName(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetStringValue(state, spell->spell->GetName());
- return 1;
- }
- int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, quest->GetQuestFlags());
- return 1;
- }
- int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 flags = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetQuestFlags(flags);
- return 0;
- }
- int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- int32 step = lua_interface->GetInt32Value(state, 3);
- int32 duration = lua_interface->GetInt32Value(state, 4);
- string action = lua_interface->GetStringValue(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step == 0) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (duration == 0) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (action.length() == 0) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetTimerStep(step);
- quest->AddFailedAction(step, action);
- quest->SetStepTimer(duration);
- client->AddQuestTimer(quest->GetQuestID());
- return 0;
- }
- int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player) {
- lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetTimerStep(0);
- quest->SetStepTimer(0);
- client->RemoveQuestTimer(quest->GetQuestID());
- return 0;
- }
- int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- Quest* quest = lua_interface->GetQuest(state, 2);
- int32 step = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!quest) {
- lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step == 0) {
- lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (quest->RemoveQuestStep(step, client)) {
- client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
- client->GetCurrentZone()->SendQuestUpdates(client);
- }
- else
- lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
- return 0;
- }
- int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state, 1);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string desc = lua_interface->GetStringValue(state, 3);
- string task_group = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step == 0) {
- lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- QuestStep* quest_step = quest->GetQuestStep(step);
- if (!quest_step) {
- lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
- return 0;
- }
- quest_step->SetStepProgress(0);
- quest_step->SetTaskGroup(task_group);
- quest_step->SetDescription(desc);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string action = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step == 0) {
- lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (action.length() == 0) {
- lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->AddFailedAction(step, action);
- return 0;
- }
- int EQ2Emu_lua_SetStepFailed(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int32 step = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (quest_id == 0) {
- lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step == 0) {
- lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- Quest* quest = ((Player*)player)->GetQuest(quest_id);
- if (!quest) {
- lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
- return 0;
- }
- quest->StepFailed(step);
- return 0;
- }
- int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (quest_id == 0) {
- lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
- return 1;
- }
- int EQ2Emu_lua_SetServerVariable(lua_State* state) {
- if (!lua_interface)
- return 0;
- string name = lua_interface->GetStringValue(state);
- string value = lua_interface->GetStringValue(state, 2);
- string comment = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (name.length() == 0) {
- lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (value.length() == 0) {
- lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- string varname = string("lua_").append(name);
- Variable* var = variables.FindVariable(varname);
- if (var)
- var->SetValue(value.c_str());
- else {
- var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
- variables.AddVariable(var);
- }
- database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
- return 0;
- }
- int EQ2Emu_lua_GetServerVariable(lua_State* state) {
- if (!lua_interface)
- return 0;
- string name = lua_interface->GetStringValue(state);
- lua_interface->ResetFunctionStack(state);
- if (name.length() == 0) {
- lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- string varname = string("lua_").append(name);
- Variable* var = variables.FindVariable(varname);
- if (var)
- lua_interface->SetStringValue(state, var->GetValue());
- else
- lua_interface->SetStringValue(state, "NULL");
- return 1;
- }
- int EQ2Emu_lua_HasLanguage(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 language_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
- return 1;
- }
- int EQ2Emu_lua_AddLanguage(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 language_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
- return 0;
- }
- Language* language = master_languages_list.GetLanguage(language_id);
- if (language)
- {
- ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
- ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
- }
- return 0;
- }
- int EQ2Emu_lua_IsNight(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (!zone) {
- lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, zone->IsDusk());
- return 1;
- }
- int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsWidget()) {
- lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Widget*)spawn)->SetMultiFloorLift(true);
- if (spawn->GetZone())
- spawn->GetZone()->AddTransportSpawn(spawn);
- return 0;
- }
- int EQ2Emu_lua_StartAutoMount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 path = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (path == 0) {
- lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
- return 0;
- }
- client->SendFlightAutoMount(path);
- return 0;
- }
- int EQ2Emu_lua_EndAutoMount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- if (!player) {
- lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
- return 0;
- }
- client->EndAutoMount();
- return 0;
- }
- int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
- return 1;
- }
- int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 event_id = lua_interface->GetInt32Value(state, 2);
- int32 value = lua_interface->GetInt32Value(state, 3);
- int32 value2 = lua_interface->GetInt32Value(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
- return 0;
- }
- int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 event_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
- if (!hd)
- return 0;
- lua_interface->SetInt32Value(state, hd->Value);
- lua_interface->SetInt32Value(state, hd->Value2);
- return 2;
- }
- int EQ2Emu_lua_SetGridID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 grid = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (grid == 0) {
- lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->SetLocation(grid);
- return 0;
- }
- int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 event_id = lua_interface->GetInt32Value(state, 2);
- int32 value1 = lua_interface->GetInt32Value(state, 3);
- int32 value2 = lua_interface->GetInt32Value(state, 4);
- bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
- int16 flag_override = lua_interface->GetInt16Value(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- //Add this quest to the list of required quests for this spawn
- spawn->SetRequiredHistory(event_id, value1, value2);
- //If private spawn value set
- if (private_spawn) {
- //Set the spawn to be private when not granted access via history
- spawn->AddAllowAccessSpawn(spawn);
- spawn->SetPrivateQuestSpawn(true);
- }
- //This value will override vis_flags in the vis packet
- if (flag_override > 0)
- spawn->SetQuestsRequiredOverride(flag_override);
- return 0;
- }
- int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int32 step_id = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
- return 1;
- }
- int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int8 level = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (level == 0) {
- lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
- return 0;
- }
- int EQ2Emu_lua_AddCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 amount = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (amount == 0) {
- lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Player*)player)->AddCoins(amount);
- return 0;
- }
- int EQ2Emu_lua_RemoveCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 amount = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (amount == 0) {
- lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
- return 1;
- }
- int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (!zone) {
- lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- vector<Entity*> players = zone->GetPlayers();
- if (players.size() == 0)
- return 0;
- lua_createtable(state, players.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < players.size(); i++) {
- lua_interface->SetSpawnValue(state, players.at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- return 1;
- }
- int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state, 1);
- if (!zone) {
- lua_interface->LogError("%s: LUA SpawnGroupByID command error: zone is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 group_id = lua_interface->GetInt32Value(state, 2);
- int16 custom_level = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
-
- //Map of <placement_id, location_id>
- map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
- map<int32, int32>::iterator itr;
- vector<Spawn*> group;
- Spawn* leader = 0;
- if(locs == nullptr)
- return 0;
-
- for (itr = locs->begin(); itr != locs->end(); itr++) {
- SpawnLocation* location = zone->GetSpawnLocation(itr->second);
- if (!location) {
- lua_interface->LogError("%s: LUA SpawnGroupByID command error: no location found for group id %u and the given ID (%u)", lua_interface->GetScriptName(state), group_id, itr->second);
- return 0;
- }
-
- int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
-
- Spawn* spawn = 0;
- if (location->entities[rand_number]) {
- if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
- spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
- spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
- spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
- spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
- spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
- if(spawn && spawn->IsOmittedByDBFlag())
- {
- LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[rand_number]->spawn_id);
- safe_delete(spawn);
- continue;
- }
- if (spawn) {
- if(!leader)
- leader = spawn;
- if(leader)
- leader->AddSpawnToGroup(spawn);
-
- spawn->SetSpawnGroupID(group_id);
-
- if(custom_level > 0 && custom_level != 0xFFFF) {
- spawn->SetLevel(custom_level);
- }
-
- const char* script = 0;
- for (int x = 0; x < 3; x++) {
- switch (x) {
- case 0:
- script = world.GetSpawnEntryScript(location->entities[rand_number]->spawn_entry_id);
- break;
- case 1:
- script = world.GetSpawnLocationScript(location->entities[rand_number]->spawn_location_id);
- break;
- case 2:
- script = world.GetSpawnScript(location->entities[rand_number]->spawn_id);
- break;
- }
- if (script && lua_interface->GetSpawnScript(script) != 0) {
- spawn->SetSpawnScript(string(script));
- break;
- }
- }
- zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- lua_interface->SetSpawnValue(state, spawn);
- group.push_back(spawn);
- }
- else {
- LogWrite(ZONE__ERROR, 0, "Zone", "%s: Error adding spawn by group id to zone %s with location id %u.", lua_interface->GetScriptName(state), zone->GetZoneName(), group_id);
- safe_delete(spawn);
- }
- }
- }
- if (!group.empty()) {
- lua_createtable(state, group.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < group.size(); i++) {
- lua_interface->SetSpawnValue(state, group[i]);
- lua_rawseti(state, newTable, i + 1);
- }
- }
- else
- lua_pushnil(state);
- return 1;
- }
- int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state, 1);
- int32 anim_id = lua_interface->GetInt32Value(state, 2);
- int16 leeway = lua_interface->GetInt16Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (anim_id == 0) {
- lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (leeway == 0)
- leeway = 5000;
- spawn->SetSpawnAnim(anim_id);
- spawn->SetSpawnAnimLeeway(leeway);
- return 0;
- }
- int EQ2Emu_lua_GetClientVersion(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!player || !player->IsPlayer()) {
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- return 0;
- }
- lua_interface->SetInt32Value(state, client->GetVersion());
- return 1;
- }
- int EQ2Emu_lua_GetItemID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, item->details.item_id);
- return 1;
- }
- int EQ2Emu_lua_IsEntity(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->IsEntity());
- return 1;
- }
- int EQ2Emu_lua_GetOrigX(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
- return 1;
- }
- int EQ2Emu_lua_GetOrigY(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
- return 1;
- }
- int EQ2Emu_lua_GetOrigZ(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
- return 1;
- }
- int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float pct = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (pct == 0) {
- lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
- lua_interface->SetInt32Value(state, amount);
- return 1;
- }
- int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float pct = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (pct == 0) {
- lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
- lua_interface->SetInt32Value(state, amount);
- return 1;
- }
- int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
- return 1;
- }
- int EQ2Emu_lua_Evac(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target = lua_interface->GetSpawn(state);
- if (target) {
- float x = target->GetZone()->GetSafeX();
- float y = target->GetZone()->GetSafeY();
- float z = target->GetZone()->GetSafeZ();
- float h = target->GetZone()->GetSafeHeading();
- target->SetX(x);
- target->SetY(y);
- target->SetZ(z);
- target->SetHeading(h);
- target->SetSpawnOrigX(x);
- target->SetSpawnOrigY(y);
- target->SetSpawnOrigZ(z);
- target->SetSpawnOrigHeading(h);
- if (target->IsPlayer()) {
- Client* client = ((Player*)target)->GetClient();
- if (client) {
- client->GetCurrentZone()->ClearHate(client->GetPlayer());
-
- int numargs = lua_interface->GetNumberOfArgs(state);
- if(numargs == 4) {
- x = lua_interface->GetFloatValue(state,1);
- y = lua_interface->GetFloatValue(state,2);
- z = lua_interface->GetFloatValue(state,3);
- h = lua_interface->GetFloatValue(state,4);
- }
- client->SetReloadingZone(true);
- target->SetX(x);
- target->SetY(y);
- target->SetZ(z);
- target->SetHeading(h);
- target->SetSpawnOrigX(x);
- target->SetSpawnOrigY(y);
- target->SetSpawnOrigZ(z);
- target->SetSpawnOrigHeading(h);
- target->SetAppearancePosition(x,y,z);
-
- client->SetZoningCoords(x,y,z,h);
- PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
- if (packet)
- {
- packet->setDataByName("x", x);
- packet->setDataByName("y", y);
- packet->setDataByName("z", z);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
-
- client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
- }
- }
- lua_interface->ResetFunctionStack(state);
- }
- else {
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
-
- if(!spell || !spell->caster || !spell->caster->GetZone()) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- ZoneServer* zone = spell->caster->GetZone();
-
- float x = spell->caster->GetZone()->GetSafeX();
- float y = spell->caster->GetZone()->GetSafeY();
- float z = spell->caster->GetZone()->GetSafeZ();
- float h = spell->caster->GetZone()->GetSafeHeading();
- int numargs = lua_interface->GetNumberOfArgs(state);
-
- if(numargs == 4) {
- x = lua_interface->GetFloatValue(state,1);
- y = lua_interface->GetFloatValue(state,2);
- z = lua_interface->GetFloatValue(state,3);
- h = lua_interface->GetFloatValue(state,4);
- }
-
- lua_interface->ResetFunctionStack(state);
-
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
- if (!target2)
- continue;
- if (target2->IsPlayer()) {
- Client* client = ((Player*)target2)->GetClient();
- if (client) {
- client->GetCurrentZone()->ClearHate(client->GetPlayer());
-
- client->SetReloadingZone(true);
- target2->SetX(x);
- target2->SetY(y);
- target2->SetZ(z);
- target2->SetHeading(h);
- target2->SetSpawnOrigX(x);
- target2->SetSpawnOrigY(y);
- target2->SetSpawnOrigZ(z);
- target2->SetSpawnOrigHeading(h);
- target2->SetAppearancePosition(x,y,z);
-
- client->SetZoningCoords(x,y,z,h);
-
- PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
- if (packet)
- {
- packet->setDataByName("x", x);
- packet->setDataByName("y", y);
- packet->setDataByName("z", z);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
-
- client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
- }
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpellTier(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!luaspell || !luaspell->spell) {
- lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- int8 tier = luaspell->spell->GetSpellTier();
- lua_interface->SetInt32Value(state, tier);
- return 1;
- }
- int EQ2Emu_lua_GetSpellID(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!luaspell || !luaspell->spell) {
- lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 spell_id = luaspell->spell->GetSpellID();
- lua_interface->SetInt32Value(state, spell_id);
- return 1;
- }
- int EQ2Emu_lua_StartTransmute(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state, 1);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ZoneServer* zone = spawn->GetZone();
- if (!zone) {
- return 0;
- }
- Client* client = ((Player*)spawn)->GetClient();
- if (!client) {
- return 0;
- }
- Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
- return 0;
- }
- int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state, 1);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ZoneServer* zone = spawn->GetZone();
- if (!zone) {
- return 0;
- }
- Client* client = ((Player*)spawn)->GetClient();
- if (!client) {
- return 0;
- }
- Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
- return 0;
- }
- int EQ2Emu_lua_ProcHate(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- int32 threat_amt = lua_interface->GetInt32Value(state, 3);
- string spell_name = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!caster) {
- lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!caster->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
- caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
- return 0;
- }
- int EQ2Emu_lua_GiveExp(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 amount = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if (player && player->IsPlayer() && amount > 0) {
- ((Player*)player)->AddXP(amount);
- }
- return 0;
- }
- int EQ2Emu_lua_DisplayText(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- string text = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (!client || text.length() == 0) {
- lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
- return 0;
- }
- client->SimpleMessage(type, text.c_str());
- return 0;
- }
- int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (!client || !spawn) {
- lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
- return 0;
- }
- vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
- if (!items) {
- lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
- return 0;
- }
- client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
- return 0;
- }
- int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawnref = lua_interface->GetSpawn(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn_id > 0 && spawnref) {
- vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
- if (spawns.size() == 0) {
- lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
- return 0;
- }
- Spawn* spawn = 0;
- int16 index = MakeRandomInt(0, spawns.size());
- if (index >= spawns.size() || index < 0)
- index = 0;
- spawn = spawns[index];
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- else {
- lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
- Spawn* player = lua_interface->GetSpawn(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- string name = lua_interface->GetStringValue(state, 3);
- float distance = lua_interface->GetFloatValue(state, 4);
- string command = lua_interface->GetStringValue(state, 5);
- string error_text = lua_interface->GetStringValue(state, 6);
- int16 cast_time = lua_interface->GetInt16Value(state, 7);
- int32 spell_visual = lua_interface->GetInt32Value(state, 8);
- lua_interface->ResetFunctionStack(state);
- if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
- if (distance == 0)
- distance = 10.0f;
- if (command.length() == 0)
- command = name;
- vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
- if (spawns.size() == 0) {
- lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
- return 0;
- }
- Spawn* spawn = 0;
- for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
- spawn = *itr;
- if (spawn) {
- spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
- player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int8 goal_num = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && player->GetZone())
- client = ((Player*)player)->GetClient();
- else{
- lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
- return 0;
- }
- if (client) {
- PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
- if (packet) {
- packet->setDataByName("goal_num", goal_num);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && player->GetZone())
- client = ((Player*)player)->GetClient();
- else {
- lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
- return 0;
- }
- if (client && client->GetVersion() >= 374) {
- client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
- }
- return 0;
- }
- int EQ2Emu_lua_InstructionWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- float duration = lua_interface->GetFloatValue(state, 2);
- string text = lua_interface->GetStringValue(state, 3);
- string voice = lua_interface->GetStringValue(state, 4);
- int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
- int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
- string signal = lua_interface->GetStringValue(state, 7);
- string goal1 = lua_interface->GetStringValue(state, 8);
- string task1 = lua_interface->GetStringValue(state, 9);
- string goal2 = lua_interface->GetStringValue(state, 10);
- string task2 = lua_interface->GetStringValue(state, 11);
- string goal3 = lua_interface->GetStringValue(state, 12);
- string task3 = lua_interface->GetStringValue(state, 13);
- string goal4 = lua_interface->GetStringValue(state, 14);
- string task4 = lua_interface->GetStringValue(state, 15);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
- return 0;
- }
- else
- client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("LUA InstructionWindow command error: could not find client");
- return 0;
- }
- if (text.length() == 0) {
- lua_interface->LogError("LUA InstructionWindow required parameters not given");
- return 0;
- }
- if (duration >= 0 && duration < 2)
- duration = 2;
- PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
- if (packet) {
- packet->setDataByName("open_seconds_max", duration);
- packet->setDataByName("text", text.c_str());
- packet->setDataByName("voice", voice.c_str());
- int8 num_goals = 1;
- if (task2.length() > 0)
- num_goals++;
- if (task3.length() > 0)
- num_goals++;
- if (task4.length() > 0)
- num_goals++;
- packet->setArrayLengthByName("num_goals", num_goals);
- for (int8 i = 0; i < num_goals; i++) {
- packet->setSubArrayLengthByName("num_tasks", 1, i);
- }
- if (goal1.length() > 0)
- packet->setArrayDataByName("goal_text", goal1.c_str());
- if (goal2.length() > 0)
- packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
- if (goal3.length() > 0)
- packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
- if (goal4.length() > 0)
- packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
- packet->setSubArrayDataByName("task_text", task1.c_str());
- if (task2.length() > 0)
- packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
- if (task3.length() > 0)
- packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
- if (task4.length() > 0)
- packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
- packet->setDataByName("complete_sound", "click");
- packet->setDataByName("signal", signal.c_str());
- packet->setDataByName("voice_key1", voice_key1);
- packet->setDataByName("voice_key2", voice_key2);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_ShowWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- string window = lua_interface->GetStringValue(state, 2);
- int8 show = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
- return 0;
- }
- else
- client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("LUA ShowWindow command error: could not find client");
- return 0;
- }
- if (window.length() == 0) {
- lua_interface->LogError("LUA ShowWindow required parameters not given");
- return 0;
- }
- PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
- if (packet) {
- packet->setDataByName("window", window.c_str());
- packet->setDataByName("show", show);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
- //See GameEvents.txt for options that can be used for this function
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- string event_name = lua_interface->GetStringValue(state, 2);
- int8 enabled = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player || !player->IsPlayer()) {
- lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
- return 0;
- }
-
- client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("LUA EnableGameEvent error: could not find client");
- return 0;
- }
- PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
- if (packet) {
- packet->setDataByName("event_name", event_name.c_str());
- packet->setDataByName("enabled", enabled);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int8 step = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && step > 0) {
- ((Player*)player)->SetTutorialStep(step);
- }
- return 0;
- }
- int EQ2Emu_lua_FlashWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- string window = lua_interface->GetStringValue(state, 2);
- float flash_seconds = lua_interface->GetFloatValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
- return 0;
- }
- else
- client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("LUA FlashWindow command error: could not find client");
- return 0;
- }
- if (window.length() == 0) {
- lua_interface->LogError("LUA FlashWindow required parameters not given");
- return 0;
- }
- PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
- if (packet) {
- packet->setDataByName("window", window.c_str());
- packet->setDataByName("flash_seconds", flash_seconds);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_CheckLOS(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && target)
- return spawn->CheckLoS(target);
- return 0;
- }
- int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float x = lua_interface->GetFloatValue(state, 2);
- float y = lua_interface->GetFloatValue(state, 3);
- float z = lua_interface->GetFloatValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (spawn)
- return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
- return 0;
- }
- int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone)
- zone->SetExpansionFlag(xpackFlag);
- return 0;
- }
- int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone)
- zone->SetHolidayFlag(holidayFlag);
- return 0;
- }
- int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetCanBind(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool canbind = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone)
- zone->SetCanBind(canbind);
- return 0;
- }
- int EQ2Emu_lua_GetCanBind(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetCanBind());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetCanGate(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool cangate = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone)
- zone->SetCanGate(cangate);
- return 0;
- }
- int EQ2Emu_lua_GetCanGate(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetCanGate());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetCanEvac(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool canevac = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone)
- zone->SetCanEvac(canevac);
- return 0;
- }
- int EQ2Emu_lua_GetCanEvac(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetCanEvac());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 spawn_value = lua_interface->GetInt32Value(state, 2);
- int8 spawn_type = lua_interface->GetInt8Value(state, 3);
- float distance = lua_interface->GetFloatValue(state, 4);
- string in_range_function = lua_interface->GetStringValue(state, 5);
- string leaving_range_function = lua_interface->GetStringValue(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (spawn && distance > 0 && in_range_function.length() > 0)
- spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
- return 0;
- }
- int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && target)
- {
- if (spawn->IsPlayer() && target->IsEntity())
- {
- lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
- return 1;
- }
- else if (spawn->IsEntity() && target->IsEntity())
- {
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool val = (lua_interface->GetInt8Value(state, 2) == 1);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity())
- {
- ((Entity*)spawn)->SetSeeInvisSpell(val);
- if (spawn->IsPlayer())
- {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetSeeHide(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool val = (lua_interface->GetInt8Value(state, 2) == 1);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity())
- {
- ((Entity*)spawn)->SetSeeHideSpell(val);
- if (spawn->IsPlayer())
- {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
- {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- string command = lua_interface->GetStringValue(state, 3);
- bool val = (lua_interface->GetInt8Value(state, 4) == 1);
- lua_interface->ResetFunctionStack(state);
- if (spawn && player && player->IsPlayer())
- {
- EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
- bool res = false;
- if (cmd)
- res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
- lua_interface->SetBooleanValue(state, res);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
- {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 charID = lua_interface->GetInt32Value(state, 2);
- string command = lua_interface->GetStringValue(state, 3);
- bool val = (lua_interface->GetInt8Value(state, 4) == 1);
- lua_interface->ResetFunctionStack(state);
- if (spawn && charID)
- {
- EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
- bool res = false;
- if (cmd)
- res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
- lua_interface->SetBooleanValue(state, res);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
- {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string command = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && command.length() > 0)
- spawn->RemovePrimaryEntityCommand(command.c_str());
- return 0;
- }
- int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float distance = lua_interface->GetFloatValue(state, 2);
- string command = lua_interface->GetStringValue(state, 3);
- Spawn* player = lua_interface->GetSpawn(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
- }
- return 0;
- }
- int EQ2Emu_lua_SendTransporters(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- int32 transport_id = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (spawn && player && transport_id && player->IsPlayer()) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (!client)
- return 0;
- vector<TransportDestination*> destinations;
- player->GetZone()->GetTransporters(&destinations, client, transport_id);
- if (destinations.size())
- {
- client->SetTemporaryTransportID(transport_id);
- client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
- }
- else
- client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
- }
- return 0;
- }
- int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 transport_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (!client)
- return 0;
- client->SetTemporaryTransportID(transport_id);
- }
- return 0;
- }
- int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (!client)
- return 0;
- lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetAlignment(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 alignment = lua_interface->GetSInt32Value(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
- {
- 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);
- return 0;
- }
- lua_interface->ResetFunctionStack(state);
- if (spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int8 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target && target->IsEntity()) {
- ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- }
- else {
- ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_GetAlignment(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
-
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
-
- lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
- return 1;
- }
- int EQ2Emu_lua_GetSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 spell_id = lua_interface->GetInt32Value(state);
- int8 spell_tier = lua_interface->GetInt8Value(state, 2);
- string custom_lua_script = lua_interface->GetStringValue(state, 3);
- if (spell_id > 0) {
- if (spell_tier == 0)
- spell_tier = 1;
- Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
-
- if(!spell) {
- lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- LuaSpell* lua_spell = 0;
- if(custom_lua_script.size() > 0)
- {
- // attempt to load the custom script since it isn't already loaded
- // we will re-obtain the lua_spell further below
- if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
- {
- 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());
- }
- }
- else
- custom_lua_script = spell->GetSpellData()->lua_script;
-
- if (!lua_spell && lua_interface)
- lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
- lua_interface->ResetFunctionStack(state);
-
- if (!lua_spell)
- {
- LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
- return 0;
- }
- lua_spell->spell = new Spell(spell);
- lua_interface->AddCustomSpell(lua_spell);
- lua_interface->SetSpellValue(state, lua_spell);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpellData(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- string field = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
- return 0;
- }
- boost::to_lower(field);
- return spell->spell->GetSpellData(state, field);
- }
- int EQ2Emu_lua_SetSpellData(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- string field = lua_interface->GetStringValue(state, 2);
- int8 fieldArg = 3; // field value after the initial set
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- boost::to_lower(field);
- bool valSet = false;
- spell->spell->SetSpellData(state, field, fieldArg);
- lua_interface->ResetFunctionStack(state);
- return valSet;
- }
- int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- int8 idx = lua_interface->GetInt32Value(state, 2);
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (spell->spell->lua_data.size() <= idx)
- {
- lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- bool setVal = true;
- LUAData* data = spell->spell->lua_data[idx];
- switch (data->type)
- {
- case 0:
- {
- sint32 value = lua_interface->GetSInt32Value(state, 3);
- sint32 value2 = lua_interface->GetSInt32Value(state, 4);
- data->int_value = value;
- data->int_value2 = value2;
- break;
- }
- case 1:
- {
- float value = lua_interface->GetFloatValue(state, 3);
- float value2 = lua_interface->GetFloatValue(state, 4);
- data->float_value = value;
- data->float_value2 = value2;
- break;
- }
- case 2:
- {
- bool value = lua_interface->GetBooleanValue(state, 3);
- data->bool_value = value;
- break;
- }
- case 3:
- {
- string value = lua_interface->GetStringValue(state, 3);
- string value2 = lua_interface->GetStringValue(state, 4);
- data->string_value = value;
- data->string_value2 = value2;
- break;
- }
- default:
- setVal = false;
- }
-
- lua_interface->ResetFunctionStack(state);
- return setVal;
- }
- int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- int8 idx = lua_interface->GetInt32Value(state, 2);
- bool secondfield = lua_interface->GetBooleanValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell->spell->lua_data.size() <= idx)
- {
- lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
- return 0;
- }
- bool setVal = true;
- LUAData* data = spell->spell->lua_data[idx];
- switch (data->type)
- {
- case 0:
- {
- if(!secondfield)
- lua_interface->SetSInt32Value(state, data->int_value);
- else
- lua_interface->SetSInt32Value(state, data->int_value2);
- break;
- }
- case 1:
- {
- if (!secondfield)
- lua_interface->SetFloatValue(state, data->float_value);
- else
- lua_interface->SetFloatValue(state, data->float_value2);
- break;
- }
- case 2:
- {
- lua_interface->SetBooleanValue(state, data->bool_value);
- break;
- }
- case 3:
- {
- if (!secondfield)
- lua_interface->SetStringValue(state, data->string_value.c_str());
- else
- lua_interface->SetStringValue(state, data->string_value2.c_str());
- break;
- }
- default:
- setVal = false;
- }
- return setVal;
- }
- int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- int8 idx = lua_interface->GetInt32Value(state, 2);
- string field = lua_interface->GetStringValue(state, 3);
- boost::to_lower(field);
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (spell->spell->effects.size() <= idx)
- {
- lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- // do we need to lock? eh probably not this should only be used before use of the custom spell
- SpellDisplayEffect* effect = spell->spell->effects[idx];
- if (field == "description")
- effect->description = string(lua_interface->GetStringValue(state, 4));
- else if (field == "bullet")
- effect->subbullet = lua_interface->GetInt8Value(state, 4);
- else if (field == "percentage")
- effect->percentage = lua_interface->GetInt8Value(state, 4);
- else { // no match
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- lua_interface->ResetFunctionStack(state);
-
- return 1;
- }
- int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- int8 idx = lua_interface->GetInt32Value(state, 2);
- string field = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
-
- boost::to_lower(field);
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell->spell->effects.size() <= idx)
- {
- lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
- return 0;
- }
- // do we need to lock? eh probably not this should only be used before use of the custom spell
- SpellDisplayEffect* effect = spell->spell->effects[idx];
- if (field == "description")
- lua_interface->SetStringValue(state, effect->description.c_str());
- else if (field == "bullet")
- lua_interface->SetInt32Value(state, effect->subbullet);
- else if (field == "percentage")
- lua_interface->SetInt32Value(state, effect->percentage);
- else // no match
- return 0;
- return 1;
- }
- int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- Spawn* caster = lua_interface->GetSpawn(state, 2);
- Spawn* target = lua_interface->GetSpawn(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!target) {
- lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
- return 0;
- }
- if (!spell) {
- lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (caster && !caster->IsEntity()) {
- lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
- return 0;
- }
- target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
- return 0;
- }
- int EQ2Emu_lua_InWater(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->InWater());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_InLava(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->InLava());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_DamageSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* attacker = lua_interface->GetSpawn(state);
- Spawn* victim = lua_interface->GetSpawn(state, 2);
- int8 type = lua_interface->GetInt8Value(state, 3);
- int8 dmg_type = lua_interface->GetInt8Value(state, 4);
- int32 low_damage = lua_interface->GetInt32Value(state, 5);
- int32 high_damage = lua_interface->GetInt32Value(state, 6);
- string spell_name = lua_interface->GetStringValue(state, 7);
- int8 crit_mod = lua_interface->GetInt8Value(state, 8);
- bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
- bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
- bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
- bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
- lua_interface->ResetFunctionStack(state);
- if (!attacker) {
- lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!attacker->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!victim) {
- lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!victim->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- bool has_damaged = ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker, take_power);
- lua_interface->SetBooleanValue(state, has_damaged);
- return 1;
- }
- int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool invul = lua_interface->GetBooleanValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetInvulnerable(invul);
- }
- return 0;
- }
- int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
- if (!lua_interface)
- return 0;
- string category = lua_interface->GetStringValue(state);
- string name = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- Rule *ret = 0;
- if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
-
- lua_interface->SetBooleanValue(state, ret->GetBool());
- return 1;
- }
-
- lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
- return 0;
- }
- int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
- if (!lua_interface)
- return 0;
- string category = lua_interface->GetStringValue(state);
- string name = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- Rule *ret = 0;
- if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
-
- lua_interface->SetInt32Value(state, ret->GetInt32());
- return 1;
- }
-
- lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
- return 0;
- }
- int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
- if (!lua_interface)
- return 0;
- string category = lua_interface->GetStringValue(state);
- string name = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- Rule *ret = 0;
- if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
-
- lua_interface->SetFloatValue(state, ret->GetFloat());
- return 1;
- }
-
- lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
- return 0;
- }
- int EQ2Emu_lua_GetAAInfo(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string type = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- int res = 1;
- boost::to_lower(type);
- if(type == "assigned_aa")
- lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
- else if ( type == "unassigned_aa")
- lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
- else if ( type == "assigned_tradeskill_aa")
- lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
- else if ( type == "unassigned_tradeskill_aa")
- lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
- else if ( type == "assigned_prestige_aa")
- lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
- else if ( type == "unassigned_prestige_aa")
- lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
- else if ( type == "assigned_tradeskill_prestige_aa")
- lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
- else if ( type == "unassigned_tradeskill_prestige_aa")
- lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
- else
- res = 0;
- return res;
- }
-
- lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_SetAAInfo(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string type = lua_interface->GetStringValue(state, 2);
- sint32 value = lua_interface->GetSInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- boost::to_lower(type);
- if(type == "assigned_aa")
- spawn->SetAssignedAA((sint16)value);
- else if ( type == "unassigned_aa")
- spawn->SetUnassignedAA((sint16)value);
- else if ( type == "assigned_tradeskill_aa")
- spawn->SetTradeskillAA((sint16)value);
- else if ( type == "unassigned_tradeskill_aa")
- spawn->SetUnassignedTradeskillAA((sint16)value);
- else if ( type == "assigned_prestige_aa")
- spawn->SetPrestigeAA((sint16)value);
- else if ( type == "unassigned_prestige_aa")
- spawn->SetUnassignedPrestigeAA((sint16)value);
- else if ( type == "assigned_tradeskill_prestige_aa")
- spawn->SetTradeskillPrestigeAA((sint16)value);
- else if ( type == "unassigned_tradeskill_prestige_aa")
- spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
- if(spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
- if (!lua_interface)
- return 0;
- string titleName = lua_interface->GetStringValue(state);
- int8 isPrefix = lua_interface->GetInt8Value(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
- lua_interface->SetSInt32Value(state, index);
- return 1;
- }
- int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string titleName = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
- lua_interface->SetSInt32Value(state, -1);
- return 1;
- }
- Player* player = (Player*)spawn;
- // check if player already has the title, don't need to add twice
- Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
- if ( playerHasTitle)
- {
- lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
- return 1;
- }
- Title* title = master_titles_list.GetTitleByName(titleName.c_str());
-
- if(!title)
- {
- lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
- lua_interface->SetSInt32Value(state, -1);
- return 1;
- }
-
- sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
- if(returnIdx < 0)
- {
- lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
- }
- lua_interface->SetSInt32Value(state, returnIdx);
- player->GetClient()->SendTitleUpdate();
- return 1;
- }
- int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string titleName = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- Player* player = (Player*)spawn;
- Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
-
- if(!title)
- {
- lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
- return 0;
- }
-
- if(title->GetPrefix())
- {
- 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());
- return 0;
- }
- database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
- player->GetClient()->SendTitleUpdate();
- return 1;
- }
- int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string titleName = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- Player* player = (Player*)spawn;
- Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
- if(!title)
- {
- lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
- return 0;
- }
-
- if(!title->GetPrefix())
- {
- 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());
- return 0;
- }
-
- database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
- player->GetClient()->SendTitleUpdate();
- return 1;
- }
- int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn)
- {
- lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: spawn is null", lua_interface->GetScriptName(state));
- return 0;
- }
- if(!spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- Player* player = (Player*)spawn;
- database.SaveCharSuffixIndex(-1, player->GetCharacterID());
- player->GetClient()->SendTitleUpdate();
- return 1;
- }
- int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
-
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn)
- {
- lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: spawn is null", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(!spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- Player* player = (Player*)spawn;
- database.SaveCharPrefixIndex(-1, player->GetCharacterID());
- player->GetClient()->SendTitleUpdate();
- return 1;
- }
- int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- 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));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
- return 1;
- }
- int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- 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));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
- return 1;
- }
- int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- 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));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
- return 1;
- }
- int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- 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));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
- return 1;
- }
- int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
- string value = lua_interface->GetStringValue(state, 3);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- 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));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- bool set_ = ent->SetInfoStructString(field, value);
- lua_interface->SetBooleanValue(state, set_);
- return 1;
- }
- int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
- int64 value = lua_interface->GetInt64Value(state, 3);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- 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));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- bool set_ = ent->SetInfoStructUInt(field, value);
- lua_interface->SetBooleanValue(state, set_);
- return 1;
- }
- int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
- sint64 value = lua_interface->GetSInt64Value(state, 3);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- 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));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- bool set_ = ent->SetInfoStructSInt(field, value);
- lua_interface->SetBooleanValue(state, set_);
- return 1;
- }
- int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
- float value = lua_interface->GetFloatValue(state, 3);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- 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));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- bool set_ = ent->SetInfoStructFloat(field, value);
- lua_interface->SetBooleanValue(state, set_);
- return 1;
- }
- int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool value = lua_interface->GetBooleanValue(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn || !spawn->IsPlayer())
- {
- 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));
- return 0;
- }
-
- ((Player*)spawn)->SetCharSheetChanged(value);
- return 0;
- }
- int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- std::string fromName = lua_interface->GetStringValue(state, 2);
- std::string subjectName = lua_interface->GetStringValue(state, 3);
- std::string mailBody = lua_interface->GetStringValue(state, 4);
- int8 mailType = lua_interface->GetInt8Value(state, 5);
- int32 copper = lua_interface->GetInt32Value(state, 6);
- int32 silver = lua_interface->GetInt32Value(state, 7);
- int32 gold = lua_interface->GetInt32Value(state, 8);
- int32 platinum = lua_interface->GetInt32Value(state, 9);
-
- int32 item_id = lua_interface->GetInt32Value(state, 10);
- int16 stack_size = lua_interface->GetInt32Value(state, 11);
- int32 expire_time = lua_interface->GetInt32Value(state, 12);
-
- int32 sent_time = lua_interface->GetInt32Value(state, 13);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn || !spawn->IsPlayer())
- {
- 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));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
- ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 char_id = lua_interface->GetInt32Value(state);
- std::string fromName = lua_interface->GetStringValue(state, 2);
- std::string subjectName = lua_interface->GetStringValue(state, 3);
- std::string mailBody = lua_interface->GetStringValue(state, 4);
- int8 mailType = lua_interface->GetInt8Value(state, 5);
- int32 copper = lua_interface->GetInt32Value(state, 6);
- int32 silver = lua_interface->GetInt32Value(state, 7);
- int32 gold = lua_interface->GetInt32Value(state, 8);
- int32 platinum = lua_interface->GetInt32Value(state, 9);
-
- int32 item_id = lua_interface->GetInt32Value(state, 10);
- int16 stack_size = lua_interface->GetInt32Value(state, 11);
- int32 expire_time = lua_interface->GetInt32Value(state, 12);
-
- int32 sent_time = lua_interface->GetInt32Value(state, 13);
- lua_interface->ResetFunctionStack(state);
-
- int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
- Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_OpenDoor(lua_State* state) {
- Spawn* widget;
- if (lua_interface) {
- widget = lua_interface->GetSpawn(state);
- bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (widget && widget->IsWidget())
- {
- ((Widget*)widget)->OpenDoor();
- if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
- widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
- }
- else
- 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));
- }
- return 0;
- }
- int EQ2Emu_lua_CloseDoor(lua_State* state) {
- Spawn* widget;
- if (lua_interface) {
- widget = lua_interface->GetSpawn(state);
- bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if (widget && widget->IsWidget())
- {
- ((Widget*)widget)->CloseDoor();
- if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
- widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
- }
- else
- 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));
- }
- return 0;
- }
- int EQ2Emu_lua_IsOpen(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* widget = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (widget && widget->IsWidget())
- {
- lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- sint32 min = lua_interface->GetSInt32Value(state);
- sint32 max = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- sint32 result = MakeRandomInt(min, max);
- lua_interface->SetSInt32Value(state, result);
- return 1;
- }
- int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
- if (!lua_interface)
- return 0;
- float min = lua_interface->GetFloatValue(state);
- float max = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- float result = MakeRandomFloat(min, max);
- lua_interface->SetFloatValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_AddIconValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 value = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn)
- {
- lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- spawn->AddIconValue(value);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 value = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn)
- {
- lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- spawn->RemoveIconValue(value);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_GetShardID(lua_State* state) {
- Spawn* npc = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (npc && npc->IsNPC()) {
- NPC* shard = (NPC*)npc;
- int32 shardid = shard->GetShardID();
- lua_interface->SetInt32Value(state, shardid);
- return 1;
- }
- lua_interface->SetInt32Value(state, 0);
- return 1;
- }
- int EQ2Emu_lua_GetShardCharID(lua_State* state) {
- Spawn* npc = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (npc && npc->IsNPC()) {
- NPC* shard = (NPC*)npc;
- int32 charid = shard->GetShardCharID();
- lua_interface->SetInt32Value(state, charid);
- return 1;
- }
- lua_interface->SetInt32Value(state, 0);
- return 1;
- }
- int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
- Spawn* npc = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (npc && npc->IsNPC()) {
- NPC* shard = (NPC*)npc;
- int64 timestamp = shard->GetShardCreatedTimestamp();
- lua_interface->SetSInt64Value(state, timestamp);
- return 1;
- }
- lua_interface->SetSInt64Value(state, 0);
- return 1;
- }
- int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 shardid = lua_interface->GetInt32Value(state);
- lua_interface->ResetFunctionStack(state);
- if(shardid < 1)
- lua_interface->SetBooleanValue(state, false);
- else
- lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
- return 1;
- }
- int EQ2Emu_lua_PauseMovement(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
- if (spawn) {
- spawn->PauseMovement(delay_in_ms);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_StopMovement(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- spawn->ResetMovement();
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_GetArrowColor(lua_State* state) {
- Player* player = (Player*)lua_interface->GetSpawn(state);
- int8 level = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && level > 0) {
- lua_interface->SetInt32Value(state, player->GetArrowColor(level));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
- Player* player = (Player*)lua_interface->GetSpawn(state);
- int8 level = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && level > 0) {
- lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- Spawn* spawn = zone->GetTransportByRailID(rail_id);
- if (spawn) {
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetRailID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- bool res = false;
- if(spawn && spawn->IsTransportSpawn())
- {
- //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
- spawn->SetRailID(rail_id);
- res = true;
- }
- else if (!spawn) {
- lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
- }
- else if(!spawn->IsTransportSpawn()) {
- 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());
- }
- lua_interface->SetBooleanValue(state, res);
- return 1;
- }
- int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetBooleanValue(state, zone->IsLoading());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_IsRunning(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->IsRunning());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 zoneID = lua_interface->GetInt32Value(state, 2);
- bool displayClient = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player || !player->IsPlayer() || !player->GetClient()) {
- lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
- }
- else if(!zoneID) {
- lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
- }
- else
- {
- lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetWorldTime(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- int16 newYear = lua_interface->GetInt16Value(state, 1);
- sint32 newMonth = lua_interface->GetInt16Value(state, 2);
- int16 newHour = lua_interface->GetInt16Value(state, 3);
- int16 newMinute = lua_interface->GetInt16Value(state, 4);
- lua_interface->ResetFunctionStack(state);
-
- world.MWorldTime.writelock(__FUNCTION__, __LINE__);
- world.GetWorldTimeStruct()->year = newYear;
- world.GetWorldTimeStruct()->month = newMonth;
- world.GetWorldTimeStruct()->hour = newHour;
- world.GetWorldTimeStruct()->minute = newMinute;
- world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
-
- return 0;
- }
- int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- lua_interface->ResetFunctionStack(state);
-
- world.MWorldTime.readlock(__FUNCTION__, __LINE__);
- lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
- world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
-
- return 1;
- }
- int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- lua_interface->ResetFunctionStack(state);
-
- world.MWorldTime.readlock(__FUNCTION__, __LINE__);
- lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
- world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
-
- return 1;
- }
- int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- lua_interface->ResetFunctionStack(state);
-
- world.MWorldTime.readlock(__FUNCTION__, __LINE__);
- lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
- world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
-
- return 1;
- }
- int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- lua_interface->ResetFunctionStack(state);
-
- world.MWorldTime.readlock(__FUNCTION__, __LINE__);
- lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
- world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
-
- return 1;
- }
- int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
- if (!lua_interface)
- return 0;
- lua_interface->ResetFunctionStack(state);
-
- world.SendTimeUpdate();
-
- return 0;
- }
- int EQ2Emu_lua_ChangeFaction(lua_State* state) {
- bool update_result = false;
- Faction* faction = 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 faction_id = lua_interface->GetInt32Value(state, 2);
- sint32 increase = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsPlayer()) {
- lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
- return 0;
- }
- Player* player = (Player*)spawn;
- Client* client = player->GetClient();
- if (faction_id > 0) {
- bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
- if(hasfaction == 0) {
- //they do not have the faction. Lets get the default value and feed it in.
- sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
- //add the default faction for the player.
- player->SetFactionValue(faction_id, defaultfaction);
- }
- if(increase >= 0) {
- update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
- faction = master_faction_list.GetFaction(faction_id);
- if(faction && update_result)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
-
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- if(increase < 0){
- //change the negative to a positive, since thats how decreasefaction() likes it.
- increase *= -1;
- update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
- faction = master_faction_list.GetFaction(faction_id);
- if(faction && update_result)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
-
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_HasCoin(lua_State* state) {
- bool hascoin = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 coins = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if (player && player->IsPlayer()) {
- hascoin = ((Player*)player)->HasCoins(coins);
- if(hascoin == 0) {
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if(hascoin == 1) {
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetLootTier(lua_State* state) {
- int32 loot_tier = 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- loot_tier = spawn->GetLootTier();
- lua_interface->SetInt32Value(state, loot_tier);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetLootTier(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 loot_tier = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if (spawn) {
- spawn->SetLootTier(loot_tier);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_GetLootDropType(lua_State* state) {
- int32 loot_drop_type = 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- loot_drop_type = spawn->GetLootDropType();
- lua_interface->SetInt32Value(state, loot_drop_type);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetLootDropType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if (spawn) {
- spawn->SetLootDropType(loot_drop_type);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 damage_amount = lua_interface->GetInt32Value(state, 2);
- if(damage_amount > 100) {
- damage_amount = 100;
- }
-
- if (!spawn) {
- lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- lua_interface->ResetFunctionStack(state);
- if (spawn->IsPlayer()) {
- if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
- lua_interface->SetBooleanValue(state, true);
- else
- lua_interface->SetBooleanValue(state, false);
- }
- else {
- lua_interface->SetBooleanValue(state, false);
- }
-
- return 1;
- }
- int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 version = lua_interface->GetInt32Value(state, 2);
-
- RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
- if(region_map == nullptr) {
- lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- string region_name = lua_interface->GetStringValue(state, 3);
- string env_name = lua_interface->GetStringValue(state, 4);
- int32 grid_id = lua_interface->GetInt32Value(state, 5);
- int32 widget_id = lua_interface->GetInt32Value(state, 6);
- float dist = lua_interface->GetFloatValue(state, 7);
- region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
-
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_RemoveRegion(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 version = lua_interface->GetInt32Value(state, 2);
-
- RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
- if(region_map == nullptr) {
- lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- string region_name = lua_interface->GetStringValue(state, 3);
- region_map->RemoveRegionNode(region_name);
-
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
- Client* client = nullptr;
- Spawn* player = lua_interface->GetSpawn(state);
- if (!player) {
- lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
- lua_interface->SetBooleanValue(state, false);
- lua_interface->ResetFunctionStack(state);
- return 1;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
- lua_interface->SetBooleanValue(state, false);
- lua_interface->ResetFunctionStack(state);
- return 1;
- }
- client = player->GetClient();
- if (!client) {
- lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
- lua_interface->SetBooleanValue(state, false);
- lua_interface->ResetFunctionStack(state);
- return 1;
- }
-
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
-
- bool success_sight = client->SetPlayerPOVGhost(spawn);
-
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, success_sight);
- return 1;
- }
- int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- bool result = false;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
- lua_interface->ResetFunctionStack(state);
- if (!spawn)
- lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsNPC())
- lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
- else
- {
- ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
- result = true;
- }
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- bool result = false;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn)
- lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsNPC())
- lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
- else
- {
- if(((NPC*)spawn)->cast_on_aggro_completed)
- result = true;
- }
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
- Client* client = nullptr;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- client = player->GetClient();
- if (!client) {
- lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- bool result = client->AddRecipeBookToPlayer(recipe_book_id);
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
- Client* client = nullptr;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 recipe_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- client = player->GetClient();
- if (!client) {
- lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- bool result = client->RemoveRecipeFromPlayer(recipe_id);
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
- Client* client = nullptr;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 widget_id = lua_interface->GetInt32Value(state, 2);
- bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
-
- // rest are all optional fields
- float x = lua_interface->GetFloatValue(state, 4);
- float y = lua_interface->GetFloatValue(state, 5);
- float z = lua_interface->GetFloatValue(state, 6);
- int32 grid_id = lua_interface->GetInt32Value(state, 7);
-
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if(!player->GetZone()) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- client = player->GetClient();
- if (!client) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if(!client->IsReadyForUpdates()) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
-
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
- Client* client = nullptr;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 widget_id = lua_interface->GetInt32Value(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if(!spawn->GetZone()) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- spawn->AddIgnoredWidget(widget_id);
-
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 widget_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!zone) {
- lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- if(!zone->IsLoading()) {
- lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- zone->AddIgnoredWidget(widget_id);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_SendHearCast(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
- int16 cast_time = lua_interface->GetInt16Value(state, 3);
- Spawn* caster = lua_interface->GetSpawn(state, 4);
- Spawn* target = lua_interface->GetSpawn(state, 5);
- lua_interface->ResetFunctionStack(state);
- if(spell && spawn && spawn->IsEntity()) {
- ZoneServer* zone = spawn->GetZone();
- if(zone) {
- zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
- }
- }
- else if (spawn) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- bool ret = ((Player*)player)->get_character_flag(flag_id);
- lua_interface->SetBooleanValue(state, ret);
- return 1;
- }
- int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Player*)player)->toggle_character_flag(flag_id);
- return 0;
- }
- int EQ2Emu_lua_GetSpellInitialTarget(lua_State* state) {
- LuaSpell* spell = lua_interface->GetSpell(state);
-
- if(!spell) {
- spell = lua_interface->GetCurrentSpell(state);
- }
-
- lua_interface->ResetFunctionStack(state);
- if (spell) {
- if(!spell->caster) {
- lua_interface->LogError("%s: LUA GetSpellTarget command error, caster does not exist.", lua_interface->GetScriptName(state));
- return 0;
- }
- if(!spell->caster->GetZone()) {
- lua_interface->LogError("%s: LUA GetSpellTarget command error, zone does not exist.", lua_interface->GetScriptName(state));
- return 0;
- }
- Spawn* spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
- if (spawn) {
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- else {
- lua_interface->LogError("%s: LUA GetSpellTarget command error, could not find initial target %u to map to spawn.", lua_interface->GetScriptName(state), spell->initial_target);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_DespawnByLocationID(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 location_id = lua_interface->GetInt32Value(state, 2);
- int32 delay = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- Spawn* spawn = zone->GetSpawnByLocationID(location_id);
- if (spawn) {
- vector<Spawn*> groupMembers;
- if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
- groupMembers = *spawn->GetSpawnGroup();
- for (int32 i = 0; i < groupMembers.size(); i++) {
- Spawn* member = groupMembers.at(i);
- if(member && !member->IsPlayer() && member != spawn) {
- member->GetZone()->Despawn(member, delay);
- }
- }
- }
-
- zone->Despawn(spawn, delay);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
|