LuaFunctions.cpp 340 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108
  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. #include <sstream>
  36. #include <boost/algorithm/string.hpp>
  37. extern MasterFactionList master_faction_list;
  38. extern WorldDatabase database;
  39. extern LuaInterface* lua_interface;
  40. extern ConfigReader configReader;
  41. extern MasterQuestList master_quest_list;
  42. extern MasterItemList master_item_list;
  43. extern MasterSpellList master_spell_list;
  44. extern World world;
  45. extern Commands commands;
  46. extern ZoneList zone_list;
  47. extern Races races;
  48. extern Classes classes;
  49. extern Variables variables;
  50. extern MasterSkillList master_skill_list;
  51. extern MasterHeroicOPList master_ho_list;
  52. extern MasterRaceTypeList race_types_list;
  53. extern MasterLanguagesList master_languages_list;
  54. vector<string> ParseString(string strVal, char delim) {
  55. stringstream ss(strVal);
  56. vector<string> ret;
  57. while (ss.good())
  58. {
  59. string substr;
  60. getline(ss, substr, delim);
  61. ret.push_back(substr);
  62. }
  63. return ret;
  64. }
  65. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  66. stringstream ss(strVal);
  67. vector<unsigned int> ret;
  68. while (ss.good())
  69. {
  70. string substr;
  71. getline(ss, substr, delim);
  72. stringstream valss(substr);
  73. unsigned int val = 0;
  74. valss >> val;
  75. ret.push_back(val);
  76. }
  77. return ret;
  78. }
  79. map<string, signed int> ParseStringMap(string strVal, char delim) {
  80. vector<string> pairs = ParseString(strVal, delim);
  81. vector<string>::iterator itr;
  82. map<string, signed int> ret;
  83. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  84. vector<string> keyvaluepair = ParseString(*itr, ':');
  85. if (keyvaluepair.size() == 2) {
  86. stringstream valss(keyvaluepair[1]);
  87. int32 val = 0;
  88. valss >> val;
  89. ret[keyvaluepair[0]] = val;
  90. }
  91. }
  92. return ret;
  93. }
  94. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  95. vector<string> pairs = ParseString(strVal, delim);
  96. vector<string>::iterator itr;
  97. map<unsigned int, unsigned short> ret;
  98. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  99. vector<string> keyvaluepair = ParseString(*itr, ':');
  100. int32 key = 0;
  101. if (keyvaluepair.size() > 0) {
  102. stringstream keyss(keyvaluepair[0]);
  103. keyss >> key;
  104. }
  105. if (keyvaluepair.size() == 1) {
  106. ret[key] = 1;
  107. }
  108. else if (keyvaluepair.size() == 2) {
  109. stringstream valss(keyvaluepair[1]);
  110. unsigned short val = 0;
  111. valss >> val;
  112. ret[key] = val;
  113. }
  114. }
  115. return ret;
  116. }
  117. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  118. vector<string> pairs = ParseString(strVal, delim);
  119. vector<string>::iterator itr;
  120. map<unsigned int, signed int> ret;
  121. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  122. vector<string> keyvaluepair = ParseString(*itr, ':');
  123. int32 key = 0;
  124. if (keyvaluepair.size() > 0) {
  125. stringstream keyss(keyvaluepair[0]);
  126. keyss >> key;
  127. }
  128. if (keyvaluepair.size() == 1) {
  129. ret[key] = 1;
  130. }
  131. else if (keyvaluepair.size() == 2) {
  132. stringstream valss(keyvaluepair[1]);
  133. signed int val = 0;
  134. valss >> val;
  135. ret[key] = val;
  136. }
  137. }
  138. return ret;
  139. }
  140. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  141. if (!lua_interface)
  142. return 0;
  143. Spawn* spawn = lua_interface->GetSpawn(state);
  144. string mp3_string = lua_interface->GetStringValue(state, 2);
  145. string text_string = lua_interface->GetStringValue(state, 3);
  146. string emote_string = lua_interface->GetStringValue(state, 4);
  147. int32 key1 = lua_interface->GetInt32Value(state, 5);
  148. int32 key2 = lua_interface->GetInt32Value(state, 6);
  149. Spawn* player = lua_interface->GetSpawn(state, 7);
  150. int8 language = lua_interface->GetInt8Value(state, 8);
  151. if (spawn) {
  152. const char* mp3 = 0;
  153. const char* text = 0;
  154. const char* emote = 0;
  155. if (mp3_string.length() > 0)
  156. mp3 = mp3_string.c_str();
  157. if (text_string.length() > 0)
  158. text = text_string.c_str();
  159. if (emote_string.length() > 0)
  160. emote = emote_string.c_str();
  161. Client* client = 0;
  162. if (player && player->IsPlayer())
  163. client = spawn->GetZone()->GetClientBySpawn(player);
  164. if (client) {
  165. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  166. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  167. }
  168. else
  169. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  170. }
  171. return 0;
  172. }
  173. int EQ2Emu_lua_PlaySound(lua_State* state) {
  174. if (!lua_interface)
  175. return 0;
  176. Spawn* spawn = lua_interface->GetSpawn(state);
  177. string sound_string = lua_interface->GetStringValue(state, 2);
  178. float x = lua_interface->GetFloatValue(state, 3);
  179. float y = lua_interface->GetFloatValue(state, 4);
  180. float z = lua_interface->GetFloatValue(state, 5);
  181. Spawn* player = lua_interface->GetSpawn(state, 6);
  182. if (spawn && sound_string.length() > 0) {
  183. Client* client = 0;
  184. if (player && player->IsPlayer())
  185. client = spawn->GetZone()->GetClientBySpawn(player);
  186. if (client)
  187. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  188. else
  189. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  190. }
  191. return 0;
  192. }
  193. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  194. if (!lua_interface)
  195. return 0;
  196. Spawn* spawn = lua_interface->GetSpawn(state);
  197. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  198. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  199. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  200. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  201. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  202. if (!spawn) {
  203. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  204. return 0;
  205. }
  206. if (quest_id > 0) {
  207. //Add this quest to the list of required quests for this spawn
  208. spawn->SetQuestsRequired(quest_id, quest_step);
  209. //If private spawn value set
  210. if (private_spawn) {
  211. //Set the spawn to be private when not granted access through this quest
  212. spawn->AddAllowAccessSpawn(spawn);
  213. spawn->SetPrivateQuestSpawn(true);
  214. }
  215. //This value allows access after a quest step, or the whole quest has been completed
  216. if (continued_access)
  217. spawn->SetQuestsRequiredContinuedAccess(true);
  218. //This value will override vis_flags in the vis packet
  219. if (flag_override > 0)
  220. spawn->SetQuestsRequiredOverride(flag_override);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. float max_distance = lua_interface->GetFloatValue(state, 2);
  229. string variable = lua_interface->GetStringValue(state, 3);
  230. string value = lua_interface->GetStringValue(state, 4);
  231. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  232. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  233. return 0;
  234. }
  235. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  236. if (!lua_interface)
  237. return 0;
  238. Client* client = 0;
  239. Spawn* player = lua_interface->GetSpawn(state);
  240. if (!player) {
  241. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  242. return 0;
  243. }
  244. if (!player->IsPlayer()) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  246. return 0;
  247. }
  248. if (player->GetZone())
  249. client = player->GetZone()->GetClientBySpawn(player);
  250. if (!client) {
  251. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  252. return 0;
  253. }
  254. float intensity = lua_interface->GetFloatValue(state, 2);
  255. int8 direction = lua_interface->GetInt8Value(state, 3);
  256. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  257. if (packet) {
  258. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  259. v1 = *(float *)(a1 + 4);
  260. if ( v1 > 0.0 )
  261. v2 = fminf(v1, 1.0);
  262. else
  263. v2 = 0.1;
  264. */
  265. packet->setDataByName("intensity", intensity);
  266. if ( client->GetVersion() > 546 )
  267. packet->setDataByName("direction", direction);
  268. client->QueuePacket(packet->serialize());
  269. safe_delete(packet);
  270. }
  271. return 0;
  272. }
  273. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  274. if (!lua_interface)
  275. return 0;
  276. Spawn* dead = lua_interface->GetSpawn(state);
  277. Spawn* killer = lua_interface->GetSpawn(state, 2);
  278. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  279. if (dead && dead->Alive() && dead->GetZone())
  280. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  281. return 0;
  282. }
  283. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  284. if (!lua_interface)
  285. return 0;
  286. Spawn* spawn = lua_interface->GetSpawn(state);
  287. float max_distance = lua_interface->GetFloatValue(state, 2);
  288. bool include_players = lua_interface->GetInt8Value(state, 3);
  289. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  290. if (max_distance > 0 && spawn && spawn->GetZone())
  291. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  292. return 0;
  293. }
  294. int EQ2Emu_lua_Despawn(lua_State* state) {
  295. if (!lua_interface)
  296. return 0;
  297. Spawn* spawn = lua_interface->GetSpawn(state);
  298. int32 delay = lua_interface->GetInt32Value(state, 2);
  299. if (spawn && spawn->GetZone())
  300. spawn->GetZone()->Despawn(spawn, delay);
  301. return 0;
  302. }
  303. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  304. if (!lua_interface)
  305. return 0;
  306. Spawn* spawn = lua_interface->GetSpawn(state);
  307. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  308. if (spawn) {
  309. spawn->info_changed = true;
  310. spawn->SetShowHandIcon(displayHandIcon);
  311. }
  312. return 0;
  313. }
  314. //this function is used to force an update packet to be sent.
  315. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  316. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  317. if (!lua_interface)
  318. return 0;
  319. Spawn* spawn = lua_interface->GetSpawn(state);
  320. if (spawn) {
  321. spawn->vis_changed = true;
  322. }
  323. return 0;
  324. }
  325. //this function is used to force an update packet to be sent.
  326. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  327. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  328. if (!lua_interface)
  329. return 0;
  330. Spawn* spawn = lua_interface->GetSpawn(state);
  331. if (spawn) {
  332. spawn->info_changed = true;
  333. }
  334. return 0;
  335. }
  336. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  337. if (!lua_interface)
  338. return 0;
  339. Spawn* spawn = lua_interface->GetSpawn(state);
  340. int32 new_state = lua_interface->GetInt32Value(state, 2);
  341. if (spawn) {
  342. spawn->GetZone()->SendStateCommand(spawn, new_state);
  343. }
  344. return 0;
  345. }
  346. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  347. if (!lua_interface)
  348. return 0;
  349. Spawn* spawn = lua_interface->GetSpawn(state);
  350. string variable = lua_interface->GetStringValue(state, 2);
  351. string value = lua_interface->GetStringValue(state, 3);
  352. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  353. bool temporary_flag = lua_interface->GetBooleanValue(state, 5); // default false as originally designed, allow user to set temporary_flag true to not update DB
  354. int32 type = commands.GetSpawnSetType(variable);
  355. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  356. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  357. return 0;
  358. }
  359. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  360. if (!lua_interface)
  361. return 0;
  362. Spawn* spawn = lua_interface->GetSpawn(state);
  363. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  364. if (spawn && spawn_id > 0) {
  365. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  366. if (closest_spawn) {
  367. lua_interface->SetSpawnValue(state, closest_spawn);
  368. return 1;
  369. }
  370. }
  371. return 0;
  372. }
  373. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  374. if (!lua_interface)
  375. return 0;
  376. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  377. int32 position = lua_interface->GetInt32Value(state, 2);
  378. if (spawnList) {
  379. if (spawnList->size() > position) {
  380. lua_interface->SetSpawnValue(state, spawnList->at(position));
  381. return 1;
  382. }
  383. else {
  384. return 0;
  385. }
  386. return spawnList->size();
  387. }
  388. return 0;
  389. }
  390. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  391. if (!lua_interface)
  392. return 0;
  393. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  394. if (spawnList) {
  395. return spawnList->size();
  396. }
  397. return 0;
  398. }
  399. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  400. if (!lua_interface)
  401. return 0;
  402. vector<Spawn*>* spawnList = new vector<Spawn*>();
  403. lua_interface->SetSpawnListValue(state, spawnList);
  404. return 1;
  405. }
  406. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  407. if (!lua_interface)
  408. return 0;
  409. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  410. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  411. if (spawnList) {
  412. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  413. if (it == spawnList->end())
  414. spawnList->push_back(spawn);
  415. }
  416. return 0;
  417. }
  418. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  419. if (!lua_interface)
  420. return 0;
  421. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  422. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  423. if (spawnList) {
  424. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  425. if(it != spawnList->end())
  426. spawnList->erase(it);
  427. }
  428. return 0;
  429. }
  430. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  431. if (!lua_interface)
  432. return 0;
  433. Spawn* spawn = lua_interface->GetSpawn(state);
  434. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  435. if (spawn) {
  436. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  437. if (spawns.size() > 0) {
  438. vector<Spawn*>* spawnList = new vector<Spawn*>();
  439. vector<Spawn*>::iterator itr;
  440. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  441. spawnList->push_back(*itr);
  442. }
  443. lua_interface->SetSpawnListValue(state, spawnList);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. string variable_name = lua_interface->GetStringValue(state);
  453. Variable* var = variables.FindVariable(variable_name);
  454. if (var) {
  455. lua_interface->SetStringValue(state, var->GetValue());
  456. return 1;
  457. }
  458. return 0;
  459. }
  460. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  461. if (!lua_interface)
  462. return 0;
  463. int32 total_coins = lua_interface->GetInt32Value(state);
  464. if (total_coins == 0) {
  465. lua_interface->SetStringValue(state, "0 copper");
  466. return 1;
  467. }
  468. char tmp[64] = { 0 };
  469. string message = "";
  470. int32 val = 0;
  471. if (total_coins >= 1000000) {
  472. val = total_coins / 1000000;
  473. total_coins -= 1000000 * val;
  474. sprintf(tmp, " %u Platinum", val);
  475. message.append(tmp);
  476. memset(tmp, 0, 64);
  477. }
  478. if (total_coins >= 10000) {
  479. val = total_coins / 10000;
  480. total_coins -= 10000 * val;
  481. sprintf(tmp, " %u Gold", val);
  482. message.append(tmp);
  483. memset(tmp, 0, 64);
  484. }
  485. if (total_coins >= 100) {
  486. val = total_coins / 100;
  487. total_coins -= 100 * val;
  488. sprintf(tmp, " %u Silver", val);
  489. message.append(tmp);
  490. memset(tmp, 0, 64);
  491. }
  492. if (total_coins > 0) {
  493. sprintf(tmp, " %u Copper", (int32)total_coins);
  494. message.append(tmp);
  495. }
  496. lua_interface->SetStringValue(state, message.c_str());
  497. return 1;
  498. }
  499. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  500. ZoneServer* zone = lua_interface->GetZone(state);
  501. int32 group_id = lua_interface->GetInt32Value(state, 2);
  502. if (zone) {
  503. Spawn* spawn = zone->GetSpawnGroup(group_id);
  504. if (spawn) {
  505. lua_interface->SetSpawnValue(state, spawn);
  506. return 1;
  507. }
  508. }
  509. return 0;
  510. }
  511. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  512. ZoneServer* zone = lua_interface->GetZone(state);
  513. int32 location_id = lua_interface->GetInt32Value(state, 2);
  514. if (zone) {
  515. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  516. if (spawn) {
  517. lua_interface->SetSpawnValue(state, spawn);
  518. return 1;
  519. }
  520. }
  521. return 0;
  522. }
  523. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  524. Spawn* spawn = lua_interface->GetSpawn(state);
  525. if (spawn) {
  526. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  527. return 1;
  528. }
  529. return 0;
  530. }
  531. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  532. Spawn* spawn = lua_interface->GetSpawn(state);
  533. if (spawn) {
  534. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  535. return 1;
  536. }
  537. return 0;
  538. }
  539. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  540. Spawn* spawn = lua_interface->GetSpawn(state);
  541. if (spawn) {
  542. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  543. return 1;
  544. }
  545. return 0;
  546. }
  547. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  548. Spawn* spawn = lua_interface->GetSpawn(state);
  549. if (spawn) {
  550. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  551. return 1;
  552. }
  553. return 0;
  554. }
  555. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  556. Player* player = (Player*)lua_interface->GetSpawn(state);
  557. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  558. if (player && player->IsPlayer() && faction_id > 0) {
  559. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  560. return 1;
  561. }
  562. return 0;
  563. }
  564. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  565. if (!lua_interface)
  566. return 0;
  567. Spawn* spawn = lua_interface->GetSpawn(state);
  568. int32 value = lua_interface->GetInt32Value(state, 2);
  569. if (spawn) {
  570. spawn->SetFactionID(value);
  571. }
  572. return 0;
  573. }
  574. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  575. Spawn* spawn = lua_interface->GetSpawn(state);
  576. if (spawn) {
  577. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  578. return 1;
  579. }
  580. return 0;
  581. }
  582. int EQ2Emu_lua_GetGender(lua_State* state) {
  583. Spawn* spawn = lua_interface->GetSpawn(state);
  584. if (spawn) {
  585. lua_interface->SetInt32Value(state, spawn->GetGender());
  586. return 1;
  587. }
  588. return 0;
  589. }
  590. int EQ2Emu_lua_GetTarget(lua_State* state) {
  591. Spawn* spawn = lua_interface->GetSpawn(state);
  592. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  593. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  594. return 1;
  595. }
  596. return 0;
  597. }
  598. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  599. if (!lua_interface)
  600. return 0;
  601. Spawn* spawn = lua_interface->GetSpawn(state);
  602. string mp3_string = lua_interface->GetStringValue(state, 2);
  603. int32 key1 = lua_interface->GetInt32Value(state, 3);
  604. int32 key2 = lua_interface->GetInt32Value(state, 4);
  605. Spawn* player = lua_interface->GetSpawn(state, 5);
  606. if (spawn && mp3_string.length() > 0) {
  607. Client* client = 0;
  608. if (player && player->IsPlayer())
  609. client = spawn->GetZone()->GetClientBySpawn(player);
  610. if (client) {
  611. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  612. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  613. }
  614. else
  615. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  616. }
  617. return 0;
  618. }
  619. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  620. if (!lua_interface)
  621. return 0;
  622. Spawn* spawn = lua_interface->GetSpawn(state);
  623. if (spawn) {
  624. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  625. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  626. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  627. return 3;
  628. }
  629. return 0;
  630. }
  631. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  632. if (!lua_interface)
  633. return 0;
  634. Spawn* spawn = lua_interface->GetSpawn(state);
  635. if (spawn) {
  636. int32 item_id = lua_interface->GetInt32Value(state, 2);
  637. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  638. return 1;
  639. }
  640. return 0;
  641. }
  642. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  643. if (!lua_interface)
  644. return 0;
  645. Spawn* spawn = lua_interface->GetSpawn(state);
  646. if (spawn && spawn->IsEntity()) {
  647. int32 item_id = lua_interface->GetInt32Value(state, 2);
  648. int16 charges = lua_interface->GetInt16Value(state, 3);
  649. if (charges == 0)
  650. charges = 1;
  651. ((Entity*)spawn)->AddLootItem(item_id, charges);
  652. }
  653. return 0;
  654. }
  655. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  656. if (!lua_interface)
  657. return 0;
  658. Spawn* spawn = lua_interface->GetSpawn(state);
  659. if (spawn && spawn->IsEntity()) {
  660. int32 item_id = lua_interface->GetInt32Value(state, 2);
  661. spawn->LootItem(item_id);
  662. }
  663. return 0;
  664. }
  665. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  666. if (!lua_interface)
  667. return 0;
  668. Spawn* spawn = lua_interface->GetSpawn(state);
  669. if (spawn) {
  670. int32 val = lua_interface->GetInt32Value(state, 2);
  671. spawn->AddLootCoins(val);
  672. }
  673. return 0;
  674. }
  675. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  676. if (!lua_interface)
  677. return 0;
  678. Spawn* entity = lua_interface->GetSpawn(state);
  679. Spawn* player = lua_interface->GetSpawn(state, 2);
  680. if (entity && player && player->IsPlayer()) {
  681. int32 coins = lua_interface->GetInt32Value(state, 3);
  682. vector<Item*>* items = 0;
  683. int i = 0;
  684. int32 item_id = 0;
  685. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  686. if (items == 0)
  687. items = new vector<Item*>;
  688. if (master_item_list.GetItem(item_id))
  689. items->push_back(master_item_list.GetItem(item_id));
  690. i++;
  691. }
  692. Client* client = 0;
  693. client = player->GetZone()->GetClientBySpawn(player);
  694. if (client)
  695. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  696. if(coins > 0)
  697. entity->AddLootCoins(coins);
  698. safe_delete(items);
  699. }
  700. return 0;
  701. }
  702. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  703. if (!lua_interface)
  704. return 0;
  705. Spawn* entity = lua_interface->GetSpawn(state);
  706. Spawn* player = lua_interface->GetSpawn(state, 2);
  707. int32 item_id = lua_interface->GetInt32Value(state, 3);
  708. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  709. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  710. return 1;
  711. }
  712. return 0;
  713. }
  714. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  715. if (!lua_interface)
  716. return 0;
  717. Spawn* entity = lua_interface->GetSpawn(state);
  718. Spawn* player = lua_interface->GetSpawn(state, 2);
  719. if (entity && player && player->IsPlayer()) {
  720. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  721. return 1;
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  726. if (!lua_interface)
  727. return 0;
  728. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  729. safe_delete(conversation);
  730. conversation = new vector<ConversationOption>();
  731. lua_interface->SetConversationValue(state, conversation);
  732. return 1;
  733. }
  734. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  738. if (conversation) {
  739. ConversationOption conv_option;
  740. conv_option.option = lua_interface->GetStringValue(state, 2);
  741. conv_option.function = lua_interface->GetStringValue(state, 3);
  742. if (conv_option.option.length() > 0)
  743. conversation->push_back(conv_option);
  744. }
  745. return 0;
  746. }
  747. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  748. if (!lua_interface)
  749. return 0;
  750. Spawn* npc = lua_interface->GetSpawn(state);
  751. Spawn* player = lua_interface->GetSpawn(state, 2);
  752. if (npc && player && player->IsPlayer() && player->GetZone()) {
  753. Client* client = player->GetZone()->GetClientBySpawn(player);
  754. if (client) {
  755. int32 conversation_id = client->GetConversationID(npc, 0);
  756. client->CloseDialog(conversation_id);
  757. }
  758. }
  759. return 0;
  760. }
  761. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  762. if (!lua_interface)
  763. return 0;
  764. Item* item = lua_interface->GetItem(state);
  765. Spawn* player = lua_interface->GetSpawn(state, 2);
  766. if (item && player && player->IsPlayer() && player->GetZone()) {
  767. Client* client = player->GetZone()->GetClientBySpawn(player);
  768. if (client) {
  769. int32 conversation_id = client->GetConversationID(0, item);
  770. client->CloseDialog(conversation_id);
  771. }
  772. }
  773. return 0;
  774. }
  775. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  776. if (!lua_interface)
  777. return 0;
  778. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  779. Spawn* spawn = 0;
  780. Item* item = 0;
  781. int8 type = lua_interface->GetInt8Value(state, 2);
  782. if (type == 1 || type == 3)
  783. spawn = lua_interface->GetSpawn(state, 3);
  784. else if (type == 2 || type == 4)
  785. item = lua_interface->GetItem(state, 3);
  786. Spawn* player = lua_interface->GetSpawn(state, 4);
  787. string text = lua_interface->GetStringValue(state, 5);
  788. string mp3 = lua_interface->GetStringValue(state, 6);
  789. int32 key1 = lua_interface->GetInt32Value(state, 7);
  790. int32 key2 = lua_interface->GetInt32Value(state, 8);
  791. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  792. Client* client = player->GetZone()->GetClientBySpawn(player);
  793. if (client) {
  794. if (spawn) {
  795. // Need to do this so the function works the same as it did before
  796. if (type == 1)
  797. type++;
  798. if (mp3.length() > 0)
  799. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  800. else
  801. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  802. }
  803. else {
  804. if (mp3.length() > 0)
  805. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  806. else
  807. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  808. }
  809. }
  810. }
  811. safe_delete(conversation);
  812. lua_interface->SetConversationValue(state, NULL);
  813. return 0;
  814. }
  815. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  816. if(!lua_interface)
  817. return 0;
  818. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  819. Item* item = lua_interface->GetItem(state, 2);
  820. Spawn* player = lua_interface->GetSpawn(state, 3);
  821. string text = lua_interface->GetStringValue(state, 4);
  822. string mp3 = lua_interface->GetStringValue(state, 5);
  823. int32 key1 = lua_interface->GetInt32Value(state, 6);
  824. int32 key2 = lua_interface->GetInt32Value(state, 7);
  825. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  826. Client* client = player->GetZone()->GetClientBySpawn(player);
  827. if(client){
  828. if(mp3.length() > 0)
  829. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  830. else
  831. client->DisplayConversation(item, conversation, (char*)text.c_str());
  832. }
  833. safe_delete(conversation);
  834. }
  835. return 0;
  836. }*/
  837. int EQ2Emu_lua_StartConversation(lua_State* state) {
  838. if (!lua_interface)
  839. return 0;
  840. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  841. Spawn* npc = lua_interface->GetSpawn(state, 2);
  842. Spawn* player = lua_interface->GetSpawn(state, 3);
  843. string text = lua_interface->GetStringValue(state, 4);
  844. string mp3 = lua_interface->GetStringValue(state, 5);
  845. int32 key1 = lua_interface->GetInt32Value(state, 6);
  846. int32 key2 = lua_interface->GetInt32Value(state, 7);
  847. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  848. Client* client = npc->GetZone()->GetClientBySpawn(player);
  849. if (mp3.length() > 0)
  850. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  851. else
  852. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  853. safe_delete(conversation);
  854. lua_interface->SetConversationValue(state, NULL);
  855. }
  856. else
  857. 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);
  858. return 0;
  859. }
  860. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  861. if (!lua_interface)
  862. return 0;
  863. Spawn* spawn = lua_interface->GetSpawn(state);
  864. float distance = lua_interface->GetFloatValue(state, 2);
  865. string in_range_function = lua_interface->GetStringValue(state, 3);
  866. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  867. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  868. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  872. ZoneServer* zone = lua_interface->GetZone(state);
  873. float x = lua_interface->GetFloatValue(state, 2);
  874. float y = lua_interface->GetFloatValue(state, 3);
  875. float z = lua_interface->GetFloatValue(state, 4);
  876. float max_variation = lua_interface->GetFloatValue(state, 5);
  877. string in_range_function = lua_interface->GetStringValue(state, 6);
  878. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  879. if (zone && in_range_function.length() > 0)
  880. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  881. return 0;
  882. }
  883. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  884. if (!lua_interface)
  885. return 0;
  886. Spawn* spawn = lua_interface->GetSpawn(state);
  887. if (spawn && spawn->IsEntity()) {
  888. int32 val = lua_interface->GetInt32Value(state, 2);
  889. ((Entity*)spawn)->SetLootCoins(val);
  890. }
  891. return 0;
  892. }
  893. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  894. if (!lua_interface)
  895. return 0;
  896. Spawn* spawn = lua_interface->GetSpawn(state);
  897. if (spawn && spawn->IsEntity()) {
  898. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  899. return 1;
  900. }
  901. return 0;
  902. }
  903. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  904. if (!lua_interface)
  905. return 0;
  906. Spawn* spawn = lua_interface->GetSpawn(state);
  907. float x = lua_interface->GetFloatValue(state, 2);
  908. float y = lua_interface->GetFloatValue(state, 3);
  909. float z = lua_interface->GetFloatValue(state, 4);
  910. float speed = lua_interface->GetFloatValue(state, 5);
  911. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  912. string function = lua_interface->GetStringValue(state, 7);
  913. if (spawn) {
  914. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  915. spawn->GetZone()->AddMovementNPC(spawn);
  916. }
  917. lua_interface->ResetFunctionStack(state);
  918. return 0;
  919. }
  920. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  921. if (!lua_interface)
  922. return 0;
  923. Spawn* spawn = lua_interface->GetSpawn(state);
  924. if (spawn) {
  925. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  926. return 1;
  927. }
  928. return 0;
  929. }
  930. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  931. if (!lua_interface)
  932. return 0;
  933. Spawn* spawn = lua_interface->GetSpawn(state);
  934. Spawn* target = lua_interface->GetSpawn(state, 2);
  935. if (spawn && target) {
  936. if (spawn->IsEntity())
  937. // ((Entity*)spawn)->FaceTarget(target);
  938. static_cast<Entity*>(spawn)->FaceTarget(target);
  939. }
  940. lua_interface->ResetFunctionStack(state);
  941. return 0;
  942. }
  943. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  944. if (!lua_interface)
  945. return 0;
  946. Spawn* spawn = lua_interface->GetSpawn(state);
  947. float x = lua_interface->GetFloatValue(state, 2);
  948. float y = lua_interface->GetFloatValue(state, 3);
  949. float z = lua_interface->GetFloatValue(state, 4);
  950. float speed = lua_interface->GetFloatValue(state, 5);
  951. string lua_function = lua_interface->GetStringValue(state, 6);
  952. bool more_points = lua_interface->GetBooleanValue(state, 7);
  953. if (spawn) {
  954. if (speed == 0)
  955. speed = spawn->GetSpeed();
  956. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  957. }
  958. lua_interface->ResetFunctionStack(state);
  959. return 0;
  960. }
  961. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  962. if (!lua_interface)
  963. return 0;
  964. Spawn* spawn = lua_interface->GetSpawn(state);
  965. if (spawn) {
  966. spawn->ClearRunningLocations();
  967. }
  968. return 0;
  969. }
  970. int EQ2Emu_lua_Say(lua_State* state) {
  971. if (!lua_interface)
  972. return 0;
  973. Spawn* spawn = lua_interface->GetSpawn(state);
  974. string message = lua_interface->GetStringValue(state, 2);
  975. Spawn* player = lua_interface->GetSpawn(state, 3);
  976. int32 language = lua_interface->GetInt32Value(state, 4);
  977. if (spawn && message.length() > 0) {
  978. Client* client = 0;
  979. if (player && player->IsPlayer())
  980. client = spawn->GetZone()->GetClientBySpawn(player);
  981. if (client)
  982. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  983. else
  984. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  985. }
  986. lua_interface->ResetFunctionStack(state);
  987. return 0;
  988. }
  989. int EQ2Emu_lua_Shout(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. Spawn* spawn = lua_interface->GetSpawn(state);
  993. string message = lua_interface->GetStringValue(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. if (spawn && message.length() > 0) {
  996. Client* client = 0;
  997. if (player && player->IsPlayer())
  998. client = spawn->GetZone()->GetClientBySpawn(player);
  999. if (client)
  1000. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1001. else
  1002. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1003. }
  1004. lua_interface->ResetFunctionStack(state);
  1005. return 0;
  1006. }
  1007. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1008. if (!lua_interface)
  1009. return 0;
  1010. Spawn* spawn = lua_interface->GetSpawn(state);
  1011. string message = lua_interface->GetStringValue(state, 2);
  1012. Spawn* player = lua_interface->GetSpawn(state, 3);
  1013. if (spawn && message.length() > 0) {
  1014. Client* client = 0;
  1015. if (player && player->IsPlayer())
  1016. client = spawn->GetZone()->GetClientBySpawn(player);
  1017. if (client)
  1018. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1019. else
  1020. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1021. }
  1022. lua_interface->ResetFunctionStack(state);
  1023. return 0;
  1024. }
  1025. int EQ2Emu_lua_Emote(lua_State* state) {
  1026. if (!lua_interface)
  1027. return 0;
  1028. Spawn* spawn = lua_interface->GetSpawn(state);
  1029. string message = lua_interface->GetStringValue(state, 2);
  1030. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1031. Spawn* player = lua_interface->GetSpawn(state, 4);
  1032. char* to = 0;
  1033. if (spawn2)
  1034. to = spawn2->GetName();
  1035. if (spawn && message.length() > 0) {
  1036. Client* client = 0;
  1037. if (player && player->IsPlayer())
  1038. client = spawn->GetZone()->GetClientBySpawn(player);
  1039. if (client)
  1040. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1041. else
  1042. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1043. }
  1044. lua_interface->ResetFunctionStack(state);
  1045. return 0;
  1046. }
  1047. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1048. if (!lua_interface)
  1049. return 0;
  1050. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1051. if (!luaspell)
  1052. return 0;
  1053. Spawn* caster = luaspell->caster;
  1054. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1055. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1056. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1057. Spawn* target = lua_interface->GetSpawn(state, 4);
  1058. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1059. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1060. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1061. lua_interface->ResetFunctionStack(state);
  1062. if (caster && caster->IsEntity()) {
  1063. bool success = false;
  1064. luaspell->resisted = false;
  1065. if (target) {
  1066. float distance = caster->GetDistance(target, true);
  1067. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1068. success = true;
  1069. }
  1070. if (luaspell->targets.size() > 0) {
  1071. Spawn* target = 0;
  1072. ZoneServer* zone = luaspell->caster->GetZone();
  1073. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1074. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1075. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1076. float distance = caster->GetDistance(target, true);
  1077. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1078. }
  1079. }
  1080. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1081. success = true;
  1082. }
  1083. if (success) {
  1084. if (caster->GetZone())
  1085. caster->GetZone()->TriggerCharSheetTimer();
  1086. }
  1087. }
  1088. return 0;
  1089. }
  1090. int EQ2Emu_lua_AddItem(lua_State* state) {
  1091. if (!lua_interface)
  1092. return 0;
  1093. Spawn* spawn = lua_interface->GetSpawn(state);
  1094. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1095. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1096. // default of 1 quantity to add
  1097. if (quantity == 0)
  1098. quantity = 1;
  1099. if (spawn && spawn->IsPlayer()) {
  1100. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1101. if (client && item_id > 0) {
  1102. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1103. return 1;
  1104. }
  1105. }
  1106. lua_interface->SetBooleanValue(state, false);
  1107. return 1;
  1108. }
  1109. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1110. if (!lua_interface)
  1111. return 0;
  1112. Spawn* spawn = lua_interface->GetSpawn(state);
  1113. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1114. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1115. string location = lua_interface->GetStringValue(state, 4);
  1116. if (spawn && spawn->IsPlayer()) {
  1117. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1118. if (client && item_id > 0) {
  1119. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1120. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1121. else
  1122. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1123. if (send_messages) {
  1124. Item* item = master_item_list.GetItem(item_id);
  1125. if (item) {
  1126. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1127. string popup_text = "You receive " + item->name;
  1128. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1129. }
  1130. }
  1131. return 1;
  1132. }
  1133. }
  1134. lua_interface->SetBooleanValue(state, false);
  1135. return 1;
  1136. }
  1137. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1138. Spawn* spawn = lua_interface->GetSpawn(state);
  1139. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1140. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1141. // default of 1 to remove
  1142. if (quantity == 0)
  1143. quantity = 1;
  1144. Client* client;
  1145. Item* item;
  1146. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1147. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1148. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1149. if (client->RemoveItem(item, quantity)) {
  1150. lua_interface->SetBooleanValue(state, true);
  1151. return 1;
  1152. }
  1153. }
  1154. }
  1155. }
  1156. lua_interface->SetBooleanValue(state, false);
  1157. return 1;
  1158. }
  1159. int EQ2Emu_lua_HasItem(lua_State* state) {
  1160. Spawn* player = lua_interface->GetSpawn(state);
  1161. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1162. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1163. if (player && player->IsPlayer()) {
  1164. bool hasItem = false;
  1165. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1166. if (!hasItem)
  1167. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1168. lua_interface->SetBooleanValue(state, hasItem);
  1169. return 1;
  1170. }
  1171. lua_interface->SetBooleanValue(state, false);
  1172. return 1;
  1173. }
  1174. int EQ2Emu_lua_Spawn(lua_State* state) {
  1175. if (!lua_interface)
  1176. return 0;
  1177. ZoneServer* zone = lua_interface->GetZone(state);
  1178. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1179. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1180. float x = lua_interface->GetFloatValue(state, 4);
  1181. float y = lua_interface->GetFloatValue(state, 5);
  1182. float z = lua_interface->GetFloatValue(state, 6);
  1183. float heading = lua_interface->GetFloatValue(state, 7);
  1184. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1185. Spawn* spawn = zone->GetSpawn(spawn_id);
  1186. if (!spawn)
  1187. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1188. else {
  1189. spawn->SetX(x);
  1190. spawn->SetZ(z);
  1191. spawn->SetY(y,true,true);
  1192. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1193. spawn->SetHeading(heading);
  1194. if (restricted_npc)
  1195. spawn->AddAllowAccessSpawn(spawn);
  1196. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1197. bool scriptActive = false;
  1198. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1199. scriptActive = true;
  1200. spawn->SetSpawnScript(string(spawn_script));
  1201. }
  1202. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1203. zone->AddSpawn(spawn);
  1204. if (scriptActive) {
  1205. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1206. }
  1207. lua_interface->SetSpawnValue(state, spawn);
  1208. return 1;
  1209. }
  1210. }
  1211. else {
  1212. string output = "Invalid paramaters to LUA Spawn command: \n";
  1213. if (!zone)
  1214. output = output.append("\t").append("Missing zone reference. \n");
  1215. if (spawn_id == 0)
  1216. output = output.append("\t").append("Missing spawn_id.");
  1217. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1218. }
  1219. return 0;
  1220. }
  1221. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1222. if (!lua_interface)
  1223. return 0;
  1224. ZoneServer* zone = lua_interface->GetZone(state);
  1225. if (zone) {
  1226. lua_interface->SetStringValue(state, zone->GetZoneName());
  1227. return 1;
  1228. }
  1229. return 0;
  1230. }
  1231. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1232. if (!lua_interface)
  1233. return 0;
  1234. ZoneServer* zone = lua_interface->GetZone(state);
  1235. if (zone) {
  1236. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1237. return 1;
  1238. }
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_GetZone(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. int32 zone_id = lua_interface->GetInt32Value(state);
  1245. ZoneServer* zone = 0;
  1246. if (zone_id > 0)
  1247. zone = zone_list.Get(zone_id);
  1248. else {
  1249. string zone_name = lua_interface->GetStringValue(state);
  1250. if (zone_name.length() > 0) {
  1251. zone = zone_list.Get(zone_name.c_str());
  1252. }
  1253. else {
  1254. Spawn* spawn = lua_interface->GetSpawn(state);
  1255. if (spawn)
  1256. zone = spawn->GetZone();
  1257. }
  1258. }
  1259. if (zone) {
  1260. lua_interface->SetZoneValue(state, zone);
  1261. return 1;
  1262. }
  1263. return 0;
  1264. }
  1265. int EQ2Emu_lua_AddHate(lua_State* state) {
  1266. Spawn* entity = lua_interface->GetSpawn(state);
  1267. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1268. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1269. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1270. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1271. if (entity && entity->IsEntity() && amount != 0) {
  1272. if (luaspell) {
  1273. ZoneServer* zone = luaspell->caster->GetZone();
  1274. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1275. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1276. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1277. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1278. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1279. if (send_packet)
  1280. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1281. }
  1282. }
  1283. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1284. }
  1285. else if (npc && npc->IsNPC() && npc->GetZone())
  1286. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1287. }
  1288. return 0;
  1289. }
  1290. int EQ2Emu_lua_Zone(lua_State* state) {
  1291. if (!lua_interface)
  1292. return 0;
  1293. ZoneServer* zone = lua_interface->GetZone(state);
  1294. Spawn* player = lua_interface->GetSpawn(state, 2);
  1295. Client* client = 0;
  1296. if (player && player->IsPlayer())
  1297. client = player->GetZone()->GetClientBySpawn(player);
  1298. float x = lua_interface->GetFloatValue(state, 3);
  1299. float y = lua_interface->GetFloatValue(state, 4);
  1300. float z = lua_interface->GetFloatValue(state, 5);
  1301. float heading = lua_interface->GetFloatValue(state, 6);
  1302. if (zone && client) {
  1303. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1304. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1305. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1306. {
  1307. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1308. return 0;
  1309. }
  1310. if (x != 0 || y != 0 || z != 0) {
  1311. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1312. player->SetX(x);
  1313. player->SetY(y);
  1314. player->SetZ(z);
  1315. player->SetHeading(heading);
  1316. client->Zone(zone->GetZoneName(), false);
  1317. }
  1318. else
  1319. client->Zone(zone->GetZoneName());
  1320. }
  1321. else
  1322. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1323. return 0;
  1324. }
  1325. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1326. if (!lua_interface)
  1327. return 0;
  1328. Spawn* spawn = lua_interface->GetSpawn(state);
  1329. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1330. if (spawn && spawn2)
  1331. spawn->AddAllowAccessSpawn(spawn2);
  1332. return 0;
  1333. }
  1334. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1335. if (!lua_interface)
  1336. return 0;
  1337. Spawn* target = lua_interface->GetSpawn(state);
  1338. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1339. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1340. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1341. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1342. if (!target) {
  1343. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1344. return 0;
  1345. }
  1346. if (!target->IsEntity()) {
  1347. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1348. return 0;
  1349. }
  1350. if (spell_id <= 0) {
  1351. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1352. return 0;
  1353. }
  1354. if (caster && !caster->IsEntity()) {
  1355. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1356. return 0;
  1357. }
  1358. if (spell_tier == 0)
  1359. spell_tier = 1;
  1360. if (!caster)
  1361. caster = target;
  1362. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1363. return 0;
  1364. }
  1365. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1366. if (!lua_interface)
  1367. return 0;
  1368. Spawn* target = lua_interface->GetSpawn(state);
  1369. int32 target_id = 0;
  1370. if (target)
  1371. target_id = target->GetID();
  1372. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1373. if (!luaspell)
  1374. return 0;
  1375. Spawn* caster = luaspell->caster;
  1376. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1377. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1378. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1379. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1380. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1381. //lua_interface->ResetFunctionStack(state);
  1382. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1383. vector<int16> faction_req;
  1384. vector<int16> race_req;
  1385. int32 class_req = 0;
  1386. int32 i = 0;
  1387. int8 f = 0;
  1388. int8 r = 0;
  1389. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1390. if (class_id < 100) {
  1391. class_req += pow(2.0, double(class_id - 1));
  1392. }
  1393. else if (class_id > 100 && class_id < 1000) {
  1394. race_req.push_back(class_id);
  1395. r++;
  1396. }
  1397. else {
  1398. faction_req.push_back(class_id);
  1399. f++;
  1400. }
  1401. i++;
  1402. }
  1403. if (caster && caster->IsEntity()) {
  1404. bool race_match = false;
  1405. bool success = false;
  1406. luaspell->resisted = false;
  1407. if (luaspell->initial_target == target_id) {
  1408. int xxx = 0;
  1409. }
  1410. if (luaspell->targets.size() > 0) {
  1411. ZoneServer* zone = luaspell->caster->GetZone();
  1412. Spawn* target = 0;
  1413. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1414. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1415. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1416. if (race_req.size() > 0) {
  1417. for (int8 i = 0; i < race_req.size(); i++) {
  1418. int32 xxx = target->GetLuaRaceId();
  1419. if (target->GetLuaRaceId() == race_req[i]) {
  1420. race_match = true;
  1421. }
  1422. }
  1423. }
  1424. else
  1425. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1426. if (race_match == true) {
  1427. float distance = caster->GetDistance(target, true);
  1428. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1429. }
  1430. }
  1431. }
  1432. success = true;
  1433. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1434. }
  1435. else if (target) {
  1436. //check class and race/faction here
  1437. if (race_req.size() > 0) {
  1438. for (int8 i = 0; i < race_req.size(); i++) {
  1439. if (target->GetLuaRaceId() == race_req[i]) {
  1440. race_match = true;
  1441. }
  1442. }
  1443. }
  1444. else
  1445. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1446. if (race_match == true) {
  1447. float distance = caster->GetDistance(target, true);
  1448. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1449. success = true;
  1450. }
  1451. }
  1452. if (success) {
  1453. Spell* spell = luaspell->spell;
  1454. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1455. ((Player*)caster)->InCombat(true);
  1456. if (caster->GetZone())
  1457. caster->GetZone()->TriggerCharSheetTimer();
  1458. }
  1459. }
  1460. }
  1461. return 0;
  1462. }
  1463. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1464. if (!lua_interface)
  1465. return 0;
  1466. Spawn* spawn = lua_interface->GetSpawn(state);
  1467. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1468. lua_interface->ResetFunctionStack(state);
  1469. if (spawn && value != 0) {
  1470. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1471. spawn->SetPower(spawn->GetTotalPower());
  1472. else
  1473. spawn->SetPower(spawn->GetPower() + value);
  1474. }
  1475. return 0;
  1476. }
  1477. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1478. if (!lua_interface)
  1479. return 0;
  1480. Spawn* spawn = lua_interface->GetSpawn(state);
  1481. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1482. lua_interface->ResetFunctionStack(state);
  1483. if (spawn && value != 0) {
  1484. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1485. spawn->SetHP(spawn->GetTotalHP());
  1486. else
  1487. spawn->SetHP(spawn->GetHP() + value);
  1488. }
  1489. return 0;
  1490. }
  1491. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1492. if (!lua_interface)
  1493. return 0;
  1494. Spawn* spawn = lua_interface->GetSpawn(state);
  1495. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1496. lua_interface->ResetFunctionStack(state);
  1497. if (spawn && value != 0) {
  1498. spawn->SetPower(spawn->GetPower() + value);
  1499. if (value > spawn->GetTotalHPBase())
  1500. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1501. }
  1502. return 0;
  1503. }
  1504. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1505. if (!lua_interface)
  1506. return 0;
  1507. Spawn* spawn = lua_interface->GetSpawn(state);
  1508. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1509. lua_interface->ResetFunctionStack(state);
  1510. if (spawn && value != 0) {
  1511. spawn->SetHP(spawn->GetHP() + value);
  1512. if (value > spawn->GetTotalHPBase())
  1513. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1514. }
  1515. return 0;
  1516. }
  1517. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1518. if (!lua_interface)
  1519. return 0;
  1520. Spawn* spawn = lua_interface->GetSpawn(state);
  1521. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1522. lua_interface->ResetFunctionStack(state);
  1523. if (spawn) {
  1524. spawn->SetHP(value);
  1525. if (value > spawn->GetTotalHPBase())
  1526. spawn->SetTotalHP(value);
  1527. }
  1528. return 0;
  1529. }
  1530. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1531. if (!lua_interface)
  1532. return 0;
  1533. Spawn* spawn = lua_interface->GetSpawn(state);
  1534. float value = lua_interface->GetFloatValue(state, 2);
  1535. lua_interface->ResetFunctionStack(state);
  1536. if (spawn && spawn->IsEntity() && value > 0)
  1537. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1538. if (spawn->IsPlayer())
  1539. ((Player*)spawn)->SetCharSheetChanged(true);
  1540. return 0;
  1541. }
  1542. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1543. if (!lua_interface)
  1544. return 0;
  1545. Spawn* spawn = lua_interface->GetSpawn(state);
  1546. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1547. lua_interface->ResetFunctionStack(state);
  1548. if (spawn && spawn->IsEntity() && value > 0)
  1549. ((Entity*)spawn)->SetTotalHPBase(value);
  1550. return 0;
  1551. }
  1552. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1553. if (!lua_interface)
  1554. return 0;
  1555. Spawn* spawn = lua_interface->GetSpawn(state);
  1556. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1557. lua_interface->ResetFunctionStack(state);
  1558. if (spawn && value > 0) {
  1559. spawn->SetPower(value);
  1560. if (value > spawn->GetTotalPowerBase())
  1561. spawn->SetTotalPower(value);
  1562. }
  1563. return 0;
  1564. }
  1565. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1566. if (!lua_interface)
  1567. return 0;
  1568. Spawn* spawn = lua_interface->GetSpawn(state);
  1569. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1570. lua_interface->ResetFunctionStack(state);
  1571. if (spawn && spawn->IsEntity() && value > 0)
  1572. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1573. return 0;
  1574. }
  1575. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1576. if (!lua_interface)
  1577. return 0;
  1578. Spawn* spawn = lua_interface->GetSpawn(state);
  1579. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1580. lua_interface->ResetFunctionStack(state);
  1581. if (spawn && spawn->IsEntity() && value > 0)
  1582. ((Entity*)spawn)->SetTotalPowerBase(value);
  1583. return 0;
  1584. }
  1585. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1586. if (!lua_interface)
  1587. return 0;
  1588. Spawn* spawn = lua_interface->GetSpawn(state);
  1589. float x = lua_interface->GetFloatValue(state, 2);
  1590. float y = lua_interface->GetFloatValue(state, 3);
  1591. float z = lua_interface->GetFloatValue(state, 4);
  1592. float heading = lua_interface->GetFloatValue(state, 5);
  1593. lua_interface->ResetFunctionStack(state);
  1594. if (spawn) {
  1595. spawn->SetX(x);
  1596. spawn->SetY(y);
  1597. spawn->SetZ(z);
  1598. if (heading != 0)
  1599. spawn->SetHeading(heading);
  1600. spawn->SetSpawnOrigX(spawn->GetX());
  1601. spawn->SetSpawnOrigY(spawn->GetY());
  1602. spawn->SetSpawnOrigZ(spawn->GetZ());
  1603. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1604. if (spawn->IsPlayer()) {
  1605. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1606. if (client) {
  1607. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1608. client->QueuePacket(packet);
  1609. }
  1610. }
  1611. }
  1612. return 0;
  1613. }
  1614. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1615. if (!lua_interface)
  1616. return 0;
  1617. Spawn* spawn = lua_interface->GetSpawn(state);
  1618. float value = lua_interface->GetFloatValue(state, 2);
  1619. lua_interface->ResetFunctionStack(state);
  1620. if (spawn) {
  1621. spawn->SetHeading(value);
  1622. if (spawn->IsPlayer()) {
  1623. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1624. if (client) {
  1625. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1626. client->QueuePacket(packet);
  1627. }
  1628. }
  1629. }
  1630. return 0;
  1631. }
  1632. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1633. if (!lua_interface)
  1634. return 0;
  1635. Spawn* spawn = lua_interface->GetSpawn(state);
  1636. int16 value = lua_interface->GetInt16Value(state, 2);
  1637. lua_interface->ResetFunctionStack(state);
  1638. if (spawn)
  1639. spawn->SetModelType(value);
  1640. return 0;
  1641. }
  1642. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1643. if (!lua_interface)
  1644. return 0;
  1645. Spawn* spawn = lua_interface->GetSpawn(state);
  1646. int8 value = lua_interface->GetInt8Value(state, 2);
  1647. lua_interface->ResetFunctionStack(state);
  1648. if (spawn) {
  1649. if (spawn->IsPlayer())
  1650. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1651. else
  1652. spawn->SetAdventureClass(value);
  1653. }
  1654. return 0;
  1655. }
  1656. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1657. if (!lua_interface)
  1658. return 0;
  1659. Spawn* spawn = lua_interface->GetSpawn(state);
  1660. int8 value = lua_interface->GetInt8Value(state, 2);
  1661. lua_interface->ResetFunctionStack(state);
  1662. if (spawn) {
  1663. spawn->SetTradeskillClass(value);
  1664. if (spawn->IsEntity()) {
  1665. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1666. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1667. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1668. }
  1669. if (spawn->IsPlayer())
  1670. ((Player*)spawn)->SetCharSheetChanged(true);
  1671. }
  1672. return 0;
  1673. }
  1674. int EQ2Emu_lua_SetMount(lua_State* state) {
  1675. if (!lua_interface)
  1676. return 0;
  1677. Spawn* spawn = lua_interface->GetSpawn(state);
  1678. int16 value = lua_interface->GetInt16Value(state, 2);
  1679. if (spawn && spawn->IsEntity()) {
  1680. ((Entity*)spawn)->SetMount(value);
  1681. EQ2_Color color;
  1682. color.red = 255;
  1683. color.green = 255;
  1684. color.blue = 255;
  1685. ((Entity*)spawn)->SetMountColor(&color);
  1686. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1687. }
  1688. return 0;
  1689. }
  1690. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1691. if (!lua_interface)
  1692. return 0;
  1693. Spawn* spawn = lua_interface->GetSpawn(state);
  1694. EQ2_Color mount_color;
  1695. EQ2_Color saddle_color;
  1696. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1697. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1698. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1699. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1700. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1701. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1702. if (spawn && spawn->IsEntity()) {
  1703. ((Entity*)spawn)->SetMountColor(&mount_color);
  1704. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1705. }
  1706. return 0;
  1707. }
  1708. int EQ2Emu_lua_GetMount(lua_State* state) {
  1709. if (!lua_interface)
  1710. return 0;
  1711. Spawn* spawn = lua_interface->GetSpawn(state);
  1712. if (spawn && spawn->IsEntity()) {
  1713. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1714. return 1;
  1715. }
  1716. return 0;
  1717. }
  1718. int EQ2Emu_lua_GetRace(lua_State* state) {
  1719. if (!lua_interface)
  1720. return 0;
  1721. Spawn* spawn = lua_interface->GetSpawn(state);
  1722. if (spawn)
  1723. {
  1724. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1725. lua_interface->SetInt32Value(state, spawn->GetRace());
  1726. return 1;
  1727. }
  1728. return 0;
  1729. }
  1730. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1731. if (!lua_interface)
  1732. return 0;
  1733. Spawn* spawn = lua_interface->GetSpawn(state);
  1734. if (spawn) {
  1735. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1736. return 1;
  1737. }
  1738. return 0;
  1739. }
  1740. int EQ2Emu_lua_GetClass(lua_State* state) {
  1741. Spawn* spawn = lua_interface->GetSpawn(state);
  1742. if (spawn) {
  1743. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1744. return 1;
  1745. }
  1746. return 0;
  1747. }
  1748. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1749. Spawn* spawn = lua_interface->GetSpawn(state);
  1750. if (spawn) {
  1751. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1752. return 1;
  1753. }
  1754. return 0;
  1755. }
  1756. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1757. if (!lua_interface)
  1758. return 0;
  1759. Spawn* spawn = lua_interface->GetSpawn(state);
  1760. float value = lua_interface->GetFloatValue(state, 2);
  1761. lua_interface->ResetFunctionStack(state);
  1762. if (spawn) {
  1763. spawn->SetSpeed(value);
  1764. ((Entity*)spawn)->SetSpeed(value);
  1765. if (spawn->IsPlayer()) {
  1766. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1767. if (client) {
  1768. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1769. if (packet) {
  1770. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1771. packet->setDataByName("speed", value);
  1772. packet->setDataByName("size", 0.51);
  1773. EQ2Packet* app = packet->serialize();
  1774. client->QueuePacket(app);
  1775. safe_delete(packet);
  1776. }
  1777. }
  1778. }
  1779. }
  1780. return 0;
  1781. }
  1782. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1783. if (!lua_interface)
  1784. return 0;
  1785. Spawn* spawn = lua_interface->GetSpawn(state);
  1786. const int16 type = lua_interface->GetInt16Value(state, 2);
  1787. const float value = lua_interface->GetFloatValue(state, 3);
  1788. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1789. int64 class_req = 0;
  1790. int32 class_id = 0;
  1791. vector<int16> faction_req;
  1792. vector<int16> race_req;
  1793. int32 i = 0;
  1794. int8 f = 0;
  1795. int8 r = 0;
  1796. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1797. if (class_id < 100) {
  1798. class_req += pow(2.0, double(class_id - 1));
  1799. }
  1800. else if (class_id > 100 && class_id < 1000) {
  1801. race_req.push_back(class_id);
  1802. r++;
  1803. }
  1804. else {
  1805. faction_req.push_back(class_id);
  1806. f++;
  1807. }
  1808. i++;
  1809. }
  1810. if (value != 0 && type >= 0) {
  1811. if (luaspell && luaspell->spell && luaspell->caster) {
  1812. ZoneServer* zone = luaspell->caster->GetZone();
  1813. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1814. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1815. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1816. if (target) {
  1817. if (target->IsPlayer()) {
  1818. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1819. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1820. if (((Player*)target)->GetGroupMemberInfo())
  1821. ((Player*)target)->UpdateGroupMemberInfo();
  1822. ((Player*)target)->SetCharSheetChanged(true);
  1823. }
  1824. else if (target->IsNPC())
  1825. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1826. else
  1827. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1828. }
  1829. }
  1830. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1831. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1832. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1833. }
  1834. else if (spawn && spawn->IsEntity()) {
  1835. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1836. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1837. if (spawn->IsPlayer())
  1838. ((Player*)spawn)->SetCharSheetChanged(true);
  1839. }
  1840. else
  1841. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1842. }
  1843. else
  1844. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1845. return 0;
  1846. }
  1847. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1848. if (!lua_interface)
  1849. return 0;
  1850. Spawn* spawn = lua_interface->GetSpawn(state);
  1851. int16 type = lua_interface->GetInt16Value(state, 2);
  1852. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1853. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1854. if (!spawn) {
  1855. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1856. return 0;
  1857. }
  1858. if (!spawn->IsEntity()) {
  1859. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1860. return 0;
  1861. }
  1862. if (value == 0) {
  1863. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1864. return 0;
  1865. }
  1866. if (!luaspell || !luaspell->spell) {
  1867. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1868. return 0;
  1869. }
  1870. int32 class_req = 0;
  1871. vector<int16> faction_req;
  1872. vector<int16> race_req;
  1873. int32 class_id = 0;
  1874. int32 i = 0;
  1875. int8 f = 0;
  1876. int8 r = 0;
  1877. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1878. if (class_id < 100) {
  1879. class_req += pow(2.0, double(class_id - 1));
  1880. }
  1881. else if (class_id > 100 && class_id < 1000) {
  1882. race_req.push_back(class_id);
  1883. r++;
  1884. }
  1885. else {
  1886. faction_req.push_back(class_id);
  1887. f++;
  1888. }
  1889. i++;
  1890. }
  1891. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1892. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1893. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1894. if (spawn->IsPlayer())
  1895. ((Player*)spawn)->SetCharSheetChanged(true);
  1896. return 0;
  1897. }
  1898. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1899. if (!lua_interface)
  1900. return 0;
  1901. Spawn* spawn = lua_interface->GetSpawn(state);
  1902. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1903. if (luaspell && luaspell->spell) {
  1904. ZoneServer* zone = luaspell->caster->GetZone();
  1905. Spawn* target = 0;
  1906. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1907. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1908. target = zone->GetSpawnByID(luaspell->targets[i]);
  1909. if (target && target->IsEntity()) {
  1910. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1911. if (target->IsPlayer())
  1912. ((Player*)target)->SetCharSheetChanged(true);
  1913. }
  1914. }
  1915. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1916. }
  1917. else if (spawn && spawn->IsEntity()) {
  1918. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1919. if (spawn->IsPlayer())
  1920. ((Player*)spawn)->SetCharSheetChanged(true);
  1921. }
  1922. return 0;
  1923. }
  1924. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1925. if (!lua_interface)
  1926. return 0;
  1927. Spawn* spawn = lua_interface->GetSpawn(state);
  1928. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1929. float value = lua_interface->GetFloatValue(state, 3);
  1930. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1931. if (value != 0) {
  1932. int32 spell_id = 0;
  1933. if (luaspell && luaspell->spell && luaspell->caster) {
  1934. spell_id = luaspell->spell->GetSpellID();
  1935. ZoneServer* zone = luaspell->caster->GetZone();
  1936. Spawn* target = 0;
  1937. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1938. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1939. target = zone->GetSpawnByID(luaspell->targets[i]);
  1940. if (target && target->Alive()) {
  1941. if (target->IsPlayer()) {
  1942. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1943. Client* client = target->GetZone()->GetClientBySpawn(target);
  1944. if (client) {
  1945. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1946. if (packet)
  1947. client->QueuePacket(packet);
  1948. }
  1949. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1950. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1951. }
  1952. else if (target->IsNPC()) {
  1953. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1954. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1955. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1956. }
  1957. else
  1958. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1959. }
  1960. }
  1961. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1962. }
  1963. else if (spawn) {
  1964. if (spawn->IsPlayer()) {
  1965. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1966. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1967. if (client) {
  1968. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1969. if (packet)
  1970. client->QueuePacket(packet);
  1971. }
  1972. }
  1973. else if (spawn->IsNPC())
  1974. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1975. else
  1976. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1977. }
  1978. }
  1979. else
  1980. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1981. return 0;
  1982. }
  1983. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1984. if (!lua_interface)
  1985. return 0;
  1986. Spawn* spawn = lua_interface->GetSpawn(state);
  1987. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1988. if (spawn && spawn->IsPlayer()) {
  1989. int32 spell_id = 0;
  1990. if (luaspell && luaspell->spell) {
  1991. spell_id = luaspell->spell->GetSpellID();
  1992. ZoneServer* zone = luaspell->caster->GetZone();
  1993. Spawn* target = 0;
  1994. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1995. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1996. target = zone->GetSpawnByID(luaspell->targets[i]);
  1997. if (target) {
  1998. if (target->IsPlayer()) {
  1999. ((Player*)target)->RemoveSkillBonus(spell_id);
  2000. Client* client = target->GetZone()->GetClientBySpawn(target);
  2001. if (client) {
  2002. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2003. if (packet)
  2004. client->QueuePacket(packet);
  2005. }
  2006. }
  2007. else if (target->IsNPC())
  2008. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2009. else
  2010. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2011. }
  2012. }
  2013. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2014. }
  2015. else if (spawn) {
  2016. if (spawn->IsPlayer()) {
  2017. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2018. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2019. if (client) {
  2020. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2021. if (packet)
  2022. client->QueuePacket(packet);
  2023. }
  2024. }
  2025. else if (spawn->IsNPC())
  2026. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2027. else
  2028. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2029. }
  2030. }
  2031. return 0;
  2032. }
  2033. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2034. if (!lua_interface)
  2035. return 0;
  2036. Spawn* spawn = lua_interface->GetSpawn(state);
  2037. int8 type = lua_interface->GetInt32Value(state, 2);
  2038. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2039. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2040. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2041. ZoneServer* zone = luaspell->caster->GetZone();
  2042. Spawn* target = 0;
  2043. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2044. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2045. target = zone->GetSpawnByID(luaspell->targets[i]);
  2046. if (target && target->IsEntity()) {
  2047. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2048. ((Entity*)target)->AddMezSpell(luaspell);
  2049. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2050. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2051. if (target->IsNPC())
  2052. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2053. }
  2054. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2055. ((Entity*)target)->AddStifleSpell(luaspell);
  2056. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2057. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2058. if (target->IsNPC())
  2059. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2060. }
  2061. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2062. ((Entity*)target)->AddDazeSpell(luaspell);
  2063. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2064. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2065. if (target->IsNPC())
  2066. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2067. }
  2068. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2069. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2070. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2071. ((Entity*)target)->AddStunSpell(luaspell);
  2072. if (target->IsNPC())
  2073. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2074. }
  2075. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2076. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2077. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2078. ((Entity*)target)->AddRootSpell(luaspell);
  2079. if (target->IsNPC())
  2080. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2081. }
  2082. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2083. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2084. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2085. ((Entity*)target)->AddFearSpell(luaspell);
  2086. if (target->IsNPC())
  2087. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2088. }
  2089. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2090. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2091. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2092. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2093. }
  2094. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2095. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2096. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2097. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2098. }
  2099. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2100. ((Entity*)target)->AddSnareSpell(luaspell);
  2101. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2102. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2103. if (target->IsNPC())
  2104. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2105. }
  2106. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2107. ((Entity*)target)->AddFlightSpell(luaspell);
  2108. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2109. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2110. }
  2111. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2112. ((Entity*)target)->AddGlideSpell(luaspell);
  2113. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2114. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2115. }
  2116. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2117. ((Entity*)target)->AddSafefallSpell(luaspell);
  2118. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2119. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2120. }
  2121. else
  2122. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2123. }
  2124. else
  2125. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2126. }
  2127. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2128. }
  2129. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2130. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2131. ((Entity*)spawn)->AddMezSpell(luaspell);
  2132. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2133. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2134. }
  2135. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2136. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2137. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2138. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2139. }
  2140. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2141. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2142. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2143. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2144. }
  2145. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2146. ((Entity*)spawn)->AddStunSpell(luaspell);
  2147. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2148. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2149. }
  2150. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2151. ((Entity*)spawn)->AddRootSpell(luaspell);
  2152. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2153. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2154. }
  2155. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2156. ((Entity*)spawn)->AddFearSpell(luaspell);
  2157. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2158. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2159. }
  2160. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2161. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2162. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2163. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2164. }
  2165. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2166. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2167. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2168. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2169. }
  2170. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2171. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2172. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2173. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2174. }
  2175. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2176. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2177. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2178. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2179. }
  2180. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2181. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2182. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2183. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2184. }
  2185. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2186. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2187. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2188. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2189. }
  2190. else
  2191. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2192. }
  2193. else
  2194. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2195. return 0;
  2196. }
  2197. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2198. if (!lua_interface)
  2199. return 0;
  2200. Spawn* spawn = lua_interface->GetSpawn(state);
  2201. int8 type = lua_interface->GetInt8Value(state, 2);
  2202. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2203. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2204. if (spawn && spawn->IsEntity()) {
  2205. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2206. ZoneServer* zone = luaspell->caster->GetZone();
  2207. Spawn* target = 0;
  2208. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2209. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2210. target = zone->GetSpawnByID(luaspell->targets[i]);
  2211. if (target) {
  2212. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2213. ((Entity*)target)->RemoveMezSpell(luaspell);
  2214. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2215. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2216. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2217. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2218. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2219. ((Entity*)target)->RemoveStunSpell(luaspell);
  2220. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2221. ((Entity*)target)->RemoveRootSpell(luaspell);
  2222. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2223. ((Entity*)target)->RemoveFearSpell(luaspell);
  2224. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2225. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2226. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2227. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2228. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2229. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2230. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2231. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2232. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2233. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2234. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2235. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2236. else
  2237. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2238. }
  2239. }
  2240. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2241. }
  2242. else if (only_remove_spawn) {
  2243. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2244. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2245. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2246. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2247. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2248. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2249. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2250. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2251. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2252. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2253. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2254. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2255. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2256. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2257. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2258. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2259. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2260. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2261. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2262. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2263. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2264. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2265. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2266. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2267. else
  2268. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2269. }
  2270. }
  2271. return 0;
  2272. }
  2273. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2274. if (!lua_interface)
  2275. return 0;
  2276. Spawn* spawn = lua_interface->GetSpawn(state);
  2277. int8 type = lua_interface->GetInt8Value(state, 2);
  2278. bool hasEffect = false;
  2279. if (!spawn)
  2280. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2281. else if (!spawn->IsEntity())
  2282. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2283. else if (type < CONTROL_MAX_EFFECTS)
  2284. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2285. else
  2286. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2287. lua_interface->SetBooleanValue(state, hasEffect);
  2288. return 1;
  2289. }
  2290. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2291. if (!lua_interface)
  2292. return 0;
  2293. Spawn* spawn = lua_interface->GetSpawn(state);
  2294. float distance = 0.0f;
  2295. if (!spawn)
  2296. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2297. else if (!spawn->IsNPC())
  2298. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2299. else
  2300. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2301. lua_interface->SetFloatValue(state, distance);
  2302. return 1;
  2303. }
  2304. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2305. if (!lua_interface)
  2306. return 0;
  2307. Spawn* spawn = lua_interface->GetSpawn(state);
  2308. float distance = 0.0f;
  2309. if (!spawn)
  2310. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2311. else if (!spawn->IsNPC())
  2312. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2313. else
  2314. distance = ((NPC*)spawn)->GetAggroRadius();
  2315. lua_interface->SetFloatValue(state, distance);
  2316. return 1;
  2317. }
  2318. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2319. if (!lua_interface)
  2320. return 0;
  2321. Spawn* spawn = lua_interface->GetSpawn(state);
  2322. float distance = lua_interface->GetFloatValue(state, 2);
  2323. bool override = lua_interface->GetBooleanValue(state, 3);
  2324. bool result = false;
  2325. lua_interface->ResetFunctionStack(state);
  2326. if (!spawn)
  2327. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2328. else if (!spawn->IsNPC())
  2329. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2330. else
  2331. {
  2332. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2333. result = true;
  2334. }
  2335. lua_interface->SetBooleanValue(state, result);
  2336. return 1;
  2337. }
  2338. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2339. if (!lua_interface)
  2340. return 0;
  2341. Spawn* spawn = lua_interface->GetSpawn(state);
  2342. int16 value = lua_interface->GetInt16Value(state, 2);
  2343. if (spawn && spawn->IsEntity()) {
  2344. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2345. if (spawn->IsPlayer())
  2346. ((Player*)spawn)->SetCharSheetChanged(true);
  2347. }
  2348. return 0;
  2349. }
  2350. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2351. if (!lua_interface)
  2352. return 0;
  2353. Spawn* spawn = lua_interface->GetSpawn(state);
  2354. int16 value = lua_interface->GetInt16Value(state, 2);
  2355. if (spawn && spawn->IsEntity()) {
  2356. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2357. if (spawn->IsPlayer())
  2358. ((Player*)spawn)->SetCharSheetChanged(true);
  2359. }
  2360. return 0;
  2361. }
  2362. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2363. if (!lua_interface)
  2364. return 0;
  2365. Spawn* spawn = lua_interface->GetSpawn(state);
  2366. int16 value = lua_interface->GetInt16Value(state, 2);
  2367. if (spawn && spawn->IsEntity()) {
  2368. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2369. if (spawn->IsPlayer())
  2370. ((Player*)spawn)->SetCharSheetChanged(true);
  2371. }
  2372. return 0;
  2373. }
  2374. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2375. if (!lua_interface)
  2376. return 0;
  2377. Spawn* spawn = lua_interface->GetSpawn(state);
  2378. int16 value = lua_interface->GetInt16Value(state, 2);
  2379. if (spawn && spawn->IsEntity()) {
  2380. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2381. if (spawn->IsPlayer())
  2382. ((Player*)spawn)->SetCharSheetChanged(true);
  2383. }
  2384. return 0;
  2385. }
  2386. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2387. if (!lua_interface)
  2388. return 0;
  2389. Spawn* spawn = lua_interface->GetSpawn(state);
  2390. int16 value = lua_interface->GetInt16Value(state, 2);
  2391. if (spawn && spawn->IsEntity()) {
  2392. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2393. if (spawn->IsPlayer())
  2394. ((Player*)spawn)->SetCharSheetChanged(true);
  2395. }
  2396. return 0;
  2397. }
  2398. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2399. if (!lua_interface)
  2400. return 0;
  2401. Spawn* spawn = lua_interface->GetSpawn(state);
  2402. int8 value = lua_interface->GetInt8Value(state, 2);
  2403. if (spawn && spawn->IsEntity()) {
  2404. ((Entity*)spawn)->SetDeity(value);
  2405. if (spawn->IsPlayer())
  2406. ((Player*)spawn)->SetCharSheetChanged(true);
  2407. }
  2408. lua_interface->ResetFunctionStack(state);
  2409. return 0;
  2410. }
  2411. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2412. if (!lua_interface)
  2413. return 0;
  2414. Spawn* spawn = lua_interface->GetSpawn(state);
  2415. if (spawn && spawn->IsEntity()) {
  2416. int8 deity = ((Entity*)spawn)->GetDeity();
  2417. lua_interface->SetInt32Value(state, deity);
  2418. return 1;
  2419. }
  2420. return 0;
  2421. }
  2422. int EQ2Emu_lua_SetInt(lua_State* state) {
  2423. if (!lua_interface)
  2424. return 0;
  2425. Spawn* spawn = lua_interface->GetSpawn(state);
  2426. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2427. if (spawn && spawn->IsEntity()) {
  2428. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2429. if (spawn->IsPlayer())
  2430. ((Player*)spawn)->SetCharSheetChanged(true);
  2431. }
  2432. return 0;
  2433. }
  2434. int EQ2Emu_lua_SetWis(lua_State* state) {
  2435. if (!lua_interface)
  2436. return 0;
  2437. Spawn* spawn = lua_interface->GetSpawn(state);
  2438. float value = lua_interface->GetFloatValue(state, 2);
  2439. if (spawn && spawn->IsEntity()) {
  2440. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2441. if (spawn->IsPlayer())
  2442. ((Player*)spawn)->SetCharSheetChanged(true);
  2443. }
  2444. return 0;
  2445. }
  2446. int EQ2Emu_lua_SetSta(lua_State* state) {
  2447. if (!lua_interface)
  2448. return 0;
  2449. Spawn* spawn = lua_interface->GetSpawn(state);
  2450. float value = lua_interface->GetFloatValue(state, 2);
  2451. if (spawn && spawn->IsEntity()) {
  2452. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2453. if (spawn->IsPlayer())
  2454. ((Player*)spawn)->SetCharSheetChanged(true);
  2455. }
  2456. return 0;
  2457. }
  2458. int EQ2Emu_lua_SetStr(lua_State* state) {
  2459. if (!lua_interface)
  2460. return 0;
  2461. Spawn* spawn = lua_interface->GetSpawn(state);
  2462. float value = lua_interface->GetFloatValue(state, 2);
  2463. if (spawn && spawn->IsEntity()) {
  2464. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2465. if (spawn->IsPlayer())
  2466. ((Player*)spawn)->SetCharSheetChanged(true);
  2467. }
  2468. return 0;
  2469. }
  2470. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2471. if (!lua_interface)
  2472. return 0;
  2473. Spawn* spawn = lua_interface->GetSpawn(state);
  2474. float value = lua_interface->GetFloatValue(state, 2);
  2475. if (spawn && spawn->IsEntity()) {
  2476. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2477. if (spawn->IsPlayer())
  2478. ((Player*)spawn)->SetCharSheetChanged(true);
  2479. }
  2480. return 0;
  2481. }
  2482. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2483. if (!lua_interface)
  2484. return 0;
  2485. Spawn* spawn = lua_interface->GetSpawn(state);
  2486. if (spawn) {
  2487. lua_interface->SetInt32Value(state, spawn->GetHP());
  2488. return 1;
  2489. }
  2490. return 0;
  2491. }
  2492. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2493. if (!lua_interface)
  2494. return 0;
  2495. Spawn* spawn = lua_interface->GetSpawn(state);
  2496. if (spawn) {
  2497. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2498. return 1;
  2499. }
  2500. return 0;
  2501. }
  2502. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2503. if (!lua_interface)
  2504. return 0;
  2505. Spawn* spawn = lua_interface->GetSpawn(state);
  2506. if (spawn) {
  2507. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2508. return 1;
  2509. }
  2510. return 0;
  2511. }
  2512. int EQ2Emu_lua_GetName(lua_State* state) {
  2513. if (!lua_interface)
  2514. return 0;
  2515. Spawn* spawn = lua_interface->GetSpawn(state);
  2516. if (spawn) {
  2517. lua_interface->SetStringValue(state, spawn->GetName());
  2518. return 1;
  2519. }
  2520. return 0;
  2521. }
  2522. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2523. Spawn* spawn = lua_interface->GetSpawn(state);
  2524. if (spawn) {
  2525. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2526. return 1;
  2527. }
  2528. return 0;
  2529. }
  2530. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2531. if (!lua_interface)
  2532. return 0;
  2533. Spawn* spawn = lua_interface->GetSpawn(state);
  2534. if (spawn) {
  2535. lua_interface->SetInt32Value(state, spawn->GetPower());
  2536. return 1;
  2537. }
  2538. return 0;
  2539. }
  2540. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2541. if (!lua_interface)
  2542. return 0;
  2543. Spawn* spawn = lua_interface->GetSpawn(state);
  2544. if (spawn) {
  2545. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2546. return 1;
  2547. }
  2548. return 0;
  2549. }
  2550. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2551. if (!lua_interface)
  2552. return 0;
  2553. Spawn* spawn = lua_interface->GetSpawn(state);
  2554. if (spawn) {
  2555. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2556. return 1;
  2557. }
  2558. return 0;
  2559. }
  2560. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2561. if (!lua_interface)
  2562. return 0;
  2563. Spawn* spawn = lua_interface->GetSpawn(state);
  2564. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2565. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2566. if (spawn && spawn2) {
  2567. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2568. lua_interface->SetFloatValue(state, distance);
  2569. return 1;
  2570. }
  2571. return 0;
  2572. }
  2573. int EQ2Emu_lua_GetX(lua_State* state) {
  2574. if (!lua_interface)
  2575. return 0;
  2576. Spawn* spawn = lua_interface->GetSpawn(state);
  2577. if (spawn) {
  2578. lua_interface->SetFloatValue(state, spawn->GetX());
  2579. return 1;
  2580. }
  2581. return 0;
  2582. }
  2583. int EQ2Emu_lua_GetY(lua_State* state) {
  2584. if (!lua_interface)
  2585. return 0;
  2586. Spawn* spawn = lua_interface->GetSpawn(state);
  2587. if (spawn) {
  2588. lua_interface->SetFloatValue(state, spawn->GetY());
  2589. return 1;
  2590. }
  2591. return 0;
  2592. }
  2593. int EQ2Emu_lua_GetZ(lua_State* state) {
  2594. if (!lua_interface)
  2595. return 0;
  2596. Spawn* spawn = lua_interface->GetSpawn(state);
  2597. if (spawn) {
  2598. lua_interface->SetFloatValue(state, spawn->GetZ());
  2599. return 1;
  2600. }
  2601. return 0;
  2602. }
  2603. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2604. if (!lua_interface)
  2605. return 0;
  2606. Spawn* spawn = lua_interface->GetSpawn(state);
  2607. if (spawn) {
  2608. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2609. return 1;
  2610. }
  2611. return 0;
  2612. }
  2613. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2614. if (!lua_interface)
  2615. return 0;
  2616. Spawn* spawn = lua_interface->GetSpawn(state);
  2617. if (spawn) {
  2618. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2619. return 1;
  2620. }
  2621. return 0;
  2622. }
  2623. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2624. if (!lua_interface)
  2625. return 0;
  2626. Spawn* spawn = lua_interface->GetSpawn(state);
  2627. if (spawn) {
  2628. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2629. return 1;
  2630. }
  2631. return 0;
  2632. }
  2633. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2634. if (!lua_interface)
  2635. return 0;
  2636. Spawn* spawn = lua_interface->GetSpawn(state);
  2637. if (spawn && spawn->IsEntity()) {
  2638. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2639. return 1;
  2640. }
  2641. return 0;
  2642. }
  2643. int EQ2Emu_lua_GetInt(lua_State* state) {
  2644. if (!lua_interface)
  2645. return 0;
  2646. Spawn* spawn = lua_interface->GetSpawn(state);
  2647. if (spawn && spawn->IsEntity()) {
  2648. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2649. return 1;
  2650. }
  2651. return 0;
  2652. }
  2653. int EQ2Emu_lua_GetWis(lua_State* state) {
  2654. if (!lua_interface)
  2655. return 0;
  2656. Spawn* spawn = lua_interface->GetSpawn(state);
  2657. if (spawn && spawn->IsEntity()) {
  2658. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2659. return 1;
  2660. }
  2661. return 0;
  2662. }
  2663. int EQ2Emu_lua_GetSta(lua_State* state) {
  2664. if (!lua_interface)
  2665. return 0;
  2666. Spawn* spawn = lua_interface->GetSpawn(state);
  2667. if (spawn && spawn->IsEntity()) {
  2668. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2669. return 1;
  2670. }
  2671. return 0;
  2672. }
  2673. int EQ2Emu_lua_GetStr(lua_State* state) {
  2674. if (!lua_interface)
  2675. return 0;
  2676. Spawn* spawn = lua_interface->GetSpawn(state);
  2677. if (spawn && spawn->IsEntity()) {
  2678. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2679. return 1;
  2680. }
  2681. return 0;
  2682. }
  2683. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2684. if (!lua_interface)
  2685. return 0;
  2686. Spawn* spawn = lua_interface->GetSpawn(state);
  2687. if (spawn && spawn->IsEntity()) {
  2688. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2689. return 1;
  2690. }
  2691. return 0;
  2692. }
  2693. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2694. if (!lua_interface)
  2695. return 0;
  2696. Spawn* spawn = lua_interface->GetSpawn(state);
  2697. if (spawn && spawn->IsEntity()) {
  2698. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2699. return 1;
  2700. }
  2701. return 0;
  2702. }
  2703. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2704. if (!lua_interface)
  2705. return 0;
  2706. Spawn* spawn = lua_interface->GetSpawn(state);
  2707. if (spawn && spawn->IsEntity()) {
  2708. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2709. return 1;
  2710. }
  2711. return 0;
  2712. }
  2713. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2714. if (!lua_interface)
  2715. return 0;
  2716. Spawn* spawn = lua_interface->GetSpawn(state);
  2717. if (spawn && spawn->IsEntity()) {
  2718. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2719. return 1;
  2720. }
  2721. return 0;
  2722. }
  2723. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2724. if (!lua_interface)
  2725. return 0;
  2726. Spawn* spawn = lua_interface->GetSpawn(state);
  2727. if (spawn && spawn->IsEntity()) {
  2728. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2729. return 1;
  2730. }
  2731. return 0;
  2732. }
  2733. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2734. if (!lua_interface)
  2735. return 0;
  2736. Spawn* spawn = lua_interface->GetSpawn(state);
  2737. if (spawn && spawn->IsEntity()) {
  2738. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2739. return 1;
  2740. }
  2741. return 0;
  2742. }
  2743. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2744. if (!lua_interface)
  2745. return 0;
  2746. Spawn* player = lua_interface->GetSpawn(state);
  2747. if (!player || !player->IsPlayer()) {
  2748. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2749. return 0;
  2750. }
  2751. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2752. if (quest_id <= 0) {
  2753. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2754. return 0;
  2755. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2756. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2757. return 0;
  2758. }
  2759. int32 step = lua_interface->GetInt32Value(state, 3);
  2760. if (step > 0) {
  2761. Client* client = player->GetZone()->GetClientBySpawn(player);
  2762. if (client)
  2763. client->AddPendingQuestUpdate(quest_id, step);
  2764. } else {
  2765. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2766. }
  2767. return 0;
  2768. }
  2769. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2770. Spawn* player = lua_interface->GetSpawn(state);
  2771. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2772. int32 step = lua_interface->GetInt32Value(state, 3);
  2773. int32 progress = lua_interface->GetInt32Value(state, 4);
  2774. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2775. Client* client = player->GetZone()->GetClientBySpawn(player);
  2776. if (client)
  2777. client->AddPendingQuestUpdate(quest_id, step, progress);
  2778. }
  2779. return 0;
  2780. }
  2781. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2782. if (!lua_interface)
  2783. return 0;
  2784. Spawn* player = lua_interface->GetSpawn(state);
  2785. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2786. if (player && player->IsPlayer() && quest_id > 0) {
  2787. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2788. return 1;
  2789. }
  2790. return 0;
  2791. }
  2792. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2793. if (!lua_interface)
  2794. return 0;
  2795. Spawn* player = lua_interface->GetSpawn(state);
  2796. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2797. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2798. if (player && player->IsPlayer() && quest_id > 0) {
  2799. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2800. return 1;
  2801. }
  2802. return 0;
  2803. }
  2804. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2805. if (!lua_interface)
  2806. return 0;
  2807. Spawn* player = lua_interface->GetSpawn(state);
  2808. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2809. if (player && player->IsPlayer() && quest_id > 0) {
  2810. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2811. return 1;
  2812. }
  2813. return 0;
  2814. }
  2815. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2816. if (!lua_interface)
  2817. return 0;
  2818. Quest* quest = lua_interface->GetQuest(state);
  2819. string name = lua_interface->GetStringValue(state, 2);
  2820. string type = lua_interface->GetStringValue(state, 3);
  2821. string zone = lua_interface->GetStringValue(state, 4);
  2822. int16 level = lua_interface->GetInt16Value(state, 5);
  2823. string description = lua_interface->GetStringValue(state, 6);
  2824. bool load = true;
  2825. if (!quest) {
  2826. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2827. load = false;
  2828. }
  2829. if (load && name.length() == 0) {
  2830. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2831. load = false;
  2832. }
  2833. if (load && type.length() == 0) {
  2834. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2835. load = false;
  2836. }
  2837. if (load && zone.length() == 0) {
  2838. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2839. load = false;
  2840. }
  2841. if (load && description.length() == 0) {
  2842. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2843. load = false;
  2844. }
  2845. if (load && level == 0) {
  2846. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2847. load = false;
  2848. }
  2849. if (load)
  2850. quest->RegisterQuest(name, type, zone, level, description);
  2851. return 0;
  2852. }
  2853. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2854. if (!lua_interface)
  2855. return 0;
  2856. Quest* quest = lua_interface->GetQuest(state);
  2857. if (quest) {
  2858. int8 level = lua_interface->GetInt16Value(state, 2);
  2859. quest->SetPrereqLevel(level);
  2860. }
  2861. return 0;
  2862. }
  2863. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2864. if (!lua_interface)
  2865. return 0;
  2866. Quest* quest = lua_interface->GetQuest(state);
  2867. if (quest) {
  2868. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2869. quest->AddPrereqQuest(quest_id);
  2870. }
  2871. return 0;
  2872. }
  2873. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2874. if (!lua_interface)
  2875. return 0;
  2876. Quest* quest = lua_interface->GetQuest(state);
  2877. if (quest) {
  2878. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2879. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2880. if (quantity == 0)
  2881. quantity = 1;
  2882. Item* master_item = master_item_list.GetItem(item_id);
  2883. if (master_item) {
  2884. Item* item = new Item(master_item);
  2885. item->details.count = quantity;
  2886. quest->AddPrereqItem(item);
  2887. }
  2888. }
  2889. return 0;
  2890. }
  2891. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2892. if (!lua_interface)
  2893. return 0;
  2894. Spawn* player = lua_interface->GetSpawn(state);
  2895. if(!player || !player->IsPlayer()) {
  2896. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  2897. return 0;
  2898. }
  2899. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2900. if (quest_id > 0) {
  2901. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2902. return 1;
  2903. } else {
  2904. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2905. }
  2906. return 0;
  2907. }
  2908. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2909. if (!lua_interface)
  2910. return 0;
  2911. Quest* quest = lua_interface->GetQuest(state);
  2912. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2913. if (quest && spawn_id > 0)
  2914. quest->SetQuestReturnNPC(spawn_id);
  2915. return 0;
  2916. }
  2917. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2918. if (!lua_interface)
  2919. return 0;
  2920. Spawn* spawn = lua_interface->GetSpawn(state);
  2921. if (!spawn) {
  2922. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2923. return 0;
  2924. }
  2925. int32 time = lua_interface->GetInt32Value(state, 2);
  2926. if (time <= 0) {
  2927. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2928. return 0;
  2929. }
  2930. string function = lua_interface->GetStringValue(state, 3);
  2931. if (function.length() == 0) {
  2932. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2933. return 0;
  2934. }
  2935. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2936. Spawn* player = lua_interface->GetSpawn(state, 5);
  2937. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2938. timer->timer = Timer::GetCurrentTime2() + time;
  2939. timer->function = function;
  2940. timer->spawn = spawn->GetID();
  2941. timer->player = player ? player->GetID() : 0;
  2942. if (max_count == 0)
  2943. max_count = 1;
  2944. timer->max_count = max_count;
  2945. timer->current_count = 0;
  2946. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2947. return 0;
  2948. }
  2949. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2950. if (!lua_interface)
  2951. return 0;
  2952. Spawn* player = lua_interface->GetSpawn(state);
  2953. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2954. if (player && player->IsPlayer() && quest_id > 0) {
  2955. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2956. return 1;
  2957. }
  2958. return 0;
  2959. }
  2960. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2961. if (!lua_interface)
  2962. return 0;
  2963. Spawn* player = lua_interface->GetSpawn(state);
  2964. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2965. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2966. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2967. if (quest)
  2968. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2969. return 1;
  2970. }
  2971. return 0;
  2972. }
  2973. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2974. if (!lua_interface)
  2975. return 0;
  2976. Spawn* player = lua_interface->GetSpawn(state);
  2977. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2978. if (player && player->IsPlayer() && quest_id > 0) {
  2979. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2980. return 1;
  2981. }
  2982. return 0;
  2983. }
  2984. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2985. if (!lua_interface)
  2986. return 0;
  2987. Spawn* npc = lua_interface->GetSpawn(state);
  2988. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2989. if (npc && !npc->IsPlayer() && quest_id > 0)
  2990. npc->AddProvidedQuest(quest_id);
  2991. return 0;
  2992. }
  2993. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2994. if (!lua_interface)
  2995. return 0;
  2996. Spawn* npc = lua_interface->GetSpawn(state);
  2997. Spawn* player = lua_interface->GetSpawn(state, 2);
  2998. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  2999. bool forced = lua_interface->GetBooleanValue(state, 4);
  3000. /* NPC is allowed to be null */
  3001. if (player && player->IsPlayer() && quest_id > 0) {
  3002. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  3003. if (master_quest) {
  3004. Client* client = player->GetZone()->GetClientBySpawn(player);
  3005. if (!client) {
  3006. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3007. }
  3008. Quest* quest = new Quest(master_quest);
  3009. if (!quest) {
  3010. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3011. }
  3012. if (client && quest) {
  3013. if (npc)
  3014. quest->SetQuestGiver(npc->GetDatabaseID());
  3015. else
  3016. quest->SetQuestGiver(0);
  3017. client->AddPendingQuest(quest, forced);
  3018. }
  3019. }
  3020. else {
  3021. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3022. }
  3023. }
  3024. else {
  3025. lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
  3026. }
  3027. return 0;
  3028. }
  3029. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3030. if (!lua_interface)
  3031. return 0;
  3032. Quest* quest = lua_interface->GetQuest(state);
  3033. if (quest) {
  3034. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3035. quest->AddPrereqClass(class_id);
  3036. }
  3037. return 0;
  3038. }
  3039. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3040. if (!lua_interface)
  3041. return 0;
  3042. Quest* quest = lua_interface->GetQuest(state);
  3043. if (quest) {
  3044. int8 race = lua_interface->GetInt8Value(state, 2);
  3045. quest->AddPrereqRace(race);
  3046. }
  3047. return 0;
  3048. }
  3049. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3050. if (!lua_interface)
  3051. return 0;
  3052. Quest* quest = lua_interface->GetQuest(state);
  3053. if (quest) {
  3054. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3055. quest->AddPrereqModelType(model_type);
  3056. }
  3057. return 0;
  3058. }
  3059. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3060. if (!lua_interface)
  3061. return 0;
  3062. Quest* quest = lua_interface->GetQuest(state);
  3063. if (!quest) {
  3064. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3065. return 0;
  3066. }
  3067. int8 level = lua_interface->GetInt8Value(state, 2);
  3068. quest->SetPrereqTSLevel(level);
  3069. return 0;
  3070. }
  3071. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3072. if (!lua_interface)
  3073. return 0;
  3074. Quest* quest = lua_interface->GetQuest(state);
  3075. if (!quest) {
  3076. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3077. return 0;
  3078. }
  3079. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3080. quest->AddPrereqTradeskillClass(class_id);
  3081. return 0;
  3082. }
  3083. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3084. if (!lua_interface)
  3085. return 0;
  3086. Quest* quest = lua_interface->GetQuest(state);
  3087. if (quest) {
  3088. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3089. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3090. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3091. quest->AddPrereqFaction(faction_id, min, max);
  3092. }
  3093. return 0;
  3094. }
  3095. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3096. if (!lua_interface)
  3097. return 0;
  3098. Quest* quest = lua_interface->GetQuest(state);
  3099. if (quest) {
  3100. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3101. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3102. if (quantity == 0)
  3103. quantity = 1;
  3104. Item* master_item = master_item_list.GetItem(item_id);
  3105. if (master_item) {
  3106. Item* item = new Item(master_item);
  3107. item->details.count = quantity;
  3108. quest->AddSelectableRewardItem(item);
  3109. }
  3110. }
  3111. return 0;
  3112. }
  3113. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3114. if (!lua_interface)
  3115. return 0;
  3116. Quest* quest = lua_interface->GetQuest(state);
  3117. if (quest) {
  3118. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3119. vector<Item*>* items = quest->GetRewardItems();
  3120. if (items) {
  3121. vector<Item*>::iterator itr;
  3122. for (itr = items->begin(); itr != items->end(); itr++) {
  3123. if (*itr && (*itr)->details.item_id == item_id) {
  3124. lua_interface->SetBooleanValue(state, true);
  3125. return 1;
  3126. }
  3127. }
  3128. }
  3129. }
  3130. lua_interface->SetBooleanValue(state, false);
  3131. return 1;
  3132. }
  3133. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3134. if (!lua_interface)
  3135. return 0;
  3136. Quest* quest = lua_interface->GetQuest(state);
  3137. if (quest) {
  3138. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3139. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3140. if (quantity == 0)
  3141. quantity = 1;
  3142. Item* master_item = master_item_list.GetItem(item_id);
  3143. if (master_item) {
  3144. Item* item = new Item(master_item);
  3145. item->details.count = quantity;
  3146. quest->AddRewardItem(item);
  3147. }
  3148. }
  3149. return 0;
  3150. }
  3151. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3152. if (!lua_interface)
  3153. return 0;
  3154. Quest* quest = lua_interface->GetQuest(state);
  3155. if (quest) {
  3156. int32 copper = lua_interface->GetInt32Value(state, 2);
  3157. int32 silver = lua_interface->GetInt32Value(state, 3);
  3158. int32 gold = lua_interface->GetInt32Value(state, 4);
  3159. int32 plat = lua_interface->GetInt32Value(state, 5);
  3160. quest->AddRewardCoins(copper, silver, gold, plat);
  3161. }
  3162. return 0;
  3163. }
  3164. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3165. if (!lua_interface)
  3166. return 0;
  3167. Quest* quest = lua_interface->GetQuest(state);
  3168. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3169. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3170. if (quest && faction_id > 0 && amount != 0)
  3171. quest->AddRewardFaction(faction_id, amount);
  3172. return 0;
  3173. }
  3174. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3175. if (!lua_interface)
  3176. return 0;
  3177. Quest* quest = lua_interface->GetQuest(state);
  3178. if (quest) {
  3179. int32 status = lua_interface->GetInt32Value(state, 2);
  3180. quest->SetRewardStatus(status);
  3181. }
  3182. return 0;
  3183. }
  3184. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3185. if (!lua_interface)
  3186. return 0;
  3187. Quest* quest = lua_interface->GetQuest(state);
  3188. if (quest) {
  3189. string comment = lua_interface->GetStringValue(state, 2);
  3190. quest->SetRewardComment(comment);
  3191. }
  3192. return 0;
  3193. }
  3194. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3195. if (!lua_interface)
  3196. return 0;
  3197. Quest* quest = lua_interface->GetQuest(state);
  3198. if (quest) {
  3199. int32 exp = lua_interface->GetInt32Value(state, 2);
  3200. quest->SetRewardXP(exp);
  3201. }
  3202. return 0;
  3203. }
  3204. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3205. Quest* quest = lua_interface->GetQuest(state);
  3206. if (quest) {
  3207. int32 step = lua_interface->GetInt32Value(state, 2);
  3208. string description = lua_interface->GetStringValue(state, 3);
  3209. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3210. float percentage = lua_interface->GetFloatValue(state, 5);
  3211. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3212. int16 icon = lua_interface->GetInt16Value(state, 7);
  3213. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3214. const char* taskgroup = 0;
  3215. if (str_taskgroup.length() > 0)
  3216. taskgroup = str_taskgroup.c_str();
  3217. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3218. if (quest_step && icon && quantity > 0)
  3219. quest_step->SetIcon(icon);
  3220. }
  3221. return 0;
  3222. }
  3223. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3224. if (!lua_interface)
  3225. return 0;
  3226. Quest* quest = lua_interface->GetQuest(state);
  3227. if (quest) {
  3228. int32 step = lua_interface->GetInt32Value(state, 2);
  3229. string description = lua_interface->GetStringValue(state, 3);
  3230. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3231. float percentage = lua_interface->GetFloatValue(state, 5);
  3232. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3233. int16 icon = lua_interface->GetInt16Value(state, 7);
  3234. const char* taskgroup = 0;
  3235. if (str_taskgroup.length() > 0)
  3236. taskgroup = str_taskgroup.c_str();
  3237. int32 npc_id = 0;
  3238. vector<int32>* ids = 0;
  3239. Spawn* spawn = nullptr;
  3240. int i = 0;
  3241. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3242. if (ids == 0)
  3243. ids = new vector<int32>;
  3244. ids->push_back(npc_id);
  3245. i++;
  3246. }
  3247. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3248. if (quest_step && icon > 0 && quantity > 0)
  3249. quest_step->SetIcon(icon);
  3250. if (quest->GetPlayer()) {
  3251. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3252. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3253. }
  3254. }
  3255. return 0;
  3256. }
  3257. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3258. if (!lua_interface)
  3259. return 0;
  3260. Quest* quest = lua_interface->GetQuest(state);
  3261. if (quest) {
  3262. int32 step = lua_interface->GetInt32Value(state, 2);
  3263. string description = lua_interface->GetStringValue(state, 3);
  3264. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3265. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3266. int16 icon = lua_interface->GetInt16Value(state, 6);
  3267. const char* taskgroup = 0;
  3268. if (str_taskgroup.length() > 0)
  3269. taskgroup = str_taskgroup.c_str();
  3270. int32 npc_id = 0;
  3271. vector<int32>* ids = 0;
  3272. int i = 0;
  3273. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3274. if (ids == 0)
  3275. ids = new vector<int32>;
  3276. ids->push_back(npc_id);
  3277. i++;
  3278. }
  3279. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3280. if (quest_step && icon > 0)
  3281. quest_step->SetIcon(icon);
  3282. if (quest->GetPlayer()) {
  3283. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3284. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3285. }
  3286. }
  3287. return 0;
  3288. }
  3289. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3290. if (!lua_interface)
  3291. return 0;
  3292. Quest* quest = lua_interface->GetQuest(state);
  3293. if (quest) {
  3294. int32 step = lua_interface->GetInt32Value(state, 2);
  3295. string description = lua_interface->GetStringValue(state, 3);
  3296. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3297. float percentage = lua_interface->GetFloatValue(state, 5);
  3298. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3299. int16 icon = lua_interface->GetInt16Value(state, 7);
  3300. const char* taskgroup = 0;
  3301. if (str_taskgroup.length() > 0)
  3302. taskgroup = str_taskgroup.c_str();
  3303. int32 item_id = 0;
  3304. vector<int32>* ids = 0;
  3305. int i = 0;
  3306. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3307. if (ids == 0)
  3308. ids = new vector<int32>;
  3309. ids->push_back(item_id);
  3310. i++;
  3311. }
  3312. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3313. if (quest_step && icon > 0 && quantity > 0)
  3314. quest_step->SetIcon(icon);
  3315. if (quest->GetPlayer()) {
  3316. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3317. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3318. }
  3319. }
  3320. return 0;
  3321. }
  3322. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3323. if (!lua_interface)
  3324. return 0;
  3325. Quest* quest = lua_interface->GetQuest(state);
  3326. if (quest) {
  3327. int32 step = lua_interface->GetInt32Value(state, 2);
  3328. string description = lua_interface->GetStringValue(state, 3);
  3329. float max_variation = lua_interface->GetFloatValue(state, 4);
  3330. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3331. int16 icon = lua_interface->GetInt16Value(state, 6);
  3332. const char* taskgroup = 0;
  3333. if (str_taskgroup.length() > 0)
  3334. taskgroup = str_taskgroup.c_str();
  3335. vector<Location>* locations = 0;
  3336. int i = 7;
  3337. while (true) {
  3338. Location loc;
  3339. loc.x = lua_interface->GetFloatValue(state, i);
  3340. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3341. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3342. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3343. break;
  3344. if (locations == 0)
  3345. locations = new vector<Location>;
  3346. locations->push_back(loc);
  3347. i += 3;
  3348. }
  3349. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3350. if (quest_step && icon > 0)
  3351. quest_step->SetIcon(icon);
  3352. if (quest->GetPlayer()) {
  3353. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3354. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3355. }
  3356. }
  3357. return 0;
  3358. }
  3359. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3360. if (!lua_interface)
  3361. return 0;
  3362. Quest* quest = lua_interface->GetQuest(state);
  3363. if (quest) {
  3364. int32 step = lua_interface->GetInt32Value(state, 2);
  3365. string description = lua_interface->GetStringValue(state, 3);
  3366. float max_variation = lua_interface->GetFloatValue(state, 4);
  3367. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3368. int16 icon = lua_interface->GetInt16Value(state, 6);
  3369. const char* taskgroup = 0;
  3370. if (str_taskgroup.length() > 0)
  3371. taskgroup = str_taskgroup.c_str();
  3372. vector<Location>* locations = 0;
  3373. int i = 7;
  3374. while (true) {
  3375. Location loc;
  3376. loc.x = lua_interface->GetFloatValue(state, i);
  3377. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3378. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3379. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3380. break;
  3381. if (locations == 0)
  3382. locations = new vector<Location>;
  3383. locations->push_back(loc);
  3384. i += 3;
  3385. }
  3386. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3387. if (quest_step && icon > 0)
  3388. quest_step->SetIcon(icon);
  3389. if (quest->GetPlayer()) {
  3390. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3391. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3392. }
  3393. }
  3394. return 0;
  3395. }
  3396. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3397. Quest* quest = lua_interface->GetQuest(state);
  3398. if (quest) {
  3399. int32 step = lua_interface->GetInt32Value(state, 2);
  3400. string description = lua_interface->GetStringValue(state, 3);
  3401. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3402. float percentage = lua_interface->GetFloatValue(state, 5);
  3403. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3404. int16 icon = lua_interface->GetInt16Value(state, 7);
  3405. const char* taskgroup = 0;
  3406. if (str_taskgroup.length() > 0)
  3407. taskgroup = str_taskgroup.c_str();
  3408. int32 spell_id = 0;
  3409. vector<int32>* ids = 0;
  3410. int i = 0;
  3411. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3412. if (ids == 0)
  3413. ids = new vector<int32>;
  3414. ids->push_back(spell_id);
  3415. i++;
  3416. }
  3417. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3418. if (quest_step && icon > 0 && quantity > 0)
  3419. quest_step->SetIcon(icon);
  3420. if (quest->GetPlayer()) {
  3421. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3422. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3423. }
  3424. }
  3425. return 0;
  3426. }
  3427. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3428. if (!lua_interface)
  3429. return 0;
  3430. Quest* quest = lua_interface->GetQuest(state);
  3431. if (quest) {
  3432. int32 step = lua_interface->GetInt32Value(state, 2);
  3433. string description = lua_interface->GetStringValue(state, 3);
  3434. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3435. float percentage = lua_interface->GetFloatValue(state, 5);
  3436. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3437. int16 icon = lua_interface->GetInt16Value(state, 7);
  3438. const char* taskgroup = 0;
  3439. if (str_taskgroup.length() > 0)
  3440. taskgroup = str_taskgroup.c_str();
  3441. int32 item_id = 0;
  3442. vector<int32>* ids = 0;
  3443. int i = 0;
  3444. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3445. if (ids == 0)
  3446. ids = new vector<int32>;
  3447. ids->push_back(item_id);
  3448. i++;
  3449. }
  3450. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3451. if (quest_step && icon > 0 && quantity > 0)
  3452. quest_step->SetIcon(icon);
  3453. if (quest->GetPlayer()) {
  3454. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3455. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3456. }
  3457. }
  3458. return 0;
  3459. }
  3460. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3461. if (!lua_interface)
  3462. return 0;
  3463. Quest* quest = lua_interface->GetQuest(state);
  3464. if (quest) {
  3465. int32 step = lua_interface->GetInt32Value(state, 2);
  3466. string description = lua_interface->GetStringValue(state, 3);
  3467. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3468. float percentage = lua_interface->GetFloatValue(state, 5);
  3469. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3470. int16 icon = lua_interface->GetInt16Value(state, 7);
  3471. const char* taskgroup = 0;
  3472. if (str_taskgroup.length() > 0)
  3473. taskgroup = str_taskgroup.c_str();
  3474. int32 item_id = 0;
  3475. vector<int32>* ids = 0;
  3476. int i = 0;
  3477. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3478. if (ids == 0)
  3479. ids = new vector<int32>;
  3480. ids->push_back(item_id);
  3481. i++;
  3482. }
  3483. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3484. if (quest_step && icon > 0 && quantity > 0)
  3485. quest_step->SetIcon(icon);
  3486. if (quest->GetPlayer()) {
  3487. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3488. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3489. }
  3490. }
  3491. return 0;
  3492. }
  3493. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3494. if (!lua_interface)
  3495. return 0;
  3496. Quest* quest = lua_interface->GetQuest(state);
  3497. if (quest) {
  3498. string action = lua_interface->GetStringValue(state, 2);
  3499. if (action.length() > 0)
  3500. quest->SetCompleteAction(action);
  3501. }
  3502. return 0;
  3503. }
  3504. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3505. if (!lua_interface)
  3506. return 0;
  3507. Quest* quest = lua_interface->GetQuest(state);
  3508. if (quest) {
  3509. int32 step = lua_interface->GetInt32Value(state, 2);
  3510. string action = lua_interface->GetStringValue(state, 3);
  3511. if (step > 0 && action.length() > 0)
  3512. quest->AddCompleteAction(step, action);
  3513. }
  3514. return 0;
  3515. }
  3516. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3517. if (!lua_interface)
  3518. return 0;
  3519. Quest* quest = lua_interface->GetQuest(state);
  3520. if (quest) {
  3521. int32 step = lua_interface->GetInt32Value(state, 2);
  3522. string action = lua_interface->GetStringValue(state, 3);
  3523. if (step > 0 && action.length() > 0)
  3524. quest->AddProgressAction(step, action);
  3525. }
  3526. return 0;
  3527. }
  3528. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3529. if (!lua_interface)
  3530. return 0;
  3531. Quest* quest = lua_interface->GetQuest(state);
  3532. string description = lua_interface->GetStringValue(state, 2);
  3533. if (quest && description.length() > 0)
  3534. quest->SetDescription(description);
  3535. return 0;
  3536. }
  3537. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3538. if (!lua_interface)
  3539. return 0;
  3540. Quest* quest = lua_interface->GetQuest(state);
  3541. string description = lua_interface->GetStringValue(state, 2);
  3542. if (quest && description.length() > 0)
  3543. quest->SetCompletedDescription(description);
  3544. return 0;
  3545. }
  3546. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3547. if (!lua_interface)
  3548. return 0;
  3549. Quest* quest = lua_interface->GetQuest(state);
  3550. int32 step = lua_interface->GetInt32Value(state, 2);
  3551. string description = lua_interface->GetStringValue(state, 3);
  3552. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3553. if (quest && step > 0 && description.length() > 0) {
  3554. quest->SetTaskGroupDescription(step, description, display_bullets);
  3555. if (quest->GetPlayer()) {
  3556. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3557. if (client)
  3558. client->SendQuestUpdateStep(quest, step, false);
  3559. }
  3560. }
  3561. return 0;
  3562. }
  3563. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3564. if (!lua_interface)
  3565. return 0;
  3566. Quest* quest = lua_interface->GetQuest(state);
  3567. int32 step = lua_interface->GetInt32Value(state, 2);
  3568. string description = lua_interface->GetStringValue(state, 3);
  3569. if (quest && step > 0 && description.length() > 0) {
  3570. quest->SetStepDescription(step, description);
  3571. if (quest->GetPlayer()) {
  3572. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3573. if (client)
  3574. client->SendQuestUpdateStepImmediately(quest, step);
  3575. }
  3576. }
  3577. return 0;
  3578. }
  3579. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3580. Quest* quest = lua_interface->GetQuest(state);
  3581. string zone = lua_interface->GetStringValue(state, 2);
  3582. if (quest && zone.length() > 0)
  3583. quest->SetZone(zone);
  3584. return 0;
  3585. }
  3586. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3587. if (!lua_interface)
  3588. return 0;
  3589. Quest* quest = lua_interface->GetQuest(state);
  3590. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3591. int32 coin = lua_interface->GetInt32Value(state, 3);
  3592. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3593. string rewards_str = lua_interface->GetStringValue(state, 5);
  3594. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3595. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3596. string text = lua_interface->GetStringValue(state, 8);
  3597. int32 source_id = 0;
  3598. if (playerSpawn && playerSpawn->IsPlayer()) {
  3599. Player* player = (Player*)playerSpawn;
  3600. Client* client = player->GetZone()->GetClientBySpawn(player);
  3601. if (client) {
  3602. vector<Item*> reward_items;
  3603. vector<Item*> selectable_reward_items;
  3604. if (rewards_str.length() > 0) {
  3605. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3606. map<unsigned int, unsigned short>::iterator itr;
  3607. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3608. if (itr->first > 0) {
  3609. Item* item = new Item(master_item_list.GetItem(itr->first));
  3610. if (item) {
  3611. if (itr->second > 0)
  3612. item->details.count = itr->second;
  3613. reward_items.push_back(item);
  3614. }
  3615. }
  3616. }
  3617. }
  3618. if (select_rewards_str.length() > 0) {
  3619. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3620. map<unsigned int, unsigned short>::iterator itr;
  3621. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3622. if (itr->first > 0) {
  3623. Item* item = new Item(master_item_list.GetItem(itr->first));
  3624. if (item) {
  3625. if (itr->second > 0)
  3626. item->stack_count = itr->second;
  3627. selectable_reward_items.push_back(item);
  3628. }
  3629. }
  3630. }
  3631. }
  3632. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3633. const char* reward_type = "Quest Reward!";
  3634. if (!quest)
  3635. reward_type = "Reward!";
  3636. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3637. }
  3638. }
  3639. return 0;
  3640. }
  3641. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3642. if (!lua_interface)
  3643. return 0;
  3644. Quest* quest = lua_interface->GetQuest(state);
  3645. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3646. if (quest && spawn) {
  3647. if (spawn->IsPlayer()) {
  3648. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3649. if (client)
  3650. client->AddPendingQuestReward(quest);
  3651. }
  3652. }
  3653. return 0;
  3654. }
  3655. int EQ2Emu_lua_Harvest(lua_State* state) {
  3656. if (!lua_interface)
  3657. return 0;
  3658. Spawn* player = lua_interface->GetSpawn(state);
  3659. Spawn* node = lua_interface->GetSpawn(state, 2);
  3660. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3661. Client* client = player->GetZone()->GetClientBySpawn(player);
  3662. if (client) {
  3663. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3664. ((GroundSpawn*)node)->ProcessHarvest(client);
  3665. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3666. player->GetZone()->RemoveSpawn(true, node, true);
  3667. }
  3668. }
  3669. else if (player && player->IsPlayer()) {
  3670. Client* client = player->GetZone()->GetClientBySpawn(player);
  3671. if (client)
  3672. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3673. }
  3674. return 0;
  3675. }
  3676. int EQ2Emu_lua_Bind(lua_State* state) {
  3677. if (!lua_interface)
  3678. return 0;
  3679. Spawn* spawn = lua_interface->GetSpawn(state);
  3680. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3681. float x = lua_interface->GetFloatValue(state, 3);
  3682. float y = lua_interface->GetFloatValue(state, 4);
  3683. float z = lua_interface->GetFloatValue(state, 5);
  3684. float h = lua_interface->GetFloatValue(state, 6);
  3685. if (!spawn) {
  3686. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3687. return 0;
  3688. }
  3689. if (!spawn->IsPlayer()) {
  3690. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3691. return 0;
  3692. }
  3693. if (zone_id == 0) {
  3694. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3695. if (!client) {
  3696. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3697. return 0;
  3698. }
  3699. if (!client->Bind())
  3700. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3701. }
  3702. else {
  3703. Player* player = (Player*)spawn;
  3704. player->GetPlayerInfo()->SetBindZone(zone_id);
  3705. player->GetPlayerInfo()->SetBindX(x);
  3706. player->GetPlayerInfo()->SetBindY(y);
  3707. player->GetPlayerInfo()->SetBindZ(z);
  3708. player->GetPlayerInfo()->SetBindHeading(h);
  3709. }
  3710. return 0;
  3711. }
  3712. int EQ2Emu_lua_Gate(lua_State* state) {
  3713. if (!lua_interface)
  3714. return 0;
  3715. Spawn* spawn = lua_interface->GetSpawn(state);
  3716. if (spawn) {
  3717. if (spawn->IsPlayer()) {
  3718. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3719. if (client) {
  3720. if (!client->Gate())
  3721. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3722. }
  3723. }
  3724. }
  3725. return 0;
  3726. }
  3727. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3728. if (!lua_interface)
  3729. return 0;
  3730. bool ret = false;
  3731. Spawn* spawn = lua_interface->GetSpawn(state);
  3732. if (spawn) {
  3733. if (spawn->IsPlayer()) {
  3734. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3735. if (client)
  3736. ret = client->BindAllowed();
  3737. }
  3738. }
  3739. lua_interface->SetBooleanValue(state, ret);
  3740. return 1;
  3741. }
  3742. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3743. if (!lua_interface)
  3744. return 0;
  3745. bool ret = false;
  3746. Spawn* spawn = lua_interface->GetSpawn(state);
  3747. if (spawn) {
  3748. if (spawn->IsPlayer()) {
  3749. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3750. if (client)
  3751. ret = client->GateAllowed();
  3752. }
  3753. }
  3754. lua_interface->SetBooleanValue(state, ret);
  3755. return 1;
  3756. }
  3757. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3758. Spawn* spawn = lua_interface->GetSpawn(state);
  3759. if (spawn) {
  3760. lua_interface->SetBooleanValue(state, spawn->Alive());
  3761. return 1;
  3762. }
  3763. return 0;
  3764. }
  3765. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3766. if (!lua_interface)
  3767. return 0;
  3768. Spawn* spawn = lua_interface->GetSpawn(state);
  3769. if (spawn && spawn->IsEntity()) {
  3770. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3771. return 1;
  3772. }
  3773. return 0;
  3774. }
  3775. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3776. Spawn* spawn = lua_interface->GetSpawn(state);
  3777. string message = lua_interface->GetStringValue(state, 2);
  3778. string color_str = lua_interface->GetStringValue(state, 3);
  3779. int8 color = CHANNEL_NARRATIVE;
  3780. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3781. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3782. if (client) {
  3783. if (color_str.length() > 0) {
  3784. // leave for backwards compat, but all future should just use the number
  3785. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3786. color = CHANNEL_COLOR_RED;
  3787. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3788. color = CHANNEL_COLOR_YELLOW;
  3789. else
  3790. {
  3791. // use a number to specify the channel as per Commands/Commands.h defines
  3792. color = (int8)atoul(color_str.c_str());
  3793. }
  3794. }
  3795. client->SimpleMessage(color, message.c_str());
  3796. }
  3797. }
  3798. return 0;
  3799. }
  3800. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3801. Spawn* spawn = lua_interface->GetSpawn(state);
  3802. string message = lua_interface->GetStringValue(state, 2);
  3803. int8 red = lua_interface->GetInt8Value(state, 3);
  3804. int8 green = lua_interface->GetInt8Value(state, 4);
  3805. int8 blue = lua_interface->GetInt8Value(state, 5);
  3806. if (!spawn) {
  3807. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3808. return 0;
  3809. }
  3810. int32 words = ::CountWordsInString(message.c_str());
  3811. if (words < 5)
  3812. words = 5;
  3813. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3814. if (client)
  3815. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3816. return 0;
  3817. }
  3818. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3819. Spawn* spawn = lua_interface->GetSpawn(state);
  3820. int8 param = lua_interface->GetInt8Value(state, 2);
  3821. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3822. int8 value = lua_interface->GetInt8Value(state, 4);
  3823. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3824. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3825. if (client) {
  3826. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3827. switch (param) {
  3828. case 1: {
  3829. packet->setDataByName("parameter1", param_value);
  3830. break;
  3831. }
  3832. case 2: {
  3833. packet->setDataByName("parameter2", param_value);
  3834. break;
  3835. }
  3836. case 3: {
  3837. packet->setDataByName("parameter3", param_value);
  3838. break;
  3839. }
  3840. case 4: {
  3841. packet->setDataByName("parameter4", param_value);
  3842. break;
  3843. }
  3844. case 5: {
  3845. packet->setDataByName("parameter5", param_value);
  3846. break;
  3847. }
  3848. }
  3849. packet->setDataByName("value", value);
  3850. client->QueuePacket(packet->serialize());
  3851. safe_delete(packet);
  3852. }
  3853. }
  3854. return 0;
  3855. }
  3856. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3857. Spawn* spawn = lua_interface->GetSpawn(state);
  3858. if (spawn && spawn->IsPlayer()) {
  3859. if (((Player*)spawn)->GetIsTracking())
  3860. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3861. else
  3862. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3863. }
  3864. return 0;
  3865. }
  3866. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3867. Spawn* player = lua_interface->GetSpawn(state);
  3868. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3869. string name = lua_interface->GetStringValue(state, 3);
  3870. float distance = lua_interface->GetFloatValue(state, 4);
  3871. string command = lua_interface->GetStringValue(state, 5);
  3872. string error_text = lua_interface->GetStringValue(state, 6);
  3873. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3874. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3875. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3876. if (spawn) {
  3877. if (distance == 0)
  3878. distance = 10.0f;
  3879. if (command.length() == 0)
  3880. command = name;
  3881. if (command.length() < 1 && name.length() < 1)
  3882. {
  3883. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3884. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3885. spawn->RemovePrimaryCommands();
  3886. }
  3887. else
  3888. {
  3889. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3890. }
  3891. }
  3892. return 0;
  3893. }
  3894. int EQ2Emu_lua_HasSpell(lua_State* state) {
  3895. if (!lua_interface)
  3896. return 0;
  3897. Spawn* player = lua_interface->GetSpawn(state);
  3898. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3899. int16 tier = lua_interface->GetInt16Value(state, 3);
  3900. if (player && player->IsPlayer()) {
  3901. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  3902. return 1;
  3903. }
  3904. return 0;
  3905. }
  3906. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3907. if (!lua_interface)
  3908. return 0;
  3909. Spawn* player = lua_interface->GetSpawn(state);
  3910. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3911. int16 tier = lua_interface->GetInt16Value(state, 3);
  3912. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3913. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  3914. bool add_to_hotbar = true;
  3915. if (num_args > 4) {
  3916. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  3917. }
  3918. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3919. if (player && spell && player->IsPlayer()) {
  3920. Client* client = player->GetClient();
  3921. if (client) {
  3922. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3923. {
  3924. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3925. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3926. client->GetPlayer()->UnlockSpell(spell);
  3927. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  3928. }
  3929. else
  3930. {
  3931. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3932. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3933. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3934. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3935. client->GetPlayer()->UnlockSpell(spell);
  3936. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  3937. }
  3938. //if (client ) {
  3939. // ((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);
  3940. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3941. if (outapp)
  3942. client->QueuePacket(outapp);
  3943. }
  3944. }
  3945. return 0;
  3946. }
  3947. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3948. if (!lua_interface)
  3949. return 0;
  3950. Spawn* player = lua_interface->GetSpawn(state);
  3951. if (player && player->IsPlayer()) {
  3952. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3953. return 1;
  3954. }
  3955. return 0;
  3956. }
  3957. int EQ2Emu_lua_Attack(lua_State* state) {
  3958. if (lua_interface) {
  3959. Spawn* npc = lua_interface->GetSpawn(state);
  3960. Spawn* player = lua_interface->GetSpawn(state, 2);
  3961. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3962. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3963. }
  3964. return 0;
  3965. }
  3966. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3967. if (lua_interface) {
  3968. Spawn* target = lua_interface->GetSpawn(state);
  3969. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3970. if (target && target->GetZone())
  3971. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3972. }
  3973. return 0;
  3974. }
  3975. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3976. Spawn* player;
  3977. if (lua_interface) {
  3978. player = lua_interface->GetSpawn(state);
  3979. if (player && player->IsPlayer()) {
  3980. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3981. return 1;
  3982. }
  3983. }
  3984. return 0;
  3985. }
  3986. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3987. Spawn* player;
  3988. Client* client;
  3989. if (lua_interface) {
  3990. player = lua_interface->GetSpawn(state);
  3991. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3992. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3993. client->HandInCollections();
  3994. }
  3995. return 0;
  3996. }
  3997. int EQ2Emu_lua_UseWidget(lua_State* state) {
  3998. Spawn* widget;
  3999. if (lua_interface) {
  4000. widget = lua_interface->GetSpawn(state);
  4001. if (widget && widget->IsWidget())
  4002. ((Widget*)widget)->HandleUse(NULL, "");
  4003. }
  4004. return 0;
  4005. }
  4006. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4007. Spawn* spawn = 0;
  4008. int32 primary_list = 0;
  4009. int32 secondary_list = 0;
  4010. if (lua_interface) {
  4011. spawn = lua_interface->GetSpawn(state);
  4012. primary_list = lua_interface->GetInt32Value(state, 2);
  4013. secondary_list = lua_interface->GetInt32Value(state, 3);
  4014. if (!spawn->IsNPC()) {
  4015. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4016. return 0;
  4017. }
  4018. NPC* npc = (NPC*)spawn;
  4019. npc->SetPrimarySpellList(primary_list);
  4020. npc->SetSecondarySpellList(secondary_list);
  4021. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4022. }
  4023. return 0;
  4024. }
  4025. int EQ2Emu_lua_GetPet(lua_State* state) {
  4026. if (!lua_interface)
  4027. return 0;
  4028. Spawn* spawn = lua_interface->GetSpawn(state);
  4029. if (spawn) {
  4030. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4031. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4032. return 1;
  4033. }
  4034. }
  4035. return 0;
  4036. }
  4037. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4038. if (!lua_interface)
  4039. return 0;
  4040. Spawn* spawn = lua_interface->GetSpawn(state);
  4041. if (spawn) {
  4042. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4043. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4044. return 1;
  4045. }
  4046. }
  4047. return 0;
  4048. }
  4049. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4050. if (!lua_interface)
  4051. return 0;
  4052. Spawn* spawn = lua_interface->GetSpawn(state);
  4053. if (spawn) {
  4054. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4055. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4056. return 1;
  4057. }
  4058. }
  4059. return 0;
  4060. }
  4061. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4062. if (!lua_interface)
  4063. return 0;
  4064. Spawn* spawn = lua_interface->GetSpawn(state);
  4065. if (spawn) {
  4066. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4067. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4068. return 1;
  4069. }
  4070. }
  4071. return 0;
  4072. }
  4073. int EQ2Emu_lua_Charm(lua_State* state) {
  4074. if (!lua_interface)
  4075. return 0;
  4076. Spawn* owner = lua_interface->GetSpawn(state);
  4077. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4078. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4079. if (!luaspell) {
  4080. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4081. return 0;
  4082. }
  4083. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4084. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4085. pet->SetPet(true);
  4086. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4087. ((NPC*)pet)->SetOwner((Entity*)owner);
  4088. // If owner is player and player does not have a summoned pet set the players charsheet
  4089. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4090. Player* player = (Player*)owner;
  4091. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4092. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  4093. player->GetInfoStruct()->pet_movement = 2;
  4094. player->GetInfoStruct()->pet_behavior = 3;
  4095. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4096. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4097. // Make sure the values get sent to the client
  4098. player->SetCharSheetChanged(true);
  4099. }
  4100. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4101. pet->SetSpawnScript("");
  4102. // Set faction to the same as the owner
  4103. pet->SetFactionID(owner->GetFactionID());
  4104. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4105. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4106. // Clear hate list
  4107. ((NPC*)pet)->Brain()->ClearHate();
  4108. // Set the brain to a pet brain
  4109. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4110. }
  4111. return 0;
  4112. }
  4113. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4114. if (!lua_interface)
  4115. return 0;
  4116. Spawn* spawn = lua_interface->GetSpawn(state);
  4117. if (!spawn) {
  4118. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4119. return 0;
  4120. }
  4121. vector<Spawn*> groupMembers;
  4122. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4123. groupMembers = *spawn->GetSpawnGroup();
  4124. }
  4125. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4126. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4127. deque<GroupMemberInfo*>::iterator itr;
  4128. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4129. if (group)
  4130. {
  4131. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4132. deque<GroupMemberInfo*>* members = group->GetMembers();
  4133. GroupMemberInfo* info = 0;
  4134. for (itr = members->begin(); itr != members->end(); itr++) {
  4135. info = *itr;
  4136. if (info->client)
  4137. groupMembers.push_back(info->client->GetPlayer());
  4138. }
  4139. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4140. }
  4141. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4142. }
  4143. else
  4144. return 0;
  4145. lua_createtable(state, groupMembers.size(), 0);
  4146. int newTable = lua_gettop(state);
  4147. for (int32 i = 0; i < groupMembers.size(); i++) {
  4148. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4149. lua_rawseti(state, newTable, i + 1);
  4150. }
  4151. return 1;
  4152. }
  4153. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4154. if (!lua_interface)
  4155. return 0;
  4156. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4157. lua_interface->SetOptionWindowValue(state, option_window);
  4158. return 1;
  4159. }
  4160. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4161. if (!lua_interface)
  4162. return 0;
  4163. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4164. if (option_window) {
  4165. OptionWindowOption option_window_option;
  4166. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4167. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4168. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4169. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4170. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4171. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4172. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4173. option_window->push_back(option_window_option);
  4174. }
  4175. return 0;
  4176. }
  4177. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4178. if (!lua_interface)
  4179. return 0;
  4180. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4181. Spawn* player = lua_interface->GetSpawn(state, 2);
  4182. string window_title = lua_interface->GetStringValue(state, 3);
  4183. string cancel_command = lua_interface->GetStringValue(state, 4);
  4184. Client* client = player->GetZone()->GetClientBySpawn(player);
  4185. if (option_window && window_title.length() > 0 && client) {
  4186. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4187. if (!packet)
  4188. return 0;
  4189. packet->setDataByName("title_text", window_title.c_str());
  4190. if (cancel_command.length() > 0)
  4191. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4192. packet->setArrayLengthByName("num_selections", option_window->size());
  4193. vector<OptionWindowOption>::iterator itr;
  4194. int8 i = 0;
  4195. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4196. OptionWindowOption opt = *itr;
  4197. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4198. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4199. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4200. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4201. if (opt.optionCommand.length() > 0)
  4202. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4203. if (opt.optionConfirmTitle.length() > 0)
  4204. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4205. i++;
  4206. }
  4207. client->QueuePacket(packet->serialize());
  4208. safe_delete(option_window);
  4209. safe_delete(packet);
  4210. }
  4211. return 0;
  4212. }
  4213. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4214. if (!lua_interface)
  4215. return 0;
  4216. Spawn* spawn = lua_interface->GetSpawn(state);
  4217. if (spawn) {
  4218. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4219. return 1;
  4220. }
  4221. else
  4222. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4223. return 0;
  4224. }
  4225. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4226. if (!lua_interface)
  4227. return 0;
  4228. Spawn* spawn = lua_interface->GetSpawn(state);
  4229. if (spawn) {
  4230. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4231. return 1;
  4232. }
  4233. else
  4234. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4235. return 0;
  4236. }
  4237. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4238. if (!lua_interface)
  4239. return 0;
  4240. Spawn* spawn = lua_interface->GetSpawn(state);
  4241. if (spawn) {
  4242. int8 class_id = spawn->GetTradeskillClass();
  4243. // Need to add 42 for the offset in the array
  4244. class_id += 44;
  4245. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4246. return 1;
  4247. }
  4248. else
  4249. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4250. return 0;
  4251. }
  4252. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4253. if (!lua_interface)
  4254. return 0;
  4255. Spawn* spawn = lua_interface->GetSpawn(state);
  4256. int16 level = lua_interface->GetInt8Value(state, 2);
  4257. if (spawn) {
  4258. if (spawn->IsPlayer())
  4259. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4260. else
  4261. spawn->SetTSLevel(level);
  4262. }
  4263. else
  4264. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4265. return 0;
  4266. }
  4267. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4268. if (!lua_interface)
  4269. return 0;
  4270. Spawn* spawn = lua_interface->GetSpawn(state);
  4271. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4272. if (spawn) {
  4273. spawn->SetAttackable(attackable);
  4274. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4275. }
  4276. return 0;
  4277. }
  4278. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4279. // Check to see if we have a valid lua_interface
  4280. if (!lua_interface)
  4281. return 0;
  4282. // Get the spawn that is getting the pet
  4283. Spawn* spawn = lua_interface->GetSpawn(state);
  4284. // Get the DB ID of the pet
  4285. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4286. // The max level the pet can gain
  4287. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4288. // Get the spell that this command was called from
  4289. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4290. // Check to make sure the spawn pointer is valid
  4291. if (!spawn) {
  4292. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4293. return 0;
  4294. }
  4295. // Check to make sure the spawn is an entity
  4296. if (!spawn->IsEntity()) {
  4297. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4298. return 0;
  4299. }
  4300. // Check to make sure the spawn doesn't already have a pet of this type
  4301. if (((Entity*)spawn)->GetPet()) {
  4302. if (spawn->IsPlayer()) {
  4303. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4304. if (client)
  4305. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4306. }
  4307. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4308. return 0;
  4309. }
  4310. // Check to see if the DB ID for the pet is set
  4311. if (pet_id == 0) {
  4312. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4313. return 0;
  4314. }
  4315. // Check to see if the pointer to the spell is valid
  4316. if (!luaspell) {
  4317. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4318. return 0;
  4319. }
  4320. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4321. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4322. if (!pet) {
  4323. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4324. return 0;
  4325. }
  4326. // Check to make sure the pet is an npc
  4327. if (!pet->IsNPC()) {
  4328. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4329. return 0;
  4330. }
  4331. // Spawn the pet at the same location as the owner
  4332. pet->SetX(spawn->GetX());
  4333. pet->SetY(spawn->GetY());
  4334. pet->SetZ(spawn->GetZ());
  4335. pet->SetLocation(spawn->GetLocation());
  4336. pet->SetHeading(spawn->GetHeading());
  4337. spawn->GetZone()->AddSpawn(pet);
  4338. /*
  4339. const char* spawn_script = world.GetSpawnScript(pet_id);
  4340. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4341. spawn->SetSpawnScript(string(spawn_script));
  4342. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4343. }*/
  4344. // Get a random pet name
  4345. string random_pet_name;
  4346. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4347. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4348. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4349. // If player set various values for the char sheet (pet window)
  4350. if (spawn->IsPlayer()) {
  4351. Player* player = (Player*)spawn;
  4352. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4353. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  4354. player->GetInfoStruct()->pet_movement = 2;
  4355. player->GetInfoStruct()->pet_behavior = 3;
  4356. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4357. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4358. // Make sure the values get sent to the client
  4359. player->SetCharSheetChanged(true);
  4360. }
  4361. // Set the pets name
  4362. pet->SetName(random_pet_name.c_str());
  4363. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4364. if (max_level > 0)
  4365. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4366. else
  4367. pet->SetLevel(spawn->GetLevel());
  4368. // Set the max level this pet can reach
  4369. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4370. // Set the faction of the pet to the same faction as the owner
  4371. pet->SetFactionID(spawn->GetFactionID());
  4372. // Set the spawn as a pet
  4373. pet->SetPet(true);
  4374. // Give a pointer of the owner to the pet
  4375. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4376. // Give a pointer of the pet to the owner
  4377. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4378. // Set the pet type
  4379. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4380. // Set the spell id used to create this pet
  4381. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4382. // Set the spell tier used to create this pet
  4383. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4384. // Set the pets spawn type to 6
  4385. pet->SetSpawnType(6);
  4386. // Set the pets brain
  4387. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4388. // Check to see if the pet has a subtitle
  4389. if (strlen(pet->GetSubTitle()) > 0) {
  4390. // Add the players name to the front of the sub title
  4391. string pet_subtitle;
  4392. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4393. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4394. // Set the pets subtitle to the new one
  4395. pet->SetSubTitle(pet_subtitle.c_str());
  4396. }
  4397. // Add the "Pet Options" entity command to the pet
  4398. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4399. // Set the pet as the return value for this function
  4400. lua_interface->SetSpawnValue(state, pet);
  4401. return 1;
  4402. }
  4403. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4404. if (!lua_interface)
  4405. return 0;
  4406. Spawn* spawn = lua_interface->GetSpawn(state);
  4407. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4408. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4409. if (!spawn) {
  4410. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4411. return 0;
  4412. }
  4413. if (!spawn->IsEntity()) {
  4414. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4415. return 0;
  4416. }
  4417. if (((Entity*)spawn)->GetDeityPet()) {
  4418. if (spawn->IsPlayer()) {
  4419. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4420. if (client)
  4421. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4422. }
  4423. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4424. return 0;
  4425. }
  4426. if (pet_id == 0) {
  4427. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4428. return 0;
  4429. }
  4430. if (!luaspell) {
  4431. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4432. return 0;
  4433. }
  4434. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4435. if (!pet) {
  4436. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4437. return 0;
  4438. }
  4439. if (!pet->IsNPC()) {
  4440. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4441. return 0;
  4442. }
  4443. pet->SetX(spawn->GetX());
  4444. pet->SetY(spawn->GetY());
  4445. pet->SetZ(spawn->GetZ());
  4446. pet->SetLocation(spawn->GetLocation());
  4447. pet->SetHeading(spawn->GetHeading());
  4448. spawn->GetZone()->AddSpawn(pet);
  4449. string random_pet_name;
  4450. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4451. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4452. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4453. pet->SetName(random_pet_name.c_str());
  4454. pet->SetLevel(spawn->GetLevel());
  4455. pet->SetFactionID(spawn->GetFactionID());
  4456. pet->SetPet(true);
  4457. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4458. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4459. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4460. pet->SetSpawnType(6);
  4461. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4462. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4463. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4464. if (strlen(pet->GetSubTitle()) > 0) {
  4465. string pet_subtitle;
  4466. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4467. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4468. pet->SetSubTitle(pet_subtitle.c_str());
  4469. }
  4470. // deity and cosmetic pets are not attackable
  4471. pet->SetAttackable(false);
  4472. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4473. lua_interface->SetSpawnValue(state, pet);
  4474. return 1;
  4475. }
  4476. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4477. if (!lua_interface)
  4478. return 0;
  4479. Spawn* spawn = lua_interface->GetSpawn(state);
  4480. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4481. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4482. if (!spawn) {
  4483. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4484. return 0;
  4485. }
  4486. if (!spawn->IsEntity()) {
  4487. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4488. return 0;
  4489. }
  4490. if (((Entity*)spawn)->GetCosmeticPet()) {
  4491. if (spawn->IsPlayer()) {
  4492. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4493. if (client)
  4494. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4495. }
  4496. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4497. return 0;
  4498. }
  4499. if (pet_id == 0) {
  4500. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4501. return 0;
  4502. }
  4503. if (!luaspell) {
  4504. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4505. return 0;
  4506. }
  4507. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4508. if (!pet) {
  4509. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4510. return 0;
  4511. }
  4512. if (!pet->IsNPC()) {
  4513. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4514. return 0;
  4515. }
  4516. pet->SetX(spawn->GetX());
  4517. pet->SetY(spawn->GetY());
  4518. pet->SetZ(spawn->GetZ());
  4519. pet->SetLocation(spawn->GetLocation());
  4520. pet->SetHeading(spawn->GetHeading());
  4521. spawn->GetZone()->AddSpawn(pet);
  4522. string random_pet_name;
  4523. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4524. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4525. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4526. pet->SetName(random_pet_name.c_str());
  4527. pet->SetLevel(spawn->GetLevel());
  4528. pet->SetFactionID(spawn->GetFactionID());
  4529. pet->SetPet(true);
  4530. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4531. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4532. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4533. pet->SetSpawnType(6);
  4534. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4535. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4536. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4537. if (strlen(pet->GetSubTitle()) > 0) {
  4538. string pet_subtitle;
  4539. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4540. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4541. pet->SetSubTitle(pet_subtitle.c_str());
  4542. }
  4543. pet->SetAttackable(false);
  4544. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4545. lua_interface->SetSpawnValue(state, pet);
  4546. return 1;
  4547. }
  4548. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4549. if (!lua_interface)
  4550. return 0;
  4551. Spawn* spawn = lua_interface->GetSpawn(state);
  4552. if (!spawn) {
  4553. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4554. return 0;
  4555. }
  4556. if (!spawn->IsPet()) {
  4557. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4558. return 0;
  4559. }
  4560. if (!((NPC*)spawn)->IsDismissing())
  4561. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
  4562. return 0;
  4563. }
  4564. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4565. if (!lua_interface)
  4566. return 0;
  4567. Quest* quest = lua_interface->GetQuest(state);
  4568. if (!quest) {
  4569. 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));
  4570. return 0;
  4571. }
  4572. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4573. if (feather_color > 0)
  4574. quest->SetFeatherColor(feather_color);
  4575. return 0;
  4576. }
  4577. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4578. if (!lua_interface)
  4579. return 0;
  4580. Spawn* spawn = lua_interface->GetSpawn(state);
  4581. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4582. if (!spawn) {
  4583. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4584. return 0;
  4585. }
  4586. if (!spawn2) {
  4587. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4588. return 0;
  4589. }
  4590. spawn->RemoveSpawnAccess(spawn2);
  4591. return 0;
  4592. }
  4593. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4594. if (!lua_interface)
  4595. return 0;
  4596. ZoneServer* zone = lua_interface->GetZone(state);
  4597. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4598. if (!zone) {
  4599. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4600. return 0;
  4601. }
  4602. if (location_id == 0) {
  4603. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4604. return 0;
  4605. }
  4606. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4607. if (!location) {
  4608. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4609. return 0;
  4610. }
  4611. Spawn* spawn = 0;
  4612. if (location->entities[0]) {
  4613. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4614. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4615. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4616. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4617. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4618. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4619. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4620. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4621. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4622. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4623. if (spawn) {
  4624. const char* script = 0;
  4625. for (int x = 0; x < 3; x++) {
  4626. switch (x) {
  4627. case 0:
  4628. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4629. break;
  4630. case 1:
  4631. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4632. break;
  4633. case 2:
  4634. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4635. break;
  4636. }
  4637. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4638. spawn->SetSpawnScript(string(script));
  4639. break;
  4640. }
  4641. }
  4642. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4643. lua_interface->SetSpawnValue(state, spawn);
  4644. return 1;
  4645. }
  4646. else {
  4647. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4648. safe_delete(spawn);
  4649. }
  4650. }
  4651. return 0;
  4652. }
  4653. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4654. if (!lua_interface)
  4655. return 0;
  4656. Spawn* caster = lua_interface->GetSpawn(state);
  4657. Spawn* target = lua_interface->GetSpawn(state, 2);
  4658. int32 id = lua_interface->GetInt32Value(state, 3);
  4659. string command = lua_interface->GetStringValue(state, 4);
  4660. if (!caster) {
  4661. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4662. return 0;
  4663. }
  4664. if (!target) {
  4665. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4666. return 0;
  4667. }
  4668. if (!caster->IsPlayer()) {
  4669. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4670. return 0;
  4671. }
  4672. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4673. if (!entity_command) {
  4674. 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());
  4675. return 0;
  4676. }
  4677. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4678. if (!client) {
  4679. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4680. return 0;
  4681. }
  4682. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4683. return 0;
  4684. }
  4685. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4686. if (!lua_interface)
  4687. return 0;
  4688. Spawn* spawn = lua_interface->GetSpawn(state);
  4689. if (!spawn) {
  4690. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4691. return 0;
  4692. }
  4693. if (!spawn->IsNPC()) {
  4694. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4695. return 0;
  4696. }
  4697. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4698. return 0;
  4699. }
  4700. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4701. if (!lua_interface)
  4702. return 0;
  4703. Spawn* spawn = lua_interface->GetSpawn(state);
  4704. int16 tick = lua_interface->GetInt16Value(state, 2);
  4705. if (!spawn) {
  4706. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4707. return 0;
  4708. }
  4709. if (!spawn->IsNPC()) {
  4710. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4711. return 0;
  4712. }
  4713. if (tick < 20) {
  4714. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4715. return 0;
  4716. }
  4717. ((NPC*)spawn)->Brain()->SetTick(tick);
  4718. return 0;
  4719. }
  4720. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4721. if (!lua_interface)
  4722. return 0;
  4723. Spawn* spawn = lua_interface->GetSpawn(state);
  4724. Spawn* target = lua_interface->GetSpawn(state, 2);
  4725. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4726. if (!spawn) {
  4727. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4728. return 0;
  4729. }
  4730. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4731. spawn->SetFollowTarget(target, follow_distance);
  4732. return 0;
  4733. }
  4734. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4735. if (!lua_interface)
  4736. return 0;
  4737. Spawn* spawn = lua_interface->GetSpawn(state);
  4738. if (!spawn) {
  4739. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4740. return 0;
  4741. }
  4742. Spawn* target = spawn->GetFollowTarget();
  4743. if (target) {
  4744. lua_interface->SetSpawnValue(state, target);
  4745. return 1;
  4746. }
  4747. return 0;
  4748. }
  4749. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4750. if (!lua_interface)
  4751. return 0;
  4752. Spawn* spawn = lua_interface->GetSpawn(state);
  4753. if (!spawn) {
  4754. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4755. return 0;
  4756. }
  4757. if (spawn->following)
  4758. spawn->following = false;
  4759. else
  4760. spawn->following = true;
  4761. return 0;
  4762. }
  4763. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4764. if (!lua_interface)
  4765. return 0;
  4766. Spawn* spawn = lua_interface->GetSpawn(state);
  4767. if (!spawn) {
  4768. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4769. return 0;
  4770. }
  4771. lua_interface->SetBooleanValue(state, spawn->following);
  4772. return 1;
  4773. }
  4774. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4775. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4776. // I will attempt to explain how this function works for future refrence
  4777. // Fist lets make sure lua_interface is valid, if not return out
  4778. if (!lua_interface)
  4779. return 0;
  4780. // Next we grab the first 2 params same as we usually would
  4781. Spawn* spawn = lua_interface->GetSpawn(state);
  4782. string var = lua_interface->GetStringValue(state, 2);
  4783. // 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
  4784. // 1 = Spawn
  4785. // 2 = Zone
  4786. // 3 = Item
  4787. // 4 = Quest
  4788. // 5 = String
  4789. // 6 = nil (null)
  4790. int8 dataType = 0;
  4791. // Define pointers for each potential type
  4792. Spawn* spawnVal = 0;
  4793. ZoneServer* zone = 0;
  4794. Item* item = 0;
  4795. Quest* quest = 0;
  4796. string val;
  4797. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4798. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4799. // options window are also light user data be we do not handle those.
  4800. // We check with lua_islightuserdata(lua_State*, index)
  4801. if (lua_islightuserdata(state, 3)) {
  4802. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4803. // and convert it to LUAUserData*
  4804. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4805. // Check to make sure the data we got is valid, if not give an error
  4806. if (!data || !data->IsCorrectlyInitialized()) {
  4807. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4808. }
  4809. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4810. else if (data->IsSpawn()) {
  4811. spawnVal = data->spawn;
  4812. dataType = 1;
  4813. }
  4814. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4815. else if (data->IsZone()) {
  4816. zone = data->zone;
  4817. dataType = 2;
  4818. }
  4819. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4820. else if (data->IsItem()) {
  4821. item = data->item;
  4822. dataType = 3;
  4823. }
  4824. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4825. else if (data->IsQuest()) {
  4826. quest = data->quest;
  4827. dataType = 4;
  4828. }
  4829. }
  4830. // Wasn't light user data, check if it is nil(null)
  4831. else if (lua_isnil(state, 3)) {
  4832. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4833. dataType = 6;
  4834. }
  4835. // Wasn't light user data or nil (null), must be a string
  4836. else {
  4837. // Set the string and dataType variable
  4838. val = lua_interface->GetStringValue(state, 3);
  4839. dataType = 5;
  4840. }
  4841. // We now have all the params, lets check to make sure they are valid
  4842. if (!spawn) {
  4843. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4844. return 0;
  4845. }
  4846. if (var.length() == 0) {
  4847. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4848. return 0;
  4849. }
  4850. if (dataType == 0) {
  4851. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4852. return 0;
  4853. }
  4854. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4855. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4856. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4857. switch (dataType) {
  4858. case 1:
  4859. // 1 = Spawn
  4860. spawn->AddTempVariable(var, spawnVal);
  4861. break;
  4862. case 2:
  4863. // 2 = Zone
  4864. spawn->AddTempVariable(var, zone);
  4865. break;
  4866. case 3:
  4867. // 3 = Item
  4868. spawn->AddTempVariable(var, item);
  4869. break;
  4870. case 4:
  4871. // 4 = Quest
  4872. spawn->AddTempVariable(var, quest);
  4873. break;
  4874. case 5:
  4875. // 5 = String
  4876. spawn->AddTempVariable(var, val);
  4877. break;
  4878. case 6:
  4879. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4880. spawn->DeleteTempVariable(var);
  4881. break;
  4882. }
  4883. // And we are done so return out
  4884. return 0;
  4885. }
  4886. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4887. if (!lua_interface)
  4888. return 0;
  4889. Spawn* spawn = lua_interface->GetSpawn(state);
  4890. string var = lua_interface->GetStringValue(state, 2);
  4891. if (!spawn) {
  4892. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4893. return 0;
  4894. }
  4895. if (var.length() == 0) {
  4896. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4897. return 0;
  4898. }
  4899. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4900. int8 type = spawn->GetTempVariableType(var);
  4901. Spawn* spawn2 = 0;
  4902. ZoneServer* zone = 0;
  4903. Item* item = 0;
  4904. Quest* quest = 0;
  4905. // Set the lua function return value based on the type of data the variable contains
  4906. switch (type) {
  4907. case 1:
  4908. spawn2 = spawn->GetTempVariableSpawn(var);
  4909. if (!spawn2)
  4910. return 0;
  4911. lua_interface->SetSpawnValue(state, spawn2);
  4912. break;
  4913. case 2:
  4914. zone = spawn->GetTempVariableZone(var);
  4915. if (!zone)
  4916. return 0;
  4917. lua_interface->SetZoneValue(state, zone);
  4918. break;
  4919. case 3:
  4920. item = spawn->GetTempVariableItem(var);
  4921. if (!item)
  4922. return 0;
  4923. lua_interface->SetItemValue(state, item);
  4924. break;
  4925. case 4:
  4926. quest = spawn->GetTempVariableQuest(var);
  4927. if (!quest)
  4928. return 0;
  4929. lua_interface->SetQuestValue(state, quest);
  4930. break;
  4931. case 5:
  4932. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4933. break;
  4934. default:
  4935. // Not a valid type then the variable was not set so return out
  4936. return 0;
  4937. }
  4938. // Return value was set so return out
  4939. return 1;
  4940. }
  4941. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4942. {
  4943. if (!lua_interface)
  4944. return 0;
  4945. Quest* quest = lua_interface->GetQuest(state);
  4946. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4947. string description = lua_interface->GetStringValue(state, 3);
  4948. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4949. if (!quest) {
  4950. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4951. lua_interface->SetBooleanValue(state, false);
  4952. return 1;
  4953. }
  4954. if (!spawn) {
  4955. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4956. lua_interface->SetBooleanValue(state, false);
  4957. return 1;
  4958. }
  4959. if (!spawn->IsPlayer()) {
  4960. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4961. lua_interface->SetBooleanValue(state, false);
  4962. return 1;
  4963. }
  4964. if (item_id == 0) {
  4965. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4966. lua_interface->SetBooleanValue(state, false);
  4967. return 1;
  4968. }
  4969. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4970. if (!client) {
  4971. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4972. lua_interface->SetBooleanValue(state, false);
  4973. return 1;
  4974. }
  4975. Item* item = master_item_list.GetItem(item_id);
  4976. if (!item) {
  4977. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4978. lua_interface->SetBooleanValue(state, false);
  4979. return 1;
  4980. }
  4981. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4982. if (packet) {
  4983. packet->setDataByName("title", "Quest Reward!");
  4984. packet->setDataByName("name", quest->GetName());
  4985. packet->setDataByName("description", description.c_str());
  4986. packet->setDataByName("level", quest->GetLevel());
  4987. packet->setArrayLengthByName("num_rewards", 1);
  4988. packet->setArrayDataByName("reward_id", item->details.item_id);
  4989. if (client->GetVersion() < 860)
  4990. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4991. else if (client->GetVersion() < 1193)
  4992. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4993. else
  4994. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4995. client->QueuePacket(packet->serialize());
  4996. safe_delete(packet);
  4997. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  4998. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  4999. return 1;
  5000. }
  5001. lua_interface->SetBooleanValue(state, false);
  5002. return 1;
  5003. }
  5004. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5005. if (!lua_interface)
  5006. return 0;
  5007. Quest* quest = lua_interface->GetQuest(state);
  5008. if (!quest) {
  5009. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5010. return 0;
  5011. }
  5012. quest->SetRepeatable(true);
  5013. return 0;
  5014. }
  5015. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5016. if (!lua_interface)
  5017. return 0;
  5018. Spawn* spawn = lua_interface->GetSpawn(state);
  5019. if (!spawn) {
  5020. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5021. return 0;
  5022. }
  5023. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5024. string ret = classes.GetClassNameCase(base_class);
  5025. if (ret.length() > 0) {
  5026. lua_interface->SetStringValue(state, ret.c_str());
  5027. return 1;
  5028. }
  5029. return 0;
  5030. }
  5031. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5032. if (!lua_interface)
  5033. return 0;
  5034. Spawn* player = lua_interface->GetSpawn(state);
  5035. if (player && player->IsPlayer()) {
  5036. Client* client = player->GetClient();
  5037. if (client)
  5038. client->SendWaypoints();
  5039. }
  5040. return 0;
  5041. }
  5042. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5043. if (!lua_interface)
  5044. return 0;
  5045. Spawn* player = lua_interface->GetSpawn(state);
  5046. string name = lua_interface->GetStringValue(state, 2);
  5047. int32 type = lua_interface->GetInt32Value(state, 3);
  5048. if (type == 0)
  5049. type = 2;
  5050. if (name.length() > 0) {
  5051. if (player && player->IsPlayer()) {
  5052. Client* client = player->GetClient();
  5053. if (client)
  5054. client->AddWaypoint(name, type);
  5055. }
  5056. }
  5057. return 0;
  5058. }
  5059. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5060. if (!lua_interface)
  5061. return 0;
  5062. Spawn* player = lua_interface->GetSpawn(state);
  5063. string name = lua_interface->GetStringValue(state, 2);
  5064. if (name.length() > 0) {
  5065. if (player && player->IsPlayer()) {
  5066. Client* client = player->GetClient();
  5067. if (client)
  5068. client->RemoveWaypoint(name);
  5069. }
  5070. }
  5071. return 0;
  5072. }
  5073. int EQ2Emu_lua_AddWard(lua_State* state) {
  5074. if (!lua_interface)
  5075. return 0;
  5076. int32 damage = lua_interface->GetInt32Value(state);
  5077. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5078. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5079. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5080. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5081. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5082. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5083. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5084. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5085. bool ward_was_added = false;
  5086. ZoneServer* zone = spell->caster->GetZone();
  5087. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5088. for (int32 i = 0; i < spell->targets.size(); i++) {
  5089. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5090. if (!target)
  5091. continue;
  5092. if (target->IsEntity()) {
  5093. // If the ward is already active remove it
  5094. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5095. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5096. // Create new ward info
  5097. WardInfo* ward = new WardInfo;
  5098. ward->Spell = spell;
  5099. ward->BaseDamage = damage;
  5100. ward->DamageLeft = damage;
  5101. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5102. ward->keepWard = keepWard;
  5103. ward->WardType = wardType;
  5104. if (damageAbsorptionPercent > 100)
  5105. damageAbsorptionPercent = 100;
  5106. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5107. if (damageAbsorptionMaxHealthPercent > 100)
  5108. damageAbsorptionMaxHealthPercent = 100;
  5109. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5110. ward->RedirectDamagePercent = redirectDamagePercent;
  5111. ward->LastRedirectDamage = 0;
  5112. ward->LastAbsorbedDamage = 0;
  5113. ward->HitCount = 0;
  5114. spell->num_triggers = maxHitCount;
  5115. spell->had_triggers = true;
  5116. spell->cancel_after_all_triggers = false;
  5117. ward->MaxHitCount = maxHitCount;
  5118. if (wardType == WARD_TYPE_MAGICAL)
  5119. ward->DamageType = damageTypes;
  5120. // Add the ward to the entity
  5121. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5122. ward_was_added = true;
  5123. }
  5124. }
  5125. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5126. if (ward_was_added && spell->caster->IsPlayer()) {
  5127. spell->had_dmg_remaining = true;
  5128. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5129. }
  5130. return 0;
  5131. }
  5132. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5133. if (!lua_interface)
  5134. return 0;
  5135. int32 amount = lua_interface->GetInt32Value(state);
  5136. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5137. WardInfo* ward = 0;
  5138. ZoneServer* zone = spell->caster->GetZone();
  5139. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5140. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5141. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5142. ward = target->GetWard(spell->spell->GetSpellID());
  5143. if (ward) {
  5144. ward->DamageLeft += amount;
  5145. if (ward->DamageLeft > ward->BaseDamage)
  5146. ward->DamageLeft = ward->BaseDamage;
  5147. for (int32 i = 0; i < spell->targets.size(); i++) {
  5148. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5149. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5150. }
  5151. }
  5152. }
  5153. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5154. if (ward && spell->caster->IsPlayer())
  5155. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5156. return 0;
  5157. }
  5158. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5159. if (!lua_interface)
  5160. return 0;
  5161. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5162. if (!spell) {
  5163. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5164. return 0;
  5165. }
  5166. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5167. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5168. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5169. if (ward) {
  5170. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5171. return 1;
  5172. }
  5173. }
  5174. return 0;
  5175. }
  5176. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5177. if (!lua_interface)
  5178. return 0;
  5179. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5180. if (!spell) {
  5181. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5182. return 0;
  5183. }
  5184. string type = lua_interface->GetStringValue(state, 2);
  5185. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5186. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5187. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5188. if (ward) {
  5189. if (boost::iequals(type, "damageleft"))
  5190. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5191. else if (boost::iequals(type, "basedamage"))
  5192. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5193. else if (boost::iequals(type, "keepward"))
  5194. lua_interface->SetBooleanValue(state, ward->keepWard);
  5195. else if (boost::iequals(type, "wardtype"))
  5196. lua_interface->SetInt32Value(state, ward->WardType);
  5197. else if (boost::iequals(type, "dmgabsorptionpct"))
  5198. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5199. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5200. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5201. else if (boost::iequals(type, "redirectdamagepercent"))
  5202. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5203. else if (boost::iequals(type, "lastredirectdamage"))
  5204. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5205. else if (boost::iequals(type, "lastabsorbeddamage"))
  5206. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5207. else if (boost::iequals(type, "hitcount"))
  5208. lua_interface->SetInt32Value(state, ward->HitCount);
  5209. else if (boost::iequals(type, "maxhitcount"))
  5210. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5211. else
  5212. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5213. return 1;
  5214. }
  5215. }
  5216. return 0;
  5217. }
  5218. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5219. if (!lua_interface)
  5220. return 0;
  5221. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5222. ZoneServer* zone = spell->caster->GetZone();
  5223. Spawn* target = 0;
  5224. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5225. for (int32 i = 0; i < spell->targets.size(); i++) {
  5226. target = zone->GetSpawnByID(spell->targets.at(i));
  5227. if (target && target->IsEntity()) {
  5228. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5229. }
  5230. }
  5231. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5232. return 0;
  5233. }
  5234. int EQ2Emu_lua_Interrupt(lua_State* state)
  5235. {
  5236. if (!lua_interface)
  5237. return 0;
  5238. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5239. Spawn* target = lua_interface->GetSpawn(state, 2);
  5240. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5241. if (!caster)
  5242. {
  5243. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5244. return 0;
  5245. }
  5246. if (!target)
  5247. {
  5248. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5249. return 0;
  5250. }
  5251. if (!spell) {
  5252. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5253. return 0;
  5254. }
  5255. if (!target->IsEntity() && !spell)
  5256. {
  5257. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5258. return 0;
  5259. }
  5260. if (!target && spell) {
  5261. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5262. for (int8 i = 0; i < spell->targets.size(); i++) {
  5263. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5264. if (!target || !target->IsEntity())
  5265. continue;
  5266. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5267. }
  5268. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5269. }
  5270. else
  5271. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5272. return 0;
  5273. }
  5274. int EQ2Emu_lua_Stealth(lua_State* state) {
  5275. if (!lua_interface)
  5276. return 0;
  5277. int8 type = lua_interface->GetInt8Value(state);
  5278. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5279. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5280. if (!spell) {
  5281. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5282. return 0;
  5283. }
  5284. ZoneServer* zone = spell->caster->GetZone();
  5285. if (spawn) {
  5286. if (spawn->IsEntity()) {
  5287. if (type == 1) {
  5288. ((Entity*)spawn)->AddStealthSpell(spell);
  5289. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5290. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5291. }
  5292. else if (type == 2) {
  5293. ((Entity*)spawn)->AddInvisSpell(spell);
  5294. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5295. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5296. }
  5297. return 0;
  5298. }
  5299. else {
  5300. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5301. return 0;
  5302. }
  5303. }
  5304. else {
  5305. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5306. for (int32 i = 0; i < spell->targets.size(); i++) {
  5307. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5308. if (!spawn || !spawn->IsEntity())
  5309. continue;
  5310. if (type == 1) {
  5311. ((Entity*)spawn)->AddStealthSpell(spell);
  5312. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5313. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5314. }
  5315. else if (type == 2) {
  5316. ((Entity*)spawn)->AddInvisSpell(spell);
  5317. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5318. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5319. }
  5320. else {
  5321. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5322. break;
  5323. }
  5324. }
  5325. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5326. }
  5327. return 0;
  5328. }
  5329. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5330. if (!lua_interface)
  5331. return 0;
  5332. Spawn* spawn = lua_interface->GetSpawn(state);
  5333. if (!spawn) {
  5334. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5335. return 0;
  5336. }
  5337. if (spawn->IsEntity()) {
  5338. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5339. return 1;
  5340. }
  5341. else
  5342. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5343. return 0;
  5344. }
  5345. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5346. if (!lua_interface)
  5347. return 0;
  5348. Spawn* spawn = lua_interface->GetSpawn(state);
  5349. if (!spawn) {
  5350. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5351. return 0;
  5352. }
  5353. if (spawn->IsEntity()) {
  5354. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5355. return 1;
  5356. }
  5357. else
  5358. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5359. return 0;
  5360. }
  5361. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5362. if (!lua_interface)
  5363. return 0;
  5364. Spawn* player = lua_interface->GetSpawn(state);
  5365. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5366. if (!player->IsPlayer()) {
  5367. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5368. return 0;
  5369. }
  5370. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5371. return 1;
  5372. }
  5373. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5374. if (!lua_interface)
  5375. return 0;
  5376. Spawn* player = lua_interface->GetSpawn(state);
  5377. int8 slot = lua_interface->GetInt8Value(state, 2);
  5378. if (!player) {
  5379. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5380. return 0;
  5381. }
  5382. if (!player->IsPlayer()) {
  5383. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5384. return 0;
  5385. }
  5386. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5387. if (!item) {
  5388. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5389. return 0;
  5390. }
  5391. lua_interface->SetItemValue(state, item);
  5392. return 1;
  5393. }
  5394. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5395. if (!lua_interface)
  5396. return 0;
  5397. Spawn* player = lua_interface->GetSpawn(state);
  5398. int32 id = lua_interface->GetInt32Value(state, 2);
  5399. if (!player) {
  5400. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5401. return 0;
  5402. }
  5403. if (!player->IsPlayer()) {
  5404. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5405. return 0;
  5406. }
  5407. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5408. if (!item) {
  5409. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5410. return 0;
  5411. }
  5412. lua_interface->SetItemValue(state, item);
  5413. return 1;
  5414. }
  5415. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5416. if (!lua_interface)
  5417. return 0;
  5418. Spawn* player = lua_interface->GetSpawn(state);
  5419. int32 id = lua_interface->GetInt32Value(state, 2);
  5420. int8 count = lua_interface->GetInt8Value(state, 3);
  5421. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5422. if (!player) {
  5423. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5424. return 0;
  5425. }
  5426. if (!player->IsPlayer()) {
  5427. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5428. return 0;
  5429. }
  5430. if (!count)
  5431. count = 1;
  5432. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5433. if (!item) {
  5434. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5435. return 0;
  5436. }
  5437. lua_interface->SetItemValue(state, item);
  5438. return 1;
  5439. }
  5440. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5441. if (!lua_interface)
  5442. return 0;
  5443. Spawn* spawn = lua_interface->GetSpawn(state);
  5444. int32 anim = lua_interface->GetInt32Value(state, 2);
  5445. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5446. int8 type = lua_interface->GetInt8Value(state, 4);
  5447. if (!spawn) {
  5448. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5449. return 0;
  5450. }
  5451. if (spawn2) {
  5452. if (spawn2->IsPlayer()) {
  5453. if (type != 1 && type != 2)
  5454. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5455. else
  5456. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5457. return 0;
  5458. }
  5459. else {
  5460. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5461. return 0;
  5462. }
  5463. }
  5464. else
  5465. spawn->GetZone()->PlayAnimation(spawn, anim);
  5466. return 0;
  5467. }
  5468. int EQ2Emu_lua_IsPet(lua_State* state) {
  5469. if (!lua_interface)
  5470. return 0;
  5471. Spawn* spawn = lua_interface->GetSpawn(state);
  5472. if (!spawn) {
  5473. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5474. return 0;
  5475. }
  5476. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5477. return 1;
  5478. }
  5479. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5480. if (!lua_interface)
  5481. return 0;
  5482. Spawn* spawn = lua_interface->GetSpawn(state);
  5483. if (!spawn) {
  5484. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5485. return 0;
  5486. }
  5487. if (!spawn->IsNPC()) {
  5488. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5489. return 0;
  5490. }
  5491. if (((NPC*)spawn)->GetOwner()) {
  5492. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5493. return 1;
  5494. }
  5495. return 0;
  5496. }
  5497. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5498. if (!lua_interface)
  5499. return 0;
  5500. Spawn* spawn = lua_interface->GetSpawn(state);
  5501. Spawn* target = lua_interface->GetSpawn(state, 2);
  5502. if (!spawn) {
  5503. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5504. return 0;
  5505. }
  5506. if (!spawn) {
  5507. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5508. return 0;
  5509. }
  5510. spawn->SetTarget(target);
  5511. return 0;
  5512. }
  5513. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5514. if (!lua_interface)
  5515. return 0;
  5516. Spawn* spawn = lua_interface->GetSpawn(state);
  5517. bool val = lua_interface->GetBooleanValue(state, 2);
  5518. if (!spawn) {
  5519. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5520. return 0;
  5521. }
  5522. if (!spawn->IsEntity()) {
  5523. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5524. return 0;
  5525. }
  5526. ((Entity*)spawn)->InCombat(val);
  5527. if (val) {
  5528. spawn->ClearRunningLocations();
  5529. spawn->CalculateRunningLocation(true);
  5530. }
  5531. return 0;
  5532. }
  5533. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5534. if (!lua_interface)
  5535. return 0;
  5536. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5537. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5538. if (!spawn1) {
  5539. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5540. return 0;
  5541. }
  5542. if (!spawn2) {
  5543. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5544. return 0;
  5545. }
  5546. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5547. return 1;
  5548. }
  5549. int EQ2Emu_lua_Runback(lua_State* state) {
  5550. if (!lua_interface)
  5551. return 0;
  5552. Spawn* spawn = lua_interface->GetSpawn(state);
  5553. if (!spawn) {
  5554. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5555. return 0;
  5556. }
  5557. if (!spawn->IsNPC()) {
  5558. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5559. return 0;
  5560. }
  5561. ((NPC*)spawn)->Runback();
  5562. return 0;
  5563. }
  5564. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5565. if (!lua_interface)
  5566. return 0;
  5567. Spawn* spawn = lua_interface->GetSpawn(state);
  5568. if (!spawn) {
  5569. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5570. return 0;
  5571. }
  5572. if (!spawn->IsNPC()) {
  5573. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5574. return 0;
  5575. }
  5576. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5577. return 1;
  5578. }
  5579. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5580. if (!lua_interface)
  5581. return 0;
  5582. Spawn* spawn = lua_interface->GetSpawn(state);
  5583. if (!spawn) {
  5584. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5585. return 0;
  5586. }
  5587. if (!spawn->IsEntity()) {
  5588. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5589. return 0;
  5590. }
  5591. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5592. return 1;
  5593. }
  5594. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5595. if (!lua_interface)
  5596. return 0;
  5597. Spawn* spawn = lua_interface->GetSpawn(state);
  5598. if (!spawn) {
  5599. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5600. return 0;
  5601. }
  5602. if (!spawn->IsEntity()) {
  5603. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5604. return 0;
  5605. }
  5606. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5607. return 1;
  5608. }
  5609. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5610. if (!lua_interface)
  5611. return 0;
  5612. Spawn* spawn = lua_interface->GetSpawn(state);
  5613. if (!spawn) {
  5614. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5615. return 0;
  5616. }
  5617. if (!spawn->IsEntity()) {
  5618. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5619. return 0;
  5620. }
  5621. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5622. return 1;
  5623. }
  5624. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5625. if (!lua_interface)
  5626. return 0;
  5627. Spawn* spawn = lua_interface->GetSpawn(state);
  5628. if (!spawn) {
  5629. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5630. return 0;
  5631. }
  5632. if (!spawn->IsEntity()) {
  5633. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5634. return 0;
  5635. }
  5636. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5637. return 1;
  5638. }
  5639. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5640. if (!lua_interface)
  5641. return 0;
  5642. Spawn* spawn = lua_interface->GetSpawn(state);
  5643. Spawn* target = lua_interface->GetSpawn(state, 2);
  5644. float distance = lua_interface->GetFloatValue(state, 3);
  5645. if (!spawn) {
  5646. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5647. return 0;
  5648. }
  5649. if (!target) {
  5650. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5651. return 0;
  5652. }
  5653. if (!spawn->IsNPC()) {
  5654. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5655. return 0;
  5656. }
  5657. if (!target->IsEntity()) {
  5658. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5659. return 0;
  5660. }
  5661. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5662. return 1;
  5663. }
  5664. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5665. if (!lua_interface)
  5666. return 0;
  5667. Spawn* spawn = lua_interface->GetSpawn(state);
  5668. Spawn* target = lua_interface->GetSpawn(state, 2);
  5669. float distance = lua_interface->GetFloatValue(state, 3);
  5670. if (!spawn) {
  5671. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5672. return 0;
  5673. }
  5674. if (!target) {
  5675. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5676. return 0;
  5677. }
  5678. if (!spawn->IsNPC()) {
  5679. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5680. return 0;
  5681. }
  5682. if (!target->IsEntity()) {
  5683. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5684. return 0;
  5685. }
  5686. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5687. return 0;
  5688. }
  5689. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5690. if (!lua_interface)
  5691. return 0;
  5692. Spawn* spawn = lua_interface->GetSpawn(state);
  5693. if (!spawn) {
  5694. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5695. return 0;
  5696. }
  5697. if (!spawn->IsNPC()) {
  5698. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5699. return 0;
  5700. }
  5701. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5702. return 1;
  5703. }
  5704. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5705. if (!lua_interface)
  5706. return 0;
  5707. Spawn* spawn = lua_interface->GetSpawn(state);
  5708. if (!spawn) {
  5709. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5710. return 0;
  5711. }
  5712. if (!spawn->IsNPC()) {
  5713. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5714. return 0;
  5715. }
  5716. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5717. return 1;
  5718. }
  5719. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5720. if (!lua_interface)
  5721. return 0;
  5722. Spawn* spawn = lua_interface->GetSpawn(state);
  5723. if (!spawn) {
  5724. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5725. return 0;
  5726. }
  5727. if (!spawn->IsNPC()) {
  5728. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5729. return 0;
  5730. }
  5731. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5732. if (hated) {
  5733. lua_interface->SetSpawnValue(state, hated);
  5734. return 1;
  5735. }
  5736. return 0;
  5737. }
  5738. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5739. if (!lua_interface)
  5740. return 0;
  5741. Spawn* spawn = lua_interface->GetSpawn(state);
  5742. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5743. if (!spawn) {
  5744. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5745. return 0;
  5746. }
  5747. if (!spawn->IsNPC()) {
  5748. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5749. return 0;
  5750. }
  5751. if (!hated) {
  5752. ((NPC*)spawn)->Brain()->ClearHate();
  5753. return 0;
  5754. }
  5755. else
  5756. {
  5757. if (!hated->IsEntity()) {
  5758. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5759. return 0;
  5760. }
  5761. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5762. return 0;
  5763. }
  5764. return 0;
  5765. }
  5766. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5767. if (!lua_interface)
  5768. return 0;
  5769. Spawn* spawn = lua_interface->GetSpawn(state);
  5770. if (!spawn) {
  5771. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5772. return 0;
  5773. }
  5774. if (!spawn->IsNPC()) {
  5775. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5776. return 0;
  5777. }
  5778. ((NPC*)spawn)->Brain()->ClearEncounter();
  5779. return 0;
  5780. }
  5781. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5782. if (!lua_interface)
  5783. return 0;
  5784. Spawn* spawn = lua_interface->GetSpawn(state);
  5785. if (!spawn) {
  5786. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5787. return 0;
  5788. }
  5789. if (!spawn->IsNPC()) {
  5790. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5791. return 0;
  5792. }
  5793. // Temp list to store hate list
  5794. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5795. if (encounterList->size() == 0) {
  5796. safe_delete(encounterList);
  5797. return 0;
  5798. }
  5799. lua_createtable(state, encounterList->size(), 0);
  5800. int newTable = lua_gettop(state);
  5801. for (int32 i = 0; i < encounterList->size(); i++) {
  5802. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5803. if (temp)
  5804. lua_interface->SetSpawnValue(state, temp);
  5805. lua_rawseti(state, newTable, i + 1);
  5806. }
  5807. safe_delete(encounterList);
  5808. return 1;
  5809. }
  5810. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5811. if (!lua_interface)
  5812. return 0;
  5813. Spawn* spawn = lua_interface->GetSpawn(state);
  5814. if (!spawn) {
  5815. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5816. return 0;
  5817. }
  5818. if (!spawn->IsNPC()) {
  5819. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5820. return 0;
  5821. }
  5822. // Temp list to store hate list
  5823. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5824. if (hateList->size() == 0) {
  5825. safe_delete(hateList);
  5826. return 0;
  5827. }
  5828. lua_createtable(state, hateList->size(), 0);
  5829. int newTable = lua_gettop(state);
  5830. for (int32 i = 0; i < hateList->size(); i++) {
  5831. lua_interface->SetSpawnValue(state, hateList->at(i));
  5832. lua_rawseti(state, newTable, i + 1);
  5833. }
  5834. safe_delete(hateList);
  5835. return 1;
  5836. }
  5837. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5838. if (!lua_interface)
  5839. return 0;
  5840. Spawn* spawn = lua_interface->GetSpawn(state);
  5841. if (!spawn) {
  5842. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5843. return 0;
  5844. }
  5845. if (spawn->IsPlayer()) {
  5846. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5847. lua_interface->SetBooleanValue(state, true);
  5848. else
  5849. lua_interface->SetBooleanValue(state, false);
  5850. return 1;
  5851. }
  5852. else {
  5853. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5854. return 1;
  5855. }
  5856. }
  5857. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5858. if (!lua_interface)
  5859. return 0;
  5860. Quest* quest = lua_interface->GetQuest(state);
  5861. if (!quest) {
  5862. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. quest->SetCompletedFlag(true);
  5866. return 0;
  5867. }
  5868. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5869. if (!lua_interface)
  5870. return 0;
  5871. Spawn* spawn = lua_interface->GetSpawn(state);
  5872. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5873. int8 tier = lua_interface->GetInt8Value(state, 3);
  5874. if (!spawn) {
  5875. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5876. return 0;
  5877. }
  5878. if (!spawn->IsEntity()) {
  5879. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5880. return 0;
  5881. }
  5882. if (spellID == 0) {
  5883. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5884. return 0;
  5885. }
  5886. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5887. if (effect) {
  5888. if (tier > 0) {
  5889. // If a tier was passed chec to see if it is the same as the effect
  5890. if (tier == effect->tier)
  5891. lua_interface->SetBooleanValue(state, true);
  5892. else
  5893. lua_interface->SetBooleanValue(state, false);
  5894. return 1;
  5895. }
  5896. else {
  5897. // Have an effect but no tier was passed so return true
  5898. lua_interface->SetBooleanValue(state, true);
  5899. }
  5900. return 1;
  5901. }
  5902. // no effect so return false
  5903. lua_interface->SetBooleanValue(state, false);
  5904. return 1;
  5905. }
  5906. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5907. if (!lua_interface)
  5908. return 0;
  5909. Spawn* spawn = lua_interface->GetSpawn(state);
  5910. int32 id = lua_interface->GetInt32Value(state, 2);
  5911. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5912. Spawn* spawn2 = 0;
  5913. vector<Spawn*> list;
  5914. if (!spawn) {
  5915. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5916. return 0;
  5917. }
  5918. //If zone not provided, use spawn's zone
  5919. if (!zone)
  5920. zone = spawn->GetZone();
  5921. list = zone->GetSpawnsByID(id);
  5922. if (list.size() == 0) {
  5923. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5924. return 0;
  5925. }
  5926. vector<Spawn*>::iterator itr = list.begin();
  5927. for (int8 i = 0; i < list.size(); i++) {
  5928. spawn2 = itr[i];
  5929. if (spawn2)
  5930. spawn2->AddAllowAccessSpawn(spawn);
  5931. }
  5932. return 0;
  5933. }
  5934. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5935. if (!lua_interface)
  5936. return 0;
  5937. Spawn* spawn = lua_interface->GetSpawn(state);
  5938. int32 id = lua_interface->GetInt32Value(state, 2);
  5939. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5940. Spawn* spawn2 = 0;
  5941. if (!spawn) {
  5942. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5943. return 0;
  5944. }
  5945. //If zone not provided, use spawn's zone
  5946. if (!zone)
  5947. zone = spawn->GetZone();
  5948. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5949. vector<Spawn*>::iterator itr = list.begin();
  5950. if (list.size() == 0) {
  5951. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5952. return 0;
  5953. }
  5954. for (int8 i = 0; i < list.size(); i++) {
  5955. spawn2 = itr[i];
  5956. if (spawn2)
  5957. spawn2->RemoveSpawnAccess(spawn);
  5958. }
  5959. return 0;
  5960. }
  5961. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5962. if (!lua_interface)
  5963. return 0;
  5964. Quest* quest = lua_interface->GetQuest(state);
  5965. if (!quest) {
  5966. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5967. return 0;
  5968. }
  5969. quest->SetYellowName(true);
  5970. return 0;
  5971. }
  5972. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5973. if (!lua_interface)
  5974. return 0;
  5975. Spawn* spawn = lua_interface->GetSpawn(state);
  5976. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5977. if (!spawn) {
  5978. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5979. return 0;
  5980. }
  5981. if (!spawn->IsPlayer()) {
  5982. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5983. return 0;
  5984. }
  5985. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5986. return 1;
  5987. }
  5988. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5989. if (!lua_interface)
  5990. return 0;
  5991. Spawn* spawn = lua_interface->GetSpawn(state);
  5992. if (!spawn) {
  5993. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5994. return 0;
  5995. }
  5996. if (!spawn->IsPlayer()) {
  5997. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5998. return 0;
  5999. }
  6000. ZoneServer* zone = spawn->GetZone();
  6001. if (!zone) {
  6002. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6003. return 0;
  6004. }
  6005. Instance_Type iType = zone->GetInstanceType();
  6006. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6007. iType == GROUP_LOCKOUT_INSTANCE ||
  6008. iType == RAID_LOCKOUT_INSTANCE ||
  6009. iType == SOLO_PERSIST_INSTANCE ||
  6010. iType == GROUP_PERSIST_INSTANCE ||
  6011. iType == RAID_PERSIST_INSTANCE) {
  6012. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6013. if (data) {
  6014. // Check to see if the timer has already been set, if it has return out.
  6015. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6016. return 0;
  6017. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6018. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6019. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6020. if (client) {
  6021. string time_msg = "";
  6022. int32 time = data->success_lockout_time;
  6023. int16 hour;
  6024. int8 min;
  6025. int8 sec;
  6026. hour = time / 3600;
  6027. time = time % 3600;
  6028. min = time / 60;
  6029. time = time % 60;
  6030. sec = time;
  6031. if (hour > 0) {
  6032. char temp[10];
  6033. sprintf(temp, " %i", hour);
  6034. time_msg.append(temp);
  6035. time_msg.append(" hour");
  6036. time_msg.append((hour > 1) ? "s" : "");
  6037. }
  6038. if (min > 0) {
  6039. char temp[5];
  6040. sprintf(temp, " %i", min);
  6041. time_msg.append(temp);
  6042. time_msg.append(" minute");
  6043. time_msg.append((min > 1) ? "s" : "");
  6044. }
  6045. // Only add seconds if minutes and hours are 0
  6046. if (hour == 0 && min == 0 && sec > 0) {
  6047. char temp[5];
  6048. sprintf(temp, " %i", sec);
  6049. time_msg.append(temp);
  6050. time_msg.append(" second");
  6051. time_msg.append((sec > 1) ? "s" : "");
  6052. }
  6053. 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());
  6054. }
  6055. }
  6056. else
  6057. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6058. }
  6059. else
  6060. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6061. return 0;
  6062. }
  6063. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6064. if (!lua_interface)
  6065. return 0;
  6066. Spawn* spawn = lua_interface->GetSpawn(state);
  6067. if (!spawn) {
  6068. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6069. return 0;
  6070. }
  6071. if (!spawn->IsPlayer()) {
  6072. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6073. return 0;
  6074. }
  6075. ZoneServer* zone = spawn->GetZone();
  6076. if (!zone) {
  6077. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6078. return 0;
  6079. }
  6080. Instance_Type iType = zone->GetInstanceType();
  6081. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6082. iType == GROUP_LOCKOUT_INSTANCE ||
  6083. iType == RAID_LOCKOUT_INSTANCE ||
  6084. iType == SOLO_PERSIST_INSTANCE ||
  6085. iType == GROUP_PERSIST_INSTANCE ||
  6086. iType == RAID_PERSIST_INSTANCE) {
  6087. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6088. if (data) {
  6089. // Check to see if the timer has already been set, if it has return out.
  6090. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6091. return 0;
  6092. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6093. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6094. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6095. if (client) {
  6096. string time_msg = "";
  6097. int32 time = data->failure_lockout_time;
  6098. int16 hour;
  6099. int8 min;
  6100. int8 sec;
  6101. hour = time / 3600;
  6102. time = time % 3600;
  6103. min = time / 60;
  6104. time = time % 60;
  6105. sec = time;
  6106. if (hour > 0) {
  6107. char temp[10];
  6108. sprintf(temp, " %i", hour);
  6109. time_msg.append(temp);
  6110. time_msg.append(" hour");
  6111. time_msg.append((hour > 1) ? "s" : "");
  6112. }
  6113. if (min > 0) {
  6114. char temp[5];
  6115. sprintf(temp, " %i", min);
  6116. time_msg.append(temp);
  6117. time_msg.append(" minute");
  6118. time_msg.append((min > 1) ? "s" : "");
  6119. }
  6120. // Only add seconds if minutes and hours are 0
  6121. if (hour == 0 && min == 0 && sec > 0) {
  6122. char temp[5];
  6123. sprintf(temp, " %i", sec);
  6124. time_msg.append(temp);
  6125. time_msg.append(" second");
  6126. time_msg.append((sec > 1) ? "s" : "");
  6127. }
  6128. 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());
  6129. }
  6130. }
  6131. else
  6132. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6133. }
  6134. else
  6135. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6139. if (!lua_interface)
  6140. return 0;
  6141. Spawn* spawn = lua_interface->GetSpawn(state);
  6142. if (!spawn) {
  6143. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6147. return 1;
  6148. }
  6149. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6150. if (!lua_interface)
  6151. return 0;
  6152. Spawn* player = lua_interface->GetSpawn(state);
  6153. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6154. if (!player) {
  6155. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6156. return 0;
  6157. }
  6158. if (!player->IsPlayer()) {
  6159. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6160. return 0;
  6161. }
  6162. if (!ground) {
  6163. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6164. return 0;
  6165. }
  6166. if (!ground->IsGroundSpawn()) {
  6167. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6168. return 0;
  6169. }
  6170. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6171. if (!groundspawn_entries) {
  6172. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6173. return 0;
  6174. }
  6175. Skill* skill = 0;
  6176. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6177. if (collection_skill == "Collecting")
  6178. skill = ((Player*)player)->GetSkillByName("Gathering");
  6179. else
  6180. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6181. if (!skill) {
  6182. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6183. return 0;
  6184. }
  6185. vector<GroundSpawnEntry*>::iterator itr;
  6186. GroundSpawnEntry* entry = 0;
  6187. bool can_harvest = false;
  6188. sint32 min_skill = -1;
  6189. // first, iterate through groundspawn_entries, discard tables player cannot use
  6190. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6191. {
  6192. entry = *itr;
  6193. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6194. min_skill = entry->min_skill_level;
  6195. // if player lacks skill, skip table
  6196. if (entry->min_skill_level > skill->current_val)
  6197. continue;
  6198. // if bonus, but player lacks level, skip table
  6199. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6200. continue;
  6201. can_harvest = true;
  6202. break;
  6203. }
  6204. lua_interface->SetBooleanValue(state, can_harvest);
  6205. // If false, send the message to the client
  6206. if (!can_harvest) {
  6207. Client* client = player->GetZone()->GetClientBySpawn(player);
  6208. if (client) {
  6209. string msg = "You do not have enough skill to ";
  6210. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6211. msg.append("gather");
  6212. else if (collection_skill == "Mining")
  6213. msg.append("mine");
  6214. else if (collection_skill == "Trapping")
  6215. msg.append("trap");
  6216. else if (collection_skill == "Foresting")
  6217. msg.append("forest");
  6218. else if (collection_skill == "Fishing")
  6219. msg.append("catch");
  6220. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6221. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  6222. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6223. }
  6224. }
  6225. return 1;
  6226. }
  6227. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6228. if (!lua_interface)
  6229. return 0;
  6230. Spawn* player = lua_interface->GetSpawn(state);
  6231. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6232. if (!player) {
  6233. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6234. return 0;
  6235. }
  6236. if (!player->IsPlayer()) {
  6237. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6241. lua_interface->SetBooleanValue(state, ret);
  6242. return 1;
  6243. }
  6244. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6245. // Check to see if we have a valid lua_interface
  6246. if (!lua_interface)
  6247. return 0;
  6248. // Get the spawn that is getting the pet
  6249. Spawn* spawn = lua_interface->GetSpawn(state);
  6250. Spawn* target = lua_interface->GetSpawn(state, 2);
  6251. // Get the DB ID of the pet
  6252. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6253. float x = lua_interface->GetFloatValue(state, 4);
  6254. float y = lua_interface->GetFloatValue(state, 5);
  6255. float z = lua_interface->GetFloatValue(state, 6);
  6256. // Get the spell that this command was called from
  6257. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6258. // Check to make sure the spawn pointer is valid
  6259. if (!spawn) {
  6260. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6261. return 0;
  6262. }
  6263. // Check to make sure the spawn is an entity
  6264. if (!spawn->IsEntity()) {
  6265. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6266. return 0;
  6267. }
  6268. if (!target) {
  6269. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6270. return 0;
  6271. }
  6272. if (!target->IsEntity()) {
  6273. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6274. return 0;
  6275. }
  6276. // Check to see if the DB ID for the pet is set
  6277. if (pet_id == 0) {
  6278. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6279. return 0;
  6280. }
  6281. // Check to see if the pointer to the spell is valid
  6282. if (!luaspell) {
  6283. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6284. return 0;
  6285. }
  6286. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6287. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6288. if (!pet) {
  6289. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6290. return 0;
  6291. }
  6292. // Check to make sure the pet is an npc
  6293. if (!pet->IsNPC()) {
  6294. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6295. return 0;
  6296. }
  6297. if (x == 0)
  6298. x = spawn->GetX();
  6299. if (y == 0)
  6300. y = spawn->GetY();
  6301. if (z == 0)
  6302. z = spawn->GetZ();
  6303. // Spawn the pet at the same location as the owner
  6304. pet->SetX(x);
  6305. pet->SetY(y);
  6306. pet->SetZ(z);
  6307. pet->SetLocation(spawn->GetLocation());
  6308. pet->SetHeading(spawn->GetHeading());
  6309. spawn->GetZone()->AddSpawn(pet);
  6310. /*
  6311. const char* spawn_script = world.GetSpawnScript(pet_id);
  6312. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6313. spawn->SetSpawnScript(string(spawn_script));
  6314. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6315. }*/
  6316. // Get a random pet name
  6317. string random_pet_name;
  6318. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6319. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6320. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6321. // Set the pets name
  6322. pet->SetName(random_pet_name.c_str());
  6323. // Set the level of the pet to the owners level
  6324. pet->SetLevel(spawn->GetLevel());
  6325. // Set the faction of the pet to the same faction as the owner
  6326. pet->SetFactionID(spawn->GetFactionID());
  6327. // Set the spawn as a pet
  6328. pet->SetPet(true);
  6329. // Give a pointer of the owner to the pet
  6330. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6331. // Set the pet type
  6332. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6333. // Set the spell id used to create this pet
  6334. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6335. // Set the spell tier used to create this pet
  6336. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6337. // Set the pets spawn type to 6
  6338. pet->SetSpawnType(6);
  6339. // Set the pets brain
  6340. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6341. // Check to see if the pet has a subtitle
  6342. if (strlen(pet->GetSubTitle()) > 0) {
  6343. // Add the players name to the front of the sub title
  6344. string pet_subtitle;
  6345. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6346. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6347. // Set the pets subtitle to the new one
  6348. pet->SetSubTitle(pet_subtitle.c_str());
  6349. }
  6350. // Set the pet as the return value for this function
  6351. lua_interface->SetSpawnValue(state, pet);
  6352. return 1;
  6353. }
  6354. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6355. if (!lua_interface)
  6356. return 0;
  6357. Spawn* spawn = lua_interface->GetSpawn(state);
  6358. Spawn* player = lua_interface->GetSpawn(state, 2);
  6359. float max_distance = lua_interface->GetFloatValue(state, 3);
  6360. string type = lua_interface->GetStringValue(state, 4);
  6361. if (!spawn || (spawn && spawn->IsPlayer())) {
  6362. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6363. return 0;
  6364. }
  6365. if (!player || (player && !player->IsPlayer())) {
  6366. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6367. return 0;
  6368. }
  6369. Client* client = 0;
  6370. if (player->GetZone())
  6371. client = player->GetZone()->GetClientBySpawn(player);
  6372. if (!client) {
  6373. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6374. return 0;
  6375. }
  6376. //Set max_distance to default if not set or not proper value
  6377. if (max_distance <= 0)
  6378. max_distance = 500;
  6379. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6380. if (packet) {
  6381. float unknown2_3 = 0;
  6382. int8 placement_mode = 0;
  6383. if (type == "wall") {
  6384. placement_mode = 2;
  6385. unknown2_3 = 150;
  6386. }
  6387. else if (type == "ceiling")
  6388. placement_mode = 1;
  6389. packet->setDataByName("placement_mode", placement_mode);
  6390. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6391. packet->setDataByName("model_type", spawn->GetModelType());
  6392. packet->setDataByName("unknown", 1); //size
  6393. packet->setDataByName("unknown2", 1); //size 2
  6394. packet->setDataByName("unknown2", .5, 1); //size 3
  6395. packet->setDataByName("unknown2", 3, 2);
  6396. packet->setDataByName("unknown2", unknown2_3, 3);
  6397. packet->setDataByName("max_distance", max_distance);
  6398. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6399. client->QueuePacket(packet->serialize());
  6400. safe_delete(packet);
  6401. }
  6402. return 0;
  6403. }
  6404. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6405. if (!lua_interface)
  6406. return 0;
  6407. Item* item = lua_interface->GetItem(state);
  6408. if (!item) {
  6409. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6410. return 0;
  6411. }
  6412. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6413. return 1;
  6414. }
  6415. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6416. if (!lua_interface)
  6417. return 0;
  6418. Spawn* spawn = lua_interface->GetSpawn(state);
  6419. if (!spawn) {
  6420. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6421. return 0;
  6422. }
  6423. if (spawn->GetZone())
  6424. spawn->GetZone()->AddTransportSpawn(spawn);
  6425. return 0;
  6426. }
  6427. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6428. if (!lua_interface)
  6429. return 0;
  6430. Skill* skill = lua_interface->GetSkill(state);
  6431. if (!skill) {
  6432. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6433. return 0;
  6434. }
  6435. lua_interface->SetInt32Value(state, skill->current_val);
  6436. return 1;
  6437. }
  6438. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6439. if (!lua_interface)
  6440. return 0;
  6441. Skill* skill = lua_interface->GetSkill(state);
  6442. if (!skill) {
  6443. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6444. return 0;
  6445. }
  6446. lua_interface->SetInt32Value(state, skill->max_val);
  6447. return 1;
  6448. }
  6449. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6450. if (!lua_interface)
  6451. return 0;
  6452. Skill* skill = lua_interface->GetSkill(state);
  6453. if (!skill) {
  6454. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6455. return 0;
  6456. }
  6457. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6458. return 1;
  6459. }
  6460. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6461. if (!lua_interface)
  6462. return 0;
  6463. Skill* skill = lua_interface->GetSkill(state);
  6464. int16 value = lua_interface->GetInt16Value(state, 2);
  6465. if (!skill) {
  6466. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6467. return 0;
  6468. }
  6469. skill->max_val = value;
  6470. if (skill->max_val < skill->current_val)
  6471. skill->current_val = skill->max_val;
  6472. return 0;
  6473. }
  6474. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6475. if (!lua_interface)
  6476. return 0;
  6477. Skill* skill = lua_interface->GetSkill(state);
  6478. int16 value = lua_interface->GetInt16Value(state, 2);
  6479. if (!skill) {
  6480. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6481. return 0;
  6482. }
  6483. if (value > skill->max_val)
  6484. skill->current_val = skill->max_val;
  6485. else
  6486. skill->current_val = value;
  6487. return 0;
  6488. }
  6489. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6490. if (!lua_interface)
  6491. return 0;
  6492. Spawn* player = lua_interface->GetSpawn(state);
  6493. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6494. if (skill_id > 0 && player && player->IsPlayer()) {
  6495. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6496. return 1;
  6497. }
  6498. return 0;
  6499. }
  6500. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6501. if (!lua_interface)
  6502. return 0;
  6503. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6504. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6505. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6506. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6507. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6508. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6509. if (player_spawn && player_spawn->IsPlayer()) {
  6510. Player* player = (Player*)player_spawn;
  6511. bool added = false;
  6512. if (!player->skill_list.HasSkill(skill_id)) {
  6513. player->AddSkill(skill_id, current_val, max_val, true);
  6514. added = true;
  6515. }
  6516. if (!more_to_add) { //need to send update regardless, even if THIS skill wasn't added, otherwise if you have a list and the last item wasn't added but the previous ones were, it wouldn't send the update
  6517. Client* client = player->GetClient();
  6518. if (client) {
  6519. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6520. if (packet)
  6521. client->QueuePacket(packet);
  6522. }
  6523. }
  6524. if (added) {
  6525. lua_interface->SetBooleanValue(state, true);
  6526. return 1;
  6527. }
  6528. }
  6529. else {
  6530. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6531. }
  6532. }
  6533. else {
  6534. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6535. }
  6536. lua_interface->SetBooleanValue(state, false);
  6537. return 1;
  6538. }
  6539. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6540. if (!lua_interface)
  6541. return 0;
  6542. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6543. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6544. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6545. if (skill_id > 0) {
  6546. if (player_spawn && player_spawn->IsPlayer()) {
  6547. Player* player = (Player*)player_spawn;
  6548. if (player->skill_list.HasSkill(skill_id)) {
  6549. player->RemovePlayerSkill(skill_id);
  6550. if (!more_to_remove) {
  6551. Client* client = player->GetClient();
  6552. if (client) {
  6553. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6554. if (packet)
  6555. client->QueuePacket(packet);
  6556. }
  6557. }
  6558. }
  6559. }
  6560. else {
  6561. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6562. }
  6563. }
  6564. else {
  6565. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6566. }
  6567. return 0;
  6568. }
  6569. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6570. if (!lua_interface)
  6571. return 0;
  6572. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6573. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6574. int16 amount = lua_interface->GetInt8Value(state, 3);
  6575. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6576. if (amount > 0 && skill_type < 100) {
  6577. if (player_spawn && player_spawn->IsPlayer()) {
  6578. Player* player = (Player*)player_spawn;
  6579. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6580. if (!more_to_increase) {
  6581. Client* client = player->GetClient();
  6582. if (client) {
  6583. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6584. if (packet)
  6585. client->QueuePacket(packet);
  6586. }
  6587. }
  6588. }
  6589. else {
  6590. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6591. }
  6592. }
  6593. else {
  6594. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6595. }
  6596. return 0;
  6597. }
  6598. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6599. if (!lua_interface)
  6600. return 0;
  6601. Spawn* spawn = lua_interface->GetSpawn(state);
  6602. string name = lua_interface->GetStringValue(state, 2);
  6603. if (!spawn) {
  6604. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6605. return 0;
  6606. }
  6607. if (!spawn->IsEntity()) {
  6608. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6609. return 0;
  6610. }
  6611. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6612. if (skill) {
  6613. lua_interface->SetSkillValue(state, skill);
  6614. return 1;
  6615. }
  6616. return 0;
  6617. }
  6618. int EQ2Emu_lua_AddProc(lua_State* state) {
  6619. if (!lua_interface)
  6620. return 0;
  6621. Spawn* spawn = lua_interface->GetSpawn(state);
  6622. int8 type = lua_interface->GetInt8Value(state, 2);
  6623. float chance = lua_interface->GetFloatValue(state, 3);
  6624. Item* item = lua_interface->GetItem(state, 4);
  6625. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6626. LuaSpell* spell = 0;
  6627. if (!spawn && (!spell || !use_all_spelltargets)) {
  6628. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6629. return 0;
  6630. }
  6631. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6632. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6633. return 0;
  6634. }
  6635. if (!item)
  6636. spell = lua_interface->GetCurrentSpell(state);
  6637. if (!item && !spell) {
  6638. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6639. return 0;
  6640. }
  6641. if (spell && use_all_spelltargets) {
  6642. Spawn* target;
  6643. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6644. for (int8 i = 0; i < spell->targets.size(); i++) {
  6645. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6646. if (!target || !target->IsEntity())
  6647. continue;
  6648. ((Entity*)target)->AddProc(type, chance, item, spell);
  6649. }
  6650. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6651. }
  6652. else
  6653. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6654. return 0;
  6655. }
  6656. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6657. if (!lua_interface)
  6658. return 0;
  6659. Spawn* spawn = lua_interface->GetSpawn(state);
  6660. Item* item = lua_interface->GetItem(state, 2);
  6661. LuaSpell* spell = 0;
  6662. if (!spawn) {
  6663. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6664. return 0;
  6665. }
  6666. if (!spawn->IsEntity()) {
  6667. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6668. return 0;
  6669. }
  6670. if (!item)
  6671. spell = lua_interface->GetCurrentSpell(state);
  6672. if (!item && !spell) {
  6673. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6674. return 0;
  6675. }
  6676. if (spell) {
  6677. Spawn* target;
  6678. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6679. for (int8 i = 0; i < spell->targets.size(); i++) {
  6680. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6681. if (!target || !target->IsEntity())
  6682. continue;
  6683. ((Entity*)target)->RemoveProc(item, spell);
  6684. }
  6685. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6686. spell->caster->RemoveProc(item, spell);
  6687. }
  6688. else
  6689. ((Entity*)spawn)->RemoveProc(item, spell);
  6690. return 0;
  6691. }
  6692. int EQ2Emu_lua_Knockback(lua_State* state) {
  6693. if (!lua_interface)
  6694. return 0;
  6695. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6696. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6697. int32 duration = lua_interface->GetInt32Value(state, 3);
  6698. float vertical = lua_interface->GetFloatValue(state, 4);
  6699. float horizontal = lua_interface->GetFloatValue(state, 5);
  6700. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6701. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6702. if (!target_spawn) {
  6703. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6704. return 0;
  6705. }
  6706. if (!spawn) {
  6707. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6708. return 0;
  6709. }
  6710. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6711. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6712. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6713. if (packet) {
  6714. packet->setDataByName("target_x", target_spawn->GetX());
  6715. packet->setDataByName("target_y", target_spawn->GetY());
  6716. packet->setDataByName("target_z", target_spawn->GetZ());
  6717. packet->setDataByName("vertical_movement", vertical);
  6718. packet->setDataByName("horizontal_movement", horizontal);
  6719. if (use_heading)
  6720. packet->setDataByName("use_player_heading", 1);
  6721. client->QueuePacket(packet->serialize());
  6722. }
  6723. safe_delete(packet);
  6724. }
  6725. return 0;
  6726. }
  6727. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6728. if (!lua_interface)
  6729. return 0;
  6730. Spawn* spawn = lua_interface->GetSpawn(state);
  6731. if (!spawn) {
  6732. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6733. return 0;
  6734. }
  6735. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6736. return 1;
  6737. }
  6738. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6739. if (!lua_interface)
  6740. return 0;
  6741. Spawn* caster = lua_interface->GetSpawn(state);
  6742. Spawn* target = lua_interface->GetSpawn(state, 2);
  6743. string name = lua_interface->GetStringValue(state, 3);
  6744. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6745. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6746. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6747. string success_msg = lua_interface->GetStringValue(state, 7);
  6748. string effect_msg = lua_interface->GetStringValue(state, 8);
  6749. if (!caster) {
  6750. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6751. return 0;
  6752. }
  6753. if (!caster->IsEntity()) {
  6754. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6755. return 0;
  6756. }
  6757. if (!target) {
  6758. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6759. return 0;
  6760. }
  6761. if (!target->IsEntity()) {
  6762. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6763. return 0;
  6764. }
  6765. if (name.length() == 0) {
  6766. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6767. return 0;
  6768. }
  6769. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6770. return 0;
  6771. }
  6772. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6773. if (!lua_interface)
  6774. return 0;
  6775. string name = lua_interface->GetStringValue(state);
  6776. if (name.length() == 0) {
  6777. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6778. return 0;
  6779. }
  6780. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6781. if (!skill) {
  6782. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6783. return 0;
  6784. }
  6785. lua_interface->SetInt32Value(state, skill->skill_id);
  6786. return 1;
  6787. }
  6788. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6789. if (!lua_interface)
  6790. return 0;
  6791. Spawn* spawn = lua_interface->GetSpawn(state);
  6792. if (!spawn) {
  6793. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6794. return 0;
  6795. }
  6796. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6797. return 1;
  6798. }
  6799. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6800. if (!lua_interface)
  6801. return 0;
  6802. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6803. if (!luaspell) {
  6804. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6805. return 0;
  6806. }
  6807. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6808. return 1;
  6809. }
  6810. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6811. if (!lua_interface)
  6812. return 0;
  6813. Spawn* spawn = lua_interface->GetSpawn(state);
  6814. Spawn* target = lua_interface->GetSpawn(state, 2);
  6815. if (!spawn) {
  6816. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6817. return 0;
  6818. }
  6819. if (!spawn->IsEntity()) {
  6820. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6821. return 0;
  6822. }
  6823. if (!target) {
  6824. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6825. return 0;
  6826. }
  6827. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6828. return 1;
  6829. }
  6830. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6831. if (!lua_interface)
  6832. return 0;
  6833. Spawn* spawn = lua_interface->GetSpawn(state);
  6834. Spawn* target = lua_interface->GetSpawn(state, 2);
  6835. if (!spawn) {
  6836. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6837. return 0;
  6838. }
  6839. if (!spawn->IsEntity()) {
  6840. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6841. return 0;
  6842. }
  6843. if (!target) {
  6844. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6845. return 0;
  6846. }
  6847. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6848. return 1;
  6849. }
  6850. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6851. if (!lua_interface)
  6852. return 0;
  6853. Item* item = lua_interface->GetItem(state);
  6854. if (!item) {
  6855. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6856. return 0;
  6857. }
  6858. lua_interface->SetInt32Value(state, item->details.count);
  6859. return 1;
  6860. }
  6861. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6862. if (!lua_interface)
  6863. return 0;
  6864. Item* item = lua_interface->GetItem(state);
  6865. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6866. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6867. if (!item) {
  6868. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6869. return 0;
  6870. }
  6871. if (!owner) {
  6872. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6873. return 0;
  6874. }
  6875. if (!owner->IsPlayer()) {
  6876. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6877. return 0;
  6878. }
  6879. if (item->stack_count < new_count) {
  6880. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6881. return 0;
  6882. }
  6883. if (new_count > 0) {
  6884. item->details.count = new_count;
  6885. item->save_needed = true;
  6886. }
  6887. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6888. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6889. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6890. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6891. else
  6892. {
  6893. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6894. return 0;
  6895. }
  6896. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6897. if (!client)
  6898. return 0;
  6899. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6900. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6901. if (app)
  6902. client->QueuePacket(app);
  6903. return 0;
  6904. }
  6905. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6906. if (!lua_interface)
  6907. return 0;
  6908. int32 time = lua_interface->GetInt32Value(state);
  6909. string function = lua_interface->GetStringValue(state, 2);
  6910. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6911. Spawn* target = lua_interface->GetSpawn(state, 4);
  6912. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6913. if (time == 0) {
  6914. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6915. return 0;
  6916. }
  6917. if (function.length() == 0) {
  6918. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6919. return 0;
  6920. }
  6921. if (!spell) {
  6922. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6923. return 0;
  6924. }
  6925. SpellScriptTimer* timer = new SpellScriptTimer;
  6926. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6927. #ifdef WIN32
  6928. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6929. #else
  6930. bzero(timer, sizeof(SpellScriptTimer));
  6931. #endif*/
  6932. timer->caster = 0;
  6933. timer->deleteWhenDone = false;
  6934. timer->target = 0;
  6935. timer->time = Timer::GetCurrentTime2() + time;
  6936. timer->customFunction = function;
  6937. timer->spell = spell;
  6938. if (caster)
  6939. timer->caster = caster->GetID();
  6940. if (target)
  6941. timer->target = target->GetID();
  6942. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6943. return 0;
  6944. }
  6945. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6946. if (!lua_interface)
  6947. return 0;
  6948. float hp_perc = lua_interface->GetFloatValue(state);
  6949. float power_perc = lua_interface->GetFloatValue(state, 2);
  6950. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6951. Spawn* target = lua_interface->GetSpawn(state, 4);
  6952. string heal_name = lua_interface->GetStringValue(state, 5);
  6953. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6954. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6955. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6956. if (!spell) {
  6957. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6958. return 0;
  6959. }
  6960. Entity* caster = spell->caster;
  6961. if (!caster) {
  6962. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6963. return 0;
  6964. }
  6965. Client* client = 0;
  6966. PendingResurrection* rez = 0;
  6967. ZoneServer* zone = spell->caster->GetZone();
  6968. if (!target) {
  6969. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6970. if (spell->targets.size() > 0) {
  6971. vector<int32> spell_targets = spell->targets;
  6972. for (int8 i = 0; i < spell_targets.size(); i++) {
  6973. target = zone->GetSpawnByID(spell_targets.at(i));
  6974. if (!target)
  6975. continue;
  6976. if (!target->IsPlayer())
  6977. continue;
  6978. client = target->GetZone()->GetClientBySpawn(target);
  6979. if (!client)
  6980. continue;
  6981. rez = client->GetCurrentRez();
  6982. if (rez->active)
  6983. continue;
  6984. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6985. rez->active = true;
  6986. rez->caster = caster;
  6987. rez->expire_timer = new Timer;
  6988. int32 duration = spell->spell->GetSpellDuration();
  6989. rez->expire_timer->Start(duration * 100);
  6990. rez->hp_perc = hp_perc;
  6991. rez->mp_perc = power_perc;
  6992. rez->range = spell->spell->GetSpellData()->range;
  6993. rez->spell_name = spell->spell->GetName();
  6994. if (heal_name.length() > 0)
  6995. rez->heal_name = heal_name;
  6996. else
  6997. rez->heal_name = rez->spell_name;
  6998. rez->no_calcs = no_calcs;
  6999. rez->crit_mod = crit_mod;
  7000. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7001. if (send_window)
  7002. client->SendResurrectionWindow();
  7003. else {
  7004. target->GetZone()->ResurrectSpawn(target, client);
  7005. rez->should_delete = true;
  7006. }
  7007. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7008. }
  7009. }
  7010. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7011. }
  7012. else {
  7013. client = target->GetZone()->GetClientBySpawn(target);
  7014. if (!client)
  7015. return 0;
  7016. rez = client->GetCurrentRez();
  7017. if (rez->active)
  7018. return 0;
  7019. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7020. rez->active = true;
  7021. rez->caster = caster;
  7022. rez->expire_timer = new Timer;
  7023. int32 duration = spell->spell->GetSpellDuration();
  7024. rez->expire_timer->Start(duration * 100);
  7025. rez->hp_perc = hp_perc;
  7026. rez->mp_perc = power_perc;
  7027. rez->range = spell->spell->GetSpellData()->range;
  7028. rez->spell_name = spell->spell->GetName();
  7029. if (heal_name.length() > 0)
  7030. rez->heal_name = heal_name;
  7031. else
  7032. rez->heal_name = rez->spell_name;
  7033. rez->no_calcs = no_calcs;
  7034. rez->crit_mod = crit_mod;
  7035. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7036. if (send_window)
  7037. client->SendResurrectionWindow();
  7038. else {
  7039. target->GetZone()->ResurrectSpawn(target, client);
  7040. rez->should_delete = true;
  7041. }
  7042. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7043. }
  7044. return 0;
  7045. }
  7046. int EQ2Emu_lua_SetVision(lua_State* state) {
  7047. if (!lua_interface)
  7048. return 0;
  7049. Spawn* spawn = lua_interface->GetSpawn(state);
  7050. int8 vision = lua_interface->GetInt8Value(state, 2);
  7051. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7052. if (!spawn) {
  7053. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7054. return 0;
  7055. }
  7056. if (!spawn->IsEntity()) {
  7057. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7058. return 0;
  7059. }
  7060. if (spell && spell->targets.size() > 0) {
  7061. ZoneServer* zone = spell->caster->GetZone();
  7062. for (int8 i = 0; i < spell->targets.size(); i++) {
  7063. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7064. if (target->IsEntity()) {
  7065. ((Entity*)target)->GetInfoStruct()->vision = vision;
  7066. if (target->IsPlayer())
  7067. ((Player*)target)->SetCharSheetChanged(true);
  7068. }
  7069. }
  7070. }
  7071. else {
  7072. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  7073. if (spawn->IsPlayer())
  7074. ((Player*)spawn)->SetCharSheetChanged(true);
  7075. }
  7076. return 0;
  7077. }
  7078. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7079. if (!lua_interface)
  7080. return 0;
  7081. Spawn* spawn = lua_interface->GetSpawn(state);
  7082. float intensity = lua_interface->GetFloatValue(state, 2);
  7083. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7084. if (!spawn) {
  7085. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7086. return 0;
  7087. }
  7088. if (!spawn->IsEntity()) {
  7089. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7090. return 0;
  7091. }
  7092. if (spell && spell->targets.size() > 0) {
  7093. ZoneServer* zone = spell->caster->GetZone();
  7094. for (int8 i = 0; i < spell->targets.size(); i++) {
  7095. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7096. if (target && target->IsEntity()) {
  7097. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  7098. if (target->IsPlayer())
  7099. ((Player*)target)->SetCharSheetChanged(true);
  7100. }
  7101. }
  7102. }
  7103. else {
  7104. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  7105. if (spawn->IsPlayer())
  7106. ((Player*)spawn)->SetCharSheetChanged(true);
  7107. }
  7108. return 0;
  7109. }
  7110. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7111. if (!lua_interface)
  7112. return 0;
  7113. Spawn* spawn = lua_interface->GetSpawn(state);
  7114. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7115. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7116. if (!spawn) {
  7117. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7118. return 0;
  7119. }
  7120. if (!spawn->IsEntity()) {
  7121. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7122. return 0;
  7123. }
  7124. if (spell && spell->targets.size() > 0) {
  7125. ZoneServer* zone = spell->caster->GetZone();
  7126. for (int8 i = 0; i < spell->targets.size(); i++) {
  7127. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7128. if (target->IsEntity()) {
  7129. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  7130. if (target->IsPlayer())
  7131. ((Player*)target)->SetCharSheetChanged(true);
  7132. }
  7133. }
  7134. }
  7135. else {
  7136. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  7137. if (spawn->IsPlayer())
  7138. ((Player*)spawn)->SetCharSheetChanged(true);
  7139. }
  7140. return 0;
  7141. }
  7142. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7143. if (!lua_interface)
  7144. return 0;
  7145. Item* item = lua_interface->GetItem(state);
  7146. int8 type = lua_interface->GetInt32Value(state, 2);
  7147. if (!item) {
  7148. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7149. return 0;
  7150. }
  7151. if (type == 1)
  7152. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7153. else if (type == 2)
  7154. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7155. return 1;
  7156. }
  7157. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7158. if (!lua_interface)
  7159. return 0;
  7160. Spawn* target = lua_interface->GetSpawn(state);
  7161. float val = lua_interface->GetFloatValue(state, 2);
  7162. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7163. // Added from Gangrenous post
  7164. if (spell && spell->resisted)
  7165. return 0;
  7166. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7167. if (val > 1.0f)
  7168. val = 1.0f - (val / 100.0f);
  7169. if (spell && spell->spell && spell->targets.size() > 0) {
  7170. ZoneServer* zone = spell->caster->GetZone();
  7171. for (int32 i = 0; i != spell->targets.size(); i++) {
  7172. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7173. if (spawn && spawn->IsEntity()) {
  7174. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7175. if (spawn->IsPlayer())
  7176. ((Player*)spawn)->SetCharSheetChanged(true);
  7177. }
  7178. }
  7179. }
  7180. else {
  7181. if (target && target->IsEntity()) {
  7182. ((Entity*)target)->SetSpeedMultiplier(val);
  7183. if (target->IsPlayer())
  7184. ((Player*)target)->SetCharSheetChanged(true);
  7185. }
  7186. }
  7187. return 0;
  7188. }
  7189. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7190. if (!lua_interface)
  7191. return 0;
  7192. Spawn* spawn = lua_interface->GetSpawn(state);
  7193. int16 model = lua_interface->GetInt16Value(state, 2);
  7194. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7195. if (spell && spell->spell && spell->targets.size() > 0) {
  7196. ZoneServer* zone = spell->caster->GetZone();
  7197. for (int32 i = 0; i < spell->targets.size(); i++) {
  7198. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7199. if (target)
  7200. target->SetIllusionModel(model);
  7201. }
  7202. }
  7203. else {
  7204. if (!spawn) {
  7205. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7206. return 0;
  7207. }
  7208. spawn->SetIllusionModel(model);
  7209. }
  7210. return 0;
  7211. }
  7212. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7213. if (!lua_interface)
  7214. return 0;
  7215. Spawn* spawn = lua_interface->GetSpawn(state);
  7216. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7217. if (spell && spell->spell && spell->targets.size() > 0) {
  7218. ZoneServer* zone = spell->caster->GetZone();
  7219. for (int32 i = 0; i < spell->targets.size(); i++) {
  7220. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7221. if (target)
  7222. target->SetIllusionModel(0);
  7223. }
  7224. }
  7225. else {
  7226. if (!spawn) {
  7227. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7228. return 0;
  7229. }
  7230. spawn->SetIllusionModel(0);
  7231. }
  7232. return 0;
  7233. }
  7234. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7235. if (!lua_interface)
  7236. return 0;
  7237. Spawn* caster = lua_interface->GetSpawn(state);
  7238. Spawn* target = lua_interface->GetSpawn(state, 2);
  7239. float chance = lua_interface->GetFloatValue(state, 3);
  7240. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7241. if (!caster) {
  7242. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7243. return 0;
  7244. }
  7245. if (!caster->IsEntity()) {
  7246. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7247. return 0;
  7248. }
  7249. if (!target) {
  7250. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7251. return 0;
  7252. }
  7253. if (!target->IsEntity()) {
  7254. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7255. return 0;
  7256. }
  7257. if (chance <= 0) {
  7258. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7259. return 0;
  7260. }
  7261. if (!spell) {
  7262. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7263. return 0;
  7264. }
  7265. if (((Entity*)caster)->GetThreatTransfer()) {
  7266. return 0;
  7267. }
  7268. ThreatTransfer* transfer = new ThreatTransfer;
  7269. transfer->Target = target->GetID();
  7270. transfer->Amount = chance;
  7271. transfer->Spell = spell;
  7272. ((Entity*)caster)->SetThreatTransfer(transfer);
  7273. return 0;
  7274. }
  7275. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7276. if (!lua_interface)
  7277. return 0;
  7278. Spawn* spawn = lua_interface->GetSpawn(state);
  7279. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7280. if (!spawn) {
  7281. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7282. return 0;
  7283. }
  7284. if (!spell) {
  7285. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7286. return 0;
  7287. }
  7288. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7289. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7290. ((Entity*)spawn)->SetThreatTransfer(0);
  7291. safe_delete(transfer);
  7292. }
  7293. return 0;
  7294. }
  7295. int EQ2Emu_lua_CureByType(lua_State* state) {
  7296. if (!lua_interface)
  7297. return 0;
  7298. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7299. if (!spell) {
  7300. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7301. return 0;
  7302. }
  7303. int8 cure_count = lua_interface->GetInt8Value(state);
  7304. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7305. string cure_name = lua_interface->GetStringValue(state, 3);
  7306. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7307. Spawn* target = lua_interface->GetSpawn(state, 5);
  7308. if (target) {
  7309. if (!target->IsEntity()) {
  7310. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7311. return 0;
  7312. }
  7313. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7314. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7315. }
  7316. else {
  7317. ZoneServer* zone = spell->caster->GetZone();
  7318. vector<int32> targets = spell->targets;
  7319. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7320. for (int8 i = 0; i < targets.size(); i++) {
  7321. target = zone->GetSpawnByID(targets.at(i));
  7322. if (!target || !target->IsEntity())
  7323. continue;
  7324. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7325. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7326. }
  7327. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7328. }
  7329. return 0;
  7330. }
  7331. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7332. if (!lua_interface)
  7333. return 0;
  7334. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7335. if (!spell) {
  7336. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7337. return 0;
  7338. }
  7339. int8 cure_count = lua_interface->GetInt8Value(state);
  7340. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7341. string cure_name = lua_interface->GetStringValue(state, 3);
  7342. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7343. Spawn* target = lua_interface->GetSpawn(state, 5);
  7344. if (target) {
  7345. if (!target->IsEntity()) {
  7346. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7347. return 0;
  7348. }
  7349. if (((Entity*)target)->GetDetCount() > 0)
  7350. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7351. }
  7352. else {
  7353. ZoneServer* zone = spell->caster->GetZone();
  7354. vector<int32> targets = spell->targets;
  7355. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7356. for (int8 i = 0; i < targets.size(); i++) {
  7357. target = zone->GetSpawnByID(targets.at(i));
  7358. if (!target || !target->IsEntity())
  7359. continue;
  7360. if (((Entity*)target)->GetDetCount() > 0)
  7361. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7362. }
  7363. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7364. }
  7365. return 0;
  7366. }
  7367. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7368. if (!lua_interface)
  7369. return 0;
  7370. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7371. if (!spell) {
  7372. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7373. return 0;
  7374. }
  7375. if (!spell->caster) {
  7376. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7377. return 0;
  7378. }
  7379. if (!spell->caster->GetZone()) {
  7380. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7381. return 0;
  7382. }
  7383. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7384. return 0;
  7385. }
  7386. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7387. if (!lua_interface)
  7388. return 0;
  7389. Spawn* spawn = lua_interface->GetSpawn(state);
  7390. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7391. if (!spell) {
  7392. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7393. return 0;
  7394. }
  7395. if (spawn && spawn->IsEntity())
  7396. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7397. else {
  7398. ZoneServer* zone = spell->caster->GetZone();
  7399. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7400. for (int32 i = 0; i < spell->targets.size(); i++) {
  7401. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7402. if (!spawn || !spawn->IsEntity())
  7403. continue;
  7404. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7405. }
  7406. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7407. }
  7408. return 0;
  7409. }
  7410. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7411. if (!lua_interface)
  7412. return 0;
  7413. Spawn* spawn = lua_interface->GetSpawn(state);
  7414. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7415. if (!spell) {
  7416. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7417. return 0;
  7418. }
  7419. if (spawn && spawn->IsEntity())
  7420. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7421. else {
  7422. ZoneServer* zone = spell->caster->GetZone();
  7423. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7424. for (int32 i = 0; i < spell->targets.size(); i++) {
  7425. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7426. if (!spawn || !spawn->IsEntity())
  7427. continue;
  7428. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7429. }
  7430. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7431. }
  7432. return 0;
  7433. }
  7434. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7435. if (!lua_interface)
  7436. return 0;
  7437. Spawn* caster = lua_interface->GetSpawn(state);
  7438. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7439. if (!caster) {
  7440. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7441. return 0;
  7442. }
  7443. if (!caster->IsPlayer()) {
  7444. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7445. return 0;
  7446. }
  7447. Spawn* target = caster->GetTarget();
  7448. if (!target) {
  7449. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7450. return 0;
  7451. }
  7452. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7453. if (!client) {
  7454. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7455. return 0;
  7456. }
  7457. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7458. if (ho) {
  7459. ho->SetTarget(target->GetID());
  7460. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7461. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7462. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7463. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7464. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7465. deque<GroupMemberInfo*>::iterator itr;
  7466. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7467. if (group)
  7468. {
  7469. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7470. deque<GroupMemberInfo*>* members = group->GetMembers();
  7471. for (itr = members->begin(); itr != members->end(); itr++) {
  7472. if ((*itr)->client)
  7473. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7474. }
  7475. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7476. }
  7477. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7478. }
  7479. else
  7480. safe_delete(ho);
  7481. }
  7482. else {
  7483. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7484. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7485. }
  7486. else
  7487. safe_delete(ho);
  7488. }
  7489. }
  7490. return 0;
  7491. }
  7492. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7493. if (!lua_interface)
  7494. return 0;
  7495. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7496. if (!spell) {
  7497. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7498. return 0;
  7499. }
  7500. int16 triggerCount = lua_interface->GetInt16Value(state);
  7501. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7502. if (!triggerCount) {
  7503. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7504. return 0;
  7505. }
  7506. spell->num_triggers = triggerCount;
  7507. spell->had_triggers = true;
  7508. spell->cancel_after_all_triggers = cancel_after_triggers;
  7509. return 0;
  7510. }
  7511. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7512. if (!lua_interface)
  7513. return 0;
  7514. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7515. if (!spell) {
  7516. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7517. return 0;
  7518. }
  7519. lua_interface->SetInt32Value(state, spell->num_triggers);
  7520. return 1;
  7521. }
  7522. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7523. if (!lua_interface)
  7524. return 0;
  7525. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7526. if (!spell) {
  7527. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7528. return 0;
  7529. }
  7530. int16 remove_count = lua_interface->GetInt16Value(state);
  7531. if (!remove_count)
  7532. remove_count = 1;
  7533. if (remove_count >= spell->num_triggers) {
  7534. spell->num_triggers = 0;
  7535. if (spell->cancel_after_all_triggers)
  7536. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7537. }
  7538. else {
  7539. spell->num_triggers -= remove_count;
  7540. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7541. }
  7542. return 0;
  7543. }
  7544. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7545. if (!lua_interface)
  7546. return 0;
  7547. Spawn* spawn = lua_interface->GetSpawn(state);
  7548. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7549. if (!spawn) {
  7550. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7551. return 0;
  7552. }
  7553. if (!copy_spawn) {
  7554. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7555. return 0;
  7556. }
  7557. spawn->CopySpawnAppearance(copy_spawn);
  7558. return 0;
  7559. }
  7560. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7561. if (!lua_interface)
  7562. return 0;
  7563. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7564. int8 type = lua_interface->GetInt8Value(state);
  7565. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7566. if (!spell) {
  7567. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7568. return 0;
  7569. }
  7570. if (spawn) {
  7571. if (!spawn->IsEntity()) {
  7572. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7573. return 0;
  7574. }
  7575. Entity* entity = ((Entity*)spawn);
  7576. switch (type) {
  7577. case IMMUNITY_TYPE_AOE:
  7578. entity->AddAOEImmunity(spell);
  7579. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7580. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7581. break;
  7582. case IMMUNITY_TYPE_STUN:
  7583. entity->AddStunImmunity(spell);
  7584. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7585. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7586. break;
  7587. case IMMUNITY_TYPE_ROOT:
  7588. entity->AddRootImmunity(spell);
  7589. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7590. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7591. break;
  7592. case IMMUNITY_TYPE_DAZE:
  7593. entity->AddDazeImmunity(spell);
  7594. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7595. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7596. break;
  7597. case IMMUNITY_TYPE_FEAR:
  7598. entity->AddFearImmunity(spell);
  7599. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7600. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7601. break;
  7602. case IMMUNITY_TYPE_MEZ:
  7603. entity->AddMezImmunity(spell);
  7604. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7605. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7606. break;
  7607. case IMMUNITY_TYPE_STIFLE:
  7608. entity->AddStifleImmunity(spell);
  7609. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7610. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7611. break;
  7612. default:
  7613. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7614. }
  7615. }
  7616. else {
  7617. bool should_break = false;
  7618. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7619. for (int8 i = 0; i < spell->targets.size(); i++) {
  7620. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7621. if (!spawn || !spawn->IsEntity())
  7622. continue;
  7623. Entity* entity = ((Entity*)spawn);
  7624. switch (type) {
  7625. case IMMUNITY_TYPE_AOE:
  7626. entity->AddAOEImmunity(spell);
  7627. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7628. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7629. break;
  7630. case IMMUNITY_TYPE_STUN:
  7631. entity->AddStunImmunity(spell);
  7632. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7633. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7634. break;
  7635. case IMMUNITY_TYPE_ROOT:
  7636. entity->AddRootImmunity(spell);
  7637. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7638. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7639. break;
  7640. case IMMUNITY_TYPE_DAZE:
  7641. entity->AddDazeImmunity(spell);
  7642. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7643. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7644. break;
  7645. case IMMUNITY_TYPE_FEAR:
  7646. entity->AddFearImmunity(spell);
  7647. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7648. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7649. break;
  7650. case IMMUNITY_TYPE_MEZ:
  7651. entity->AddMezImmunity(spell);
  7652. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7653. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7654. break;
  7655. case IMMUNITY_TYPE_STIFLE:
  7656. entity->AddStifleImmunity(spell);
  7657. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7658. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7659. break;
  7660. default:
  7661. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7662. should_break = true;
  7663. }
  7664. if (should_break)
  7665. break;
  7666. }
  7667. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7668. }
  7669. return 0;
  7670. }
  7671. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7672. if (!lua_interface)
  7673. return 0;
  7674. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7675. int8 type = lua_interface->GetInt8Value(state);
  7676. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7677. if (!spell) {
  7678. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7679. return 0;
  7680. }
  7681. if (spawn) {
  7682. if (!spawn->IsEntity()) {
  7683. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7684. return 0;
  7685. }
  7686. Entity* entity = ((Entity*)spawn);
  7687. switch (type) {
  7688. case IMMUNITY_TYPE_AOE:
  7689. entity->RemoveAOEImmunity(spell);
  7690. break;
  7691. case IMMUNITY_TYPE_STUN:
  7692. entity->RemoveStunImmunity(spell);
  7693. break;
  7694. case IMMUNITY_TYPE_ROOT:
  7695. entity->RemoveRootImmunity(spell);
  7696. break;
  7697. case IMMUNITY_TYPE_DAZE:
  7698. entity->RemoveDazeImmunity(spell);
  7699. break;
  7700. case IMMUNITY_TYPE_FEAR:
  7701. entity->RemoveFearImmunity(spell);
  7702. break;
  7703. case IMMUNITY_TYPE_MEZ:
  7704. entity->RemoveMezImmunity(spell);
  7705. break;
  7706. case IMMUNITY_TYPE_STIFLE:
  7707. entity->RemoveStifleImmunity(spell);
  7708. break;
  7709. default:
  7710. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7711. }
  7712. }
  7713. else {
  7714. bool should_break = false;
  7715. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7716. for (int8 i = 0; i < spell->targets.size(); i++) {
  7717. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7718. if (!spawn || !spawn->IsEntity())
  7719. continue;
  7720. Entity* entity = ((Entity*)spawn);
  7721. switch (type) {
  7722. case IMMUNITY_TYPE_AOE:
  7723. entity->RemoveAOEImmunity(spell);
  7724. break;
  7725. case IMMUNITY_TYPE_STUN:
  7726. entity->RemoveStunImmunity(spell);
  7727. break;
  7728. case IMMUNITY_TYPE_ROOT:
  7729. entity->RemoveRootImmunity(spell);
  7730. break;
  7731. case IMMUNITY_TYPE_DAZE:
  7732. entity->RemoveDazeImmunity(spell);
  7733. break;
  7734. case IMMUNITY_TYPE_FEAR:
  7735. entity->RemoveFearImmunity(spell);
  7736. break;
  7737. case IMMUNITY_TYPE_MEZ:
  7738. entity->RemoveMezImmunity(spell);
  7739. break;
  7740. case IMMUNITY_TYPE_STIFLE:
  7741. entity->RemoveStifleImmunity(spell);
  7742. break;
  7743. default:
  7744. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7745. should_break = true;
  7746. }
  7747. if (should_break)
  7748. break;
  7749. }
  7750. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7751. }
  7752. return 0;
  7753. }
  7754. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7755. if (!lua_interface)
  7756. return 0;
  7757. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7758. if (!spell) {
  7759. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7760. return 0;
  7761. }
  7762. float snare = lua_interface->GetFloatValue(state);
  7763. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7764. // convert the val to the speed multipler value (100 - val)
  7765. float val = 100.0 - snare;
  7766. val /= 100.0;
  7767. if (spawn) {
  7768. if (!spawn->IsEntity()) {
  7769. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7770. return 0;
  7771. }
  7772. ((Entity*)spawn)->SetSnareValue(spell, val);
  7773. }
  7774. else {
  7775. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7776. for (int8 i = 0; i < spell->targets.size(); i++) {
  7777. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7778. if (!spawn || !spawn->IsEntity())
  7779. continue;
  7780. ((Entity*)spawn)->SetSnareValue(spell, val);
  7781. }
  7782. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7783. }
  7784. return 0;
  7785. }
  7786. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7787. if (!lua_interface)
  7788. return 0;
  7789. Spawn* spawn = lua_interface->GetSpawn(state);
  7790. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7791. if (!spawn) {
  7792. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7793. return 0;
  7794. }
  7795. if (race_id == 0) {
  7796. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7797. return 0;
  7798. }
  7799. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7800. return 1;
  7801. }
  7802. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7803. if (!lua_interface)
  7804. return 0;
  7805. Spawn* spawn = lua_interface->GetSpawn(state);
  7806. if (!spawn) {
  7807. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7808. return 0;
  7809. }
  7810. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7811. return 1;
  7812. }
  7813. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7814. if (!lua_interface)
  7815. return 0;
  7816. Spawn* spawn = lua_interface->GetSpawn(state);
  7817. if (!spawn) {
  7818. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7819. return 0;
  7820. }
  7821. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7822. return 1;
  7823. }
  7824. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7825. if (!lua_interface)
  7826. return 0;
  7827. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7828. if (!spell) {
  7829. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7830. return 0;
  7831. }
  7832. lua_interface->SetStringValue(state, spell->spell->GetName());
  7833. return 1;
  7834. }
  7835. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7836. if (!lua_interface)
  7837. return 0;
  7838. Quest* quest = lua_interface->GetQuest(state);
  7839. if (!quest) {
  7840. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7841. return 0;
  7842. }
  7843. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7844. return 1;
  7845. }
  7846. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7847. if (!lua_interface)
  7848. return 0;
  7849. Quest* quest = lua_interface->GetQuest(state);
  7850. int32 flags = lua_interface->GetInt32Value(state, 2);
  7851. if (!quest) {
  7852. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7853. return 0;
  7854. }
  7855. quest->SetQuestFlags(flags);
  7856. return 0;
  7857. }
  7858. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7859. if (!lua_interface)
  7860. return 0;
  7861. Quest* quest = lua_interface->GetQuest(state);
  7862. Spawn* player = lua_interface->GetSpawn(state, 2);
  7863. int32 step = lua_interface->GetInt32Value(state, 3);
  7864. int32 duration = lua_interface->GetInt32Value(state, 4);
  7865. string action = lua_interface->GetStringValue(state, 5);
  7866. if (!quest) {
  7867. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7868. return 0;
  7869. }
  7870. if (!player) {
  7871. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7872. return 0;
  7873. }
  7874. if (!player->IsPlayer()) {
  7875. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7876. return 0;
  7877. }
  7878. if (step == 0) {
  7879. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7880. return 0;
  7881. }
  7882. if (duration == 0) {
  7883. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7884. return 0;
  7885. }
  7886. if (action.length() == 0) {
  7887. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7888. return 0;
  7889. }
  7890. Client* client = player->GetZone()->GetClientBySpawn(player);
  7891. if (!client) {
  7892. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7893. return 0;
  7894. }
  7895. quest->SetTimerStep(step);
  7896. quest->AddFailedAction(step, action);
  7897. quest->SetStepTimer(duration);
  7898. client->AddQuestTimer(quest->GetQuestID());
  7899. return 0;
  7900. }
  7901. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7902. if (!lua_interface)
  7903. return 0;
  7904. Quest* quest = lua_interface->GetQuest(state);
  7905. Spawn* player = lua_interface->GetSpawn(state, 2);
  7906. if (!quest) {
  7907. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7908. return 0;
  7909. }
  7910. if (!player) {
  7911. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7912. return 0;
  7913. }
  7914. if (!player->IsPlayer()) {
  7915. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7916. return 0;
  7917. }
  7918. Client* client = player->GetZone()->GetClientBySpawn(player);
  7919. if (!client) {
  7920. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7921. return 0;
  7922. }
  7923. quest->SetTimerStep(0);
  7924. quest->SetStepTimer(0);
  7925. client->RemoveQuestTimer(quest->GetQuestID());
  7926. return 0;
  7927. }
  7928. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7929. if (!lua_interface)
  7930. return 0;
  7931. Spawn* player = lua_interface->GetSpawn(state);
  7932. Quest* quest = lua_interface->GetQuest(state, 2);
  7933. int32 step = lua_interface->GetInt32Value(state, 3);
  7934. if (!player) {
  7935. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7936. return 0;
  7937. }
  7938. if (!player->IsPlayer()) {
  7939. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7940. return 0;
  7941. }
  7942. if (!quest) {
  7943. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7944. return 0;
  7945. }
  7946. if (step == 0) {
  7947. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7948. return 0;
  7949. }
  7950. Client* client = player->GetZone()->GetClientBySpawn(player);
  7951. if (!client) {
  7952. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7953. return 0;
  7954. }
  7955. if (quest->RemoveQuestStep(step, client)) {
  7956. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7957. client->GetCurrentZone()->SendQuestUpdates(client);
  7958. }
  7959. else
  7960. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7961. return 0;
  7962. }
  7963. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7964. if (!lua_interface)
  7965. return 0;
  7966. Quest* quest = lua_interface->GetQuest(state, 1);
  7967. int32 step = lua_interface->GetInt32Value(state, 2);
  7968. string desc = lua_interface->GetStringValue(state, 3);
  7969. string task_group = lua_interface->GetStringValue(state, 4);
  7970. if (!quest) {
  7971. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7972. return 0;
  7973. }
  7974. if (step == 0) {
  7975. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7976. return 0;
  7977. }
  7978. QuestStep* quest_step = quest->GetQuestStep(step);
  7979. if (!quest_step) {
  7980. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7981. return 0;
  7982. }
  7983. quest_step->SetStepProgress(0);
  7984. quest_step->SetTaskGroup(task_group);
  7985. quest_step->SetDescription(desc);
  7986. return 0;
  7987. }
  7988. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7989. if (!lua_interface)
  7990. return 0;
  7991. Quest* quest = lua_interface->GetQuest(state);
  7992. int32 step = lua_interface->GetInt32Value(state, 2);
  7993. string action = lua_interface->GetStringValue(state, 3);
  7994. if (!quest) {
  7995. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7996. return 0;
  7997. }
  7998. if (step == 0) {
  7999. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8000. return 0;
  8001. }
  8002. if (action.length() == 0) {
  8003. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8004. return 0;
  8005. }
  8006. quest->AddFailedAction(step, action);
  8007. return 0;
  8008. }
  8009. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8010. if (!lua_interface)
  8011. return 0;
  8012. Spawn* player = lua_interface->GetSpawn(state);
  8013. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8014. int32 step = lua_interface->GetInt32Value(state, 3);
  8015. if (!player) {
  8016. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8017. return 0;
  8018. }
  8019. if (!player->IsPlayer()) {
  8020. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8021. return 0;
  8022. }
  8023. if (quest_id == 0) {
  8024. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8025. return 0;
  8026. }
  8027. if (step == 0) {
  8028. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8029. return 0;
  8030. }
  8031. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8032. if (!quest) {
  8033. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8034. return 0;
  8035. }
  8036. quest->StepFailed(step);
  8037. return 0;
  8038. }
  8039. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8040. if (!lua_interface)
  8041. return 0;
  8042. Spawn* player = lua_interface->GetSpawn(state);
  8043. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8044. if (!player) {
  8045. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8046. return 0;
  8047. }
  8048. if (!player->IsPlayer()) {
  8049. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8050. return 0;
  8051. }
  8052. if (quest_id == 0) {
  8053. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8054. return 0;
  8055. }
  8056. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8057. if (!quest) {
  8058. lua_interface->SetInt32Value(state, 0);
  8059. return 1;
  8060. }
  8061. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8062. return 1;
  8063. }
  8064. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8065. if (!lua_interface)
  8066. return 0;
  8067. string name = lua_interface->GetStringValue(state);
  8068. string value = lua_interface->GetStringValue(state, 2);
  8069. string comment = lua_interface->GetStringValue(state, 3);
  8070. if (name.length() == 0) {
  8071. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8072. return 0;
  8073. }
  8074. if (value.length() == 0) {
  8075. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8076. return 0;
  8077. }
  8078. string varname = string("lua_").append(name);
  8079. Variable* var = variables.FindVariable(varname);
  8080. if (var)
  8081. var->SetValue(value.c_str());
  8082. else {
  8083. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8084. variables.AddVariable(var);
  8085. }
  8086. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8087. return 0;
  8088. }
  8089. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8090. if (!lua_interface)
  8091. return 0;
  8092. string name = lua_interface->GetStringValue(state);
  8093. if (name.length() == 0) {
  8094. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8095. return 0;
  8096. }
  8097. string varname = string("lua_").append(name);
  8098. Variable* var = variables.FindVariable(varname);
  8099. if (var)
  8100. lua_interface->SetStringValue(state, var->GetValue());
  8101. else
  8102. lua_interface->SetStringValue(state, "NULL");
  8103. return 1;
  8104. }
  8105. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8106. if (!lua_interface)
  8107. return 0;
  8108. Spawn* player = lua_interface->GetSpawn(state);
  8109. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8110. if (!player) {
  8111. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8112. return 0;
  8113. }
  8114. if (!player->IsPlayer()) {
  8115. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8116. return 0;
  8117. }
  8118. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8119. return 1;
  8120. }
  8121. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8122. if (!lua_interface)
  8123. return 0;
  8124. Spawn* player = lua_interface->GetSpawn(state);
  8125. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8126. if (!player) {
  8127. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8128. return 0;
  8129. }
  8130. if (!player->IsPlayer()) {
  8131. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8132. return 0;
  8133. }
  8134. Language* language = master_languages_list.GetLanguage(language_id);
  8135. if (language)
  8136. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8137. return 0;
  8138. }
  8139. int EQ2Emu_lua_IsNight(lua_State* state) {
  8140. if (!lua_interface)
  8141. return 0;
  8142. ZoneServer* zone = lua_interface->GetZone(state);
  8143. if (!zone) {
  8144. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8145. return 0;
  8146. }
  8147. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8148. return 1;
  8149. }
  8150. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8151. if (!lua_interface)
  8152. return 0;
  8153. Spawn* spawn = lua_interface->GetSpawn(state);
  8154. if (!spawn) {
  8155. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8156. return 0;
  8157. }
  8158. if (!spawn->IsWidget()) {
  8159. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8160. return 0;
  8161. }
  8162. ((Widget*)spawn)->SetMultiFloorLift(true);
  8163. if (spawn->GetZone())
  8164. spawn->GetZone()->AddTransportSpawn(spawn);
  8165. return 0;
  8166. }
  8167. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8168. if (!lua_interface)
  8169. return 0;
  8170. Spawn* player = lua_interface->GetSpawn(state);
  8171. int32 path = lua_interface->GetInt32Value(state, 2);
  8172. if (!player) {
  8173. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8174. return 0;
  8175. }
  8176. if (!player->IsPlayer()) {
  8177. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8178. return 0;
  8179. }
  8180. if (path == 0) {
  8181. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8182. return 0;
  8183. }
  8184. Client* client = player->GetZone()->GetClientBySpawn(player);
  8185. if (!client) {
  8186. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8187. return 0;
  8188. }
  8189. client->SendFlightAutoMount(path);
  8190. return 0;
  8191. }
  8192. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8193. if (!lua_interface)
  8194. return 0;
  8195. Spawn* player = lua_interface->GetSpawn(state);
  8196. if (!player) {
  8197. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8198. return 0;
  8199. }
  8200. if (!player->IsPlayer()) {
  8201. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8202. return 0;
  8203. }
  8204. Client* client = player->GetZone()->GetClientBySpawn(player);
  8205. if (!client) {
  8206. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8207. return 0;
  8208. }
  8209. client->EndAutoMount();
  8210. return 0;
  8211. }
  8212. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8213. if (!lua_interface)
  8214. return 0;
  8215. Spawn* player = lua_interface->GetSpawn(state);
  8216. if (!player) {
  8217. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8218. return 0;
  8219. }
  8220. if (!player->IsPlayer()) {
  8221. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8222. return 0;
  8223. }
  8224. Client* client = player->GetZone()->GetClientBySpawn(player);
  8225. if (!client) {
  8226. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8227. return 0;
  8228. }
  8229. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8230. return 1;
  8231. }
  8232. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8233. if (!lua_interface)
  8234. return 0;
  8235. Spawn* player = lua_interface->GetSpawn(state);
  8236. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8237. int32 value = lua_interface->GetInt32Value(state, 3);
  8238. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8239. if (!player) {
  8240. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8241. return 0;
  8242. }
  8243. if (!player->IsPlayer()) {
  8244. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8248. return 0;
  8249. }
  8250. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8251. if (!lua_interface)
  8252. return 0;
  8253. Spawn* player = lua_interface->GetSpawn(state);
  8254. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8255. if (!player) {
  8256. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8257. return 0;
  8258. }
  8259. if (!player->IsPlayer()) {
  8260. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8261. return 0;
  8262. }
  8263. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8264. if (!hd)
  8265. return 0;
  8266. lua_interface->SetInt32Value(state, hd->Value);
  8267. lua_interface->SetInt32Value(state, hd->Value2);
  8268. return 2;
  8269. }
  8270. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8271. if (!lua_interface)
  8272. return 0;
  8273. Spawn* spawn = lua_interface->GetSpawn(state);
  8274. int32 grid = lua_interface->GetInt32Value(state, 2);
  8275. if (!spawn) {
  8276. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8277. return 0;
  8278. }
  8279. if (grid == 0) {
  8280. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8281. return 0;
  8282. }
  8283. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8284. return 0;
  8285. }
  8286. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8287. if (!lua_interface)
  8288. return 0;
  8289. Spawn* spawn = lua_interface->GetSpawn(state);
  8290. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8291. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8292. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8293. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8294. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8295. if (!spawn) {
  8296. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8297. return 0;
  8298. }
  8299. //Add this quest to the list of required quests for this spawn
  8300. spawn->SetRequiredHistory(event_id, value1, value2);
  8301. //If private spawn value set
  8302. if (private_spawn) {
  8303. //Set the spawn to be private when not granted access via history
  8304. spawn->AddAllowAccessSpawn(spawn);
  8305. spawn->SetPrivateQuestSpawn(true);
  8306. }
  8307. //This value will override vis_flags in the vis packet
  8308. if (flag_override > 0)
  8309. spawn->SetQuestsRequiredOverride(flag_override);
  8310. return 0;
  8311. }
  8312. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8313. if (!lua_interface)
  8314. return 0;
  8315. Spawn* player = lua_interface->GetSpawn(state);
  8316. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8317. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8318. if (!player) {
  8319. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8320. return 0;
  8321. }
  8322. if (!player->IsPlayer()) {
  8323. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8324. return 0;
  8325. }
  8326. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8327. return 1;
  8328. }
  8329. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8330. if (!lua_interface)
  8331. return 0;
  8332. Spawn* player = lua_interface->GetSpawn(state);
  8333. int8 level = lua_interface->GetInt8Value(state, 2);
  8334. if (!player) {
  8335. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8336. return 0;
  8337. }
  8338. if (!player->IsPlayer()) {
  8339. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8340. return 0;
  8341. }
  8342. if (level == 0) {
  8343. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8344. return 0;
  8345. }
  8346. Client* client = player->GetZone()->GetClientBySpawn(player);
  8347. if (!client) {
  8348. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8349. return 0;
  8350. }
  8351. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8352. return 0;
  8353. }
  8354. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8355. if (!lua_interface)
  8356. return 0;
  8357. Spawn* player = lua_interface->GetSpawn(state);
  8358. int32 amount = lua_interface->GetInt32Value(state, 2);
  8359. if (!player) {
  8360. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8361. return 0;
  8362. }
  8363. if (!player->IsPlayer()) {
  8364. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8365. return 0;
  8366. }
  8367. if (amount == 0) {
  8368. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8369. return 0;
  8370. }
  8371. ((Player*)player)->AddCoins(amount);
  8372. return 0;
  8373. }
  8374. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8375. if (!lua_interface)
  8376. return 0;
  8377. Spawn* player = lua_interface->GetSpawn(state);
  8378. int32 amount = lua_interface->GetInt32Value(state, 2);
  8379. if (!player) {
  8380. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8381. return 0;
  8382. }
  8383. if (!player->IsPlayer()) {
  8384. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8385. return 0;
  8386. }
  8387. if (amount == 0) {
  8388. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8389. return 0;
  8390. }
  8391. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8392. return 1;
  8393. }
  8394. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8395. if (!lua_interface)
  8396. return 0;
  8397. ZoneServer* zone = lua_interface->GetZone(state);
  8398. if (!zone) {
  8399. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8400. return 0;
  8401. }
  8402. vector<Entity*> players = zone->GetPlayers();
  8403. if (players.size() == 0)
  8404. return 0;
  8405. lua_createtable(state, players.size(), 0);
  8406. int newTable = lua_gettop(state);
  8407. for (int32 i = 0; i < players.size(); i++) {
  8408. lua_interface->SetSpawnValue(state, players.at(i));
  8409. lua_rawseti(state, newTable, i + 1);
  8410. }
  8411. return 1;
  8412. }
  8413. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8414. if (!lua_interface)
  8415. return 0;
  8416. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8417. if (!zone) {
  8418. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8419. return 0;
  8420. }
  8421. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8422. //Map of <placement_id, location_id>
  8423. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8424. map<int32, int32>::iterator itr;
  8425. vector<Spawn*> group;
  8426. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8427. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8428. if (!location) {
  8429. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8430. return 0;
  8431. }
  8432. Spawn* spawn = 0;
  8433. if (location->entities[0]) {
  8434. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8435. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8436. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8437. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8438. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8439. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8440. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8441. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8442. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8443. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8444. if (spawn) {
  8445. const char* script = 0;
  8446. for (int x = 0; x < 3; x++) {
  8447. switch (x) {
  8448. case 0:
  8449. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8450. break;
  8451. case 1:
  8452. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8453. break;
  8454. case 2:
  8455. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8456. break;
  8457. }
  8458. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8459. spawn->SetSpawnScript(string(script));
  8460. break;
  8461. }
  8462. }
  8463. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8464. lua_interface->SetSpawnValue(state, spawn);
  8465. group.push_back(spawn);
  8466. }
  8467. else {
  8468. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8469. safe_delete(spawn);
  8470. }
  8471. }
  8472. }
  8473. if (!group.empty()) {
  8474. lua_createtable(state, group.size(), 0);
  8475. int newTable = lua_gettop(state);
  8476. for (int32 i = 0; i < group.size(); i++) {
  8477. lua_interface->SetSpawnValue(state, group[i]);
  8478. lua_rawseti(state, newTable, i + 1);
  8479. }
  8480. }
  8481. else
  8482. lua_pushnil(state);
  8483. return 1;
  8484. }
  8485. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8486. if (!lua_interface)
  8487. return 0;
  8488. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8489. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8490. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8491. if (!spawn) {
  8492. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8493. return 0;
  8494. }
  8495. if (anim_id == 0) {
  8496. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8497. return 0;
  8498. }
  8499. if (leeway == 0)
  8500. leeway = 5000;
  8501. spawn->SetSpawnAnim(anim_id);
  8502. spawn->SetSpawnAnimLeeway(leeway);
  8503. return 0;
  8504. }
  8505. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8506. if (!lua_interface)
  8507. return 0;
  8508. Spawn* player = lua_interface->GetSpawn(state);
  8509. if (!player) {
  8510. return 0;
  8511. }
  8512. Client* client = player->GetZone()->GetClientBySpawn(player);
  8513. if (!client) {
  8514. return 0;
  8515. }
  8516. lua_interface->SetInt32Value(state, client->GetVersion());
  8517. return 1;
  8518. }
  8519. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8520. if (!lua_interface)
  8521. return 0;
  8522. Item* item = lua_interface->GetItem(state);
  8523. if (!item) {
  8524. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8525. return 0;
  8526. }
  8527. lua_interface->SetInt32Value(state, item->details.item_id);
  8528. return 1;
  8529. }
  8530. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8531. if (!lua_interface)
  8532. return 0;
  8533. Spawn* spawn = lua_interface->GetSpawn(state);
  8534. if (!spawn) {
  8535. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8539. return 1;
  8540. }
  8541. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8542. if (!lua_interface)
  8543. return 0;
  8544. Spawn* spawn = lua_interface->GetSpawn(state);
  8545. if (!spawn) {
  8546. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8547. return 0;
  8548. }
  8549. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8550. return 1;
  8551. }
  8552. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8553. if (!lua_interface)
  8554. return 0;
  8555. Spawn* spawn = lua_interface->GetSpawn(state);
  8556. if (!spawn) {
  8557. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8558. return 0;
  8559. }
  8560. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8561. return 1;
  8562. }
  8563. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8564. if (!lua_interface)
  8565. return 0;
  8566. Spawn* spawn = lua_interface->GetSpawn(state);
  8567. if (!spawn) {
  8568. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8569. return 0;
  8570. }
  8571. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8572. return 1;
  8573. }
  8574. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8575. if (!lua_interface)
  8576. return 0;
  8577. Spawn* spawn = lua_interface->GetSpawn(state);
  8578. float pct = lua_interface->GetFloatValue(state, 2);
  8579. if (!spawn) {
  8580. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8581. return 0;
  8582. }
  8583. if (pct == 0) {
  8584. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8585. return 0;
  8586. }
  8587. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8588. lua_interface->SetInt32Value(state, amount);
  8589. return 1;
  8590. }
  8591. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8592. if (!lua_interface)
  8593. return 0;
  8594. Spawn* spawn = lua_interface->GetSpawn(state);
  8595. float pct = lua_interface->GetFloatValue(state, 2);
  8596. if (!spawn) {
  8597. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8598. return 0;
  8599. }
  8600. if (pct == 0) {
  8601. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8602. return 0;
  8603. }
  8604. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8605. lua_interface->SetInt32Value(state, amount);
  8606. return 1;
  8607. }
  8608. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8609. if (!lua_interface)
  8610. return 0;
  8611. Spawn* spawn = lua_interface->GetSpawn(state);
  8612. if (!spawn) {
  8613. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8614. return 0;
  8615. }
  8616. if (!spawn->IsPlayer()) {
  8617. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8618. return 0;
  8619. }
  8620. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8621. return 1;
  8622. }
  8623. int EQ2Emu_lua_Evac(lua_State* state) {
  8624. if (!lua_interface)
  8625. return 0;
  8626. Spawn* target = lua_interface->GetSpawn(state);
  8627. if (target) {
  8628. float x = target->GetZone()->GetSafeX();
  8629. float y = target->GetZone()->GetSafeY();
  8630. float z = target->GetZone()->GetSafeZ();
  8631. float h = target->GetZone()->GetSafeHeading();
  8632. target->SetX(x);
  8633. target->SetY(y);
  8634. target->SetZ(z);
  8635. target->SetHeading(h);
  8636. target->SetSpawnOrigX(target->GetX());
  8637. target->SetSpawnOrigY(target->GetY());
  8638. target->SetSpawnOrigZ(target->GetZ());
  8639. target->SetSpawnOrigHeading(target->GetHeading());
  8640. if (target->IsPlayer()) {
  8641. Client* client = target->GetZone()->GetClientBySpawn(target);
  8642. if (client) {
  8643. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8644. if (packet)
  8645. {
  8646. packet->setDataByName("x", x);
  8647. packet->setDataByName("y", y);
  8648. packet->setDataByName("z", z);
  8649. client->QueuePacket(packet->serialize());
  8650. safe_delete(packet);
  8651. }
  8652. }
  8653. }
  8654. }
  8655. else {
  8656. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8657. ZoneServer* zone = spell->caster->GetZone();
  8658. float x = spell->caster->GetZone()->GetSafeX();
  8659. float y = spell->caster->GetZone()->GetSafeY();
  8660. float z = spell->caster->GetZone()->GetSafeZ();
  8661. float h = spell->caster->GetZone()->GetSafeHeading();
  8662. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8663. for (int32 i = 0; i < spell->targets.size(); i++) {
  8664. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8665. if (!target2)
  8666. continue;
  8667. target2->SetX(x);
  8668. target2->SetY(y);
  8669. target2->SetZ(z);
  8670. target2->SetHeading(h);
  8671. target2->SetSpawnOrigX(target2->GetX());
  8672. target2->SetSpawnOrigY(target2->GetY());
  8673. target2->SetSpawnOrigZ(target2->GetZ());
  8674. target2->SetSpawnOrigHeading(target2->GetHeading());
  8675. if (target2->IsPlayer()) {
  8676. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8677. if (client) {
  8678. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8679. if (packet)
  8680. {
  8681. packet->setDataByName("x", x);
  8682. packet->setDataByName("y", y);
  8683. packet->setDataByName("z", z);
  8684. client->QueuePacket(packet->serialize());
  8685. safe_delete(packet);
  8686. }
  8687. }
  8688. }
  8689. }
  8690. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8691. }
  8692. return 0;
  8693. }
  8694. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8695. if (!lua_interface)
  8696. return 0;
  8697. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8698. if (!luaspell) {
  8699. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8700. return 0;
  8701. }
  8702. int8 tier = luaspell->spell->GetSpellTier();
  8703. lua_interface->SetInt32Value(state, tier);
  8704. return 1;
  8705. }
  8706. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8707. if (!lua_interface)
  8708. return 0;
  8709. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8710. if (!luaspell) {
  8711. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8712. return 0;
  8713. }
  8714. int32 spell_id = luaspell->spell->GetSpellID();
  8715. lua_interface->SetInt32Value(state, spell_id);
  8716. return 1;
  8717. }
  8718. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8719. if (!lua_interface)
  8720. return 0;
  8721. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8722. if (!spawn) {
  8723. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8724. return 0;
  8725. }
  8726. if (!spawn->IsPlayer()) {
  8727. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8728. return 0;
  8729. }
  8730. ZoneServer* zone = spawn->GetZone();
  8731. if (!zone) {
  8732. return 0;
  8733. }
  8734. Client* client = zone->GetClientBySpawn(spawn);
  8735. if (!client) {
  8736. return 0;
  8737. }
  8738. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8739. return 0;
  8740. }
  8741. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8742. if (!lua_interface)
  8743. return 0;
  8744. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8745. if (!spawn) {
  8746. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8747. return 0;
  8748. }
  8749. if (!spawn->IsPlayer()) {
  8750. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8751. return 0;
  8752. }
  8753. ZoneServer* zone = spawn->GetZone();
  8754. if (!zone) {
  8755. return 0;
  8756. }
  8757. Client* client = zone->GetClientBySpawn(spawn);
  8758. if (!client) {
  8759. return 0;
  8760. }
  8761. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8762. return 0;
  8763. }
  8764. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8765. if (!lua_interface)
  8766. return 0;
  8767. Spawn* caster = lua_interface->GetSpawn(state);
  8768. Spawn* target = lua_interface->GetSpawn(state, 2);
  8769. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8770. string spell_name = lua_interface->GetStringValue(state, 4);
  8771. if (!caster) {
  8772. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8773. return 0;
  8774. }
  8775. if (!caster->IsEntity()) {
  8776. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8777. return 0;
  8778. }
  8779. if (!target) {
  8780. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8781. return 0;
  8782. }
  8783. if (!target->IsEntity()) {
  8784. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8785. return 0;
  8786. }
  8787. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8788. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8789. return 0;
  8790. }
  8791. int EQ2Emu_lua_AddLootToObject(lua_State* state) {
  8792. if (!lua_interface)
  8793. return 0;
  8794. Spawn* object = lua_interface->GetSpawn(state);
  8795. Spawn* player = lua_interface->GetSpawn(state, 2);
  8796. if (object && player && player->IsPlayer()) {
  8797. int32 coins = lua_interface->GetInt32Value(state, 3);
  8798. vector<Item*>* items = 0;
  8799. int i = 0;
  8800. int32 item_id = 0;
  8801. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  8802. if (items == 0)
  8803. items = new vector<Item*>;
  8804. if (master_item_list.GetItem(item_id))
  8805. items->push_back(master_item_list.GetItem(item_id));
  8806. i++;
  8807. }
  8808. Client* client = 0;
  8809. client = object->GetZone()->GetClientBySpawn(player);
  8810. if (client) {
  8811. ((Player*)player)->AddPendingLootItems(object->GetID(), items);
  8812. }
  8813. safe_delete(items);
  8814. }
  8815. return 0;
  8816. }
  8817. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8818. if (!lua_interface)
  8819. return 0;
  8820. Spawn* player = lua_interface->GetSpawn(state);
  8821. int32 amount = lua_interface->GetInt32Value(state, 2);
  8822. if (player && player->IsPlayer() && amount > 0) {
  8823. ((Player*)player)->AddXP(amount);
  8824. ((Player*)player)->SetCharSheetChanged(true);
  8825. Client* client = player->GetZone()->GetClientBySpawn(player);
  8826. if (client) {
  8827. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8828. }
  8829. }
  8830. return 0;
  8831. }
  8832. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8833. if (!lua_interface)
  8834. return 0;
  8835. Spawn* player = lua_interface->GetSpawn(state);
  8836. int8 type = lua_interface->GetInt8Value(state, 2);
  8837. string text = lua_interface->GetStringValue(state, 3);
  8838. Client* client = 0;
  8839. if (player && player->IsPlayer())
  8840. client = player->GetZone()->GetClientBySpawn(player);
  8841. if (!client || text.length() == 0) {
  8842. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8843. return 0;
  8844. }
  8845. client->SimpleMessage(type, text.c_str());
  8846. return 0;
  8847. }
  8848. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8849. if (!lua_interface)
  8850. return 0;
  8851. Spawn* player = lua_interface->GetSpawn(state);
  8852. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8853. Client* client = 0;
  8854. if (player && player->IsPlayer())
  8855. client = player->GetZone()->GetClientBySpawn(player);
  8856. if (!client || !spawn) {
  8857. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8858. return 0;
  8859. }
  8860. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8861. if (!items) {
  8862. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8863. return 0;
  8864. }
  8865. client->Loot(spawn->GetLootCoins(), items, spawn);
  8866. return 0;
  8867. }
  8868. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8869. if (!lua_interface)
  8870. return 0;
  8871. Spawn* spawnref = lua_interface->GetSpawn(state);
  8872. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8873. if (spawn_id > 0 && spawnref) {
  8874. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8875. if (spawns.size() == 0) {
  8876. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8877. return 0;
  8878. }
  8879. Spawn* spawn = 0;
  8880. int16 index = MakeRandomInt(0, spawns.size());
  8881. if (index >= spawns.size() || index < 0)
  8882. index = 0;
  8883. spawn = spawns[index];
  8884. lua_interface->SetSpawnValue(state, spawn);
  8885. return 1;
  8886. }
  8887. else {
  8888. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8889. }
  8890. return 0;
  8891. }
  8892. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8893. Spawn* player = lua_interface->GetSpawn(state);
  8894. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8895. string name = lua_interface->GetStringValue(state, 3);
  8896. float distance = lua_interface->GetFloatValue(state, 4);
  8897. string command = lua_interface->GetStringValue(state, 5);
  8898. string error_text = lua_interface->GetStringValue(state, 6);
  8899. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8900. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  8901. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  8902. if (distance == 0)
  8903. distance = 10.0f;
  8904. if (command.length() == 0)
  8905. command = name;
  8906. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  8907. if (spawns.size() == 0) {
  8908. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8909. return 0;
  8910. }
  8911. Spawn* spawn = 0;
  8912. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  8913. spawn = *itr;
  8914. if (spawn) {
  8915. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  8916. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  8917. }
  8918. }
  8919. }
  8920. return 0;
  8921. }
  8922. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  8923. if (!lua_interface)
  8924. return 0;
  8925. Client* client = 0;
  8926. Spawn* player = lua_interface->GetSpawn(state);
  8927. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  8928. if (player && player->IsPlayer() && player->GetZone())
  8929. client = player->GetZone()->GetClientBySpawn(player);
  8930. else{
  8931. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  8932. return 0;
  8933. }
  8934. if (client) {
  8935. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8936. if (packet) {
  8937. packet->setDataByName("goal_num", goal_num);
  8938. client->QueuePacket(packet->serialize());
  8939. safe_delete(packet);
  8940. }
  8941. }
  8942. return 0;
  8943. }
  8944. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  8945. if (!lua_interface)
  8946. return 0;
  8947. Client* client = 0;
  8948. Spawn* player = lua_interface->GetSpawn(state);
  8949. if (player && player->IsPlayer() && player->GetZone())
  8950. client = player->GetZone()->GetClientBySpawn(player);
  8951. else {
  8952. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  8953. return 0;
  8954. }
  8955. if (client) {
  8956. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  8957. }
  8958. return 0;
  8959. }
  8960. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  8961. if (!lua_interface)
  8962. return 0;
  8963. Client* client = 0;
  8964. Spawn* player = lua_interface->GetSpawn(state);
  8965. float duration = lua_interface->GetFloatValue(state, 2);
  8966. string text = lua_interface->GetStringValue(state, 3);
  8967. string voice = lua_interface->GetStringValue(state, 4);
  8968. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  8969. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  8970. string signal = lua_interface->GetStringValue(state, 7);
  8971. string goal1 = lua_interface->GetStringValue(state, 8);
  8972. string task1 = lua_interface->GetStringValue(state, 9);
  8973. string goal2 = lua_interface->GetStringValue(state, 10);
  8974. string task2 = lua_interface->GetStringValue(state, 11);
  8975. string goal3 = lua_interface->GetStringValue(state, 12);
  8976. string task3 = lua_interface->GetStringValue(state, 13);
  8977. string goal4 = lua_interface->GetStringValue(state, 14);
  8978. string task4 = lua_interface->GetStringValue(state, 15);
  8979. if (!player) {
  8980. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  8981. return 0;
  8982. }
  8983. if (!player->IsPlayer()) {
  8984. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  8985. return 0;
  8986. }
  8987. else
  8988. client = ((Player*)player)->GetClient();
  8989. if (!client) {
  8990. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  8991. return 0;
  8992. }
  8993. if (text.length() == 0) {
  8994. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  8995. return 0;
  8996. }
  8997. if (duration >= 0 && duration < 2)
  8998. duration = 2;
  8999. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9000. if (packet) {
  9001. packet->setDataByName("open_seconds_max", duration);
  9002. packet->setDataByName("text", text.c_str());
  9003. packet->setDataByName("voice", voice.c_str());
  9004. int8 num_goals = 1;
  9005. if (task2.length() > 0)
  9006. num_goals++;
  9007. if (task3.length() > 0)
  9008. num_goals++;
  9009. if (task4.length() > 0)
  9010. num_goals++;
  9011. packet->setArrayLengthByName("num_goals", num_goals);
  9012. for (int8 i = 0; i < num_goals; i++) {
  9013. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9014. }
  9015. if (goal1.length() > 0)
  9016. packet->setArrayDataByName("goal_text", goal1.c_str());
  9017. if (goal2.length() > 0)
  9018. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9019. if (goal3.length() > 0)
  9020. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9021. if (goal4.length() > 0)
  9022. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9023. packet->setSubArrayDataByName("task_text", task1.c_str());
  9024. if (task2.length() > 0)
  9025. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9026. if (task3.length() > 0)
  9027. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9028. if (task4.length() > 0)
  9029. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9030. packet->setDataByName("complete_sound", "click");
  9031. packet->setDataByName("signal", signal.c_str());
  9032. packet->setDataByName("voice_key1", voice_key1);
  9033. packet->setDataByName("voice_key2", voice_key2);
  9034. client->QueuePacket(packet->serialize());
  9035. safe_delete(packet);
  9036. }
  9037. return 0;
  9038. }
  9039. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9040. if (!lua_interface)
  9041. return 0;
  9042. Client* client = 0;
  9043. Spawn* player = lua_interface->GetSpawn(state);
  9044. string window = lua_interface->GetStringValue(state, 2);
  9045. int8 show = lua_interface->GetInt8Value(state, 3);
  9046. if (!player) {
  9047. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9048. return 0;
  9049. }
  9050. if (!player->IsPlayer()) {
  9051. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9052. return 0;
  9053. }
  9054. else
  9055. client = ((Player*)player)->GetClient();
  9056. if (!client) {
  9057. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9058. return 0;
  9059. }
  9060. if (window.length() == 0) {
  9061. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9062. return 0;
  9063. }
  9064. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9065. if (packet) {
  9066. packet->setDataByName("window", window.c_str());
  9067. packet->setDataByName("show", show);
  9068. client->QueuePacket(packet->serialize());
  9069. safe_delete(packet);
  9070. }
  9071. return 0;
  9072. }
  9073. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9074. //See GameEvents.txt for options that can be used for this function
  9075. if (!lua_interface)
  9076. return 0;
  9077. Client* client = 0;
  9078. Spawn* player = lua_interface->GetSpawn(state);
  9079. string event_name = lua_interface->GetStringValue(state, 2);
  9080. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9081. if (!player || !player->IsPlayer()) {
  9082. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9083. return 0;
  9084. }
  9085. if (player->GetZone())
  9086. client = player->GetZone()->GetClientBySpawn(player);
  9087. if (!client) {
  9088. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9089. return 0;
  9090. }
  9091. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9092. if (packet) {
  9093. packet->setDataByName("event_name", event_name.c_str());
  9094. packet->setDataByName("enabled", enabled);
  9095. client->QueuePacket(packet->serialize());
  9096. safe_delete(packet);
  9097. }
  9098. return 0;
  9099. }
  9100. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9101. if (!lua_interface)
  9102. return 0;
  9103. Spawn* player = lua_interface->GetSpawn(state);
  9104. if (player && player->IsPlayer()) {
  9105. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9106. return 1;
  9107. }
  9108. return 0;
  9109. }
  9110. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9111. if (!lua_interface)
  9112. return 0;
  9113. Spawn* player = lua_interface->GetSpawn(state);
  9114. int8 step = lua_interface->GetInt8Value(state, 2);
  9115. if (player && player->IsPlayer() && step > 0) {
  9116. ((Player*)player)->SetTutorialStep(step);
  9117. }
  9118. return 0;
  9119. }
  9120. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9121. if (!lua_interface)
  9122. return 0;
  9123. Client* client = 0;
  9124. Spawn* player = lua_interface->GetSpawn(state);
  9125. string window = lua_interface->GetStringValue(state, 2);
  9126. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9127. if (!player) {
  9128. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9129. return 0;
  9130. }
  9131. if (!player->IsPlayer()) {
  9132. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9133. return 0;
  9134. }
  9135. else
  9136. client = ((Player*)player)->GetClient();
  9137. if (!client) {
  9138. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9139. return 0;
  9140. }
  9141. if (window.length() == 0) {
  9142. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9143. return 0;
  9144. }
  9145. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9146. if (packet) {
  9147. packet->setDataByName("window", window.c_str());
  9148. packet->setDataByName("flash_seconds", flash_seconds);
  9149. client->QueuePacket(packet->serialize());
  9150. safe_delete(packet);
  9151. }
  9152. return 0;
  9153. }
  9154. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9155. if (!lua_interface)
  9156. return 0;
  9157. Spawn* spawn = lua_interface->GetSpawn(state);
  9158. Spawn* target = lua_interface->GetSpawn(state, 2);
  9159. if (spawn && target)
  9160. return spawn->CheckLoS(target);
  9161. return 0;
  9162. }
  9163. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9164. if (!lua_interface)
  9165. return 0;
  9166. Spawn* spawn = lua_interface->GetSpawn(state);
  9167. float x = lua_interface->GetFloatValue(state, 2);
  9168. float y = lua_interface->GetFloatValue(state, 3);
  9169. float z = lua_interface->GetFloatValue(state, 4);
  9170. if (spawn)
  9171. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9172. return 0;
  9173. }
  9174. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9175. if (!lua_interface)
  9176. return 0;
  9177. ZoneServer* zone = lua_interface->GetZone(state);
  9178. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9179. if (zone)
  9180. zone->SetExpansionFlag(xpackFlag);
  9181. return 0;
  9182. }
  9183. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9184. if (!lua_interface)
  9185. return 0;
  9186. ZoneServer* zone = lua_interface->GetZone(state);
  9187. if (zone) {
  9188. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9189. return 1;
  9190. }
  9191. return 0;
  9192. }
  9193. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9194. if (!lua_interface)
  9195. return 0;
  9196. ZoneServer* zone = lua_interface->GetZone(state);
  9197. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9198. if (zone)
  9199. zone->SetHolidayFlag(holidayFlag);
  9200. return 0;
  9201. }
  9202. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9203. if (!lua_interface)
  9204. return 0;
  9205. ZoneServer* zone = lua_interface->GetZone(state);
  9206. if (zone) {
  9207. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9208. return 1;
  9209. }
  9210. return 0;
  9211. }
  9212. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9213. if (!lua_interface)
  9214. return 0;
  9215. Spawn* spawn = lua_interface->GetSpawn(state);
  9216. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9217. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9218. float distance = lua_interface->GetFloatValue(state, 4);
  9219. string in_range_function = lua_interface->GetStringValue(state, 5);
  9220. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9221. if (spawn && distance > 0 && in_range_function.length() > 0)
  9222. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9223. return 0;
  9224. }
  9225. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9226. if (!lua_interface)
  9227. return 0;
  9228. Spawn* spawn = lua_interface->GetSpawn(state);
  9229. Spawn* target = lua_interface->GetSpawn(state, 2);
  9230. if (spawn && target)
  9231. {
  9232. if (spawn->IsPlayer() && target->IsEntity())
  9233. {
  9234. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9235. return 1;
  9236. }
  9237. else if (spawn->IsEntity() && target->IsEntity())
  9238. {
  9239. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9240. return 1;
  9241. }
  9242. }
  9243. return 0;
  9244. }
  9245. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9246. if (!lua_interface)
  9247. return 0;
  9248. Spawn* spawn = lua_interface->GetSpawn(state);
  9249. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9250. if (spawn && spawn->IsEntity())
  9251. {
  9252. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9253. if (spawn->IsPlayer())
  9254. {
  9255. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9256. if (client)
  9257. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9258. }
  9259. }
  9260. return 0;
  9261. }
  9262. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9263. if (!lua_interface)
  9264. return 0;
  9265. Spawn* spawn = lua_interface->GetSpawn(state);
  9266. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9267. if (spawn && spawn->IsEntity())
  9268. {
  9269. ((Entity*)spawn)->SetSeeHideSpell(val);
  9270. if (spawn->IsPlayer())
  9271. {
  9272. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9273. if (client)
  9274. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9275. }
  9276. }
  9277. return 0;
  9278. }
  9279. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9280. {
  9281. if (!lua_interface)
  9282. return 0;
  9283. Spawn* player = lua_interface->GetSpawn(state);
  9284. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9285. string command = lua_interface->GetStringValue(state, 3);
  9286. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9287. if (spawn && player && player->IsPlayer())
  9288. {
  9289. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9290. bool res = false;
  9291. if (cmd)
  9292. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9293. lua_interface->SetBooleanValue(state, res);
  9294. return 1;
  9295. }
  9296. return 0;
  9297. }
  9298. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9299. {
  9300. if (!lua_interface)
  9301. return 0;
  9302. Spawn* spawn = lua_interface->GetSpawn(state);
  9303. string command = lua_interface->GetStringValue(state, 2);
  9304. if (spawn && command.length() > 0)
  9305. spawn->RemovePrimaryEntityCommand(command.c_str());
  9306. return 0;
  9307. }
  9308. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9309. if (!lua_interface)
  9310. return 0;
  9311. Spawn* spawn = lua_interface->GetSpawn(state);
  9312. float distance = lua_interface->GetFloatValue(state, 2);
  9313. string command = lua_interface->GetStringValue(state, 3);
  9314. Spawn* player = lua_interface->GetSpawn(state, 4);
  9315. if (spawn) {
  9316. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9317. }
  9318. return 0;
  9319. }
  9320. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9321. if (!lua_interface)
  9322. return 0;
  9323. Spawn* spawn = lua_interface->GetSpawn(state);
  9324. Spawn* player = lua_interface->GetSpawn(state, 2);
  9325. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9326. if (spawn && player && transport_id && player->IsPlayer()) {
  9327. Client* client = 0;
  9328. if (player && player->IsPlayer())
  9329. client = player->GetZone()->GetClientBySpawn(player);
  9330. if (!client)
  9331. return 0;
  9332. vector<TransportDestination*> destinations;
  9333. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9334. if (destinations.size())
  9335. {
  9336. client->SetTemporaryTransportID(transport_id);
  9337. client->ProcessTeleport(spawn, &destinations, transport_id);
  9338. }
  9339. else
  9340. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9341. }
  9342. return 0;
  9343. }
  9344. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9345. if (!lua_interface)
  9346. return 0;
  9347. Spawn* player = lua_interface->GetSpawn(state);
  9348. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9349. if (player && player->IsPlayer()) {
  9350. Client* client = 0;
  9351. if (player && player->IsPlayer())
  9352. client = player->GetZone()->GetClientBySpawn(player);
  9353. if (!client)
  9354. return 0;
  9355. client->SetTemporaryTransportID(transport_id);
  9356. }
  9357. return 0;
  9358. }
  9359. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9360. if (!lua_interface)
  9361. return 0;
  9362. Spawn* player = lua_interface->GetSpawn(state);
  9363. if (player && player->IsPlayer()) {
  9364. Client* client = 0;
  9365. if (player && player->IsPlayer())
  9366. client = player->GetZone()->GetClientBySpawn(player);
  9367. if (!client)
  9368. return 0;
  9369. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9370. return 1;
  9371. }
  9372. return 0;
  9373. }
  9374. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9375. if (!lua_interface)
  9376. return 0;
  9377. Spawn* spawn = lua_interface->GetSpawn(state);
  9378. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9379. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9380. if (!spawn) {
  9381. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9382. return 0;
  9383. }
  9384. if (!spawn->IsEntity()) {
  9385. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9386. return 0;
  9387. }
  9388. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9389. {
  9390. lua_interface->LogError("%s: LUA SetAlignment command error: alignment value beyond supported min: %i and max: %i", lua_interface->GetScriptName(state), SCHAR_MIN, SCHAR_MAX);
  9391. return 0;
  9392. }
  9393. if (spell && spell->targets.size() > 0) {
  9394. ZoneServer* zone = spell->caster->GetZone();
  9395. for (int8 i = 0; i < spell->targets.size(); i++) {
  9396. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9397. if (target->IsEntity()) {
  9398. ((Entity*)target)->GetInfoStruct()->alignment = (sint8)alignment;
  9399. if (target->IsPlayer())
  9400. ((Player*)target)->SetCharSheetChanged(true);
  9401. }
  9402. }
  9403. }
  9404. else {
  9405. ((Entity*)spawn)->GetInfoStruct()->alignment = (sint8)alignment;
  9406. if (spawn->IsPlayer())
  9407. ((Player*)spawn)->SetCharSheetChanged(true);
  9408. }
  9409. return 0;
  9410. }
  9411. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9412. if (!lua_interface)
  9413. return 0;
  9414. Spawn* spawn = lua_interface->GetSpawn(state);
  9415. if (!spawn) {
  9416. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9417. return 0;
  9418. }
  9419. if (!spawn->IsEntity()) {
  9420. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9421. return 0;
  9422. }
  9423. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9424. return 1;
  9425. }
  9426. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9427. if (!lua_interface)
  9428. return 0;
  9429. int32 spell_id = lua_interface->GetInt32Value(state);
  9430. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9431. if (spell_id > 0) {
  9432. if (spell_tier == 0)
  9433. spell_tier = 1;
  9434. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9435. LuaSpell* lua_spell = 0;
  9436. if (lua_interface)
  9437. lua_spell = lua_interface->GetSpell(spell->GetSpellData()->lua_script.c_str());
  9438. if (!lua_spell)
  9439. return 0;
  9440. lua_spell->spell = new Spell(spell);
  9441. lua_interface->AddCustomSpell(lua_spell);
  9442. lua_interface->SetSpellValue(state, lua_spell);
  9443. return 1;
  9444. }
  9445. return 0;
  9446. }
  9447. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9448. if (!lua_interface)
  9449. return 0;
  9450. LuaSpell* spell = lua_interface->GetSpell(state);
  9451. string field = lua_interface->GetStringValue(state, 2);
  9452. if (!spell) {
  9453. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9454. return 0;
  9455. }
  9456. if (!spell->spell || !spell->spell->GetSpellData()) {
  9457. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9458. return 0;
  9459. }
  9460. boost::to_lower(field);
  9461. return spell->spell->GetSpellData(state, field);
  9462. }
  9463. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9464. if (!lua_interface)
  9465. return 0;
  9466. LuaSpell* spell = lua_interface->GetSpell(state);
  9467. string field = lua_interface->GetStringValue(state, 2);
  9468. int8 fieldArg = 3; // field value after the initial set
  9469. if (!spell) {
  9470. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9471. return 0;
  9472. }
  9473. if (!spell->spell || !spell->spell->GetSpellData()) {
  9474. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9475. return 0;
  9476. }
  9477. boost::to_lower(field);
  9478. bool valSet = false;
  9479. spell->spell->SetSpellData(state, field, fieldArg);
  9480. return valSet;
  9481. }
  9482. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9483. if (!lua_interface)
  9484. return 0;
  9485. LuaSpell* spell = lua_interface->GetSpell(state);
  9486. int8 idx = lua_interface->GetInt32Value(state, 2);
  9487. if (!spell) {
  9488. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9489. return 0;
  9490. }
  9491. if (!spell->spell || !spell->spell->GetSpellData()) {
  9492. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9493. return 0;
  9494. }
  9495. if (spell->spell->lua_data.size() <= idx)
  9496. {
  9497. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9498. return 0;
  9499. }
  9500. bool setVal = true;
  9501. LUAData* data = spell->spell->lua_data[idx];
  9502. switch (data->type)
  9503. {
  9504. case 0:
  9505. {
  9506. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9507. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9508. data->int_value = value;
  9509. data->int_value2 = value2;
  9510. break;
  9511. }
  9512. case 1:
  9513. {
  9514. float value = lua_interface->GetFloatValue(state, 3);
  9515. float value2 = lua_interface->GetFloatValue(state, 4);
  9516. data->float_value = value;
  9517. data->float_value2 = value2;
  9518. break;
  9519. }
  9520. case 2:
  9521. {
  9522. bool value = lua_interface->GetBooleanValue(state, 3);
  9523. data->bool_value = value;
  9524. break;
  9525. }
  9526. case 3:
  9527. {
  9528. string value = lua_interface->GetStringValue(state, 3);
  9529. string value2 = lua_interface->GetStringValue(state, 4);
  9530. data->string_value = value;
  9531. data->string_value2 = value2;
  9532. break;
  9533. }
  9534. default:
  9535. setVal = false;
  9536. }
  9537. return setVal;
  9538. }
  9539. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9540. if (!lua_interface)
  9541. return 0;
  9542. LuaSpell* spell = lua_interface->GetSpell(state);
  9543. int8 idx = lua_interface->GetInt32Value(state, 2);
  9544. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9545. if (!spell) {
  9546. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9547. return 0;
  9548. }
  9549. if (!spell->spell || !spell->spell->GetSpellData()) {
  9550. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9551. return 0;
  9552. }
  9553. if (spell->spell->lua_data.size() <= idx)
  9554. {
  9555. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9556. return 0;
  9557. }
  9558. bool setVal = true;
  9559. LUAData* data = spell->spell->lua_data[idx];
  9560. switch (data->type)
  9561. {
  9562. case 0:
  9563. {
  9564. if(!secondfield)
  9565. lua_interface->SetSInt32Value(state, data->int_value);
  9566. else
  9567. lua_interface->SetSInt32Value(state, data->int_value2);
  9568. break;
  9569. }
  9570. case 1:
  9571. {
  9572. if (!secondfield)
  9573. lua_interface->SetFloatValue(state, data->float_value);
  9574. else
  9575. lua_interface->SetFloatValue(state, data->float_value2);
  9576. break;
  9577. }
  9578. case 2:
  9579. {
  9580. lua_interface->SetBooleanValue(state, data->bool_value);
  9581. break;
  9582. }
  9583. case 3:
  9584. {
  9585. if (!secondfield)
  9586. lua_interface->SetStringValue(state, data->string_value.c_str());
  9587. else
  9588. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9589. break;
  9590. }
  9591. default:
  9592. setVal = false;
  9593. }
  9594. return setVal;
  9595. }
  9596. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9597. if (!lua_interface)
  9598. return 0;
  9599. LuaSpell* spell = lua_interface->GetSpell(state);
  9600. int8 idx = lua_interface->GetInt32Value(state, 2);
  9601. string field = lua_interface->GetStringValue(state, 3);
  9602. boost::to_lower(field);
  9603. if (!spell) {
  9604. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9605. return 0;
  9606. }
  9607. if (!spell->spell || !spell->spell->GetSpellData()) {
  9608. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9609. return 0;
  9610. }
  9611. if (spell->spell->effects.size() <= idx)
  9612. {
  9613. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9614. return 0;
  9615. }
  9616. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9617. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9618. if (field == "description")
  9619. effect->description = string(lua_interface->GetStringValue(state, 4));
  9620. else if (field == "bullet")
  9621. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9622. else if (field == "percentage")
  9623. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9624. else // no match
  9625. return 0;
  9626. return 1;
  9627. }
  9628. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9629. if (!lua_interface)
  9630. return 0;
  9631. LuaSpell* spell = lua_interface->GetSpell(state);
  9632. int8 idx = lua_interface->GetInt32Value(state, 2);
  9633. string field = lua_interface->GetStringValue(state, 3);
  9634. boost::to_lower(field);
  9635. if (!spell) {
  9636. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9637. return 0;
  9638. }
  9639. if (!spell->spell || !spell->spell->GetSpellData()) {
  9640. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9641. return 0;
  9642. }
  9643. if (spell->spell->effects.size() <= idx)
  9644. {
  9645. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9646. return 0;
  9647. }
  9648. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9649. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9650. if (field == "description")
  9651. lua_interface->SetStringValue(state, effect->description.c_str());
  9652. else if (field == "bullet")
  9653. lua_interface->SetInt32Value(state, effect->subbullet);
  9654. else if (field == "percentage")
  9655. lua_interface->SetInt32Value(state, effect->percentage);
  9656. else // no match
  9657. return 0;
  9658. return 1;
  9659. }
  9660. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9661. if (!lua_interface)
  9662. return 0;
  9663. LuaSpell* spell = lua_interface->GetSpell(state);
  9664. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9665. Spawn* target = lua_interface->GetSpawn(state, 3);
  9666. if (!target) {
  9667. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9668. return 0;
  9669. }
  9670. if (!target->IsEntity()) {
  9671. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9672. return 0;
  9673. }
  9674. if (!spell) {
  9675. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9676. return 0;
  9677. }
  9678. if (caster && !caster->IsEntity()) {
  9679. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9680. return 0;
  9681. }
  9682. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9683. return 0;
  9684. }
  9685. int EQ2Emu_lua_InWater(lua_State* state) {
  9686. if (!lua_interface)
  9687. return 0;
  9688. Spawn* spawn = lua_interface->GetSpawn(state);
  9689. if (spawn) {
  9690. lua_interface->SetBooleanValue(state, spawn->InWater());
  9691. return 1;
  9692. }
  9693. return 0;
  9694. }
  9695. int EQ2Emu_lua_InLava(lua_State* state) {
  9696. if (!lua_interface)
  9697. return 0;
  9698. Spawn* spawn = lua_interface->GetSpawn(state);
  9699. if (spawn) {
  9700. lua_interface->SetBooleanValue(state, spawn->InLava());
  9701. return 1;
  9702. }
  9703. return 0;
  9704. }
  9705. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9706. if (!lua_interface)
  9707. return 0;
  9708. Spawn* attacker = lua_interface->GetSpawn(state);
  9709. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9710. int8 type = lua_interface->GetInt8Value(state, 3);
  9711. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9712. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9713. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9714. string spell_name = lua_interface->GetStringValue(state, 7);
  9715. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9716. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9717. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9718. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9719. if (!attacker) {
  9720. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9721. return 0;
  9722. }
  9723. if (!attacker->IsEntity()) {
  9724. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9725. return 0;
  9726. }
  9727. if (!victim) {
  9728. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9729. return 0;
  9730. }
  9731. if (!victim->IsEntity()) {
  9732. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9733. return 0;
  9734. }
  9735. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9736. return 0;
  9737. }
  9738. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9739. if (!lua_interface)
  9740. return 0;
  9741. Spawn* spawn = lua_interface->GetSpawn(state);
  9742. if (spawn) {
  9743. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9744. return 1;
  9745. }
  9746. return 0;
  9747. }