LuaFunctions.cpp 286 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "../common/Log.h"
  29. #include <math.h>
  30. #include "HeroicOp/HeroicOp.h"
  31. #include "RaceTypes/RaceTypes.h"
  32. #include "ClientPacketFunctions.h"
  33. #include "Transmute.h"
  34. #include <boost/algorithm/string/predicate.hpp>
  35. extern WorldDatabase database;
  36. extern LuaInterface* lua_interface;
  37. extern ConfigReader configReader;
  38. extern MasterQuestList master_quest_list;
  39. extern MasterItemList master_item_list;
  40. extern MasterSpellList master_spell_list;
  41. extern World world;
  42. extern Commands commands;
  43. extern ZoneList zone_list;
  44. extern Races races;
  45. extern Classes classes;
  46. extern Variables variables;
  47. extern MasterSkillList master_skill_list;
  48. extern MasterHeroicOPList master_ho_list;
  49. extern MasterRaceTypeList race_types_list;
  50. extern MasterLanguagesList master_languages_list;
  51. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  52. if (!lua_interface)
  53. return 0;
  54. Spawn* spawn = lua_interface->GetSpawn(state);
  55. string mp3_string = lua_interface->GetStringValue(state, 2);
  56. string text_string = lua_interface->GetStringValue(state, 3);
  57. string emote_string = lua_interface->GetStringValue(state, 4);
  58. int32 key1 = lua_interface->GetInt32Value(state, 5);
  59. int32 key2 = lua_interface->GetInt32Value(state, 6);
  60. Spawn* player = lua_interface->GetSpawn(state, 7);
  61. int8 language = lua_interface->GetInt8Value(state, 8);
  62. if (spawn) {
  63. const char* mp3 = 0;
  64. const char* text = 0;
  65. const char* emote = 0;
  66. if (mp3_string.length() > 0)
  67. mp3 = mp3_string.c_str();
  68. if (text_string.length() > 0)
  69. text = text_string.c_str();
  70. if (emote_string.length() > 0)
  71. emote = emote_string.c_str();
  72. Client* client = 0;
  73. if (player && player->IsPlayer())
  74. client = spawn->GetZone()->GetClientBySpawn(player);
  75. if (client) {
  76. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  77. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  78. }
  79. else
  80. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  81. }
  82. return 0;
  83. }
  84. int EQ2Emu_lua_PlaySound(lua_State* state) {
  85. if (!lua_interface)
  86. return 0;
  87. Spawn* spawn = lua_interface->GetSpawn(state);
  88. string sound_string = lua_interface->GetStringValue(state, 2);
  89. float x = lua_interface->GetFloatValue(state, 3);
  90. float y = lua_interface->GetFloatValue(state, 4);
  91. float z = lua_interface->GetFloatValue(state, 5);
  92. Spawn* player = lua_interface->GetSpawn(state, 6);
  93. if (spawn && sound_string.length() > 0) {
  94. Client* client = 0;
  95. if (player && player->IsPlayer())
  96. client = spawn->GetZone()->GetClientBySpawn(player);
  97. if (client)
  98. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  99. else
  100. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  101. }
  102. return 0;
  103. }
  104. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  105. if (!lua_interface)
  106. return 0;
  107. Spawn* spawn = lua_interface->GetSpawn(state);
  108. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  109. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  110. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  111. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  112. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  113. if (!spawn) {
  114. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  115. return 0;
  116. }
  117. if (quest_id > 0) {
  118. //Add this quest to the list of required quests for this spawn
  119. spawn->SetQuestsRequired(quest_id, quest_step);
  120. //If private spawn value set
  121. if (private_spawn) {
  122. //Set the spawn to be private when not granted access through this quest
  123. spawn->AddAllowAccessSpawn(spawn);
  124. spawn->SetPrivateQuestSpawn(true);
  125. }
  126. //This value allows access after a quest step, or the whole quest has been completed
  127. if (continued_access)
  128. spawn->SetQuestsRequiredContinuedAccess(true);
  129. //This value will override vis_flags in the vis packet
  130. if (flag_override > 0)
  131. spawn->SetQuestsRequiredOverride(flag_override);
  132. }
  133. return 0;
  134. }
  135. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  136. if (!lua_interface)
  137. return 0;
  138. Spawn* spawn = lua_interface->GetSpawn(state);
  139. float max_distance = lua_interface->GetFloatValue(state, 2);
  140. string variable = lua_interface->GetStringValue(state, 3);
  141. string value = lua_interface->GetStringValue(state, 4);
  142. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  143. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  144. return 0;
  145. }
  146. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  147. if (!lua_interface)
  148. return 0;
  149. Client* client = 0;
  150. Spawn* player = lua_interface->GetSpawn(state);
  151. if (!player) {
  152. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  153. return 0;
  154. }
  155. if (!player->IsPlayer()) {
  156. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  157. return 0;
  158. }
  159. if (player->GetZone())
  160. client = player->GetZone()->GetClientBySpawn(player);
  161. if (!client) {
  162. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  163. return 0;
  164. }
  165. int16 value1 = lua_interface->GetInt16Value(state, 2);
  166. int16 value2 = lua_interface->GetInt16Value(state, 3);
  167. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  168. if (packet) {
  169. packet->setDataByName("unknown1", value1);
  170. packet->setDataByName("unknown2", value2);
  171. client->QueuePacket(packet->serialize());
  172. safe_delete(packet);
  173. }
  174. return 0;
  175. }
  176. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  177. if (!lua_interface)
  178. return 0;
  179. Spawn* dead = lua_interface->GetSpawn(state);
  180. Spawn* killer = lua_interface->GetSpawn(state, 2);
  181. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  182. if (dead && dead->Alive() && dead->GetZone())
  183. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  184. return 0;
  185. }
  186. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  187. if (!lua_interface)
  188. return 0;
  189. Spawn* spawn = lua_interface->GetSpawn(state);
  190. float max_distance = lua_interface->GetFloatValue(state, 2);
  191. bool include_players = lua_interface->GetInt8Value(state, 3);
  192. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  193. if (max_distance > 0 && spawn && spawn->GetZone())
  194. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  195. return 0;
  196. }
  197. int EQ2Emu_lua_Despawn(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 delay = lua_interface->GetInt32Value(state, 2);
  202. if (spawn && spawn->GetZone())
  203. spawn->GetZone()->Despawn(spawn, delay);
  204. return 0;
  205. }
  206. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  207. if (!lua_interface)
  208. return 0;
  209. Spawn* spawn = lua_interface->GetSpawn(state);
  210. string variable = lua_interface->GetStringValue(state, 2);
  211. string value = lua_interface->GetStringValue(state, 3);
  212. int32 type = commands.GetSpawnSetType(variable);
  213. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  214. commands.SetSpawnCommand(0, spawn, type, value.c_str());
  215. return 0;
  216. }
  217. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  218. if (!lua_interface)
  219. return 0;
  220. Spawn* spawn = lua_interface->GetSpawn(state);
  221. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  222. if (spawn && spawn_id > 0) {
  223. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  224. if (closest_spawn) {
  225. lua_interface->SetSpawnValue(state, closest_spawn);
  226. return 1;
  227. }
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. string variable_name = lua_interface->GetStringValue(state);
  235. Variable* var = variables.FindVariable(variable_name);
  236. if (var) {
  237. lua_interface->SetStringValue(state, var->GetValue());
  238. return 1;
  239. }
  240. return 0;
  241. }
  242. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  243. if (!lua_interface)
  244. return 0;
  245. int32 total_coins = lua_interface->GetInt32Value(state);
  246. if (total_coins == 0) {
  247. lua_interface->SetStringValue(state, "0 copper");
  248. return 1;
  249. }
  250. char tmp[64] = { 0 };
  251. string message = "";
  252. int32 val = 0;
  253. if (total_coins >= 1000000) {
  254. val = total_coins / 1000000;
  255. total_coins -= 1000000 * val;
  256. sprintf(tmp, " %u Platinum", val);
  257. message.append(tmp);
  258. memset(tmp, 0, 64);
  259. }
  260. if (total_coins >= 10000) {
  261. val = total_coins / 10000;
  262. total_coins -= 10000 * val;
  263. sprintf(tmp, " %u Gold", val);
  264. message.append(tmp);
  265. memset(tmp, 0, 64);
  266. }
  267. if (total_coins >= 100) {
  268. val = total_coins / 100;
  269. total_coins -= 100 * val;
  270. sprintf(tmp, " %u Silver", val);
  271. message.append(tmp);
  272. memset(tmp, 0, 64);
  273. }
  274. if (total_coins > 0) {
  275. sprintf(tmp, " %u Copper", (int32)total_coins);
  276. message.append(tmp);
  277. }
  278. lua_interface->SetStringValue(state, message.c_str());
  279. return 1;
  280. }
  281. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  282. ZoneServer* zone = lua_interface->GetZone(state);
  283. int32 group_id = lua_interface->GetInt32Value(state, 2);
  284. if (zone) {
  285. Spawn* spawn = zone->GetSpawnGroup(group_id);
  286. if (spawn) {
  287. lua_interface->SetSpawnValue(state, spawn);
  288. return 1;
  289. }
  290. }
  291. return 0;
  292. }
  293. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  294. ZoneServer* zone = lua_interface->GetZone(state);
  295. int32 location_id = lua_interface->GetInt32Value(state, 2);
  296. if (zone) {
  297. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  298. if (spawn) {
  299. lua_interface->SetSpawnValue(state, spawn);
  300. return 1;
  301. }
  302. }
  303. return 0;
  304. }
  305. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  306. Spawn* spawn = lua_interface->GetSpawn(state);
  307. if (spawn) {
  308. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  309. return 1;
  310. }
  311. return 0;
  312. }
  313. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  314. Spawn* spawn = lua_interface->GetSpawn(state);
  315. if (spawn) {
  316. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  317. return 1;
  318. }
  319. return 0;
  320. }
  321. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  322. Spawn* spawn = lua_interface->GetSpawn(state);
  323. if (spawn) {
  324. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  325. return 1;
  326. }
  327. return 0;
  328. }
  329. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  330. Spawn* spawn = lua_interface->GetSpawn(state);
  331. if (spawn) {
  332. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  333. return 1;
  334. }
  335. return 0;
  336. }
  337. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  338. Player* player = (Player*)lua_interface->GetSpawn(state);
  339. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  340. if (player && player->IsPlayer() && faction_id > 0) {
  341. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  342. return 1;
  343. }
  344. return 0;
  345. }
  346. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  347. if (!lua_interface)
  348. return 0;
  349. Spawn* spawn = lua_interface->GetSpawn(state);
  350. int32 value = lua_interface->GetInt32Value(state, 2);
  351. if (spawn) {
  352. spawn->SetFactionID(value);
  353. }
  354. return 0;
  355. }
  356. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. if (spawn) {
  359. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  360. return 1;
  361. }
  362. return 0;
  363. }
  364. int EQ2Emu_lua_GetGender(lua_State* state) {
  365. Spawn* spawn = lua_interface->GetSpawn(state);
  366. if (spawn) {
  367. lua_interface->SetInt32Value(state, spawn->GetGender());
  368. return 1;
  369. }
  370. return 0;
  371. }
  372. int EQ2Emu_lua_GetTarget(lua_State* state) {
  373. Spawn* spawn = lua_interface->GetSpawn(state);
  374. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  375. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  376. return 1;
  377. }
  378. return 0;
  379. }
  380. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  381. if (!lua_interface)
  382. return 0;
  383. Spawn* spawn = lua_interface->GetSpawn(state);
  384. string mp3_string = lua_interface->GetStringValue(state, 2);
  385. int32 key1 = lua_interface->GetInt32Value(state, 3);
  386. int32 key2 = lua_interface->GetInt32Value(state, 4);
  387. Spawn* player = lua_interface->GetSpawn(state, 5);
  388. if (spawn && mp3_string.length() > 0) {
  389. Client* client = 0;
  390. if (player && player->IsPlayer())
  391. client = spawn->GetZone()->GetClientBySpawn(player);
  392. if (client) {
  393. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  394. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  395. }
  396. else
  397. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  398. }
  399. return 0;
  400. }
  401. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  402. if (!lua_interface)
  403. return 0;
  404. Spawn* spawn = lua_interface->GetSpawn(state);
  405. if (spawn) {
  406. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  407. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  408. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  409. return 3;
  410. }
  411. return 0;
  412. }
  413. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. if (spawn && spawn->IsEntity()) {
  418. int32 item_id = lua_interface->GetInt32Value(state, 2);
  419. int16 charges = lua_interface->GetInt16Value(state, 3);
  420. if (charges == 0)
  421. charges = 1;
  422. ((Entity*)spawn)->AddLootItem(item_id, charges);
  423. }
  424. return 0;
  425. }
  426. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  427. if (!lua_interface)
  428. return 0;
  429. Spawn* spawn = lua_interface->GetSpawn(state);
  430. if (spawn && spawn->IsEntity()) {
  431. int32 item_id = lua_interface->GetInt32Value(state, 2);
  432. ((Entity*)spawn)->LootItem(item_id);
  433. }
  434. return 0;
  435. }
  436. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  437. if (!lua_interface)
  438. return 0;
  439. Spawn* spawn = lua_interface->GetSpawn(state);
  440. if (spawn && spawn->IsEntity()) {
  441. int32 val = lua_interface->GetInt32Value(state, 2);
  442. ((Entity*)spawn)->AddLootCoins(val);
  443. }
  444. return 0;
  445. }
  446. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  447. if (!lua_interface)
  448. return 0;
  449. Spawn* entity = lua_interface->GetSpawn(state);
  450. Spawn* player = lua_interface->GetSpawn(state, 2);
  451. if (entity && entity->IsEntity() && player && player->IsPlayer()) {
  452. int32 coins = lua_interface->GetInt32Value(state, 3);
  453. vector<Item*>* items = 0;
  454. int i = 0;
  455. int32 item_id = 0;
  456. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  457. if (items == 0)
  458. items = new vector<Item*>;
  459. if (master_item_list.GetItem(item_id))
  460. items->push_back(master_item_list.GetItem(item_id));
  461. i++;
  462. }
  463. Client* client = 0;
  464. client = entity->GetZone()->GetClientBySpawn(player);
  465. if (client) {
  466. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  467. client->Loot(coins, ((Player*)player)->GetPendingLootItems(entity->GetID()), (Entity*)entity);
  468. }
  469. safe_delete(items);
  470. }
  471. return 0;
  472. }
  473. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  474. if (!lua_interface)
  475. return 0;
  476. Spawn* entity = lua_interface->GetSpawn(state);
  477. Spawn* player = lua_interface->GetSpawn(state, 2);
  478. int32 item_id = lua_interface->GetInt32Value(state, 3);
  479. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  480. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  481. return 1;
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* entity = lua_interface->GetSpawn(state);
  489. Spawn* player = lua_interface->GetSpawn(state, 2);
  490. if (entity && entity->IsEntity() && player && player->IsPlayer()) {
  491. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  492. return 1;
  493. }
  494. return 0;
  495. }
  496. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  497. if (!lua_interface)
  498. return 0;
  499. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  500. safe_delete(conversation);
  501. conversation = new vector<ConversationOption>();
  502. lua_interface->SetConversationValue(state, conversation);
  503. return 1;
  504. }
  505. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  509. if (conversation) {
  510. ConversationOption conv_option;
  511. conv_option.option = lua_interface->GetStringValue(state, 2);
  512. conv_option.function = lua_interface->GetStringValue(state, 3);
  513. if (conv_option.option.length() > 0)
  514. conversation->push_back(conv_option);
  515. }
  516. return 0;
  517. }
  518. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  519. if (!lua_interface)
  520. return 0;
  521. Spawn* npc = lua_interface->GetSpawn(state);
  522. Spawn* player = lua_interface->GetSpawn(state, 2);
  523. if (npc && player && player->IsPlayer() && player->GetZone()) {
  524. Client* client = player->GetZone()->GetClientBySpawn(player);
  525. if (client) {
  526. int32 conversation_id = client->GetConversationID(npc, 0);
  527. client->CloseDialog(conversation_id);
  528. }
  529. }
  530. return 0;
  531. }
  532. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  533. if (!lua_interface)
  534. return 0;
  535. Item* item = lua_interface->GetItem(state);
  536. Spawn* player = lua_interface->GetSpawn(state, 2);
  537. if (item && player && player->IsPlayer() && player->GetZone()) {
  538. Client* client = player->GetZone()->GetClientBySpawn(player);
  539. if (client) {
  540. int32 conversation_id = client->GetConversationID(0, item);
  541. client->CloseDialog(conversation_id);
  542. }
  543. }
  544. return 0;
  545. }
  546. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  547. if (!lua_interface)
  548. return 0;
  549. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  550. Spawn* spawn = 0;
  551. Item* item = 0;
  552. int8 type = lua_interface->GetInt8Value(state, 2);
  553. if (type == 1 || type == 3)
  554. spawn = lua_interface->GetSpawn(state, 3);
  555. else if (type == 2 || type == 4)
  556. item = lua_interface->GetItem(state, 3);
  557. Spawn* player = lua_interface->GetSpawn(state, 4);
  558. string text = lua_interface->GetStringValue(state, 5);
  559. string mp3 = lua_interface->GetStringValue(state, 6);
  560. int32 key1 = lua_interface->GetInt32Value(state, 7);
  561. int32 key2 = lua_interface->GetInt32Value(state, 8);
  562. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  563. Client* client = player->GetZone()->GetClientBySpawn(player);
  564. if (client) {
  565. if (spawn) {
  566. // Need to do this so the function works the same as it did before
  567. if (type == 1)
  568. type++;
  569. if (mp3.length() > 0)
  570. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  571. else
  572. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  573. }
  574. else {
  575. if (mp3.length() > 0)
  576. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  577. else
  578. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  579. }
  580. }
  581. }
  582. safe_delete(conversation);
  583. lua_interface->SetConversationValue(state, NULL);
  584. return 0;
  585. }
  586. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  587. if(!lua_interface)
  588. return 0;
  589. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  590. Item* item = lua_interface->GetItem(state, 2);
  591. Spawn* player = lua_interface->GetSpawn(state, 3);
  592. string text = lua_interface->GetStringValue(state, 4);
  593. string mp3 = lua_interface->GetStringValue(state, 5);
  594. int32 key1 = lua_interface->GetInt32Value(state, 6);
  595. int32 key2 = lua_interface->GetInt32Value(state, 7);
  596. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  597. Client* client = player->GetZone()->GetClientBySpawn(player);
  598. if(client){
  599. if(mp3.length() > 0)
  600. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  601. else
  602. client->DisplayConversation(item, conversation, (char*)text.c_str());
  603. }
  604. safe_delete(conversation);
  605. }
  606. return 0;
  607. }*/
  608. int EQ2Emu_lua_StartConversation(lua_State* state) {
  609. if (!lua_interface)
  610. return 0;
  611. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  612. Spawn* npc = lua_interface->GetSpawn(state, 2);
  613. Spawn* player = lua_interface->GetSpawn(state, 3);
  614. string text = lua_interface->GetStringValue(state, 4);
  615. string mp3 = lua_interface->GetStringValue(state, 5);
  616. int32 key1 = lua_interface->GetInt32Value(state, 6);
  617. int32 key2 = lua_interface->GetInt32Value(state, 7);
  618. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  619. Client* client = npc->GetZone()->GetClientBySpawn(player);
  620. if (mp3.length() > 0)
  621. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  622. else
  623. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  624. safe_delete(conversation);
  625. lua_interface->SetConversationValue(state, NULL);
  626. }
  627. else
  628. 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.", npc ? npc->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  629. return 0;
  630. }
  631. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  632. if (!lua_interface)
  633. return 0;
  634. Spawn* spawn = lua_interface->GetSpawn(state);
  635. float distance = lua_interface->GetFloatValue(state, 2);
  636. string in_range_function = lua_interface->GetStringValue(state, 3);
  637. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  638. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  639. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  640. return 0;
  641. }
  642. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  643. ZoneServer* zone = lua_interface->GetZone(state);
  644. float x = lua_interface->GetFloatValue(state, 2);
  645. float y = lua_interface->GetFloatValue(state, 3);
  646. float z = lua_interface->GetFloatValue(state, 4);
  647. float max_variation = lua_interface->GetFloatValue(state, 5);
  648. string in_range_function = lua_interface->GetStringValue(state, 6);
  649. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  650. if (zone && in_range_function.length() > 0)
  651. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  652. return 0;
  653. }
  654. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. if (spawn && spawn->IsEntity()) {
  659. int32 val = lua_interface->GetInt32Value(state, 2);
  660. ((Entity*)spawn)->SetLootCoins(val);
  661. }
  662. return 0;
  663. }
  664. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  665. if (!lua_interface)
  666. return 0;
  667. Spawn* spawn = lua_interface->GetSpawn(state);
  668. if (spawn && spawn->IsEntity()) {
  669. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  670. return 1;
  671. }
  672. return 0;
  673. }
  674. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  675. if (!lua_interface)
  676. return 0;
  677. Spawn* spawn = lua_interface->GetSpawn(state);
  678. float x = lua_interface->GetFloatValue(state, 2);
  679. float y = lua_interface->GetFloatValue(state, 3);
  680. float z = lua_interface->GetFloatValue(state, 4);
  681. float speed = lua_interface->GetFloatValue(state, 5);
  682. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  683. string function = lua_interface->GetStringValue(state, 7);
  684. if (spawn) {
  685. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  686. spawn->GetZone()->AddMovementNPC(spawn);
  687. }
  688. lua_interface->ResetFunctionStack(state);
  689. return 0;
  690. }
  691. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  692. if (!lua_interface)
  693. return 0;
  694. Spawn* spawn = lua_interface->GetSpawn(state);
  695. if (spawn) {
  696. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  697. return 1;
  698. }
  699. return 0;
  700. }
  701. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  702. if (!lua_interface)
  703. return 0;
  704. Spawn* spawn = lua_interface->GetSpawn(state);
  705. Spawn* target = lua_interface->GetSpawn(state, 2);
  706. if (spawn && target) {
  707. if (spawn->IsEntity())
  708. // ((Entity*)spawn)->FaceTarget(target);
  709. static_cast<Entity*>(spawn)->FaceTarget(target);
  710. }
  711. lua_interface->ResetFunctionStack(state);
  712. return 0;
  713. }
  714. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  715. if (!lua_interface)
  716. return 0;
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. float x = lua_interface->GetFloatValue(state, 2);
  719. float y = lua_interface->GetFloatValue(state, 3);
  720. float z = lua_interface->GetFloatValue(state, 4);
  721. float speed = lua_interface->GetFloatValue(state, 5);
  722. string lua_function = lua_interface->GetStringValue(state, 6);
  723. bool more_points = lua_interface->GetBooleanValue(state, 7);
  724. if (spawn) {
  725. if (speed == 0)
  726. speed = spawn->GetSpeed();
  727. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  728. }
  729. lua_interface->ResetFunctionStack(state);
  730. return 0;
  731. }
  732. int EQ2Emu_lua_Say(lua_State* state) {
  733. if (!lua_interface)
  734. return 0;
  735. Spawn* spawn = lua_interface->GetSpawn(state);
  736. string message = lua_interface->GetStringValue(state, 2);
  737. Spawn* player = lua_interface->GetSpawn(state, 3);
  738. int32 language = lua_interface->GetInt32Value(state, 4);
  739. if (spawn && message.length() > 0) {
  740. Client* client = 0;
  741. if (player && player->IsPlayer())
  742. client = spawn->GetZone()->GetClientBySpawn(player);
  743. if (client)
  744. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  745. else
  746. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  747. }
  748. lua_interface->ResetFunctionStack(state);
  749. return 0;
  750. }
  751. int EQ2Emu_lua_Shout(lua_State* state) {
  752. if (!lua_interface)
  753. return 0;
  754. Spawn* spawn = lua_interface->GetSpawn(state);
  755. string message = lua_interface->GetStringValue(state, 2);
  756. Spawn* player = lua_interface->GetSpawn(state, 3);
  757. if (spawn && message.length() > 0) {
  758. Client* client = 0;
  759. if (player && player->IsPlayer())
  760. client = spawn->GetZone()->GetClientBySpawn(player);
  761. if (client)
  762. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  763. else
  764. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  765. }
  766. lua_interface->ResetFunctionStack(state);
  767. return 0;
  768. }
  769. int EQ2Emu_lua_SayOOC(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. string message = lua_interface->GetStringValue(state, 2);
  774. Spawn* player = lua_interface->GetSpawn(state, 3);
  775. if (spawn && message.length() > 0) {
  776. Client* client = 0;
  777. if (player && player->IsPlayer())
  778. client = spawn->GetZone()->GetClientBySpawn(player);
  779. if (client)
  780. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OOC, message.c_str(), 30);
  781. else
  782. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OOC, message.c_str(), 30);
  783. }
  784. lua_interface->ResetFunctionStack(state);
  785. return 0;
  786. }
  787. int EQ2Emu_lua_Emote(lua_State* state) {
  788. if (!lua_interface)
  789. return 0;
  790. Spawn* spawn = lua_interface->GetSpawn(state);
  791. string message = lua_interface->GetStringValue(state, 2);
  792. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  793. Spawn* player = lua_interface->GetSpawn(state, 4);
  794. char* to = 0;
  795. if (spawn2)
  796. to = spawn2->GetName();
  797. if (spawn && message.length() > 0) {
  798. Client* client = 0;
  799. if (player && player->IsPlayer())
  800. client = spawn->GetZone()->GetClientBySpawn(player);
  801. if (client)
  802. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  803. else
  804. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  805. }
  806. lua_interface->ResetFunctionStack(state);
  807. return 0;
  808. }
  809. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  810. if (!lua_interface)
  811. return 0;
  812. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  813. if (!luaspell)
  814. return 0;
  815. Spawn* caster = luaspell->caster;
  816. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  817. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  818. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  819. Spawn* target = lua_interface->GetSpawn(state, 4);
  820. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  821. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  822. lua_interface->ResetFunctionStack(state);
  823. if (caster && caster->IsEntity()) {
  824. bool success = false;
  825. luaspell->resisted = false;
  826. if (target) {
  827. float distance = caster->GetDistance(target, true);
  828. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs))
  829. success = true;
  830. }
  831. if (luaspell->targets.size() > 0) {
  832. Spawn* target = 0;
  833. ZoneServer* zone = luaspell->caster->GetZone();
  834. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  835. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  836. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  837. float distance = caster->GetDistance(target, true);
  838. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs);
  839. }
  840. }
  841. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  842. success = true;
  843. }
  844. if (success) {
  845. if (caster->GetZone())
  846. caster->GetZone()->TriggerCharSheetTimer();
  847. }
  848. }
  849. return 0;
  850. }
  851. int EQ2Emu_lua_SummonItem(lua_State* state) {
  852. if (!lua_interface)
  853. return 0;
  854. Spawn* spawn = lua_interface->GetSpawn(state);
  855. int32 item_id = lua_interface->GetInt32Value(state, 2);
  856. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  857. string location = lua_interface->GetStringValue(state, 4);
  858. if (spawn && spawn->IsPlayer()) {
  859. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  860. if (client && item_id > 0) {
  861. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  862. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  863. else
  864. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  865. if (send_messages) {
  866. Item* item = master_item_list.GetItem(item_id);
  867. if (item) {
  868. client->Message(CHANNEL_COLOR_YELLOW, "You receive \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  869. string popup_text = "You receive " + item->name;
  870. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  871. }
  872. }
  873. return 1;
  874. }
  875. }
  876. lua_interface->SetBooleanValue(state, false);
  877. return 1;
  878. }
  879. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  880. Spawn* spawn = lua_interface->GetSpawn(state);
  881. int32 item_id = lua_interface->GetInt32Value(state, 2);
  882. Client* client;
  883. Item* item;
  884. if (spawn && spawn->IsPlayer() && item_id > 0) {
  885. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  886. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  887. if (client->RemoveItem(item, 1)) {
  888. lua_interface->SetBooleanValue(state, true);
  889. return 1;
  890. }
  891. }
  892. }
  893. }
  894. lua_interface->SetBooleanValue(state, false);
  895. return 1;
  896. }
  897. int EQ2Emu_lua_HasItem(lua_State* state) {
  898. Spawn* player = lua_interface->GetSpawn(state);
  899. int32 item_id = lua_interface->GetInt32Value(state, 2);
  900. bool include_bank = lua_interface->GetInt8Value(state, 3);
  901. if (player && player->IsPlayer()) {
  902. bool hasItem = false;
  903. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  904. if (!hasItem)
  905. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  906. lua_interface->SetBooleanValue(state, hasItem);
  907. return 1;
  908. }
  909. lua_interface->SetBooleanValue(state, false);
  910. return 1;
  911. }
  912. int EQ2Emu_lua_Spawn(lua_State* state) {
  913. if (!lua_interface)
  914. return 0;
  915. ZoneServer* zone = lua_interface->GetZone(state);
  916. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  917. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  918. float x = lua_interface->GetFloatValue(state, 4);
  919. float y = lua_interface->GetFloatValue(state, 5);
  920. float z = lua_interface->GetFloatValue(state, 6);
  921. float heading = lua_interface->GetFloatValue(state, 7);
  922. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  923. Spawn* spawn = zone->GetSpawn(spawn_id);
  924. if (!spawn)
  925. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  926. else {
  927. spawn->SetX(x);
  928. spawn->SetZ(z);
  929. spawn->SetY(y,true,true);
  930. spawn->SetLocation(zone->GetClosestLocation(spawn));
  931. spawn->SetHeading(heading);
  932. if (restricted_npc)
  933. spawn->AddAllowAccessSpawn(spawn);
  934. const char* spawn_script = world.GetSpawnScript(spawn_id);
  935. bool scriptActive = false;
  936. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  937. scriptActive = true;
  938. spawn->SetSpawnScript(string(spawn_script));
  939. }
  940. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  941. zone->AddSpawn(spawn);
  942. if (scriptActive) {
  943. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  944. }
  945. lua_interface->SetSpawnValue(state, spawn);
  946. return 1;
  947. }
  948. }
  949. else {
  950. string output = "Invalid paramaters to LUA Spawn command: \n";
  951. if (!zone)
  952. output = output.append("\t").append("Missing zone reference. \n");
  953. if (spawn_id == 0)
  954. output = output.append("\t").append("Missing spawn_id.");
  955. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone - %s", lua_interface->GetScriptName(state), output.c_str());
  956. }
  957. return 0;
  958. }
  959. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  960. if (!lua_interface)
  961. return 0;
  962. ZoneServer* zone = lua_interface->GetZone(state);
  963. if (zone) {
  964. lua_interface->SetStringValue(state, zone->GetZoneName());
  965. return 1;
  966. }
  967. return 0;
  968. }
  969. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  970. if (!lua_interface)
  971. return 0;
  972. ZoneServer* zone = lua_interface->GetZone(state);
  973. if (zone) {
  974. lua_interface->SetInt32Value(state, zone->GetZoneID());
  975. return 1;
  976. }
  977. return 0;
  978. }
  979. int EQ2Emu_lua_GetZone(lua_State* state) {
  980. if (!lua_interface)
  981. return 0;
  982. int32 zone_id = lua_interface->GetInt32Value(state);
  983. ZoneServer* zone = 0;
  984. if (zone_id > 0)
  985. zone = zone_list.Get(zone_id);
  986. else {
  987. string zone_name = lua_interface->GetStringValue(state);
  988. if (zone_name.length() > 0) {
  989. zone = zone_list.Get(zone_name.c_str());
  990. }
  991. else {
  992. Spawn* spawn = lua_interface->GetSpawn(state);
  993. if (spawn)
  994. zone = spawn->GetZone();
  995. }
  996. }
  997. if (zone) {
  998. lua_interface->SetZoneValue(state, zone);
  999. return 1;
  1000. }
  1001. return 0;
  1002. }
  1003. int EQ2Emu_lua_AddHate(lua_State* state) {
  1004. Spawn* entity = lua_interface->GetSpawn(state);
  1005. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1006. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1007. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1008. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1009. if (entity && entity->IsEntity() && amount != 0) {
  1010. if (luaspell) {
  1011. ZoneServer* zone = luaspell->caster->GetZone();
  1012. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1013. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1014. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1015. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1016. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1017. if (send_packet)
  1018. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1019. }
  1020. }
  1021. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1022. }
  1023. else if (npc && npc->IsNPC() && npc->GetZone())
  1024. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1025. }
  1026. return 0;
  1027. }
  1028. int EQ2Emu_lua_Zone(lua_State* state) {
  1029. if (!lua_interface)
  1030. return 0;
  1031. ZoneServer* zone = lua_interface->GetZone(state);
  1032. Spawn* player = lua_interface->GetSpawn(state, 2);
  1033. Client* client = 0;
  1034. if (player && player->IsPlayer())
  1035. client = player->GetZone()->GetClientBySpawn(player);
  1036. float x = lua_interface->GetFloatValue(state, 3);
  1037. float y = lua_interface->GetFloatValue(state, 4);
  1038. float z = lua_interface->GetFloatValue(state, 5);
  1039. float heading = lua_interface->GetFloatValue(state, 6);
  1040. if (zone && client) {
  1041. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1042. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1043. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1044. {
  1045. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1046. return 0;
  1047. }
  1048. if (x != 0 || y != 0 || z != 0) {
  1049. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1050. player->SetX(x);
  1051. player->SetY(y);
  1052. player->SetZ(z);
  1053. player->SetHeading(heading);
  1054. client->Zone(zone->GetZoneName(), false);
  1055. }
  1056. else
  1057. client->Zone(zone->GetZoneName());
  1058. }
  1059. else
  1060. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1061. return 0;
  1062. }
  1063. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1064. if (!lua_interface)
  1065. return 0;
  1066. Spawn* spawn = lua_interface->GetSpawn(state);
  1067. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1068. if (spawn && spawn2)
  1069. spawn->AddAllowAccessSpawn(spawn2);
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* target = lua_interface->GetSpawn(state);
  1076. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1077. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1078. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1079. if (!target) {
  1080. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1081. return 0;
  1082. }
  1083. if (!target->IsEntity()) {
  1084. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1085. return 0;
  1086. }
  1087. if (spell_id <= 0) {
  1088. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1089. return 0;
  1090. }
  1091. if (caster && !caster->IsEntity()) {
  1092. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1093. return 0;
  1094. }
  1095. if (spell_tier == 0)
  1096. spell_tier = 1;
  1097. if (!caster)
  1098. caster = target;
  1099. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target);
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* target = lua_interface->GetSpawn(state);
  1106. int32 target_id = 0;
  1107. if (target)
  1108. target_id = target->GetID();
  1109. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1110. if (!luaspell)
  1111. return 0;
  1112. Spawn* caster = luaspell->caster;
  1113. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1114. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1115. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1116. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1117. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1118. //lua_interface->ResetFunctionStack(state);
  1119. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1120. vector<int16> faction_req;
  1121. vector<int16> race_req;
  1122. int32 class_req = 0;
  1123. int32 i = 0;
  1124. int8 f = 0;
  1125. int8 r = 0;
  1126. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1127. if (class_id < 100) {
  1128. class_req += pow(2.0, double(class_id - 1));
  1129. }
  1130. else if (class_id > 100 && class_id < 1000) {
  1131. race_req.push_back(class_id);
  1132. r++;
  1133. }
  1134. else {
  1135. faction_req.push_back(class_id);
  1136. f++;
  1137. }
  1138. i++;
  1139. }
  1140. if (caster && caster->IsEntity()) {
  1141. bool race_match = false;
  1142. bool success = false;
  1143. luaspell->resisted = false;
  1144. if (luaspell->initial_target == target_id) {
  1145. int xxx = 0;
  1146. }
  1147. if (luaspell->targets.size() > 0) {
  1148. ZoneServer* zone = luaspell->caster->GetZone();
  1149. Spawn* target = 0;
  1150. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1151. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1152. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1153. if (race_req.size() > 0) {
  1154. for (int8 i = 0; i < race_req.size(); i++) {
  1155. int32 xxx = target->GetLuaRaceId();
  1156. if (target->GetLuaRaceId() == race_req[i]) {
  1157. race_match = true;
  1158. }
  1159. }
  1160. }
  1161. else
  1162. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1163. if (race_match == true) {
  1164. float distance = caster->GetDistance(target, true);
  1165. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1166. }
  1167. }
  1168. }
  1169. success = true;
  1170. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1171. }
  1172. else if (target) {
  1173. //check class and race/faction here
  1174. if (race_req.size() > 0) {
  1175. for (int8 i = 0; i < race_req.size(); i++) {
  1176. if (target->GetLuaRaceId() == race_req[i]) {
  1177. race_match = true;
  1178. }
  1179. }
  1180. }
  1181. else
  1182. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1183. if (race_match == true) {
  1184. float distance = caster->GetDistance(target, true);
  1185. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1186. success = true;
  1187. }
  1188. }
  1189. if (success) {
  1190. Spell* spell = luaspell->spell;
  1191. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1192. ((Player*)caster)->InCombat(true);
  1193. if (caster->GetZone())
  1194. caster->GetZone()->TriggerCharSheetTimer();
  1195. }
  1196. }
  1197. }
  1198. return 0;
  1199. }
  1200. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1201. if (!lua_interface)
  1202. return 0;
  1203. Spawn* spawn = lua_interface->GetSpawn(state);
  1204. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1205. lua_interface->ResetFunctionStack(state);
  1206. if (spawn && value != 0) {
  1207. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1208. spawn->SetPower(spawn->GetTotalPower());
  1209. else
  1210. spawn->SetPower(spawn->GetPower() + value);
  1211. }
  1212. return 0;
  1213. }
  1214. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1215. if (!lua_interface)
  1216. return 0;
  1217. Spawn* spawn = lua_interface->GetSpawn(state);
  1218. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1219. lua_interface->ResetFunctionStack(state);
  1220. if (spawn && value != 0) {
  1221. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1222. spawn->SetHP(spawn->GetTotalHP());
  1223. else
  1224. spawn->SetHP(spawn->GetHP() + value);
  1225. }
  1226. return 0;
  1227. }
  1228. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1229. if (!lua_interface)
  1230. return 0;
  1231. Spawn* spawn = lua_interface->GetSpawn(state);
  1232. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1233. lua_interface->ResetFunctionStack(state);
  1234. if (spawn && value != 0) {
  1235. spawn->SetPower(spawn->GetPower() + value);
  1236. if (value > spawn->GetTotalHPBase())
  1237. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1238. }
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. Spawn* spawn = lua_interface->GetSpawn(state);
  1245. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1246. lua_interface->ResetFunctionStack(state);
  1247. if (spawn && value != 0) {
  1248. spawn->SetHP(spawn->GetHP() + value);
  1249. if (value > spawn->GetTotalHPBase())
  1250. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1251. }
  1252. return 0;
  1253. }
  1254. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1255. if (!lua_interface)
  1256. return 0;
  1257. Spawn* spawn = lua_interface->GetSpawn(state);
  1258. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1259. lua_interface->ResetFunctionStack(state);
  1260. if (spawn && value > 0) {
  1261. spawn->SetHP(value);
  1262. if (value > spawn->GetTotalHPBase())
  1263. spawn->SetTotalHP(value);
  1264. }
  1265. return 0;
  1266. }
  1267. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1268. if (!lua_interface)
  1269. return 0;
  1270. Spawn* spawn = lua_interface->GetSpawn(state);
  1271. float value = lua_interface->GetFloatValue(state, 2);
  1272. lua_interface->ResetFunctionStack(state);
  1273. if (spawn && spawn->IsEntity() && value > 0)
  1274. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1275. if (spawn->IsPlayer())
  1276. ((Player*)spawn)->SetCharSheetChanged(true);
  1277. return 0;
  1278. }
  1279. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1280. if (!lua_interface)
  1281. return 0;
  1282. Spawn* spawn = lua_interface->GetSpawn(state);
  1283. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1284. lua_interface->ResetFunctionStack(state);
  1285. if (spawn && spawn->IsEntity() && value > 0)
  1286. ((Entity*)spawn)->SetTotalHPBase(value);
  1287. return 0;
  1288. }
  1289. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1290. if (!lua_interface)
  1291. return 0;
  1292. Spawn* spawn = lua_interface->GetSpawn(state);
  1293. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1294. lua_interface->ResetFunctionStack(state);
  1295. if (spawn && value > 0) {
  1296. spawn->SetPower(value);
  1297. if (value > spawn->GetTotalPowerBase())
  1298. spawn->SetTotalPower(value);
  1299. }
  1300. return 0;
  1301. }
  1302. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1303. if (!lua_interface)
  1304. return 0;
  1305. Spawn* spawn = lua_interface->GetSpawn(state);
  1306. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1307. lua_interface->ResetFunctionStack(state);
  1308. if (spawn && spawn->IsEntity() && value > 0)
  1309. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1310. return 0;
  1311. }
  1312. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1313. if (!lua_interface)
  1314. return 0;
  1315. Spawn* spawn = lua_interface->GetSpawn(state);
  1316. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1317. lua_interface->ResetFunctionStack(state);
  1318. if (spawn && spawn->IsEntity() && value > 0)
  1319. ((Entity*)spawn)->SetTotalPowerBase(value);
  1320. return 0;
  1321. }
  1322. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1323. if (!lua_interface)
  1324. return 0;
  1325. Spawn* spawn = lua_interface->GetSpawn(state);
  1326. float x = lua_interface->GetFloatValue(state, 2);
  1327. float y = lua_interface->GetFloatValue(state, 3);
  1328. float z = lua_interface->GetFloatValue(state, 4);
  1329. float heading = lua_interface->GetFloatValue(state, 5);
  1330. lua_interface->ResetFunctionStack(state);
  1331. if (spawn) {
  1332. spawn->SetX(x);
  1333. spawn->SetY(y);
  1334. spawn->SetZ(z);
  1335. if (heading != 0)
  1336. spawn->SetHeading(heading);
  1337. spawn->SetSpawnOrigX(spawn->GetX());
  1338. spawn->SetSpawnOrigY(spawn->GetY());
  1339. spawn->SetSpawnOrigZ(spawn->GetZ());
  1340. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1341. if (spawn->IsPlayer()) {
  1342. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1343. if (client) {
  1344. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1345. client->QueuePacket(packet);
  1346. }
  1347. }
  1348. }
  1349. return 0;
  1350. }
  1351. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1352. if (!lua_interface)
  1353. return 0;
  1354. Spawn* spawn = lua_interface->GetSpawn(state);
  1355. float value = lua_interface->GetFloatValue(state, 2);
  1356. lua_interface->ResetFunctionStack(state);
  1357. if (spawn) {
  1358. spawn->SetHeading(value);
  1359. if (spawn->IsPlayer()) {
  1360. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1361. if (client) {
  1362. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1363. client->QueuePacket(packet);
  1364. }
  1365. }
  1366. }
  1367. return 0;
  1368. }
  1369. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1370. if (!lua_interface)
  1371. return 0;
  1372. Spawn* spawn = lua_interface->GetSpawn(state);
  1373. int16 value = lua_interface->GetInt16Value(state, 2);
  1374. lua_interface->ResetFunctionStack(state);
  1375. if (spawn)
  1376. spawn->SetModelType(value);
  1377. return 0;
  1378. }
  1379. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1380. if (!lua_interface)
  1381. return 0;
  1382. Spawn* spawn = lua_interface->GetSpawn(state);
  1383. int8 value = lua_interface->GetInt8Value(state, 2);
  1384. lua_interface->ResetFunctionStack(state);
  1385. if (spawn) {
  1386. if (spawn->IsPlayer())
  1387. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1388. else
  1389. spawn->SetAdventureClass(value);
  1390. }
  1391. return 0;
  1392. }
  1393. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1394. if (!lua_interface)
  1395. return 0;
  1396. Spawn* spawn = lua_interface->GetSpawn(state);
  1397. int8 value = lua_interface->GetInt8Value(state, 2);
  1398. lua_interface->ResetFunctionStack(state);
  1399. if (spawn) {
  1400. spawn->SetTradeskillClass(value);
  1401. if (spawn->IsEntity()) {
  1402. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1403. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1404. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1405. }
  1406. if (spawn->IsPlayer())
  1407. ((Player*)spawn)->SetCharSheetChanged(true);
  1408. }
  1409. return 0;
  1410. }
  1411. int EQ2Emu_lua_SetMount(lua_State* state) {
  1412. if (!lua_interface)
  1413. return 0;
  1414. Spawn* spawn = lua_interface->GetSpawn(state);
  1415. int16 value = lua_interface->GetInt16Value(state, 2);
  1416. if (spawn && spawn->IsEntity()) {
  1417. ((Entity*)spawn)->SetMount(value);
  1418. EQ2_Color color;
  1419. color.red = 255;
  1420. color.green = 255;
  1421. color.blue = 255;
  1422. ((Entity*)spawn)->SetMountColor(&color);
  1423. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1424. }
  1425. return 0;
  1426. }
  1427. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1428. if (!lua_interface)
  1429. return 0;
  1430. Spawn* spawn = lua_interface->GetSpawn(state);
  1431. EQ2_Color mount_color;
  1432. EQ2_Color saddle_color;
  1433. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1434. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1435. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1436. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1437. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1438. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1439. if (spawn && spawn->IsEntity()) {
  1440. ((Entity*)spawn)->SetMountColor(&mount_color);
  1441. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1442. }
  1443. return 0;
  1444. }
  1445. int EQ2Emu_lua_GetMount(lua_State* state) {
  1446. if (!lua_interface)
  1447. return 0;
  1448. Spawn* spawn = lua_interface->GetSpawn(state);
  1449. if (spawn && spawn->IsEntity()) {
  1450. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1451. return 1;
  1452. }
  1453. return 0;
  1454. }
  1455. int EQ2Emu_lua_GetRace(lua_State* state) {
  1456. if (!lua_interface)
  1457. return 0;
  1458. Spawn* spawn = lua_interface->GetSpawn(state);
  1459. if (spawn)
  1460. {
  1461. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1462. lua_interface->SetInt32Value(state, spawn->GetRace());
  1463. return 1;
  1464. }
  1465. return 0;
  1466. }
  1467. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1468. if (!lua_interface)
  1469. return 0;
  1470. Spawn* spawn = lua_interface->GetSpawn(state);
  1471. if (spawn) {
  1472. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1473. return 1;
  1474. }
  1475. return 0;
  1476. }
  1477. int EQ2Emu_lua_GetClass(lua_State* state) {
  1478. Spawn* spawn = lua_interface->GetSpawn(state);
  1479. if (spawn) {
  1480. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1481. return 1;
  1482. }
  1483. return 0;
  1484. }
  1485. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1486. Spawn* spawn = lua_interface->GetSpawn(state);
  1487. if (spawn) {
  1488. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1489. return 1;
  1490. }
  1491. return 0;
  1492. }
  1493. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1494. if (!lua_interface)
  1495. return 0;
  1496. Spawn* spawn = lua_interface->GetSpawn(state);
  1497. float value = lua_interface->GetFloatValue(state, 2);
  1498. lua_interface->ResetFunctionStack(state);
  1499. if (spawn) {
  1500. spawn->SetSpeed(value);
  1501. ((Entity*)spawn)->SetSpeed(value);
  1502. if (spawn->IsPlayer()) {
  1503. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1504. if (client) {
  1505. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1506. if (packet) {
  1507. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1508. packet->setDataByName("speed", value);
  1509. packet->setDataByName("size", 0.51);
  1510. EQ2Packet* app = packet->serialize();
  1511. client->QueuePacket(app);
  1512. safe_delete(packet);
  1513. }
  1514. }
  1515. }
  1516. }
  1517. return 0;
  1518. }
  1519. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1520. if (!lua_interface)
  1521. return 0;
  1522. Spawn* spawn = lua_interface->GetSpawn(state);
  1523. const int16 type = lua_interface->GetInt16Value(state, 2);
  1524. const float value = lua_interface->GetFloatValue(state, 3);
  1525. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1526. int64 class_req = 0;
  1527. int32 class_id = 0;
  1528. vector<int16> faction_req;
  1529. vector<int16> race_req;
  1530. int32 i = 0;
  1531. int8 f = 0;
  1532. int8 r = 0;
  1533. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1534. if (class_id < 100) {
  1535. class_req += pow(2.0, double(class_id - 1));
  1536. }
  1537. else if (class_id > 100 && class_id < 1000) {
  1538. race_req.push_back(class_id);
  1539. r++;
  1540. }
  1541. else {
  1542. faction_req.push_back(class_id);
  1543. f++;
  1544. }
  1545. i++;
  1546. }
  1547. if (value != 0 && type >= 0) {
  1548. if (luaspell && luaspell->spell && luaspell->caster) {
  1549. ZoneServer* zone = luaspell->caster->GetZone();
  1550. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1551. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1552. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1553. if (target) {
  1554. if (target->IsPlayer()) {
  1555. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1556. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1557. if (((Player*)target)->GetGroupMemberInfo())
  1558. ((Player*)target)->UpdateGroupMemberInfo();
  1559. ((Player*)target)->SetCharSheetChanged(true);
  1560. }
  1561. else if (target->IsNPC())
  1562. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1563. else
  1564. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1565. }
  1566. }
  1567. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1568. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1569. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1570. }
  1571. else if (spawn && spawn->IsEntity()) {
  1572. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1573. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1574. if (spawn->IsPlayer())
  1575. ((Player*)spawn)->SetCharSheetChanged(true);
  1576. }
  1577. else
  1578. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1579. }
  1580. else
  1581. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1582. return 0;
  1583. }
  1584. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1585. if (!lua_interface)
  1586. return 0;
  1587. Spawn* spawn = lua_interface->GetSpawn(state);
  1588. int16 type = lua_interface->GetInt16Value(state, 2);
  1589. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1590. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1591. if (!spawn) {
  1592. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1593. return 0;
  1594. }
  1595. if (!spawn->IsEntity()) {
  1596. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1597. return 0;
  1598. }
  1599. if (value == 0) {
  1600. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1601. return 0;
  1602. }
  1603. if (!luaspell || !luaspell->spell) {
  1604. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1605. return 0;
  1606. }
  1607. int32 class_req = 0;
  1608. vector<int16> faction_req;
  1609. vector<int16> race_req;
  1610. int32 class_id = 0;
  1611. int32 i = 0;
  1612. int8 f = 0;
  1613. int8 r = 0;
  1614. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1615. if (class_id < 100) {
  1616. class_req += pow(2.0, double(class_id - 1));
  1617. }
  1618. else if (class_id > 100 && class_id < 1000) {
  1619. race_req.push_back(class_id);
  1620. r++;
  1621. }
  1622. else {
  1623. faction_req.push_back(class_id);
  1624. f++;
  1625. }
  1626. i++;
  1627. }
  1628. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1629. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1630. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1631. if (spawn->IsPlayer())
  1632. ((Player*)spawn)->SetCharSheetChanged(true);
  1633. return 0;
  1634. }
  1635. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1636. if (!lua_interface)
  1637. return 0;
  1638. Spawn* spawn = lua_interface->GetSpawn(state);
  1639. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1640. if (luaspell && luaspell->spell) {
  1641. ZoneServer* zone = luaspell->caster->GetZone();
  1642. Spawn* target = 0;
  1643. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1644. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1645. target = zone->GetSpawnByID(luaspell->targets[i]);
  1646. if (target && target->IsEntity()) {
  1647. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1648. if (target->IsPlayer())
  1649. ((Player*)target)->SetCharSheetChanged(true);
  1650. }
  1651. }
  1652. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1653. }
  1654. else if (spawn && spawn->IsEntity()) {
  1655. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1656. if (spawn->IsPlayer())
  1657. ((Player*)spawn)->SetCharSheetChanged(true);
  1658. }
  1659. return 0;
  1660. }
  1661. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1662. if (!lua_interface)
  1663. return 0;
  1664. Spawn* spawn = lua_interface->GetSpawn(state);
  1665. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1666. float value = lua_interface->GetFloatValue(state, 3);
  1667. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1668. if (value != 0) {
  1669. int32 spell_id = 0;
  1670. if (luaspell && luaspell->spell && luaspell->caster) {
  1671. spell_id = luaspell->spell->GetSpellID();
  1672. ZoneServer* zone = luaspell->caster->GetZone();
  1673. Spawn* target = 0;
  1674. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1675. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1676. target = zone->GetSpawnByID(luaspell->targets[i]);
  1677. if (target && target->Alive()) {
  1678. if (target->IsPlayer()) {
  1679. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1680. Client* client = target->GetZone()->GetClientBySpawn(target);
  1681. if (client) {
  1682. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1683. if (packet)
  1684. client->QueuePacket(packet);
  1685. }
  1686. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1687. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1688. }
  1689. else if (target->IsNPC()) {
  1690. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1691. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1692. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1693. }
  1694. else
  1695. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1696. }
  1697. }
  1698. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1699. }
  1700. else if (spawn) {
  1701. if (spawn->IsPlayer()) {
  1702. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1703. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1704. if (client) {
  1705. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1706. if (packet)
  1707. client->QueuePacket(packet);
  1708. }
  1709. }
  1710. else if (spawn->IsNPC())
  1711. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1712. else
  1713. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1714. }
  1715. }
  1716. else
  1717. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1718. return 0;
  1719. }
  1720. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1721. if (!lua_interface)
  1722. return 0;
  1723. Spawn* spawn = lua_interface->GetSpawn(state);
  1724. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1725. if (spawn && spawn->IsPlayer()) {
  1726. int32 spell_id = 0;
  1727. if (luaspell && luaspell->spell) {
  1728. spell_id = luaspell->spell->GetSpellID();
  1729. ZoneServer* zone = luaspell->caster->GetZone();
  1730. Spawn* target = 0;
  1731. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1732. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1733. target = zone->GetSpawnByID(luaspell->targets[i]);
  1734. if (target) {
  1735. if (target->IsPlayer()) {
  1736. ((Player*)target)->RemoveSkillBonus(spell_id);
  1737. Client* client = target->GetZone()->GetClientBySpawn(target);
  1738. if (client) {
  1739. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1740. if (packet)
  1741. client->QueuePacket(packet);
  1742. }
  1743. }
  1744. else if (target->IsNPC())
  1745. ((NPC*)target)->RemoveSkillBonus(spell_id);
  1746. else
  1747. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1748. }
  1749. }
  1750. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1751. }
  1752. else if (spawn) {
  1753. if (spawn->IsPlayer()) {
  1754. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  1755. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1756. if (client) {
  1757. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1758. if (packet)
  1759. client->QueuePacket(packet);
  1760. }
  1761. }
  1762. else if (spawn->IsNPC())
  1763. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  1764. else
  1765. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1766. }
  1767. }
  1768. return 0;
  1769. }
  1770. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  1771. if (!lua_interface)
  1772. return 0;
  1773. Spawn* spawn = lua_interface->GetSpawn(state);
  1774. int8 type = lua_interface->GetInt32Value(state, 2);
  1775. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  1776. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1777. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  1778. ZoneServer* zone = luaspell->caster->GetZone();
  1779. Spawn* target = 0;
  1780. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1781. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1782. target = zone->GetSpawnByID(luaspell->targets[i]);
  1783. if (target && target->IsEntity()) {
  1784. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  1785. ((Entity*)target)->AddMezSpell(luaspell);
  1786. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  1787. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  1788. if (target->IsNPC())
  1789. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1790. }
  1791. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  1792. ((Entity*)target)->AddStifleSpell(luaspell);
  1793. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  1794. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  1795. if (target->IsNPC())
  1796. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1797. }
  1798. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  1799. ((Entity*)target)->AddDazeSpell(luaspell);
  1800. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  1801. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  1802. if (target->IsNPC())
  1803. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1804. }
  1805. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  1806. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  1807. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  1808. ((Entity*)target)->AddStunSpell(luaspell);
  1809. if (target->IsNPC())
  1810. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1811. }
  1812. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  1813. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  1814. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  1815. ((Entity*)target)->AddRootSpell(luaspell);
  1816. if (target->IsNPC())
  1817. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1818. }
  1819. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  1820. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  1821. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  1822. ((Entity*)target)->AddFearSpell(luaspell);
  1823. if (target->IsNPC())
  1824. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1825. }
  1826. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  1827. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  1828. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  1829. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  1830. }
  1831. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  1832. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  1833. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  1834. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  1835. }
  1836. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  1837. ((Entity*)target)->AddSnareSpell(luaspell);
  1838. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  1839. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  1840. if (target->IsNPC())
  1841. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1842. }
  1843. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  1844. ((Entity*)target)->AddFlightSpell(luaspell);
  1845. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  1846. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  1847. }
  1848. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  1849. ((Entity*)target)->AddGlideSpell(luaspell);
  1850. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  1851. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  1852. }
  1853. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  1854. ((Entity*)target)->AddSafefallSpell(luaspell);
  1855. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  1856. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  1857. }
  1858. else
  1859. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1860. }
  1861. else
  1862. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  1863. }
  1864. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1865. }
  1866. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  1867. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  1868. ((Entity*)spawn)->AddMezSpell(luaspell);
  1869. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  1870. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  1871. }
  1872. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  1873. ((Entity*)spawn)->AddStifleSpell(luaspell);
  1874. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  1875. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  1876. }
  1877. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  1878. ((Entity*)spawn)->AddDazeSpell(luaspell);
  1879. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  1880. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  1881. }
  1882. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  1883. ((Entity*)spawn)->AddStunSpell(luaspell);
  1884. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  1885. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  1886. }
  1887. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  1888. ((Entity*)spawn)->AddRootSpell(luaspell);
  1889. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  1890. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  1891. }
  1892. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  1893. ((Entity*)spawn)->AddFearSpell(luaspell);
  1894. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  1895. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  1896. }
  1897. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  1898. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  1899. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  1900. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  1901. }
  1902. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  1903. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  1904. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  1905. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  1906. }
  1907. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  1908. ((Entity*)spawn)->AddSnareSpell(luaspell);
  1909. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  1910. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  1911. }
  1912. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  1913. ((Entity*)spawn)->AddFlightSpell(luaspell);
  1914. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  1915. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  1916. }
  1917. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  1918. ((Entity*)spawn)->AddGlideSpell(luaspell);
  1919. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  1920. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  1921. }
  1922. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  1923. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  1924. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  1925. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  1926. }
  1927. else
  1928. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1929. }
  1930. else
  1931. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  1932. return 0;
  1933. }
  1934. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  1935. if (!lua_interface)
  1936. return 0;
  1937. Spawn* spawn = lua_interface->GetSpawn(state);
  1938. int8 type = lua_interface->GetInt8Value(state, 2);
  1939. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  1940. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1941. if (spawn && spawn->IsEntity()) {
  1942. if (!only_remove_spawn && luaspell && luaspell->spell) {
  1943. ZoneServer* zone = luaspell->caster->GetZone();
  1944. Spawn* target = 0;
  1945. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1946. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1947. target = zone->GetSpawnByID(luaspell->targets[i]);
  1948. if (target) {
  1949. if (type == CONTROL_EFFECT_TYPE_MEZ)
  1950. ((Entity*)target)->RemoveMezSpell(luaspell);
  1951. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  1952. ((Entity*)target)->RemoveStifleSpell(luaspell);
  1953. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  1954. ((Entity*)target)->RemoveDazeSpell(luaspell);
  1955. else if (type == CONTROL_EFFECT_TYPE_STUN)
  1956. ((Entity*)target)->RemoveStunSpell(luaspell);
  1957. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  1958. ((Entity*)target)->RemoveRootSpell(luaspell);
  1959. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  1960. ((Entity*)target)->RemoveFearSpell(luaspell);
  1961. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  1962. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  1963. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  1964. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  1965. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  1966. ((Entity*)target)->RemoveSnareSpell(luaspell);
  1967. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  1968. ((Entity*)target)->RemoveFlightSpell(luaspell);
  1969. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  1970. ((Entity*)target)->RemoveGlideSpell(luaspell);
  1971. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  1972. ((Entity*)target)->RemoveGlideSpell(luaspell);
  1973. else
  1974. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1975. }
  1976. }
  1977. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1978. }
  1979. else if (only_remove_spawn) {
  1980. if (type == CONTROL_EFFECT_TYPE_MEZ)
  1981. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  1982. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  1983. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  1984. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  1985. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  1986. else if (type == CONTROL_EFFECT_TYPE_STUN)
  1987. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  1988. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  1989. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  1990. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  1991. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  1992. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  1993. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  1994. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  1995. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  1996. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  1997. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  1998. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  1999. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2000. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2001. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2002. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2003. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2004. else
  2005. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2006. }
  2007. }
  2008. return 0;
  2009. }
  2010. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2011. if (!lua_interface)
  2012. return 0;
  2013. Spawn* spawn = lua_interface->GetSpawn(state);
  2014. int16 value = lua_interface->GetInt16Value(state, 2);
  2015. if (spawn && spawn->IsEntity()) {
  2016. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2017. if (spawn->IsPlayer())
  2018. ((Player*)spawn)->SetCharSheetChanged(true);
  2019. }
  2020. return 0;
  2021. }
  2022. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2023. if (!lua_interface)
  2024. return 0;
  2025. Spawn* spawn = lua_interface->GetSpawn(state);
  2026. int16 value = lua_interface->GetInt16Value(state, 2);
  2027. if (spawn && spawn->IsEntity()) {
  2028. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2029. if (spawn->IsPlayer())
  2030. ((Player*)spawn)->SetCharSheetChanged(true);
  2031. }
  2032. return 0;
  2033. }
  2034. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2035. if (!lua_interface)
  2036. return 0;
  2037. Spawn* spawn = lua_interface->GetSpawn(state);
  2038. int16 value = lua_interface->GetInt16Value(state, 2);
  2039. if (spawn && spawn->IsEntity()) {
  2040. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2041. if (spawn->IsPlayer())
  2042. ((Player*)spawn)->SetCharSheetChanged(true);
  2043. }
  2044. return 0;
  2045. }
  2046. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2047. if (!lua_interface)
  2048. return 0;
  2049. Spawn* spawn = lua_interface->GetSpawn(state);
  2050. int16 value = lua_interface->GetInt16Value(state, 2);
  2051. if (spawn && spawn->IsEntity()) {
  2052. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2053. if (spawn->IsPlayer())
  2054. ((Player*)spawn)->SetCharSheetChanged(true);
  2055. }
  2056. return 0;
  2057. }
  2058. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2059. if (!lua_interface)
  2060. return 0;
  2061. Spawn* spawn = lua_interface->GetSpawn(state);
  2062. int16 value = lua_interface->GetInt16Value(state, 2);
  2063. if (spawn && spawn->IsEntity()) {
  2064. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2065. if (spawn->IsPlayer())
  2066. ((Player*)spawn)->SetCharSheetChanged(true);
  2067. }
  2068. return 0;
  2069. }
  2070. int EQ2Emu_lua_SetInt(lua_State* state) {
  2071. if (!lua_interface)
  2072. return 0;
  2073. Spawn* spawn = lua_interface->GetSpawn(state);
  2074. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2075. if (spawn && spawn->IsEntity()) {
  2076. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2077. if (spawn->IsPlayer())
  2078. ((Player*)spawn)->SetCharSheetChanged(true);
  2079. }
  2080. return 0;
  2081. }
  2082. int EQ2Emu_lua_SetWis(lua_State* state) {
  2083. if (!lua_interface)
  2084. return 0;
  2085. Spawn* spawn = lua_interface->GetSpawn(state);
  2086. float value = lua_interface->GetFloatValue(state, 2);
  2087. if (spawn && spawn->IsEntity()) {
  2088. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2089. if (spawn->IsPlayer())
  2090. ((Player*)spawn)->SetCharSheetChanged(true);
  2091. }
  2092. return 0;
  2093. }
  2094. int EQ2Emu_lua_SetSta(lua_State* state) {
  2095. if (!lua_interface)
  2096. return 0;
  2097. Spawn* spawn = lua_interface->GetSpawn(state);
  2098. float value = lua_interface->GetFloatValue(state, 2);
  2099. if (spawn && spawn->IsEntity()) {
  2100. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2101. if (spawn->IsPlayer())
  2102. ((Player*)spawn)->SetCharSheetChanged(true);
  2103. }
  2104. return 0;
  2105. }
  2106. int EQ2Emu_lua_SetStr(lua_State* state) {
  2107. if (!lua_interface)
  2108. return 0;
  2109. Spawn* spawn = lua_interface->GetSpawn(state);
  2110. float value = lua_interface->GetFloatValue(state, 2);
  2111. if (spawn && spawn->IsEntity()) {
  2112. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2113. if (spawn->IsPlayer())
  2114. ((Player*)spawn)->SetCharSheetChanged(true);
  2115. }
  2116. return 0;
  2117. }
  2118. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2119. if (!lua_interface)
  2120. return 0;
  2121. Spawn* spawn = lua_interface->GetSpawn(state);
  2122. float value = lua_interface->GetFloatValue(state, 2);
  2123. if (spawn && spawn->IsEntity()) {
  2124. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2125. if (spawn->IsPlayer())
  2126. ((Player*)spawn)->SetCharSheetChanged(true);
  2127. }
  2128. return 0;
  2129. }
  2130. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2131. if (!lua_interface)
  2132. return 0;
  2133. Spawn* spawn = lua_interface->GetSpawn(state);
  2134. if (spawn) {
  2135. lua_interface->SetInt32Value(state, spawn->GetHP());
  2136. return 1;
  2137. }
  2138. return 0;
  2139. }
  2140. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2141. if (!lua_interface)
  2142. return 0;
  2143. Spawn* spawn = lua_interface->GetSpawn(state);
  2144. if (spawn) {
  2145. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2146. return 1;
  2147. }
  2148. return 0;
  2149. }
  2150. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2151. if (!lua_interface)
  2152. return 0;
  2153. Spawn* spawn = lua_interface->GetSpawn(state);
  2154. if (spawn) {
  2155. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2156. return 1;
  2157. }
  2158. return 0;
  2159. }
  2160. int EQ2Emu_lua_GetName(lua_State* state) {
  2161. if (!lua_interface)
  2162. return 0;
  2163. Spawn* spawn = lua_interface->GetSpawn(state);
  2164. if (spawn) {
  2165. lua_interface->SetStringValue(state, spawn->GetName());
  2166. return 1;
  2167. }
  2168. return 0;
  2169. }
  2170. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2171. Spawn* spawn = lua_interface->GetSpawn(state);
  2172. if (spawn) {
  2173. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2174. return 1;
  2175. }
  2176. return 0;
  2177. }
  2178. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2179. if (!lua_interface)
  2180. return 0;
  2181. Spawn* spawn = lua_interface->GetSpawn(state);
  2182. if (spawn) {
  2183. lua_interface->SetInt32Value(state, spawn->GetPower());
  2184. return 1;
  2185. }
  2186. return 0;
  2187. }
  2188. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2189. if (!lua_interface)
  2190. return 0;
  2191. Spawn* spawn = lua_interface->GetSpawn(state);
  2192. if (spawn) {
  2193. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2194. return 1;
  2195. }
  2196. return 0;
  2197. }
  2198. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2199. if (!lua_interface)
  2200. return 0;
  2201. Spawn* spawn = lua_interface->GetSpawn(state);
  2202. if (spawn) {
  2203. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2204. return 1;
  2205. }
  2206. return 0;
  2207. }
  2208. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2209. if (!lua_interface)
  2210. return 0;
  2211. Spawn* spawn = lua_interface->GetSpawn(state);
  2212. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2213. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2214. if (spawn && spawn2) {
  2215. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2216. lua_interface->SetFloatValue(state, distance);
  2217. return 1;
  2218. }
  2219. return 0;
  2220. }
  2221. int EQ2Emu_lua_GetX(lua_State* state) {
  2222. if (!lua_interface)
  2223. return 0;
  2224. Spawn* spawn = lua_interface->GetSpawn(state);
  2225. if (spawn) {
  2226. lua_interface->SetFloatValue(state, spawn->GetX());
  2227. return 1;
  2228. }
  2229. return 0;
  2230. }
  2231. int EQ2Emu_lua_GetY(lua_State* state) {
  2232. if (!lua_interface)
  2233. return 0;
  2234. Spawn* spawn = lua_interface->GetSpawn(state);
  2235. if (spawn) {
  2236. lua_interface->SetFloatValue(state, spawn->GetY());
  2237. return 1;
  2238. }
  2239. return 0;
  2240. }
  2241. int EQ2Emu_lua_GetZ(lua_State* state) {
  2242. if (!lua_interface)
  2243. return 0;
  2244. Spawn* spawn = lua_interface->GetSpawn(state);
  2245. if (spawn) {
  2246. lua_interface->SetFloatValue(state, spawn->GetZ());
  2247. return 1;
  2248. }
  2249. return 0;
  2250. }
  2251. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2252. if (!lua_interface)
  2253. return 0;
  2254. Spawn* spawn = lua_interface->GetSpawn(state);
  2255. if (spawn) {
  2256. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2257. return 1;
  2258. }
  2259. return 0;
  2260. }
  2261. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2262. if (!lua_interface)
  2263. return 0;
  2264. Spawn* spawn = lua_interface->GetSpawn(state);
  2265. if (spawn) {
  2266. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2267. return 1;
  2268. }
  2269. return 0;
  2270. }
  2271. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2272. if (!lua_interface)
  2273. return 0;
  2274. Spawn* spawn = lua_interface->GetSpawn(state);
  2275. if (spawn) {
  2276. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2277. return 1;
  2278. }
  2279. return 0;
  2280. }
  2281. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2282. if (!lua_interface)
  2283. return 0;
  2284. Spawn* spawn = lua_interface->GetSpawn(state);
  2285. if (spawn && spawn->IsEntity()) {
  2286. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2287. return 1;
  2288. }
  2289. return 0;
  2290. }
  2291. int EQ2Emu_lua_GetInt(lua_State* state) {
  2292. if (!lua_interface)
  2293. return 0;
  2294. Spawn* spawn = lua_interface->GetSpawn(state);
  2295. if (spawn && spawn->IsEntity()) {
  2296. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2297. return 1;
  2298. }
  2299. return 0;
  2300. }
  2301. int EQ2Emu_lua_GetWis(lua_State* state) {
  2302. if (!lua_interface)
  2303. return 0;
  2304. Spawn* spawn = lua_interface->GetSpawn(state);
  2305. if (spawn && spawn->IsEntity()) {
  2306. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2307. return 1;
  2308. }
  2309. return 0;
  2310. }
  2311. int EQ2Emu_lua_GetSta(lua_State* state) {
  2312. if (!lua_interface)
  2313. return 0;
  2314. Spawn* spawn = lua_interface->GetSpawn(state);
  2315. if (spawn && spawn->IsEntity()) {
  2316. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2317. return 1;
  2318. }
  2319. return 0;
  2320. }
  2321. int EQ2Emu_lua_GetStr(lua_State* state) {
  2322. if (!lua_interface)
  2323. return 0;
  2324. Spawn* spawn = lua_interface->GetSpawn(state);
  2325. if (spawn && spawn->IsEntity()) {
  2326. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2327. return 1;
  2328. }
  2329. return 0;
  2330. }
  2331. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2332. if (!lua_interface)
  2333. return 0;
  2334. Spawn* spawn = lua_interface->GetSpawn(state);
  2335. if (spawn && spawn->IsEntity()) {
  2336. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2337. return 1;
  2338. }
  2339. return 0;
  2340. }
  2341. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2342. if (!lua_interface)
  2343. return 0;
  2344. Spawn* spawn = lua_interface->GetSpawn(state);
  2345. if (spawn && spawn->IsEntity()) {
  2346. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2347. return 1;
  2348. }
  2349. return 0;
  2350. }
  2351. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2352. if (!lua_interface)
  2353. return 0;
  2354. Spawn* spawn = lua_interface->GetSpawn(state);
  2355. if (spawn && spawn->IsEntity()) {
  2356. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2357. return 1;
  2358. }
  2359. return 0;
  2360. }
  2361. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2362. if (!lua_interface)
  2363. return 0;
  2364. Spawn* spawn = lua_interface->GetSpawn(state);
  2365. if (spawn && spawn->IsEntity()) {
  2366. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2367. return 1;
  2368. }
  2369. return 0;
  2370. }
  2371. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2372. if (!lua_interface)
  2373. return 0;
  2374. Spawn* spawn = lua_interface->GetSpawn(state);
  2375. if (spawn && spawn->IsEntity()) {
  2376. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2377. return 1;
  2378. }
  2379. return 0;
  2380. }
  2381. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2382. if (!lua_interface)
  2383. return 0;
  2384. Spawn* spawn = lua_interface->GetSpawn(state);
  2385. if (spawn && spawn->IsEntity()) {
  2386. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2387. return 1;
  2388. }
  2389. return 0;
  2390. }
  2391. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2392. if (!lua_interface)
  2393. return 0;
  2394. Spawn* player = lua_interface->GetSpawn(state);
  2395. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2396. int32 step = lua_interface->GetInt32Value(state, 3);
  2397. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2398. Client* client = player->GetZone()->GetClientBySpawn(player);
  2399. if (client)
  2400. client->AddPendingQuestUpdate(quest_id, step);
  2401. }
  2402. return 0;
  2403. }
  2404. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2405. Spawn* player = lua_interface->GetSpawn(state);
  2406. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2407. int32 step = lua_interface->GetInt32Value(state, 3);
  2408. int32 progress = lua_interface->GetInt32Value(state, 4);
  2409. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2410. Client* client = player->GetZone()->GetClientBySpawn(player);
  2411. if (client)
  2412. client->AddPendingQuestUpdate(quest_id, step, progress);
  2413. }
  2414. return 0;
  2415. }
  2416. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2417. if (!lua_interface)
  2418. return 0;
  2419. Spawn* player = lua_interface->GetSpawn(state);
  2420. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2421. if (player && player->IsPlayer() && quest_id > 0) {
  2422. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2423. return 1;
  2424. }
  2425. return 0;
  2426. }
  2427. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2428. if (!lua_interface)
  2429. return 0;
  2430. Spawn* player = lua_interface->GetSpawn(state);
  2431. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2432. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2433. if (player && player->IsPlayer() && quest_id > 0) {
  2434. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2435. return 1;
  2436. }
  2437. return 0;
  2438. }
  2439. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2440. if (!lua_interface)
  2441. return 0;
  2442. Spawn* player = lua_interface->GetSpawn(state);
  2443. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2444. if (player && player->IsPlayer() && quest_id > 0) {
  2445. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2446. return 1;
  2447. }
  2448. return 0;
  2449. }
  2450. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2451. if (!lua_interface)
  2452. return 0;
  2453. Quest* quest = lua_interface->GetQuest(state);
  2454. string name = lua_interface->GetStringValue(state, 2);
  2455. string type = lua_interface->GetStringValue(state, 3);
  2456. string zone = lua_interface->GetStringValue(state, 4);
  2457. int16 level = lua_interface->GetInt16Value(state, 5);
  2458. string description = lua_interface->GetStringValue(state, 6);
  2459. bool load = true;
  2460. if (!quest) {
  2461. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2462. load = false;
  2463. }
  2464. if (load && name.length() == 0) {
  2465. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2466. load = false;
  2467. }
  2468. if (load && type.length() == 0) {
  2469. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2470. load = false;
  2471. }
  2472. if (load && zone.length() == 0) {
  2473. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2474. load = false;
  2475. }
  2476. if (load && description.length() == 0) {
  2477. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2478. load = false;
  2479. }
  2480. if (load && level == 0) {
  2481. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2482. load = false;
  2483. }
  2484. if (load)
  2485. quest->RegisterQuest(name, type, zone, level, description);
  2486. return 0;
  2487. }
  2488. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2489. if (!lua_interface)
  2490. return 0;
  2491. Quest* quest = lua_interface->GetQuest(state);
  2492. if (quest) {
  2493. int8 level = lua_interface->GetInt16Value(state, 2);
  2494. quest->SetPrereqLevel(level);
  2495. }
  2496. return 0;
  2497. }
  2498. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2499. if (!lua_interface)
  2500. return 0;
  2501. Quest* quest = lua_interface->GetQuest(state);
  2502. if (quest) {
  2503. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2504. quest->AddPrereqQuest(quest_id);
  2505. }
  2506. return 0;
  2507. }
  2508. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2509. if (!lua_interface)
  2510. return 0;
  2511. Quest* quest = lua_interface->GetQuest(state);
  2512. if (quest) {
  2513. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2514. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2515. if (quantity == 0)
  2516. quantity = 1;
  2517. Item* master_item = master_item_list.GetItem(item_id);
  2518. if (master_item) {
  2519. Item* item = new Item(master_item);
  2520. item->details.count = quantity;
  2521. quest->AddPrereqItem(item);
  2522. }
  2523. }
  2524. return 0;
  2525. }
  2526. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2527. if (!lua_interface)
  2528. return 0;
  2529. Spawn* player = lua_interface->GetSpawn(state);
  2530. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2531. if (player && player->IsPlayer() && quest_id > 0) {
  2532. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2533. return 1;
  2534. }
  2535. return 0;
  2536. }
  2537. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2538. if (!lua_interface)
  2539. return 0;
  2540. Quest* quest = lua_interface->GetQuest(state);
  2541. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2542. if (quest && spawn_id > 0)
  2543. quest->SetQuestReturnNPC(spawn_id);
  2544. return 0;
  2545. }
  2546. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2547. if (!lua_interface)
  2548. return 0;
  2549. Spawn* spawn = lua_interface->GetSpawn(state);
  2550. if (!spawn) {
  2551. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2552. return 0;
  2553. }
  2554. int32 time = lua_interface->GetInt32Value(state, 2);
  2555. if (time <= 0) {
  2556. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2557. return 0;
  2558. }
  2559. string function = lua_interface->GetStringValue(state, 3);
  2560. if (function.length() == 0) {
  2561. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2562. return 0;
  2563. }
  2564. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2565. Spawn* player = lua_interface->GetSpawn(state, 5);
  2566. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2567. timer->timer = Timer::GetCurrentTime2() + time;
  2568. timer->function = function;
  2569. timer->spawn = spawn->GetID();
  2570. timer->player = player ? player->GetID() : 0;
  2571. if (max_count == 0)
  2572. max_count = 1;
  2573. timer->max_count = max_count;
  2574. timer->current_count = 0;
  2575. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2576. return 0;
  2577. }
  2578. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2579. if (!lua_interface)
  2580. return 0;
  2581. Spawn* player = lua_interface->GetSpawn(state);
  2582. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2583. if (player && player->IsPlayer() && quest_id > 0) {
  2584. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2585. return 1;
  2586. }
  2587. return 0;
  2588. }
  2589. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2590. if (!lua_interface)
  2591. return 0;
  2592. Spawn* player = lua_interface->GetSpawn(state);
  2593. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2594. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2595. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2596. if (quest)
  2597. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2598. return 1;
  2599. }
  2600. return 0;
  2601. }
  2602. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2603. if (!lua_interface)
  2604. return 0;
  2605. Spawn* player = lua_interface->GetSpawn(state);
  2606. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2607. if (player && player->IsPlayer() && quest_id > 0) {
  2608. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2609. return 1;
  2610. }
  2611. return 0;
  2612. }
  2613. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2614. if (!lua_interface)
  2615. return 0;
  2616. Spawn* npc = lua_interface->GetSpawn(state);
  2617. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2618. if (npc && !npc->IsPlayer() && quest_id > 0)
  2619. npc->AddProvidedQuest(quest_id);
  2620. return 0;
  2621. }
  2622. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2623. if (!lua_interface)
  2624. return 0;
  2625. Spawn* npc = lua_interface->GetSpawn(state);
  2626. Spawn* player = lua_interface->GetSpawn(state, 2);
  2627. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  2628. /* NPC is allowed to be null */
  2629. if (player && player->IsPlayer() && quest_id > 0) {
  2630. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  2631. if (master_quest) {
  2632. Client* client = player->GetZone()->GetClientBySpawn(player);
  2633. Quest* quest = new Quest(master_quest);
  2634. if (client && quest) {
  2635. client->AddPendingQuest(quest);
  2636. if (npc)
  2637. quest->SetQuestGiver(npc->GetDatabaseID());
  2638. else
  2639. quest->SetQuestGiver(0);
  2640. }
  2641. }
  2642. }
  2643. return 0;
  2644. }
  2645. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  2646. if (!lua_interface)
  2647. return 0;
  2648. Quest* quest = lua_interface->GetQuest(state);
  2649. if (quest) {
  2650. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2651. quest->AddPrereqClass(class_id);
  2652. }
  2653. return 0;
  2654. }
  2655. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  2656. if (!lua_interface)
  2657. return 0;
  2658. Quest* quest = lua_interface->GetQuest(state);
  2659. if (quest) {
  2660. int8 race = lua_interface->GetInt8Value(state, 2);
  2661. quest->AddPrereqRace(race);
  2662. }
  2663. return 0;
  2664. }
  2665. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  2666. if (!lua_interface)
  2667. return 0;
  2668. Quest* quest = lua_interface->GetQuest(state);
  2669. if (quest) {
  2670. int16 model_type = lua_interface->GetInt16Value(state, 2);
  2671. quest->AddPrereqModelType(model_type);
  2672. }
  2673. return 0;
  2674. }
  2675. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  2676. if (!lua_interface)
  2677. return 0;
  2678. Quest* quest = lua_interface->GetQuest(state);
  2679. if (!quest) {
  2680. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  2681. return 0;
  2682. }
  2683. int8 level = lua_interface->GetInt8Value(state, 2);
  2684. quest->SetPrereqTSLevel(level);
  2685. return 0;
  2686. }
  2687. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  2688. if (!lua_interface)
  2689. return 0;
  2690. Quest* quest = lua_interface->GetQuest(state);
  2691. if (!quest) {
  2692. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  2693. return 0;
  2694. }
  2695. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2696. quest->AddPrereqTradeskillClass(class_id);
  2697. return 0;
  2698. }
  2699. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  2700. if (!lua_interface)
  2701. return 0;
  2702. Quest* quest = lua_interface->GetQuest(state);
  2703. if (quest) {
  2704. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2705. sint32 min = lua_interface->GetSInt32Value(state, 3);
  2706. sint32 max = lua_interface->GetSInt32Value(state, 4);
  2707. quest->AddPrereqFaction(faction_id, min, max);
  2708. }
  2709. return 0;
  2710. }
  2711. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  2712. if (!lua_interface)
  2713. return 0;
  2714. Quest* quest = lua_interface->GetQuest(state);
  2715. if (quest) {
  2716. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2717. int8 quantity = lua_interface->GetInt8Value(state, 3);
  2718. if (quantity == 0)
  2719. quantity = 1;
  2720. Item* master_item = master_item_list.GetItem(item_id);
  2721. if (master_item) {
  2722. Item* item = new Item(master_item);
  2723. item->details.count = quantity;
  2724. quest->AddSelectableRewardItem(item);
  2725. }
  2726. }
  2727. return 0;
  2728. }
  2729. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  2730. if (!lua_interface)
  2731. return 0;
  2732. Quest* quest = lua_interface->GetQuest(state);
  2733. if (quest) {
  2734. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2735. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2736. if (quantity == 0)
  2737. quantity = 1;
  2738. Item* master_item = master_item_list.GetItem(item_id);
  2739. if (master_item) {
  2740. Item* item = new Item(master_item);
  2741. item->details.count = quantity;
  2742. quest->AddRewardItem(item);
  2743. }
  2744. }
  2745. return 0;
  2746. }
  2747. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  2748. if (!lua_interface)
  2749. return 0;
  2750. Quest* quest = lua_interface->GetQuest(state);
  2751. if (quest) {
  2752. int32 copper = lua_interface->GetInt32Value(state, 2);
  2753. int32 silver = lua_interface->GetInt32Value(state, 3);
  2754. int32 gold = lua_interface->GetInt32Value(state, 4);
  2755. int32 plat = lua_interface->GetInt32Value(state, 5);
  2756. quest->AddRewardCoins(copper, silver, gold, plat);
  2757. }
  2758. return 0;
  2759. }
  2760. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  2761. if (!lua_interface)
  2762. return 0;
  2763. Quest* quest = lua_interface->GetQuest(state);
  2764. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2765. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  2766. if (quest && faction_id > 0 && amount != 0)
  2767. quest->AddRewardFaction(faction_id, amount);
  2768. return 0;
  2769. }
  2770. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  2771. if (!lua_interface)
  2772. return 0;
  2773. Quest* quest = lua_interface->GetQuest(state);
  2774. if (quest) {
  2775. int32 status = lua_interface->GetInt32Value(state, 2);
  2776. quest->SetRewardStatus(status);
  2777. }
  2778. return 0;
  2779. }
  2780. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  2781. if (!lua_interface)
  2782. return 0;
  2783. Quest* quest = lua_interface->GetQuest(state);
  2784. if (quest) {
  2785. string comment = lua_interface->GetStringValue(state, 2);
  2786. quest->SetRewardComment(comment);
  2787. }
  2788. return 0;
  2789. }
  2790. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  2791. if (!lua_interface)
  2792. return 0;
  2793. Quest* quest = lua_interface->GetQuest(state);
  2794. if (quest) {
  2795. int32 exp = lua_interface->GetInt32Value(state, 2);
  2796. quest->SetRewardXP(exp);
  2797. }
  2798. return 0;
  2799. }
  2800. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  2801. Quest* quest = lua_interface->GetQuest(state);
  2802. if (quest) {
  2803. int32 step = lua_interface->GetInt32Value(state, 2);
  2804. string description = lua_interface->GetStringValue(state, 3);
  2805. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2806. float percentage = lua_interface->GetFloatValue(state, 5);
  2807. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2808. int16 icon = lua_interface->GetInt16Value(state, 7);
  2809. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  2810. const char* taskgroup = 0;
  2811. if (str_taskgroup.length() > 0)
  2812. taskgroup = str_taskgroup.c_str();
  2813. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  2814. if (quest_step && icon && quantity > 0)
  2815. quest_step->SetIcon(icon);
  2816. }
  2817. return 0;
  2818. }
  2819. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  2820. if (!lua_interface)
  2821. return 0;
  2822. Quest* quest = lua_interface->GetQuest(state);
  2823. if (quest) {
  2824. int32 step = lua_interface->GetInt32Value(state, 2);
  2825. string description = lua_interface->GetStringValue(state, 3);
  2826. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2827. float percentage = lua_interface->GetFloatValue(state, 5);
  2828. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2829. int16 icon = lua_interface->GetInt16Value(state, 7);
  2830. const char* taskgroup = 0;
  2831. if (str_taskgroup.length() > 0)
  2832. taskgroup = str_taskgroup.c_str();
  2833. int32 npc_id = 0;
  2834. vector<int32>* ids = 0;
  2835. Spawn* spawn = nullptr;
  2836. int i = 0;
  2837. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2838. if (ids == 0)
  2839. ids = new vector<int32>;
  2840. ids->push_back(npc_id);
  2841. i++;
  2842. }
  2843. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2844. if (quest_step && icon > 0 && quantity > 0)
  2845. quest_step->SetIcon(icon);
  2846. }
  2847. return 0;
  2848. }
  2849. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  2850. if (!lua_interface)
  2851. return 0;
  2852. Quest* quest = lua_interface->GetQuest(state);
  2853. if (quest) {
  2854. int32 step = lua_interface->GetInt32Value(state, 2);
  2855. string description = lua_interface->GetStringValue(state, 3);
  2856. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2857. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2858. int16 icon = lua_interface->GetInt16Value(state, 6);
  2859. const char* taskgroup = 0;
  2860. if (str_taskgroup.length() > 0)
  2861. taskgroup = str_taskgroup.c_str();
  2862. int32 npc_id = 0;
  2863. vector<int32>* ids = 0;
  2864. int i = 0;
  2865. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  2866. if (ids == 0)
  2867. ids = new vector<int32>;
  2868. ids->push_back(npc_id);
  2869. i++;
  2870. }
  2871. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  2872. if (quest_step && icon > 0)
  2873. quest_step->SetIcon(icon);
  2874. if (quest->GetPlayer()) {
  2875. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  2876. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  2877. }
  2878. }
  2879. return 0;
  2880. }
  2881. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  2882. if (!lua_interface)
  2883. return 0;
  2884. Quest* quest = lua_interface->GetQuest(state);
  2885. if (quest) {
  2886. int32 step = lua_interface->GetInt32Value(state, 2);
  2887. string description = lua_interface->GetStringValue(state, 3);
  2888. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2889. float percentage = lua_interface->GetFloatValue(state, 5);
  2890. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2891. int16 icon = lua_interface->GetInt16Value(state, 7);
  2892. const char* taskgroup = 0;
  2893. if (str_taskgroup.length() > 0)
  2894. taskgroup = str_taskgroup.c_str();
  2895. int32 item_id = 0;
  2896. vector<int32>* ids = 0;
  2897. int i = 0;
  2898. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2899. if (ids == 0)
  2900. ids = new vector<int32>;
  2901. ids->push_back(item_id);
  2902. i++;
  2903. }
  2904. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2905. if (quest_step && icon > 0 && quantity > 0)
  2906. quest_step->SetIcon(icon);
  2907. }
  2908. return 0;
  2909. }
  2910. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  2911. if (!lua_interface)
  2912. return 0;
  2913. Quest* quest = lua_interface->GetQuest(state);
  2914. if (quest) {
  2915. int32 step = lua_interface->GetInt32Value(state, 2);
  2916. string description = lua_interface->GetStringValue(state, 3);
  2917. float max_variation = lua_interface->GetFloatValue(state, 4);
  2918. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2919. int16 icon = lua_interface->GetInt16Value(state, 6);
  2920. const char* taskgroup = 0;
  2921. if (str_taskgroup.length() > 0)
  2922. taskgroup = str_taskgroup.c_str();
  2923. vector<Location>* locations = 0;
  2924. int i = 7;
  2925. while (true) {
  2926. Location loc;
  2927. loc.x = lua_interface->GetFloatValue(state, i);
  2928. loc.y = lua_interface->GetFloatValue(state, i + 1);
  2929. loc.z = lua_interface->GetFloatValue(state, i + 2);
  2930. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  2931. break;
  2932. if (locations == 0)
  2933. locations = new vector<Location>;
  2934. locations->push_back(loc);
  2935. i += 3;
  2936. }
  2937. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  2938. if (quest_step && icon > 0)
  2939. quest_step->SetIcon(icon);
  2940. }
  2941. return 0;
  2942. }
  2943. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  2944. if (!lua_interface)
  2945. return 0;
  2946. Quest* quest = lua_interface->GetQuest(state);
  2947. if (quest) {
  2948. int32 step = lua_interface->GetInt32Value(state, 2);
  2949. string description = lua_interface->GetStringValue(state, 3);
  2950. float max_variation = lua_interface->GetFloatValue(state, 4);
  2951. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2952. int16 icon = lua_interface->GetInt16Value(state, 6);
  2953. const char* taskgroup = 0;
  2954. if (str_taskgroup.length() > 0)
  2955. taskgroup = str_taskgroup.c_str();
  2956. vector<Location>* locations = 0;
  2957. int i = 7;
  2958. while (true) {
  2959. Location loc;
  2960. loc.x = lua_interface->GetFloatValue(state, i);
  2961. loc.y = lua_interface->GetFloatValue(state, i + 1);
  2962. loc.z = lua_interface->GetFloatValue(state, i + 2);
  2963. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  2964. break;
  2965. if (locations == 0)
  2966. locations = new vector<Location>;
  2967. locations->push_back(loc);
  2968. i += 3;
  2969. }
  2970. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  2971. if (quest_step && icon > 0)
  2972. quest_step->SetIcon(icon);
  2973. }
  2974. return 0;
  2975. }
  2976. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  2977. Quest* quest = lua_interface->GetQuest(state);
  2978. if (quest) {
  2979. int32 step = lua_interface->GetInt32Value(state, 2);
  2980. string description = lua_interface->GetStringValue(state, 3);
  2981. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2982. float percentage = lua_interface->GetFloatValue(state, 5);
  2983. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2984. int16 icon = lua_interface->GetInt16Value(state, 7);
  2985. const char* taskgroup = 0;
  2986. if (str_taskgroup.length() > 0)
  2987. taskgroup = str_taskgroup.c_str();
  2988. int32 spell_id = 0;
  2989. vector<int32>* ids = 0;
  2990. int i = 0;
  2991. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2992. if (ids == 0)
  2993. ids = new vector<int32>;
  2994. ids->push_back(spell_id);
  2995. i++;
  2996. }
  2997. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2998. if (quest_step && icon > 0 && quantity > 0)
  2999. quest_step->SetIcon(icon);
  3000. }
  3001. return 0;
  3002. }
  3003. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3004. if (!lua_interface)
  3005. return 0;
  3006. Quest* quest = lua_interface->GetQuest(state);
  3007. if (quest) {
  3008. int32 step = lua_interface->GetInt32Value(state, 2);
  3009. string description = lua_interface->GetStringValue(state, 3);
  3010. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3011. float percentage = lua_interface->GetFloatValue(state, 5);
  3012. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3013. int16 icon = lua_interface->GetInt16Value(state, 7);
  3014. const char* taskgroup = 0;
  3015. if (str_taskgroup.length() > 0)
  3016. taskgroup = str_taskgroup.c_str();
  3017. int32 item_id = 0;
  3018. vector<int32>* ids = 0;
  3019. int i = 0;
  3020. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3021. if (ids == 0)
  3022. ids = new vector<int32>;
  3023. ids->push_back(item_id);
  3024. i++;
  3025. }
  3026. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3027. if (quest_step && icon > 0 && quantity > 0)
  3028. quest_step->SetIcon(icon);
  3029. }
  3030. return 0;
  3031. }
  3032. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3033. if (!lua_interface)
  3034. return 0;
  3035. Quest* quest = lua_interface->GetQuest(state);
  3036. if (quest) {
  3037. int32 step = lua_interface->GetInt32Value(state, 2);
  3038. string description = lua_interface->GetStringValue(state, 3);
  3039. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3040. float percentage = lua_interface->GetFloatValue(state, 5);
  3041. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3042. int16 icon = lua_interface->GetInt16Value(state, 7);
  3043. const char* taskgroup = 0;
  3044. if (str_taskgroup.length() > 0)
  3045. taskgroup = str_taskgroup.c_str();
  3046. int32 item_id = 0;
  3047. vector<int32>* ids = 0;
  3048. int i = 0;
  3049. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3050. if (ids == 0)
  3051. ids = new vector<int32>;
  3052. ids->push_back(item_id);
  3053. i++;
  3054. }
  3055. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3056. if (quest_step && icon > 0 && quantity > 0)
  3057. quest_step->SetIcon(icon);
  3058. }
  3059. return 0;
  3060. }
  3061. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3062. if (!lua_interface)
  3063. return 0;
  3064. Quest* quest = lua_interface->GetQuest(state);
  3065. if (quest) {
  3066. string action = lua_interface->GetStringValue(state, 2);
  3067. if (action.length() > 0)
  3068. quest->SetCompleteAction(action);
  3069. }
  3070. return 0;
  3071. }
  3072. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3073. if (!lua_interface)
  3074. return 0;
  3075. Quest* quest = lua_interface->GetQuest(state);
  3076. if (quest) {
  3077. int32 step = lua_interface->GetInt32Value(state, 2);
  3078. string action = lua_interface->GetStringValue(state, 3);
  3079. if (step > 0 && action.length() > 0)
  3080. quest->AddCompleteAction(step, action);
  3081. }
  3082. return 0;
  3083. }
  3084. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3085. if (!lua_interface)
  3086. return 0;
  3087. Quest* quest = lua_interface->GetQuest(state);
  3088. if (quest) {
  3089. int32 step = lua_interface->GetInt32Value(state, 2);
  3090. string action = lua_interface->GetStringValue(state, 3);
  3091. if (step > 0 && action.length() > 0)
  3092. quest->AddProgressAction(step, action);
  3093. }
  3094. return 0;
  3095. }
  3096. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3097. if (!lua_interface)
  3098. return 0;
  3099. Quest* quest = lua_interface->GetQuest(state);
  3100. string description = lua_interface->GetStringValue(state, 2);
  3101. if (quest && description.length() > 0)
  3102. quest->SetDescription(description);
  3103. return 0;
  3104. }
  3105. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3106. if (!lua_interface)
  3107. return 0;
  3108. Quest* quest = lua_interface->GetQuest(state);
  3109. string description = lua_interface->GetStringValue(state, 2);
  3110. if (quest && description.length() > 0)
  3111. quest->SetCompletedDescription(description);
  3112. return 0;
  3113. }
  3114. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3115. if (!lua_interface)
  3116. return 0;
  3117. Quest* quest = lua_interface->GetQuest(state);
  3118. int32 step = lua_interface->GetInt32Value(state, 2);
  3119. string description = lua_interface->GetStringValue(state, 3);
  3120. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3121. if (quest && step > 0 && description.length() > 0) {
  3122. quest->SetTaskGroupDescription(step, description, display_bullets);
  3123. if (quest->GetPlayer()) {
  3124. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3125. if (client)
  3126. client->SendQuestUpdateStep(quest, step, false);
  3127. }
  3128. }
  3129. return 0;
  3130. }
  3131. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3132. if (!lua_interface)
  3133. return 0;
  3134. Quest* quest = lua_interface->GetQuest(state);
  3135. int32 step = lua_interface->GetInt32Value(state, 2);
  3136. string description = lua_interface->GetStringValue(state, 3);
  3137. if (quest && step > 0 && description.length() > 0) {
  3138. quest->SetStepDescription(step, description);
  3139. if (quest->GetPlayer()) {
  3140. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3141. if (client)
  3142. client->SendQuestUpdateStep(quest, step);
  3143. }
  3144. }
  3145. return 0;
  3146. }
  3147. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3148. Quest* quest = lua_interface->GetQuest(state);
  3149. string zone = lua_interface->GetStringValue(state, 2);
  3150. if (quest && zone.length() > 0)
  3151. quest->SetZone(zone);
  3152. return 0;
  3153. }
  3154. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3155. if (!lua_interface)
  3156. return 0;
  3157. Quest* quest = lua_interface->GetQuest(state);
  3158. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3159. if (quest && spawn) {
  3160. if (spawn->IsPlayer()) {
  3161. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3162. if (client)
  3163. client->AddPendingQuestReward(quest);
  3164. }
  3165. }
  3166. return 0;
  3167. }
  3168. int EQ2Emu_lua_Harvest(lua_State* state) {
  3169. if (!lua_interface)
  3170. return 0;
  3171. Spawn* player = lua_interface->GetSpawn(state);
  3172. Spawn* node = lua_interface->GetSpawn(state, 2);
  3173. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3174. Client* client = player->GetZone()->GetClientBySpawn(player);
  3175. if (client) {
  3176. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3177. ((GroundSpawn*)node)->ProcessHarvest(client);
  3178. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3179. player->GetZone()->RemoveSpawn(true, node, true);
  3180. }
  3181. }
  3182. else if (player && player->IsPlayer()) {
  3183. Client* client = player->GetZone()->GetClientBySpawn(player);
  3184. if (client)
  3185. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3186. }
  3187. return 0;
  3188. }
  3189. int EQ2Emu_lua_Bind(lua_State* state) {
  3190. if (!lua_interface)
  3191. return 0;
  3192. Spawn* spawn = lua_interface->GetSpawn(state);
  3193. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3194. float x = lua_interface->GetFloatValue(state, 3);
  3195. float y = lua_interface->GetFloatValue(state, 4);
  3196. float z = lua_interface->GetFloatValue(state, 5);
  3197. float h = lua_interface->GetFloatValue(state, 6);
  3198. if (!spawn) {
  3199. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3200. return 0;
  3201. }
  3202. if (!spawn->IsPlayer()) {
  3203. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3204. return 0;
  3205. }
  3206. if (zone_id == 0) {
  3207. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3208. if (!client) {
  3209. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3210. return 0;
  3211. }
  3212. if (!client->Bind())
  3213. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3214. }
  3215. else {
  3216. Player* player = (Player*)spawn;
  3217. player->GetPlayerInfo()->SetBindZone(zone_id);
  3218. player->GetPlayerInfo()->SetBindX(x);
  3219. player->GetPlayerInfo()->SetBindY(y);
  3220. player->GetPlayerInfo()->SetBindZ(z);
  3221. player->GetPlayerInfo()->SetBindHeading(h);
  3222. }
  3223. return 0;
  3224. }
  3225. int EQ2Emu_lua_Gate(lua_State* state) {
  3226. if (!lua_interface)
  3227. return 0;
  3228. Spawn* spawn = lua_interface->GetSpawn(state);
  3229. if (spawn) {
  3230. if (spawn->IsPlayer()) {
  3231. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3232. if (client) {
  3233. if (!client->Gate())
  3234. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3235. }
  3236. }
  3237. }
  3238. return 0;
  3239. }
  3240. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3241. if (!lua_interface)
  3242. return 0;
  3243. bool ret = false;
  3244. Spawn* spawn = lua_interface->GetSpawn(state);
  3245. if (spawn) {
  3246. if (spawn->IsPlayer()) {
  3247. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3248. if (client)
  3249. ret = client->BindAllowed();
  3250. }
  3251. }
  3252. lua_interface->SetBooleanValue(state, ret);
  3253. return 1;
  3254. }
  3255. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3256. if (!lua_interface)
  3257. return 0;
  3258. bool ret = false;
  3259. Spawn* spawn = lua_interface->GetSpawn(state);
  3260. if (spawn) {
  3261. if (spawn->IsPlayer()) {
  3262. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3263. if (client)
  3264. ret = client->GateAllowed();
  3265. }
  3266. }
  3267. lua_interface->SetBooleanValue(state, ret);
  3268. return 1;
  3269. }
  3270. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3271. Spawn* spawn = lua_interface->GetSpawn(state);
  3272. if (spawn) {
  3273. lua_interface->SetBooleanValue(state, spawn->Alive());
  3274. return 1;
  3275. }
  3276. return 0;
  3277. }
  3278. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3279. if (!lua_interface)
  3280. return 0;
  3281. Spawn* spawn = lua_interface->GetSpawn(state);
  3282. if (spawn && spawn->IsEntity()) {
  3283. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3284. return 1;
  3285. }
  3286. return 0;
  3287. }
  3288. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3289. Spawn* spawn = lua_interface->GetSpawn(state);
  3290. string message = lua_interface->GetStringValue(state, 2);
  3291. string color_str = lua_interface->GetStringValue(state, 3);
  3292. int8 color = CHANNEL_COLOR_WHITE;
  3293. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3294. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3295. if (client) {
  3296. if (color_str.length() > 0) {
  3297. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3298. color = CHANNEL_COLOR_RED;
  3299. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3300. color = CHANNEL_COLOR_YELLOW;
  3301. }
  3302. client->SimpleMessage(color, message.c_str());
  3303. }
  3304. }
  3305. return 0;
  3306. }
  3307. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3308. Spawn* spawn = lua_interface->GetSpawn(state);
  3309. string message = lua_interface->GetStringValue(state, 2);
  3310. int8 red = lua_interface->GetInt8Value(state, 3);
  3311. int8 green = lua_interface->GetInt8Value(state, 4);
  3312. int8 blue = lua_interface->GetInt8Value(state, 5);
  3313. if (!spawn) {
  3314. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3315. return 0;
  3316. }
  3317. int32 words = ::CountWordsInString(message.c_str());
  3318. if (words < 5)
  3319. words = 5;
  3320. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3321. if (client)
  3322. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3323. return 0;
  3324. }
  3325. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3326. Spawn* spawn = lua_interface->GetSpawn(state);
  3327. int8 param = lua_interface->GetInt8Value(state, 2);
  3328. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3329. int8 value = lua_interface->GetInt8Value(state, 4);
  3330. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3331. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3332. if (client) {
  3333. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3334. switch (param) {
  3335. case 1: {
  3336. packet->setDataByName("parameter1", param_value);
  3337. break;
  3338. }
  3339. case 2: {
  3340. packet->setDataByName("parameter2", param_value);
  3341. break;
  3342. }
  3343. case 3: {
  3344. packet->setDataByName("parameter3", param_value);
  3345. break;
  3346. }
  3347. case 4: {
  3348. packet->setDataByName("parameter4", param_value);
  3349. break;
  3350. }
  3351. case 5: {
  3352. packet->setDataByName("parameter5", param_value);
  3353. break;
  3354. }
  3355. }
  3356. packet->setDataByName("value", value);
  3357. client->QueuePacket(packet->serialize());
  3358. safe_delete(packet);
  3359. }
  3360. }
  3361. return 0;
  3362. }
  3363. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3364. Spawn* spawn = lua_interface->GetSpawn(state);
  3365. if (spawn && spawn->IsPlayer()) {
  3366. if (((Player*)spawn)->GetIsTracking())
  3367. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3368. else
  3369. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3370. }
  3371. return 0;
  3372. }
  3373. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3374. Spawn* player = lua_interface->GetSpawn(state);
  3375. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3376. string name = lua_interface->GetStringValue(state, 3);
  3377. float distance = lua_interface->GetFloatValue(state, 4);
  3378. string command = lua_interface->GetStringValue(state, 5);
  3379. string error_text = lua_interface->GetStringValue(state, 6);
  3380. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3381. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3382. if (spawn && player && player->IsPlayer() && name.length() > 0) {
  3383. if (distance == 0)
  3384. distance = 10.0f;
  3385. if (command.length() == 0)
  3386. command = name;
  3387. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  3388. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3389. }
  3390. return 0;
  3391. }
  3392. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3393. if (!lua_interface)
  3394. return 0;
  3395. Spawn* player = lua_interface->GetSpawn(state);
  3396. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3397. int16 tier = lua_interface->GetInt16Value(state, 3);
  3398. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3399. if (player && spell && player->IsPlayer()) {
  3400. Client* client = player->GetZone()->GetClientBySpawn(player);
  3401. if (client) {
  3402. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3403. {
  3404. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3405. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3406. client->GetPlayer()->UnlockSpell(spell);
  3407. client->SendSpellUpdate(spell);
  3408. }
  3409. else
  3410. {
  3411. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3412. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3413. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3414. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3415. client->GetPlayer()->UnlockSpell(spell);
  3416. client->SendSpellUpdate(spell);
  3417. }
  3418. //if (client ) {
  3419. // ((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);
  3420. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3421. if (outapp)
  3422. client->QueuePacket(outapp);
  3423. }
  3424. }
  3425. return 0;
  3426. }
  3427. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3428. if (!lua_interface)
  3429. return 0;
  3430. Spawn* player = lua_interface->GetSpawn(state);
  3431. if (player && player->IsPlayer()) {
  3432. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3433. return 1;
  3434. }
  3435. return 0;
  3436. }
  3437. int EQ2Emu_lua_Attack(lua_State* state) {
  3438. if (lua_interface) {
  3439. Spawn* npc = lua_interface->GetSpawn(state);
  3440. Spawn* player = lua_interface->GetSpawn(state, 2);
  3441. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3442. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3443. }
  3444. return 0;
  3445. }
  3446. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3447. if (lua_interface) {
  3448. Spawn* target = lua_interface->GetSpawn(state);
  3449. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3450. if (target && target->GetZone())
  3451. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3452. }
  3453. return 0;
  3454. }
  3455. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3456. Spawn* player;
  3457. if (lua_interface) {
  3458. player = lua_interface->GetSpawn(state);
  3459. if (player && player->IsPlayer()) {
  3460. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3461. return 1;
  3462. }
  3463. }
  3464. return 0;
  3465. }
  3466. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3467. Spawn* player;
  3468. Client* client;
  3469. if (lua_interface) {
  3470. player = lua_interface->GetSpawn(state);
  3471. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3472. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3473. client->HandInCollections();
  3474. }
  3475. return 0;
  3476. }
  3477. int EQ2Emu_lua_UseWidget(lua_State* state) {
  3478. Spawn* widget;
  3479. if (lua_interface) {
  3480. widget = lua_interface->GetSpawn(state);
  3481. if (widget && widget->IsWidget())
  3482. ((Widget*)widget)->HandleUse(NULL, "");
  3483. }
  3484. return 0;
  3485. }
  3486. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  3487. Spawn* spawn = 0;
  3488. int32 primary_list = 0;
  3489. int32 secondary_list = 0;
  3490. if (lua_interface) {
  3491. spawn = lua_interface->GetSpawn(state);
  3492. primary_list = lua_interface->GetInt32Value(state, 2);
  3493. secondary_list = lua_interface->GetInt32Value(state, 3);
  3494. if (!spawn->IsNPC()) {
  3495. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  3496. return 0;
  3497. }
  3498. NPC* npc = (NPC*)spawn;
  3499. npc->SetPrimarySpellList(primary_list);
  3500. npc->SetSecondarySpellList(secondary_list);
  3501. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  3502. }
  3503. return 0;
  3504. }
  3505. int EQ2Emu_lua_GetPet(lua_State* state) {
  3506. if (!lua_interface)
  3507. return 0;
  3508. Spawn* spawn = lua_interface->GetSpawn(state);
  3509. if (spawn) {
  3510. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  3511. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  3512. return 1;
  3513. }
  3514. }
  3515. return 0;
  3516. }
  3517. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  3518. if (!lua_interface)
  3519. return 0;
  3520. Spawn* spawn = lua_interface->GetSpawn(state);
  3521. if (spawn) {
  3522. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  3523. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  3524. return 1;
  3525. }
  3526. }
  3527. return 0;
  3528. }
  3529. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  3530. if (!lua_interface)
  3531. return 0;
  3532. Spawn* spawn = lua_interface->GetSpawn(state);
  3533. if (spawn) {
  3534. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  3535. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  3536. return 1;
  3537. }
  3538. }
  3539. return 0;
  3540. }
  3541. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  3542. if (!lua_interface)
  3543. return 0;
  3544. Spawn* spawn = lua_interface->GetSpawn(state);
  3545. if (spawn) {
  3546. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  3547. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  3548. return 1;
  3549. }
  3550. }
  3551. return 0;
  3552. }
  3553. int EQ2Emu_lua_Charm(lua_State* state) {
  3554. if (!lua_interface)
  3555. return 0;
  3556. Spawn* owner = lua_interface->GetSpawn(state);
  3557. Spawn* pet = lua_interface->GetSpawn(state, 2);
  3558. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3559. if (!luaspell) {
  3560. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  3561. return 0;
  3562. }
  3563. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  3564. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  3565. pet->SetPet(true);
  3566. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  3567. ((NPC*)pet)->SetOwner((Entity*)owner);
  3568. // If owner is player and player does not have a summoned pet set the players charsheet
  3569. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  3570. Player* player = (Player*)owner;
  3571. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3572. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  3573. player->GetInfoStruct()->pet_movement = 2;
  3574. player->GetInfoStruct()->pet_behavior = 3;
  3575. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3576. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3577. // Make sure the values get sent to the client
  3578. player->SetCharSheetChanged(true);
  3579. }
  3580. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  3581. pet->SetSpawnScript("");
  3582. // Set faction to the same as the owner
  3583. pet->SetFactionID(owner->GetFactionID());
  3584. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3585. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3586. // Clear hate list
  3587. ((NPC*)pet)->Brain()->ClearHate();
  3588. // Set the brain to a pet brain
  3589. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  3590. }
  3591. return 0;
  3592. }
  3593. int EQ2Emu_lua_GetGroup(lua_State* state) {
  3594. if (!lua_interface)
  3595. return 0;
  3596. Spawn* spawn = lua_interface->GetSpawn(state);
  3597. if (!spawn) {
  3598. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  3599. return 0;
  3600. }
  3601. vector<Spawn*> groupMembers;
  3602. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  3603. groupMembers = *spawn->GetSpawnGroup();
  3604. }
  3605. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  3606. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  3607. deque<GroupMemberInfo*>::iterator itr;
  3608. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  3609. GroupMemberInfo* info = 0;
  3610. for (itr = members->begin(); itr != members->end(); itr++) {
  3611. info = *itr;
  3612. if (info->client)
  3613. groupMembers.push_back(info->client->GetPlayer());
  3614. }
  3615. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  3616. }
  3617. else
  3618. return 0;
  3619. lua_createtable(state, groupMembers.size(), 0);
  3620. int newTable = lua_gettop(state);
  3621. for (int32 i = 0; i < groupMembers.size(); i++) {
  3622. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  3623. lua_rawseti(state, newTable, i + 1);
  3624. }
  3625. return 1;
  3626. }
  3627. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  3628. if (!lua_interface)
  3629. return 0;
  3630. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  3631. lua_interface->SetOptionWindowValue(state, option_window);
  3632. return 1;
  3633. }
  3634. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  3635. if (!lua_interface)
  3636. return 0;
  3637. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  3638. if (option_window) {
  3639. OptionWindowOption option_window_option;
  3640. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  3641. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  3642. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  3643. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  3644. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  3645. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  3646. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  3647. option_window->push_back(option_window_option);
  3648. }
  3649. return 0;
  3650. }
  3651. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  3652. if (!lua_interface)
  3653. return 0;
  3654. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  3655. Spawn* player = lua_interface->GetSpawn(state, 2);
  3656. string window_title = lua_interface->GetStringValue(state, 3);
  3657. string cancel_command = lua_interface->GetStringValue(state, 4);
  3658. Client* client = player->GetZone()->GetClientBySpawn(player);
  3659. if (option_window && window_title.length() > 0 && client) {
  3660. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  3661. if (!packet)
  3662. return 0;
  3663. packet->setDataByName("title_text", window_title.c_str());
  3664. if (cancel_command.length() > 0)
  3665. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  3666. packet->setArrayLengthByName("num_selections", option_window->size());
  3667. vector<OptionWindowOption>::iterator itr;
  3668. int8 i = 0;
  3669. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  3670. OptionWindowOption opt = *itr;
  3671. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  3672. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  3673. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  3674. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  3675. if (opt.optionCommand.length() > 0)
  3676. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  3677. if (opt.optionConfirmTitle.length() > 0)
  3678. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  3679. i++;
  3680. }
  3681. client->QueuePacket(packet->serialize());
  3682. safe_delete(option_window);
  3683. safe_delete(packet);
  3684. }
  3685. return 0;
  3686. }
  3687. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  3688. if (!lua_interface)
  3689. return 0;
  3690. Spawn* spawn = lua_interface->GetSpawn(state);
  3691. if (spawn) {
  3692. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  3693. return 1;
  3694. }
  3695. else
  3696. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3697. return 0;
  3698. }
  3699. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  3700. if (!lua_interface)
  3701. return 0;
  3702. Spawn* spawn = lua_interface->GetSpawn(state);
  3703. if (spawn) {
  3704. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  3705. return 1;
  3706. }
  3707. else
  3708. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  3709. return 0;
  3710. }
  3711. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  3712. if (!lua_interface)
  3713. return 0;
  3714. Spawn* spawn = lua_interface->GetSpawn(state);
  3715. if (spawn) {
  3716. int8 class_id = spawn->GetTradeskillClass();
  3717. // Need to add 42 for the offset in the array
  3718. class_id += 44;
  3719. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  3720. return 1;
  3721. }
  3722. else
  3723. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3724. return 0;
  3725. }
  3726. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  3727. if (!lua_interface)
  3728. return 0;
  3729. Spawn* spawn = lua_interface->GetSpawn(state);
  3730. int16 level = lua_interface->GetInt8Value(state, 2);
  3731. if (spawn) {
  3732. if (spawn->IsPlayer())
  3733. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  3734. else
  3735. spawn->SetTSLevel(level);
  3736. }
  3737. else
  3738. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3739. return 0;
  3740. }
  3741. int EQ2Emu_lua_SummonPet(lua_State* state) {
  3742. // Check to see if we have a valid lua_interface
  3743. if (!lua_interface)
  3744. return 0;
  3745. // Get the spawn that is getting the pet
  3746. Spawn* spawn = lua_interface->GetSpawn(state);
  3747. // Get the DB ID of the pet
  3748. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3749. // The max level the pet can gain
  3750. int8 max_level = lua_interface->GetInt8Value(state, 3);
  3751. // Get the spell that this command was called from
  3752. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3753. // Check to make sure the spawn pointer is valid
  3754. if (!spawn) {
  3755. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3756. return 0;
  3757. }
  3758. // Check to make sure the spawn is an entity
  3759. if (!spawn->IsEntity()) {
  3760. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3761. return 0;
  3762. }
  3763. // Check to make sure the spawn doesn't already have a pet of this type
  3764. if (((Entity*)spawn)->GetPet()) {
  3765. if (spawn->IsPlayer()) {
  3766. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3767. if (client)
  3768. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  3769. }
  3770. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3771. return 0;
  3772. }
  3773. // Check to see if the DB ID for the pet is set
  3774. if (pet_id == 0) {
  3775. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3776. return 0;
  3777. }
  3778. // Check to see if the pointer to the spell is valid
  3779. if (!luaspell) {
  3780. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3781. return 0;
  3782. }
  3783. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  3784. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3785. if (!pet) {
  3786. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3787. return 0;
  3788. }
  3789. // Check to make sure the pet is an npc
  3790. if (!pet->IsNPC()) {
  3791. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  3792. return 0;
  3793. }
  3794. // Spawn the pet at the same location as the owner
  3795. pet->SetX(spawn->GetX());
  3796. pet->SetY(spawn->GetY());
  3797. pet->SetZ(spawn->GetZ());
  3798. pet->SetLocation(spawn->GetLocation());
  3799. pet->SetHeading(spawn->GetHeading());
  3800. spawn->GetZone()->AddSpawn(pet);
  3801. /*
  3802. const char* spawn_script = world.GetSpawnScript(pet_id);
  3803. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  3804. spawn->SetSpawnScript(string(spawn_script));
  3805. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  3806. }*/
  3807. // Get a random pet name
  3808. string random_pet_name;
  3809. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3810. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3811. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3812. // If player set various values for the char sheet (pet window)
  3813. if (spawn->IsPlayer()) {
  3814. Player* player = (Player*)spawn;
  3815. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3816. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  3817. player->GetInfoStruct()->pet_movement = 2;
  3818. player->GetInfoStruct()->pet_behavior = 3;
  3819. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3820. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3821. // Make sure the values get sent to the client
  3822. player->SetCharSheetChanged(true);
  3823. }
  3824. // Set the pets name
  3825. pet->SetName(random_pet_name.c_str());
  3826. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  3827. if (max_level > 0)
  3828. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  3829. else
  3830. pet->SetLevel(spawn->GetLevel());
  3831. // Set the max level this pet can reach
  3832. ((NPC*)pet)->SetMaxPetLevel(max_level);
  3833. // Set the faction of the pet to the same faction as the owner
  3834. pet->SetFactionID(spawn->GetFactionID());
  3835. // Set the spawn as a pet
  3836. pet->SetPet(true);
  3837. // Give a pointer of the owner to the pet
  3838. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3839. // Give a pointer of the pet to the owner
  3840. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  3841. // Set the pet type
  3842. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  3843. // Set the spell id used to create this pet
  3844. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3845. // Set the spell tier used to create this pet
  3846. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3847. // Set the pets spawn type to 6
  3848. pet->SetSpawnType(6);
  3849. // Set the pets brain
  3850. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  3851. // Check to see if the pet has a subtitle
  3852. if (strlen(pet->GetSubTitle()) > 0) {
  3853. // Add the players name to the front of the sub title
  3854. string pet_subtitle;
  3855. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3856. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3857. // Set the pets subtitle to the new one
  3858. pet->SetSubTitle(pet_subtitle.c_str());
  3859. }
  3860. // Add the "Pet Options" entity command to the pet
  3861. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3862. // Set the pet as the return value for this function
  3863. lua_interface->SetSpawnValue(state, pet);
  3864. return 1;
  3865. }
  3866. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  3867. if (!lua_interface)
  3868. return 0;
  3869. Spawn* spawn = lua_interface->GetSpawn(state);
  3870. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3871. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3872. if (!spawn) {
  3873. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3874. return 0;
  3875. }
  3876. if (!spawn->IsEntity()) {
  3877. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3878. return 0;
  3879. }
  3880. if (((Entity*)spawn)->GetDeityPet()) {
  3881. if (spawn->IsPlayer()) {
  3882. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3883. if (client)
  3884. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  3885. }
  3886. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3887. return 0;
  3888. }
  3889. if (pet_id == 0) {
  3890. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3891. return 0;
  3892. }
  3893. if (!luaspell) {
  3894. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3895. return 0;
  3896. }
  3897. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3898. if (!pet) {
  3899. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3900. return 0;
  3901. }
  3902. if (!pet->IsNPC()) {
  3903. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  3904. return 0;
  3905. }
  3906. pet->SetX(spawn->GetX());
  3907. pet->SetY(spawn->GetY());
  3908. pet->SetZ(spawn->GetZ());
  3909. pet->SetLocation(spawn->GetLocation());
  3910. pet->SetHeading(spawn->GetHeading());
  3911. spawn->GetZone()->AddSpawn(pet);
  3912. string random_pet_name;
  3913. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3914. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3915. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3916. pet->SetName(random_pet_name.c_str());
  3917. pet->SetLevel(spawn->GetLevel());
  3918. pet->SetFactionID(spawn->GetFactionID());
  3919. pet->SetPet(true);
  3920. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  3921. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3922. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  3923. pet->SetSpawnType(6);
  3924. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  3925. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3926. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3927. if (strlen(pet->GetSubTitle()) > 0) {
  3928. string pet_subtitle;
  3929. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3930. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3931. pet->SetSubTitle(pet_subtitle.c_str());
  3932. }
  3933. // deity and cosmetic pets are not attackable
  3934. pet->SetAttackable(false);
  3935. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3936. lua_interface->SetSpawnValue(state, pet);
  3937. return 1;
  3938. }
  3939. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  3940. if (!lua_interface)
  3941. return 0;
  3942. Spawn* spawn = lua_interface->GetSpawn(state);
  3943. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3944. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3945. if (!spawn) {
  3946. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3947. return 0;
  3948. }
  3949. if (!spawn->IsEntity()) {
  3950. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3951. return 0;
  3952. }
  3953. if (((Entity*)spawn)->GetCosmeticPet()) {
  3954. if (spawn->IsPlayer()) {
  3955. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3956. if (client)
  3957. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  3958. }
  3959. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3960. return 0;
  3961. }
  3962. if (pet_id == 0) {
  3963. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3964. return 0;
  3965. }
  3966. if (!luaspell) {
  3967. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3968. return 0;
  3969. }
  3970. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3971. if (!pet) {
  3972. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3973. return 0;
  3974. }
  3975. if (!pet->IsNPC()) {
  3976. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  3977. return 0;
  3978. }
  3979. pet->SetX(spawn->GetX());
  3980. pet->SetY(spawn->GetY());
  3981. pet->SetZ(spawn->GetZ());
  3982. pet->SetLocation(spawn->GetLocation());
  3983. pet->SetHeading(spawn->GetHeading());
  3984. spawn->GetZone()->AddSpawn(pet);
  3985. string random_pet_name;
  3986. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3987. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3988. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3989. pet->SetName(random_pet_name.c_str());
  3990. pet->SetLevel(spawn->GetLevel());
  3991. pet->SetFactionID(spawn->GetFactionID());
  3992. pet->SetPet(true);
  3993. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  3994. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3995. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  3996. pet->SetSpawnType(6);
  3997. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  3998. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3999. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4000. if (strlen(pet->GetSubTitle()) > 0) {
  4001. string pet_subtitle;
  4002. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4003. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4004. pet->SetSubTitle(pet_subtitle.c_str());
  4005. }
  4006. pet->SetAttackable(false);
  4007. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4008. lua_interface->SetSpawnValue(state, pet);
  4009. return 1;
  4010. }
  4011. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4012. if (!lua_interface)
  4013. return 0;
  4014. Spawn* spawn = lua_interface->GetSpawn(state);
  4015. if (!spawn) {
  4016. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4017. return 0;
  4018. }
  4019. if (!spawn->IsPet()) {
  4020. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4021. return 0;
  4022. }
  4023. if (!((NPC*)spawn)->IsDismissing())
  4024. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
  4025. return 0;
  4026. }
  4027. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4028. if (!lua_interface)
  4029. return 0;
  4030. Quest* quest = lua_interface->GetQuest(state);
  4031. if (!quest) {
  4032. 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));
  4033. return 0;
  4034. }
  4035. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4036. if (feather_color > 0)
  4037. quest->SetFeatherColor(feather_color);
  4038. return 0;
  4039. }
  4040. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4041. if (!lua_interface)
  4042. return 0;
  4043. Spawn* spawn = lua_interface->GetSpawn(state);
  4044. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4045. if (!spawn) {
  4046. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4047. return 0;
  4048. }
  4049. if (!spawn2) {
  4050. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4051. return 0;
  4052. }
  4053. spawn->RemoveSpawnAccess(spawn2);
  4054. return 0;
  4055. }
  4056. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4057. if (!lua_interface)
  4058. return 0;
  4059. ZoneServer* zone = lua_interface->GetZone(state);
  4060. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4061. if (!zone) {
  4062. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4063. return 0;
  4064. }
  4065. if (location_id == 0) {
  4066. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4067. return 0;
  4068. }
  4069. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4070. if (!location) {
  4071. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4072. return 0;
  4073. }
  4074. Spawn* spawn = 0;
  4075. if (location->entities[0]) {
  4076. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4077. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4078. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4079. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4080. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4081. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4082. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4083. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4084. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4085. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4086. if (spawn) {
  4087. const char* script = 0;
  4088. for (int x = 0; x < 3; x++) {
  4089. switch (x) {
  4090. case 0:
  4091. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4092. break;
  4093. case 1:
  4094. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4095. break;
  4096. case 2:
  4097. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4098. break;
  4099. }
  4100. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4101. spawn->SetSpawnScript(string(script));
  4102. break;
  4103. }
  4104. }
  4105. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4106. lua_interface->SetSpawnValue(state, spawn);
  4107. return 1;
  4108. }
  4109. else {
  4110. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4111. safe_delete(spawn);
  4112. }
  4113. }
  4114. return 0;
  4115. }
  4116. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4117. if (!lua_interface)
  4118. return 0;
  4119. Spawn* caster = lua_interface->GetSpawn(state);
  4120. Spawn* target = lua_interface->GetSpawn(state, 2);
  4121. int32 id = lua_interface->GetInt32Value(state, 3);
  4122. string command = lua_interface->GetStringValue(state, 4);
  4123. if (!caster) {
  4124. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4125. return 0;
  4126. }
  4127. if (!target) {
  4128. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4129. return 0;
  4130. }
  4131. if (!caster->IsPlayer()) {
  4132. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4133. return 0;
  4134. }
  4135. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4136. if (!entity_command) {
  4137. 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());
  4138. return 0;
  4139. }
  4140. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4141. if (!client) {
  4142. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4143. return 0;
  4144. }
  4145. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4146. return 0;
  4147. }
  4148. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4149. if (!lua_interface)
  4150. return 0;
  4151. Spawn* spawn = lua_interface->GetSpawn(state);
  4152. if (!spawn) {
  4153. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4154. return 0;
  4155. }
  4156. if (!spawn->IsNPC()) {
  4157. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4158. return 0;
  4159. }
  4160. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4161. return 0;
  4162. }
  4163. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4164. if (!lua_interface)
  4165. return 0;
  4166. Spawn* spawn = lua_interface->GetSpawn(state);
  4167. int16 tick = lua_interface->GetInt16Value(state, 2);
  4168. if (!spawn) {
  4169. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4170. return 0;
  4171. }
  4172. if (!spawn->IsNPC()) {
  4173. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4174. return 0;
  4175. }
  4176. if (tick < 20) {
  4177. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4178. return 0;
  4179. }
  4180. ((NPC*)spawn)->Brain()->SetTick(tick);
  4181. return 0;
  4182. }
  4183. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4184. if (!lua_interface)
  4185. return 0;
  4186. Spawn* spawn = lua_interface->GetSpawn(state);
  4187. Spawn* target = lua_interface->GetSpawn(state, 2);
  4188. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4189. if (!spawn) {
  4190. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4191. return 0;
  4192. }
  4193. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4194. spawn->SetFollowTarget(target, follow_distance);
  4195. return 0;
  4196. }
  4197. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4198. if (!lua_interface)
  4199. return 0;
  4200. Spawn* spawn = lua_interface->GetSpawn(state);
  4201. if (!spawn) {
  4202. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4203. return 0;
  4204. }
  4205. Spawn* target = spawn->GetFollowTarget();
  4206. if (target) {
  4207. lua_interface->SetSpawnValue(state, target);
  4208. return 1;
  4209. }
  4210. return 0;
  4211. }
  4212. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4213. if (!lua_interface)
  4214. return 0;
  4215. Spawn* spawn = lua_interface->GetSpawn(state);
  4216. if (!spawn) {
  4217. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4218. return 0;
  4219. }
  4220. if (spawn->following)
  4221. spawn->following = false;
  4222. else
  4223. spawn->following = true;
  4224. return 0;
  4225. }
  4226. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4227. if (!lua_interface)
  4228. return 0;
  4229. Spawn* spawn = lua_interface->GetSpawn(state);
  4230. if (!spawn) {
  4231. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4232. return 0;
  4233. }
  4234. lua_interface->SetBooleanValue(state, spawn->following);
  4235. return 1;
  4236. }
  4237. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4238. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4239. // I will attempt to explain how this function works for future refrence
  4240. // Fist lets make sure lua_interface is valid, if not return out
  4241. if (!lua_interface)
  4242. return 0;
  4243. // Next we grab the first 2 params same as we usually would
  4244. Spawn* spawn = lua_interface->GetSpawn(state);
  4245. string var = lua_interface->GetStringValue(state, 2);
  4246. // 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
  4247. // 1 = Spawn
  4248. // 2 = Zone
  4249. // 3 = Item
  4250. // 4 = Quest
  4251. // 5 = String
  4252. // 6 = nil (null)
  4253. int8 dataType = 0;
  4254. // Define pointers for each potential type
  4255. Spawn* spawnVal = 0;
  4256. ZoneServer* zone = 0;
  4257. Item* item = 0;
  4258. Quest* quest = 0;
  4259. string val;
  4260. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4261. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4262. // options window are also light user data be we do not handle those.
  4263. // We check with lua_islightuserdata(lua_State*, index)
  4264. if (lua_islightuserdata(state, 3)) {
  4265. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4266. // and convert it to LUAUserData*
  4267. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4268. // Check to make sure the data we got is valid, if not give an error
  4269. if (!data || !data->IsCorrectlyInitialized()) {
  4270. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4271. }
  4272. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4273. else if (data->IsSpawn()) {
  4274. spawnVal = data->spawn;
  4275. dataType = 1;
  4276. }
  4277. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4278. else if (data->IsZone()) {
  4279. zone = data->zone;
  4280. dataType = 2;
  4281. }
  4282. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4283. else if (data->IsItem()) {
  4284. item = data->item;
  4285. dataType = 3;
  4286. }
  4287. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4288. else if (data->IsQuest()) {
  4289. quest = data->quest;
  4290. dataType = 4;
  4291. }
  4292. }
  4293. // Wasn't light user data, check if it is nil(null)
  4294. else if (lua_isnil(state, 3)) {
  4295. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4296. dataType = 6;
  4297. }
  4298. // Wasn't light user data or nil (null), must be a string
  4299. else {
  4300. // Set the string and dataType variable
  4301. val = lua_interface->GetStringValue(state, 3);
  4302. dataType = 5;
  4303. }
  4304. // We now have all the params, lets check to make sure they are valid
  4305. if (!spawn) {
  4306. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4307. return 0;
  4308. }
  4309. if (var.length() == 0) {
  4310. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4311. return 0;
  4312. }
  4313. if (dataType == 0) {
  4314. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4315. return 0;
  4316. }
  4317. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4318. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4319. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4320. switch (dataType) {
  4321. case 1:
  4322. // 1 = Spawn
  4323. spawn->AddTempVariable(var, spawnVal);
  4324. break;
  4325. case 2:
  4326. // 2 = Zone
  4327. spawn->AddTempVariable(var, zone);
  4328. break;
  4329. case 3:
  4330. // 3 = Item
  4331. spawn->AddTempVariable(var, item);
  4332. break;
  4333. case 4:
  4334. // 4 = Quest
  4335. spawn->AddTempVariable(var, quest);
  4336. break;
  4337. case 5:
  4338. // 5 = String
  4339. spawn->AddTempVariable(var, val);
  4340. break;
  4341. case 6:
  4342. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4343. spawn->DeleteTempVariable(var);
  4344. break;
  4345. }
  4346. // And we are done so return out
  4347. return 0;
  4348. }
  4349. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4350. if (!lua_interface)
  4351. return 0;
  4352. Spawn* spawn = lua_interface->GetSpawn(state);
  4353. string var = lua_interface->GetStringValue(state, 2);
  4354. if (!spawn) {
  4355. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4356. return 0;
  4357. }
  4358. if (var.length() == 0) {
  4359. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4360. return 0;
  4361. }
  4362. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4363. int8 type = spawn->GetTempVariableType(var);
  4364. Spawn* spawn2 = 0;
  4365. ZoneServer* zone = 0;
  4366. Item* item = 0;
  4367. Quest* quest = 0;
  4368. // Set the lua function return value based on the type of data the variable contains
  4369. switch (type) {
  4370. case 1:
  4371. spawn2 = spawn->GetTempVariableSpawn(var);
  4372. if (!spawn2)
  4373. return 0;
  4374. lua_interface->SetSpawnValue(state, spawn2);
  4375. break;
  4376. case 2:
  4377. zone = spawn->GetTempVariableZone(var);
  4378. if (!zone)
  4379. return 0;
  4380. lua_interface->SetZoneValue(state, zone);
  4381. break;
  4382. case 3:
  4383. item = spawn->GetTempVariableItem(var);
  4384. if (!item)
  4385. return 0;
  4386. lua_interface->SetItemValue(state, item);
  4387. break;
  4388. case 4:
  4389. quest = spawn->GetTempVariableQuest(var);
  4390. if (!quest)
  4391. return 0;
  4392. lua_interface->SetQuestValue(state, quest);
  4393. break;
  4394. case 5:
  4395. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4396. break;
  4397. default:
  4398. // Not a valid type then the variable was not set so return out
  4399. return 0;
  4400. }
  4401. // Return value was set so return out
  4402. return 1;
  4403. }
  4404. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4405. {
  4406. if (!lua_interface)
  4407. return 0;
  4408. Quest* quest = lua_interface->GetQuest(state);
  4409. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4410. string description = lua_interface->GetStringValue(state, 3);
  4411. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4412. if (!quest) {
  4413. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4414. lua_interface->SetBooleanValue(state, false);
  4415. return 1;
  4416. }
  4417. if (!spawn) {
  4418. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4419. lua_interface->SetBooleanValue(state, false);
  4420. return 1;
  4421. }
  4422. if (!spawn->IsPlayer()) {
  4423. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4424. lua_interface->SetBooleanValue(state, false);
  4425. return 1;
  4426. }
  4427. if (item_id == 0) {
  4428. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4429. lua_interface->SetBooleanValue(state, false);
  4430. return 1;
  4431. }
  4432. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4433. if (!client) {
  4434. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4435. lua_interface->SetBooleanValue(state, false);
  4436. return 1;
  4437. }
  4438. Item* item = master_item_list.GetItem(item_id);
  4439. if (!item) {
  4440. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4441. lua_interface->SetBooleanValue(state, false);
  4442. return 1;
  4443. }
  4444. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4445. if (packet) {
  4446. packet->setDataByName("title", "Quest Reward!");
  4447. packet->setDataByName("name", quest->GetName());
  4448. packet->setDataByName("description", description.c_str());
  4449. packet->setDataByName("level", quest->GetLevel());
  4450. packet->setArrayLengthByName("num_rewards", 1);
  4451. packet->setArrayDataByName("reward_id", item->details.item_id);
  4452. if (client->GetVersion() < 860)
  4453. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4454. else if (client->GetVersion() < 1193)
  4455. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4456. else
  4457. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4458. client->QueuePacket(packet->serialize());
  4459. safe_delete(packet);
  4460. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  4461. client->Message(CHANNEL_COLOR_YELLOW, "You receive \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  4462. return 1;
  4463. }
  4464. lua_interface->SetBooleanValue(state, false);
  4465. return 1;
  4466. }
  4467. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  4468. if (!lua_interface)
  4469. return 0;
  4470. Quest* quest = lua_interface->GetQuest(state);
  4471. if (!quest) {
  4472. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  4473. return 0;
  4474. }
  4475. quest->SetRepeatable(true);
  4476. return 0;
  4477. }
  4478. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  4479. if (!lua_interface)
  4480. return 0;
  4481. Spawn* spawn = lua_interface->GetSpawn(state);
  4482. if (!spawn) {
  4483. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  4484. return 0;
  4485. }
  4486. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  4487. string ret = classes.GetClassNameCase(base_class);
  4488. if (ret.length() > 0) {
  4489. lua_interface->SetStringValue(state, ret.c_str());
  4490. return 1;
  4491. }
  4492. return 0;
  4493. }
  4494. int EQ2Emu_lua_AddWard(lua_State* state) {
  4495. if (!lua_interface)
  4496. return 0;
  4497. int32 damage = lua_interface->GetInt32Value(state);
  4498. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  4499. int8 wardType = lua_interface->GetInt8Value(state, 3);
  4500. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  4501. int8 damageAbsorptionPercent = lua_interface->GetInt8Value(state, 5);
  4502. int8 damageAbsorptionMaxHealthPercent = lua_interface->GetInt8Value(state, 6);
  4503. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4504. bool ward_was_added = false;
  4505. ZoneServer* zone = spell->caster->GetZone();
  4506. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4507. for (int32 i = 0; i < spell->targets.size(); i++) {
  4508. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  4509. if (!target)
  4510. continue;
  4511. if (target->IsEntity()) {
  4512. // If the ward is already active remove it
  4513. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  4514. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4515. // Create new ward info
  4516. WardInfo* ward = new WardInfo;
  4517. ward->Spell = spell;
  4518. ward->BaseDamage = damage;
  4519. ward->DamageLeft = damage;
  4520. ward->keepWard = keepWard;
  4521. ward->WardType = wardType;
  4522. if (damageAbsorptionPercent > 100)
  4523. damageAbsorptionPercent = 100;
  4524. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  4525. if (damageAbsorptionMaxHealthPercent > 100)
  4526. damageAbsorptionMaxHealthPercent = 100;
  4527. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  4528. if (wardType == WARD_TYPE_MAGICAL)
  4529. ward->DamageType = damageTypes;
  4530. // Add the ward to the entity
  4531. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  4532. ward_was_added = true;
  4533. }
  4534. }
  4535. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4536. if (ward_was_added && spell->caster->IsPlayer()) {
  4537. spell->had_dmg_remaining = true;
  4538. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  4539. }
  4540. return 0;
  4541. }
  4542. int EQ2Emu_lua_AddToWard(lua_State* state) {
  4543. if (!lua_interface)
  4544. return 0;
  4545. int32 amount = lua_interface->GetInt32Value(state);
  4546. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4547. WardInfo* ward = 0;
  4548. ZoneServer* zone = spell->caster->GetZone();
  4549. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4550. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4551. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  4552. ward = target->GetWard(spell->spell->GetSpellID());
  4553. if (ward) {
  4554. ward->DamageLeft += amount;
  4555. if (ward->DamageLeft > ward->BaseDamage)
  4556. ward->DamageLeft = ward->BaseDamage;
  4557. for (int32 i = 0; i < spell->targets.size(); i++) {
  4558. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  4559. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  4560. }
  4561. }
  4562. }
  4563. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4564. if (ward && spell->caster->IsPlayer())
  4565. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  4566. return 0;
  4567. }
  4568. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  4569. if (!lua_interface)
  4570. return 0;
  4571. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4572. if (!spell) {
  4573. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  4574. return 0;
  4575. }
  4576. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4577. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  4578. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  4579. if (ward) {
  4580. lua_interface->SetInt32Value(state, ward->DamageLeft);
  4581. return 1;
  4582. }
  4583. }
  4584. return 0;
  4585. }
  4586. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  4587. if (!lua_interface)
  4588. return 0;
  4589. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4590. if (!spell) {
  4591. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  4592. return 0;
  4593. }
  4594. string type = lua_interface->GetStringValue(state, 2);
  4595. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4596. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  4597. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  4598. if (ward) {
  4599. if (boost::iequals(type, "damageleft"))
  4600. lua_interface->SetInt32Value(state, ward->DamageLeft);
  4601. else if (boost::iequals(type, "basedamage"))
  4602. lua_interface->SetInt32Value(state, ward->BaseDamage);
  4603. else if (boost::iequals(type, "keepward"))
  4604. lua_interface->SetBooleanValue(state, ward->keepWard);
  4605. else if (boost::iequals(type, "wardtype"))
  4606. lua_interface->SetInt32Value(state, ward->WardType);
  4607. else if (boost::iequals(type, "dmgabsorptionpct"))
  4608. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  4609. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  4610. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  4611. else
  4612. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  4613. return 1;
  4614. }
  4615. }
  4616. return 0;
  4617. }
  4618. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  4619. if (!lua_interface)
  4620. return 0;
  4621. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4622. ZoneServer* zone = spell->caster->GetZone();
  4623. Spawn* target = 0;
  4624. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4625. for (int32 i = 0; i < spell->targets.size(); i++) {
  4626. target = zone->GetSpawnByID(spell->targets.at(i));
  4627. if (target && target->IsEntity()) {
  4628. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4629. }
  4630. }
  4631. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4632. return 0;
  4633. }
  4634. int EQ2Emu_lua_Interrupt(lua_State* state)
  4635. {
  4636. if (!lua_interface)
  4637. return 0;
  4638. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  4639. Spawn* target = lua_interface->GetSpawn(state, 2);
  4640. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4641. if (!caster)
  4642. {
  4643. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  4644. return 0;
  4645. }
  4646. if (!target)
  4647. {
  4648. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  4649. return 0;
  4650. }
  4651. if (!spell) {
  4652. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  4653. return 0;
  4654. }
  4655. if (!target->IsEntity() && !spell)
  4656. {
  4657. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  4658. return 0;
  4659. }
  4660. if (!target && spell) {
  4661. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4662. for (int8 i = 0; i < spell->targets.size(); i++) {
  4663. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  4664. if (!target || !target->IsEntity())
  4665. continue;
  4666. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  4667. }
  4668. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4669. }
  4670. else
  4671. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  4672. return 0;
  4673. }
  4674. int EQ2Emu_lua_Stealth(lua_State* state) {
  4675. if (!lua_interface)
  4676. return 0;
  4677. int8 type = lua_interface->GetInt8Value(state);
  4678. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4679. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4680. if (!spell) {
  4681. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  4682. return 0;
  4683. }
  4684. ZoneServer* zone = spell->caster->GetZone();
  4685. if (spawn) {
  4686. if (spawn->IsEntity()) {
  4687. if (type == 1) {
  4688. ((Entity*)spawn)->AddStealthSpell(spell);
  4689. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  4690. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  4691. }
  4692. else if (type == 2) {
  4693. ((Entity*)spawn)->AddInvisSpell(spell);
  4694. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  4695. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  4696. }
  4697. return 0;
  4698. }
  4699. else {
  4700. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  4701. return 0;
  4702. }
  4703. }
  4704. else {
  4705. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4706. for (int32 i = 0; i < spell->targets.size(); i++) {
  4707. spawn = zone->GetSpawnByID(spell->targets.at(i));
  4708. if (!spawn || !spawn->IsEntity())
  4709. continue;
  4710. if (type == 1) {
  4711. ((Entity*)spawn)->AddStealthSpell(spell);
  4712. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  4713. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  4714. }
  4715. else if (type == 2) {
  4716. ((Entity*)spawn)->AddInvisSpell(spell);
  4717. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  4718. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  4719. }
  4720. else {
  4721. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  4722. break;
  4723. }
  4724. }
  4725. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4726. }
  4727. return 0;
  4728. }
  4729. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  4730. if (!lua_interface)
  4731. return 0;
  4732. Spawn* spawn = lua_interface->GetSpawn(state);
  4733. if (!spawn) {
  4734. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  4735. return 0;
  4736. }
  4737. if (spawn->IsEntity()) {
  4738. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  4739. return 1;
  4740. }
  4741. else
  4742. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  4743. return 0;
  4744. }
  4745. int EQ2Emu_lua_IsInvis(lua_State* state) {
  4746. if (!lua_interface)
  4747. return 0;
  4748. Spawn* spawn = lua_interface->GetSpawn(state);
  4749. if (!spawn) {
  4750. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  4751. return 0;
  4752. }
  4753. if (spawn->IsEntity()) {
  4754. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  4755. return 1;
  4756. }
  4757. else
  4758. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  4759. return 0;
  4760. }
  4761. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  4762. if (!lua_interface)
  4763. return 0;
  4764. Spawn* player = lua_interface->GetSpawn(state);
  4765. int32 item_id = lua_interface->GetInt32Value(state, 2);
  4766. if (!player->IsPlayer()) {
  4767. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  4768. return 0;
  4769. }
  4770. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  4771. return 1;
  4772. }
  4773. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  4774. if (!lua_interface)
  4775. return 0;
  4776. Spawn* player = lua_interface->GetSpawn(state);
  4777. int8 slot = lua_interface->GetInt8Value(state, 2);
  4778. if (!player) {
  4779. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  4780. return 0;
  4781. }
  4782. if (!player->IsPlayer()) {
  4783. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  4784. return 0;
  4785. }
  4786. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  4787. if (!item) {
  4788. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  4789. return 0;
  4790. }
  4791. lua_interface->SetItemValue(state, item);
  4792. return 1;
  4793. }
  4794. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  4795. if (!lua_interface)
  4796. return 0;
  4797. Spawn* player = lua_interface->GetSpawn(state);
  4798. int32 id = lua_interface->GetInt32Value(state, 2);
  4799. if (!player) {
  4800. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  4801. return 0;
  4802. }
  4803. if (!player->IsPlayer()) {
  4804. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  4805. return 0;
  4806. }
  4807. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  4808. if (!item) {
  4809. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  4810. return 0;
  4811. }
  4812. lua_interface->SetItemValue(state, item);
  4813. return 1;
  4814. }
  4815. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  4816. if (!lua_interface)
  4817. return 0;
  4818. Spawn* player = lua_interface->GetSpawn(state);
  4819. int32 id = lua_interface->GetInt32Value(state, 2);
  4820. int8 count = lua_interface->GetInt8Value(state, 3);
  4821. bool include_bank = lua_interface->GetInt8Value(state, 4);
  4822. if (!player) {
  4823. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  4824. return 0;
  4825. }
  4826. if (!player->IsPlayer()) {
  4827. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  4828. return 0;
  4829. }
  4830. if (!count)
  4831. count = 1;
  4832. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  4833. if (!item) {
  4834. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  4835. return 0;
  4836. }
  4837. lua_interface->SetItemValue(state, item);
  4838. return 1;
  4839. }
  4840. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  4841. if (!lua_interface)
  4842. return 0;
  4843. Spawn* spawn = lua_interface->GetSpawn(state);
  4844. int32 anim = lua_interface->GetInt32Value(state, 2);
  4845. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  4846. int8 type = lua_interface->GetInt8Value(state, 4);
  4847. if (!spawn) {
  4848. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  4849. return 0;
  4850. }
  4851. if (spawn2) {
  4852. if (spawn2->IsPlayer()) {
  4853. if (type != 1 && type != 2)
  4854. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  4855. else
  4856. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  4857. return 0;
  4858. }
  4859. else {
  4860. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  4861. return 0;
  4862. }
  4863. }
  4864. else
  4865. spawn->GetZone()->PlayAnimation(spawn, anim);
  4866. return 0;
  4867. }
  4868. int EQ2Emu_lua_IsPet(lua_State* state) {
  4869. if (!lua_interface)
  4870. return 0;
  4871. Spawn* spawn = lua_interface->GetSpawn(state);
  4872. if (!spawn) {
  4873. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4874. return 0;
  4875. }
  4876. lua_interface->SetBooleanValue(state, spawn->IsPet());
  4877. return 1;
  4878. }
  4879. int EQ2Emu_lua_GetOwner(lua_State* state) {
  4880. if (!lua_interface)
  4881. return 0;
  4882. Spawn* spawn = lua_interface->GetSpawn(state);
  4883. if (!spawn) {
  4884. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  4885. return 0;
  4886. }
  4887. if (!spawn->IsNPC()) {
  4888. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  4889. return 0;
  4890. }
  4891. if (((NPC*)spawn)->GetOwner()) {
  4892. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  4893. return 1;
  4894. }
  4895. return 0;
  4896. }
  4897. int EQ2Emu_lua_SetTarget(lua_State* state) {
  4898. if (!lua_interface)
  4899. return 0;
  4900. Spawn* spawn = lua_interface->GetSpawn(state);
  4901. Spawn* target = lua_interface->GetSpawn(state, 2);
  4902. if (!spawn) {
  4903. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4904. return 0;
  4905. }
  4906. if (!spawn) {
  4907. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  4908. return 0;
  4909. }
  4910. spawn->SetTarget(target);
  4911. return 0;
  4912. }
  4913. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  4914. if (!lua_interface)
  4915. return 0;
  4916. Spawn* spawn = lua_interface->GetSpawn(state);
  4917. bool val = lua_interface->GetBooleanValue(state, 2);
  4918. if (!spawn) {
  4919. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  4920. return 0;
  4921. }
  4922. if (!spawn->IsEntity()) {
  4923. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  4924. return 0;
  4925. }
  4926. ((Entity*)spawn)->InCombat(val);
  4927. if (val) {
  4928. spawn->ClearRunningLocations();
  4929. spawn->CalculateRunningLocation(true);
  4930. }
  4931. return 0;
  4932. }
  4933. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  4934. if (!lua_interface)
  4935. return 0;
  4936. Spawn* spawn1 = lua_interface->GetSpawn(state);
  4937. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4938. if (!spawn1) {
  4939. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4940. return 0;
  4941. }
  4942. if (!spawn2) {
  4943. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4944. return 0;
  4945. }
  4946. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  4947. return 1;
  4948. }
  4949. int EQ2Emu_lua_Runback(lua_State* state) {
  4950. if (!lua_interface)
  4951. return 0;
  4952. Spawn* spawn = lua_interface->GetSpawn(state);
  4953. if (!spawn) {
  4954. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  4955. return 0;
  4956. }
  4957. if (!spawn->IsNPC()) {
  4958. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  4959. return 0;
  4960. }
  4961. ((NPC*)spawn)->Runback();
  4962. return 0;
  4963. }
  4964. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  4965. if (!lua_interface)
  4966. return 0;
  4967. Spawn* spawn = lua_interface->GetSpawn(state);
  4968. if (!spawn) {
  4969. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  4970. return 0;
  4971. }
  4972. if (!spawn->IsNPC()) {
  4973. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  4974. return 0;
  4975. }
  4976. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  4977. return 1;
  4978. }
  4979. int EQ2Emu_lua_IsCasting(lua_State* state) {
  4980. if (!lua_interface)
  4981. return 0;
  4982. Spawn* spawn = lua_interface->GetSpawn(state);
  4983. if (!spawn) {
  4984. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  4985. return 0;
  4986. }
  4987. if (!spawn->IsEntity()) {
  4988. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  4989. return 0;
  4990. }
  4991. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  4992. return 1;
  4993. }
  4994. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  4995. if (!lua_interface)
  4996. return 0;
  4997. Spawn* spawn = lua_interface->GetSpawn(state);
  4998. if (!spawn) {
  4999. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5000. return 0;
  5001. }
  5002. if (!spawn->IsEntity()) {
  5003. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5004. return 0;
  5005. }
  5006. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5007. return 1;
  5008. }
  5009. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5010. if (!lua_interface)
  5011. return 0;
  5012. Spawn* spawn = lua_interface->GetSpawn(state);
  5013. if (!spawn) {
  5014. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5015. return 0;
  5016. }
  5017. if (!spawn->IsEntity()) {
  5018. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5019. return 0;
  5020. }
  5021. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5022. return 1;
  5023. }
  5024. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5025. if (!lua_interface)
  5026. return 0;
  5027. Spawn* spawn = lua_interface->GetSpawn(state);
  5028. if (!spawn) {
  5029. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5030. return 0;
  5031. }
  5032. if (!spawn->IsEntity()) {
  5033. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5034. return 0;
  5035. }
  5036. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5037. return 1;
  5038. }
  5039. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5040. if (!lua_interface)
  5041. return 0;
  5042. Spawn* spawn = lua_interface->GetSpawn(state);
  5043. Spawn* target = lua_interface->GetSpawn(state, 2);
  5044. float distance = lua_interface->GetFloatValue(state, 3);
  5045. if (!spawn) {
  5046. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5047. return 0;
  5048. }
  5049. if (!target) {
  5050. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5051. return 0;
  5052. }
  5053. if (!spawn->IsNPC()) {
  5054. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5055. return 0;
  5056. }
  5057. if (!target->IsEntity()) {
  5058. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5059. return 0;
  5060. }
  5061. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5062. return 1;
  5063. }
  5064. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5065. if (!lua_interface)
  5066. return 0;
  5067. Spawn* spawn = lua_interface->GetSpawn(state);
  5068. Spawn* target = lua_interface->GetSpawn(state, 2);
  5069. float distance = lua_interface->GetFloatValue(state, 3);
  5070. if (!spawn) {
  5071. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5072. return 0;
  5073. }
  5074. if (!target) {
  5075. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5076. return 0;
  5077. }
  5078. if (!spawn->IsNPC()) {
  5079. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5080. return 0;
  5081. }
  5082. if (!target->IsEntity()) {
  5083. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5084. return 0;
  5085. }
  5086. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5087. return 0;
  5088. }
  5089. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5090. if (!lua_interface)
  5091. return 0;
  5092. Spawn* spawn = lua_interface->GetSpawn(state);
  5093. if (!spawn) {
  5094. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5095. return 0;
  5096. }
  5097. if (!spawn->IsNPC()) {
  5098. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5099. return 0;
  5100. }
  5101. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5102. return 1;
  5103. }
  5104. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5105. if (!lua_interface)
  5106. return 0;
  5107. Spawn* spawn = lua_interface->GetSpawn(state);
  5108. if (!spawn) {
  5109. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5110. return 0;
  5111. }
  5112. if (!spawn->IsNPC()) {
  5113. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5114. return 0;
  5115. }
  5116. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5117. return 1;
  5118. }
  5119. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5120. if (!lua_interface)
  5121. return 0;
  5122. Spawn* spawn = lua_interface->GetSpawn(state);
  5123. if (!spawn) {
  5124. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5125. return 0;
  5126. }
  5127. if (!spawn->IsNPC()) {
  5128. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5129. return 0;
  5130. }
  5131. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5132. if (hated) {
  5133. lua_interface->SetSpawnValue(state, hated);
  5134. return 1;
  5135. }
  5136. return 0;
  5137. }
  5138. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5139. if (!lua_interface)
  5140. return 0;
  5141. Spawn* spawn = lua_interface->GetSpawn(state);
  5142. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5143. if (!spawn) {
  5144. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5145. return 0;
  5146. }
  5147. if (!spawn->IsNPC()) {
  5148. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5149. return 0;
  5150. }
  5151. if (!hated) {
  5152. ((NPC*)spawn)->Brain()->ClearHate();
  5153. return 0;
  5154. }
  5155. else
  5156. {
  5157. if (!hated->IsEntity()) {
  5158. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5159. return 0;
  5160. }
  5161. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5162. return 0;
  5163. }
  5164. return 0;
  5165. }
  5166. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5167. if (!lua_interface)
  5168. return 0;
  5169. Spawn* spawn = lua_interface->GetSpawn(state);
  5170. if (!spawn) {
  5171. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5172. return 0;
  5173. }
  5174. if (!spawn->IsNPC()) {
  5175. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5176. return 0;
  5177. }
  5178. ((NPC*)spawn)->Brain()->ClearEncounter();
  5179. return 0;
  5180. }
  5181. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5182. if (!lua_interface)
  5183. return 0;
  5184. Spawn* spawn = lua_interface->GetSpawn(state);
  5185. if (!spawn) {
  5186. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5187. return 0;
  5188. }
  5189. if (!spawn->IsNPC()) {
  5190. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5191. return 0;
  5192. }
  5193. // Temp list to store hate list
  5194. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5195. if (encounterList->size() == 0) {
  5196. safe_delete(encounterList);
  5197. return 0;
  5198. }
  5199. lua_createtable(state, encounterList->size(), 0);
  5200. int newTable = lua_gettop(state);
  5201. for (int32 i = 0; i < encounterList->size(); i++) {
  5202. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5203. if (temp)
  5204. lua_interface->SetSpawnValue(state, temp);
  5205. lua_rawseti(state, newTable, i + 1);
  5206. }
  5207. safe_delete(encounterList);
  5208. return 1;
  5209. }
  5210. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5211. if (!lua_interface)
  5212. return 0;
  5213. Spawn* spawn = lua_interface->GetSpawn(state);
  5214. if (!spawn) {
  5215. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5216. return 0;
  5217. }
  5218. if (!spawn->IsNPC()) {
  5219. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5220. return 0;
  5221. }
  5222. // Temp list to store hate list
  5223. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5224. if (hateList->size() == 0) {
  5225. safe_delete(hateList);
  5226. return 0;
  5227. }
  5228. lua_createtable(state, hateList->size(), 0);
  5229. int newTable = lua_gettop(state);
  5230. for (int32 i = 0; i < hateList->size(); i++) {
  5231. lua_interface->SetSpawnValue(state, hateList->at(i));
  5232. lua_rawseti(state, newTable, i + 1);
  5233. }
  5234. safe_delete(hateList);
  5235. return 1;
  5236. }
  5237. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5238. if (!lua_interface)
  5239. return 0;
  5240. Spawn* spawn = lua_interface->GetSpawn(state);
  5241. if (!spawn) {
  5242. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5243. return 0;
  5244. }
  5245. if (spawn->IsPlayer()) {
  5246. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5247. lua_interface->SetBooleanValue(state, true);
  5248. else
  5249. lua_interface->SetBooleanValue(state, false);
  5250. return 1;
  5251. }
  5252. else {
  5253. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5254. return 1;
  5255. }
  5256. }
  5257. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5258. if (!lua_interface)
  5259. return 0;
  5260. Quest* quest = lua_interface->GetQuest(state);
  5261. if (!quest) {
  5262. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5263. return 0;
  5264. }
  5265. quest->SetCompletedFlag(true);
  5266. return 0;
  5267. }
  5268. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5269. if (!lua_interface)
  5270. return 0;
  5271. Spawn* spawn = lua_interface->GetSpawn(state);
  5272. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5273. int8 tier = lua_interface->GetInt8Value(state, 3);
  5274. if (!spawn) {
  5275. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5276. return 0;
  5277. }
  5278. if (!spawn->IsEntity()) {
  5279. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5280. return 0;
  5281. }
  5282. if (spellID == 0) {
  5283. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5284. return 0;
  5285. }
  5286. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5287. if (effect) {
  5288. if (tier > 0) {
  5289. // If a tier was passed chec to see if it is the same as the effect
  5290. if (tier == effect->tier)
  5291. lua_interface->SetBooleanValue(state, true);
  5292. else
  5293. lua_interface->SetBooleanValue(state, false);
  5294. return 1;
  5295. }
  5296. else {
  5297. // Have an effect but no tier was passed so return true
  5298. lua_interface->SetBooleanValue(state, true);
  5299. }
  5300. return 1;
  5301. }
  5302. // no effect so return false
  5303. lua_interface->SetBooleanValue(state, false);
  5304. return 1;
  5305. }
  5306. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5307. if (!lua_interface)
  5308. return 0;
  5309. Spawn* spawn = lua_interface->GetSpawn(state);
  5310. int32 id = lua_interface->GetInt32Value(state, 2);
  5311. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5312. Spawn* spawn2 = 0;
  5313. vector<Spawn*> list;
  5314. if (!spawn) {
  5315. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5316. return 0;
  5317. }
  5318. //If zone not provided, use spawn's zone
  5319. if (!zone)
  5320. zone = spawn->GetZone();
  5321. list = zone->GetSpawnsByID(id);
  5322. if (list.size() == 0) {
  5323. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5324. return 0;
  5325. }
  5326. vector<Spawn*>::iterator itr = list.begin();
  5327. for (int8 i = 0; i < list.size(); i++) {
  5328. spawn2 = itr[i];
  5329. if (spawn2)
  5330. spawn2->AddAllowAccessSpawn(spawn);
  5331. }
  5332. return 0;
  5333. }
  5334. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5335. if (!lua_interface)
  5336. return 0;
  5337. Spawn* spawn = lua_interface->GetSpawn(state);
  5338. int32 id = lua_interface->GetInt32Value(state, 2);
  5339. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5340. Spawn* spawn2 = 0;
  5341. if (!spawn) {
  5342. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5343. return 0;
  5344. }
  5345. //If zone not provided, use spawn's zone
  5346. if (!zone)
  5347. zone = spawn->GetZone();
  5348. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5349. vector<Spawn*>::iterator itr = list.begin();
  5350. if (list.size() == 0) {
  5351. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5352. return 0;
  5353. }
  5354. for (int8 i = 0; i < list.size(); i++) {
  5355. spawn2 = itr[i];
  5356. if (spawn2)
  5357. spawn2->RemoveSpawnAccess(spawn);
  5358. }
  5359. return 0;
  5360. }
  5361. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5362. if (!lua_interface)
  5363. return 0;
  5364. Quest* quest = lua_interface->GetQuest(state);
  5365. if (!quest) {
  5366. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5367. return 0;
  5368. }
  5369. quest->SetYellowName(true);
  5370. return 0;
  5371. }
  5372. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5373. if (!lua_interface)
  5374. return 0;
  5375. Spawn* spawn = lua_interface->GetSpawn(state);
  5376. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5377. if (!spawn) {
  5378. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5379. return 0;
  5380. }
  5381. if (!spawn->IsPlayer()) {
  5382. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5383. return 0;
  5384. }
  5385. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5386. return 1;
  5387. }
  5388. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5389. if (!lua_interface)
  5390. return 0;
  5391. Spawn* spawn = lua_interface->GetSpawn(state);
  5392. if (!spawn) {
  5393. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5394. return 0;
  5395. }
  5396. if (!spawn->IsPlayer()) {
  5397. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5398. return 0;
  5399. }
  5400. ZoneServer* zone = spawn->GetZone();
  5401. if (!zone) {
  5402. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5403. return 0;
  5404. }
  5405. Instance_Type iType = zone->GetInstanceType();
  5406. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5407. iType == GROUP_LOCKOUT_INSTANCE ||
  5408. iType == RAID_LOCKOUT_INSTANCE ||
  5409. iType == SOLO_PERSIST_INSTANCE ||
  5410. iType == GROUP_PERSIST_INSTANCE ||
  5411. iType == RAID_PERSIST_INSTANCE) {
  5412. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5413. if (data) {
  5414. // Check to see if the timer has already been set, if it has return out.
  5415. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  5416. return 0;
  5417. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  5418. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  5419. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5420. if (client) {
  5421. string time_msg = "";
  5422. int32 time = data->success_lockout_time;
  5423. int16 hour;
  5424. int8 min;
  5425. int8 sec;
  5426. hour = time / 3600;
  5427. time = time % 3600;
  5428. min = time / 60;
  5429. time = time % 60;
  5430. sec = time;
  5431. if (hour > 0) {
  5432. char temp[10];
  5433. sprintf(temp, " %i", hour);
  5434. time_msg.append(temp);
  5435. time_msg.append(" hour");
  5436. time_msg.append((hour > 1) ? "s" : "");
  5437. }
  5438. if (min > 0) {
  5439. char temp[5];
  5440. sprintf(temp, " %i", min);
  5441. time_msg.append(temp);
  5442. time_msg.append(" minute");
  5443. time_msg.append((min > 1) ? "s" : "");
  5444. }
  5445. // Only add seconds if minutes and hours are 0
  5446. if (hour == 0 && min == 0 && sec > 0) {
  5447. char temp[5];
  5448. sprintf(temp, " %i", sec);
  5449. time_msg.append(temp);
  5450. time_msg.append(" second");
  5451. time_msg.append((sec > 1) ? "s" : "");
  5452. }
  5453. 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());
  5454. }
  5455. }
  5456. else
  5457. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5458. }
  5459. else
  5460. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5461. return 0;
  5462. }
  5463. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  5464. if (!lua_interface)
  5465. return 0;
  5466. Spawn* spawn = lua_interface->GetSpawn(state);
  5467. if (!spawn) {
  5468. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5469. return 0;
  5470. }
  5471. if (!spawn->IsPlayer()) {
  5472. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5473. return 0;
  5474. }
  5475. ZoneServer* zone = spawn->GetZone();
  5476. if (!zone) {
  5477. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5478. return 0;
  5479. }
  5480. Instance_Type iType = zone->GetInstanceType();
  5481. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5482. iType == GROUP_LOCKOUT_INSTANCE ||
  5483. iType == RAID_LOCKOUT_INSTANCE ||
  5484. iType == SOLO_PERSIST_INSTANCE ||
  5485. iType == GROUP_PERSIST_INSTANCE ||
  5486. iType == RAID_PERSIST_INSTANCE) {
  5487. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5488. if (data) {
  5489. // Check to see if the timer has already been set, if it has return out.
  5490. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  5491. return 0;
  5492. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  5493. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  5494. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5495. if (client) {
  5496. string time_msg = "";
  5497. int32 time = data->failure_lockout_time;
  5498. int16 hour;
  5499. int8 min;
  5500. int8 sec;
  5501. hour = time / 3600;
  5502. time = time % 3600;
  5503. min = time / 60;
  5504. time = time % 60;
  5505. sec = time;
  5506. if (hour > 0) {
  5507. char temp[10];
  5508. sprintf(temp, " %i", hour);
  5509. time_msg.append(temp);
  5510. time_msg.append(" hour");
  5511. time_msg.append((hour > 1) ? "s" : "");
  5512. }
  5513. if (min > 0) {
  5514. char temp[5];
  5515. sprintf(temp, " %i", min);
  5516. time_msg.append(temp);
  5517. time_msg.append(" minute");
  5518. time_msg.append((min > 1) ? "s" : "");
  5519. }
  5520. // Only add seconds if minutes and hours are 0
  5521. if (hour == 0 && min == 0 && sec > 0) {
  5522. char temp[5];
  5523. sprintf(temp, " %i", sec);
  5524. time_msg.append(temp);
  5525. time_msg.append(" second");
  5526. time_msg.append((sec > 1) ? "s" : "");
  5527. }
  5528. 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());
  5529. }
  5530. }
  5531. else
  5532. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5533. }
  5534. else
  5535. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5536. return 0;
  5537. }
  5538. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  5539. if (!lua_interface)
  5540. return 0;
  5541. Spawn* spawn = lua_interface->GetSpawn(state);
  5542. if (!spawn) {
  5543. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  5544. return 0;
  5545. }
  5546. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  5547. return 1;
  5548. }
  5549. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  5550. if (!lua_interface)
  5551. return 0;
  5552. Spawn* player = lua_interface->GetSpawn(state);
  5553. Spawn* ground = lua_interface->GetSpawn(state, 2);
  5554. if (!player) {
  5555. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  5556. return 0;
  5557. }
  5558. if (!player->IsPlayer()) {
  5559. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  5560. return 0;
  5561. }
  5562. if (!ground) {
  5563. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  5564. return 0;
  5565. }
  5566. if (!ground->IsGroundSpawn()) {
  5567. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  5568. return 0;
  5569. }
  5570. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  5571. if (!groundspawn_entries) {
  5572. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  5573. return 0;
  5574. }
  5575. Skill* skill = 0;
  5576. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  5577. if (collection_skill == "Collecting")
  5578. skill = ((Player*)player)->GetSkillByName("Gathering");
  5579. else
  5580. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  5581. if (!skill) {
  5582. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  5583. return 0;
  5584. }
  5585. vector<GroundSpawnEntry*>::iterator itr;
  5586. GroundSpawnEntry* entry = 0;
  5587. bool can_harvest = false;
  5588. sint32 min_skill = -1;
  5589. // first, iterate through groundspawn_entries, discard tables player cannot use
  5590. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  5591. {
  5592. entry = *itr;
  5593. if (min_skill == -1 || entry->min_skill_level < min_skill)
  5594. min_skill = entry->min_skill_level;
  5595. // if player lacks skill, skip table
  5596. if (entry->min_skill_level > skill->current_val)
  5597. continue;
  5598. // if bonus, but player lacks level, skip table
  5599. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  5600. continue;
  5601. can_harvest = true;
  5602. break;
  5603. }
  5604. lua_interface->SetBooleanValue(state, can_harvest);
  5605. // If false, send the message to the client
  5606. if (!can_harvest) {
  5607. Client* client = player->GetZone()->GetClientBySpawn(player);
  5608. if (client) {
  5609. string msg = "You do not have enough skill to ";
  5610. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  5611. msg.append("gather");
  5612. else if (collection_skill == "Mining")
  5613. msg.append("mine");
  5614. else if (collection_skill == "Trapping")
  5615. msg.append("trap");
  5616. else if (collection_skill == "Foresting")
  5617. msg.append("forest");
  5618. else if (collection_skill == "Fishing")
  5619. msg.append("catch");
  5620. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  5621. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  5622. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  5623. }
  5624. }
  5625. return 1;
  5626. }
  5627. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  5628. if (!lua_interface)
  5629. return 0;
  5630. Spawn* player = lua_interface->GetSpawn(state);
  5631. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  5632. if (!player) {
  5633. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  5634. return 0;
  5635. }
  5636. if (!player->IsPlayer()) {
  5637. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  5638. return 0;
  5639. }
  5640. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  5641. lua_interface->SetBooleanValue(state, ret);
  5642. return 1;
  5643. }
  5644. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  5645. // Check to see if we have a valid lua_interface
  5646. if (!lua_interface)
  5647. return 0;
  5648. // Get the spawn that is getting the pet
  5649. Spawn* spawn = lua_interface->GetSpawn(state);
  5650. Spawn* target = lua_interface->GetSpawn(state, 2);
  5651. // Get the DB ID of the pet
  5652. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  5653. float x = lua_interface->GetFloatValue(state, 4);
  5654. float y = lua_interface->GetFloatValue(state, 5);
  5655. float z = lua_interface->GetFloatValue(state, 6);
  5656. // Get the spell that this command was called from
  5657. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5658. // Check to make sure the spawn pointer is valid
  5659. if (!spawn) {
  5660. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5661. return 0;
  5662. }
  5663. // Check to make sure the spawn is an entity
  5664. if (!spawn->IsEntity()) {
  5665. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5666. return 0;
  5667. }
  5668. if (!target) {
  5669. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  5670. return 0;
  5671. }
  5672. if (!target->IsEntity()) {
  5673. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  5674. return 0;
  5675. }
  5676. // Check to see if the DB ID for the pet is set
  5677. if (pet_id == 0) {
  5678. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5679. return 0;
  5680. }
  5681. // Check to see if the pointer to the spell is valid
  5682. if (!luaspell) {
  5683. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5684. return 0;
  5685. }
  5686. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5687. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5688. if (!pet) {
  5689. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  5690. return 0;
  5691. }
  5692. // Check to make sure the pet is an npc
  5693. if (!pet->IsNPC()) {
  5694. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  5695. return 0;
  5696. }
  5697. if (x == 0)
  5698. x = spawn->GetX();
  5699. if (y == 0)
  5700. y = spawn->GetY();
  5701. if (z == 0)
  5702. z = spawn->GetZ();
  5703. // Spawn the pet at the same location as the owner
  5704. pet->SetX(x);
  5705. pet->SetY(y);
  5706. pet->SetZ(z);
  5707. pet->SetLocation(spawn->GetLocation());
  5708. pet->SetHeading(spawn->GetHeading());
  5709. spawn->GetZone()->AddSpawn(pet);
  5710. /*
  5711. const char* spawn_script = world.GetSpawnScript(pet_id);
  5712. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5713. spawn->SetSpawnScript(string(spawn_script));
  5714. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5715. }*/
  5716. // Get a random pet name
  5717. string random_pet_name;
  5718. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5719. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5720. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5721. // Set the pets name
  5722. pet->SetName(random_pet_name.c_str());
  5723. // Set the level of the pet to the owners level
  5724. pet->SetLevel(spawn->GetLevel());
  5725. // Set the faction of the pet to the same faction as the owner
  5726. pet->SetFactionID(spawn->GetFactionID());
  5727. // Set the spawn as a pet
  5728. pet->SetPet(true);
  5729. // Give a pointer of the owner to the pet
  5730. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5731. // Set the pet type
  5732. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  5733. // Set the spell id used to create this pet
  5734. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5735. // Set the spell tier used to create this pet
  5736. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5737. // Set the pets spawn type to 6
  5738. pet->SetSpawnType(6);
  5739. // Set the pets brain
  5740. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  5741. // Check to see if the pet has a subtitle
  5742. if (strlen(pet->GetSubTitle()) > 0) {
  5743. // Add the players name to the front of the sub title
  5744. string pet_subtitle;
  5745. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5746. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5747. // Set the pets subtitle to the new one
  5748. pet->SetSubTitle(pet_subtitle.c_str());
  5749. }
  5750. // Set the pet as the return value for this function
  5751. lua_interface->SetSpawnValue(state, pet);
  5752. return 1;
  5753. }
  5754. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  5755. if (!lua_interface)
  5756. return 0;
  5757. Spawn* spawn = lua_interface->GetSpawn(state);
  5758. Spawn* player = lua_interface->GetSpawn(state, 2);
  5759. float max_distance = lua_interface->GetFloatValue(state, 3);
  5760. string type = lua_interface->GetStringValue(state, 4);
  5761. if (!spawn || (spawn && spawn->IsPlayer())) {
  5762. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  5763. return 0;
  5764. }
  5765. if (!player || (player && !player->IsPlayer())) {
  5766. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  5767. return 0;
  5768. }
  5769. Client* client = 0;
  5770. if (player->GetZone())
  5771. client = player->GetZone()->GetClientBySpawn(player);
  5772. if (!client) {
  5773. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  5774. return 0;
  5775. }
  5776. //Set max_distance to default if not set or not proper value
  5777. if (max_distance <= 0)
  5778. max_distance = 500;
  5779. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  5780. if (packet) {
  5781. float unknown2_3 = 0;
  5782. int8 placement_mode = 0;
  5783. if (type == "wall") {
  5784. placement_mode = 2;
  5785. unknown2_3 = 150;
  5786. }
  5787. else if (type == "ceiling")
  5788. placement_mode = 1;
  5789. packet->setDataByName("placement_mode", placement_mode);
  5790. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  5791. packet->setDataByName("model_type", spawn->GetModelType());
  5792. packet->setDataByName("unknown", 1); //size
  5793. packet->setDataByName("unknown2", 1); //size 2
  5794. packet->setDataByName("unknown2", .5, 1); //size 3
  5795. packet->setDataByName("unknown2", 3, 2);
  5796. packet->setDataByName("unknown2", unknown2_3, 3);
  5797. packet->setDataByName("max_distance", max_distance);
  5798. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  5799. client->QueuePacket(packet->serialize());
  5800. safe_delete(packet);
  5801. }
  5802. return 0;
  5803. }
  5804. int EQ2Emu_lua_GetItemType(lua_State* state) {
  5805. if (!lua_interface)
  5806. return 0;
  5807. Item* item = lua_interface->GetItem(state);
  5808. if (!item) {
  5809. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  5810. return 0;
  5811. }
  5812. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  5813. return 1;
  5814. }
  5815. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  5816. if (!lua_interface)
  5817. return 0;
  5818. Spawn* spawn = lua_interface->GetSpawn(state);
  5819. if (!spawn) {
  5820. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  5821. return 0;
  5822. }
  5823. if (spawn->GetZone())
  5824. spawn->GetZone()->AddTransportSpawn(spawn);
  5825. return 0;
  5826. }
  5827. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  5828. if (!lua_interface)
  5829. return 0;
  5830. Skill* skill = lua_interface->GetSkill(state);
  5831. if (!skill) {
  5832. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5833. return 0;
  5834. }
  5835. lua_interface->SetInt32Value(state, skill->current_val);
  5836. return 1;
  5837. }
  5838. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  5839. if (!lua_interface)
  5840. return 0;
  5841. Skill* skill = lua_interface->GetSkill(state);
  5842. if (!skill) {
  5843. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5844. return 0;
  5845. }
  5846. lua_interface->SetInt32Value(state, skill->max_val);
  5847. return 1;
  5848. }
  5849. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  5850. if (!lua_interface)
  5851. return 0;
  5852. Skill* skill = lua_interface->GetSkill(state);
  5853. if (!skill) {
  5854. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  5855. return 0;
  5856. }
  5857. lua_interface->SetStringValue(state, skill->name.data.c_str());
  5858. return 1;
  5859. }
  5860. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  5861. if (!lua_interface)
  5862. return 0;
  5863. Skill* skill = lua_interface->GetSkill(state);
  5864. int16 value = lua_interface->GetInt16Value(state, 2);
  5865. if (!skill) {
  5866. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5867. return 0;
  5868. }
  5869. skill->max_val = value;
  5870. if (skill->max_val < skill->current_val)
  5871. skill->current_val = skill->max_val;
  5872. return 0;
  5873. }
  5874. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  5875. if (!lua_interface)
  5876. return 0;
  5877. Skill* skill = lua_interface->GetSkill(state);
  5878. int16 value = lua_interface->GetInt16Value(state, 2);
  5879. if (!skill) {
  5880. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5881. return 0;
  5882. }
  5883. if (value > skill->max_val)
  5884. skill->current_val = skill->max_val;
  5885. else
  5886. skill->current_val = value;
  5887. return 0;
  5888. }
  5889. int EQ2Emu_lua_GetSkill(lua_State* state) {
  5890. if (!lua_interface)
  5891. return 0;
  5892. Spawn* spawn = lua_interface->GetSpawn(state);
  5893. string name = lua_interface->GetStringValue(state, 2);
  5894. if (!spawn) {
  5895. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  5896. return 0;
  5897. }
  5898. if (!spawn->IsEntity()) {
  5899. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5900. return 0;
  5901. }
  5902. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  5903. if (skill) {
  5904. lua_interface->SetSkillValue(state, skill);
  5905. return 1;
  5906. }
  5907. return 0;
  5908. }
  5909. int EQ2Emu_lua_AddProc(lua_State* state) {
  5910. if (!lua_interface)
  5911. return 0;
  5912. Spawn* spawn = lua_interface->GetSpawn(state);
  5913. int8 type = lua_interface->GetInt8Value(state, 2);
  5914. float chance = lua_interface->GetFloatValue(state, 3);
  5915. Item* item = lua_interface->GetItem(state, 4);
  5916. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  5917. LuaSpell* spell = 0;
  5918. if (!spawn && (!spell || !use_all_spelltargets)) {
  5919. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  5920. return 0;
  5921. }
  5922. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  5923. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5924. return 0;
  5925. }
  5926. if (!item)
  5927. spell = lua_interface->GetCurrentSpell(state);
  5928. if (!item && !spell) {
  5929. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  5930. return 0;
  5931. }
  5932. if (spell && use_all_spelltargets) {
  5933. Spawn* target;
  5934. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5935. for (int8 i = 0; i < spell->targets.size(); i++) {
  5936. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5937. if (!target || !target->IsEntity())
  5938. continue;
  5939. ((Entity*)target)->AddProc(type, chance, item, spell);
  5940. }
  5941. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5942. }
  5943. else
  5944. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  5945. return 0;
  5946. }
  5947. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  5948. if (!lua_interface)
  5949. return 0;
  5950. Spawn* spawn = lua_interface->GetSpawn(state);
  5951. Item* item = lua_interface->GetItem(state, 2);
  5952. LuaSpell* spell = 0;
  5953. if (!spawn) {
  5954. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  5955. return 0;
  5956. }
  5957. if (!spawn->IsEntity()) {
  5958. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5959. return 0;
  5960. }
  5961. if (!item)
  5962. spell = lua_interface->GetCurrentSpell(state);
  5963. if (!item && !spell) {
  5964. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  5965. return 0;
  5966. }
  5967. if (spell) {
  5968. Spawn* target;
  5969. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5970. for (int8 i = 0; i < spell->targets.size(); i++) {
  5971. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5972. if (!target || !target->IsEntity())
  5973. continue;
  5974. ((Entity*)target)->RemoveProc(item, spell);
  5975. }
  5976. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5977. spell->caster->RemoveProc(item, spell);
  5978. }
  5979. else
  5980. ((Entity*)spawn)->RemoveProc(item, spell);
  5981. return 0;
  5982. }
  5983. int EQ2Emu_lua_Knockback(lua_State* state) {
  5984. if (!lua_interface)
  5985. return 0;
  5986. Spawn* target_spawn = lua_interface->GetSpawn(state);
  5987. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5988. int32 duration = lua_interface->GetInt32Value(state, 3);
  5989. float vertical = lua_interface->GetFloatValue(state, 4);
  5990. float horizontal = lua_interface->GetFloatValue(state, 5);
  5991. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  5992. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5993. if (!target_spawn) {
  5994. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  5995. return 0;
  5996. }
  5997. if (!spawn) {
  5998. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6002. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6003. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6004. if (packet) {
  6005. packet->setDataByName("target_x", target_spawn->GetX());
  6006. packet->setDataByName("target_y", target_spawn->GetY());
  6007. packet->setDataByName("target_z", target_spawn->GetZ());
  6008. packet->setDataByName("vertical_movement", vertical);
  6009. packet->setDataByName("horizontal_movement", horizontal);
  6010. if (use_heading)
  6011. packet->setDataByName("use_player_heading", 1);
  6012. client->QueuePacket(packet->serialize());
  6013. }
  6014. safe_delete(packet);
  6015. }
  6016. return 0;
  6017. }
  6018. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6019. if (!lua_interface)
  6020. return 0;
  6021. Spawn* spawn = lua_interface->GetSpawn(state);
  6022. if (!spawn) {
  6023. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6024. return 0;
  6025. }
  6026. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6027. return 1;
  6028. }
  6029. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6030. if (!lua_interface)
  6031. return 0;
  6032. Spawn* caster = lua_interface->GetSpawn(state);
  6033. Spawn* target = lua_interface->GetSpawn(state, 2);
  6034. string name = lua_interface->GetStringValue(state, 3);
  6035. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6036. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6037. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6038. string success_msg = lua_interface->GetStringValue(state, 7);
  6039. string effect_msg = lua_interface->GetStringValue(state, 8);
  6040. if (!caster) {
  6041. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6042. return 0;
  6043. }
  6044. if (!caster->IsEntity()) {
  6045. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6046. return 0;
  6047. }
  6048. if (!target) {
  6049. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6050. return 0;
  6051. }
  6052. if (!target->IsEntity()) {
  6053. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6054. return 0;
  6055. }
  6056. if (name.length() == 0) {
  6057. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6058. return 0;
  6059. }
  6060. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6061. return 0;
  6062. }
  6063. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6064. if (!lua_interface)
  6065. return 0;
  6066. string name = lua_interface->GetStringValue(state);
  6067. if (name.length() == 0) {
  6068. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6069. return 0;
  6070. }
  6071. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6072. if (!skill) {
  6073. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6074. return 0;
  6075. }
  6076. lua_interface->SetInt32Value(state, skill->skill_id);
  6077. return 1;
  6078. }
  6079. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6080. if (!lua_interface)
  6081. return 0;
  6082. Spawn* spawn = lua_interface->GetSpawn(state);
  6083. if (!spawn) {
  6084. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6085. return 0;
  6086. }
  6087. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6088. return 1;
  6089. }
  6090. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6091. if (!lua_interface)
  6092. return 0;
  6093. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6094. if (!luaspell) {
  6095. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6096. return 0;
  6097. }
  6098. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6099. return 1;
  6100. }
  6101. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6102. if (!lua_interface)
  6103. return 0;
  6104. Spawn* spawn = lua_interface->GetSpawn(state);
  6105. Spawn* target = lua_interface->GetSpawn(state, 2);
  6106. if (!spawn) {
  6107. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6108. return 0;
  6109. }
  6110. if (!spawn->IsEntity()) {
  6111. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6112. return 0;
  6113. }
  6114. if (!target) {
  6115. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6116. return 0;
  6117. }
  6118. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6119. return 1;
  6120. }
  6121. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6122. if (!lua_interface)
  6123. return 0;
  6124. Spawn* spawn = lua_interface->GetSpawn(state);
  6125. Spawn* target = lua_interface->GetSpawn(state, 2);
  6126. if (!spawn) {
  6127. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6128. return 0;
  6129. }
  6130. if (!spawn->IsEntity()) {
  6131. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6132. return 0;
  6133. }
  6134. if (!target) {
  6135. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6139. return 1;
  6140. }
  6141. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6142. if (!lua_interface)
  6143. return 0;
  6144. Item* item = lua_interface->GetItem(state);
  6145. if (!item) {
  6146. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6147. return 0;
  6148. }
  6149. lua_interface->SetInt32Value(state, item->details.count);
  6150. return 1;
  6151. }
  6152. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6153. if (!lua_interface)
  6154. return 0;
  6155. Item* item = lua_interface->GetItem(state);
  6156. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6157. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6158. if (!item) {
  6159. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6160. return 0;
  6161. }
  6162. if (!owner) {
  6163. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6164. return 0;
  6165. }
  6166. if (!owner->IsPlayer()) {
  6167. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6168. return 0;
  6169. }
  6170. if (item->stack_count < new_count) {
  6171. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6172. return 0;
  6173. }
  6174. if (new_count > 0) {
  6175. item->details.count = new_count;
  6176. item->save_needed = true;
  6177. }
  6178. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6179. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6180. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6181. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6182. else
  6183. {
  6184. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6185. return 0;
  6186. }
  6187. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6188. if (!client)
  6189. return 0;
  6190. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6191. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6192. if (app)
  6193. client->QueuePacket(app);
  6194. return 0;
  6195. }
  6196. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6197. if (!lua_interface)
  6198. return 0;
  6199. int32 time = lua_interface->GetInt32Value(state);
  6200. string function = lua_interface->GetStringValue(state, 2);
  6201. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6202. Spawn* target = lua_interface->GetSpawn(state, 4);
  6203. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6204. if (time == 0) {
  6205. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6206. return 0;
  6207. }
  6208. if (function.length() == 0) {
  6209. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6210. return 0;
  6211. }
  6212. if (!spell) {
  6213. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6214. return 0;
  6215. }
  6216. SpellScriptTimer* timer = new SpellScriptTimer;
  6217. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6218. #ifdef WIN32
  6219. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6220. #else
  6221. bzero(timer, sizeof(SpellScriptTimer));
  6222. #endif*/
  6223. timer->caster = 0;
  6224. timer->deleteWhenDone = false;
  6225. timer->target = 0;
  6226. timer->time = Timer::GetCurrentTime2() + time;
  6227. timer->customFunction = function;
  6228. timer->spell = spell;
  6229. if (caster)
  6230. timer->caster = caster->GetID();
  6231. if (target)
  6232. timer->target = target->GetID();
  6233. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6234. return 0;
  6235. }
  6236. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6237. if (!lua_interface)
  6238. return 0;
  6239. float hp_perc = lua_interface->GetFloatValue(state);
  6240. float power_perc = lua_interface->GetFloatValue(state, 2);
  6241. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6242. Spawn* target = lua_interface->GetSpawn(state, 4);
  6243. string heal_name = lua_interface->GetStringValue(state, 5);
  6244. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6245. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6246. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6247. if (!spell) {
  6248. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6249. return 0;
  6250. }
  6251. Entity* caster = spell->caster;
  6252. if (!caster) {
  6253. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6254. return 0;
  6255. }
  6256. Client* client = 0;
  6257. PendingResurrection* rez = 0;
  6258. ZoneServer* zone = spell->caster->GetZone();
  6259. if (!target) {
  6260. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6261. if (spell->targets.size() > 0) {
  6262. vector<int32> spell_targets = spell->targets;
  6263. for (int8 i = 0; i < spell_targets.size(); i++) {
  6264. target = zone->GetSpawnByID(spell_targets.at(i));
  6265. if (!target)
  6266. continue;
  6267. if (!target->IsPlayer())
  6268. continue;
  6269. client = target->GetZone()->GetClientBySpawn(target);
  6270. if (!client)
  6271. continue;
  6272. rez = client->GetCurrentRez();
  6273. if (rez->active)
  6274. continue;
  6275. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6276. rez->active = true;
  6277. rez->caster = caster;
  6278. rez->expire_timer = new Timer;
  6279. int32 duration = spell->spell->GetSpellDuration();
  6280. rez->expire_timer->Start(duration * 100);
  6281. rez->hp_perc = hp_perc;
  6282. rez->mp_perc = power_perc;
  6283. rez->range = spell->spell->GetSpellData()->range;
  6284. rez->spell_name = spell->spell->GetName();
  6285. if (heal_name.length() > 0)
  6286. rez->heal_name = heal_name;
  6287. else
  6288. rez->heal_name = rez->spell_name;
  6289. rez->no_calcs = no_calcs;
  6290. rez->crit_mod = crit_mod;
  6291. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6292. if (send_window)
  6293. client->SendResurrectionWindow();
  6294. else {
  6295. target->GetZone()->ResurrectSpawn(target, client);
  6296. rez->should_delete = true;
  6297. }
  6298. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6299. }
  6300. }
  6301. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6302. }
  6303. else {
  6304. client = target->GetZone()->GetClientBySpawn(target);
  6305. if (!client)
  6306. return 0;
  6307. rez = client->GetCurrentRez();
  6308. if (rez->active)
  6309. return 0;
  6310. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6311. rez->active = true;
  6312. rez->caster = caster;
  6313. rez->expire_timer = new Timer;
  6314. int32 duration = spell->spell->GetSpellDuration();
  6315. rez->expire_timer->Start(duration * 100);
  6316. rez->hp_perc = hp_perc;
  6317. rez->mp_perc = power_perc;
  6318. rez->range = spell->spell->GetSpellData()->range;
  6319. rez->spell_name = spell->spell->GetName();
  6320. if (heal_name.length() > 0)
  6321. rez->heal_name = heal_name;
  6322. else
  6323. rez->heal_name = rez->spell_name;
  6324. rez->no_calcs = no_calcs;
  6325. rez->crit_mod = crit_mod;
  6326. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6327. if (send_window)
  6328. client->SendResurrectionWindow();
  6329. else {
  6330. target->GetZone()->ResurrectSpawn(target, client);
  6331. rez->should_delete = true;
  6332. }
  6333. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6334. }
  6335. return 0;
  6336. }
  6337. int EQ2Emu_lua_SetVision(lua_State* state) {
  6338. if (!lua_interface)
  6339. return 0;
  6340. Spawn* spawn = lua_interface->GetSpawn(state);
  6341. int8 vision = lua_interface->GetInt8Value(state, 2);
  6342. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6343. if (!spawn) {
  6344. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6345. return 0;
  6346. }
  6347. if (!spawn->IsEntity()) {
  6348. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6349. return 0;
  6350. }
  6351. if (spell && spell->targets.size() > 0) {
  6352. ZoneServer* zone = spell->caster->GetZone();
  6353. for (int8 i = 0; i < spell->targets.size(); i++) {
  6354. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6355. if (target->IsEntity()) {
  6356. ((Entity*)target)->GetInfoStruct()->vision = vision;
  6357. if (target->IsPlayer())
  6358. ((Player*)target)->SetCharSheetChanged(true);
  6359. }
  6360. }
  6361. }
  6362. else {
  6363. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  6364. if (spawn->IsPlayer())
  6365. ((Player*)spawn)->SetCharSheetChanged(true);
  6366. }
  6367. return 0;
  6368. }
  6369. int EQ2Emu_lua_BlurVision(lua_State* state) {
  6370. if (!lua_interface)
  6371. return 0;
  6372. Spawn* spawn = lua_interface->GetSpawn(state);
  6373. float intensity = lua_interface->GetFloatValue(state, 2);
  6374. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6375. if (!spawn) {
  6376. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6377. return 0;
  6378. }
  6379. if (!spawn->IsEntity()) {
  6380. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6381. return 0;
  6382. }
  6383. if (spell && spell->targets.size() > 0) {
  6384. ZoneServer* zone = spell->caster->GetZone();
  6385. for (int8 i = 0; i < spell->targets.size(); i++) {
  6386. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6387. if (target && target->IsEntity()) {
  6388. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  6389. if (target->IsPlayer())
  6390. ((Player*)target)->SetCharSheetChanged(true);
  6391. }
  6392. }
  6393. }
  6394. else {
  6395. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  6396. if (spawn->IsPlayer())
  6397. ((Player*)spawn)->SetCharSheetChanged(true);
  6398. }
  6399. return 0;
  6400. }
  6401. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  6402. if (!lua_interface)
  6403. return 0;
  6404. Spawn* spawn = lua_interface->GetSpawn(state);
  6405. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  6406. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6407. if (!spawn) {
  6408. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  6409. return 0;
  6410. }
  6411. if (!spawn->IsEntity()) {
  6412. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  6413. return 0;
  6414. }
  6415. if (spell && spell->targets.size() > 0) {
  6416. ZoneServer* zone = spell->caster->GetZone();
  6417. for (int8 i = 0; i < spell->targets.size(); i++) {
  6418. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6419. if (target->IsEntity()) {
  6420. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6421. if (target->IsPlayer())
  6422. ((Player*)target)->SetCharSheetChanged(true);
  6423. }
  6424. }
  6425. }
  6426. else {
  6427. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6428. if (spawn->IsPlayer())
  6429. ((Player*)spawn)->SetCharSheetChanged(true);
  6430. }
  6431. return 0;
  6432. }
  6433. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  6434. if (!lua_interface)
  6435. return 0;
  6436. Item* item = lua_interface->GetItem(state);
  6437. int8 type = lua_interface->GetInt32Value(state, 2);
  6438. if (!item) {
  6439. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  6440. return 0;
  6441. }
  6442. if (type == 1)
  6443. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  6444. else if (type == 2)
  6445. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  6446. return 1;
  6447. }
  6448. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  6449. if (!lua_interface)
  6450. return 0;
  6451. Spawn* target = lua_interface->GetSpawn(state);
  6452. float val = lua_interface->GetFloatValue(state, 2);
  6453. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6454. // Added from Gangrenous post
  6455. if (spell && spell->resisted)
  6456. return 0;
  6457. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  6458. if (val > 1.0f)
  6459. val = 1.0f - (val / 100.0f);
  6460. if (spell && spell->spell && spell->targets.size() > 0) {
  6461. ZoneServer* zone = spell->caster->GetZone();
  6462. for (int32 i = 0; i != spell->targets.size(); i++) {
  6463. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  6464. if (spawn && spawn->IsEntity()) {
  6465. ((Entity*)spawn)->SetSpeedMultiplier(val);
  6466. if (spawn->IsPlayer())
  6467. ((Player*)spawn)->SetCharSheetChanged(true);
  6468. }
  6469. }
  6470. }
  6471. else {
  6472. if (target && target->IsEntity()) {
  6473. ((Entity*)target)->SetSpeedMultiplier(val);
  6474. if (target->IsPlayer())
  6475. ((Player*)target)->SetCharSheetChanged(true);
  6476. }
  6477. }
  6478. return 0;
  6479. }
  6480. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  6481. if (!lua_interface)
  6482. return 0;
  6483. Spawn* spawn = lua_interface->GetSpawn(state);
  6484. int16 model = lua_interface->GetInt16Value(state, 2);
  6485. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6486. if (spell && spell->spell && spell->targets.size() > 0) {
  6487. ZoneServer* zone = spell->caster->GetZone();
  6488. for (int32 i = 0; i < spell->targets.size(); i++) {
  6489. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6490. if (target)
  6491. target->SetIllusionModel(model);
  6492. }
  6493. }
  6494. else {
  6495. if (!spawn) {
  6496. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6497. return 0;
  6498. }
  6499. spawn->SetIllusionModel(model);
  6500. }
  6501. return 0;
  6502. }
  6503. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  6504. if (!lua_interface)
  6505. return 0;
  6506. Spawn* spawn = lua_interface->GetSpawn(state);
  6507. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6508. if (spell && spell->spell && spell->targets.size() > 0) {
  6509. ZoneServer* zone = spell->caster->GetZone();
  6510. for (int32 i = 0; i < spell->targets.size(); i++) {
  6511. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6512. if (target)
  6513. target->SetIllusionModel(0);
  6514. }
  6515. }
  6516. else {
  6517. if (!spawn) {
  6518. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6519. return 0;
  6520. }
  6521. spawn->SetIllusionModel(0);
  6522. }
  6523. return 0;
  6524. }
  6525. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  6526. if (!lua_interface)
  6527. return 0;
  6528. Spawn* caster = lua_interface->GetSpawn(state);
  6529. Spawn* target = lua_interface->GetSpawn(state, 2);
  6530. float chance = lua_interface->GetFloatValue(state, 3);
  6531. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6532. if (!caster) {
  6533. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6534. return 0;
  6535. }
  6536. if (!caster->IsEntity()) {
  6537. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  6538. return 0;
  6539. }
  6540. if (!target) {
  6541. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6542. return 0;
  6543. }
  6544. if (!target->IsEntity()) {
  6545. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  6546. return 0;
  6547. }
  6548. if (chance <= 0) {
  6549. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  6550. return 0;
  6551. }
  6552. if (!spell) {
  6553. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6554. return 0;
  6555. }
  6556. if (((Entity*)caster)->GetThreatTransfer()) {
  6557. return 0;
  6558. }
  6559. ThreatTransfer* transfer = new ThreatTransfer;
  6560. transfer->Target = target->GetID();
  6561. transfer->Amount = chance;
  6562. transfer->Spell = spell;
  6563. ((Entity*)caster)->SetThreatTransfer(transfer);
  6564. return 0;
  6565. }
  6566. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  6567. if (!lua_interface)
  6568. return 0;
  6569. Spawn* spawn = lua_interface->GetSpawn(state);
  6570. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6571. if (!spawn) {
  6572. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6573. return 0;
  6574. }
  6575. if (!spell) {
  6576. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6577. return 0;
  6578. }
  6579. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  6580. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  6581. safe_delete(transfer);
  6582. ((Entity*)spawn)->SetThreatTransfer(0);
  6583. }
  6584. return 0;
  6585. }
  6586. int EQ2Emu_lua_CureByType(lua_State* state) {
  6587. if (!lua_interface)
  6588. return 0;
  6589. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6590. if (!spell) {
  6591. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6592. return 0;
  6593. }
  6594. int8 cure_count = lua_interface->GetInt8Value(state);
  6595. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  6596. string cure_name = lua_interface->GetStringValue(state, 3);
  6597. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  6598. Spawn* target = lua_interface->GetSpawn(state, 5);
  6599. if (target) {
  6600. if (!target->IsEntity()) {
  6601. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  6602. return 0;
  6603. }
  6604. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  6605. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6606. }
  6607. else {
  6608. ZoneServer* zone = spell->caster->GetZone();
  6609. vector<int32> targets = spell->targets;
  6610. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6611. for (int8 i = 0; i < targets.size(); i++) {
  6612. target = zone->GetSpawnByID(targets.at(i));
  6613. if (!target || !target->IsEntity())
  6614. continue;
  6615. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  6616. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6617. }
  6618. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6619. }
  6620. return 0;
  6621. }
  6622. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  6623. if (!lua_interface)
  6624. return 0;
  6625. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6626. if (!spell) {
  6627. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6628. return 0;
  6629. }
  6630. int8 cure_count = lua_interface->GetInt8Value(state);
  6631. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  6632. string cure_name = lua_interface->GetStringValue(state, 3);
  6633. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  6634. Spawn* target = lua_interface->GetSpawn(state, 5);
  6635. if (target) {
  6636. if (!target->IsEntity()) {
  6637. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  6638. return 0;
  6639. }
  6640. if (((Entity*)target)->GetDetCount() > 0)
  6641. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6642. }
  6643. else {
  6644. ZoneServer* zone = spell->caster->GetZone();
  6645. vector<int32> targets = spell->targets;
  6646. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6647. for (int8 i = 0; i < targets.size(); i++) {
  6648. target = zone->GetSpawnByID(targets.at(i));
  6649. if (!target || !target->IsEntity())
  6650. continue;
  6651. if (((Entity*)target)->GetDetCount() > 0)
  6652. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6653. }
  6654. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6655. }
  6656. return 0;
  6657. }
  6658. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  6659. if (!lua_interface)
  6660. return 0;
  6661. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6662. if (!spell) {
  6663. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  6664. return 0;
  6665. }
  6666. if (!spell->caster) {
  6667. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  6668. return 0;
  6669. }
  6670. if (!spell->caster->GetZone()) {
  6671. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  6672. return 0;
  6673. }
  6674. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  6675. return 0;
  6676. }
  6677. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  6678. if (!lua_interface)
  6679. return 0;
  6680. Spawn* spawn = lua_interface->GetSpawn(state);
  6681. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6682. if (!spell) {
  6683. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6684. return 0;
  6685. }
  6686. if (spawn && spawn->IsEntity())
  6687. ((Entity*)spawn)->RemoveStealthSpell(spell);
  6688. else {
  6689. ZoneServer* zone = spell->caster->GetZone();
  6690. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6691. for (int32 i = 0; i < spell->targets.size(); i++) {
  6692. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6693. if (!spawn || !spawn->IsEntity())
  6694. continue;
  6695. ((Entity*)spawn)->RemoveStealthSpell(spell);
  6696. }
  6697. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6698. }
  6699. return 0;
  6700. }
  6701. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  6702. if (!lua_interface)
  6703. return 0;
  6704. Spawn* spawn = lua_interface->GetSpawn(state);
  6705. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6706. if (!spell) {
  6707. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  6708. return 0;
  6709. }
  6710. if (spawn && spawn->IsEntity())
  6711. ((Entity*)spawn)->RemoveInvisSpell(spell);
  6712. else {
  6713. ZoneServer* zone = spell->caster->GetZone();
  6714. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6715. for (int32 i = 0; i < spell->targets.size(); i++) {
  6716. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6717. if (!spawn || !spawn->IsEntity())
  6718. continue;
  6719. ((Entity*)spawn)->RemoveInvisSpell(spell);
  6720. }
  6721. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6722. }
  6723. return 0;
  6724. }
  6725. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  6726. if (!lua_interface)
  6727. return 0;
  6728. Spawn* caster = lua_interface->GetSpawn(state);
  6729. int8 class_id = lua_interface->GetInt8Value(state, 2);
  6730. if (!caster) {
  6731. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  6732. return 0;
  6733. }
  6734. if (!caster->IsPlayer()) {
  6735. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  6736. return 0;
  6737. }
  6738. Spawn* target = caster->GetTarget();
  6739. if (!target) {
  6740. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  6741. return 0;
  6742. }
  6743. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  6744. if (!client) {
  6745. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  6746. return 0;
  6747. }
  6748. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  6749. if (ho) {
  6750. ho->SetTarget(target->GetID());
  6751. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  6752. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  6753. if (((Entity*)caster)->GetGroupMemberInfo()) {
  6754. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  6755. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  6756. deque<GroupMemberInfo*>::iterator itr;
  6757. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  6758. for (itr = members->begin(); itr != members->end(); itr++) {
  6759. if ((*itr)->client)
  6760. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  6761. }
  6762. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  6763. }
  6764. else
  6765. safe_delete(ho);
  6766. }
  6767. else {
  6768. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  6769. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  6770. }
  6771. else
  6772. safe_delete(ho);
  6773. }
  6774. }
  6775. return 0;
  6776. }
  6777. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  6778. if (!lua_interface)
  6779. return 0;
  6780. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6781. if (!spell) {
  6782. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6783. return 0;
  6784. }
  6785. int16 triggerCount = lua_interface->GetInt16Value(state);
  6786. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  6787. if (!triggerCount) {
  6788. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  6789. return 0;
  6790. }
  6791. spell->num_triggers = triggerCount;
  6792. spell->had_triggers = true;
  6793. spell->cancel_after_all_triggers = cancel_after_triggers;
  6794. return 0;
  6795. }
  6796. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  6797. if (!lua_interface)
  6798. return 0;
  6799. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6800. if (!spell) {
  6801. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6802. return 0;
  6803. }
  6804. lua_interface->SetInt32Value(state, spell->num_triggers);
  6805. return 1;
  6806. }
  6807. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  6808. if (!lua_interface)
  6809. return 0;
  6810. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6811. if (!spell) {
  6812. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6813. return 0;
  6814. }
  6815. int16 remove_count = lua_interface->GetInt16Value(state);
  6816. if (!remove_count)
  6817. remove_count = 1;
  6818. if (remove_count >= spell->num_triggers) {
  6819. spell->num_triggers = 0;
  6820. if (spell->cancel_after_all_triggers)
  6821. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  6822. }
  6823. else {
  6824. spell->num_triggers -= remove_count;
  6825. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  6826. }
  6827. return 0;
  6828. }
  6829. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  6830. if (!lua_interface)
  6831. return 0;
  6832. Spawn* spawn = lua_interface->GetSpawn(state);
  6833. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  6834. if (!spawn) {
  6835. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  6836. return 0;
  6837. }
  6838. if (!copy_spawn) {
  6839. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  6840. return 0;
  6841. }
  6842. spawn->CopySpawnAppearance(copy_spawn);
  6843. return 0;
  6844. }
  6845. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  6846. if (!lua_interface)
  6847. return 0;
  6848. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6849. int8 type = lua_interface->GetInt8Value(state);
  6850. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6851. if (!spell) {
  6852. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  6853. return 0;
  6854. }
  6855. if (spawn) {
  6856. if (!spawn->IsEntity()) {
  6857. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  6858. return 0;
  6859. }
  6860. Entity* entity = ((Entity*)spawn);
  6861. switch (type) {
  6862. case IMMUNITY_TYPE_AOE:
  6863. entity->AddAOEImmunity(spell);
  6864. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  6865. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  6866. break;
  6867. case IMMUNITY_TYPE_STUN:
  6868. entity->AddStunImmunity(spell);
  6869. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  6870. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  6871. break;
  6872. case IMMUNITY_TYPE_ROOT:
  6873. entity->AddRootImmunity(spell);
  6874. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  6875. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  6876. break;
  6877. case IMMUNITY_TYPE_DAZE:
  6878. entity->AddDazeImmunity(spell);
  6879. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  6880. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  6881. break;
  6882. case IMMUNITY_TYPE_FEAR:
  6883. entity->AddFearImmunity(spell);
  6884. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  6885. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  6886. break;
  6887. case IMMUNITY_TYPE_MEZ:
  6888. entity->AddMezImmunity(spell);
  6889. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  6890. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  6891. break;
  6892. case IMMUNITY_TYPE_STIFLE:
  6893. entity->AddStifleImmunity(spell);
  6894. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  6895. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  6896. break;
  6897. default:
  6898. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6899. }
  6900. }
  6901. else {
  6902. bool should_break = false;
  6903. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6904. for (int8 i = 0; i < spell->targets.size(); i++) {
  6905. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6906. if (!spawn || !spawn->IsEntity())
  6907. continue;
  6908. Entity* entity = ((Entity*)spawn);
  6909. switch (type) {
  6910. case IMMUNITY_TYPE_AOE:
  6911. entity->AddAOEImmunity(spell);
  6912. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  6913. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  6914. break;
  6915. case IMMUNITY_TYPE_STUN:
  6916. entity->AddStunImmunity(spell);
  6917. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  6918. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  6919. break;
  6920. case IMMUNITY_TYPE_ROOT:
  6921. entity->AddRootImmunity(spell);
  6922. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  6923. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  6924. break;
  6925. case IMMUNITY_TYPE_DAZE:
  6926. entity->AddDazeImmunity(spell);
  6927. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  6928. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  6929. break;
  6930. case IMMUNITY_TYPE_FEAR:
  6931. entity->AddFearImmunity(spell);
  6932. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  6933. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  6934. break;
  6935. case IMMUNITY_TYPE_MEZ:
  6936. entity->AddMezImmunity(spell);
  6937. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  6938. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  6939. break;
  6940. case IMMUNITY_TYPE_STIFLE:
  6941. entity->AddStifleImmunity(spell);
  6942. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  6943. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  6944. break;
  6945. default:
  6946. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6947. should_break = true;
  6948. }
  6949. if (should_break)
  6950. break;
  6951. }
  6952. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6953. }
  6954. return 0;
  6955. }
  6956. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  6957. if (!lua_interface)
  6958. return 0;
  6959. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6960. int8 type = lua_interface->GetInt8Value(state);
  6961. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6962. if (!spell) {
  6963. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  6964. return 0;
  6965. }
  6966. if (spawn) {
  6967. if (!spawn->IsEntity()) {
  6968. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  6969. return 0;
  6970. }
  6971. Entity* entity = ((Entity*)spawn);
  6972. switch (type) {
  6973. case IMMUNITY_TYPE_AOE:
  6974. entity->RemoveAOEImmunity(spell);
  6975. break;
  6976. case IMMUNITY_TYPE_STUN:
  6977. entity->RemoveStunImmunity(spell);
  6978. break;
  6979. case IMMUNITY_TYPE_ROOT:
  6980. entity->RemoveRootImmunity(spell);
  6981. break;
  6982. case IMMUNITY_TYPE_DAZE:
  6983. entity->RemoveDazeImmunity(spell);
  6984. break;
  6985. case IMMUNITY_TYPE_FEAR:
  6986. entity->RemoveFearImmunity(spell);
  6987. break;
  6988. case IMMUNITY_TYPE_MEZ:
  6989. entity->RemoveMezImmunity(spell);
  6990. break;
  6991. case IMMUNITY_TYPE_STIFLE:
  6992. entity->RemoveStifleImmunity(spell);
  6993. break;
  6994. default:
  6995. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6996. }
  6997. }
  6998. else {
  6999. bool should_break = false;
  7000. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7001. for (int8 i = 0; i < spell->targets.size(); i++) {
  7002. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7003. if (!spawn || !spawn->IsEntity())
  7004. continue;
  7005. Entity* entity = ((Entity*)spawn);
  7006. switch (type) {
  7007. case IMMUNITY_TYPE_AOE:
  7008. entity->RemoveAOEImmunity(spell);
  7009. break;
  7010. case IMMUNITY_TYPE_STUN:
  7011. entity->RemoveStunImmunity(spell);
  7012. break;
  7013. case IMMUNITY_TYPE_ROOT:
  7014. entity->RemoveRootImmunity(spell);
  7015. break;
  7016. case IMMUNITY_TYPE_DAZE:
  7017. entity->RemoveDazeImmunity(spell);
  7018. break;
  7019. case IMMUNITY_TYPE_FEAR:
  7020. entity->RemoveFearImmunity(spell);
  7021. break;
  7022. case IMMUNITY_TYPE_MEZ:
  7023. entity->RemoveMezImmunity(spell);
  7024. break;
  7025. case IMMUNITY_TYPE_STIFLE:
  7026. entity->RemoveStifleImmunity(spell);
  7027. break;
  7028. default:
  7029. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7030. should_break = true;
  7031. }
  7032. if (should_break)
  7033. break;
  7034. }
  7035. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7036. }
  7037. return 0;
  7038. }
  7039. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7040. if (!lua_interface)
  7041. return 0;
  7042. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7043. if (!spell) {
  7044. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7045. return 0;
  7046. }
  7047. float snare = lua_interface->GetFloatValue(state);
  7048. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7049. // convert the val to the speed multipler value (100 - val)
  7050. float val = 100.0 - snare;
  7051. val /= 100.0;
  7052. if (spawn) {
  7053. if (!spawn->IsEntity()) {
  7054. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7055. return 0;
  7056. }
  7057. ((Entity*)spawn)->SetSnareValue(spell, val);
  7058. }
  7059. else {
  7060. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7061. for (int8 i = 0; i < spell->targets.size(); i++) {
  7062. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7063. if (!spawn || !spawn->IsEntity())
  7064. continue;
  7065. ((Entity*)spawn)->SetSnareValue(spell, val);
  7066. }
  7067. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7068. }
  7069. return 0;
  7070. }
  7071. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7072. if (!lua_interface)
  7073. return 0;
  7074. Spawn* spawn = lua_interface->GetSpawn(state);
  7075. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7076. if (!spawn) {
  7077. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7078. return 0;
  7079. }
  7080. if (race_id == 0) {
  7081. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7082. return 0;
  7083. }
  7084. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7085. return 1;
  7086. }
  7087. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7088. if (!lua_interface)
  7089. return 0;
  7090. Spawn* spawn = lua_interface->GetSpawn(state);
  7091. if (!spawn) {
  7092. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7093. return 0;
  7094. }
  7095. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7096. return 1;
  7097. }
  7098. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7099. if (!lua_interface)
  7100. return 0;
  7101. Spawn* spawn = lua_interface->GetSpawn(state);
  7102. if (!spawn) {
  7103. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7104. return 0;
  7105. }
  7106. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7107. return 1;
  7108. }
  7109. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7110. if (!lua_interface)
  7111. return 0;
  7112. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7113. if (!spell) {
  7114. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7115. return 0;
  7116. }
  7117. lua_interface->SetStringValue(state, spell->spell->GetName());
  7118. return 1;
  7119. }
  7120. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7121. if (!lua_interface)
  7122. return 0;
  7123. Quest* quest = lua_interface->GetQuest(state);
  7124. if (!quest) {
  7125. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7126. return 0;
  7127. }
  7128. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7129. return 1;
  7130. }
  7131. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7132. if (!lua_interface)
  7133. return 0;
  7134. Quest* quest = lua_interface->GetQuest(state);
  7135. int32 flags = lua_interface->GetInt32Value(state, 2);
  7136. if (!quest) {
  7137. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7138. return 0;
  7139. }
  7140. quest->SetQuestFlags(flags);
  7141. return 0;
  7142. }
  7143. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7144. if (!lua_interface)
  7145. return 0;
  7146. Quest* quest = lua_interface->GetQuest(state);
  7147. Spawn* player = lua_interface->GetSpawn(state, 2);
  7148. int32 step = lua_interface->GetInt32Value(state, 3);
  7149. int32 duration = lua_interface->GetInt32Value(state, 4);
  7150. string action = lua_interface->GetStringValue(state, 5);
  7151. if (!quest) {
  7152. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7153. return 0;
  7154. }
  7155. if (!player) {
  7156. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7157. return 0;
  7158. }
  7159. if (!player->IsPlayer()) {
  7160. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7161. return 0;
  7162. }
  7163. if (step == 0) {
  7164. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7165. return 0;
  7166. }
  7167. if (duration == 0) {
  7168. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7169. return 0;
  7170. }
  7171. if (action.length() == 0) {
  7172. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7173. return 0;
  7174. }
  7175. Client* client = player->GetZone()->GetClientBySpawn(player);
  7176. if (!client) {
  7177. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7178. return 0;
  7179. }
  7180. quest->SetTimerStep(step);
  7181. quest->AddFailedAction(step, action);
  7182. quest->SetStepTimer(duration);
  7183. client->AddQuestTimer(quest->GetQuestID());
  7184. return 0;
  7185. }
  7186. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7187. if (!lua_interface)
  7188. return 0;
  7189. Quest* quest = lua_interface->GetQuest(state);
  7190. Spawn* player = lua_interface->GetSpawn(state, 2);
  7191. if (!quest) {
  7192. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7193. return 0;
  7194. }
  7195. if (!player) {
  7196. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7197. return 0;
  7198. }
  7199. if (!player->IsPlayer()) {
  7200. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7201. return 0;
  7202. }
  7203. Client* client = player->GetZone()->GetClientBySpawn(player);
  7204. if (!client) {
  7205. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7206. return 0;
  7207. }
  7208. quest->SetTimerStep(0);
  7209. quest->SetStepTimer(0);
  7210. client->RemoveQuestTimer(quest->GetQuestID());
  7211. return 0;
  7212. }
  7213. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7214. if (!lua_interface)
  7215. return 0;
  7216. Spawn* player = lua_interface->GetSpawn(state);
  7217. Quest* quest = lua_interface->GetQuest(state, 2);
  7218. int32 step = lua_interface->GetInt32Value(state, 3);
  7219. if (!player) {
  7220. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7221. return 0;
  7222. }
  7223. if (!player->IsPlayer()) {
  7224. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7225. return 0;
  7226. }
  7227. if (!quest) {
  7228. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7229. return 0;
  7230. }
  7231. if (step == 0) {
  7232. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7233. return 0;
  7234. }
  7235. Client* client = player->GetZone()->GetClientBySpawn(player);
  7236. if (!client) {
  7237. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7238. return 0;
  7239. }
  7240. if (quest->RemoveQuestStep(step, client)) {
  7241. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7242. client->GetCurrentZone()->SendQuestUpdates(client);
  7243. }
  7244. else
  7245. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7246. return 0;
  7247. }
  7248. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7249. if (!lua_interface)
  7250. return 0;
  7251. Quest* quest = lua_interface->GetQuest(state, 1);
  7252. int32 step = lua_interface->GetInt32Value(state, 2);
  7253. string desc = lua_interface->GetStringValue(state, 3);
  7254. string task_group = lua_interface->GetStringValue(state, 4);
  7255. if (!quest) {
  7256. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7257. return 0;
  7258. }
  7259. if (step == 0) {
  7260. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7261. return 0;
  7262. }
  7263. QuestStep* quest_step = quest->GetQuestStep(step);
  7264. if (!quest_step) {
  7265. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7266. return 0;
  7267. }
  7268. quest_step->SetStepProgress(0);
  7269. quest_step->SetTaskGroup(task_group);
  7270. quest_step->SetDescription(desc);
  7271. return 0;
  7272. }
  7273. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7274. if (!lua_interface)
  7275. return 0;
  7276. Quest* quest = lua_interface->GetQuest(state);
  7277. int32 step = lua_interface->GetInt32Value(state, 2);
  7278. string action = lua_interface->GetStringValue(state, 3);
  7279. if (!quest) {
  7280. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7281. return 0;
  7282. }
  7283. if (step == 0) {
  7284. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  7285. return 0;
  7286. }
  7287. if (action.length() == 0) {
  7288. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  7289. return 0;
  7290. }
  7291. quest->AddFailedAction(step, action);
  7292. return 0;
  7293. }
  7294. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  7295. if (!lua_interface)
  7296. return 0;
  7297. Spawn* player = lua_interface->GetSpawn(state);
  7298. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7299. int32 step = lua_interface->GetInt32Value(state, 3);
  7300. if (!player) {
  7301. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7302. return 0;
  7303. }
  7304. if (!player->IsPlayer()) {
  7305. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7306. return 0;
  7307. }
  7308. if (quest_id == 0) {
  7309. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  7310. return 0;
  7311. }
  7312. if (step == 0) {
  7313. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  7314. return 0;
  7315. }
  7316. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  7317. if (!quest) {
  7318. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  7319. return 0;
  7320. }
  7321. quest->StepFailed(step);
  7322. return 0;
  7323. }
  7324. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  7325. if (!lua_interface)
  7326. return 0;
  7327. Spawn* player = lua_interface->GetSpawn(state);
  7328. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7329. if (!player) {
  7330. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  7331. return 0;
  7332. }
  7333. if (!player->IsPlayer()) {
  7334. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  7335. return 0;
  7336. }
  7337. if (quest_id == 0) {
  7338. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  7339. return 0;
  7340. }
  7341. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  7342. if (!quest) {
  7343. lua_interface->SetInt32Value(state, 0);
  7344. return 1;
  7345. }
  7346. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  7347. return 1;
  7348. }
  7349. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  7350. if (!lua_interface)
  7351. return 0;
  7352. string name = lua_interface->GetStringValue(state);
  7353. string value = lua_interface->GetStringValue(state, 2);
  7354. string comment = lua_interface->GetStringValue(state, 3);
  7355. if (name.length() == 0) {
  7356. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7357. return 0;
  7358. }
  7359. if (value.length() == 0) {
  7360. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  7361. return 0;
  7362. }
  7363. string varname = string("lua_").append(name);
  7364. Variable* var = variables.FindVariable(varname);
  7365. if (var)
  7366. var->SetValue(value.c_str());
  7367. else {
  7368. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  7369. variables.AddVariable(var);
  7370. }
  7371. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  7372. return 0;
  7373. }
  7374. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  7375. if (!lua_interface)
  7376. return 0;
  7377. string name = lua_interface->GetStringValue(state);
  7378. if (name.length() == 0) {
  7379. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7380. return 0;
  7381. }
  7382. string varname = string("lua_").append(name);
  7383. Variable* var = variables.FindVariable(varname);
  7384. if (var)
  7385. lua_interface->SetStringValue(state, var->GetValue());
  7386. else
  7387. lua_interface->SetStringValue(state, "NULL");
  7388. return 1;
  7389. }
  7390. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  7391. if (!lua_interface)
  7392. return 0;
  7393. Spawn* player = lua_interface->GetSpawn(state);
  7394. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7395. if (!player) {
  7396. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7397. return 0;
  7398. }
  7399. if (!player->IsPlayer()) {
  7400. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7401. return 0;
  7402. }
  7403. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  7404. return 1;
  7405. }
  7406. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  7407. if (!lua_interface)
  7408. return 0;
  7409. Spawn* player = lua_interface->GetSpawn(state);
  7410. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7411. if (!player) {
  7412. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7413. return 0;
  7414. }
  7415. if (!player->IsPlayer()) {
  7416. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7417. return 0;
  7418. }
  7419. Language* language = master_languages_list.GetLanguage(language_id);
  7420. if (language)
  7421. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  7422. return 0;
  7423. }
  7424. int EQ2Emu_lua_IsNight(lua_State* state) {
  7425. if (!lua_interface)
  7426. return 0;
  7427. ZoneServer* zone = lua_interface->GetZone(state);
  7428. if (!zone) {
  7429. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  7430. return 0;
  7431. }
  7432. lua_interface->SetBooleanValue(state, zone->IsDusk());
  7433. return 1;
  7434. }
  7435. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  7436. if (!lua_interface)
  7437. return 0;
  7438. Spawn* spawn = lua_interface->GetSpawn(state);
  7439. if (!spawn) {
  7440. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  7441. return 0;
  7442. }
  7443. if (!spawn->IsWidget()) {
  7444. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  7445. return 0;
  7446. }
  7447. ((Widget*)spawn)->SetMultiFloorLift(true);
  7448. if (spawn->GetZone())
  7449. spawn->GetZone()->AddTransportSpawn(spawn);
  7450. return 0;
  7451. }
  7452. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  7453. if (!lua_interface)
  7454. return 0;
  7455. Spawn* player = lua_interface->GetSpawn(state);
  7456. int32 path = lua_interface->GetInt32Value(state, 2);
  7457. if (!player) {
  7458. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7459. return 0;
  7460. }
  7461. if (!player->IsPlayer()) {
  7462. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7463. return 0;
  7464. }
  7465. if (path == 0) {
  7466. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  7467. return 0;
  7468. }
  7469. Client* client = player->GetZone()->GetClientBySpawn(player);
  7470. if (!client) {
  7471. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7472. return 0;
  7473. }
  7474. client->SetPendingFlightPath(path);
  7475. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  7476. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  7477. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  7478. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", client->GetVersion());
  7479. if (packet) {
  7480. client->QueuePacket(packet->serialize());
  7481. safe_delete(packet);
  7482. }
  7483. return 0;
  7484. }
  7485. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  7486. if (!lua_interface)
  7487. return 0;
  7488. Spawn* player = lua_interface->GetSpawn(state);
  7489. if (!player) {
  7490. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7491. return 0;
  7492. }
  7493. if (!player->IsPlayer()) {
  7494. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7495. return 0;
  7496. }
  7497. Client* client = player->GetZone()->GetClientBySpawn(player);
  7498. if (!client) {
  7499. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7500. return 0;
  7501. }
  7502. client->EndAutoMount();
  7503. return 0;
  7504. }
  7505. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  7506. if (!lua_interface)
  7507. return 0;
  7508. Spawn* player = lua_interface->GetSpawn(state);
  7509. if (!player) {
  7510. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  7511. return 0;
  7512. }
  7513. if (!player->IsPlayer()) {
  7514. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7515. return 0;
  7516. }
  7517. Client* client = player->GetZone()->GetClientBySpawn(player);
  7518. if (!client) {
  7519. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7520. return 0;
  7521. }
  7522. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  7523. return 1;
  7524. }
  7525. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  7526. if (!lua_interface)
  7527. return 0;
  7528. Spawn* player = lua_interface->GetSpawn(state);
  7529. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7530. int32 value = lua_interface->GetInt32Value(state, 3);
  7531. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7532. if (!player) {
  7533. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7534. return 0;
  7535. }
  7536. if (!player->IsPlayer()) {
  7537. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  7538. return 0;
  7539. }
  7540. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  7541. return 0;
  7542. }
  7543. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  7544. if (!lua_interface)
  7545. return 0;
  7546. Spawn* player = lua_interface->GetSpawn(state);
  7547. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7548. if (!player) {
  7549. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7550. return 0;
  7551. }
  7552. if (!player->IsPlayer()) {
  7553. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  7554. return 0;
  7555. }
  7556. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  7557. if (!hd)
  7558. return 0;
  7559. lua_interface->SetInt32Value(state, hd->Value);
  7560. lua_interface->SetInt32Value(state, hd->Value2);
  7561. return 2;
  7562. }
  7563. int EQ2Emu_lua_SetGridID(lua_State* state) {
  7564. if (!lua_interface)
  7565. return 0;
  7566. Spawn* spawn = lua_interface->GetSpawn(state);
  7567. int32 grid = lua_interface->GetInt32Value(state, 2);
  7568. if (!spawn) {
  7569. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  7570. return 0;
  7571. }
  7572. if (grid == 0) {
  7573. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  7574. return 0;
  7575. }
  7576. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  7577. return 0;
  7578. }
  7579. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  7580. if (!lua_interface)
  7581. return 0;
  7582. Spawn* spawn = lua_interface->GetSpawn(state);
  7583. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7584. int32 value1 = lua_interface->GetInt32Value(state, 3);
  7585. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7586. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  7587. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  7588. if (!spawn) {
  7589. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7590. return 0;
  7591. }
  7592. //Add this quest to the list of required quests for this spawn
  7593. spawn->SetRequiredHistory(event_id, value1, value2);
  7594. //If private spawn value set
  7595. if (private_spawn) {
  7596. //Set the spawn to be private when not granted access via history
  7597. spawn->AddAllowAccessSpawn(spawn);
  7598. spawn->SetPrivateQuestSpawn(true);
  7599. }
  7600. //This value will override vis_flags in the vis packet
  7601. if (flag_override > 0)
  7602. spawn->SetQuestsRequiredOverride(flag_override);
  7603. return 0;
  7604. }
  7605. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  7606. if (!lua_interface)
  7607. return 0;
  7608. Spawn* player = lua_interface->GetSpawn(state);
  7609. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7610. int32 step_id = lua_interface->GetInt32Value(state, 3);
  7611. if (!player) {
  7612. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  7613. return 0;
  7614. }
  7615. if (!player->IsPlayer()) {
  7616. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  7617. return 0;
  7618. }
  7619. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  7620. return 1;
  7621. }
  7622. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  7623. if (!lua_interface)
  7624. return 0;
  7625. Spawn* player = lua_interface->GetSpawn(state);
  7626. int8 level = lua_interface->GetInt8Value(state, 2);
  7627. if (!player) {
  7628. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  7629. return 0;
  7630. }
  7631. if (!player->IsPlayer()) {
  7632. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  7633. return 0;
  7634. }
  7635. if (level == 0) {
  7636. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  7637. return 0;
  7638. }
  7639. Client* client = player->GetZone()->GetClientBySpawn(player);
  7640. if (!client) {
  7641. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  7642. return 0;
  7643. }
  7644. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  7645. client->GetPlayer()->SetXP(1);
  7646. client->GetPlayer()->SetNeededXP();
  7647. return 0;
  7648. }
  7649. int EQ2Emu_lua_AddCoin(lua_State* state) {
  7650. if (!lua_interface)
  7651. return 0;
  7652. Spawn* player = lua_interface->GetSpawn(state);
  7653. int32 amount = lua_interface->GetInt32Value(state, 2);
  7654. if (!player) {
  7655. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  7656. return 0;
  7657. }
  7658. if (!player->IsPlayer()) {
  7659. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  7660. return 0;
  7661. }
  7662. if (amount == 0) {
  7663. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  7664. return 0;
  7665. }
  7666. ((Player*)player)->AddCoins(amount);
  7667. return 0;
  7668. }
  7669. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  7670. if (!lua_interface)
  7671. return 0;
  7672. Spawn* player = lua_interface->GetSpawn(state);
  7673. int32 amount = lua_interface->GetInt32Value(state, 2);
  7674. if (!player) {
  7675. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  7676. return 0;
  7677. }
  7678. if (!player->IsPlayer()) {
  7679. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  7680. return 0;
  7681. }
  7682. if (amount == 0) {
  7683. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  7684. return 0;
  7685. }
  7686. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  7687. return 1;
  7688. }
  7689. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  7690. if (!lua_interface)
  7691. return 0;
  7692. ZoneServer* zone = lua_interface->GetZone(state);
  7693. if (!zone) {
  7694. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  7695. return 0;
  7696. }
  7697. vector<Entity*> players = zone->GetPlayers();
  7698. if (players.size() == 0)
  7699. return 0;
  7700. lua_createtable(state, players.size(), 0);
  7701. int newTable = lua_gettop(state);
  7702. for (int32 i = 0; i < players.size(); i++) {
  7703. lua_interface->SetSpawnValue(state, players.at(i));
  7704. lua_rawseti(state, newTable, i + 1);
  7705. }
  7706. return 1;
  7707. }
  7708. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  7709. if (!lua_interface)
  7710. return 0;
  7711. ZoneServer* zone = lua_interface->GetZone(state, 1);
  7712. if (!zone) {
  7713. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  7714. return 0;
  7715. }
  7716. int32 group_id = lua_interface->GetInt32Value(state, 2);
  7717. //Map of <placement_id, location_id>
  7718. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  7719. map<int32, int32>::iterator itr;
  7720. vector<Spawn*> group;
  7721. for (itr = locs->begin(); itr != locs->end(); itr++) {
  7722. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  7723. if (!location) {
  7724. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  7725. return 0;
  7726. }
  7727. Spawn* spawn = 0;
  7728. if (location->entities[0]) {
  7729. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  7730. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  7731. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  7732. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  7733. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  7734. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  7735. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  7736. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  7737. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  7738. spawn = zone->AddSignSpawn(location, location->entities[0]);
  7739. if (spawn) {
  7740. const char* script = 0;
  7741. for (int x = 0; x < 3; x++) {
  7742. switch (x) {
  7743. case 0:
  7744. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  7745. break;
  7746. case 1:
  7747. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  7748. break;
  7749. case 2:
  7750. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  7751. break;
  7752. }
  7753. if (script && lua_interface->GetSpawnScript(script) != 0) {
  7754. spawn->SetSpawnScript(string(script));
  7755. break;
  7756. }
  7757. }
  7758. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7759. lua_interface->SetSpawnValue(state, spawn);
  7760. group.push_back(spawn);
  7761. }
  7762. else {
  7763. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  7764. safe_delete(spawn);
  7765. }
  7766. }
  7767. }
  7768. if (!group.empty()) {
  7769. lua_createtable(state, group.size(), 0);
  7770. int newTable = lua_gettop(state);
  7771. for (int32 i = 0; i < group.size(); i++) {
  7772. lua_interface->SetSpawnValue(state, group[i]);
  7773. lua_rawseti(state, newTable, i + 1);
  7774. }
  7775. }
  7776. else
  7777. lua_pushnil(state);
  7778. return 1;
  7779. }
  7780. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  7781. if (!lua_interface)
  7782. return 0;
  7783. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  7784. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  7785. int16 leeway = lua_interface->GetInt16Value(state, 3);
  7786. if (!spawn) {
  7787. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  7788. return 0;
  7789. }
  7790. if (anim_id == 0) {
  7791. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  7792. return 0;
  7793. }
  7794. if (leeway == 0)
  7795. leeway = 5000;
  7796. spawn->SetSpawnAnim(anim_id);
  7797. spawn->SetSpawnAnimLeeway(leeway);
  7798. return 0;
  7799. }
  7800. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  7801. if (!lua_interface)
  7802. return 0;
  7803. Spawn* player = lua_interface->GetSpawn(state);
  7804. if (!player) {
  7805. return 0;
  7806. }
  7807. Client* client = player->GetZone()->GetClientBySpawn(player);
  7808. if (!client) {
  7809. return 0;
  7810. }
  7811. lua_interface->SetInt32Value(state, client->GetVersion());
  7812. return 1;
  7813. }
  7814. int EQ2Emu_lua_GetItemID(lua_State* state) {
  7815. if (!lua_interface)
  7816. return 0;
  7817. Item* item = lua_interface->GetItem(state);
  7818. if (!item) {
  7819. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  7820. return 0;
  7821. }
  7822. lua_interface->SetInt32Value(state, item->details.item_id);
  7823. return 1;
  7824. }
  7825. int EQ2Emu_lua_IsEntity(lua_State* state) {
  7826. if (!lua_interface)
  7827. return 0;
  7828. Spawn* spawn = lua_interface->GetSpawn(state);
  7829. if (!spawn) {
  7830. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  7831. return 0;
  7832. }
  7833. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  7834. return 1;
  7835. }
  7836. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  7837. if (!lua_interface)
  7838. return 0;
  7839. Spawn* spawn = lua_interface->GetSpawn(state);
  7840. if (!spawn) {
  7841. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  7842. return 0;
  7843. }
  7844. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  7845. return 1;
  7846. }
  7847. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  7848. if (!lua_interface)
  7849. return 0;
  7850. Spawn* spawn = lua_interface->GetSpawn(state);
  7851. if (!spawn) {
  7852. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  7853. return 0;
  7854. }
  7855. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  7856. return 1;
  7857. }
  7858. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  7859. if (!lua_interface)
  7860. return 0;
  7861. Spawn* spawn = lua_interface->GetSpawn(state);
  7862. if (!spawn) {
  7863. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  7864. return 0;
  7865. }
  7866. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  7867. return 1;
  7868. }
  7869. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  7870. if (!lua_interface)
  7871. return 0;
  7872. Spawn* spawn = lua_interface->GetSpawn(state);
  7873. float pct = lua_interface->GetFloatValue(state, 2);
  7874. if (!spawn) {
  7875. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  7876. return 0;
  7877. }
  7878. if (pct == 0) {
  7879. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  7880. return 0;
  7881. }
  7882. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  7883. lua_interface->SetInt32Value(state, amount);
  7884. return 1;
  7885. }
  7886. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  7887. if (!lua_interface)
  7888. return 0;
  7889. Spawn* spawn = lua_interface->GetSpawn(state);
  7890. float pct = lua_interface->GetFloatValue(state, 2);
  7891. if (!spawn) {
  7892. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  7893. return 0;
  7894. }
  7895. if (pct == 0) {
  7896. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  7897. return 0;
  7898. }
  7899. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  7900. lua_interface->SetInt32Value(state, amount);
  7901. return 1;
  7902. }
  7903. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  7904. if (!lua_interface)
  7905. return 0;
  7906. Spawn* spawn = lua_interface->GetSpawn(state);
  7907. if (!spawn) {
  7908. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  7909. return 0;
  7910. }
  7911. if (!spawn->IsPlayer()) {
  7912. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  7913. return 0;
  7914. }
  7915. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  7916. return 1;
  7917. }
  7918. int EQ2Emu_lua_Evac(lua_State* state) {
  7919. if (!lua_interface)
  7920. return 0;
  7921. Spawn* target = lua_interface->GetSpawn(state);
  7922. if (target) {
  7923. float x = target->GetZone()->GetSafeX();
  7924. float y = target->GetZone()->GetSafeY();
  7925. float z = target->GetZone()->GetSafeZ();
  7926. float h = target->GetZone()->GetSafeHeading();
  7927. target->SetX(x);
  7928. target->SetY(y);
  7929. target->SetZ(z);
  7930. target->SetHeading(h);
  7931. target->SetSpawnOrigX(target->GetX());
  7932. target->SetSpawnOrigY(target->GetY());
  7933. target->SetSpawnOrigZ(target->GetZ());
  7934. target->SetSpawnOrigHeading(target->GetHeading());
  7935. if (target->IsPlayer()) {
  7936. Client* client = target->GetZone()->GetClientBySpawn(target);
  7937. if (client) {
  7938. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  7939. if (packet)
  7940. {
  7941. packet->setDataByName("x", x);
  7942. packet->setDataByName("y", y);
  7943. packet->setDataByName("z", z);
  7944. client->QueuePacket(packet->serialize());
  7945. safe_delete(packet);
  7946. }
  7947. }
  7948. }
  7949. }
  7950. else {
  7951. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7952. ZoneServer* zone = spell->caster->GetZone();
  7953. float x = spell->caster->GetZone()->GetSafeX();
  7954. float y = spell->caster->GetZone()->GetSafeY();
  7955. float z = spell->caster->GetZone()->GetSafeZ();
  7956. float h = spell->caster->GetZone()->GetSafeHeading();
  7957. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7958. for (int32 i = 0; i < spell->targets.size(); i++) {
  7959. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  7960. if (!target2)
  7961. continue;
  7962. target2->SetX(x);
  7963. target2->SetY(y);
  7964. target2->SetZ(z);
  7965. target2->SetHeading(h);
  7966. target2->SetSpawnOrigX(target2->GetX());
  7967. target2->SetSpawnOrigY(target2->GetY());
  7968. target2->SetSpawnOrigZ(target2->GetZ());
  7969. target2->SetSpawnOrigHeading(target2->GetHeading());
  7970. if (target2->IsPlayer()) {
  7971. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  7972. if (client) {
  7973. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  7974. if (packet)
  7975. {
  7976. packet->setDataByName("x", x);
  7977. packet->setDataByName("y", y);
  7978. packet->setDataByName("z", z);
  7979. client->QueuePacket(packet->serialize());
  7980. safe_delete(packet);
  7981. }
  7982. }
  7983. }
  7984. }
  7985. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7986. }
  7987. return 0;
  7988. }
  7989. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  7990. if (!lua_interface)
  7991. return 0;
  7992. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7993. if (!luaspell) {
  7994. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  7995. return 0;
  7996. }
  7997. int8 tier = luaspell->spell->GetSpellTier();
  7998. lua_interface->SetInt32Value(state, tier);
  7999. return 1;
  8000. }
  8001. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8002. if (!lua_interface)
  8003. return 0;
  8004. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8005. if (!luaspell) {
  8006. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8007. return 0;
  8008. }
  8009. int32 spell_id = luaspell->spell->GetSpellID();
  8010. lua_interface->SetInt32Value(state, spell_id);
  8011. return 1;
  8012. }
  8013. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8014. if (!lua_interface)
  8015. return 0;
  8016. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8017. if (!spawn) {
  8018. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8019. return 0;
  8020. }
  8021. if (!spawn->IsPlayer()) {
  8022. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8023. return 0;
  8024. }
  8025. ZoneServer* zone = spawn->GetZone();
  8026. if (!zone) {
  8027. return 0;
  8028. }
  8029. Client* client = zone->GetClientBySpawn(spawn);
  8030. if (!client) {
  8031. return 0;
  8032. }
  8033. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8034. return 0;
  8035. }
  8036. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8037. if (!lua_interface)
  8038. return 0;
  8039. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8040. if (!spawn) {
  8041. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8042. return 0;
  8043. }
  8044. if (!spawn->IsPlayer()) {
  8045. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8046. return 0;
  8047. }
  8048. ZoneServer* zone = spawn->GetZone();
  8049. if (!zone) {
  8050. return 0;
  8051. }
  8052. Client* client = zone->GetClientBySpawn(spawn);
  8053. if (!client) {
  8054. return 0;
  8055. }
  8056. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8057. return 0;
  8058. }
  8059. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8060. if (!lua_interface)
  8061. return 0;
  8062. Spawn* caster = lua_interface->GetSpawn(state);
  8063. Spawn* target = lua_interface->GetSpawn(state, 2);
  8064. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8065. string spell_name = lua_interface->GetStringValue(state, 4);
  8066. if (!caster) {
  8067. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8068. return 0;
  8069. }
  8070. if (!caster->IsEntity()) {
  8071. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8072. return 0;
  8073. }
  8074. if (!target) {
  8075. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8076. return 0;
  8077. }
  8078. if (!target->IsEntity()) {
  8079. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8080. return 0;
  8081. }
  8082. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8083. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8084. return 0;
  8085. }
  8086. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  8087. if (!lua_interface)
  8088. return 0;
  8089. Spawn* spawn = lua_interface->GetSpawn(state);
  8090. Spawn* target = lua_interface->GetSpawn(state, 2);
  8091. if (spawn && target)
  8092. return spawn->CheckLoS(target);
  8093. return 0;
  8094. }
  8095. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  8096. if (!lua_interface)
  8097. return 0;
  8098. Spawn* spawn = lua_interface->GetSpawn(state);
  8099. float x = lua_interface->GetFloatValue(state, 2);
  8100. float y = lua_interface->GetFloatValue(state, 3);
  8101. float z = lua_interface->GetFloatValue(state, 4);
  8102. if (spawn)
  8103. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  8104. return 0;
  8105. }
  8106. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  8107. if (!lua_interface)
  8108. return 0;
  8109. ZoneServer* zone = lua_interface->GetZone(state);
  8110. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  8111. if (zone)
  8112. zone->SetExpansionFlag(xpackFlag);
  8113. return 0;
  8114. }
  8115. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  8116. if (!lua_interface)
  8117. return 0;
  8118. ZoneServer* zone = lua_interface->GetZone(state);
  8119. if (zone) {
  8120. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  8121. return 1;
  8122. }
  8123. return 0;
  8124. }
  8125. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  8126. if (!lua_interface)
  8127. return 0;
  8128. Spawn* spawn = lua_interface->GetSpawn(state);
  8129. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  8130. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  8131. float distance = lua_interface->GetFloatValue(state, 4);
  8132. string in_range_function = lua_interface->GetStringValue(state, 5);
  8133. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  8134. if (spawn && distance > 0 && in_range_function.length() > 0)
  8135. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  8136. return 0;
  8137. }