123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461 |
- /*
- 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() > 546 )
- 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*>* spawnList = lua_interface->GetSpawnList(state);
- int32 position = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawnList) {
- if (spawnList->size() > position) {
- lua_interface->SetSpawnValue(state, spawnList->at(position));
- return 1;
- }
- else {
- return 0;
- }
- return spawnList->size();
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
- lua_interface->ResetFunctionStack(state);
- if (spawnList) {
- return spawnList->size();
- }
- return 0;
- }
- int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<Spawn*>* spawnList = new vector<Spawn*>();
- lua_interface->SetSpawnListValue(state, spawnList);
- return 1;
- }
- int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawnList) {
- auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
- if (it == spawnList->end())
- spawnList->push_back(spawn);
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawnList) {
- auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
- if(it != spawnList->end())
- spawnList->erase(it);
- }
- return 0;
- }
- 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) {
- vector<Spawn*>* spawnList = new vector<Spawn*>();
- vector<Spawn*>::iterator itr;
- for (itr = spawns.begin(); itr != spawns.end(); itr++) {
- spawnList->push_back(*itr);
- }
- lua_interface->SetSpawnListValue(state, spawnList);
- 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) {
- vector<Spawn*>* spawnList = new vector<Spawn*>();
- vector<Spawn*>::iterator itr;
- for (itr = spawns.begin(); itr != spawns.end(); itr++) {
- spawnList->push_back(*itr);
- }
- lua_interface->SetSpawnListValue(state, spawnList);
- 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) {
- 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);
- 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);
- 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);
- }
- }
- }
- safe_delete(conversation);
- lua_interface->SetConversationValue(state, NULL);
- 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);
- safe_delete(conversation);
- lua_interface->SetConversationValue(state, NULL);
- }
- 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) {
- 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) {
- 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);
- else {
- string zone_name = lua_interface->GetStringValue(state);
- if (zone_name.length() > 0) {
- zone = zone_list.Get(zone_name.c_str());
- }
- 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);
-
- if(!luaspell || luaspell->resisted) {
- return 0;
- }
-
- if (entity && entity->IsEntity() && amount != 0) {
- if (luaspell) {
- 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()) {
- ((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())
- ((NPC*)npc)->AddHate((Entity*)entity, amount);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_Zone(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- 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);
- 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));
- lua_interface->ResetFunctionStack(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);
- 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) {
- return 0;
- }
- 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;
- }
- }
- 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();
- }
- }
- }
- return 0;
- }
- 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->SetPower(spawn->GetPower() + value);
- if (value > spawn->GetTotalHPBase())
- spawn->SetTotalPower(spawn->GetTotalPower() + 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->SetHP(spawn->GetHP() + value);
- if (value > spawn->GetTotalHPBase())
- spawn->SetTotalHP(spawn->GetTotalHP() + 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);
- float value = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && value > 0)
- ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
- if (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);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && value > 0)
- ((Entity*)spawn)->AddSpellBonus(0, 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
-
- 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);
- 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);
- if (luaspell && luaspell->spell) {
- 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()) {
- ((Entity*)target)->RemoveSpellBonus(luaspell);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- 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) {
- 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);
- if (spawn && spawn->IsPlayer()) {
- int32 spell_id = 0;
- if (luaspell && luaspell->spell) {
- 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);
-
- 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);
- if (spawn && spawn->IsEntity()) {
- if (!only_remove_spawn && luaspell && luaspell->spell) {
- 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);
- 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;
- 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;
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(0, 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;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float value = lua_interface->GetFloatValue(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(0, 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);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(0, 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);
- float value = lua_interface->GetFloatValue(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(0, 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);
- float value = lua_interface->GetFloatValue(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(0, 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);
- 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);
- 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);
- 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);
- 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);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetLevel());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(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);
- 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);
- 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;
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- if (!player || !player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- 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;
- }
- int32 step = lua_interface->GetInt32Value(state, 3);
- 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);
- 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);
- 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);
- 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);
- if (quest) {
- int8 level = lua_interface->GetInt16Value(state, 2);
- quest->SetPrereqLevel(level);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- if (quest) {
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- quest->AddPrereqQuest(quest_id);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- if (quest) {
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int8 quantity = lua_interface->GetInt32Value(state, 3);
- 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);
- if(!player || !player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- if (quest_id > 0) {
- lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
- 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)->GetCompletedQuest(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()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- 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()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- 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()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- 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()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- 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()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- 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()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- 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()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- 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()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- 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()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- 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()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- 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);
- /* if (quest->GetPlayer()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- if (client)
- client->SendQuestUpdateStep(quest, step, false);
- }*/
- }
- 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);
- /*if (quest->GetPlayer()) {
- Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
- if (client)
- client->SendQuestUpdateStepImmediately(quest, step);
- }*/
- }
- 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_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_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->IsPlayer())
- ((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());
- 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());
- 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));
- zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- }*/
- // Get a random pet name
- 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);
- // 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(random_pet_name);
- 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(random_pet_name.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);
- // 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);
- // 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()->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;
- }
- Spawn* spawn = 0;
- if (location->entities[0]) {
- if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
- spawn = zone->AddNPCSpawn(location, location->entities[0]);
- else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
- spawn = zone->AddGroundSpawn(location, location->entities[0]);
- else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
- spawn = zone->AddObjectSpawn(location, location->entities[0]);
- else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
- spawn = zone->AddWidgetSpawn(location, location->entities[0]);
- else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
- spawn = zone->AddSignSpawn(location, location->entities[0]);
- 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;
- 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 (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;
- }
- if (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);
- return 1;
- }
- }
- 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);
-
- if (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);
- return 1;
- }
- }
- 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* player = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- Item* item = ((Player*)player)->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));
- zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- }*/
- // Get a random pet name
- 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);
- // Set the pets name
- pet->SetName(random_pet_name.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);
- 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 (!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->GetCurrentSpell(state);
- 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 && 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_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 (!spawn) {
- lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 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) {
- 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
- ((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 (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
- 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);
- }
- 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_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) {
- 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);
- int8 vision = lua_interface->GetInt8Value(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) {
- lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", 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) {
- lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- 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;
- }
- 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 {
- 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 {
- 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) {
- lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- if(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 {
- 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;
- }
- Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
- if (!quest) {
- lua_interface->SetInt32Value(state, 0);
- return 1;
- }
- lua_interface->SetInt32Value(state, quest->GetCompleteCount());
- 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());
- }
- 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->SetPos(&(spawn->appearance.pos.grid_id), 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 GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 group_id = lua_interface->GetInt32Value(state, 2);
- 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;
- for (itr = locs->begin(); itr != locs->end(); itr++) {
- SpawnLocation* location = zone->GetSpawnLocation(itr->second);
- if (!location) {
- lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
- return 0;
- }
- Spawn* spawn = 0;
- if (location->entities[0]) {
- if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
- spawn = zone->AddNPCSpawn(location, location->entities[0]);
- else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
- spawn = zone->AddGroundSpawn(location, location->entities[0]);
- else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
- spawn = zone->AddObjectSpawn(location, location->entities[0]);
- else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
- spawn = zone->AddWidgetSpawn(location, location->entities[0]);
- else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
- spawn = zone->AddSignSpawn(location, location->entities[0]);
- 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[0]->spawn_id);
- safe_delete(spawn);
- continue;
- }
- 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);
- group.push_back(spawn);
- }
- else {
- LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", 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) {
- 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) {
- 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) {
- 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->Loot(spawn->GetLootCoins(), items, spawn);
- 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->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* player = lua_interface->GetSpawn(state);
- ZoneServer* zone = player->GetZone();
- bool canbind = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone)
- zone->SetCanBind(canbind);
- return 0;
- }
- int EQ2Emu_lua_GetCanBind(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- ZoneServer* zone = player->GetZone();
- lua_interface->ResetFunctionStack(state);
- 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* player = lua_interface->GetSpawn(state);
- ZoneServer* zone = player->GetZone();
- bool cangate = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone)
- zone->SetCanGate(cangate);
- return 0;
- }
- int EQ2Emu_lua_GetCanGate(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- ZoneServer* zone = player->GetZone();
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetCanGate());
- 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);
- 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());
- lua_interface->LoadLuaSpell(custom_lua_script);
- }
- }
- else
- custom_lua_script = spell->GetSpellData()->lua_script;
-
- if (!lua_spell && lua_interface)
- lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
- 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);
- 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));
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
- return 0;
- }
- boost::to_lower(field);
- bool valSet = false;
- spell->spell->SetSpellData(state, field, fieldArg);
- 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));
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(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);
- 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;
- }
- 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);
- 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));
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(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);
- 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
- return 0;
- 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);
- 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);
- 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);
- lua_interface->ResetFunctionStack(state);
- if (!attacker) {
- lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!attacker->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!victim) {
- lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!victim->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
- return 0;
- }
- 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->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->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->StopMovement();
- }
- 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;
- Player* player = (Player*)lua_interface->GetSpawn(state);
- int32 coins = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if (player && player->IsPlayer()) {
- hascoin = 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));
- return 0;
- }
- 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);
- 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);
- 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);
- return 1;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- client = player->GetClient();
- if (!client) {
- lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
- lua_interface->SetBooleanValue(state, false);
- 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;
- }
|