LuaFunctions.cpp 341 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include <boost/algorithm/string/predicate.hpp>
  36. #include <sstream>
  37. #include <boost/algorithm/string.hpp>
  38. extern MasterFactionList master_faction_list;
  39. extern WorldDatabase database;
  40. extern LuaInterface* lua_interface;
  41. extern ConfigReader configReader;
  42. extern MasterQuestList master_quest_list;
  43. extern MasterItemList master_item_list;
  44. extern MasterSpellList master_spell_list;
  45. extern World world;
  46. extern Commands commands;
  47. extern ZoneList zone_list;
  48. extern Races races;
  49. extern Classes classes;
  50. extern Variables variables;
  51. extern MasterSkillList master_skill_list;
  52. extern MasterHeroicOPList master_ho_list;
  53. extern MasterRaceTypeList race_types_list;
  54. extern MasterLanguagesList master_languages_list;
  55. extern RuleManager rule_manager;
  56. vector<string> ParseString(string strVal, char delim) {
  57. stringstream ss(strVal);
  58. vector<string> ret;
  59. while (ss.good())
  60. {
  61. string substr;
  62. getline(ss, substr, delim);
  63. ret.push_back(substr);
  64. }
  65. return ret;
  66. }
  67. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  68. stringstream ss(strVal);
  69. vector<unsigned int> ret;
  70. while (ss.good())
  71. {
  72. string substr;
  73. getline(ss, substr, delim);
  74. stringstream valss(substr);
  75. unsigned int val = 0;
  76. valss >> val;
  77. ret.push_back(val);
  78. }
  79. return ret;
  80. }
  81. map<string, signed int> ParseStringMap(string strVal, char delim) {
  82. vector<string> pairs = ParseString(strVal, delim);
  83. vector<string>::iterator itr;
  84. map<string, signed int> ret;
  85. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  86. vector<string> keyvaluepair = ParseString(*itr, ':');
  87. if (keyvaluepair.size() == 2) {
  88. stringstream valss(keyvaluepair[1]);
  89. int32 val = 0;
  90. valss >> val;
  91. ret[keyvaluepair[0]] = val;
  92. }
  93. }
  94. return ret;
  95. }
  96. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  97. vector<string> pairs = ParseString(strVal, delim);
  98. vector<string>::iterator itr;
  99. map<unsigned int, unsigned short> ret;
  100. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  101. vector<string> keyvaluepair = ParseString(*itr, ':');
  102. int32 key = 0;
  103. if (keyvaluepair.size() > 0) {
  104. stringstream keyss(keyvaluepair[0]);
  105. keyss >> key;
  106. }
  107. if (keyvaluepair.size() == 1) {
  108. ret[key] = 1;
  109. }
  110. else if (keyvaluepair.size() == 2) {
  111. stringstream valss(keyvaluepair[1]);
  112. unsigned short val = 0;
  113. valss >> val;
  114. ret[key] = val;
  115. }
  116. }
  117. return ret;
  118. }
  119. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  120. vector<string> pairs = ParseString(strVal, delim);
  121. vector<string>::iterator itr;
  122. map<unsigned int, signed int> ret;
  123. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  124. vector<string> keyvaluepair = ParseString(*itr, ':');
  125. int32 key = 0;
  126. if (keyvaluepair.size() > 0) {
  127. stringstream keyss(keyvaluepair[0]);
  128. keyss >> key;
  129. }
  130. if (keyvaluepair.size() == 1) {
  131. ret[key] = 1;
  132. }
  133. else if (keyvaluepair.size() == 2) {
  134. stringstream valss(keyvaluepair[1]);
  135. signed int val = 0;
  136. valss >> val;
  137. ret[key] = val;
  138. }
  139. }
  140. return ret;
  141. }
  142. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  143. if (!lua_interface)
  144. return 0;
  145. Spawn* spawn = lua_interface->GetSpawn(state);
  146. string mp3_string = lua_interface->GetStringValue(state, 2);
  147. string text_string = lua_interface->GetStringValue(state, 3);
  148. string emote_string = lua_interface->GetStringValue(state, 4);
  149. int32 key1 = lua_interface->GetInt32Value(state, 5);
  150. int32 key2 = lua_interface->GetInt32Value(state, 6);
  151. Spawn* player = lua_interface->GetSpawn(state, 7);
  152. int8 language = lua_interface->GetInt8Value(state, 8);
  153. if (spawn) {
  154. const char* mp3 = 0;
  155. const char* text = 0;
  156. const char* emote = 0;
  157. if (mp3_string.length() > 0)
  158. mp3 = mp3_string.c_str();
  159. if (text_string.length() > 0)
  160. text = text_string.c_str();
  161. if (emote_string.length() > 0)
  162. emote = emote_string.c_str();
  163. Client* client = 0;
  164. if (player && player->IsPlayer())
  165. client = spawn->GetZone()->GetClientBySpawn(player);
  166. if (client) {
  167. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  168. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  169. }
  170. else
  171. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. return 0;
  174. }
  175. int EQ2Emu_lua_PlaySound(lua_State* state) {
  176. if (!lua_interface)
  177. return 0;
  178. Spawn* spawn = lua_interface->GetSpawn(state);
  179. string sound_string = lua_interface->GetStringValue(state, 2);
  180. float x = lua_interface->GetFloatValue(state, 3);
  181. float y = lua_interface->GetFloatValue(state, 4);
  182. float z = lua_interface->GetFloatValue(state, 5);
  183. Spawn* player = lua_interface->GetSpawn(state, 6);
  184. if (spawn && sound_string.length() > 0) {
  185. Client* client = 0;
  186. if (player && player->IsPlayer())
  187. client = spawn->GetZone()->GetClientBySpawn(player);
  188. if (client)
  189. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  190. else
  191. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  192. }
  193. return 0;
  194. }
  195. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  196. if (!lua_interface)
  197. return 0;
  198. Spawn* spawn = lua_interface->GetSpawn(state);
  199. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  200. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  201. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  202. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  203. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  204. if (!spawn) {
  205. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  206. return 0;
  207. }
  208. if (quest_id > 0) {
  209. //Add this quest to the list of required quests for this spawn
  210. spawn->SetQuestsRequired(quest_id, quest_step);
  211. //If private spawn value set
  212. if (private_spawn) {
  213. //Set the spawn to be private when not granted access through this quest
  214. spawn->AddAllowAccessSpawn(spawn);
  215. spawn->SetPrivateQuestSpawn(true);
  216. }
  217. //This value allows access after a quest step, or the whole quest has been completed
  218. if (continued_access)
  219. spawn->SetQuestsRequiredContinuedAccess(true);
  220. //This value will override vis_flags in the vis packet
  221. if (flag_override > 0)
  222. spawn->SetQuestsRequiredOverride(flag_override);
  223. }
  224. return 0;
  225. }
  226. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  227. if (!lua_interface)
  228. return 0;
  229. Spawn* spawn = lua_interface->GetSpawn(state);
  230. float max_distance = lua_interface->GetFloatValue(state, 2);
  231. string variable = lua_interface->GetStringValue(state, 3);
  232. string value = lua_interface->GetStringValue(state, 4);
  233. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  234. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  235. return 0;
  236. }
  237. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  238. if (!lua_interface)
  239. return 0;
  240. Client* client = 0;
  241. Spawn* player = lua_interface->GetSpawn(state);
  242. if (!player) {
  243. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  244. return 0;
  245. }
  246. if (!player->IsPlayer()) {
  247. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  248. return 0;
  249. }
  250. if (player->GetZone())
  251. client = player->GetZone()->GetClientBySpawn(player);
  252. if (!client) {
  253. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  254. return 0;
  255. }
  256. float intensity = lua_interface->GetFloatValue(state, 2);
  257. int8 direction = lua_interface->GetInt8Value(state, 3);
  258. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  259. if (packet) {
  260. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  261. v1 = *(float *)(a1 + 4);
  262. if ( v1 > 0.0 )
  263. v2 = fminf(v1, 1.0);
  264. else
  265. v2 = 0.1;
  266. */
  267. packet->setDataByName("intensity", intensity);
  268. if ( client->GetVersion() > 546 )
  269. packet->setDataByName("direction", direction);
  270. client->QueuePacket(packet->serialize());
  271. safe_delete(packet);
  272. }
  273. return 0;
  274. }
  275. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  276. if (!lua_interface)
  277. return 0;
  278. Spawn* dead = lua_interface->GetSpawn(state);
  279. Spawn* killer = lua_interface->GetSpawn(state, 2);
  280. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  281. if (dead && dead->Alive() && dead->GetZone())
  282. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  283. return 0;
  284. }
  285. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  286. if (!lua_interface)
  287. return 0;
  288. Spawn* spawn = lua_interface->GetSpawn(state);
  289. float max_distance = lua_interface->GetFloatValue(state, 2);
  290. bool include_players = lua_interface->GetInt8Value(state, 3);
  291. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  292. if (max_distance > 0 && spawn && spawn->GetZone())
  293. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  294. return 0;
  295. }
  296. int EQ2Emu_lua_Despawn(lua_State* state) {
  297. if (!lua_interface)
  298. return 0;
  299. Spawn* spawn = lua_interface->GetSpawn(state);
  300. int32 delay = lua_interface->GetInt32Value(state, 2);
  301. if (spawn && spawn->GetZone())
  302. spawn->GetZone()->Despawn(spawn, delay);
  303. return 0;
  304. }
  305. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  306. if (!lua_interface)
  307. return 0;
  308. Spawn* spawn = lua_interface->GetSpawn(state);
  309. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  310. if (spawn) {
  311. spawn->info_changed = true;
  312. spawn->SetShowHandIcon(displayHandIcon);
  313. }
  314. return 0;
  315. }
  316. //this function is used to force an update packet to be sent.
  317. //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
  318. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. if (spawn) {
  323. spawn->vis_changed = true;
  324. }
  325. return 0;
  326. }
  327. //this function is used to force an update packet to be sent.
  328. //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
  329. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  330. if (!lua_interface)
  331. return 0;
  332. Spawn* spawn = lua_interface->GetSpawn(state);
  333. if (spawn) {
  334. spawn->info_changed = true;
  335. }
  336. return 0;
  337. }
  338. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  339. if (!lua_interface)
  340. return 0;
  341. Spawn* spawn = lua_interface->GetSpawn(state);
  342. int32 new_state = lua_interface->GetInt32Value(state, 2);
  343. if (spawn) {
  344. spawn->GetZone()->SendStateCommand(spawn, new_state);
  345. }
  346. return 0;
  347. }
  348. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  349. if (!lua_interface)
  350. return 0;
  351. Spawn* spawn = lua_interface->GetSpawn(state);
  352. string variable = lua_interface->GetStringValue(state, 2);
  353. string value = lua_interface->GetStringValue(state, 3);
  354. 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.
  355. bool temporary_flag = lua_interface->GetBooleanValue(state, 5); // default false as originally designed, allow user to set temporary_flag true to not update DB
  356. int32 type = commands.GetSpawnSetType(variable);
  357. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  358. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  359. return 0;
  360. }
  361. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  362. if (!lua_interface)
  363. return 0;
  364. Spawn* spawn = lua_interface->GetSpawn(state);
  365. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  366. if (spawn && spawn_id > 0) {
  367. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  368. if (closest_spawn) {
  369. lua_interface->SetSpawnValue(state, closest_spawn);
  370. return 1;
  371. }
  372. }
  373. return 0;
  374. }
  375. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  376. if (!lua_interface)
  377. return 0;
  378. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  379. int32 position = lua_interface->GetInt32Value(state, 2);
  380. if (spawnList) {
  381. if (spawnList->size() > position) {
  382. lua_interface->SetSpawnValue(state, spawnList->at(position));
  383. return 1;
  384. }
  385. else {
  386. return 0;
  387. }
  388. return spawnList->size();
  389. }
  390. return 0;
  391. }
  392. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  393. if (!lua_interface)
  394. return 0;
  395. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  396. if (spawnList) {
  397. return spawnList->size();
  398. }
  399. return 0;
  400. }
  401. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  402. if (!lua_interface)
  403. return 0;
  404. vector<Spawn*>* spawnList = new vector<Spawn*>();
  405. lua_interface->SetSpawnListValue(state, spawnList);
  406. return 1;
  407. }
  408. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  409. if (!lua_interface)
  410. return 0;
  411. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  412. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  413. if (spawnList) {
  414. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  415. if (it == spawnList->end())
  416. spawnList->push_back(spawn);
  417. }
  418. return 0;
  419. }
  420. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  421. if (!lua_interface)
  422. return 0;
  423. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  424. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  425. if (spawnList) {
  426. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  427. if(it != spawnList->end())
  428. spawnList->erase(it);
  429. }
  430. return 0;
  431. }
  432. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  433. if (!lua_interface)
  434. return 0;
  435. Spawn* spawn = lua_interface->GetSpawn(state);
  436. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  437. if (spawn) {
  438. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  439. if (spawns.size() > 0) {
  440. vector<Spawn*>* spawnList = new vector<Spawn*>();
  441. vector<Spawn*>::iterator itr;
  442. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  443. spawnList->push_back(*itr);
  444. }
  445. lua_interface->SetSpawnListValue(state, spawnList);
  446. return 1;
  447. }
  448. }
  449. return 0;
  450. }
  451. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  452. if (!lua_interface)
  453. return 0;
  454. string variable_name = lua_interface->GetStringValue(state);
  455. Variable* var = variables.FindVariable(variable_name);
  456. if (var) {
  457. lua_interface->SetStringValue(state, var->GetValue());
  458. return 1;
  459. }
  460. return 0;
  461. }
  462. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  463. if (!lua_interface)
  464. return 0;
  465. int32 total_coins = lua_interface->GetInt32Value(state);
  466. if (total_coins == 0) {
  467. lua_interface->SetStringValue(state, "0 copper");
  468. return 1;
  469. }
  470. char tmp[64] = { 0 };
  471. string message = "";
  472. int32 val = 0;
  473. if (total_coins >= 1000000) {
  474. val = total_coins / 1000000;
  475. total_coins -= 1000000 * val;
  476. sprintf(tmp, " %u Platinum", val);
  477. message.append(tmp);
  478. memset(tmp, 0, 64);
  479. }
  480. if (total_coins >= 10000) {
  481. val = total_coins / 10000;
  482. total_coins -= 10000 * val;
  483. sprintf(tmp, " %u Gold", val);
  484. message.append(tmp);
  485. memset(tmp, 0, 64);
  486. }
  487. if (total_coins >= 100) {
  488. val = total_coins / 100;
  489. total_coins -= 100 * val;
  490. sprintf(tmp, " %u Silver", val);
  491. message.append(tmp);
  492. memset(tmp, 0, 64);
  493. }
  494. if (total_coins > 0) {
  495. sprintf(tmp, " %u Copper", (int32)total_coins);
  496. message.append(tmp);
  497. }
  498. lua_interface->SetStringValue(state, message.c_str());
  499. return 1;
  500. }
  501. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  502. ZoneServer* zone = lua_interface->GetZone(state);
  503. int32 group_id = lua_interface->GetInt32Value(state, 2);
  504. if (zone) {
  505. Spawn* spawn = zone->GetSpawnGroup(group_id);
  506. if (spawn) {
  507. lua_interface->SetSpawnValue(state, spawn);
  508. return 1;
  509. }
  510. }
  511. return 0;
  512. }
  513. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  514. ZoneServer* zone = lua_interface->GetZone(state);
  515. int32 location_id = lua_interface->GetInt32Value(state, 2);
  516. if (zone) {
  517. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  518. if (spawn) {
  519. lua_interface->SetSpawnValue(state, spawn);
  520. return 1;
  521. }
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  526. Spawn* spawn = lua_interface->GetSpawn(state);
  527. if (spawn) {
  528. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  529. return 1;
  530. }
  531. return 0;
  532. }
  533. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  534. Spawn* spawn = lua_interface->GetSpawn(state);
  535. if (spawn) {
  536. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  537. return 1;
  538. }
  539. return 0;
  540. }
  541. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  542. Spawn* spawn = lua_interface->GetSpawn(state);
  543. if (spawn) {
  544. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  545. return 1;
  546. }
  547. return 0;
  548. }
  549. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  550. Spawn* spawn = lua_interface->GetSpawn(state);
  551. if (spawn) {
  552. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  553. return 1;
  554. }
  555. return 0;
  556. }
  557. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  558. Player* player = (Player*)lua_interface->GetSpawn(state);
  559. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  560. if (player && player->IsPlayer() && faction_id > 0) {
  561. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  562. return 1;
  563. }
  564. return 0;
  565. }
  566. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  567. if (!lua_interface)
  568. return 0;
  569. Spawn* spawn = lua_interface->GetSpawn(state);
  570. int32 value = lua_interface->GetInt32Value(state, 2);
  571. if (spawn) {
  572. spawn->SetFactionID(value);
  573. }
  574. return 0;
  575. }
  576. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  577. Spawn* spawn = lua_interface->GetSpawn(state);
  578. if (spawn) {
  579. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  580. return 1;
  581. }
  582. return 0;
  583. }
  584. int EQ2Emu_lua_GetGender(lua_State* state) {
  585. Spawn* spawn = lua_interface->GetSpawn(state);
  586. if (spawn) {
  587. lua_interface->SetInt32Value(state, spawn->GetGender());
  588. return 1;
  589. }
  590. return 0;
  591. }
  592. int EQ2Emu_lua_GetTarget(lua_State* state) {
  593. Spawn* spawn = lua_interface->GetSpawn(state);
  594. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  595. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  596. return 1;
  597. }
  598. return 0;
  599. }
  600. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  601. if (!lua_interface)
  602. return 0;
  603. Spawn* spawn = lua_interface->GetSpawn(state);
  604. string mp3_string = lua_interface->GetStringValue(state, 2);
  605. int32 key1 = lua_interface->GetInt32Value(state, 3);
  606. int32 key2 = lua_interface->GetInt32Value(state, 4);
  607. Spawn* player = lua_interface->GetSpawn(state, 5);
  608. if (spawn && mp3_string.length() > 0) {
  609. Client* client = 0;
  610. if (player && player->IsPlayer())
  611. client = spawn->GetZone()->GetClientBySpawn(player);
  612. if (client) {
  613. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  614. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  615. }
  616. else
  617. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  618. }
  619. return 0;
  620. }
  621. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  622. if (!lua_interface)
  623. return 0;
  624. Spawn* spawn = lua_interface->GetSpawn(state);
  625. if (spawn) {
  626. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  627. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  628. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  629. return 3;
  630. }
  631. return 0;
  632. }
  633. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  634. if (!lua_interface)
  635. return 0;
  636. Spawn* spawn = lua_interface->GetSpawn(state);
  637. if (spawn) {
  638. int32 item_id = lua_interface->GetInt32Value(state, 2);
  639. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  640. return 1;
  641. }
  642. return 0;
  643. }
  644. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  645. if (!lua_interface)
  646. return 0;
  647. Spawn* spawn = lua_interface->GetSpawn(state);
  648. if (spawn && spawn->IsEntity()) {
  649. int32 item_id = lua_interface->GetInt32Value(state, 2);
  650. int16 charges = lua_interface->GetInt16Value(state, 3);
  651. if (charges == 0)
  652. charges = 1;
  653. ((Entity*)spawn)->AddLootItem(item_id, charges);
  654. }
  655. return 0;
  656. }
  657. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  658. if (!lua_interface)
  659. return 0;
  660. Spawn* spawn = lua_interface->GetSpawn(state);
  661. if (spawn && spawn->IsEntity()) {
  662. int32 item_id = lua_interface->GetInt32Value(state, 2);
  663. spawn->LootItem(item_id);
  664. }
  665. return 0;
  666. }
  667. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  668. if (!lua_interface)
  669. return 0;
  670. Spawn* spawn = lua_interface->GetSpawn(state);
  671. if (spawn) {
  672. int32 val = lua_interface->GetInt32Value(state, 2);
  673. spawn->AddLootCoins(val);
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* entity = lua_interface->GetSpawn(state);
  681. Spawn* player = lua_interface->GetSpawn(state, 2);
  682. if (entity && player && player->IsPlayer()) {
  683. int32 coins = lua_interface->GetInt32Value(state, 3);
  684. vector<Item*>* items = 0;
  685. int i = 0;
  686. int32 item_id = 0;
  687. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  688. if (items == 0)
  689. items = new vector<Item*>;
  690. if (master_item_list.GetItem(item_id))
  691. items->push_back(master_item_list.GetItem(item_id));
  692. i++;
  693. }
  694. Client* client = 0;
  695. client = player->GetZone()->GetClientBySpawn(player);
  696. if (client)
  697. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  698. if(coins > 0)
  699. entity->AddLootCoins(coins);
  700. safe_delete(items);
  701. }
  702. return 0;
  703. }
  704. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  705. if (!lua_interface)
  706. return 0;
  707. Spawn* entity = lua_interface->GetSpawn(state);
  708. Spawn* player = lua_interface->GetSpawn(state, 2);
  709. int32 item_id = lua_interface->GetInt32Value(state, 3);
  710. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  711. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  717. if (!lua_interface)
  718. return 0;
  719. Spawn* entity = lua_interface->GetSpawn(state);
  720. Spawn* player = lua_interface->GetSpawn(state, 2);
  721. if (entity && player && player->IsPlayer()) {
  722. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  723. return 1;
  724. }
  725. return 0;
  726. }
  727. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  728. if (!lua_interface)
  729. return 0;
  730. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  731. safe_delete(conversation);
  732. conversation = new vector<ConversationOption>();
  733. lua_interface->SetConversationValue(state, conversation);
  734. return 1;
  735. }
  736. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  737. if (!lua_interface)
  738. return 0;
  739. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  740. if (conversation) {
  741. ConversationOption conv_option;
  742. conv_option.option = lua_interface->GetStringValue(state, 2);
  743. conv_option.function = lua_interface->GetStringValue(state, 3);
  744. if (conv_option.option.length() > 0)
  745. conversation->push_back(conv_option);
  746. }
  747. return 0;
  748. }
  749. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  750. if (!lua_interface)
  751. return 0;
  752. Spawn* npc = lua_interface->GetSpawn(state);
  753. Spawn* player = lua_interface->GetSpawn(state, 2);
  754. if (npc && player && player->IsPlayer() && player->GetZone()) {
  755. Client* client = player->GetZone()->GetClientBySpawn(player);
  756. if (client) {
  757. int32 conversation_id = client->GetConversationID(npc, 0);
  758. client->CloseDialog(conversation_id);
  759. }
  760. }
  761. return 0;
  762. }
  763. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  764. if (!lua_interface)
  765. return 0;
  766. Item* item = lua_interface->GetItem(state);
  767. Spawn* player = lua_interface->GetSpawn(state, 2);
  768. if (item && player && player->IsPlayer() && player->GetZone()) {
  769. Client* client = player->GetZone()->GetClientBySpawn(player);
  770. if (client) {
  771. int32 conversation_id = client->GetConversationID(0, item);
  772. client->CloseDialog(conversation_id);
  773. }
  774. }
  775. return 0;
  776. }
  777. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  778. if (!lua_interface)
  779. return 0;
  780. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  781. Spawn* spawn = 0;
  782. Item* item = 0;
  783. int8 type = lua_interface->GetInt8Value(state, 2);
  784. if (type == 1 || type == 3)
  785. spawn = lua_interface->GetSpawn(state, 3);
  786. else if (type == 2 || type == 4)
  787. item = lua_interface->GetItem(state, 3);
  788. Spawn* player = lua_interface->GetSpawn(state, 4);
  789. string text = lua_interface->GetStringValue(state, 5);
  790. string mp3 = lua_interface->GetStringValue(state, 6);
  791. int32 key1 = lua_interface->GetInt32Value(state, 7);
  792. int32 key2 = lua_interface->GetInt32Value(state, 8);
  793. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  794. Client* client = player->GetZone()->GetClientBySpawn(player);
  795. if (client) {
  796. if (spawn) {
  797. // Need to do this so the function works the same as it did before
  798. if (type == 1)
  799. type++;
  800. if (mp3.length() > 0)
  801. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  802. else
  803. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  804. }
  805. else {
  806. if (mp3.length() > 0)
  807. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  808. else
  809. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  810. }
  811. }
  812. }
  813. safe_delete(conversation);
  814. lua_interface->SetConversationValue(state, NULL);
  815. return 0;
  816. }
  817. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  818. if(!lua_interface)
  819. return 0;
  820. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  821. Item* item = lua_interface->GetItem(state, 2);
  822. Spawn* player = lua_interface->GetSpawn(state, 3);
  823. string text = lua_interface->GetStringValue(state, 4);
  824. string mp3 = lua_interface->GetStringValue(state, 5);
  825. int32 key1 = lua_interface->GetInt32Value(state, 6);
  826. int32 key2 = lua_interface->GetInt32Value(state, 7);
  827. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  828. Client* client = player->GetZone()->GetClientBySpawn(player);
  829. if(client){
  830. if(mp3.length() > 0)
  831. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  832. else
  833. client->DisplayConversation(item, conversation, (char*)text.c_str());
  834. }
  835. safe_delete(conversation);
  836. }
  837. return 0;
  838. }*/
  839. int EQ2Emu_lua_StartConversation(lua_State* state) {
  840. if (!lua_interface)
  841. return 0;
  842. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  843. Spawn* npc = lua_interface->GetSpawn(state, 2);
  844. Spawn* player = lua_interface->GetSpawn(state, 3);
  845. string text = lua_interface->GetStringValue(state, 4);
  846. string mp3 = lua_interface->GetStringValue(state, 5);
  847. int32 key1 = lua_interface->GetInt32Value(state, 6);
  848. int32 key2 = lua_interface->GetInt32Value(state, 7);
  849. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  850. Client* client = npc->GetZone()->GetClientBySpawn(player);
  851. if (mp3.length() > 0)
  852. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  853. else
  854. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  855. safe_delete(conversation);
  856. lua_interface->SetConversationValue(state, NULL);
  857. }
  858. else
  859. 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);
  860. return 0;
  861. }
  862. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  863. if (!lua_interface)
  864. return 0;
  865. Spawn* spawn = lua_interface->GetSpawn(state);
  866. float distance = lua_interface->GetFloatValue(state, 2);
  867. string in_range_function = lua_interface->GetStringValue(state, 3);
  868. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  869. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  870. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  871. return 0;
  872. }
  873. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  874. ZoneServer* zone = lua_interface->GetZone(state);
  875. float x = lua_interface->GetFloatValue(state, 2);
  876. float y = lua_interface->GetFloatValue(state, 3);
  877. float z = lua_interface->GetFloatValue(state, 4);
  878. float max_variation = lua_interface->GetFloatValue(state, 5);
  879. string in_range_function = lua_interface->GetStringValue(state, 6);
  880. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  881. if (zone && in_range_function.length() > 0)
  882. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  883. return 0;
  884. }
  885. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  886. if (!lua_interface)
  887. return 0;
  888. Spawn* spawn = lua_interface->GetSpawn(state);
  889. if (spawn && spawn->IsEntity()) {
  890. int32 val = lua_interface->GetInt32Value(state, 2);
  891. ((Entity*)spawn)->SetLootCoins(val);
  892. }
  893. return 0;
  894. }
  895. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  896. if (!lua_interface)
  897. return 0;
  898. Spawn* spawn = lua_interface->GetSpawn(state);
  899. if (spawn && spawn->IsEntity()) {
  900. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  901. return 1;
  902. }
  903. return 0;
  904. }
  905. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  906. if (!lua_interface)
  907. return 0;
  908. Spawn* spawn = lua_interface->GetSpawn(state);
  909. float x = lua_interface->GetFloatValue(state, 2);
  910. float y = lua_interface->GetFloatValue(state, 3);
  911. float z = lua_interface->GetFloatValue(state, 4);
  912. float speed = lua_interface->GetFloatValue(state, 5);
  913. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  914. string function = lua_interface->GetStringValue(state, 7);
  915. if (spawn) {
  916. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  917. spawn->GetZone()->AddMovementNPC(spawn);
  918. }
  919. lua_interface->ResetFunctionStack(state);
  920. return 0;
  921. }
  922. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  923. if (!lua_interface)
  924. return 0;
  925. Spawn* spawn = lua_interface->GetSpawn(state);
  926. if (spawn) {
  927. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  928. return 1;
  929. }
  930. return 0;
  931. }
  932. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  933. if (!lua_interface)
  934. return 0;
  935. Spawn* spawn = lua_interface->GetSpawn(state);
  936. Spawn* target = lua_interface->GetSpawn(state, 2);
  937. if (spawn && target) {
  938. if (spawn->IsEntity())
  939. // ((Entity*)spawn)->FaceTarget(target);
  940. static_cast<Entity*>(spawn)->FaceTarget(target);
  941. }
  942. lua_interface->ResetFunctionStack(state);
  943. return 0;
  944. }
  945. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  946. if (!lua_interface)
  947. return 0;
  948. Spawn* spawn = lua_interface->GetSpawn(state);
  949. float x = lua_interface->GetFloatValue(state, 2);
  950. float y = lua_interface->GetFloatValue(state, 3);
  951. float z = lua_interface->GetFloatValue(state, 4);
  952. float speed = lua_interface->GetFloatValue(state, 5);
  953. string lua_function = lua_interface->GetStringValue(state, 6);
  954. bool more_points = lua_interface->GetBooleanValue(state, 7);
  955. if (spawn) {
  956. if (speed == 0)
  957. speed = spawn->GetSpeed();
  958. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  959. }
  960. lua_interface->ResetFunctionStack(state);
  961. return 0;
  962. }
  963. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  964. if (!lua_interface)
  965. return 0;
  966. Spawn* spawn = lua_interface->GetSpawn(state);
  967. if (spawn) {
  968. spawn->ClearRunningLocations();
  969. }
  970. return 0;
  971. }
  972. int EQ2Emu_lua_Say(lua_State* state) {
  973. if (!lua_interface)
  974. return 0;
  975. Spawn* spawn = lua_interface->GetSpawn(state);
  976. string message = lua_interface->GetStringValue(state, 2);
  977. Spawn* player = lua_interface->GetSpawn(state, 3);
  978. int32 language = lua_interface->GetInt32Value(state, 4);
  979. if (spawn && message.length() > 0) {
  980. Client* client = 0;
  981. if (player && player->IsPlayer())
  982. client = spawn->GetZone()->GetClientBySpawn(player);
  983. if (client)
  984. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  985. else
  986. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  987. }
  988. lua_interface->ResetFunctionStack(state);
  989. return 0;
  990. }
  991. int EQ2Emu_lua_Shout(lua_State* state) {
  992. if (!lua_interface)
  993. return 0;
  994. Spawn* spawn = lua_interface->GetSpawn(state);
  995. string message = lua_interface->GetStringValue(state, 2);
  996. Spawn* player = lua_interface->GetSpawn(state, 3);
  997. if (spawn && message.length() > 0) {
  998. Client* client = 0;
  999. if (player && player->IsPlayer())
  1000. client = spawn->GetZone()->GetClientBySpawn(player);
  1001. if (client)
  1002. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1003. else
  1004. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  1005. }
  1006. lua_interface->ResetFunctionStack(state);
  1007. return 0;
  1008. }
  1009. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1010. if (!lua_interface)
  1011. return 0;
  1012. Spawn* spawn = lua_interface->GetSpawn(state);
  1013. string message = lua_interface->GetStringValue(state, 2);
  1014. Spawn* player = lua_interface->GetSpawn(state, 3);
  1015. if (spawn && message.length() > 0) {
  1016. Client* client = 0;
  1017. if (player && player->IsPlayer())
  1018. client = spawn->GetZone()->GetClientBySpawn(player);
  1019. if (client)
  1020. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1021. else
  1022. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1023. }
  1024. lua_interface->ResetFunctionStack(state);
  1025. return 0;
  1026. }
  1027. int EQ2Emu_lua_Emote(lua_State* state) {
  1028. if (!lua_interface)
  1029. return 0;
  1030. Spawn* spawn = lua_interface->GetSpawn(state);
  1031. string message = lua_interface->GetStringValue(state, 2);
  1032. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1033. Spawn* player = lua_interface->GetSpawn(state, 4);
  1034. char* to = 0;
  1035. if (spawn2)
  1036. to = spawn2->GetName();
  1037. if (spawn && message.length() > 0) {
  1038. Client* client = 0;
  1039. if (player && player->IsPlayer())
  1040. client = spawn->GetZone()->GetClientBySpawn(player);
  1041. if (client)
  1042. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1043. else
  1044. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1045. }
  1046. lua_interface->ResetFunctionStack(state);
  1047. return 0;
  1048. }
  1049. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1050. if (!lua_interface)
  1051. return 0;
  1052. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1053. if (!luaspell)
  1054. return 0;
  1055. Spawn* caster = luaspell->caster;
  1056. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1057. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1058. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1059. Spawn* target = lua_interface->GetSpawn(state, 4);
  1060. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1061. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1062. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1063. lua_interface->ResetFunctionStack(state);
  1064. if (caster && caster->IsEntity()) {
  1065. bool success = false;
  1066. luaspell->resisted = false;
  1067. if (target) {
  1068. float distance = caster->GetDistance(target, true);
  1069. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1070. success = true;
  1071. }
  1072. if (luaspell->targets.size() > 0) {
  1073. Spawn* target = 0;
  1074. ZoneServer* zone = luaspell->caster->GetZone();
  1075. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1076. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1077. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1078. float distance = caster->GetDistance(target, true);
  1079. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1080. }
  1081. }
  1082. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1083. success = true;
  1084. }
  1085. if (success) {
  1086. if (caster->GetZone())
  1087. caster->GetZone()->TriggerCharSheetTimer();
  1088. }
  1089. }
  1090. return 0;
  1091. }
  1092. int EQ2Emu_lua_AddItem(lua_State* state) {
  1093. if (!lua_interface)
  1094. return 0;
  1095. Spawn* spawn = lua_interface->GetSpawn(state);
  1096. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1097. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1098. // default of 1 quantity to add
  1099. if (quantity == 0)
  1100. quantity = 1;
  1101. if (spawn && spawn->IsPlayer()) {
  1102. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1103. if (client && item_id > 0) {
  1104. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1105. return 1;
  1106. }
  1107. }
  1108. lua_interface->SetBooleanValue(state, false);
  1109. return 1;
  1110. }
  1111. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1112. if (!lua_interface)
  1113. return 0;
  1114. Spawn* spawn = lua_interface->GetSpawn(state);
  1115. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1116. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1117. string location = lua_interface->GetStringValue(state, 4);
  1118. if (spawn && spawn->IsPlayer()) {
  1119. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1120. if (client && item_id > 0) {
  1121. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1122. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1123. else
  1124. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1125. if (send_messages) {
  1126. Item* item = master_item_list.GetItem(item_id);
  1127. if (item) {
  1128. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1129. string popup_text = "You receive " + item->name;
  1130. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1131. }
  1132. }
  1133. return 1;
  1134. }
  1135. }
  1136. lua_interface->SetBooleanValue(state, false);
  1137. return 1;
  1138. }
  1139. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1140. Spawn* spawn = lua_interface->GetSpawn(state);
  1141. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1142. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1143. // default of 1 to remove
  1144. if (quantity == 0)
  1145. quantity = 1;
  1146. Client* client;
  1147. Item* item;
  1148. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1149. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1150. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1151. if (client->RemoveItem(item, quantity)) {
  1152. lua_interface->SetBooleanValue(state, true);
  1153. return 1;
  1154. }
  1155. }
  1156. }
  1157. }
  1158. lua_interface->SetBooleanValue(state, false);
  1159. return 1;
  1160. }
  1161. int EQ2Emu_lua_HasItem(lua_State* state) {
  1162. Spawn* player = lua_interface->GetSpawn(state);
  1163. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1164. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1165. if (player && player->IsPlayer()) {
  1166. bool hasItem = false;
  1167. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1168. if (!hasItem)
  1169. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1170. lua_interface->SetBooleanValue(state, hasItem);
  1171. return 1;
  1172. }
  1173. lua_interface->SetBooleanValue(state, false);
  1174. return 1;
  1175. }
  1176. int EQ2Emu_lua_Spawn(lua_State* state) {
  1177. if (!lua_interface)
  1178. return 0;
  1179. ZoneServer* zone = lua_interface->GetZone(state);
  1180. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1181. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1182. float x = lua_interface->GetFloatValue(state, 4);
  1183. float y = lua_interface->GetFloatValue(state, 5);
  1184. float z = lua_interface->GetFloatValue(state, 6);
  1185. float heading = lua_interface->GetFloatValue(state, 7);
  1186. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1187. Spawn* spawn = zone->GetSpawn(spawn_id);
  1188. if (!spawn)
  1189. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1190. else {
  1191. spawn->SetX(x);
  1192. spawn->SetZ(z);
  1193. spawn->SetY(y,true,true);
  1194. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1195. spawn->SetHeading(heading);
  1196. if (restricted_npc)
  1197. spawn->AddAllowAccessSpawn(spawn);
  1198. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1199. bool scriptActive = false;
  1200. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1201. scriptActive = true;
  1202. spawn->SetSpawnScript(string(spawn_script));
  1203. }
  1204. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1205. zone->AddSpawn(spawn);
  1206. if (scriptActive) {
  1207. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1208. }
  1209. lua_interface->SetSpawnValue(state, spawn);
  1210. return 1;
  1211. }
  1212. }
  1213. else {
  1214. string output = "Invalid paramaters to LUA Spawn command: \n";
  1215. if (!zone)
  1216. output = output.append("\t").append("Missing zone reference. \n");
  1217. if (spawn_id == 0)
  1218. output = output.append("\t").append("Missing spawn_id.");
  1219. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1220. }
  1221. return 0;
  1222. }
  1223. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1224. if (!lua_interface)
  1225. return 0;
  1226. ZoneServer* zone = lua_interface->GetZone(state);
  1227. if (zone) {
  1228. lua_interface->SetStringValue(state, zone->GetZoneName());
  1229. return 1;
  1230. }
  1231. return 0;
  1232. }
  1233. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1234. if (!lua_interface)
  1235. return 0;
  1236. ZoneServer* zone = lua_interface->GetZone(state);
  1237. if (zone) {
  1238. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1239. return 1;
  1240. }
  1241. return 0;
  1242. }
  1243. int EQ2Emu_lua_GetZone(lua_State* state) {
  1244. if (!lua_interface)
  1245. return 0;
  1246. int32 zone_id = lua_interface->GetInt32Value(state);
  1247. ZoneServer* zone = 0;
  1248. if (zone_id > 0)
  1249. zone = zone_list.Get(zone_id);
  1250. else {
  1251. string zone_name = lua_interface->GetStringValue(state);
  1252. if (zone_name.length() > 0) {
  1253. zone = zone_list.Get(zone_name.c_str());
  1254. }
  1255. else {
  1256. Spawn* spawn = lua_interface->GetSpawn(state);
  1257. if (spawn)
  1258. zone = spawn->GetZone();
  1259. }
  1260. }
  1261. if (zone) {
  1262. lua_interface->SetZoneValue(state, zone);
  1263. return 1;
  1264. }
  1265. return 0;
  1266. }
  1267. int EQ2Emu_lua_AddHate(lua_State* state) {
  1268. Spawn* entity = lua_interface->GetSpawn(state);
  1269. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1270. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1271. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1272. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1273. if (entity && entity->IsEntity() && amount != 0) {
  1274. if (luaspell) {
  1275. ZoneServer* zone = luaspell->caster->GetZone();
  1276. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1277. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1278. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1279. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1280. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1281. if (send_packet)
  1282. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1283. }
  1284. }
  1285. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1286. }
  1287. else if (npc && npc->IsNPC() && npc->GetZone())
  1288. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1289. }
  1290. return 0;
  1291. }
  1292. int EQ2Emu_lua_Zone(lua_State* state) {
  1293. if (!lua_interface)
  1294. return 0;
  1295. ZoneServer* zone = lua_interface->GetZone(state);
  1296. Spawn* player = lua_interface->GetSpawn(state, 2);
  1297. Client* client = 0;
  1298. if (player && player->IsPlayer())
  1299. client = player->GetZone()->GetClientBySpawn(player);
  1300. float x = lua_interface->GetFloatValue(state, 3);
  1301. float y = lua_interface->GetFloatValue(state, 4);
  1302. float z = lua_interface->GetFloatValue(state, 5);
  1303. float heading = lua_interface->GetFloatValue(state, 6);
  1304. if (zone && client) {
  1305. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1306. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1307. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1308. {
  1309. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1310. return 0;
  1311. }
  1312. if (x != 0 || y != 0 || z != 0) {
  1313. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1314. player->SetX(x);
  1315. player->SetY(y);
  1316. player->SetZ(z);
  1317. player->SetHeading(heading);
  1318. client->Zone(zone->GetZoneName(), false);
  1319. }
  1320. else
  1321. client->Zone(zone->GetZoneName());
  1322. }
  1323. else
  1324. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1325. return 0;
  1326. }
  1327. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1328. if (!lua_interface)
  1329. return 0;
  1330. Spawn* spawn = lua_interface->GetSpawn(state);
  1331. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1332. if (spawn && spawn2)
  1333. spawn->AddAllowAccessSpawn(spawn2);
  1334. return 0;
  1335. }
  1336. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1337. if (!lua_interface)
  1338. return 0;
  1339. Spawn* target = lua_interface->GetSpawn(state);
  1340. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1341. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1342. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1343. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1344. if (!target) {
  1345. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1346. return 0;
  1347. }
  1348. if (!target->IsEntity()) {
  1349. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1350. return 0;
  1351. }
  1352. if (spell_id <= 0) {
  1353. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1354. return 0;
  1355. }
  1356. if (caster && !caster->IsEntity()) {
  1357. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1358. return 0;
  1359. }
  1360. if (spell_tier == 0)
  1361. spell_tier = 1;
  1362. if (!caster)
  1363. caster = target;
  1364. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1365. return 0;
  1366. }
  1367. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1368. if (!lua_interface)
  1369. return 0;
  1370. Spawn* target = lua_interface->GetSpawn(state);
  1371. int32 target_id = 0;
  1372. if (target)
  1373. target_id = target->GetID();
  1374. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1375. if (!luaspell)
  1376. return 0;
  1377. Spawn* caster = luaspell->caster;
  1378. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1379. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1380. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1381. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1382. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1383. //lua_interface->ResetFunctionStack(state);
  1384. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1385. vector<int16> faction_req;
  1386. vector<int16> race_req;
  1387. int32 class_req = 0;
  1388. int32 i = 0;
  1389. int8 f = 0;
  1390. int8 r = 0;
  1391. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1392. if (class_id < 100) {
  1393. class_req += pow(2.0, double(class_id - 1));
  1394. }
  1395. else if (class_id > 100 && class_id < 1000) {
  1396. race_req.push_back(class_id);
  1397. r++;
  1398. }
  1399. else {
  1400. faction_req.push_back(class_id);
  1401. f++;
  1402. }
  1403. i++;
  1404. }
  1405. if (caster && caster->IsEntity()) {
  1406. bool race_match = false;
  1407. bool success = false;
  1408. luaspell->resisted = false;
  1409. if (luaspell->initial_target == target_id) {
  1410. int xxx = 0;
  1411. }
  1412. if (luaspell->targets.size() > 0) {
  1413. ZoneServer* zone = luaspell->caster->GetZone();
  1414. Spawn* target = 0;
  1415. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1416. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1417. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1418. if (race_req.size() > 0) {
  1419. for (int8 i = 0; i < race_req.size(); i++) {
  1420. int32 xxx = target->GetLuaRaceId();
  1421. if (target->GetLuaRaceId() == race_req[i]) {
  1422. race_match = true;
  1423. }
  1424. }
  1425. }
  1426. else
  1427. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1428. if (race_match == true) {
  1429. float distance = caster->GetDistance(target, true);
  1430. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1431. }
  1432. }
  1433. }
  1434. success = true;
  1435. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1436. }
  1437. else if (target) {
  1438. //check class and race/faction here
  1439. if (race_req.size() > 0) {
  1440. for (int8 i = 0; i < race_req.size(); i++) {
  1441. if (target->GetLuaRaceId() == race_req[i]) {
  1442. race_match = true;
  1443. }
  1444. }
  1445. }
  1446. else
  1447. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1448. if (race_match == true) {
  1449. float distance = caster->GetDistance(target, true);
  1450. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1451. success = true;
  1452. }
  1453. }
  1454. if (success) {
  1455. Spell* spell = luaspell->spell;
  1456. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1457. ((Player*)caster)->InCombat(true);
  1458. if (caster->GetZone())
  1459. caster->GetZone()->TriggerCharSheetTimer();
  1460. }
  1461. }
  1462. }
  1463. return 0;
  1464. }
  1465. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1466. if (!lua_interface)
  1467. return 0;
  1468. Spawn* spawn = lua_interface->GetSpawn(state);
  1469. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1470. lua_interface->ResetFunctionStack(state);
  1471. if (spawn && value != 0) {
  1472. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1473. spawn->SetPower(spawn->GetTotalPower());
  1474. else
  1475. spawn->SetPower(spawn->GetPower() + value);
  1476. }
  1477. return 0;
  1478. }
  1479. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1480. if (!lua_interface)
  1481. return 0;
  1482. Spawn* spawn = lua_interface->GetSpawn(state);
  1483. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1484. lua_interface->ResetFunctionStack(state);
  1485. if (spawn && value != 0) {
  1486. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1487. spawn->SetHP(spawn->GetTotalHP());
  1488. else
  1489. spawn->SetHP(spawn->GetHP() + value);
  1490. }
  1491. return 0;
  1492. }
  1493. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1494. if (!lua_interface)
  1495. return 0;
  1496. Spawn* spawn = lua_interface->GetSpawn(state);
  1497. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1498. lua_interface->ResetFunctionStack(state);
  1499. if (spawn && value != 0) {
  1500. spawn->SetPower(spawn->GetPower() + value);
  1501. if (value > spawn->GetTotalHPBase())
  1502. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1503. }
  1504. return 0;
  1505. }
  1506. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1507. if (!lua_interface)
  1508. return 0;
  1509. Spawn* spawn = lua_interface->GetSpawn(state);
  1510. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1511. lua_interface->ResetFunctionStack(state);
  1512. if (spawn && value != 0) {
  1513. spawn->SetHP(spawn->GetHP() + value);
  1514. if (value > spawn->GetTotalHPBase())
  1515. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1516. }
  1517. return 0;
  1518. }
  1519. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1520. if (!lua_interface)
  1521. return 0;
  1522. Spawn* spawn = lua_interface->GetSpawn(state);
  1523. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1524. lua_interface->ResetFunctionStack(state);
  1525. if (spawn) {
  1526. spawn->SetHP(value);
  1527. if (value > spawn->GetTotalHPBase())
  1528. spawn->SetTotalHP(value);
  1529. }
  1530. return 0;
  1531. }
  1532. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1533. if (!lua_interface)
  1534. return 0;
  1535. Spawn* spawn = lua_interface->GetSpawn(state);
  1536. float value = lua_interface->GetFloatValue(state, 2);
  1537. lua_interface->ResetFunctionStack(state);
  1538. if (spawn && spawn->IsEntity() && value > 0)
  1539. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1540. if (spawn->IsPlayer())
  1541. ((Player*)spawn)->SetCharSheetChanged(true);
  1542. return 0;
  1543. }
  1544. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1545. if (!lua_interface)
  1546. return 0;
  1547. Spawn* spawn = lua_interface->GetSpawn(state);
  1548. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1549. lua_interface->ResetFunctionStack(state);
  1550. if (spawn && spawn->IsEntity() && value > 0)
  1551. ((Entity*)spawn)->SetTotalHPBase(value);
  1552. return 0;
  1553. }
  1554. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1555. if (!lua_interface)
  1556. return 0;
  1557. Spawn* spawn = lua_interface->GetSpawn(state);
  1558. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1559. lua_interface->ResetFunctionStack(state);
  1560. if (spawn && value > 0) {
  1561. spawn->SetPower(value);
  1562. if (value > spawn->GetTotalPowerBase())
  1563. spawn->SetTotalPower(value);
  1564. }
  1565. return 0;
  1566. }
  1567. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1568. if (!lua_interface)
  1569. return 0;
  1570. Spawn* spawn = lua_interface->GetSpawn(state);
  1571. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1572. lua_interface->ResetFunctionStack(state);
  1573. if (spawn && spawn->IsEntity() && value > 0)
  1574. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1575. return 0;
  1576. }
  1577. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1578. if (!lua_interface)
  1579. return 0;
  1580. Spawn* spawn = lua_interface->GetSpawn(state);
  1581. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1582. lua_interface->ResetFunctionStack(state);
  1583. if (spawn && spawn->IsEntity() && value > 0)
  1584. ((Entity*)spawn)->SetTotalPowerBase(value);
  1585. return 0;
  1586. }
  1587. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1588. if (!lua_interface)
  1589. return 0;
  1590. Spawn* spawn = lua_interface->GetSpawn(state);
  1591. float x = lua_interface->GetFloatValue(state, 2);
  1592. float y = lua_interface->GetFloatValue(state, 3);
  1593. float z = lua_interface->GetFloatValue(state, 4);
  1594. float heading = lua_interface->GetFloatValue(state, 5);
  1595. lua_interface->ResetFunctionStack(state);
  1596. if (spawn) {
  1597. spawn->SetX(x);
  1598. spawn->SetY(y);
  1599. spawn->SetZ(z);
  1600. if (heading != 0)
  1601. spawn->SetHeading(heading);
  1602. spawn->SetSpawnOrigX(spawn->GetX());
  1603. spawn->SetSpawnOrigY(spawn->GetY());
  1604. spawn->SetSpawnOrigZ(spawn->GetZ());
  1605. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1606. if (spawn->IsPlayer()) {
  1607. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1608. if (client) {
  1609. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1610. client->QueuePacket(packet);
  1611. }
  1612. }
  1613. }
  1614. return 0;
  1615. }
  1616. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1617. if (!lua_interface)
  1618. return 0;
  1619. Spawn* spawn = lua_interface->GetSpawn(state);
  1620. float value = lua_interface->GetFloatValue(state, 2);
  1621. lua_interface->ResetFunctionStack(state);
  1622. if (spawn) {
  1623. spawn->SetHeading(value);
  1624. if (spawn->IsPlayer()) {
  1625. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1626. if (client) {
  1627. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1628. client->QueuePacket(packet);
  1629. }
  1630. }
  1631. }
  1632. return 0;
  1633. }
  1634. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1635. if (!lua_interface)
  1636. return 0;
  1637. Spawn* spawn = lua_interface->GetSpawn(state);
  1638. int16 value = lua_interface->GetInt16Value(state, 2);
  1639. lua_interface->ResetFunctionStack(state);
  1640. if (spawn)
  1641. spawn->SetModelType(value);
  1642. return 0;
  1643. }
  1644. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1645. if (!lua_interface)
  1646. return 0;
  1647. Spawn* spawn = lua_interface->GetSpawn(state);
  1648. int8 value = lua_interface->GetInt8Value(state, 2);
  1649. lua_interface->ResetFunctionStack(state);
  1650. if (spawn) {
  1651. if (spawn->IsPlayer())
  1652. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1653. else
  1654. spawn->SetAdventureClass(value);
  1655. }
  1656. return 0;
  1657. }
  1658. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1659. if (!lua_interface)
  1660. return 0;
  1661. Spawn* spawn = lua_interface->GetSpawn(state);
  1662. int8 value = lua_interface->GetInt8Value(state, 2);
  1663. lua_interface->ResetFunctionStack(state);
  1664. if (spawn) {
  1665. spawn->SetTradeskillClass(value);
  1666. if (spawn->IsEntity()) {
  1667. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1668. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1669. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1670. }
  1671. if (spawn->IsPlayer())
  1672. ((Player*)spawn)->SetCharSheetChanged(true);
  1673. }
  1674. return 0;
  1675. }
  1676. int EQ2Emu_lua_SetMount(lua_State* state) {
  1677. if (!lua_interface)
  1678. return 0;
  1679. Spawn* spawn = lua_interface->GetSpawn(state);
  1680. int16 value = lua_interface->GetInt16Value(state, 2);
  1681. if (spawn && spawn->IsEntity()) {
  1682. ((Entity*)spawn)->SetMount(value);
  1683. EQ2_Color color;
  1684. color.red = 255;
  1685. color.green = 255;
  1686. color.blue = 255;
  1687. ((Entity*)spawn)->SetMountColor(&color);
  1688. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1689. }
  1690. return 0;
  1691. }
  1692. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1693. if (!lua_interface)
  1694. return 0;
  1695. Spawn* spawn = lua_interface->GetSpawn(state);
  1696. EQ2_Color mount_color;
  1697. EQ2_Color saddle_color;
  1698. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1699. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1700. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1701. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1702. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1703. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1704. if (spawn && spawn->IsEntity()) {
  1705. ((Entity*)spawn)->SetMountColor(&mount_color);
  1706. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1707. }
  1708. return 0;
  1709. }
  1710. int EQ2Emu_lua_GetMount(lua_State* state) {
  1711. if (!lua_interface)
  1712. return 0;
  1713. Spawn* spawn = lua_interface->GetSpawn(state);
  1714. if (spawn && spawn->IsEntity()) {
  1715. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1716. return 1;
  1717. }
  1718. return 0;
  1719. }
  1720. int EQ2Emu_lua_GetRace(lua_State* state) {
  1721. if (!lua_interface)
  1722. return 0;
  1723. Spawn* spawn = lua_interface->GetSpawn(state);
  1724. if (spawn)
  1725. {
  1726. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1727. lua_interface->SetInt32Value(state, spawn->GetRace());
  1728. return 1;
  1729. }
  1730. return 0;
  1731. }
  1732. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1733. if (!lua_interface)
  1734. return 0;
  1735. Spawn* spawn = lua_interface->GetSpawn(state);
  1736. if (spawn) {
  1737. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1738. return 1;
  1739. }
  1740. return 0;
  1741. }
  1742. int EQ2Emu_lua_GetClass(lua_State* state) {
  1743. Spawn* spawn = lua_interface->GetSpawn(state);
  1744. if (spawn) {
  1745. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1746. return 1;
  1747. }
  1748. return 0;
  1749. }
  1750. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1751. Spawn* spawn = lua_interface->GetSpawn(state);
  1752. if (spawn) {
  1753. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1754. return 1;
  1755. }
  1756. return 0;
  1757. }
  1758. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1759. if (!lua_interface)
  1760. return 0;
  1761. Spawn* spawn = lua_interface->GetSpawn(state);
  1762. float value = lua_interface->GetFloatValue(state, 2);
  1763. lua_interface->ResetFunctionStack(state);
  1764. if (spawn) {
  1765. spawn->SetSpeed(value);
  1766. ((Entity*)spawn)->SetSpeed(value);
  1767. if (spawn->IsPlayer()) {
  1768. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1769. if (client) {
  1770. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1771. if (packet) {
  1772. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1773. packet->setDataByName("speed", value);
  1774. packet->setDataByName("size", 0.51);
  1775. EQ2Packet* app = packet->serialize();
  1776. client->QueuePacket(app);
  1777. safe_delete(packet);
  1778. }
  1779. }
  1780. }
  1781. }
  1782. return 0;
  1783. }
  1784. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1785. if (!lua_interface)
  1786. return 0;
  1787. Spawn* spawn = lua_interface->GetSpawn(state);
  1788. const int16 type = lua_interface->GetInt16Value(state, 2);
  1789. const float value = lua_interface->GetFloatValue(state, 3);
  1790. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1791. int64 class_req = 0;
  1792. int32 class_id = 0;
  1793. vector<int16> faction_req;
  1794. vector<int16> race_req;
  1795. int32 i = 0;
  1796. int8 f = 0;
  1797. int8 r = 0;
  1798. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1799. if (class_id < 100) {
  1800. class_req += pow(2.0, double(class_id - 1));
  1801. }
  1802. else if (class_id > 100 && class_id < 1000) {
  1803. race_req.push_back(class_id);
  1804. r++;
  1805. }
  1806. else {
  1807. faction_req.push_back(class_id);
  1808. f++;
  1809. }
  1810. i++;
  1811. }
  1812. if (value != 0 && type >= 0) {
  1813. if (luaspell && luaspell->spell && luaspell->caster) {
  1814. ZoneServer* zone = luaspell->caster->GetZone();
  1815. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1816. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1817. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1818. if (target) {
  1819. if (target->IsPlayer()) {
  1820. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1821. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1822. if (((Player*)target)->GetGroupMemberInfo())
  1823. ((Player*)target)->UpdateGroupMemberInfo();
  1824. ((Player*)target)->SetCharSheetChanged(true);
  1825. }
  1826. else if (target->IsNPC())
  1827. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1828. else
  1829. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1830. }
  1831. }
  1832. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1833. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1834. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1835. }
  1836. else if (spawn && spawn->IsEntity()) {
  1837. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1838. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1839. if (spawn->IsPlayer())
  1840. ((Player*)spawn)->SetCharSheetChanged(true);
  1841. }
  1842. else
  1843. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1844. }
  1845. else
  1846. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1847. return 0;
  1848. }
  1849. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1850. if (!lua_interface)
  1851. return 0;
  1852. Spawn* spawn = lua_interface->GetSpawn(state);
  1853. int16 type = lua_interface->GetInt16Value(state, 2);
  1854. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1855. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1856. if (!spawn) {
  1857. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1858. return 0;
  1859. }
  1860. if (!spawn->IsEntity()) {
  1861. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1862. return 0;
  1863. }
  1864. if (value == 0) {
  1865. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1866. return 0;
  1867. }
  1868. if (!luaspell || !luaspell->spell) {
  1869. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1870. return 0;
  1871. }
  1872. int32 class_req = 0;
  1873. vector<int16> faction_req;
  1874. vector<int16> race_req;
  1875. int32 class_id = 0;
  1876. int32 i = 0;
  1877. int8 f = 0;
  1878. int8 r = 0;
  1879. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1880. if (class_id < 100) {
  1881. class_req += pow(2.0, double(class_id - 1));
  1882. }
  1883. else if (class_id > 100 && class_id < 1000) {
  1884. race_req.push_back(class_id);
  1885. r++;
  1886. }
  1887. else {
  1888. faction_req.push_back(class_id);
  1889. f++;
  1890. }
  1891. i++;
  1892. }
  1893. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1894. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1895. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1896. if (spawn->IsPlayer())
  1897. ((Player*)spawn)->SetCharSheetChanged(true);
  1898. return 0;
  1899. }
  1900. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1901. if (!lua_interface)
  1902. return 0;
  1903. Spawn* spawn = lua_interface->GetSpawn(state);
  1904. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1905. if (luaspell && luaspell->spell) {
  1906. ZoneServer* zone = luaspell->caster->GetZone();
  1907. Spawn* target = 0;
  1908. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1909. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1910. target = zone->GetSpawnByID(luaspell->targets[i]);
  1911. if (target && target->IsEntity()) {
  1912. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1913. if (target->IsPlayer())
  1914. ((Player*)target)->SetCharSheetChanged(true);
  1915. }
  1916. }
  1917. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1918. }
  1919. else if (spawn && spawn->IsEntity()) {
  1920. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1921. if (spawn->IsPlayer())
  1922. ((Player*)spawn)->SetCharSheetChanged(true);
  1923. }
  1924. return 0;
  1925. }
  1926. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1927. if (!lua_interface)
  1928. return 0;
  1929. Spawn* spawn = lua_interface->GetSpawn(state);
  1930. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1931. float value = lua_interface->GetFloatValue(state, 3);
  1932. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1933. if (value != 0) {
  1934. int32 spell_id = 0;
  1935. if (luaspell && luaspell->spell && luaspell->caster) {
  1936. spell_id = luaspell->spell->GetSpellID();
  1937. ZoneServer* zone = luaspell->caster->GetZone();
  1938. Spawn* target = 0;
  1939. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1940. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1941. target = zone->GetSpawnByID(luaspell->targets[i]);
  1942. if (target && target->Alive()) {
  1943. if (target->IsPlayer()) {
  1944. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1945. Client* client = target->GetZone()->GetClientBySpawn(target);
  1946. if (client) {
  1947. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1948. if (packet)
  1949. client->QueuePacket(packet);
  1950. }
  1951. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1952. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1953. }
  1954. else if (target->IsNPC()) {
  1955. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1956. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1957. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1958. }
  1959. else
  1960. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1961. }
  1962. }
  1963. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1964. }
  1965. else if (spawn) {
  1966. if (spawn->IsPlayer()) {
  1967. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1968. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1969. if (client) {
  1970. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1971. if (packet)
  1972. client->QueuePacket(packet);
  1973. }
  1974. }
  1975. else if (spawn->IsNPC())
  1976. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1977. else
  1978. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1979. }
  1980. }
  1981. else
  1982. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1983. return 0;
  1984. }
  1985. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1986. if (!lua_interface)
  1987. return 0;
  1988. Spawn* spawn = lua_interface->GetSpawn(state);
  1989. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1990. if (spawn && spawn->IsPlayer()) {
  1991. int32 spell_id = 0;
  1992. if (luaspell && luaspell->spell) {
  1993. spell_id = luaspell->spell->GetSpellID();
  1994. ZoneServer* zone = luaspell->caster->GetZone();
  1995. Spawn* target = 0;
  1996. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1997. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1998. target = zone->GetSpawnByID(luaspell->targets[i]);
  1999. if (target) {
  2000. if (target->IsPlayer()) {
  2001. ((Player*)target)->RemoveSkillBonus(spell_id);
  2002. Client* client = target->GetZone()->GetClientBySpawn(target);
  2003. if (client) {
  2004. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2005. if (packet)
  2006. client->QueuePacket(packet);
  2007. }
  2008. }
  2009. else if (target->IsNPC())
  2010. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2011. else
  2012. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2013. }
  2014. }
  2015. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2016. }
  2017. else if (spawn) {
  2018. if (spawn->IsPlayer()) {
  2019. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2020. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2021. if (client) {
  2022. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2023. if (packet)
  2024. client->QueuePacket(packet);
  2025. }
  2026. }
  2027. else if (spawn->IsNPC())
  2028. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2029. else
  2030. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2031. }
  2032. }
  2033. return 0;
  2034. }
  2035. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2036. if (!lua_interface)
  2037. return 0;
  2038. Spawn* spawn = lua_interface->GetSpawn(state);
  2039. int8 type = lua_interface->GetInt32Value(state, 2);
  2040. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2041. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2042. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2043. ZoneServer* zone = luaspell->caster->GetZone();
  2044. Spawn* target = 0;
  2045. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2046. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2047. target = zone->GetSpawnByID(luaspell->targets[i]);
  2048. if (target && target->IsEntity()) {
  2049. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2050. ((Entity*)target)->AddMezSpell(luaspell);
  2051. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2052. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2053. if (target->IsNPC())
  2054. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2055. }
  2056. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2057. ((Entity*)target)->AddStifleSpell(luaspell);
  2058. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2059. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2060. if (target->IsNPC())
  2061. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2062. }
  2063. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2064. ((Entity*)target)->AddDazeSpell(luaspell);
  2065. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2066. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2067. if (target->IsNPC())
  2068. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2069. }
  2070. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2071. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2072. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2073. ((Entity*)target)->AddStunSpell(luaspell);
  2074. if (target->IsNPC())
  2075. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2076. }
  2077. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2078. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2079. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2080. ((Entity*)target)->AddRootSpell(luaspell);
  2081. if (target->IsNPC())
  2082. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2083. }
  2084. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2085. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2086. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2087. ((Entity*)target)->AddFearSpell(luaspell);
  2088. if (target->IsNPC())
  2089. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2090. }
  2091. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2092. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2093. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2094. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2095. }
  2096. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2097. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2098. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2099. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2100. }
  2101. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2102. ((Entity*)target)->AddSnareSpell(luaspell);
  2103. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2104. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2105. if (target->IsNPC())
  2106. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2107. }
  2108. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2109. ((Entity*)target)->AddFlightSpell(luaspell);
  2110. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2111. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2112. }
  2113. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2114. ((Entity*)target)->AddGlideSpell(luaspell);
  2115. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2116. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2117. }
  2118. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2119. ((Entity*)target)->AddSafefallSpell(luaspell);
  2120. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2121. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2122. }
  2123. else
  2124. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2125. }
  2126. else
  2127. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2128. }
  2129. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2130. }
  2131. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2132. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2133. ((Entity*)spawn)->AddMezSpell(luaspell);
  2134. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2135. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2136. }
  2137. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2138. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2139. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2140. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2141. }
  2142. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2143. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2144. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2145. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2146. }
  2147. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2148. ((Entity*)spawn)->AddStunSpell(luaspell);
  2149. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2150. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2151. }
  2152. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2153. ((Entity*)spawn)->AddRootSpell(luaspell);
  2154. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2155. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2156. }
  2157. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2158. ((Entity*)spawn)->AddFearSpell(luaspell);
  2159. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2160. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2161. }
  2162. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2163. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2164. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2165. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2166. }
  2167. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2168. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2169. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2170. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2171. }
  2172. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2173. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2174. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2175. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2176. }
  2177. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2178. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2179. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2180. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2181. }
  2182. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2183. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2184. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2185. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2186. }
  2187. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2188. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2189. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2190. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2191. }
  2192. else
  2193. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2194. }
  2195. else
  2196. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2197. return 0;
  2198. }
  2199. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2200. if (!lua_interface)
  2201. return 0;
  2202. Spawn* spawn = lua_interface->GetSpawn(state);
  2203. int8 type = lua_interface->GetInt8Value(state, 2);
  2204. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2205. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2206. if (spawn && spawn->IsEntity()) {
  2207. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2208. ZoneServer* zone = luaspell->caster->GetZone();
  2209. Spawn* target = 0;
  2210. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2211. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2212. target = zone->GetSpawnByID(luaspell->targets[i]);
  2213. if (target) {
  2214. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2215. ((Entity*)target)->RemoveMezSpell(luaspell);
  2216. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2217. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2218. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2219. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2220. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2221. ((Entity*)target)->RemoveStunSpell(luaspell);
  2222. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2223. ((Entity*)target)->RemoveRootSpell(luaspell);
  2224. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2225. ((Entity*)target)->RemoveFearSpell(luaspell);
  2226. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2227. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2228. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2229. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2230. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2231. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2232. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2233. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2234. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2235. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2236. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2237. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2238. else
  2239. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2240. }
  2241. }
  2242. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2243. }
  2244. else if (only_remove_spawn) {
  2245. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2246. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2247. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2248. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2249. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2250. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2251. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2252. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2253. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2254. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2255. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2256. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2257. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2258. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2259. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2260. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2261. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2262. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2263. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2264. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2265. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2266. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2267. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2268. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2269. else
  2270. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2271. }
  2272. }
  2273. return 0;
  2274. }
  2275. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2276. if (!lua_interface)
  2277. return 0;
  2278. Spawn* spawn = lua_interface->GetSpawn(state);
  2279. int8 type = lua_interface->GetInt8Value(state, 2);
  2280. bool hasEffect = false;
  2281. if (!spawn)
  2282. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2283. else if (!spawn->IsEntity())
  2284. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2285. else if (type < CONTROL_MAX_EFFECTS)
  2286. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2287. else
  2288. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2289. lua_interface->SetBooleanValue(state, hasEffect);
  2290. return 1;
  2291. }
  2292. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2293. if (!lua_interface)
  2294. return 0;
  2295. Spawn* spawn = lua_interface->GetSpawn(state);
  2296. float distance = 0.0f;
  2297. if (!spawn)
  2298. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2299. else if (!spawn->IsNPC())
  2300. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2301. else
  2302. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2303. lua_interface->SetFloatValue(state, distance);
  2304. return 1;
  2305. }
  2306. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2307. if (!lua_interface)
  2308. return 0;
  2309. Spawn* spawn = lua_interface->GetSpawn(state);
  2310. float distance = 0.0f;
  2311. if (!spawn)
  2312. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2313. else if (!spawn->IsNPC())
  2314. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2315. else
  2316. distance = ((NPC*)spawn)->GetAggroRadius();
  2317. lua_interface->SetFloatValue(state, distance);
  2318. return 1;
  2319. }
  2320. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2321. if (!lua_interface)
  2322. return 0;
  2323. Spawn* spawn = lua_interface->GetSpawn(state);
  2324. float distance = lua_interface->GetFloatValue(state, 2);
  2325. bool override = lua_interface->GetBooleanValue(state, 3);
  2326. bool result = false;
  2327. lua_interface->ResetFunctionStack(state);
  2328. if (!spawn)
  2329. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2330. else if (!spawn->IsNPC())
  2331. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2332. else
  2333. {
  2334. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2335. result = true;
  2336. }
  2337. lua_interface->SetBooleanValue(state, result);
  2338. return 1;
  2339. }
  2340. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2341. if (!lua_interface)
  2342. return 0;
  2343. Spawn* spawn = lua_interface->GetSpawn(state);
  2344. int16 value = lua_interface->GetInt16Value(state, 2);
  2345. if (spawn && spawn->IsEntity()) {
  2346. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2347. if (spawn->IsPlayer())
  2348. ((Player*)spawn)->SetCharSheetChanged(true);
  2349. }
  2350. return 0;
  2351. }
  2352. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2353. if (!lua_interface)
  2354. return 0;
  2355. Spawn* spawn = lua_interface->GetSpawn(state);
  2356. int16 value = lua_interface->GetInt16Value(state, 2);
  2357. if (spawn && spawn->IsEntity()) {
  2358. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2359. if (spawn->IsPlayer())
  2360. ((Player*)spawn)->SetCharSheetChanged(true);
  2361. }
  2362. return 0;
  2363. }
  2364. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2365. if (!lua_interface)
  2366. return 0;
  2367. Spawn* spawn = lua_interface->GetSpawn(state);
  2368. int16 value = lua_interface->GetInt16Value(state, 2);
  2369. if (spawn && spawn->IsEntity()) {
  2370. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2371. if (spawn->IsPlayer())
  2372. ((Player*)spawn)->SetCharSheetChanged(true);
  2373. }
  2374. return 0;
  2375. }
  2376. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2377. if (!lua_interface)
  2378. return 0;
  2379. Spawn* spawn = lua_interface->GetSpawn(state);
  2380. int16 value = lua_interface->GetInt16Value(state, 2);
  2381. if (spawn && spawn->IsEntity()) {
  2382. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2383. if (spawn->IsPlayer())
  2384. ((Player*)spawn)->SetCharSheetChanged(true);
  2385. }
  2386. return 0;
  2387. }
  2388. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2389. if (!lua_interface)
  2390. return 0;
  2391. Spawn* spawn = lua_interface->GetSpawn(state);
  2392. int16 value = lua_interface->GetInt16Value(state, 2);
  2393. if (spawn && spawn->IsEntity()) {
  2394. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2395. if (spawn->IsPlayer())
  2396. ((Player*)spawn)->SetCharSheetChanged(true);
  2397. }
  2398. return 0;
  2399. }
  2400. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2401. if (!lua_interface)
  2402. return 0;
  2403. Spawn* spawn = lua_interface->GetSpawn(state);
  2404. int8 value = lua_interface->GetInt8Value(state, 2);
  2405. if (spawn && spawn->IsEntity()) {
  2406. ((Entity*)spawn)->SetDeity(value);
  2407. if (spawn->IsPlayer())
  2408. ((Player*)spawn)->SetCharSheetChanged(true);
  2409. }
  2410. lua_interface->ResetFunctionStack(state);
  2411. return 0;
  2412. }
  2413. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2414. if (!lua_interface)
  2415. return 0;
  2416. Spawn* spawn = lua_interface->GetSpawn(state);
  2417. if (spawn && spawn->IsEntity()) {
  2418. int8 deity = ((Entity*)spawn)->GetDeity();
  2419. lua_interface->SetInt32Value(state, deity);
  2420. return 1;
  2421. }
  2422. return 0;
  2423. }
  2424. int EQ2Emu_lua_SetInt(lua_State* state) {
  2425. if (!lua_interface)
  2426. return 0;
  2427. Spawn* spawn = lua_interface->GetSpawn(state);
  2428. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2429. if (spawn && spawn->IsEntity()) {
  2430. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2431. if (spawn->IsPlayer())
  2432. ((Player*)spawn)->SetCharSheetChanged(true);
  2433. }
  2434. return 0;
  2435. }
  2436. int EQ2Emu_lua_SetWis(lua_State* state) {
  2437. if (!lua_interface)
  2438. return 0;
  2439. Spawn* spawn = lua_interface->GetSpawn(state);
  2440. float value = lua_interface->GetFloatValue(state, 2);
  2441. if (spawn && spawn->IsEntity()) {
  2442. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2443. if (spawn->IsPlayer())
  2444. ((Player*)spawn)->SetCharSheetChanged(true);
  2445. }
  2446. return 0;
  2447. }
  2448. int EQ2Emu_lua_SetSta(lua_State* state) {
  2449. if (!lua_interface)
  2450. return 0;
  2451. Spawn* spawn = lua_interface->GetSpawn(state);
  2452. float value = lua_interface->GetFloatValue(state, 2);
  2453. if (spawn && spawn->IsEntity()) {
  2454. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2455. if (spawn->IsPlayer())
  2456. ((Player*)spawn)->SetCharSheetChanged(true);
  2457. }
  2458. return 0;
  2459. }
  2460. int EQ2Emu_lua_SetStr(lua_State* state) {
  2461. if (!lua_interface)
  2462. return 0;
  2463. Spawn* spawn = lua_interface->GetSpawn(state);
  2464. float value = lua_interface->GetFloatValue(state, 2);
  2465. if (spawn && spawn->IsEntity()) {
  2466. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2467. if (spawn->IsPlayer())
  2468. ((Player*)spawn)->SetCharSheetChanged(true);
  2469. }
  2470. return 0;
  2471. }
  2472. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2473. if (!lua_interface)
  2474. return 0;
  2475. Spawn* spawn = lua_interface->GetSpawn(state);
  2476. float value = lua_interface->GetFloatValue(state, 2);
  2477. if (spawn && spawn->IsEntity()) {
  2478. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2479. if (spawn->IsPlayer())
  2480. ((Player*)spawn)->SetCharSheetChanged(true);
  2481. }
  2482. return 0;
  2483. }
  2484. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2485. if (!lua_interface)
  2486. return 0;
  2487. Spawn* spawn = lua_interface->GetSpawn(state);
  2488. if (spawn) {
  2489. lua_interface->SetInt32Value(state, spawn->GetHP());
  2490. return 1;
  2491. }
  2492. return 0;
  2493. }
  2494. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2495. if (!lua_interface)
  2496. return 0;
  2497. Spawn* spawn = lua_interface->GetSpawn(state);
  2498. if (spawn) {
  2499. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2500. return 1;
  2501. }
  2502. return 0;
  2503. }
  2504. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2505. if (!lua_interface)
  2506. return 0;
  2507. Spawn* spawn = lua_interface->GetSpawn(state);
  2508. if (spawn) {
  2509. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2510. return 1;
  2511. }
  2512. return 0;
  2513. }
  2514. int EQ2Emu_lua_GetName(lua_State* state) {
  2515. if (!lua_interface)
  2516. return 0;
  2517. Spawn* spawn = lua_interface->GetSpawn(state);
  2518. if (spawn) {
  2519. lua_interface->SetStringValue(state, spawn->GetName());
  2520. return 1;
  2521. }
  2522. return 0;
  2523. }
  2524. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2525. Spawn* spawn = lua_interface->GetSpawn(state);
  2526. if (spawn) {
  2527. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2528. return 1;
  2529. }
  2530. return 0;
  2531. }
  2532. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2533. if (!lua_interface)
  2534. return 0;
  2535. Spawn* spawn = lua_interface->GetSpawn(state);
  2536. if (spawn) {
  2537. lua_interface->SetInt32Value(state, spawn->GetPower());
  2538. return 1;
  2539. }
  2540. return 0;
  2541. }
  2542. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2543. if (!lua_interface)
  2544. return 0;
  2545. Spawn* spawn = lua_interface->GetSpawn(state);
  2546. if (spawn) {
  2547. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2548. return 1;
  2549. }
  2550. return 0;
  2551. }
  2552. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2553. if (!lua_interface)
  2554. return 0;
  2555. Spawn* spawn = lua_interface->GetSpawn(state);
  2556. if (spawn) {
  2557. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2558. return 1;
  2559. }
  2560. return 0;
  2561. }
  2562. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2563. if (!lua_interface)
  2564. return 0;
  2565. Spawn* spawn = lua_interface->GetSpawn(state);
  2566. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2567. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2568. if (spawn && spawn2) {
  2569. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2570. lua_interface->SetFloatValue(state, distance);
  2571. return 1;
  2572. }
  2573. return 0;
  2574. }
  2575. int EQ2Emu_lua_GetX(lua_State* state) {
  2576. if (!lua_interface)
  2577. return 0;
  2578. Spawn* spawn = lua_interface->GetSpawn(state);
  2579. if (spawn) {
  2580. lua_interface->SetFloatValue(state, spawn->GetX());
  2581. return 1;
  2582. }
  2583. return 0;
  2584. }
  2585. int EQ2Emu_lua_GetY(lua_State* state) {
  2586. if (!lua_interface)
  2587. return 0;
  2588. Spawn* spawn = lua_interface->GetSpawn(state);
  2589. if (spawn) {
  2590. lua_interface->SetFloatValue(state, spawn->GetY());
  2591. return 1;
  2592. }
  2593. return 0;
  2594. }
  2595. int EQ2Emu_lua_GetZ(lua_State* state) {
  2596. if (!lua_interface)
  2597. return 0;
  2598. Spawn* spawn = lua_interface->GetSpawn(state);
  2599. if (spawn) {
  2600. lua_interface->SetFloatValue(state, spawn->GetZ());
  2601. return 1;
  2602. }
  2603. return 0;
  2604. }
  2605. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2606. if (!lua_interface)
  2607. return 0;
  2608. Spawn* spawn = lua_interface->GetSpawn(state);
  2609. if (spawn) {
  2610. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2611. return 1;
  2612. }
  2613. return 0;
  2614. }
  2615. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2616. if (!lua_interface)
  2617. return 0;
  2618. Spawn* spawn = lua_interface->GetSpawn(state);
  2619. if (spawn) {
  2620. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2621. return 1;
  2622. }
  2623. return 0;
  2624. }
  2625. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2626. if (!lua_interface)
  2627. return 0;
  2628. Spawn* spawn = lua_interface->GetSpawn(state);
  2629. if (spawn) {
  2630. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2631. return 1;
  2632. }
  2633. return 0;
  2634. }
  2635. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2636. if (!lua_interface)
  2637. return 0;
  2638. Spawn* spawn = lua_interface->GetSpawn(state);
  2639. if (spawn && spawn->IsEntity()) {
  2640. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2641. return 1;
  2642. }
  2643. return 0;
  2644. }
  2645. int EQ2Emu_lua_GetInt(lua_State* state) {
  2646. if (!lua_interface)
  2647. return 0;
  2648. Spawn* spawn = lua_interface->GetSpawn(state);
  2649. if (spawn && spawn->IsEntity()) {
  2650. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2651. return 1;
  2652. }
  2653. return 0;
  2654. }
  2655. int EQ2Emu_lua_GetWis(lua_State* state) {
  2656. if (!lua_interface)
  2657. return 0;
  2658. Spawn* spawn = lua_interface->GetSpawn(state);
  2659. if (spawn && spawn->IsEntity()) {
  2660. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2661. return 1;
  2662. }
  2663. return 0;
  2664. }
  2665. int EQ2Emu_lua_GetSta(lua_State* state) {
  2666. if (!lua_interface)
  2667. return 0;
  2668. Spawn* spawn = lua_interface->GetSpawn(state);
  2669. if (spawn && spawn->IsEntity()) {
  2670. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2671. return 1;
  2672. }
  2673. return 0;
  2674. }
  2675. int EQ2Emu_lua_GetStr(lua_State* state) {
  2676. if (!lua_interface)
  2677. return 0;
  2678. Spawn* spawn = lua_interface->GetSpawn(state);
  2679. if (spawn && spawn->IsEntity()) {
  2680. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2681. return 1;
  2682. }
  2683. return 0;
  2684. }
  2685. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2686. if (!lua_interface)
  2687. return 0;
  2688. Spawn* spawn = lua_interface->GetSpawn(state);
  2689. if (spawn && spawn->IsEntity()) {
  2690. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2691. return 1;
  2692. }
  2693. return 0;
  2694. }
  2695. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2696. if (!lua_interface)
  2697. return 0;
  2698. Spawn* spawn = lua_interface->GetSpawn(state);
  2699. if (spawn && spawn->IsEntity()) {
  2700. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2701. return 1;
  2702. }
  2703. return 0;
  2704. }
  2705. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2706. if (!lua_interface)
  2707. return 0;
  2708. Spawn* spawn = lua_interface->GetSpawn(state);
  2709. if (spawn && spawn->IsEntity()) {
  2710. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2711. return 1;
  2712. }
  2713. return 0;
  2714. }
  2715. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2716. if (!lua_interface)
  2717. return 0;
  2718. Spawn* spawn = lua_interface->GetSpawn(state);
  2719. if (spawn && spawn->IsEntity()) {
  2720. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2721. return 1;
  2722. }
  2723. return 0;
  2724. }
  2725. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2726. if (!lua_interface)
  2727. return 0;
  2728. Spawn* spawn = lua_interface->GetSpawn(state);
  2729. if (spawn && spawn->IsEntity()) {
  2730. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2731. return 1;
  2732. }
  2733. return 0;
  2734. }
  2735. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2736. if (!lua_interface)
  2737. return 0;
  2738. Spawn* spawn = lua_interface->GetSpawn(state);
  2739. if (spawn && spawn->IsEntity()) {
  2740. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2741. return 1;
  2742. }
  2743. return 0;
  2744. }
  2745. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2746. if (!lua_interface)
  2747. return 0;
  2748. Spawn* player = lua_interface->GetSpawn(state);
  2749. if (!player || !player->IsPlayer()) {
  2750. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2751. return 0;
  2752. }
  2753. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2754. if (quest_id <= 0) {
  2755. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2756. return 0;
  2757. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2758. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2759. return 0;
  2760. }
  2761. int32 step = lua_interface->GetInt32Value(state, 3);
  2762. if (step > 0) {
  2763. Client* client = player->GetZone()->GetClientBySpawn(player);
  2764. if (client)
  2765. client->AddPendingQuestUpdate(quest_id, step);
  2766. } else {
  2767. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2768. }
  2769. return 0;
  2770. }
  2771. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2772. Spawn* player = lua_interface->GetSpawn(state);
  2773. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2774. int32 step = lua_interface->GetInt32Value(state, 3);
  2775. int32 progress = lua_interface->GetInt32Value(state, 4);
  2776. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2777. Client* client = player->GetZone()->GetClientBySpawn(player);
  2778. if (client)
  2779. client->AddPendingQuestUpdate(quest_id, step, progress);
  2780. }
  2781. return 0;
  2782. }
  2783. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2784. if (!lua_interface)
  2785. return 0;
  2786. Spawn* player = lua_interface->GetSpawn(state);
  2787. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2788. if (player && player->IsPlayer() && quest_id > 0) {
  2789. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2790. return 1;
  2791. }
  2792. return 0;
  2793. }
  2794. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2795. if (!lua_interface)
  2796. return 0;
  2797. Spawn* player = lua_interface->GetSpawn(state);
  2798. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2799. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2800. if (player && player->IsPlayer() && quest_id > 0) {
  2801. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2802. return 1;
  2803. }
  2804. return 0;
  2805. }
  2806. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2807. if (!lua_interface)
  2808. return 0;
  2809. Spawn* player = lua_interface->GetSpawn(state);
  2810. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2811. if (player && player->IsPlayer() && quest_id > 0) {
  2812. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2813. return 1;
  2814. }
  2815. return 0;
  2816. }
  2817. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2818. if (!lua_interface)
  2819. return 0;
  2820. Quest* quest = lua_interface->GetQuest(state);
  2821. string name = lua_interface->GetStringValue(state, 2);
  2822. string type = lua_interface->GetStringValue(state, 3);
  2823. string zone = lua_interface->GetStringValue(state, 4);
  2824. int16 level = lua_interface->GetInt16Value(state, 5);
  2825. string description = lua_interface->GetStringValue(state, 6);
  2826. bool load = true;
  2827. if (!quest) {
  2828. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2829. load = false;
  2830. }
  2831. if (load && name.length() == 0) {
  2832. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2833. load = false;
  2834. }
  2835. if (load && type.length() == 0) {
  2836. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2837. load = false;
  2838. }
  2839. if (load && zone.length() == 0) {
  2840. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2841. load = false;
  2842. }
  2843. if (load && description.length() == 0) {
  2844. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2845. load = false;
  2846. }
  2847. if (load && level == 0) {
  2848. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2849. load = false;
  2850. }
  2851. if (load)
  2852. quest->RegisterQuest(name, type, zone, level, description);
  2853. return 0;
  2854. }
  2855. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2856. if (!lua_interface)
  2857. return 0;
  2858. Quest* quest = lua_interface->GetQuest(state);
  2859. if (quest) {
  2860. int8 level = lua_interface->GetInt16Value(state, 2);
  2861. quest->SetPrereqLevel(level);
  2862. }
  2863. return 0;
  2864. }
  2865. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2866. if (!lua_interface)
  2867. return 0;
  2868. Quest* quest = lua_interface->GetQuest(state);
  2869. if (quest) {
  2870. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2871. quest->AddPrereqQuest(quest_id);
  2872. }
  2873. return 0;
  2874. }
  2875. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2876. if (!lua_interface)
  2877. return 0;
  2878. Quest* quest = lua_interface->GetQuest(state);
  2879. if (quest) {
  2880. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2881. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2882. if (quantity == 0)
  2883. quantity = 1;
  2884. Item* master_item = master_item_list.GetItem(item_id);
  2885. if (master_item) {
  2886. Item* item = new Item(master_item);
  2887. item->details.count = quantity;
  2888. quest->AddPrereqItem(item);
  2889. }
  2890. }
  2891. return 0;
  2892. }
  2893. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2894. if (!lua_interface)
  2895. return 0;
  2896. Spawn* player = lua_interface->GetSpawn(state);
  2897. if(!player || !player->IsPlayer()) {
  2898. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  2899. return 0;
  2900. }
  2901. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2902. if (quest_id > 0) {
  2903. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2904. return 1;
  2905. } else {
  2906. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2907. }
  2908. return 0;
  2909. }
  2910. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2911. if (!lua_interface)
  2912. return 0;
  2913. Quest* quest = lua_interface->GetQuest(state);
  2914. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2915. if (quest && spawn_id > 0)
  2916. quest->SetQuestReturnNPC(spawn_id);
  2917. return 0;
  2918. }
  2919. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2920. if (!lua_interface)
  2921. return 0;
  2922. Spawn* spawn = lua_interface->GetSpawn(state);
  2923. if (!spawn) {
  2924. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2925. return 0;
  2926. }
  2927. int32 time = lua_interface->GetInt32Value(state, 2);
  2928. if (time <= 0) {
  2929. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2930. return 0;
  2931. }
  2932. string function = lua_interface->GetStringValue(state, 3);
  2933. if (function.length() == 0) {
  2934. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2935. return 0;
  2936. }
  2937. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2938. Spawn* player = lua_interface->GetSpawn(state, 5);
  2939. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2940. timer->timer = Timer::GetCurrentTime2() + time;
  2941. timer->function = function;
  2942. timer->spawn = spawn->GetID();
  2943. timer->player = player ? player->GetID() : 0;
  2944. if (max_count == 0)
  2945. max_count = 1;
  2946. timer->max_count = max_count;
  2947. timer->current_count = 0;
  2948. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2949. return 0;
  2950. }
  2951. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2952. if (!lua_interface)
  2953. return 0;
  2954. Spawn* player = lua_interface->GetSpawn(state);
  2955. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2956. if (player && player->IsPlayer() && quest_id > 0) {
  2957. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2958. return 1;
  2959. }
  2960. return 0;
  2961. }
  2962. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2963. if (!lua_interface)
  2964. return 0;
  2965. Spawn* player = lua_interface->GetSpawn(state);
  2966. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2967. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2968. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2969. if (quest)
  2970. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2971. return 1;
  2972. }
  2973. return 0;
  2974. }
  2975. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2976. if (!lua_interface)
  2977. return 0;
  2978. Spawn* player = lua_interface->GetSpawn(state);
  2979. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2980. if (player && player->IsPlayer() && quest_id > 0) {
  2981. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2982. return 1;
  2983. }
  2984. return 0;
  2985. }
  2986. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2987. if (!lua_interface)
  2988. return 0;
  2989. Spawn* npc = lua_interface->GetSpawn(state);
  2990. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2991. if (npc && !npc->IsPlayer() && quest_id > 0)
  2992. npc->AddProvidedQuest(quest_id);
  2993. return 0;
  2994. }
  2995. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2996. if (!lua_interface)
  2997. return 0;
  2998. Spawn* npc = lua_interface->GetSpawn(state);
  2999. Spawn* player = lua_interface->GetSpawn(state, 2);
  3000. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3001. bool forced = lua_interface->GetBooleanValue(state, 4);
  3002. /* NPC is allowed to be null */
  3003. if (player && player->IsPlayer() && quest_id > 0) {
  3004. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  3005. if (master_quest) {
  3006. Client* client = player->GetZone()->GetClientBySpawn(player);
  3007. if (!client) {
  3008. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3009. }
  3010. Quest* quest = new Quest(master_quest);
  3011. if (!quest) {
  3012. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3013. }
  3014. if (client && quest) {
  3015. if (npc)
  3016. quest->SetQuestGiver(npc->GetDatabaseID());
  3017. else
  3018. quest->SetQuestGiver(0);
  3019. client->AddPendingQuest(quest, forced);
  3020. }
  3021. }
  3022. else {
  3023. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3024. }
  3025. }
  3026. else {
  3027. 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);
  3028. }
  3029. return 0;
  3030. }
  3031. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3032. if (!lua_interface)
  3033. return 0;
  3034. Quest* quest = lua_interface->GetQuest(state);
  3035. if (quest) {
  3036. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3037. quest->AddPrereqClass(class_id);
  3038. }
  3039. return 0;
  3040. }
  3041. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3042. if (!lua_interface)
  3043. return 0;
  3044. Quest* quest = lua_interface->GetQuest(state);
  3045. if (quest) {
  3046. int8 race = lua_interface->GetInt8Value(state, 2);
  3047. quest->AddPrereqRace(race);
  3048. }
  3049. return 0;
  3050. }
  3051. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3052. if (!lua_interface)
  3053. return 0;
  3054. Quest* quest = lua_interface->GetQuest(state);
  3055. if (quest) {
  3056. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3057. quest->AddPrereqModelType(model_type);
  3058. }
  3059. return 0;
  3060. }
  3061. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3062. if (!lua_interface)
  3063. return 0;
  3064. Quest* quest = lua_interface->GetQuest(state);
  3065. if (!quest) {
  3066. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3067. return 0;
  3068. }
  3069. int8 level = lua_interface->GetInt8Value(state, 2);
  3070. quest->SetPrereqTSLevel(level);
  3071. return 0;
  3072. }
  3073. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3074. if (!lua_interface)
  3075. return 0;
  3076. Quest* quest = lua_interface->GetQuest(state);
  3077. if (!quest) {
  3078. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3079. return 0;
  3080. }
  3081. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3082. quest->AddPrereqTradeskillClass(class_id);
  3083. return 0;
  3084. }
  3085. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3086. if (!lua_interface)
  3087. return 0;
  3088. Quest* quest = lua_interface->GetQuest(state);
  3089. if (quest) {
  3090. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3091. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3092. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3093. quest->AddPrereqFaction(faction_id, min, max);
  3094. }
  3095. return 0;
  3096. }
  3097. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3098. if (!lua_interface)
  3099. return 0;
  3100. Quest* quest = lua_interface->GetQuest(state);
  3101. if (quest) {
  3102. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3103. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3104. if (quantity == 0)
  3105. quantity = 1;
  3106. Item* master_item = master_item_list.GetItem(item_id);
  3107. if (master_item) {
  3108. Item* item = new Item(master_item);
  3109. item->details.count = quantity;
  3110. quest->AddSelectableRewardItem(item);
  3111. }
  3112. }
  3113. return 0;
  3114. }
  3115. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3116. if (!lua_interface)
  3117. return 0;
  3118. Quest* quest = lua_interface->GetQuest(state);
  3119. if (quest) {
  3120. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3121. vector<Item*>* items = quest->GetRewardItems();
  3122. if (items) {
  3123. vector<Item*>::iterator itr;
  3124. for (itr = items->begin(); itr != items->end(); itr++) {
  3125. if (*itr && (*itr)->details.item_id == item_id) {
  3126. lua_interface->SetBooleanValue(state, true);
  3127. return 1;
  3128. }
  3129. }
  3130. }
  3131. }
  3132. lua_interface->SetBooleanValue(state, false);
  3133. return 1;
  3134. }
  3135. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3136. if (!lua_interface)
  3137. return 0;
  3138. Quest* quest = lua_interface->GetQuest(state);
  3139. if (quest) {
  3140. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3141. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3142. if (quantity == 0)
  3143. quantity = 1;
  3144. Item* master_item = master_item_list.GetItem(item_id);
  3145. if (master_item) {
  3146. Item* item = new Item(master_item);
  3147. item->details.count = quantity;
  3148. quest->AddRewardItem(item);
  3149. }
  3150. }
  3151. return 0;
  3152. }
  3153. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3154. if (!lua_interface)
  3155. return 0;
  3156. Quest* quest = lua_interface->GetQuest(state);
  3157. if (quest) {
  3158. int32 copper = lua_interface->GetInt32Value(state, 2);
  3159. int32 silver = lua_interface->GetInt32Value(state, 3);
  3160. int32 gold = lua_interface->GetInt32Value(state, 4);
  3161. int32 plat = lua_interface->GetInt32Value(state, 5);
  3162. quest->AddRewardCoins(copper, silver, gold, plat);
  3163. }
  3164. return 0;
  3165. }
  3166. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3167. if (!lua_interface)
  3168. return 0;
  3169. Quest* quest = lua_interface->GetQuest(state);
  3170. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3171. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3172. if (quest && faction_id > 0 && amount != 0)
  3173. quest->AddRewardFaction(faction_id, amount);
  3174. return 0;
  3175. }
  3176. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3177. if (!lua_interface)
  3178. return 0;
  3179. Quest* quest = lua_interface->GetQuest(state);
  3180. if (quest) {
  3181. int32 status = lua_interface->GetInt32Value(state, 2);
  3182. quest->SetRewardStatus(status);
  3183. }
  3184. return 0;
  3185. }
  3186. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3187. if (!lua_interface)
  3188. return 0;
  3189. Quest* quest = lua_interface->GetQuest(state);
  3190. if (quest) {
  3191. string comment = lua_interface->GetStringValue(state, 2);
  3192. quest->SetRewardComment(comment);
  3193. }
  3194. return 0;
  3195. }
  3196. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3197. if (!lua_interface)
  3198. return 0;
  3199. Quest* quest = lua_interface->GetQuest(state);
  3200. if (quest) {
  3201. int32 exp = lua_interface->GetInt32Value(state, 2);
  3202. quest->SetRewardXP(exp);
  3203. }
  3204. return 0;
  3205. }
  3206. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3207. Quest* quest = lua_interface->GetQuest(state);
  3208. if (quest) {
  3209. int32 step = lua_interface->GetInt32Value(state, 2);
  3210. string description = lua_interface->GetStringValue(state, 3);
  3211. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3212. float percentage = lua_interface->GetFloatValue(state, 5);
  3213. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3214. int16 icon = lua_interface->GetInt16Value(state, 7);
  3215. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3216. const char* taskgroup = 0;
  3217. if (str_taskgroup.length() > 0)
  3218. taskgroup = str_taskgroup.c_str();
  3219. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3220. if (quest_step && icon && quantity > 0)
  3221. quest_step->SetIcon(icon);
  3222. }
  3223. return 0;
  3224. }
  3225. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3226. if (!lua_interface)
  3227. return 0;
  3228. Quest* quest = lua_interface->GetQuest(state);
  3229. if (quest) {
  3230. int32 step = lua_interface->GetInt32Value(state, 2);
  3231. string description = lua_interface->GetStringValue(state, 3);
  3232. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3233. float percentage = lua_interface->GetFloatValue(state, 5);
  3234. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3235. int16 icon = lua_interface->GetInt16Value(state, 7);
  3236. const char* taskgroup = 0;
  3237. if (str_taskgroup.length() > 0)
  3238. taskgroup = str_taskgroup.c_str();
  3239. int32 npc_id = 0;
  3240. vector<int32>* ids = 0;
  3241. Spawn* spawn = nullptr;
  3242. int i = 0;
  3243. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3244. if (ids == 0)
  3245. ids = new vector<int32>;
  3246. ids->push_back(npc_id);
  3247. i++;
  3248. }
  3249. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3250. if (quest_step && icon > 0 && quantity > 0)
  3251. quest_step->SetIcon(icon);
  3252. if (quest->GetPlayer()) {
  3253. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3254. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3255. }
  3256. }
  3257. return 0;
  3258. }
  3259. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3260. if (!lua_interface)
  3261. return 0;
  3262. Quest* quest = lua_interface->GetQuest(state);
  3263. if (quest) {
  3264. int32 step = lua_interface->GetInt32Value(state, 2);
  3265. string description = lua_interface->GetStringValue(state, 3);
  3266. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3267. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3268. int16 icon = lua_interface->GetInt16Value(state, 6);
  3269. const char* taskgroup = 0;
  3270. if (str_taskgroup.length() > 0)
  3271. taskgroup = str_taskgroup.c_str();
  3272. int32 npc_id = 0;
  3273. vector<int32>* ids = 0;
  3274. int i = 0;
  3275. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3276. if (ids == 0)
  3277. ids = new vector<int32>;
  3278. ids->push_back(npc_id);
  3279. i++;
  3280. }
  3281. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3282. if (quest_step && icon > 0)
  3283. quest_step->SetIcon(icon);
  3284. if (quest->GetPlayer()) {
  3285. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3286. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3287. }
  3288. }
  3289. return 0;
  3290. }
  3291. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3292. if (!lua_interface)
  3293. return 0;
  3294. Quest* quest = lua_interface->GetQuest(state);
  3295. if (quest) {
  3296. int32 step = lua_interface->GetInt32Value(state, 2);
  3297. string description = lua_interface->GetStringValue(state, 3);
  3298. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3299. float percentage = lua_interface->GetFloatValue(state, 5);
  3300. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3301. int16 icon = lua_interface->GetInt16Value(state, 7);
  3302. const char* taskgroup = 0;
  3303. if (str_taskgroup.length() > 0)
  3304. taskgroup = str_taskgroup.c_str();
  3305. int32 item_id = 0;
  3306. vector<int32>* ids = 0;
  3307. int i = 0;
  3308. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3309. if (ids == 0)
  3310. ids = new vector<int32>;
  3311. ids->push_back(item_id);
  3312. i++;
  3313. }
  3314. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3315. if (quest_step && icon > 0 && quantity > 0)
  3316. quest_step->SetIcon(icon);
  3317. if (quest->GetPlayer()) {
  3318. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3319. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3320. }
  3321. }
  3322. return 0;
  3323. }
  3324. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3325. if (!lua_interface)
  3326. return 0;
  3327. Quest* quest = lua_interface->GetQuest(state);
  3328. if (quest) {
  3329. int32 step = lua_interface->GetInt32Value(state, 2);
  3330. string description = lua_interface->GetStringValue(state, 3);
  3331. float max_variation = lua_interface->GetFloatValue(state, 4);
  3332. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3333. int16 icon = lua_interface->GetInt16Value(state, 6);
  3334. const char* taskgroup = 0;
  3335. if (str_taskgroup.length() > 0)
  3336. taskgroup = str_taskgroup.c_str();
  3337. vector<Location>* locations = 0;
  3338. int i = 7;
  3339. while (true) {
  3340. Location loc;
  3341. loc.x = lua_interface->GetFloatValue(state, i);
  3342. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3343. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3344. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3345. break;
  3346. if (locations == 0)
  3347. locations = new vector<Location>;
  3348. locations->push_back(loc);
  3349. i += 3;
  3350. }
  3351. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3352. if (quest_step && icon > 0)
  3353. quest_step->SetIcon(icon);
  3354. if (quest->GetPlayer()) {
  3355. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3356. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3357. }
  3358. }
  3359. return 0;
  3360. }
  3361. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3362. if (!lua_interface)
  3363. return 0;
  3364. Quest* quest = lua_interface->GetQuest(state);
  3365. if (quest) {
  3366. int32 step = lua_interface->GetInt32Value(state, 2);
  3367. string description = lua_interface->GetStringValue(state, 3);
  3368. float max_variation = lua_interface->GetFloatValue(state, 4);
  3369. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3370. int16 icon = lua_interface->GetInt16Value(state, 6);
  3371. const char* taskgroup = 0;
  3372. if (str_taskgroup.length() > 0)
  3373. taskgroup = str_taskgroup.c_str();
  3374. vector<Location>* locations = 0;
  3375. int i = 7;
  3376. while (true) {
  3377. Location loc;
  3378. loc.x = lua_interface->GetFloatValue(state, i);
  3379. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3380. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3381. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3382. break;
  3383. if (locations == 0)
  3384. locations = new vector<Location>;
  3385. locations->push_back(loc);
  3386. i += 3;
  3387. }
  3388. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3389. if (quest_step && icon > 0)
  3390. quest_step->SetIcon(icon);
  3391. if (quest->GetPlayer()) {
  3392. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3393. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3394. }
  3395. }
  3396. return 0;
  3397. }
  3398. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3399. Quest* quest = lua_interface->GetQuest(state);
  3400. if (quest) {
  3401. int32 step = lua_interface->GetInt32Value(state, 2);
  3402. string description = lua_interface->GetStringValue(state, 3);
  3403. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3404. float percentage = lua_interface->GetFloatValue(state, 5);
  3405. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3406. int16 icon = lua_interface->GetInt16Value(state, 7);
  3407. const char* taskgroup = 0;
  3408. if (str_taskgroup.length() > 0)
  3409. taskgroup = str_taskgroup.c_str();
  3410. int32 spell_id = 0;
  3411. vector<int32>* ids = 0;
  3412. int i = 0;
  3413. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3414. if (ids == 0)
  3415. ids = new vector<int32>;
  3416. ids->push_back(spell_id);
  3417. i++;
  3418. }
  3419. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3420. if (quest_step && icon > 0 && quantity > 0)
  3421. quest_step->SetIcon(icon);
  3422. if (quest->GetPlayer()) {
  3423. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3424. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3425. }
  3426. }
  3427. return 0;
  3428. }
  3429. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3430. if (!lua_interface)
  3431. return 0;
  3432. Quest* quest = lua_interface->GetQuest(state);
  3433. if (quest) {
  3434. int32 step = lua_interface->GetInt32Value(state, 2);
  3435. string description = lua_interface->GetStringValue(state, 3);
  3436. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3437. float percentage = lua_interface->GetFloatValue(state, 5);
  3438. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3439. int16 icon = lua_interface->GetInt16Value(state, 7);
  3440. const char* taskgroup = 0;
  3441. if (str_taskgroup.length() > 0)
  3442. taskgroup = str_taskgroup.c_str();
  3443. int32 item_id = 0;
  3444. vector<int32>* ids = 0;
  3445. int i = 0;
  3446. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3447. if (ids == 0)
  3448. ids = new vector<int32>;
  3449. ids->push_back(item_id);
  3450. i++;
  3451. }
  3452. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3453. if (quest_step && icon > 0 && quantity > 0)
  3454. quest_step->SetIcon(icon);
  3455. if (quest->GetPlayer()) {
  3456. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3457. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3458. }
  3459. }
  3460. return 0;
  3461. }
  3462. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3463. if (!lua_interface)
  3464. return 0;
  3465. Quest* quest = lua_interface->GetQuest(state);
  3466. if (quest) {
  3467. int32 step = lua_interface->GetInt32Value(state, 2);
  3468. string description = lua_interface->GetStringValue(state, 3);
  3469. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3470. float percentage = lua_interface->GetFloatValue(state, 5);
  3471. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3472. int16 icon = lua_interface->GetInt16Value(state, 7);
  3473. const char* taskgroup = 0;
  3474. if (str_taskgroup.length() > 0)
  3475. taskgroup = str_taskgroup.c_str();
  3476. int32 item_id = 0;
  3477. vector<int32>* ids = 0;
  3478. int i = 0;
  3479. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3480. if (ids == 0)
  3481. ids = new vector<int32>;
  3482. ids->push_back(item_id);
  3483. i++;
  3484. }
  3485. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3486. if (quest_step && icon > 0 && quantity > 0)
  3487. quest_step->SetIcon(icon);
  3488. if (quest->GetPlayer()) {
  3489. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3490. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3491. }
  3492. }
  3493. return 0;
  3494. }
  3495. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3496. if (!lua_interface)
  3497. return 0;
  3498. Quest* quest = lua_interface->GetQuest(state);
  3499. if (quest) {
  3500. string action = lua_interface->GetStringValue(state, 2);
  3501. if (action.length() > 0)
  3502. quest->SetCompleteAction(action);
  3503. }
  3504. return 0;
  3505. }
  3506. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3507. if (!lua_interface)
  3508. return 0;
  3509. Quest* quest = lua_interface->GetQuest(state);
  3510. if (quest) {
  3511. int32 step = lua_interface->GetInt32Value(state, 2);
  3512. string action = lua_interface->GetStringValue(state, 3);
  3513. if (step > 0 && action.length() > 0)
  3514. quest->AddCompleteAction(step, action);
  3515. }
  3516. return 0;
  3517. }
  3518. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3519. if (!lua_interface)
  3520. return 0;
  3521. Quest* quest = lua_interface->GetQuest(state);
  3522. if (quest) {
  3523. int32 step = lua_interface->GetInt32Value(state, 2);
  3524. string action = lua_interface->GetStringValue(state, 3);
  3525. if (step > 0 && action.length() > 0)
  3526. quest->AddProgressAction(step, action);
  3527. }
  3528. return 0;
  3529. }
  3530. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3531. if (!lua_interface)
  3532. return 0;
  3533. Quest* quest = lua_interface->GetQuest(state);
  3534. string description = lua_interface->GetStringValue(state, 2);
  3535. if (quest && description.length() > 0)
  3536. quest->SetDescription(description);
  3537. return 0;
  3538. }
  3539. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3540. if (!lua_interface)
  3541. return 0;
  3542. Quest* quest = lua_interface->GetQuest(state);
  3543. string description = lua_interface->GetStringValue(state, 2);
  3544. if (quest && description.length() > 0)
  3545. quest->SetCompletedDescription(description);
  3546. return 0;
  3547. }
  3548. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3549. if (!lua_interface)
  3550. return 0;
  3551. Quest* quest = lua_interface->GetQuest(state);
  3552. int32 step = lua_interface->GetInt32Value(state, 2);
  3553. string description = lua_interface->GetStringValue(state, 3);
  3554. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3555. if (quest && step > 0 && description.length() > 0) {
  3556. quest->SetTaskGroupDescription(step, description, display_bullets);
  3557. if (quest->GetPlayer()) {
  3558. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3559. if (client)
  3560. client->SendQuestUpdateStep(quest, step, false);
  3561. }
  3562. }
  3563. return 0;
  3564. }
  3565. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3566. if (!lua_interface)
  3567. return 0;
  3568. Quest* quest = lua_interface->GetQuest(state);
  3569. int32 step = lua_interface->GetInt32Value(state, 2);
  3570. string description = lua_interface->GetStringValue(state, 3);
  3571. if (quest && step > 0 && description.length() > 0) {
  3572. quest->SetStepDescription(step, description);
  3573. if (quest->GetPlayer()) {
  3574. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3575. if (client)
  3576. client->SendQuestUpdateStepImmediately(quest, step);
  3577. }
  3578. }
  3579. return 0;
  3580. }
  3581. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3582. Quest* quest = lua_interface->GetQuest(state);
  3583. string zone = lua_interface->GetStringValue(state, 2);
  3584. if (quest && zone.length() > 0)
  3585. quest->SetZone(zone);
  3586. return 0;
  3587. }
  3588. int EQ2Emu_lua_GiveImmediateQuestReward(lua_State* state) {
  3589. if (!lua_interface)
  3590. return 0;
  3591. Quest* quest = lua_interface->GetQuest(state);
  3592. Spawn* playerSpawn = lua_interface->GetSpawn(state, 2);
  3593. int32 coin = lua_interface->GetInt32Value(state, 3);
  3594. int32 status_points = lua_interface->GetInt32Value(state, 4);
  3595. string rewards_str = lua_interface->GetStringValue(state, 5);
  3596. string select_rewards_str = lua_interface->GetStringValue(state, 6);
  3597. string factions_map_str = lua_interface->GetStringValue(state, 7);
  3598. string text = lua_interface->GetStringValue(state, 8);
  3599. int32 source_id = 0;
  3600. if (playerSpawn && playerSpawn->IsPlayer()) {
  3601. Player* player = (Player*)playerSpawn;
  3602. Client* client = player->GetZone()->GetClientBySpawn(player);
  3603. if (client) {
  3604. vector<Item*> reward_items;
  3605. vector<Item*> selectable_reward_items;
  3606. if (rewards_str.length() > 0) {
  3607. map<unsigned int, unsigned short> rewards = ParseIntMap(rewards_str);
  3608. map<unsigned int, unsigned short>::iterator itr;
  3609. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3610. if (itr->first > 0) {
  3611. Item* item = new Item(master_item_list.GetItem(itr->first));
  3612. if (item) {
  3613. if (itr->second > 0)
  3614. item->details.count = itr->second;
  3615. reward_items.push_back(item);
  3616. }
  3617. }
  3618. }
  3619. }
  3620. if (select_rewards_str.length() > 0) {
  3621. map<unsigned int, unsigned short> rewards = ParseIntMap(select_rewards_str);
  3622. map<unsigned int, unsigned short>::iterator itr;
  3623. for (itr = rewards.begin(); itr != rewards.end(); itr++) {
  3624. if (itr->first > 0) {
  3625. Item* item = new Item(master_item_list.GetItem(itr->first));
  3626. if (item) {
  3627. if (itr->second > 0)
  3628. item->stack_count = itr->second;
  3629. selectable_reward_items.push_back(item);
  3630. }
  3631. }
  3632. }
  3633. }
  3634. map<unsigned int, signed int> faction_rewards = ParseSInt32Map(factions_map_str);
  3635. const char* reward_type = "Quest Reward!";
  3636. if (!quest)
  3637. reward_type = "Reward!";
  3638. client->DisplayQuestRewards(quest, coin, &reward_items, &selectable_reward_items, &faction_rewards, reward_type, status_points, text.c_str());
  3639. }
  3640. }
  3641. return 0;
  3642. }
  3643. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3644. if (!lua_interface)
  3645. return 0;
  3646. Quest* quest = lua_interface->GetQuest(state);
  3647. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3648. if (quest && spawn) {
  3649. if (spawn->IsPlayer()) {
  3650. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3651. if (client)
  3652. client->AddPendingQuestReward(quest);
  3653. }
  3654. }
  3655. return 0;
  3656. }
  3657. int EQ2Emu_lua_Harvest(lua_State* state) {
  3658. if (!lua_interface)
  3659. return 0;
  3660. Spawn* player = lua_interface->GetSpawn(state);
  3661. Spawn* node = lua_interface->GetSpawn(state, 2);
  3662. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3663. Client* client = player->GetZone()->GetClientBySpawn(player);
  3664. if (client) {
  3665. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3666. ((GroundSpawn*)node)->ProcessHarvest(client);
  3667. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3668. player->GetZone()->RemoveSpawn(node, true);
  3669. }
  3670. }
  3671. else if (player && player->IsPlayer()) {
  3672. Client* client = player->GetZone()->GetClientBySpawn(player);
  3673. if (client)
  3674. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3675. }
  3676. return 0;
  3677. }
  3678. int EQ2Emu_lua_Bind(lua_State* state) {
  3679. if (!lua_interface)
  3680. return 0;
  3681. Spawn* spawn = lua_interface->GetSpawn(state);
  3682. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3683. float x = lua_interface->GetFloatValue(state, 3);
  3684. float y = lua_interface->GetFloatValue(state, 4);
  3685. float z = lua_interface->GetFloatValue(state, 5);
  3686. float h = lua_interface->GetFloatValue(state, 6);
  3687. if (!spawn) {
  3688. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3689. return 0;
  3690. }
  3691. if (!spawn->IsPlayer()) {
  3692. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3693. return 0;
  3694. }
  3695. if (zone_id == 0) {
  3696. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3697. if (!client) {
  3698. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3699. return 0;
  3700. }
  3701. if (!client->Bind())
  3702. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3703. }
  3704. else {
  3705. Player* player = (Player*)spawn;
  3706. player->GetPlayerInfo()->SetBindZone(zone_id);
  3707. player->GetPlayerInfo()->SetBindX(x);
  3708. player->GetPlayerInfo()->SetBindY(y);
  3709. player->GetPlayerInfo()->SetBindZ(z);
  3710. player->GetPlayerInfo()->SetBindHeading(h);
  3711. }
  3712. return 0;
  3713. }
  3714. int EQ2Emu_lua_Gate(lua_State* state) {
  3715. if (!lua_interface)
  3716. return 0;
  3717. Spawn* spawn = lua_interface->GetSpawn(state);
  3718. if (spawn) {
  3719. if (spawn->IsPlayer()) {
  3720. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3721. if (client) {
  3722. if (!client->Gate())
  3723. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3724. }
  3725. }
  3726. }
  3727. return 0;
  3728. }
  3729. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3730. if (!lua_interface)
  3731. return 0;
  3732. bool ret = false;
  3733. Spawn* spawn = lua_interface->GetSpawn(state);
  3734. if (spawn) {
  3735. if (spawn->IsPlayer()) {
  3736. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3737. if (client)
  3738. ret = client->BindAllowed();
  3739. }
  3740. }
  3741. lua_interface->SetBooleanValue(state, ret);
  3742. return 1;
  3743. }
  3744. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3745. if (!lua_interface)
  3746. return 0;
  3747. bool ret = false;
  3748. Spawn* spawn = lua_interface->GetSpawn(state);
  3749. if (spawn) {
  3750. if (spawn->IsPlayer()) {
  3751. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3752. if (client)
  3753. ret = client->GateAllowed();
  3754. }
  3755. }
  3756. lua_interface->SetBooleanValue(state, ret);
  3757. return 1;
  3758. }
  3759. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3760. Spawn* spawn = lua_interface->GetSpawn(state);
  3761. if (spawn) {
  3762. lua_interface->SetBooleanValue(state, spawn->Alive());
  3763. return 1;
  3764. }
  3765. return 0;
  3766. }
  3767. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3768. if (!lua_interface)
  3769. return 0;
  3770. Spawn* spawn = lua_interface->GetSpawn(state);
  3771. if (spawn && spawn->IsEntity()) {
  3772. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3773. return 1;
  3774. }
  3775. return 0;
  3776. }
  3777. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3778. Spawn* spawn = lua_interface->GetSpawn(state);
  3779. string message = lua_interface->GetStringValue(state, 2);
  3780. string color_str = lua_interface->GetStringValue(state, 3);
  3781. int8 color = CHANNEL_NARRATIVE;
  3782. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3783. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3784. if (client) {
  3785. if (color_str.length() > 0) {
  3786. // leave for backwards compat, but all future should just use the number
  3787. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3788. color = CHANNEL_COLOR_RED;
  3789. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3790. color = CHANNEL_COLOR_YELLOW;
  3791. else
  3792. {
  3793. // use a number to specify the channel as per Commands/Commands.h defines
  3794. color = (int8)atoul(color_str.c_str());
  3795. }
  3796. }
  3797. client->SimpleMessage(color, message.c_str());
  3798. }
  3799. }
  3800. return 0;
  3801. }
  3802. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3803. Spawn* spawn = lua_interface->GetSpawn(state);
  3804. string message = lua_interface->GetStringValue(state, 2);
  3805. int8 red = lua_interface->GetInt8Value(state, 3);
  3806. int8 green = lua_interface->GetInt8Value(state, 4);
  3807. int8 blue = lua_interface->GetInt8Value(state, 5);
  3808. if (!spawn) {
  3809. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3810. return 0;
  3811. }
  3812. int32 words = ::CountWordsInString(message.c_str());
  3813. if (words < 5)
  3814. words = 5;
  3815. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3816. if (client)
  3817. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3818. return 0;
  3819. }
  3820. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3821. Spawn* spawn = lua_interface->GetSpawn(state);
  3822. int8 param = lua_interface->GetInt8Value(state, 2);
  3823. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3824. int8 value = lua_interface->GetInt8Value(state, 4);
  3825. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3826. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3827. if (client) {
  3828. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3829. switch (param) {
  3830. case 1: {
  3831. packet->setDataByName("parameter1", param_value);
  3832. break;
  3833. }
  3834. case 2: {
  3835. packet->setDataByName("parameter2", param_value);
  3836. break;
  3837. }
  3838. case 3: {
  3839. packet->setDataByName("parameter3", param_value);
  3840. break;
  3841. }
  3842. case 4: {
  3843. packet->setDataByName("parameter4", param_value);
  3844. break;
  3845. }
  3846. case 5: {
  3847. packet->setDataByName("parameter5", param_value);
  3848. break;
  3849. }
  3850. }
  3851. packet->setDataByName("value", value);
  3852. client->QueuePacket(packet->serialize());
  3853. safe_delete(packet);
  3854. }
  3855. }
  3856. return 0;
  3857. }
  3858. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3859. Spawn* spawn = lua_interface->GetSpawn(state);
  3860. if (spawn && spawn->IsPlayer()) {
  3861. if (((Player*)spawn)->GetIsTracking())
  3862. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3863. else
  3864. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3865. }
  3866. return 0;
  3867. }
  3868. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3869. Spawn* player = lua_interface->GetSpawn(state);
  3870. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3871. string name = lua_interface->GetStringValue(state, 3);
  3872. float distance = lua_interface->GetFloatValue(state, 4);
  3873. string command = lua_interface->GetStringValue(state, 5);
  3874. string error_text = lua_interface->GetStringValue(state, 6);
  3875. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3876. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3877. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3878. if (spawn) {
  3879. if (distance == 0)
  3880. distance = 10.0f;
  3881. if (command.length() == 0)
  3882. command = name;
  3883. if (command.length() < 1 && name.length() < 1)
  3884. {
  3885. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3886. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3887. spawn->RemovePrimaryCommands();
  3888. }
  3889. else
  3890. {
  3891. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3892. }
  3893. }
  3894. return 0;
  3895. }
  3896. int EQ2Emu_lua_HasSpell(lua_State* state) {
  3897. if (!lua_interface)
  3898. return 0;
  3899. Spawn* player = lua_interface->GetSpawn(state);
  3900. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3901. int16 tier = lua_interface->GetInt16Value(state, 3);
  3902. if (player && player->IsPlayer()) {
  3903. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  3904. return 1;
  3905. }
  3906. return 0;
  3907. }
  3908. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3909. if (!lua_interface)
  3910. return 0;
  3911. Spawn* player = lua_interface->GetSpawn(state);
  3912. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3913. int16 tier = lua_interface->GetInt16Value(state, 3);
  3914. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3915. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  3916. bool add_to_hotbar = true;
  3917. if (num_args > 4) {
  3918. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  3919. }
  3920. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3921. if (player && spell && player->IsPlayer()) {
  3922. Client* client = player->GetClient();
  3923. if (client) {
  3924. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3925. {
  3926. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3927. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3928. client->GetPlayer()->UnlockSpell(spell);
  3929. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  3930. }
  3931. else
  3932. {
  3933. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3934. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3935. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3936. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3937. client->GetPlayer()->UnlockSpell(spell);
  3938. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  3939. }
  3940. //if (client ) {
  3941. // ((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);
  3942. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3943. if (outapp)
  3944. client->QueuePacket(outapp);
  3945. }
  3946. }
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3950. if (!lua_interface)
  3951. return 0;
  3952. Spawn* player = lua_interface->GetSpawn(state);
  3953. if (player && player->IsPlayer()) {
  3954. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3955. return 1;
  3956. }
  3957. return 0;
  3958. }
  3959. int EQ2Emu_lua_Attack(lua_State* state) {
  3960. if (lua_interface) {
  3961. Spawn* npc = lua_interface->GetSpawn(state);
  3962. Spawn* player = lua_interface->GetSpawn(state, 2);
  3963. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3964. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3965. }
  3966. return 0;
  3967. }
  3968. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3969. if (lua_interface) {
  3970. Spawn* target = lua_interface->GetSpawn(state);
  3971. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3972. if (target && target->GetZone())
  3973. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3974. }
  3975. return 0;
  3976. }
  3977. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3978. Spawn* player;
  3979. if (lua_interface) {
  3980. player = lua_interface->GetSpawn(state);
  3981. if (player && player->IsPlayer()) {
  3982. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3983. return 1;
  3984. }
  3985. }
  3986. return 0;
  3987. }
  3988. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3989. Spawn* player;
  3990. Client* client;
  3991. if (lua_interface) {
  3992. player = lua_interface->GetSpawn(state);
  3993. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3994. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3995. client->HandInCollections();
  3996. }
  3997. return 0;
  3998. }
  3999. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4000. Spawn* widget;
  4001. if (lua_interface) {
  4002. widget = lua_interface->GetSpawn(state);
  4003. if (widget && widget->IsWidget())
  4004. ((Widget*)widget)->HandleUse(NULL, "");
  4005. }
  4006. return 0;
  4007. }
  4008. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4009. Spawn* spawn = 0;
  4010. int32 primary_list = 0;
  4011. int32 secondary_list = 0;
  4012. if (lua_interface) {
  4013. spawn = lua_interface->GetSpawn(state);
  4014. primary_list = lua_interface->GetInt32Value(state, 2);
  4015. secondary_list = lua_interface->GetInt32Value(state, 3);
  4016. if (!spawn->IsNPC()) {
  4017. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4018. return 0;
  4019. }
  4020. NPC* npc = (NPC*)spawn;
  4021. npc->SetPrimarySpellList(primary_list);
  4022. npc->SetSecondarySpellList(secondary_list);
  4023. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4024. }
  4025. return 0;
  4026. }
  4027. int EQ2Emu_lua_GetPet(lua_State* state) {
  4028. if (!lua_interface)
  4029. return 0;
  4030. Spawn* spawn = lua_interface->GetSpawn(state);
  4031. if (spawn) {
  4032. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4033. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4034. return 1;
  4035. }
  4036. }
  4037. return 0;
  4038. }
  4039. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4040. if (!lua_interface)
  4041. return 0;
  4042. Spawn* spawn = lua_interface->GetSpawn(state);
  4043. if (spawn) {
  4044. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4045. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4046. return 1;
  4047. }
  4048. }
  4049. return 0;
  4050. }
  4051. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4052. if (!lua_interface)
  4053. return 0;
  4054. Spawn* spawn = lua_interface->GetSpawn(state);
  4055. if (spawn) {
  4056. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4057. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4058. return 1;
  4059. }
  4060. }
  4061. return 0;
  4062. }
  4063. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4064. if (!lua_interface)
  4065. return 0;
  4066. Spawn* spawn = lua_interface->GetSpawn(state);
  4067. if (spawn) {
  4068. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4069. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4070. return 1;
  4071. }
  4072. }
  4073. return 0;
  4074. }
  4075. int EQ2Emu_lua_Charm(lua_State* state) {
  4076. if (!lua_interface)
  4077. return 0;
  4078. Spawn* owner = lua_interface->GetSpawn(state);
  4079. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4080. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4081. if (!luaspell) {
  4082. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4083. return 0;
  4084. }
  4085. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4086. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4087. pet->SetPet(true);
  4088. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4089. ((NPC*)pet)->SetOwner((Entity*)owner);
  4090. // If owner is player and player does not have a summoned pet set the players charsheet
  4091. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4092. Player* player = (Player*)owner;
  4093. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4094. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  4095. player->GetInfoStruct()->pet_movement = 2;
  4096. player->GetInfoStruct()->pet_behavior = 3;
  4097. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4098. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4099. // Make sure the values get sent to the client
  4100. player->SetCharSheetChanged(true);
  4101. }
  4102. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4103. pet->SetSpawnScript("");
  4104. // Set faction to the same as the owner
  4105. pet->SetFactionID(owner->GetFactionID());
  4106. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4107. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4108. // Clear hate list
  4109. ((NPC*)pet)->Brain()->ClearHate();
  4110. // Set the brain to a pet brain
  4111. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4112. }
  4113. return 0;
  4114. }
  4115. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4116. if (!lua_interface)
  4117. return 0;
  4118. Spawn* spawn = lua_interface->GetSpawn(state);
  4119. if (!spawn) {
  4120. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4121. return 0;
  4122. }
  4123. vector<Spawn*> groupMembers;
  4124. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4125. groupMembers = *spawn->GetSpawnGroup();
  4126. }
  4127. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4128. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4129. deque<GroupMemberInfo*>::iterator itr;
  4130. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4131. if (group)
  4132. {
  4133. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4134. deque<GroupMemberInfo*>* members = group->GetMembers();
  4135. GroupMemberInfo* info = 0;
  4136. for (itr = members->begin(); itr != members->end(); itr++) {
  4137. info = *itr;
  4138. if (info->client)
  4139. groupMembers.push_back(info->client->GetPlayer());
  4140. }
  4141. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4142. }
  4143. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4144. }
  4145. else
  4146. return 0;
  4147. lua_createtable(state, groupMembers.size(), 0);
  4148. int newTable = lua_gettop(state);
  4149. for (int32 i = 0; i < groupMembers.size(); i++) {
  4150. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4151. lua_rawseti(state, newTable, i + 1);
  4152. }
  4153. return 1;
  4154. }
  4155. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4156. if (!lua_interface)
  4157. return 0;
  4158. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4159. lua_interface->SetOptionWindowValue(state, option_window);
  4160. return 1;
  4161. }
  4162. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4163. if (!lua_interface)
  4164. return 0;
  4165. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4166. if (option_window) {
  4167. OptionWindowOption option_window_option;
  4168. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4169. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4170. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4171. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4172. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4173. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4174. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4175. option_window->push_back(option_window_option);
  4176. }
  4177. return 0;
  4178. }
  4179. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4180. if (!lua_interface)
  4181. return 0;
  4182. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4183. Spawn* player = lua_interface->GetSpawn(state, 2);
  4184. string window_title = lua_interface->GetStringValue(state, 3);
  4185. string cancel_command = lua_interface->GetStringValue(state, 4);
  4186. Client* client = player->GetZone()->GetClientBySpawn(player);
  4187. if (option_window && window_title.length() > 0 && client) {
  4188. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4189. if (!packet)
  4190. return 0;
  4191. packet->setDataByName("title_text", window_title.c_str());
  4192. if (cancel_command.length() > 0)
  4193. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4194. packet->setArrayLengthByName("num_selections", option_window->size());
  4195. vector<OptionWindowOption>::iterator itr;
  4196. int8 i = 0;
  4197. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4198. OptionWindowOption opt = *itr;
  4199. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4200. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4201. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4202. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4203. if (opt.optionCommand.length() > 0)
  4204. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4205. if (opt.optionConfirmTitle.length() > 0)
  4206. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4207. i++;
  4208. }
  4209. client->QueuePacket(packet->serialize());
  4210. safe_delete(option_window);
  4211. safe_delete(packet);
  4212. }
  4213. return 0;
  4214. }
  4215. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4216. if (!lua_interface)
  4217. return 0;
  4218. Spawn* spawn = lua_interface->GetSpawn(state);
  4219. if (spawn) {
  4220. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4221. return 1;
  4222. }
  4223. else
  4224. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4225. return 0;
  4226. }
  4227. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4228. if (!lua_interface)
  4229. return 0;
  4230. Spawn* spawn = lua_interface->GetSpawn(state);
  4231. if (spawn) {
  4232. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4233. return 1;
  4234. }
  4235. else
  4236. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4240. if (!lua_interface)
  4241. return 0;
  4242. Spawn* spawn = lua_interface->GetSpawn(state);
  4243. if (spawn) {
  4244. int8 class_id = spawn->GetTradeskillClass();
  4245. // Need to add 42 for the offset in the array
  4246. class_id += 44;
  4247. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4248. return 1;
  4249. }
  4250. else
  4251. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4252. return 0;
  4253. }
  4254. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4255. if (!lua_interface)
  4256. return 0;
  4257. Spawn* spawn = lua_interface->GetSpawn(state);
  4258. int16 level = lua_interface->GetInt8Value(state, 2);
  4259. if (spawn) {
  4260. if (spawn->IsPlayer())
  4261. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4262. else
  4263. spawn->SetTSLevel(level);
  4264. }
  4265. else
  4266. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4267. return 0;
  4268. }
  4269. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4270. if (!lua_interface)
  4271. return 0;
  4272. Spawn* spawn = lua_interface->GetSpawn(state);
  4273. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4274. if (spawn) {
  4275. spawn->SetAttackable(attackable);
  4276. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4277. }
  4278. return 0;
  4279. }
  4280. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4281. // Check to see if we have a valid lua_interface
  4282. if (!lua_interface)
  4283. return 0;
  4284. // Get the spawn that is getting the pet
  4285. Spawn* spawn = lua_interface->GetSpawn(state);
  4286. // Get the DB ID of the pet
  4287. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4288. // The max level the pet can gain
  4289. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4290. // Get the spell that this command was called from
  4291. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4292. // Check to make sure the spawn pointer is valid
  4293. if (!spawn) {
  4294. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4295. return 0;
  4296. }
  4297. // Check to make sure the spawn is an entity
  4298. if (!spawn->IsEntity()) {
  4299. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4300. return 0;
  4301. }
  4302. // Check to make sure the spawn doesn't already have a pet of this type
  4303. if (((Entity*)spawn)->GetPet()) {
  4304. if (spawn->IsPlayer()) {
  4305. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4306. if (client)
  4307. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4308. }
  4309. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4310. return 0;
  4311. }
  4312. // Check to see if the DB ID for the pet is set
  4313. if (pet_id == 0) {
  4314. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4315. return 0;
  4316. }
  4317. // Check to see if the pointer to the spell is valid
  4318. if (!luaspell) {
  4319. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4320. return 0;
  4321. }
  4322. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4323. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4324. if (!pet) {
  4325. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4326. return 0;
  4327. }
  4328. // Check to make sure the pet is an npc
  4329. if (!pet->IsNPC()) {
  4330. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4331. return 0;
  4332. }
  4333. // Spawn the pet at the same location as the owner
  4334. pet->SetX(spawn->GetX());
  4335. pet->SetY(spawn->GetY());
  4336. pet->SetZ(spawn->GetZ());
  4337. pet->SetLocation(spawn->GetLocation());
  4338. pet->SetHeading(spawn->GetHeading());
  4339. spawn->GetZone()->AddSpawn(pet);
  4340. /*
  4341. const char* spawn_script = world.GetSpawnScript(pet_id);
  4342. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4343. spawn->SetSpawnScript(string(spawn_script));
  4344. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4345. }*/
  4346. // Get a random pet name
  4347. string random_pet_name;
  4348. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4349. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4350. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4351. // If player set various values for the char sheet (pet window)
  4352. if (spawn->IsPlayer()) {
  4353. Player* player = (Player*)spawn;
  4354. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  4355. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  4356. player->GetInfoStruct()->pet_movement = 2;
  4357. player->GetInfoStruct()->pet_behavior = 3;
  4358. player->GetInfoStruct()->pet_health_pct = 1.0f;
  4359. player->GetInfoStruct()->pet_power_pct = 1.0f;
  4360. // Make sure the values get sent to the client
  4361. player->SetCharSheetChanged(true);
  4362. }
  4363. // Set the pets name
  4364. pet->SetName(random_pet_name.c_str());
  4365. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4366. if (max_level > 0)
  4367. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4368. else
  4369. pet->SetLevel(spawn->GetLevel());
  4370. // Set the max level this pet can reach
  4371. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4372. // Set the faction of the pet to the same faction as the owner
  4373. pet->SetFactionID(spawn->GetFactionID());
  4374. // Set the spawn as a pet
  4375. pet->SetPet(true);
  4376. // Give a pointer of the owner to the pet
  4377. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4378. // Give a pointer of the pet to the owner
  4379. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4380. // Set the pet type
  4381. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4382. // Set the spell id used to create this pet
  4383. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4384. // Set the spell tier used to create this pet
  4385. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4386. // Set the pets spawn type to 6
  4387. pet->SetSpawnType(6);
  4388. // Set the pets brain
  4389. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4390. // Check to see if the pet has a subtitle
  4391. if (strlen(pet->GetSubTitle()) > 0) {
  4392. // Add the players name to the front of the sub title
  4393. string pet_subtitle;
  4394. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4395. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4396. // Set the pets subtitle to the new one
  4397. pet->SetSubTitle(pet_subtitle.c_str());
  4398. }
  4399. // Add the "Pet Options" entity command to the pet
  4400. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4401. // Set the pet as the return value for this function
  4402. lua_interface->SetSpawnValue(state, pet);
  4403. return 1;
  4404. }
  4405. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4406. if (!lua_interface)
  4407. return 0;
  4408. Spawn* spawn = lua_interface->GetSpawn(state);
  4409. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4410. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4411. if (!spawn) {
  4412. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4413. return 0;
  4414. }
  4415. if (!spawn->IsEntity()) {
  4416. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4417. return 0;
  4418. }
  4419. if (((Entity*)spawn)->GetDeityPet()) {
  4420. if (spawn->IsPlayer()) {
  4421. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4422. if (client)
  4423. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4424. }
  4425. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4426. return 0;
  4427. }
  4428. if (pet_id == 0) {
  4429. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4430. return 0;
  4431. }
  4432. if (!luaspell) {
  4433. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4434. return 0;
  4435. }
  4436. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4437. if (!pet) {
  4438. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4439. return 0;
  4440. }
  4441. if (!pet->IsNPC()) {
  4442. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4443. return 0;
  4444. }
  4445. pet->SetX(spawn->GetX());
  4446. pet->SetY(spawn->GetY());
  4447. pet->SetZ(spawn->GetZ());
  4448. pet->SetLocation(spawn->GetLocation());
  4449. pet->SetHeading(spawn->GetHeading());
  4450. spawn->GetZone()->AddSpawn(pet);
  4451. string random_pet_name;
  4452. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4453. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4454. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4455. pet->SetName(random_pet_name.c_str());
  4456. pet->SetLevel(spawn->GetLevel());
  4457. pet->SetFactionID(spawn->GetFactionID());
  4458. pet->SetPet(true);
  4459. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4460. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4461. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4462. pet->SetSpawnType(6);
  4463. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4464. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4465. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4466. if (strlen(pet->GetSubTitle()) > 0) {
  4467. string pet_subtitle;
  4468. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4469. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4470. pet->SetSubTitle(pet_subtitle.c_str());
  4471. }
  4472. // deity and cosmetic pets are not attackable
  4473. pet->SetAttackable(false);
  4474. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4475. lua_interface->SetSpawnValue(state, pet);
  4476. return 1;
  4477. }
  4478. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4479. if (!lua_interface)
  4480. return 0;
  4481. Spawn* spawn = lua_interface->GetSpawn(state);
  4482. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4483. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4484. if (!spawn) {
  4485. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4486. return 0;
  4487. }
  4488. if (!spawn->IsEntity()) {
  4489. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4490. return 0;
  4491. }
  4492. if (((Entity*)spawn)->GetCosmeticPet()) {
  4493. if (spawn->IsPlayer()) {
  4494. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4495. if (client)
  4496. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4497. }
  4498. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4499. return 0;
  4500. }
  4501. if (pet_id == 0) {
  4502. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4503. return 0;
  4504. }
  4505. if (!luaspell) {
  4506. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4507. return 0;
  4508. }
  4509. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4510. if (!pet) {
  4511. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4512. return 0;
  4513. }
  4514. if (!pet->IsNPC()) {
  4515. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4516. return 0;
  4517. }
  4518. pet->SetX(spawn->GetX());
  4519. pet->SetY(spawn->GetY());
  4520. pet->SetZ(spawn->GetZ());
  4521. pet->SetLocation(spawn->GetLocation());
  4522. pet->SetHeading(spawn->GetHeading());
  4523. spawn->GetZone()->AddSpawn(pet);
  4524. string random_pet_name;
  4525. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4526. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4527. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4528. pet->SetName(random_pet_name.c_str());
  4529. pet->SetLevel(spawn->GetLevel());
  4530. pet->SetFactionID(spawn->GetFactionID());
  4531. pet->SetPet(true);
  4532. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4533. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4534. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4535. pet->SetSpawnType(6);
  4536. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4537. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4538. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4539. if (strlen(pet->GetSubTitle()) > 0) {
  4540. string pet_subtitle;
  4541. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4542. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4543. pet->SetSubTitle(pet_subtitle.c_str());
  4544. }
  4545. pet->SetAttackable(false);
  4546. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4547. lua_interface->SetSpawnValue(state, pet);
  4548. return 1;
  4549. }
  4550. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4551. if (!lua_interface)
  4552. return 0;
  4553. Spawn* spawn = lua_interface->GetSpawn(state);
  4554. if (!spawn) {
  4555. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4556. return 0;
  4557. }
  4558. if (!spawn->IsPet()) {
  4559. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4560. return 0;
  4561. }
  4562. if (!((NPC*)spawn)->IsDismissing())
  4563. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4564. return 0;
  4565. }
  4566. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4567. if (!lua_interface)
  4568. return 0;
  4569. Quest* quest = lua_interface->GetQuest(state);
  4570. if (!quest) {
  4571. 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));
  4572. return 0;
  4573. }
  4574. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4575. if (feather_color > 0)
  4576. quest->SetFeatherColor(feather_color);
  4577. return 0;
  4578. }
  4579. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4580. if (!lua_interface)
  4581. return 0;
  4582. Spawn* spawn = lua_interface->GetSpawn(state);
  4583. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4584. if (!spawn) {
  4585. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4586. return 0;
  4587. }
  4588. if (!spawn2) {
  4589. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4590. return 0;
  4591. }
  4592. spawn->RemoveSpawnAccess(spawn2);
  4593. return 0;
  4594. }
  4595. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4596. if (!lua_interface)
  4597. return 0;
  4598. ZoneServer* zone = lua_interface->GetZone(state);
  4599. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4600. if (!zone) {
  4601. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4602. return 0;
  4603. }
  4604. if (location_id == 0) {
  4605. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4606. return 0;
  4607. }
  4608. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4609. if (!location) {
  4610. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4611. return 0;
  4612. }
  4613. Spawn* spawn = 0;
  4614. if (location->entities[0]) {
  4615. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4616. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4617. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4618. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4619. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4620. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4621. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4622. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4623. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4624. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4625. if (spawn) {
  4626. const char* script = 0;
  4627. for (int x = 0; x < 3; x++) {
  4628. switch (x) {
  4629. case 0:
  4630. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4631. break;
  4632. case 1:
  4633. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4634. break;
  4635. case 2:
  4636. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4637. break;
  4638. }
  4639. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4640. spawn->SetSpawnScript(string(script));
  4641. break;
  4642. }
  4643. }
  4644. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4645. lua_interface->SetSpawnValue(state, spawn);
  4646. return 1;
  4647. }
  4648. else {
  4649. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4650. safe_delete(spawn);
  4651. }
  4652. }
  4653. return 0;
  4654. }
  4655. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4656. if (!lua_interface)
  4657. return 0;
  4658. Spawn* caster = lua_interface->GetSpawn(state);
  4659. Spawn* target = lua_interface->GetSpawn(state, 2);
  4660. int32 id = lua_interface->GetInt32Value(state, 3);
  4661. string command = lua_interface->GetStringValue(state, 4);
  4662. if (!caster) {
  4663. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4664. return 0;
  4665. }
  4666. if (!target) {
  4667. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4668. return 0;
  4669. }
  4670. if (!caster->IsPlayer()) {
  4671. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4672. return 0;
  4673. }
  4674. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4675. if (!entity_command) {
  4676. 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());
  4677. return 0;
  4678. }
  4679. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4680. if (!client) {
  4681. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4682. return 0;
  4683. }
  4684. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4685. return 0;
  4686. }
  4687. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4688. if (!lua_interface)
  4689. return 0;
  4690. Spawn* spawn = lua_interface->GetSpawn(state);
  4691. if (!spawn) {
  4692. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4693. return 0;
  4694. }
  4695. if (!spawn->IsNPC()) {
  4696. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4697. return 0;
  4698. }
  4699. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4700. return 0;
  4701. }
  4702. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4703. if (!lua_interface)
  4704. return 0;
  4705. Spawn* spawn = lua_interface->GetSpawn(state);
  4706. int16 tick = lua_interface->GetInt16Value(state, 2);
  4707. if (!spawn) {
  4708. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4709. return 0;
  4710. }
  4711. if (!spawn->IsNPC()) {
  4712. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4713. return 0;
  4714. }
  4715. if (tick < 20) {
  4716. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4717. return 0;
  4718. }
  4719. ((NPC*)spawn)->Brain()->SetTick(tick);
  4720. return 0;
  4721. }
  4722. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4723. if (!lua_interface)
  4724. return 0;
  4725. Spawn* spawn = lua_interface->GetSpawn(state);
  4726. Spawn* target = lua_interface->GetSpawn(state, 2);
  4727. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4728. if (!spawn) {
  4729. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4730. return 0;
  4731. }
  4732. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4733. spawn->SetFollowTarget(target, follow_distance);
  4734. return 0;
  4735. }
  4736. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4737. if (!lua_interface)
  4738. return 0;
  4739. Spawn* spawn = lua_interface->GetSpawn(state);
  4740. if (!spawn) {
  4741. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4742. return 0;
  4743. }
  4744. Spawn* target = spawn->GetFollowTarget();
  4745. if (target) {
  4746. lua_interface->SetSpawnValue(state, target);
  4747. return 1;
  4748. }
  4749. return 0;
  4750. }
  4751. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4752. if (!lua_interface)
  4753. return 0;
  4754. Spawn* spawn = lua_interface->GetSpawn(state);
  4755. if (!spawn) {
  4756. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4757. return 0;
  4758. }
  4759. if (spawn->following)
  4760. spawn->following = false;
  4761. else
  4762. spawn->following = true;
  4763. return 0;
  4764. }
  4765. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4766. if (!lua_interface)
  4767. return 0;
  4768. Spawn* spawn = lua_interface->GetSpawn(state);
  4769. if (!spawn) {
  4770. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4771. return 0;
  4772. }
  4773. lua_interface->SetBooleanValue(state, spawn->following);
  4774. return 1;
  4775. }
  4776. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4777. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4778. // I will attempt to explain how this function works for future refrence
  4779. // Fist lets make sure lua_interface is valid, if not return out
  4780. if (!lua_interface)
  4781. return 0;
  4782. // Next we grab the first 2 params same as we usually would
  4783. Spawn* spawn = lua_interface->GetSpawn(state);
  4784. string var = lua_interface->GetStringValue(state, 2);
  4785. // 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
  4786. // 1 = Spawn
  4787. // 2 = Zone
  4788. // 3 = Item
  4789. // 4 = Quest
  4790. // 5 = String
  4791. // 6 = nil (null)
  4792. int8 dataType = 0;
  4793. // Define pointers for each potential type
  4794. Spawn* spawnVal = 0;
  4795. ZoneServer* zone = 0;
  4796. Item* item = 0;
  4797. Quest* quest = 0;
  4798. string val;
  4799. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4800. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4801. // options window are also light user data be we do not handle those.
  4802. // We check with lua_islightuserdata(lua_State*, index)
  4803. if (lua_islightuserdata(state, 3)) {
  4804. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4805. // and convert it to LUAUserData*
  4806. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4807. // Check to make sure the data we got is valid, if not give an error
  4808. if (!data || !data->IsCorrectlyInitialized()) {
  4809. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4810. }
  4811. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4812. else if (data->IsSpawn()) {
  4813. spawnVal = data->spawn;
  4814. dataType = 1;
  4815. }
  4816. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4817. else if (data->IsZone()) {
  4818. zone = data->zone;
  4819. dataType = 2;
  4820. }
  4821. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4822. else if (data->IsItem()) {
  4823. item = data->item;
  4824. dataType = 3;
  4825. }
  4826. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4827. else if (data->IsQuest()) {
  4828. quest = data->quest;
  4829. dataType = 4;
  4830. }
  4831. }
  4832. // Wasn't light user data, check if it is nil(null)
  4833. else if (lua_isnil(state, 3)) {
  4834. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4835. dataType = 6;
  4836. }
  4837. // Wasn't light user data or nil (null), must be a string
  4838. else {
  4839. // Set the string and dataType variable
  4840. val = lua_interface->GetStringValue(state, 3);
  4841. dataType = 5;
  4842. }
  4843. // We now have all the params, lets check to make sure they are valid
  4844. if (!spawn) {
  4845. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4846. return 0;
  4847. }
  4848. if (var.length() == 0) {
  4849. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4850. return 0;
  4851. }
  4852. if (dataType == 0) {
  4853. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4854. return 0;
  4855. }
  4856. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4857. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4858. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4859. switch (dataType) {
  4860. case 1:
  4861. // 1 = Spawn
  4862. spawn->AddTempVariable(var, spawnVal);
  4863. break;
  4864. case 2:
  4865. // 2 = Zone
  4866. spawn->AddTempVariable(var, zone);
  4867. break;
  4868. case 3:
  4869. // 3 = Item
  4870. spawn->AddTempVariable(var, item);
  4871. break;
  4872. case 4:
  4873. // 4 = Quest
  4874. spawn->AddTempVariable(var, quest);
  4875. break;
  4876. case 5:
  4877. // 5 = String
  4878. spawn->AddTempVariable(var, val);
  4879. break;
  4880. case 6:
  4881. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4882. spawn->DeleteTempVariable(var);
  4883. break;
  4884. }
  4885. // And we are done so return out
  4886. return 0;
  4887. }
  4888. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4889. if (!lua_interface)
  4890. return 0;
  4891. Spawn* spawn = lua_interface->GetSpawn(state);
  4892. string var = lua_interface->GetStringValue(state, 2);
  4893. if (!spawn) {
  4894. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4895. return 0;
  4896. }
  4897. if (var.length() == 0) {
  4898. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4899. return 0;
  4900. }
  4901. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4902. int8 type = spawn->GetTempVariableType(var);
  4903. Spawn* spawn2 = 0;
  4904. ZoneServer* zone = 0;
  4905. Item* item = 0;
  4906. Quest* quest = 0;
  4907. // Set the lua function return value based on the type of data the variable contains
  4908. switch (type) {
  4909. case 1:
  4910. spawn2 = spawn->GetTempVariableSpawn(var);
  4911. if (!spawn2)
  4912. return 0;
  4913. lua_interface->SetSpawnValue(state, spawn2);
  4914. break;
  4915. case 2:
  4916. zone = spawn->GetTempVariableZone(var);
  4917. if (!zone)
  4918. return 0;
  4919. lua_interface->SetZoneValue(state, zone);
  4920. break;
  4921. case 3:
  4922. item = spawn->GetTempVariableItem(var);
  4923. if (!item)
  4924. return 0;
  4925. lua_interface->SetItemValue(state, item);
  4926. break;
  4927. case 4:
  4928. quest = spawn->GetTempVariableQuest(var);
  4929. if (!quest)
  4930. return 0;
  4931. lua_interface->SetQuestValue(state, quest);
  4932. break;
  4933. case 5:
  4934. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4935. break;
  4936. default:
  4937. // Not a valid type then the variable was not set so return out
  4938. return 0;
  4939. }
  4940. // Return value was set so return out
  4941. return 1;
  4942. }
  4943. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4944. {
  4945. if (!lua_interface)
  4946. return 0;
  4947. Quest* quest = lua_interface->GetQuest(state);
  4948. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4949. string description = lua_interface->GetStringValue(state, 3);
  4950. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4951. if (!quest) {
  4952. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4953. lua_interface->SetBooleanValue(state, false);
  4954. return 1;
  4955. }
  4956. if (!spawn) {
  4957. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4958. lua_interface->SetBooleanValue(state, false);
  4959. return 1;
  4960. }
  4961. if (!spawn->IsPlayer()) {
  4962. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4963. lua_interface->SetBooleanValue(state, false);
  4964. return 1;
  4965. }
  4966. if (item_id == 0) {
  4967. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4968. lua_interface->SetBooleanValue(state, false);
  4969. return 1;
  4970. }
  4971. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4972. if (!client) {
  4973. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4974. lua_interface->SetBooleanValue(state, false);
  4975. return 1;
  4976. }
  4977. Item* item = master_item_list.GetItem(item_id);
  4978. if (!item) {
  4979. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4980. lua_interface->SetBooleanValue(state, false);
  4981. return 1;
  4982. }
  4983. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4984. if (packet) {
  4985. packet->setDataByName("title", "Quest Reward!");
  4986. packet->setDataByName("name", quest->GetName());
  4987. packet->setDataByName("description", description.c_str());
  4988. packet->setDataByName("level", quest->GetLevel());
  4989. packet->setArrayLengthByName("num_rewards", 1);
  4990. packet->setArrayDataByName("reward_id", item->details.item_id);
  4991. if (client->GetVersion() < 860)
  4992. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4993. else if (client->GetVersion() < 1193)
  4994. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4995. else
  4996. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4997. client->QueuePacket(packet->serialize());
  4998. safe_delete(packet);
  4999. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  5000. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  5001. return 1;
  5002. }
  5003. lua_interface->SetBooleanValue(state, false);
  5004. return 1;
  5005. }
  5006. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5007. if (!lua_interface)
  5008. return 0;
  5009. Quest* quest = lua_interface->GetQuest(state);
  5010. if (!quest) {
  5011. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5012. return 0;
  5013. }
  5014. quest->SetRepeatable(true);
  5015. return 0;
  5016. }
  5017. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5018. if (!lua_interface)
  5019. return 0;
  5020. Spawn* spawn = lua_interface->GetSpawn(state);
  5021. if (!spawn) {
  5022. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5026. string ret = classes.GetClassNameCase(base_class);
  5027. if (ret.length() > 0) {
  5028. lua_interface->SetStringValue(state, ret.c_str());
  5029. return 1;
  5030. }
  5031. return 0;
  5032. }
  5033. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5034. if (!lua_interface)
  5035. return 0;
  5036. Spawn* player = lua_interface->GetSpawn(state);
  5037. if (player && player->IsPlayer()) {
  5038. Client* client = player->GetClient();
  5039. if (client)
  5040. client->SendWaypoints();
  5041. }
  5042. return 0;
  5043. }
  5044. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5045. if (!lua_interface)
  5046. return 0;
  5047. Spawn* player = lua_interface->GetSpawn(state);
  5048. string name = lua_interface->GetStringValue(state, 2);
  5049. int32 type = lua_interface->GetInt32Value(state, 3);
  5050. if (type == 0)
  5051. type = 2;
  5052. if (name.length() > 0) {
  5053. if (player && player->IsPlayer()) {
  5054. Client* client = player->GetClient();
  5055. if (client)
  5056. client->AddWaypoint(name, type);
  5057. }
  5058. }
  5059. return 0;
  5060. }
  5061. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5062. if (!lua_interface)
  5063. return 0;
  5064. Spawn* player = lua_interface->GetSpawn(state);
  5065. string name = lua_interface->GetStringValue(state, 2);
  5066. if (name.length() > 0) {
  5067. if (player && player->IsPlayer()) {
  5068. Client* client = player->GetClient();
  5069. if (client)
  5070. client->RemoveWaypoint(name);
  5071. }
  5072. }
  5073. return 0;
  5074. }
  5075. int EQ2Emu_lua_AddWard(lua_State* state) {
  5076. if (!lua_interface)
  5077. return 0;
  5078. int32 damage = lua_interface->GetInt32Value(state);
  5079. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5080. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5081. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5082. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5083. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5084. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5085. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5086. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5087. bool ward_was_added = false;
  5088. ZoneServer* zone = spell->caster->GetZone();
  5089. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5090. for (int32 i = 0; i < spell->targets.size(); i++) {
  5091. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5092. if (!target)
  5093. continue;
  5094. if (target->IsEntity()) {
  5095. // If the ward is already active remove it
  5096. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5097. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5098. // Create new ward info
  5099. WardInfo* ward = new WardInfo;
  5100. ward->Spell = spell;
  5101. ward->BaseDamage = damage;
  5102. ward->DamageLeft = damage;
  5103. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5104. ward->keepWard = keepWard;
  5105. ward->WardType = wardType;
  5106. if (damageAbsorptionPercent > 100)
  5107. damageAbsorptionPercent = 100;
  5108. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5109. if (damageAbsorptionMaxHealthPercent > 100)
  5110. damageAbsorptionMaxHealthPercent = 100;
  5111. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5112. ward->RedirectDamagePercent = redirectDamagePercent;
  5113. ward->LastRedirectDamage = 0;
  5114. ward->LastAbsorbedDamage = 0;
  5115. ward->HitCount = 0;
  5116. spell->num_triggers = maxHitCount;
  5117. spell->had_triggers = true;
  5118. spell->cancel_after_all_triggers = false;
  5119. ward->MaxHitCount = maxHitCount;
  5120. if (wardType == WARD_TYPE_MAGICAL)
  5121. ward->DamageType = damageTypes;
  5122. // Add the ward to the entity
  5123. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5124. ward_was_added = true;
  5125. }
  5126. }
  5127. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5128. if (ward_was_added && spell->caster->IsPlayer()) {
  5129. spell->had_dmg_remaining = true;
  5130. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5131. }
  5132. return 0;
  5133. }
  5134. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5135. if (!lua_interface)
  5136. return 0;
  5137. int32 amount = lua_interface->GetInt32Value(state);
  5138. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5139. WardInfo* ward = 0;
  5140. ZoneServer* zone = spell->caster->GetZone();
  5141. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5142. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5143. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5144. ward = target->GetWard(spell->spell->GetSpellID());
  5145. if (ward) {
  5146. ward->DamageLeft += amount;
  5147. if (ward->DamageLeft > ward->BaseDamage)
  5148. ward->DamageLeft = ward->BaseDamage;
  5149. for (int32 i = 0; i < spell->targets.size(); i++) {
  5150. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5151. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5152. }
  5153. }
  5154. }
  5155. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5156. if (ward && spell->caster->IsPlayer())
  5157. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5158. return 0;
  5159. }
  5160. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5161. if (!lua_interface)
  5162. return 0;
  5163. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5164. if (!spell) {
  5165. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5166. return 0;
  5167. }
  5168. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5169. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5170. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5171. if (ward) {
  5172. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5173. return 1;
  5174. }
  5175. }
  5176. return 0;
  5177. }
  5178. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5179. if (!lua_interface)
  5180. return 0;
  5181. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5182. if (!spell) {
  5183. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5184. return 0;
  5185. }
  5186. string type = lua_interface->GetStringValue(state, 2);
  5187. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5188. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5189. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5190. if (ward) {
  5191. if (boost::iequals(type, "damageleft"))
  5192. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5193. else if (boost::iequals(type, "basedamage"))
  5194. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5195. else if (boost::iequals(type, "keepward"))
  5196. lua_interface->SetBooleanValue(state, ward->keepWard);
  5197. else if (boost::iequals(type, "wardtype"))
  5198. lua_interface->SetInt32Value(state, ward->WardType);
  5199. else if (boost::iequals(type, "dmgabsorptionpct"))
  5200. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5201. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5202. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5203. else if (boost::iequals(type, "redirectdamagepercent"))
  5204. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5205. else if (boost::iequals(type, "lastredirectdamage"))
  5206. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5207. else if (boost::iequals(type, "lastabsorbeddamage"))
  5208. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5209. else if (boost::iequals(type, "hitcount"))
  5210. lua_interface->SetInt32Value(state, ward->HitCount);
  5211. else if (boost::iequals(type, "maxhitcount"))
  5212. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5213. else
  5214. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5215. return 1;
  5216. }
  5217. }
  5218. return 0;
  5219. }
  5220. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5221. if (!lua_interface)
  5222. return 0;
  5223. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5224. ZoneServer* zone = spell->caster->GetZone();
  5225. Spawn* target = 0;
  5226. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5227. for (int32 i = 0; i < spell->targets.size(); i++) {
  5228. target = zone->GetSpawnByID(spell->targets.at(i));
  5229. if (target && target->IsEntity()) {
  5230. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5231. }
  5232. }
  5233. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5234. return 0;
  5235. }
  5236. int EQ2Emu_lua_Interrupt(lua_State* state)
  5237. {
  5238. if (!lua_interface)
  5239. return 0;
  5240. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5241. Spawn* target = lua_interface->GetSpawn(state, 2);
  5242. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5243. if (!caster)
  5244. {
  5245. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5246. return 0;
  5247. }
  5248. if (!target)
  5249. {
  5250. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5251. return 0;
  5252. }
  5253. if (!spell) {
  5254. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5255. return 0;
  5256. }
  5257. if (!target->IsEntity() && !spell)
  5258. {
  5259. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5260. return 0;
  5261. }
  5262. if (!target && spell) {
  5263. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5264. for (int8 i = 0; i < spell->targets.size(); i++) {
  5265. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5266. if (!target || !target->IsEntity())
  5267. continue;
  5268. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5269. }
  5270. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5271. }
  5272. else
  5273. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5274. return 0;
  5275. }
  5276. int EQ2Emu_lua_Stealth(lua_State* state) {
  5277. if (!lua_interface)
  5278. return 0;
  5279. int8 type = lua_interface->GetInt8Value(state);
  5280. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5281. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5282. if (!spell) {
  5283. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5284. return 0;
  5285. }
  5286. ZoneServer* zone = spell->caster->GetZone();
  5287. if (spawn) {
  5288. if (spawn->IsEntity()) {
  5289. if (type == 1) {
  5290. ((Entity*)spawn)->AddStealthSpell(spell);
  5291. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5292. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5293. }
  5294. else if (type == 2) {
  5295. ((Entity*)spawn)->AddInvisSpell(spell);
  5296. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5297. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5298. }
  5299. return 0;
  5300. }
  5301. else {
  5302. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5303. return 0;
  5304. }
  5305. }
  5306. else {
  5307. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5308. for (int32 i = 0; i < spell->targets.size(); i++) {
  5309. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5310. if (!spawn || !spawn->IsEntity())
  5311. continue;
  5312. if (type == 1) {
  5313. ((Entity*)spawn)->AddStealthSpell(spell);
  5314. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5315. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5316. }
  5317. else if (type == 2) {
  5318. ((Entity*)spawn)->AddInvisSpell(spell);
  5319. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5320. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5321. }
  5322. else {
  5323. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5324. break;
  5325. }
  5326. }
  5327. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5328. }
  5329. return 0;
  5330. }
  5331. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5332. if (!lua_interface)
  5333. return 0;
  5334. Spawn* spawn = lua_interface->GetSpawn(state);
  5335. if (!spawn) {
  5336. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5337. return 0;
  5338. }
  5339. if (spawn->IsEntity()) {
  5340. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5341. return 1;
  5342. }
  5343. else
  5344. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5345. return 0;
  5346. }
  5347. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5348. if (!lua_interface)
  5349. return 0;
  5350. Spawn* spawn = lua_interface->GetSpawn(state);
  5351. if (!spawn) {
  5352. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5353. return 0;
  5354. }
  5355. if (spawn->IsEntity()) {
  5356. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5357. return 1;
  5358. }
  5359. else
  5360. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5361. return 0;
  5362. }
  5363. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5364. if (!lua_interface)
  5365. return 0;
  5366. Spawn* player = lua_interface->GetSpawn(state);
  5367. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5368. if (!player->IsPlayer()) {
  5369. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5370. return 0;
  5371. }
  5372. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5373. return 1;
  5374. }
  5375. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5376. if (!lua_interface)
  5377. return 0;
  5378. Spawn* player = lua_interface->GetSpawn(state);
  5379. int8 slot = lua_interface->GetInt8Value(state, 2);
  5380. if (!player) {
  5381. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5382. return 0;
  5383. }
  5384. if (!player->IsPlayer()) {
  5385. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5386. return 0;
  5387. }
  5388. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5389. if (!item) {
  5390. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5391. return 0;
  5392. }
  5393. lua_interface->SetItemValue(state, item);
  5394. return 1;
  5395. }
  5396. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5397. if (!lua_interface)
  5398. return 0;
  5399. Spawn* player = lua_interface->GetSpawn(state);
  5400. int32 id = lua_interface->GetInt32Value(state, 2);
  5401. if (!player) {
  5402. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5403. return 0;
  5404. }
  5405. if (!player->IsPlayer()) {
  5406. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5407. return 0;
  5408. }
  5409. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5410. if (!item) {
  5411. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5412. return 0;
  5413. }
  5414. lua_interface->SetItemValue(state, item);
  5415. return 1;
  5416. }
  5417. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5418. if (!lua_interface)
  5419. return 0;
  5420. Spawn* player = lua_interface->GetSpawn(state);
  5421. int32 id = lua_interface->GetInt32Value(state, 2);
  5422. int8 count = lua_interface->GetInt8Value(state, 3);
  5423. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5424. if (!player) {
  5425. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5426. return 0;
  5427. }
  5428. if (!player->IsPlayer()) {
  5429. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5430. return 0;
  5431. }
  5432. if (!count)
  5433. count = 1;
  5434. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5435. if (!item) {
  5436. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5437. return 0;
  5438. }
  5439. lua_interface->SetItemValue(state, item);
  5440. return 1;
  5441. }
  5442. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5443. if (!lua_interface)
  5444. return 0;
  5445. Spawn* spawn = lua_interface->GetSpawn(state);
  5446. int32 anim = lua_interface->GetInt32Value(state, 2);
  5447. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5448. int8 type = lua_interface->GetInt8Value(state, 4);
  5449. if (!spawn) {
  5450. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5451. return 0;
  5452. }
  5453. if (spawn2) {
  5454. if (spawn2->IsPlayer()) {
  5455. if (type != 1 && type != 2)
  5456. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5457. else
  5458. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5459. return 0;
  5460. }
  5461. else {
  5462. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5463. return 0;
  5464. }
  5465. }
  5466. else
  5467. spawn->GetZone()->PlayAnimation(spawn, anim);
  5468. return 0;
  5469. }
  5470. int EQ2Emu_lua_IsPet(lua_State* state) {
  5471. if (!lua_interface)
  5472. return 0;
  5473. Spawn* spawn = lua_interface->GetSpawn(state);
  5474. if (!spawn) {
  5475. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5476. return 0;
  5477. }
  5478. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5479. return 1;
  5480. }
  5481. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5482. if (!lua_interface)
  5483. return 0;
  5484. Spawn* spawn = lua_interface->GetSpawn(state);
  5485. if (!spawn) {
  5486. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5487. return 0;
  5488. }
  5489. if (!spawn->IsNPC()) {
  5490. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5491. return 0;
  5492. }
  5493. if (((NPC*)spawn)->GetOwner()) {
  5494. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5495. return 1;
  5496. }
  5497. return 0;
  5498. }
  5499. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5500. if (!lua_interface)
  5501. return 0;
  5502. Spawn* spawn = lua_interface->GetSpawn(state);
  5503. Spawn* target = lua_interface->GetSpawn(state, 2);
  5504. if (!spawn) {
  5505. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5506. return 0;
  5507. }
  5508. if (!spawn) {
  5509. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5510. return 0;
  5511. }
  5512. spawn->SetTarget(target);
  5513. return 0;
  5514. }
  5515. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5516. if (!lua_interface)
  5517. return 0;
  5518. Spawn* spawn = lua_interface->GetSpawn(state);
  5519. bool val = lua_interface->GetBooleanValue(state, 2);
  5520. if (!spawn) {
  5521. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5522. return 0;
  5523. }
  5524. if (!spawn->IsEntity()) {
  5525. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5526. return 0;
  5527. }
  5528. ((Entity*)spawn)->InCombat(val);
  5529. if (val) {
  5530. spawn->ClearRunningLocations();
  5531. spawn->CalculateRunningLocation(true);
  5532. }
  5533. return 0;
  5534. }
  5535. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5536. if (!lua_interface)
  5537. return 0;
  5538. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5539. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5540. if (!spawn1) {
  5541. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5542. return 0;
  5543. }
  5544. if (!spawn2) {
  5545. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5546. return 0;
  5547. }
  5548. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5549. return 1;
  5550. }
  5551. int EQ2Emu_lua_Runback(lua_State* state) {
  5552. if (!lua_interface)
  5553. return 0;
  5554. Spawn* spawn = lua_interface->GetSpawn(state);
  5555. if (!spawn) {
  5556. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5557. return 0;
  5558. }
  5559. if (!spawn->IsNPC()) {
  5560. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5561. return 0;
  5562. }
  5563. ((NPC*)spawn)->Runback();
  5564. return 0;
  5565. }
  5566. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5567. if (!lua_interface)
  5568. return 0;
  5569. Spawn* spawn = lua_interface->GetSpawn(state);
  5570. if (!spawn) {
  5571. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5572. return 0;
  5573. }
  5574. if (!spawn->IsNPC()) {
  5575. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5576. return 0;
  5577. }
  5578. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5579. return 1;
  5580. }
  5581. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5582. if (!lua_interface)
  5583. return 0;
  5584. Spawn* spawn = lua_interface->GetSpawn(state);
  5585. if (!spawn) {
  5586. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5587. return 0;
  5588. }
  5589. if (!spawn->IsEntity()) {
  5590. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5591. return 0;
  5592. }
  5593. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5594. return 1;
  5595. }
  5596. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5597. if (!lua_interface)
  5598. return 0;
  5599. Spawn* spawn = lua_interface->GetSpawn(state);
  5600. if (!spawn) {
  5601. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5602. return 0;
  5603. }
  5604. if (!spawn->IsEntity()) {
  5605. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5606. return 0;
  5607. }
  5608. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5609. return 1;
  5610. }
  5611. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5612. if (!lua_interface)
  5613. return 0;
  5614. Spawn* spawn = lua_interface->GetSpawn(state);
  5615. if (!spawn) {
  5616. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5617. return 0;
  5618. }
  5619. if (!spawn->IsEntity()) {
  5620. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5621. return 0;
  5622. }
  5623. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5624. return 1;
  5625. }
  5626. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5627. if (!lua_interface)
  5628. return 0;
  5629. Spawn* spawn = lua_interface->GetSpawn(state);
  5630. if (!spawn) {
  5631. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5632. return 0;
  5633. }
  5634. if (!spawn->IsEntity()) {
  5635. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5636. return 0;
  5637. }
  5638. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5639. return 1;
  5640. }
  5641. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5642. if (!lua_interface)
  5643. return 0;
  5644. Spawn* spawn = lua_interface->GetSpawn(state);
  5645. Spawn* target = lua_interface->GetSpawn(state, 2);
  5646. float distance = lua_interface->GetFloatValue(state, 3);
  5647. if (!spawn) {
  5648. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5649. return 0;
  5650. }
  5651. if (!target) {
  5652. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5653. return 0;
  5654. }
  5655. if (!spawn->IsNPC()) {
  5656. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5657. return 0;
  5658. }
  5659. if (!target->IsEntity()) {
  5660. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5661. return 0;
  5662. }
  5663. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5664. return 1;
  5665. }
  5666. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5667. if (!lua_interface)
  5668. return 0;
  5669. Spawn* spawn = lua_interface->GetSpawn(state);
  5670. Spawn* target = lua_interface->GetSpawn(state, 2);
  5671. float distance = lua_interface->GetFloatValue(state, 3);
  5672. if (!spawn) {
  5673. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5674. return 0;
  5675. }
  5676. if (!target) {
  5677. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5678. return 0;
  5679. }
  5680. if (!spawn->IsNPC()) {
  5681. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5682. return 0;
  5683. }
  5684. if (!target->IsEntity()) {
  5685. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5686. return 0;
  5687. }
  5688. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5689. return 0;
  5690. }
  5691. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5692. if (!lua_interface)
  5693. return 0;
  5694. Spawn* spawn = lua_interface->GetSpawn(state);
  5695. if (!spawn) {
  5696. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5697. return 0;
  5698. }
  5699. if (!spawn->IsNPC()) {
  5700. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5701. return 0;
  5702. }
  5703. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5704. return 1;
  5705. }
  5706. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5707. if (!lua_interface)
  5708. return 0;
  5709. Spawn* spawn = lua_interface->GetSpawn(state);
  5710. if (!spawn) {
  5711. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5712. return 0;
  5713. }
  5714. if (!spawn->IsNPC()) {
  5715. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5716. return 0;
  5717. }
  5718. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5719. return 1;
  5720. }
  5721. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5722. if (!lua_interface)
  5723. return 0;
  5724. Spawn* spawn = lua_interface->GetSpawn(state);
  5725. if (!spawn) {
  5726. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5727. return 0;
  5728. }
  5729. if (!spawn->IsNPC()) {
  5730. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5731. return 0;
  5732. }
  5733. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5734. if (hated) {
  5735. lua_interface->SetSpawnValue(state, hated);
  5736. return 1;
  5737. }
  5738. return 0;
  5739. }
  5740. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5741. if (!lua_interface)
  5742. return 0;
  5743. Spawn* spawn = lua_interface->GetSpawn(state);
  5744. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5745. if (!spawn) {
  5746. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5747. return 0;
  5748. }
  5749. if (!spawn->IsNPC()) {
  5750. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5751. return 0;
  5752. }
  5753. if (!hated) {
  5754. ((NPC*)spawn)->Brain()->ClearHate();
  5755. return 0;
  5756. }
  5757. else
  5758. {
  5759. if (!hated->IsEntity()) {
  5760. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5761. return 0;
  5762. }
  5763. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5764. return 0;
  5765. }
  5766. return 0;
  5767. }
  5768. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5769. if (!lua_interface)
  5770. return 0;
  5771. Spawn* spawn = lua_interface->GetSpawn(state);
  5772. if (!spawn) {
  5773. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5774. return 0;
  5775. }
  5776. if (!spawn->IsNPC()) {
  5777. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. ((NPC*)spawn)->Brain()->ClearEncounter();
  5781. return 0;
  5782. }
  5783. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5784. if (!lua_interface)
  5785. return 0;
  5786. Spawn* spawn = lua_interface->GetSpawn(state);
  5787. if (!spawn) {
  5788. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5789. return 0;
  5790. }
  5791. if (!spawn->IsNPC()) {
  5792. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5793. return 0;
  5794. }
  5795. // Temp list to store hate list
  5796. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5797. if (encounterList->size() == 0) {
  5798. safe_delete(encounterList);
  5799. return 0;
  5800. }
  5801. lua_createtable(state, encounterList->size(), 0);
  5802. int newTable = lua_gettop(state);
  5803. for (int32 i = 0; i < encounterList->size(); i++) {
  5804. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5805. if (temp)
  5806. lua_interface->SetSpawnValue(state, temp);
  5807. lua_rawseti(state, newTable, i + 1);
  5808. }
  5809. safe_delete(encounterList);
  5810. return 1;
  5811. }
  5812. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5813. if (!lua_interface)
  5814. return 0;
  5815. Spawn* spawn = lua_interface->GetSpawn(state);
  5816. if (!spawn) {
  5817. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5818. return 0;
  5819. }
  5820. if (!spawn->IsNPC()) {
  5821. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5822. return 0;
  5823. }
  5824. // Temp list to store hate list
  5825. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5826. if (hateList->size() == 0) {
  5827. safe_delete(hateList);
  5828. return 0;
  5829. }
  5830. lua_createtable(state, hateList->size(), 0);
  5831. int newTable = lua_gettop(state);
  5832. for (int32 i = 0; i < hateList->size(); i++) {
  5833. lua_interface->SetSpawnValue(state, hateList->at(i));
  5834. lua_rawseti(state, newTable, i + 1);
  5835. }
  5836. safe_delete(hateList);
  5837. return 1;
  5838. }
  5839. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5840. if (!lua_interface)
  5841. return 0;
  5842. Spawn* spawn = lua_interface->GetSpawn(state);
  5843. if (!spawn) {
  5844. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5845. return 0;
  5846. }
  5847. if (spawn->IsPlayer()) {
  5848. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5849. lua_interface->SetBooleanValue(state, true);
  5850. else
  5851. lua_interface->SetBooleanValue(state, false);
  5852. return 1;
  5853. }
  5854. else {
  5855. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5856. return 1;
  5857. }
  5858. }
  5859. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5860. if (!lua_interface)
  5861. return 0;
  5862. Quest* quest = lua_interface->GetQuest(state);
  5863. if (!quest) {
  5864. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5865. return 0;
  5866. }
  5867. quest->SetCompletedFlag(true);
  5868. return 0;
  5869. }
  5870. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5871. if (!lua_interface)
  5872. return 0;
  5873. Spawn* spawn = lua_interface->GetSpawn(state);
  5874. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5875. int8 tier = lua_interface->GetInt8Value(state, 3);
  5876. if (!spawn) {
  5877. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5878. return 0;
  5879. }
  5880. if (!spawn->IsEntity()) {
  5881. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5882. return 0;
  5883. }
  5884. if (spellID == 0) {
  5885. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5886. return 0;
  5887. }
  5888. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5889. if (effect) {
  5890. if (tier > 0) {
  5891. // If a tier was passed chec to see if it is the same as the effect
  5892. if (tier == effect->tier)
  5893. lua_interface->SetBooleanValue(state, true);
  5894. else
  5895. lua_interface->SetBooleanValue(state, false);
  5896. return 1;
  5897. }
  5898. else {
  5899. // Have an effect but no tier was passed so return true
  5900. lua_interface->SetBooleanValue(state, true);
  5901. }
  5902. return 1;
  5903. }
  5904. // no effect so return false
  5905. lua_interface->SetBooleanValue(state, false);
  5906. return 1;
  5907. }
  5908. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5909. if (!lua_interface)
  5910. return 0;
  5911. Spawn* spawn = lua_interface->GetSpawn(state);
  5912. int32 id = lua_interface->GetInt32Value(state, 2);
  5913. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5914. Spawn* spawn2 = 0;
  5915. vector<Spawn*> list;
  5916. if (!spawn) {
  5917. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5918. return 0;
  5919. }
  5920. //If zone not provided, use spawn's zone
  5921. if (!zone)
  5922. zone = spawn->GetZone();
  5923. list = zone->GetSpawnsByID(id);
  5924. if (list.size() == 0) {
  5925. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5926. return 0;
  5927. }
  5928. vector<Spawn*>::iterator itr = list.begin();
  5929. for (int8 i = 0; i < list.size(); i++) {
  5930. spawn2 = itr[i];
  5931. if (spawn2)
  5932. spawn2->AddAllowAccessSpawn(spawn);
  5933. }
  5934. return 0;
  5935. }
  5936. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5937. if (!lua_interface)
  5938. return 0;
  5939. Spawn* spawn = lua_interface->GetSpawn(state);
  5940. int32 id = lua_interface->GetInt32Value(state, 2);
  5941. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5942. Spawn* spawn2 = 0;
  5943. if (!spawn) {
  5944. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5945. return 0;
  5946. }
  5947. //If zone not provided, use spawn's zone
  5948. if (!zone)
  5949. zone = spawn->GetZone();
  5950. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5951. vector<Spawn*>::iterator itr = list.begin();
  5952. if (list.size() == 0) {
  5953. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5954. return 0;
  5955. }
  5956. for (int8 i = 0; i < list.size(); i++) {
  5957. spawn2 = itr[i];
  5958. if (spawn2)
  5959. spawn2->RemoveSpawnAccess(spawn);
  5960. }
  5961. return 0;
  5962. }
  5963. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5964. if (!lua_interface)
  5965. return 0;
  5966. Quest* quest = lua_interface->GetQuest(state);
  5967. if (!quest) {
  5968. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5969. return 0;
  5970. }
  5971. quest->SetYellowName(true);
  5972. return 0;
  5973. }
  5974. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5975. if (!lua_interface)
  5976. return 0;
  5977. Spawn* spawn = lua_interface->GetSpawn(state);
  5978. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5979. if (!spawn) {
  5980. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5981. return 0;
  5982. }
  5983. if (!spawn->IsPlayer()) {
  5984. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5985. return 0;
  5986. }
  5987. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5988. return 1;
  5989. }
  5990. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5991. if (!lua_interface)
  5992. return 0;
  5993. Spawn* spawn = lua_interface->GetSpawn(state);
  5994. if (!spawn) {
  5995. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5996. return 0;
  5997. }
  5998. if (!spawn->IsPlayer()) {
  5999. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6000. return 0;
  6001. }
  6002. ZoneServer* zone = spawn->GetZone();
  6003. if (!zone) {
  6004. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6005. return 0;
  6006. }
  6007. Instance_Type iType = zone->GetInstanceType();
  6008. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6009. iType == GROUP_LOCKOUT_INSTANCE ||
  6010. iType == RAID_LOCKOUT_INSTANCE ||
  6011. iType == SOLO_PERSIST_INSTANCE ||
  6012. iType == GROUP_PERSIST_INSTANCE ||
  6013. iType == RAID_PERSIST_INSTANCE) {
  6014. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6015. if (data) {
  6016. // Check to see if the timer has already been set, if it has return out.
  6017. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6018. return 0;
  6019. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6020. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6021. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6022. if (client) {
  6023. string time_msg = "";
  6024. int32 time = data->success_lockout_time;
  6025. int16 hour;
  6026. int8 min;
  6027. int8 sec;
  6028. hour = time / 3600;
  6029. time = time % 3600;
  6030. min = time / 60;
  6031. time = time % 60;
  6032. sec = time;
  6033. if (hour > 0) {
  6034. char temp[10];
  6035. sprintf(temp, " %i", hour);
  6036. time_msg.append(temp);
  6037. time_msg.append(" hour");
  6038. time_msg.append((hour > 1) ? "s" : "");
  6039. }
  6040. if (min > 0) {
  6041. char temp[5];
  6042. sprintf(temp, " %i", min);
  6043. time_msg.append(temp);
  6044. time_msg.append(" minute");
  6045. time_msg.append((min > 1) ? "s" : "");
  6046. }
  6047. // Only add seconds if minutes and hours are 0
  6048. if (hour == 0 && min == 0 && sec > 0) {
  6049. char temp[5];
  6050. sprintf(temp, " %i", sec);
  6051. time_msg.append(temp);
  6052. time_msg.append(" second");
  6053. time_msg.append((sec > 1) ? "s" : "");
  6054. }
  6055. 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());
  6056. }
  6057. }
  6058. else
  6059. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6060. }
  6061. else
  6062. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6063. return 0;
  6064. }
  6065. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6066. if (!lua_interface)
  6067. return 0;
  6068. Spawn* spawn = lua_interface->GetSpawn(state);
  6069. if (!spawn) {
  6070. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6071. return 0;
  6072. }
  6073. if (!spawn->IsPlayer()) {
  6074. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6075. return 0;
  6076. }
  6077. ZoneServer* zone = spawn->GetZone();
  6078. if (!zone) {
  6079. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6080. return 0;
  6081. }
  6082. Instance_Type iType = zone->GetInstanceType();
  6083. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6084. iType == GROUP_LOCKOUT_INSTANCE ||
  6085. iType == RAID_LOCKOUT_INSTANCE ||
  6086. iType == SOLO_PERSIST_INSTANCE ||
  6087. iType == GROUP_PERSIST_INSTANCE ||
  6088. iType == RAID_PERSIST_INSTANCE) {
  6089. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6090. if (data) {
  6091. // Check to see if the timer has already been set, if it has return out.
  6092. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6093. return 0;
  6094. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6095. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6096. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6097. if (client) {
  6098. string time_msg = "";
  6099. int32 time = data->failure_lockout_time;
  6100. int16 hour;
  6101. int8 min;
  6102. int8 sec;
  6103. hour = time / 3600;
  6104. time = time % 3600;
  6105. min = time / 60;
  6106. time = time % 60;
  6107. sec = time;
  6108. if (hour > 0) {
  6109. char temp[10];
  6110. sprintf(temp, " %i", hour);
  6111. time_msg.append(temp);
  6112. time_msg.append(" hour");
  6113. time_msg.append((hour > 1) ? "s" : "");
  6114. }
  6115. if (min > 0) {
  6116. char temp[5];
  6117. sprintf(temp, " %i", min);
  6118. time_msg.append(temp);
  6119. time_msg.append(" minute");
  6120. time_msg.append((min > 1) ? "s" : "");
  6121. }
  6122. // Only add seconds if minutes and hours are 0
  6123. if (hour == 0 && min == 0 && sec > 0) {
  6124. char temp[5];
  6125. sprintf(temp, " %i", sec);
  6126. time_msg.append(temp);
  6127. time_msg.append(" second");
  6128. time_msg.append((sec > 1) ? "s" : "");
  6129. }
  6130. 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());
  6131. }
  6132. }
  6133. else
  6134. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6135. }
  6136. else
  6137. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6138. return 0;
  6139. }
  6140. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6141. if (!lua_interface)
  6142. return 0;
  6143. Spawn* spawn = lua_interface->GetSpawn(state);
  6144. if (!spawn) {
  6145. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6146. return 0;
  6147. }
  6148. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6149. return 1;
  6150. }
  6151. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6152. if (!lua_interface)
  6153. return 0;
  6154. Spawn* player = lua_interface->GetSpawn(state);
  6155. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6156. if (!player) {
  6157. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6158. return 0;
  6159. }
  6160. if (!player->IsPlayer()) {
  6161. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. if (!ground) {
  6165. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. if (!ground->IsGroundSpawn()) {
  6169. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6170. return 0;
  6171. }
  6172. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6173. if (!groundspawn_entries) {
  6174. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6175. return 0;
  6176. }
  6177. Skill* skill = 0;
  6178. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6179. if (collection_skill == "Collecting")
  6180. skill = ((Player*)player)->GetSkillByName("Gathering");
  6181. else
  6182. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6183. if (!skill) {
  6184. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6185. return 0;
  6186. }
  6187. vector<GroundSpawnEntry*>::iterator itr;
  6188. GroundSpawnEntry* entry = 0;
  6189. bool can_harvest = false;
  6190. sint32 min_skill = -1;
  6191. // first, iterate through groundspawn_entries, discard tables player cannot use
  6192. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6193. {
  6194. entry = *itr;
  6195. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6196. min_skill = entry->min_skill_level;
  6197. // if player lacks skill, skip table
  6198. if (entry->min_skill_level > skill->current_val)
  6199. continue;
  6200. // if bonus, but player lacks level, skip table
  6201. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6202. continue;
  6203. can_harvest = true;
  6204. break;
  6205. }
  6206. lua_interface->SetBooleanValue(state, can_harvest);
  6207. // If false, send the message to the client
  6208. if (!can_harvest) {
  6209. Client* client = player->GetZone()->GetClientBySpawn(player);
  6210. if (client) {
  6211. string msg = "You do not have enough skill to ";
  6212. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6213. msg.append("gather");
  6214. else if (collection_skill == "Mining")
  6215. msg.append("mine");
  6216. else if (collection_skill == "Trapping")
  6217. msg.append("trap");
  6218. else if (collection_skill == "Foresting")
  6219. msg.append("forest");
  6220. else if (collection_skill == "Fishing")
  6221. msg.append("catch");
  6222. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6223. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  6224. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6225. }
  6226. }
  6227. return 1;
  6228. }
  6229. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6230. if (!lua_interface)
  6231. return 0;
  6232. Spawn* player = lua_interface->GetSpawn(state);
  6233. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6234. if (!player) {
  6235. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. if (!player->IsPlayer()) {
  6239. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6240. return 0;
  6241. }
  6242. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6243. lua_interface->SetBooleanValue(state, ret);
  6244. return 1;
  6245. }
  6246. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6247. // Check to see if we have a valid lua_interface
  6248. if (!lua_interface)
  6249. return 0;
  6250. // Get the spawn that is getting the pet
  6251. Spawn* spawn = lua_interface->GetSpawn(state);
  6252. Spawn* target = lua_interface->GetSpawn(state, 2);
  6253. // Get the DB ID of the pet
  6254. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6255. float x = lua_interface->GetFloatValue(state, 4);
  6256. float y = lua_interface->GetFloatValue(state, 5);
  6257. float z = lua_interface->GetFloatValue(state, 6);
  6258. // Get the spell that this command was called from
  6259. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6260. // Check to make sure the spawn pointer is valid
  6261. if (!spawn) {
  6262. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6263. return 0;
  6264. }
  6265. // Check to make sure the spawn is an entity
  6266. if (!spawn->IsEntity()) {
  6267. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6268. return 0;
  6269. }
  6270. if (!target) {
  6271. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6272. return 0;
  6273. }
  6274. if (!target->IsEntity()) {
  6275. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6276. return 0;
  6277. }
  6278. // Check to see if the DB ID for the pet is set
  6279. if (pet_id == 0) {
  6280. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6281. return 0;
  6282. }
  6283. // Check to see if the pointer to the spell is valid
  6284. if (!luaspell) {
  6285. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6286. return 0;
  6287. }
  6288. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6289. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6290. if (!pet) {
  6291. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6292. return 0;
  6293. }
  6294. // Check to make sure the pet is an npc
  6295. if (!pet->IsNPC()) {
  6296. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6297. return 0;
  6298. }
  6299. if (x == 0)
  6300. x = spawn->GetX();
  6301. if (y == 0)
  6302. y = spawn->GetY();
  6303. if (z == 0)
  6304. z = spawn->GetZ();
  6305. // Spawn the pet at the same location as the owner
  6306. pet->SetX(x);
  6307. pet->SetY(y);
  6308. pet->SetZ(z);
  6309. pet->SetLocation(spawn->GetLocation());
  6310. pet->SetHeading(spawn->GetHeading());
  6311. spawn->GetZone()->AddSpawn(pet);
  6312. /*
  6313. const char* spawn_script = world.GetSpawnScript(pet_id);
  6314. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6315. spawn->SetSpawnScript(string(spawn_script));
  6316. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6317. }*/
  6318. // Get a random pet name
  6319. string random_pet_name;
  6320. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6321. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6322. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6323. // Set the pets name
  6324. pet->SetName(random_pet_name.c_str());
  6325. // Set the level of the pet to the owners level
  6326. pet->SetLevel(spawn->GetLevel());
  6327. // Set the faction of the pet to the same faction as the owner
  6328. pet->SetFactionID(spawn->GetFactionID());
  6329. // Set the spawn as a pet
  6330. pet->SetPet(true);
  6331. // Give a pointer of the owner to the pet
  6332. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6333. // Set the pet type
  6334. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6335. // Set the spell id used to create this pet
  6336. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6337. // Set the spell tier used to create this pet
  6338. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6339. // Set the pets spawn type to 6
  6340. pet->SetSpawnType(6);
  6341. // Set the pets brain
  6342. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6343. // Check to see if the pet has a subtitle
  6344. if (strlen(pet->GetSubTitle()) > 0) {
  6345. // Add the players name to the front of the sub title
  6346. string pet_subtitle;
  6347. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6348. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6349. // Set the pets subtitle to the new one
  6350. pet->SetSubTitle(pet_subtitle.c_str());
  6351. }
  6352. // Set the pet as the return value for this function
  6353. lua_interface->SetSpawnValue(state, pet);
  6354. return 1;
  6355. }
  6356. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6357. if (!lua_interface)
  6358. return 0;
  6359. Spawn* spawn = lua_interface->GetSpawn(state);
  6360. Spawn* player = lua_interface->GetSpawn(state, 2);
  6361. float max_distance = lua_interface->GetFloatValue(state, 3);
  6362. string type = lua_interface->GetStringValue(state, 4);
  6363. if (!spawn || (spawn && spawn->IsPlayer())) {
  6364. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6365. return 0;
  6366. }
  6367. if (!player || (player && !player->IsPlayer())) {
  6368. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6369. return 0;
  6370. }
  6371. Client* client = 0;
  6372. if (player->GetZone())
  6373. client = player->GetZone()->GetClientBySpawn(player);
  6374. if (!client) {
  6375. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6376. return 0;
  6377. }
  6378. //Set max_distance to default if not set or not proper value
  6379. if (max_distance <= 0)
  6380. max_distance = 500;
  6381. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6382. if (packet) {
  6383. float unknown2_3 = 0;
  6384. int8 placement_mode = 0;
  6385. if (type == "wall") {
  6386. placement_mode = 2;
  6387. unknown2_3 = 150;
  6388. }
  6389. else if (type == "ceiling")
  6390. placement_mode = 1;
  6391. packet->setDataByName("placement_mode", placement_mode);
  6392. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6393. packet->setDataByName("model_type", spawn->GetModelType());
  6394. packet->setDataByName("unknown", 1); //size
  6395. packet->setDataByName("unknown2", 1); //size 2
  6396. packet->setDataByName("unknown2", .5, 1); //size 3
  6397. packet->setDataByName("unknown2", 3, 2);
  6398. packet->setDataByName("unknown2", unknown2_3, 3);
  6399. packet->setDataByName("max_distance", max_distance);
  6400. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6401. client->QueuePacket(packet->serialize());
  6402. safe_delete(packet);
  6403. }
  6404. return 0;
  6405. }
  6406. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6407. if (!lua_interface)
  6408. return 0;
  6409. Item* item = lua_interface->GetItem(state);
  6410. if (!item) {
  6411. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6412. return 0;
  6413. }
  6414. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6415. return 1;
  6416. }
  6417. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6418. if (!lua_interface)
  6419. return 0;
  6420. Spawn* spawn = lua_interface->GetSpawn(state);
  6421. if (!spawn) {
  6422. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6423. return 0;
  6424. }
  6425. if (spawn->GetZone())
  6426. spawn->GetZone()->AddTransportSpawn(spawn);
  6427. return 0;
  6428. }
  6429. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6430. if (!lua_interface)
  6431. return 0;
  6432. Skill* skill = lua_interface->GetSkill(state);
  6433. if (!skill) {
  6434. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6435. return 0;
  6436. }
  6437. lua_interface->SetInt32Value(state, skill->current_val);
  6438. return 1;
  6439. }
  6440. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6441. if (!lua_interface)
  6442. return 0;
  6443. Skill* skill = lua_interface->GetSkill(state);
  6444. if (!skill) {
  6445. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6446. return 0;
  6447. }
  6448. lua_interface->SetInt32Value(state, skill->max_val);
  6449. return 1;
  6450. }
  6451. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6452. if (!lua_interface)
  6453. return 0;
  6454. Skill* skill = lua_interface->GetSkill(state);
  6455. if (!skill) {
  6456. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6457. return 0;
  6458. }
  6459. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6460. return 1;
  6461. }
  6462. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6463. if (!lua_interface)
  6464. return 0;
  6465. Skill* skill = lua_interface->GetSkill(state);
  6466. int16 value = lua_interface->GetInt16Value(state, 2);
  6467. if (!skill) {
  6468. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6469. return 0;
  6470. }
  6471. skill->max_val = value;
  6472. if (skill->max_val < skill->current_val)
  6473. skill->current_val = skill->max_val;
  6474. return 0;
  6475. }
  6476. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6477. if (!lua_interface)
  6478. return 0;
  6479. Skill* skill = lua_interface->GetSkill(state);
  6480. int16 value = lua_interface->GetInt16Value(state, 2);
  6481. if (!skill) {
  6482. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6483. return 0;
  6484. }
  6485. if (value > skill->max_val)
  6486. skill->current_val = skill->max_val;
  6487. else
  6488. skill->current_val = value;
  6489. return 0;
  6490. }
  6491. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6492. if (!lua_interface)
  6493. return 0;
  6494. Spawn* player = lua_interface->GetSpawn(state);
  6495. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6496. if (skill_id > 0 && player && player->IsPlayer()) {
  6497. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6498. return 1;
  6499. }
  6500. return 0;
  6501. }
  6502. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6503. if (!lua_interface)
  6504. return 0;
  6505. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6506. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6507. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6508. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6509. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6510. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6511. if (player_spawn && player_spawn->IsPlayer()) {
  6512. Player* player = (Player*)player_spawn;
  6513. bool added = false;
  6514. if (!player->skill_list.HasSkill(skill_id)) {
  6515. player->AddSkill(skill_id, current_val, max_val, true);
  6516. added = true;
  6517. }
  6518. 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
  6519. Client* client = player->GetClient();
  6520. if (client) {
  6521. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6522. if (packet)
  6523. client->QueuePacket(packet);
  6524. }
  6525. }
  6526. if (added) {
  6527. lua_interface->SetBooleanValue(state, true);
  6528. return 1;
  6529. }
  6530. }
  6531. else {
  6532. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6533. }
  6534. }
  6535. else {
  6536. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6537. }
  6538. lua_interface->SetBooleanValue(state, false);
  6539. return 1;
  6540. }
  6541. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6542. if (!lua_interface)
  6543. return 0;
  6544. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6545. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6546. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6547. if (skill_id > 0) {
  6548. if (player_spawn && player_spawn->IsPlayer()) {
  6549. Player* player = (Player*)player_spawn;
  6550. if (player->skill_list.HasSkill(skill_id)) {
  6551. player->RemovePlayerSkill(skill_id);
  6552. if (!more_to_remove) {
  6553. Client* client = player->GetClient();
  6554. if (client) {
  6555. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6556. if (packet)
  6557. client->QueuePacket(packet);
  6558. }
  6559. }
  6560. }
  6561. }
  6562. else {
  6563. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6564. }
  6565. }
  6566. else {
  6567. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6568. }
  6569. return 0;
  6570. }
  6571. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6572. if (!lua_interface)
  6573. return 0;
  6574. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6575. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6576. int16 amount = lua_interface->GetInt8Value(state, 3);
  6577. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6578. if (amount > 0 && skill_type < 100) {
  6579. if (player_spawn && player_spawn->IsPlayer()) {
  6580. Player* player = (Player*)player_spawn;
  6581. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6582. if (!more_to_increase) {
  6583. Client* client = player->GetClient();
  6584. if (client) {
  6585. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6586. if (packet)
  6587. client->QueuePacket(packet);
  6588. }
  6589. }
  6590. }
  6591. else {
  6592. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6593. }
  6594. }
  6595. else {
  6596. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6597. }
  6598. return 0;
  6599. }
  6600. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6601. if (!lua_interface)
  6602. return 0;
  6603. Spawn* spawn = lua_interface->GetSpawn(state);
  6604. string name = lua_interface->GetStringValue(state, 2);
  6605. if (!spawn) {
  6606. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6607. return 0;
  6608. }
  6609. if (!spawn->IsEntity()) {
  6610. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6611. return 0;
  6612. }
  6613. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6614. if (skill) {
  6615. lua_interface->SetSkillValue(state, skill);
  6616. return 1;
  6617. }
  6618. return 0;
  6619. }
  6620. int EQ2Emu_lua_AddProc(lua_State* state) {
  6621. if (!lua_interface)
  6622. return 0;
  6623. Spawn* spawn = lua_interface->GetSpawn(state);
  6624. int8 type = lua_interface->GetInt8Value(state, 2);
  6625. float chance = lua_interface->GetFloatValue(state, 3);
  6626. Item* item = lua_interface->GetItem(state, 4);
  6627. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6628. LuaSpell* spell = 0;
  6629. if (!spawn && (!spell || !use_all_spelltargets)) {
  6630. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6631. return 0;
  6632. }
  6633. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6634. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6635. return 0;
  6636. }
  6637. if (!item)
  6638. spell = lua_interface->GetCurrentSpell(state);
  6639. if (!item && !spell) {
  6640. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6641. return 0;
  6642. }
  6643. if (spell && use_all_spelltargets) {
  6644. Spawn* target;
  6645. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6646. for (int8 i = 0; i < spell->targets.size(); i++) {
  6647. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6648. if (!target || !target->IsEntity())
  6649. continue;
  6650. ((Entity*)target)->AddProc(type, chance, item, spell);
  6651. }
  6652. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6653. }
  6654. else
  6655. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6656. return 0;
  6657. }
  6658. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6659. if (!lua_interface)
  6660. return 0;
  6661. Spawn* spawn = lua_interface->GetSpawn(state);
  6662. Item* item = lua_interface->GetItem(state, 2);
  6663. LuaSpell* spell = 0;
  6664. if (!spawn) {
  6665. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6666. return 0;
  6667. }
  6668. if (!spawn->IsEntity()) {
  6669. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6670. return 0;
  6671. }
  6672. if (!item)
  6673. spell = lua_interface->GetCurrentSpell(state);
  6674. if (!item && !spell) {
  6675. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6676. return 0;
  6677. }
  6678. if (spell) {
  6679. Spawn* target;
  6680. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6681. for (int8 i = 0; i < spell->targets.size(); i++) {
  6682. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6683. if (!target || !target->IsEntity())
  6684. continue;
  6685. ((Entity*)target)->RemoveProc(item, spell);
  6686. }
  6687. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6688. spell->caster->RemoveProc(item, spell);
  6689. }
  6690. else
  6691. ((Entity*)spawn)->RemoveProc(item, spell);
  6692. return 0;
  6693. }
  6694. int EQ2Emu_lua_Knockback(lua_State* state) {
  6695. if (!lua_interface)
  6696. return 0;
  6697. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6698. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6699. int32 duration = lua_interface->GetInt32Value(state, 3);
  6700. float vertical = lua_interface->GetFloatValue(state, 4);
  6701. float horizontal = lua_interface->GetFloatValue(state, 5);
  6702. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6703. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6704. if (!target_spawn) {
  6705. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6706. return 0;
  6707. }
  6708. if (!spawn) {
  6709. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6710. return 0;
  6711. }
  6712. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6713. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6714. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6715. if (packet) {
  6716. packet->setDataByName("target_x", target_spawn->GetX());
  6717. packet->setDataByName("target_y", target_spawn->GetY());
  6718. packet->setDataByName("target_z", target_spawn->GetZ());
  6719. packet->setDataByName("vertical_movement", vertical);
  6720. packet->setDataByName("horizontal_movement", horizontal);
  6721. if (use_heading)
  6722. packet->setDataByName("use_player_heading", 1);
  6723. client->QueuePacket(packet->serialize());
  6724. }
  6725. safe_delete(packet);
  6726. }
  6727. return 0;
  6728. }
  6729. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6730. if (!lua_interface)
  6731. return 0;
  6732. Spawn* spawn = lua_interface->GetSpawn(state);
  6733. if (!spawn) {
  6734. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6735. return 0;
  6736. }
  6737. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6738. return 1;
  6739. }
  6740. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6741. if (!lua_interface)
  6742. return 0;
  6743. Spawn* caster = lua_interface->GetSpawn(state);
  6744. Spawn* target = lua_interface->GetSpawn(state, 2);
  6745. string name = lua_interface->GetStringValue(state, 3);
  6746. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6747. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6748. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6749. string success_msg = lua_interface->GetStringValue(state, 7);
  6750. string effect_msg = lua_interface->GetStringValue(state, 8);
  6751. if (!caster) {
  6752. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6753. return 0;
  6754. }
  6755. if (!caster->IsEntity()) {
  6756. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6757. return 0;
  6758. }
  6759. if (!target) {
  6760. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6761. return 0;
  6762. }
  6763. if (!target->IsEntity()) {
  6764. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6765. return 0;
  6766. }
  6767. if (name.length() == 0) {
  6768. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6769. return 0;
  6770. }
  6771. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6772. return 0;
  6773. }
  6774. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6775. if (!lua_interface)
  6776. return 0;
  6777. string name = lua_interface->GetStringValue(state);
  6778. if (name.length() == 0) {
  6779. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6780. return 0;
  6781. }
  6782. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6783. if (!skill) {
  6784. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6785. return 0;
  6786. }
  6787. lua_interface->SetInt32Value(state, skill->skill_id);
  6788. return 1;
  6789. }
  6790. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6791. if (!lua_interface)
  6792. return 0;
  6793. Spawn* spawn = lua_interface->GetSpawn(state);
  6794. if (!spawn) {
  6795. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6796. return 0;
  6797. }
  6798. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6799. return 1;
  6800. }
  6801. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6802. if (!lua_interface)
  6803. return 0;
  6804. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6805. if (!luaspell) {
  6806. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6807. return 0;
  6808. }
  6809. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6810. return 1;
  6811. }
  6812. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6813. if (!lua_interface)
  6814. return 0;
  6815. Spawn* spawn = lua_interface->GetSpawn(state);
  6816. Spawn* target = lua_interface->GetSpawn(state, 2);
  6817. if (!spawn) {
  6818. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6819. return 0;
  6820. }
  6821. if (!spawn->IsEntity()) {
  6822. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6823. return 0;
  6824. }
  6825. if (!target) {
  6826. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6827. return 0;
  6828. }
  6829. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6830. return 1;
  6831. }
  6832. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6833. if (!lua_interface)
  6834. return 0;
  6835. Spawn* spawn = lua_interface->GetSpawn(state);
  6836. Spawn* target = lua_interface->GetSpawn(state, 2);
  6837. if (!spawn) {
  6838. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6839. return 0;
  6840. }
  6841. if (!spawn->IsEntity()) {
  6842. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6843. return 0;
  6844. }
  6845. if (!target) {
  6846. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6847. return 0;
  6848. }
  6849. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6850. return 1;
  6851. }
  6852. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6853. if (!lua_interface)
  6854. return 0;
  6855. Item* item = lua_interface->GetItem(state);
  6856. if (!item) {
  6857. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6858. return 0;
  6859. }
  6860. lua_interface->SetInt32Value(state, item->details.count);
  6861. return 1;
  6862. }
  6863. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6864. if (!lua_interface)
  6865. return 0;
  6866. Item* item = lua_interface->GetItem(state);
  6867. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6868. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6869. if (!item) {
  6870. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6871. return 0;
  6872. }
  6873. if (!owner) {
  6874. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6875. return 0;
  6876. }
  6877. if (!owner->IsPlayer()) {
  6878. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6879. return 0;
  6880. }
  6881. if (item->stack_count < new_count) {
  6882. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6883. return 0;
  6884. }
  6885. if (new_count > 0) {
  6886. item->details.count = new_count;
  6887. item->save_needed = true;
  6888. }
  6889. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6890. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6891. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6892. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6893. else
  6894. {
  6895. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6896. return 0;
  6897. }
  6898. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6899. if (!client)
  6900. return 0;
  6901. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6902. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6903. if (app)
  6904. client->QueuePacket(app);
  6905. return 0;
  6906. }
  6907. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6908. if (!lua_interface)
  6909. return 0;
  6910. int32 time = lua_interface->GetInt32Value(state);
  6911. string function = lua_interface->GetStringValue(state, 2);
  6912. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6913. Spawn* target = lua_interface->GetSpawn(state, 4);
  6914. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6915. if (time == 0) {
  6916. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6917. return 0;
  6918. }
  6919. if (function.length() == 0) {
  6920. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6921. return 0;
  6922. }
  6923. if (!spell) {
  6924. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6925. return 0;
  6926. }
  6927. SpellScriptTimer* timer = new SpellScriptTimer;
  6928. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6929. #ifdef WIN32
  6930. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6931. #else
  6932. bzero(timer, sizeof(SpellScriptTimer));
  6933. #endif*/
  6934. timer->caster = 0;
  6935. timer->deleteWhenDone = false;
  6936. timer->target = 0;
  6937. timer->time = Timer::GetCurrentTime2() + time;
  6938. timer->customFunction = function;
  6939. timer->spell = spell;
  6940. if (caster)
  6941. timer->caster = caster->GetID();
  6942. if (target)
  6943. timer->target = target->GetID();
  6944. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6945. return 0;
  6946. }
  6947. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6948. if (!lua_interface)
  6949. return 0;
  6950. float hp_perc = lua_interface->GetFloatValue(state);
  6951. float power_perc = lua_interface->GetFloatValue(state, 2);
  6952. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6953. Spawn* target = lua_interface->GetSpawn(state, 4);
  6954. string heal_name = lua_interface->GetStringValue(state, 5);
  6955. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6956. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6957. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6958. if (!spell) {
  6959. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6960. return 0;
  6961. }
  6962. Entity* caster = spell->caster;
  6963. if (!caster) {
  6964. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6965. return 0;
  6966. }
  6967. Client* client = 0;
  6968. PendingResurrection* rez = 0;
  6969. ZoneServer* zone = spell->caster->GetZone();
  6970. if (!target) {
  6971. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6972. if (spell->targets.size() > 0) {
  6973. vector<int32> spell_targets = spell->targets;
  6974. for (int8 i = 0; i < spell_targets.size(); i++) {
  6975. target = zone->GetSpawnByID(spell_targets.at(i));
  6976. if (!target)
  6977. continue;
  6978. if (!target->IsPlayer())
  6979. continue;
  6980. client = target->GetZone()->GetClientBySpawn(target);
  6981. if (!client)
  6982. continue;
  6983. rez = client->GetCurrentRez();
  6984. if (rez->active)
  6985. continue;
  6986. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6987. rez->active = true;
  6988. rez->caster = caster;
  6989. rez->expire_timer = new Timer;
  6990. int32 duration = spell->spell->GetSpellDuration();
  6991. rez->expire_timer->Start(duration * 100);
  6992. rez->hp_perc = hp_perc;
  6993. rez->mp_perc = power_perc;
  6994. rez->range = spell->spell->GetSpellData()->range;
  6995. rez->spell_name = spell->spell->GetName();
  6996. if (heal_name.length() > 0)
  6997. rez->heal_name = heal_name;
  6998. else
  6999. rez->heal_name = rez->spell_name;
  7000. rez->no_calcs = no_calcs;
  7001. rez->crit_mod = crit_mod;
  7002. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7003. if (send_window)
  7004. client->SendResurrectionWindow();
  7005. else {
  7006. target->GetZone()->ResurrectSpawn(target, client);
  7007. rez->should_delete = true;
  7008. }
  7009. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7010. }
  7011. }
  7012. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7013. }
  7014. else {
  7015. client = target->GetZone()->GetClientBySpawn(target);
  7016. if (!client)
  7017. return 0;
  7018. rez = client->GetCurrentRez();
  7019. if (rez->active)
  7020. return 0;
  7021. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7022. rez->active = true;
  7023. rez->caster = caster;
  7024. rez->expire_timer = new Timer;
  7025. int32 duration = spell->spell->GetSpellDuration();
  7026. rez->expire_timer->Start(duration * 100);
  7027. rez->hp_perc = hp_perc;
  7028. rez->mp_perc = power_perc;
  7029. rez->range = spell->spell->GetSpellData()->range;
  7030. rez->spell_name = spell->spell->GetName();
  7031. if (heal_name.length() > 0)
  7032. rez->heal_name = heal_name;
  7033. else
  7034. rez->heal_name = rez->spell_name;
  7035. rez->no_calcs = no_calcs;
  7036. rez->crit_mod = crit_mod;
  7037. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7038. if (send_window)
  7039. client->SendResurrectionWindow();
  7040. else {
  7041. target->GetZone()->ResurrectSpawn(target, client);
  7042. rez->should_delete = true;
  7043. }
  7044. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7045. }
  7046. return 0;
  7047. }
  7048. int EQ2Emu_lua_SetVision(lua_State* state) {
  7049. if (!lua_interface)
  7050. return 0;
  7051. Spawn* spawn = lua_interface->GetSpawn(state);
  7052. int8 vision = lua_interface->GetInt8Value(state, 2);
  7053. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7054. if (!spawn) {
  7055. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7056. return 0;
  7057. }
  7058. if (!spawn->IsEntity()) {
  7059. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7060. return 0;
  7061. }
  7062. if (spell && spell->targets.size() > 0) {
  7063. ZoneServer* zone = spell->caster->GetZone();
  7064. for (int8 i = 0; i < spell->targets.size(); i++) {
  7065. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7066. if (target->IsEntity()) {
  7067. ((Entity*)target)->GetInfoStruct()->vision = vision;
  7068. if (target->IsPlayer())
  7069. ((Player*)target)->SetCharSheetChanged(true);
  7070. }
  7071. }
  7072. }
  7073. else {
  7074. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  7075. if (spawn->IsPlayer())
  7076. ((Player*)spawn)->SetCharSheetChanged(true);
  7077. }
  7078. return 0;
  7079. }
  7080. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7081. if (!lua_interface)
  7082. return 0;
  7083. Spawn* spawn = lua_interface->GetSpawn(state);
  7084. float intensity = lua_interface->GetFloatValue(state, 2);
  7085. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7086. if (!spawn) {
  7087. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7088. return 0;
  7089. }
  7090. if (!spawn->IsEntity()) {
  7091. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7092. return 0;
  7093. }
  7094. if (spell && spell->targets.size() > 0) {
  7095. ZoneServer* zone = spell->caster->GetZone();
  7096. for (int8 i = 0; i < spell->targets.size(); i++) {
  7097. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7098. if (target && target->IsEntity()) {
  7099. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  7100. if (target->IsPlayer())
  7101. ((Player*)target)->SetCharSheetChanged(true);
  7102. }
  7103. }
  7104. }
  7105. else {
  7106. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  7107. if (spawn->IsPlayer())
  7108. ((Player*)spawn)->SetCharSheetChanged(true);
  7109. }
  7110. return 0;
  7111. }
  7112. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7113. if (!lua_interface)
  7114. return 0;
  7115. Spawn* spawn = lua_interface->GetSpawn(state);
  7116. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7117. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7118. if (!spawn) {
  7119. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7120. return 0;
  7121. }
  7122. if (!spawn->IsEntity()) {
  7123. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7124. return 0;
  7125. }
  7126. if (spell && spell->targets.size() > 0) {
  7127. ZoneServer* zone = spell->caster->GetZone();
  7128. for (int8 i = 0; i < spell->targets.size(); i++) {
  7129. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7130. if (target->IsEntity()) {
  7131. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  7132. if (target->IsPlayer())
  7133. ((Player*)target)->SetCharSheetChanged(true);
  7134. }
  7135. }
  7136. }
  7137. else {
  7138. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  7139. if (spawn->IsPlayer())
  7140. ((Player*)spawn)->SetCharSheetChanged(true);
  7141. }
  7142. return 0;
  7143. }
  7144. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7145. if (!lua_interface)
  7146. return 0;
  7147. Item* item = lua_interface->GetItem(state);
  7148. int8 type = lua_interface->GetInt32Value(state, 2);
  7149. if (!item) {
  7150. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7151. return 0;
  7152. }
  7153. if (type == 1)
  7154. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7155. else if (type == 2)
  7156. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7157. return 1;
  7158. }
  7159. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7160. if (!lua_interface)
  7161. return 0;
  7162. Spawn* target = lua_interface->GetSpawn(state);
  7163. float val = lua_interface->GetFloatValue(state, 2);
  7164. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7165. // Added from Gangrenous post
  7166. if (spell && spell->resisted)
  7167. return 0;
  7168. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7169. if (val > 1.0f)
  7170. val = 1.0f - (val / 100.0f);
  7171. if (spell && spell->spell && spell->targets.size() > 0) {
  7172. ZoneServer* zone = spell->caster->GetZone();
  7173. for (int32 i = 0; i != spell->targets.size(); i++) {
  7174. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7175. if (spawn && spawn->IsEntity()) {
  7176. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7177. if (spawn->IsPlayer())
  7178. ((Player*)spawn)->SetCharSheetChanged(true);
  7179. }
  7180. }
  7181. }
  7182. else {
  7183. if (target && target->IsEntity()) {
  7184. ((Entity*)target)->SetSpeedMultiplier(val);
  7185. if (target->IsPlayer())
  7186. ((Player*)target)->SetCharSheetChanged(true);
  7187. }
  7188. }
  7189. return 0;
  7190. }
  7191. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7192. if (!lua_interface)
  7193. return 0;
  7194. Spawn* spawn = lua_interface->GetSpawn(state);
  7195. int16 model = lua_interface->GetInt16Value(state, 2);
  7196. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7197. if (spell && spell->spell && spell->targets.size() > 0) {
  7198. ZoneServer* zone = spell->caster->GetZone();
  7199. for (int32 i = 0; i < spell->targets.size(); i++) {
  7200. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7201. if (target)
  7202. target->SetIllusionModel(model);
  7203. }
  7204. }
  7205. else {
  7206. if (!spawn) {
  7207. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7208. return 0;
  7209. }
  7210. spawn->SetIllusionModel(model);
  7211. }
  7212. return 0;
  7213. }
  7214. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7215. if (!lua_interface)
  7216. return 0;
  7217. Spawn* spawn = lua_interface->GetSpawn(state);
  7218. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7219. if (spell && spell->spell && spell->targets.size() > 0) {
  7220. ZoneServer* zone = spell->caster->GetZone();
  7221. for (int32 i = 0; i < spell->targets.size(); i++) {
  7222. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7223. if (target)
  7224. target->SetIllusionModel(0);
  7225. }
  7226. }
  7227. else {
  7228. if (!spawn) {
  7229. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7230. return 0;
  7231. }
  7232. spawn->SetIllusionModel(0);
  7233. }
  7234. return 0;
  7235. }
  7236. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7237. if (!lua_interface)
  7238. return 0;
  7239. Spawn* caster = lua_interface->GetSpawn(state);
  7240. Spawn* target = lua_interface->GetSpawn(state, 2);
  7241. float chance = lua_interface->GetFloatValue(state, 3);
  7242. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7243. if (!caster) {
  7244. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7245. return 0;
  7246. }
  7247. if (!caster->IsEntity()) {
  7248. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7249. return 0;
  7250. }
  7251. if (!target) {
  7252. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7253. return 0;
  7254. }
  7255. if (!target->IsEntity()) {
  7256. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7257. return 0;
  7258. }
  7259. if (chance <= 0) {
  7260. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7261. return 0;
  7262. }
  7263. if (!spell) {
  7264. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7265. return 0;
  7266. }
  7267. if (((Entity*)caster)->GetThreatTransfer()) {
  7268. return 0;
  7269. }
  7270. ThreatTransfer* transfer = new ThreatTransfer;
  7271. transfer->Target = target->GetID();
  7272. transfer->Amount = chance;
  7273. transfer->Spell = spell;
  7274. ((Entity*)caster)->SetThreatTransfer(transfer);
  7275. return 0;
  7276. }
  7277. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7278. if (!lua_interface)
  7279. return 0;
  7280. Spawn* spawn = lua_interface->GetSpawn(state);
  7281. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7282. if (!spawn) {
  7283. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7284. return 0;
  7285. }
  7286. if (!spell) {
  7287. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7288. return 0;
  7289. }
  7290. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7291. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7292. ((Entity*)spawn)->SetThreatTransfer(0);
  7293. safe_delete(transfer);
  7294. }
  7295. return 0;
  7296. }
  7297. int EQ2Emu_lua_CureByType(lua_State* state) {
  7298. if (!lua_interface)
  7299. return 0;
  7300. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7301. if (!spell) {
  7302. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7303. return 0;
  7304. }
  7305. int8 cure_count = lua_interface->GetInt8Value(state);
  7306. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7307. string cure_name = lua_interface->GetStringValue(state, 3);
  7308. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7309. Spawn* target = lua_interface->GetSpawn(state, 5);
  7310. if (target) {
  7311. if (!target->IsEntity()) {
  7312. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7313. return 0;
  7314. }
  7315. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7316. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7317. }
  7318. else {
  7319. ZoneServer* zone = spell->caster->GetZone();
  7320. vector<int32> targets = spell->targets;
  7321. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7322. for (int8 i = 0; i < targets.size(); i++) {
  7323. target = zone->GetSpawnByID(targets.at(i));
  7324. if (!target || !target->IsEntity())
  7325. continue;
  7326. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7327. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7328. }
  7329. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7330. }
  7331. return 0;
  7332. }
  7333. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7334. if (!lua_interface)
  7335. return 0;
  7336. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7337. if (!spell) {
  7338. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7339. return 0;
  7340. }
  7341. int8 cure_count = lua_interface->GetInt8Value(state);
  7342. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7343. string cure_name = lua_interface->GetStringValue(state, 3);
  7344. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7345. Spawn* target = lua_interface->GetSpawn(state, 5);
  7346. if (target) {
  7347. if (!target->IsEntity()) {
  7348. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7349. return 0;
  7350. }
  7351. if (((Entity*)target)->GetDetCount() > 0)
  7352. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7353. }
  7354. else {
  7355. ZoneServer* zone = spell->caster->GetZone();
  7356. vector<int32> targets = spell->targets;
  7357. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7358. for (int8 i = 0; i < targets.size(); i++) {
  7359. target = zone->GetSpawnByID(targets.at(i));
  7360. if (!target || !target->IsEntity())
  7361. continue;
  7362. if (((Entity*)target)->GetDetCount() > 0)
  7363. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7364. }
  7365. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7366. }
  7367. return 0;
  7368. }
  7369. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7370. if (!lua_interface)
  7371. return 0;
  7372. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7373. if (!spell) {
  7374. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7375. return 0;
  7376. }
  7377. if (!spell->caster) {
  7378. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7379. return 0;
  7380. }
  7381. if (!spell->caster->GetZone()) {
  7382. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7383. return 0;
  7384. }
  7385. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7386. return 0;
  7387. }
  7388. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7389. if (!lua_interface)
  7390. return 0;
  7391. Spawn* spawn = lua_interface->GetSpawn(state);
  7392. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7393. if (!spell) {
  7394. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7395. return 0;
  7396. }
  7397. if (spawn && spawn->IsEntity())
  7398. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7399. else {
  7400. ZoneServer* zone = spell->caster->GetZone();
  7401. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7402. for (int32 i = 0; i < spell->targets.size(); i++) {
  7403. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7404. if (!spawn || !spawn->IsEntity())
  7405. continue;
  7406. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7407. }
  7408. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7409. }
  7410. return 0;
  7411. }
  7412. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7413. if (!lua_interface)
  7414. return 0;
  7415. Spawn* spawn = lua_interface->GetSpawn(state);
  7416. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7417. if (!spell) {
  7418. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7419. return 0;
  7420. }
  7421. if (spawn && spawn->IsEntity())
  7422. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7423. else {
  7424. ZoneServer* zone = spell->caster->GetZone();
  7425. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7426. for (int32 i = 0; i < spell->targets.size(); i++) {
  7427. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7428. if (!spawn || !spawn->IsEntity())
  7429. continue;
  7430. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7431. }
  7432. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7433. }
  7434. return 0;
  7435. }
  7436. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7437. if (!lua_interface)
  7438. return 0;
  7439. Spawn* caster = lua_interface->GetSpawn(state);
  7440. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7441. if (!caster) {
  7442. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7443. return 0;
  7444. }
  7445. if (!caster->IsPlayer()) {
  7446. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7447. return 0;
  7448. }
  7449. Spawn* target = caster->GetTarget();
  7450. if (!target) {
  7451. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7452. return 0;
  7453. }
  7454. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7455. if (!client) {
  7456. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7457. return 0;
  7458. }
  7459. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7460. if (ho) {
  7461. ho->SetTarget(target->GetID());
  7462. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7463. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7464. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7465. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7466. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7467. deque<GroupMemberInfo*>::iterator itr;
  7468. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7469. if (group)
  7470. {
  7471. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7472. deque<GroupMemberInfo*>* members = group->GetMembers();
  7473. for (itr = members->begin(); itr != members->end(); itr++) {
  7474. if ((*itr)->client)
  7475. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7476. }
  7477. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7478. }
  7479. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7480. }
  7481. else
  7482. safe_delete(ho);
  7483. }
  7484. else {
  7485. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7486. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7487. }
  7488. else
  7489. safe_delete(ho);
  7490. }
  7491. }
  7492. return 0;
  7493. }
  7494. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7495. if (!lua_interface)
  7496. return 0;
  7497. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7498. if (!spell) {
  7499. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7500. return 0;
  7501. }
  7502. int16 triggerCount = lua_interface->GetInt16Value(state);
  7503. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7504. if (!triggerCount) {
  7505. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7506. return 0;
  7507. }
  7508. spell->num_triggers = triggerCount;
  7509. spell->had_triggers = true;
  7510. spell->cancel_after_all_triggers = cancel_after_triggers;
  7511. return 0;
  7512. }
  7513. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7514. if (!lua_interface)
  7515. return 0;
  7516. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7517. if (!spell) {
  7518. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7519. return 0;
  7520. }
  7521. lua_interface->SetInt32Value(state, spell->num_triggers);
  7522. return 1;
  7523. }
  7524. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7525. if (!lua_interface)
  7526. return 0;
  7527. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7528. if (!spell) {
  7529. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7530. return 0;
  7531. }
  7532. int16 remove_count = lua_interface->GetInt16Value(state);
  7533. if (!remove_count)
  7534. remove_count = 1;
  7535. if (remove_count >= spell->num_triggers) {
  7536. spell->num_triggers = 0;
  7537. if (spell->cancel_after_all_triggers)
  7538. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7539. }
  7540. else {
  7541. spell->num_triggers -= remove_count;
  7542. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7543. }
  7544. return 0;
  7545. }
  7546. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7547. if (!lua_interface)
  7548. return 0;
  7549. Spawn* spawn = lua_interface->GetSpawn(state);
  7550. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7551. if (!spawn) {
  7552. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7553. return 0;
  7554. }
  7555. if (!copy_spawn) {
  7556. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7557. return 0;
  7558. }
  7559. spawn->CopySpawnAppearance(copy_spawn);
  7560. return 0;
  7561. }
  7562. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7563. if (!lua_interface)
  7564. return 0;
  7565. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7566. int8 type = lua_interface->GetInt8Value(state);
  7567. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7568. if (!spell) {
  7569. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7570. return 0;
  7571. }
  7572. if (spawn) {
  7573. if (!spawn->IsEntity()) {
  7574. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7575. return 0;
  7576. }
  7577. Entity* entity = ((Entity*)spawn);
  7578. switch (type) {
  7579. case IMMUNITY_TYPE_AOE:
  7580. entity->AddAOEImmunity(spell);
  7581. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7582. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7583. break;
  7584. case IMMUNITY_TYPE_STUN:
  7585. entity->AddStunImmunity(spell);
  7586. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7587. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7588. break;
  7589. case IMMUNITY_TYPE_ROOT:
  7590. entity->AddRootImmunity(spell);
  7591. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7592. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7593. break;
  7594. case IMMUNITY_TYPE_DAZE:
  7595. entity->AddDazeImmunity(spell);
  7596. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7597. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7598. break;
  7599. case IMMUNITY_TYPE_FEAR:
  7600. entity->AddFearImmunity(spell);
  7601. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7602. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7603. break;
  7604. case IMMUNITY_TYPE_MEZ:
  7605. entity->AddMezImmunity(spell);
  7606. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7607. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7608. break;
  7609. case IMMUNITY_TYPE_STIFLE:
  7610. entity->AddStifleImmunity(spell);
  7611. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7612. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7613. break;
  7614. default:
  7615. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7616. }
  7617. }
  7618. else {
  7619. bool should_break = false;
  7620. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7621. for (int8 i = 0; i < spell->targets.size(); i++) {
  7622. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7623. if (!spawn || !spawn->IsEntity())
  7624. continue;
  7625. Entity* entity = ((Entity*)spawn);
  7626. switch (type) {
  7627. case IMMUNITY_TYPE_AOE:
  7628. entity->AddAOEImmunity(spell);
  7629. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  7630. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  7631. break;
  7632. case IMMUNITY_TYPE_STUN:
  7633. entity->AddStunImmunity(spell);
  7634. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  7635. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  7636. break;
  7637. case IMMUNITY_TYPE_ROOT:
  7638. entity->AddRootImmunity(spell);
  7639. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  7640. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  7641. break;
  7642. case IMMUNITY_TYPE_DAZE:
  7643. entity->AddDazeImmunity(spell);
  7644. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  7645. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  7646. break;
  7647. case IMMUNITY_TYPE_FEAR:
  7648. entity->AddFearImmunity(spell);
  7649. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  7650. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  7651. break;
  7652. case IMMUNITY_TYPE_MEZ:
  7653. entity->AddMezImmunity(spell);
  7654. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  7655. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  7656. break;
  7657. case IMMUNITY_TYPE_STIFLE:
  7658. entity->AddStifleImmunity(spell);
  7659. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  7660. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  7661. break;
  7662. default:
  7663. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7664. should_break = true;
  7665. }
  7666. if (should_break)
  7667. break;
  7668. }
  7669. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7670. }
  7671. return 0;
  7672. }
  7673. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7674. if (!lua_interface)
  7675. return 0;
  7676. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7677. int8 type = lua_interface->GetInt8Value(state);
  7678. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7679. if (!spell) {
  7680. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7681. return 0;
  7682. }
  7683. if (spawn) {
  7684. if (!spawn->IsEntity()) {
  7685. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7686. return 0;
  7687. }
  7688. Entity* entity = ((Entity*)spawn);
  7689. switch (type) {
  7690. case IMMUNITY_TYPE_AOE:
  7691. entity->RemoveAOEImmunity(spell);
  7692. break;
  7693. case IMMUNITY_TYPE_STUN:
  7694. entity->RemoveStunImmunity(spell);
  7695. break;
  7696. case IMMUNITY_TYPE_ROOT:
  7697. entity->RemoveRootImmunity(spell);
  7698. break;
  7699. case IMMUNITY_TYPE_DAZE:
  7700. entity->RemoveDazeImmunity(spell);
  7701. break;
  7702. case IMMUNITY_TYPE_FEAR:
  7703. entity->RemoveFearImmunity(spell);
  7704. break;
  7705. case IMMUNITY_TYPE_MEZ:
  7706. entity->RemoveMezImmunity(spell);
  7707. break;
  7708. case IMMUNITY_TYPE_STIFLE:
  7709. entity->RemoveStifleImmunity(spell);
  7710. break;
  7711. default:
  7712. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7713. }
  7714. }
  7715. else {
  7716. bool should_break = false;
  7717. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7718. for (int8 i = 0; i < spell->targets.size(); i++) {
  7719. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7720. if (!spawn || !spawn->IsEntity())
  7721. continue;
  7722. Entity* entity = ((Entity*)spawn);
  7723. switch (type) {
  7724. case IMMUNITY_TYPE_AOE:
  7725. entity->RemoveAOEImmunity(spell);
  7726. break;
  7727. case IMMUNITY_TYPE_STUN:
  7728. entity->RemoveStunImmunity(spell);
  7729. break;
  7730. case IMMUNITY_TYPE_ROOT:
  7731. entity->RemoveRootImmunity(spell);
  7732. break;
  7733. case IMMUNITY_TYPE_DAZE:
  7734. entity->RemoveDazeImmunity(spell);
  7735. break;
  7736. case IMMUNITY_TYPE_FEAR:
  7737. entity->RemoveFearImmunity(spell);
  7738. break;
  7739. case IMMUNITY_TYPE_MEZ:
  7740. entity->RemoveMezImmunity(spell);
  7741. break;
  7742. case IMMUNITY_TYPE_STIFLE:
  7743. entity->RemoveStifleImmunity(spell);
  7744. break;
  7745. default:
  7746. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7747. should_break = true;
  7748. }
  7749. if (should_break)
  7750. break;
  7751. }
  7752. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7753. }
  7754. return 0;
  7755. }
  7756. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7757. if (!lua_interface)
  7758. return 0;
  7759. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7760. if (!spell) {
  7761. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7762. return 0;
  7763. }
  7764. float snare = lua_interface->GetFloatValue(state);
  7765. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7766. // convert the val to the speed multipler value (100 - val)
  7767. float val = 100.0 - snare;
  7768. val /= 100.0;
  7769. if (spawn) {
  7770. if (!spawn->IsEntity()) {
  7771. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7772. return 0;
  7773. }
  7774. ((Entity*)spawn)->SetSnareValue(spell, val);
  7775. }
  7776. else {
  7777. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7778. for (int8 i = 0; i < spell->targets.size(); i++) {
  7779. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7780. if (!spawn || !spawn->IsEntity())
  7781. continue;
  7782. ((Entity*)spawn)->SetSnareValue(spell, val);
  7783. }
  7784. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7785. }
  7786. return 0;
  7787. }
  7788. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7789. if (!lua_interface)
  7790. return 0;
  7791. Spawn* spawn = lua_interface->GetSpawn(state);
  7792. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7793. if (!spawn) {
  7794. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7795. return 0;
  7796. }
  7797. if (race_id == 0) {
  7798. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7799. return 0;
  7800. }
  7801. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7802. return 1;
  7803. }
  7804. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7805. if (!lua_interface)
  7806. return 0;
  7807. Spawn* spawn = lua_interface->GetSpawn(state);
  7808. if (!spawn) {
  7809. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7810. return 0;
  7811. }
  7812. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7813. return 1;
  7814. }
  7815. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7816. if (!lua_interface)
  7817. return 0;
  7818. Spawn* spawn = lua_interface->GetSpawn(state);
  7819. if (!spawn) {
  7820. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7821. return 0;
  7822. }
  7823. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7824. return 1;
  7825. }
  7826. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7827. if (!lua_interface)
  7828. return 0;
  7829. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7830. if (!spell) {
  7831. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7832. return 0;
  7833. }
  7834. lua_interface->SetStringValue(state, spell->spell->GetName());
  7835. return 1;
  7836. }
  7837. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7838. if (!lua_interface)
  7839. return 0;
  7840. Quest* quest = lua_interface->GetQuest(state);
  7841. if (!quest) {
  7842. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7846. return 1;
  7847. }
  7848. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7849. if (!lua_interface)
  7850. return 0;
  7851. Quest* quest = lua_interface->GetQuest(state);
  7852. int32 flags = lua_interface->GetInt32Value(state, 2);
  7853. if (!quest) {
  7854. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7855. return 0;
  7856. }
  7857. quest->SetQuestFlags(flags);
  7858. return 0;
  7859. }
  7860. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7861. if (!lua_interface)
  7862. return 0;
  7863. Quest* quest = lua_interface->GetQuest(state);
  7864. Spawn* player = lua_interface->GetSpawn(state, 2);
  7865. int32 step = lua_interface->GetInt32Value(state, 3);
  7866. int32 duration = lua_interface->GetInt32Value(state, 4);
  7867. string action = lua_interface->GetStringValue(state, 5);
  7868. if (!quest) {
  7869. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7870. return 0;
  7871. }
  7872. if (!player) {
  7873. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7874. return 0;
  7875. }
  7876. if (!player->IsPlayer()) {
  7877. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7878. return 0;
  7879. }
  7880. if (step == 0) {
  7881. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7882. return 0;
  7883. }
  7884. if (duration == 0) {
  7885. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7886. return 0;
  7887. }
  7888. if (action.length() == 0) {
  7889. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7890. return 0;
  7891. }
  7892. Client* client = player->GetZone()->GetClientBySpawn(player);
  7893. if (!client) {
  7894. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7895. return 0;
  7896. }
  7897. quest->SetTimerStep(step);
  7898. quest->AddFailedAction(step, action);
  7899. quest->SetStepTimer(duration);
  7900. client->AddQuestTimer(quest->GetQuestID());
  7901. return 0;
  7902. }
  7903. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7904. if (!lua_interface)
  7905. return 0;
  7906. Quest* quest = lua_interface->GetQuest(state);
  7907. Spawn* player = lua_interface->GetSpawn(state, 2);
  7908. if (!quest) {
  7909. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7910. return 0;
  7911. }
  7912. if (!player) {
  7913. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7914. return 0;
  7915. }
  7916. if (!player->IsPlayer()) {
  7917. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7918. return 0;
  7919. }
  7920. Client* client = player->GetZone()->GetClientBySpawn(player);
  7921. if (!client) {
  7922. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7923. return 0;
  7924. }
  7925. quest->SetTimerStep(0);
  7926. quest->SetStepTimer(0);
  7927. client->RemoveQuestTimer(quest->GetQuestID());
  7928. return 0;
  7929. }
  7930. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7931. if (!lua_interface)
  7932. return 0;
  7933. Spawn* player = lua_interface->GetSpawn(state);
  7934. Quest* quest = lua_interface->GetQuest(state, 2);
  7935. int32 step = lua_interface->GetInt32Value(state, 3);
  7936. if (!player) {
  7937. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7938. return 0;
  7939. }
  7940. if (!player->IsPlayer()) {
  7941. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7942. return 0;
  7943. }
  7944. if (!quest) {
  7945. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7946. return 0;
  7947. }
  7948. if (step == 0) {
  7949. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7950. return 0;
  7951. }
  7952. Client* client = player->GetZone()->GetClientBySpawn(player);
  7953. if (!client) {
  7954. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7955. return 0;
  7956. }
  7957. if (quest->RemoveQuestStep(step, client)) {
  7958. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7959. client->GetCurrentZone()->SendQuestUpdates(client);
  7960. }
  7961. else
  7962. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7963. return 0;
  7964. }
  7965. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7966. if (!lua_interface)
  7967. return 0;
  7968. Quest* quest = lua_interface->GetQuest(state, 1);
  7969. int32 step = lua_interface->GetInt32Value(state, 2);
  7970. string desc = lua_interface->GetStringValue(state, 3);
  7971. string task_group = lua_interface->GetStringValue(state, 4);
  7972. if (!quest) {
  7973. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7974. return 0;
  7975. }
  7976. if (step == 0) {
  7977. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7978. return 0;
  7979. }
  7980. QuestStep* quest_step = quest->GetQuestStep(step);
  7981. if (!quest_step) {
  7982. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7983. return 0;
  7984. }
  7985. quest_step->SetStepProgress(0);
  7986. quest_step->SetTaskGroup(task_group);
  7987. quest_step->SetDescription(desc);
  7988. return 0;
  7989. }
  7990. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7991. if (!lua_interface)
  7992. return 0;
  7993. Quest* quest = lua_interface->GetQuest(state);
  7994. int32 step = lua_interface->GetInt32Value(state, 2);
  7995. string action = lua_interface->GetStringValue(state, 3);
  7996. if (!quest) {
  7997. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7998. return 0;
  7999. }
  8000. if (step == 0) {
  8001. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8002. return 0;
  8003. }
  8004. if (action.length() == 0) {
  8005. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8006. return 0;
  8007. }
  8008. quest->AddFailedAction(step, action);
  8009. return 0;
  8010. }
  8011. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8012. if (!lua_interface)
  8013. return 0;
  8014. Spawn* player = lua_interface->GetSpawn(state);
  8015. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8016. int32 step = lua_interface->GetInt32Value(state, 3);
  8017. if (!player) {
  8018. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8019. return 0;
  8020. }
  8021. if (!player->IsPlayer()) {
  8022. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8023. return 0;
  8024. }
  8025. if (quest_id == 0) {
  8026. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8027. return 0;
  8028. }
  8029. if (step == 0) {
  8030. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8031. return 0;
  8032. }
  8033. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8034. if (!quest) {
  8035. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8036. return 0;
  8037. }
  8038. quest->StepFailed(step);
  8039. return 0;
  8040. }
  8041. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8042. if (!lua_interface)
  8043. return 0;
  8044. Spawn* player = lua_interface->GetSpawn(state);
  8045. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8046. if (!player) {
  8047. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8048. return 0;
  8049. }
  8050. if (!player->IsPlayer()) {
  8051. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8052. return 0;
  8053. }
  8054. if (quest_id == 0) {
  8055. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8056. return 0;
  8057. }
  8058. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8059. if (!quest) {
  8060. lua_interface->SetInt32Value(state, 0);
  8061. return 1;
  8062. }
  8063. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8064. return 1;
  8065. }
  8066. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8067. if (!lua_interface)
  8068. return 0;
  8069. string name = lua_interface->GetStringValue(state);
  8070. string value = lua_interface->GetStringValue(state, 2);
  8071. string comment = lua_interface->GetStringValue(state, 3);
  8072. if (name.length() == 0) {
  8073. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8074. return 0;
  8075. }
  8076. if (value.length() == 0) {
  8077. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8078. return 0;
  8079. }
  8080. string varname = string("lua_").append(name);
  8081. Variable* var = variables.FindVariable(varname);
  8082. if (var)
  8083. var->SetValue(value.c_str());
  8084. else {
  8085. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8086. variables.AddVariable(var);
  8087. }
  8088. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8089. return 0;
  8090. }
  8091. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8092. if (!lua_interface)
  8093. return 0;
  8094. string name = lua_interface->GetStringValue(state);
  8095. if (name.length() == 0) {
  8096. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8097. return 0;
  8098. }
  8099. string varname = string("lua_").append(name);
  8100. Variable* var = variables.FindVariable(varname);
  8101. if (var)
  8102. lua_interface->SetStringValue(state, var->GetValue());
  8103. else
  8104. lua_interface->SetStringValue(state, "NULL");
  8105. return 1;
  8106. }
  8107. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8108. if (!lua_interface)
  8109. return 0;
  8110. Spawn* player = lua_interface->GetSpawn(state);
  8111. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8112. if (!player) {
  8113. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8114. return 0;
  8115. }
  8116. if (!player->IsPlayer()) {
  8117. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8118. return 0;
  8119. }
  8120. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8121. return 1;
  8122. }
  8123. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8124. if (!lua_interface)
  8125. return 0;
  8126. Spawn* player = lua_interface->GetSpawn(state);
  8127. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8128. if (!player) {
  8129. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8130. return 0;
  8131. }
  8132. if (!player->IsPlayer()) {
  8133. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8134. return 0;
  8135. }
  8136. Language* language = master_languages_list.GetLanguage(language_id);
  8137. if (language)
  8138. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8139. return 0;
  8140. }
  8141. int EQ2Emu_lua_IsNight(lua_State* state) {
  8142. if (!lua_interface)
  8143. return 0;
  8144. ZoneServer* zone = lua_interface->GetZone(state);
  8145. if (!zone) {
  8146. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8147. return 0;
  8148. }
  8149. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8150. return 1;
  8151. }
  8152. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8153. if (!lua_interface)
  8154. return 0;
  8155. Spawn* spawn = lua_interface->GetSpawn(state);
  8156. if (!spawn) {
  8157. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8158. return 0;
  8159. }
  8160. if (!spawn->IsWidget()) {
  8161. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8162. return 0;
  8163. }
  8164. ((Widget*)spawn)->SetMultiFloorLift(true);
  8165. if (spawn->GetZone())
  8166. spawn->GetZone()->AddTransportSpawn(spawn);
  8167. return 0;
  8168. }
  8169. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8170. if (!lua_interface)
  8171. return 0;
  8172. Spawn* player = lua_interface->GetSpawn(state);
  8173. int32 path = lua_interface->GetInt32Value(state, 2);
  8174. if (!player) {
  8175. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8176. return 0;
  8177. }
  8178. if (!player->IsPlayer()) {
  8179. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8180. return 0;
  8181. }
  8182. if (path == 0) {
  8183. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8184. return 0;
  8185. }
  8186. Client* client = player->GetZone()->GetClientBySpawn(player);
  8187. if (!client) {
  8188. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8189. return 0;
  8190. }
  8191. client->SendFlightAutoMount(path);
  8192. return 0;
  8193. }
  8194. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8195. if (!lua_interface)
  8196. return 0;
  8197. Spawn* player = lua_interface->GetSpawn(state);
  8198. if (!player) {
  8199. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8200. return 0;
  8201. }
  8202. if (!player->IsPlayer()) {
  8203. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8204. return 0;
  8205. }
  8206. Client* client = player->GetZone()->GetClientBySpawn(player);
  8207. if (!client) {
  8208. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8209. return 0;
  8210. }
  8211. client->EndAutoMount();
  8212. return 0;
  8213. }
  8214. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8215. if (!lua_interface)
  8216. return 0;
  8217. Spawn* player = lua_interface->GetSpawn(state);
  8218. if (!player) {
  8219. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8220. return 0;
  8221. }
  8222. if (!player->IsPlayer()) {
  8223. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8224. return 0;
  8225. }
  8226. Client* client = player->GetZone()->GetClientBySpawn(player);
  8227. if (!client) {
  8228. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8229. return 0;
  8230. }
  8231. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8232. return 1;
  8233. }
  8234. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8235. if (!lua_interface)
  8236. return 0;
  8237. Spawn* player = lua_interface->GetSpawn(state);
  8238. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8239. int32 value = lua_interface->GetInt32Value(state, 3);
  8240. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8241. if (!player) {
  8242. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8243. return 0;
  8244. }
  8245. if (!player->IsPlayer()) {
  8246. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8247. return 0;
  8248. }
  8249. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8250. return 0;
  8251. }
  8252. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8253. if (!lua_interface)
  8254. return 0;
  8255. Spawn* player = lua_interface->GetSpawn(state);
  8256. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8257. if (!player) {
  8258. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8259. return 0;
  8260. }
  8261. if (!player->IsPlayer()) {
  8262. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8263. return 0;
  8264. }
  8265. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8266. if (!hd)
  8267. return 0;
  8268. lua_interface->SetInt32Value(state, hd->Value);
  8269. lua_interface->SetInt32Value(state, hd->Value2);
  8270. return 2;
  8271. }
  8272. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8273. if (!lua_interface)
  8274. return 0;
  8275. Spawn* spawn = lua_interface->GetSpawn(state);
  8276. int32 grid = lua_interface->GetInt32Value(state, 2);
  8277. if (!spawn) {
  8278. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8279. return 0;
  8280. }
  8281. if (grid == 0) {
  8282. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8283. return 0;
  8284. }
  8285. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8286. return 0;
  8287. }
  8288. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8289. if (!lua_interface)
  8290. return 0;
  8291. Spawn* spawn = lua_interface->GetSpawn(state);
  8292. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8293. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8294. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8295. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8296. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8297. if (!spawn) {
  8298. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8299. return 0;
  8300. }
  8301. //Add this quest to the list of required quests for this spawn
  8302. spawn->SetRequiredHistory(event_id, value1, value2);
  8303. //If private spawn value set
  8304. if (private_spawn) {
  8305. //Set the spawn to be private when not granted access via history
  8306. spawn->AddAllowAccessSpawn(spawn);
  8307. spawn->SetPrivateQuestSpawn(true);
  8308. }
  8309. //This value will override vis_flags in the vis packet
  8310. if (flag_override > 0)
  8311. spawn->SetQuestsRequiredOverride(flag_override);
  8312. return 0;
  8313. }
  8314. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8315. if (!lua_interface)
  8316. return 0;
  8317. Spawn* player = lua_interface->GetSpawn(state);
  8318. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8319. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8320. if (!player) {
  8321. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. if (!player->IsPlayer()) {
  8325. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8329. return 1;
  8330. }
  8331. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8332. if (!lua_interface)
  8333. return 0;
  8334. Spawn* player = lua_interface->GetSpawn(state);
  8335. int8 level = lua_interface->GetInt8Value(state, 2);
  8336. if (!player) {
  8337. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8338. return 0;
  8339. }
  8340. if (!player->IsPlayer()) {
  8341. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8342. return 0;
  8343. }
  8344. if (level == 0) {
  8345. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8346. return 0;
  8347. }
  8348. Client* client = player->GetZone()->GetClientBySpawn(player);
  8349. if (!client) {
  8350. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8351. return 0;
  8352. }
  8353. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8354. return 0;
  8355. }
  8356. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8357. if (!lua_interface)
  8358. return 0;
  8359. Spawn* player = lua_interface->GetSpawn(state);
  8360. int32 amount = lua_interface->GetInt32Value(state, 2);
  8361. if (!player) {
  8362. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8363. return 0;
  8364. }
  8365. if (!player->IsPlayer()) {
  8366. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8367. return 0;
  8368. }
  8369. if (amount == 0) {
  8370. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8371. return 0;
  8372. }
  8373. ((Player*)player)->AddCoins(amount);
  8374. return 0;
  8375. }
  8376. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8377. if (!lua_interface)
  8378. return 0;
  8379. Spawn* player = lua_interface->GetSpawn(state);
  8380. int32 amount = lua_interface->GetInt32Value(state, 2);
  8381. if (!player) {
  8382. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8383. return 0;
  8384. }
  8385. if (!player->IsPlayer()) {
  8386. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8387. return 0;
  8388. }
  8389. if (amount == 0) {
  8390. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8391. return 0;
  8392. }
  8393. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8394. return 1;
  8395. }
  8396. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8397. if (!lua_interface)
  8398. return 0;
  8399. ZoneServer* zone = lua_interface->GetZone(state);
  8400. if (!zone) {
  8401. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8402. return 0;
  8403. }
  8404. vector<Entity*> players = zone->GetPlayers();
  8405. if (players.size() == 0)
  8406. return 0;
  8407. lua_createtable(state, players.size(), 0);
  8408. int newTable = lua_gettop(state);
  8409. for (int32 i = 0; i < players.size(); i++) {
  8410. lua_interface->SetSpawnValue(state, players.at(i));
  8411. lua_rawseti(state, newTable, i + 1);
  8412. }
  8413. return 1;
  8414. }
  8415. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8416. if (!lua_interface)
  8417. return 0;
  8418. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8419. if (!zone) {
  8420. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8421. return 0;
  8422. }
  8423. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8424. //Map of <placement_id, location_id>
  8425. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8426. map<int32, int32>::iterator itr;
  8427. vector<Spawn*> group;
  8428. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8429. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8430. if (!location) {
  8431. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8432. return 0;
  8433. }
  8434. Spawn* spawn = 0;
  8435. if (location->entities[0]) {
  8436. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8437. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8438. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8439. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8440. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8441. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8442. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8443. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8444. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8445. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8446. if (spawn) {
  8447. const char* script = 0;
  8448. for (int x = 0; x < 3; x++) {
  8449. switch (x) {
  8450. case 0:
  8451. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8452. break;
  8453. case 1:
  8454. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8455. break;
  8456. case 2:
  8457. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8458. break;
  8459. }
  8460. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8461. spawn->SetSpawnScript(string(script));
  8462. break;
  8463. }
  8464. }
  8465. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8466. lua_interface->SetSpawnValue(state, spawn);
  8467. group.push_back(spawn);
  8468. }
  8469. else {
  8470. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8471. safe_delete(spawn);
  8472. }
  8473. }
  8474. }
  8475. if (!group.empty()) {
  8476. lua_createtable(state, group.size(), 0);
  8477. int newTable = lua_gettop(state);
  8478. for (int32 i = 0; i < group.size(); i++) {
  8479. lua_interface->SetSpawnValue(state, group[i]);
  8480. lua_rawseti(state, newTable, i + 1);
  8481. }
  8482. }
  8483. else
  8484. lua_pushnil(state);
  8485. return 1;
  8486. }
  8487. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8488. if (!lua_interface)
  8489. return 0;
  8490. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8491. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8492. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8493. if (!spawn) {
  8494. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8495. return 0;
  8496. }
  8497. if (anim_id == 0) {
  8498. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8499. return 0;
  8500. }
  8501. if (leeway == 0)
  8502. leeway = 5000;
  8503. spawn->SetSpawnAnim(anim_id);
  8504. spawn->SetSpawnAnimLeeway(leeway);
  8505. return 0;
  8506. }
  8507. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8508. if (!lua_interface)
  8509. return 0;
  8510. Spawn* player = lua_interface->GetSpawn(state);
  8511. if (!player) {
  8512. return 0;
  8513. }
  8514. Client* client = player->GetZone()->GetClientBySpawn(player);
  8515. if (!client) {
  8516. return 0;
  8517. }
  8518. lua_interface->SetInt32Value(state, client->GetVersion());
  8519. return 1;
  8520. }
  8521. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8522. if (!lua_interface)
  8523. return 0;
  8524. Item* item = lua_interface->GetItem(state);
  8525. if (!item) {
  8526. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8527. return 0;
  8528. }
  8529. lua_interface->SetInt32Value(state, item->details.item_id);
  8530. return 1;
  8531. }
  8532. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8533. if (!lua_interface)
  8534. return 0;
  8535. Spawn* spawn = lua_interface->GetSpawn(state);
  8536. if (!spawn) {
  8537. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8538. return 0;
  8539. }
  8540. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8541. return 1;
  8542. }
  8543. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8544. if (!lua_interface)
  8545. return 0;
  8546. Spawn* spawn = lua_interface->GetSpawn(state);
  8547. if (!spawn) {
  8548. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8549. return 0;
  8550. }
  8551. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8552. return 1;
  8553. }
  8554. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8555. if (!lua_interface)
  8556. return 0;
  8557. Spawn* spawn = lua_interface->GetSpawn(state);
  8558. if (!spawn) {
  8559. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8560. return 0;
  8561. }
  8562. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8563. return 1;
  8564. }
  8565. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8566. if (!lua_interface)
  8567. return 0;
  8568. Spawn* spawn = lua_interface->GetSpawn(state);
  8569. if (!spawn) {
  8570. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8571. return 0;
  8572. }
  8573. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8574. return 1;
  8575. }
  8576. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8577. if (!lua_interface)
  8578. return 0;
  8579. Spawn* spawn = lua_interface->GetSpawn(state);
  8580. float pct = lua_interface->GetFloatValue(state, 2);
  8581. if (!spawn) {
  8582. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8583. return 0;
  8584. }
  8585. if (pct == 0) {
  8586. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8587. return 0;
  8588. }
  8589. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8590. lua_interface->SetInt32Value(state, amount);
  8591. return 1;
  8592. }
  8593. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8594. if (!lua_interface)
  8595. return 0;
  8596. Spawn* spawn = lua_interface->GetSpawn(state);
  8597. float pct = lua_interface->GetFloatValue(state, 2);
  8598. if (!spawn) {
  8599. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8600. return 0;
  8601. }
  8602. if (pct == 0) {
  8603. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8604. return 0;
  8605. }
  8606. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8607. lua_interface->SetInt32Value(state, amount);
  8608. return 1;
  8609. }
  8610. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8611. if (!lua_interface)
  8612. return 0;
  8613. Spawn* spawn = lua_interface->GetSpawn(state);
  8614. if (!spawn) {
  8615. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8616. return 0;
  8617. }
  8618. if (!spawn->IsPlayer()) {
  8619. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8620. return 0;
  8621. }
  8622. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8623. return 1;
  8624. }
  8625. int EQ2Emu_lua_Evac(lua_State* state) {
  8626. if (!lua_interface)
  8627. return 0;
  8628. Spawn* target = lua_interface->GetSpawn(state);
  8629. if (target) {
  8630. float x = target->GetZone()->GetSafeX();
  8631. float y = target->GetZone()->GetSafeY();
  8632. float z = target->GetZone()->GetSafeZ();
  8633. float h = target->GetZone()->GetSafeHeading();
  8634. target->SetX(x);
  8635. target->SetY(y);
  8636. target->SetZ(z);
  8637. target->SetHeading(h);
  8638. target->SetSpawnOrigX(target->GetX());
  8639. target->SetSpawnOrigY(target->GetY());
  8640. target->SetSpawnOrigZ(target->GetZ());
  8641. target->SetSpawnOrigHeading(target->GetHeading());
  8642. if (target->IsPlayer()) {
  8643. Client* client = target->GetZone()->GetClientBySpawn(target);
  8644. if (client) {
  8645. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8646. if (packet)
  8647. {
  8648. packet->setDataByName("x", x);
  8649. packet->setDataByName("y", y);
  8650. packet->setDataByName("z", z);
  8651. client->QueuePacket(packet->serialize());
  8652. safe_delete(packet);
  8653. }
  8654. }
  8655. }
  8656. }
  8657. else {
  8658. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8659. ZoneServer* zone = spell->caster->GetZone();
  8660. float x = spell->caster->GetZone()->GetSafeX();
  8661. float y = spell->caster->GetZone()->GetSafeY();
  8662. float z = spell->caster->GetZone()->GetSafeZ();
  8663. float h = spell->caster->GetZone()->GetSafeHeading();
  8664. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8665. for (int32 i = 0; i < spell->targets.size(); i++) {
  8666. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8667. if (!target2)
  8668. continue;
  8669. target2->SetX(x);
  8670. target2->SetY(y);
  8671. target2->SetZ(z);
  8672. target2->SetHeading(h);
  8673. target2->SetSpawnOrigX(target2->GetX());
  8674. target2->SetSpawnOrigY(target2->GetY());
  8675. target2->SetSpawnOrigZ(target2->GetZ());
  8676. target2->SetSpawnOrigHeading(target2->GetHeading());
  8677. if (target2->IsPlayer()) {
  8678. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8679. if (client) {
  8680. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8681. if (packet)
  8682. {
  8683. packet->setDataByName("x", x);
  8684. packet->setDataByName("y", y);
  8685. packet->setDataByName("z", z);
  8686. client->QueuePacket(packet->serialize());
  8687. safe_delete(packet);
  8688. }
  8689. }
  8690. }
  8691. }
  8692. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8693. }
  8694. return 0;
  8695. }
  8696. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8697. if (!lua_interface)
  8698. return 0;
  8699. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8700. if (!luaspell) {
  8701. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8702. return 0;
  8703. }
  8704. int8 tier = luaspell->spell->GetSpellTier();
  8705. lua_interface->SetInt32Value(state, tier);
  8706. return 1;
  8707. }
  8708. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8709. if (!lua_interface)
  8710. return 0;
  8711. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8712. if (!luaspell) {
  8713. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8714. return 0;
  8715. }
  8716. int32 spell_id = luaspell->spell->GetSpellID();
  8717. lua_interface->SetInt32Value(state, spell_id);
  8718. return 1;
  8719. }
  8720. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8721. if (!lua_interface)
  8722. return 0;
  8723. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8724. if (!spawn) {
  8725. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8726. return 0;
  8727. }
  8728. if (!spawn->IsPlayer()) {
  8729. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8730. return 0;
  8731. }
  8732. ZoneServer* zone = spawn->GetZone();
  8733. if (!zone) {
  8734. return 0;
  8735. }
  8736. Client* client = zone->GetClientBySpawn(spawn);
  8737. if (!client) {
  8738. return 0;
  8739. }
  8740. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8741. return 0;
  8742. }
  8743. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8744. if (!lua_interface)
  8745. return 0;
  8746. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8747. if (!spawn) {
  8748. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8749. return 0;
  8750. }
  8751. if (!spawn->IsPlayer()) {
  8752. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8753. return 0;
  8754. }
  8755. ZoneServer* zone = spawn->GetZone();
  8756. if (!zone) {
  8757. return 0;
  8758. }
  8759. Client* client = zone->GetClientBySpawn(spawn);
  8760. if (!client) {
  8761. return 0;
  8762. }
  8763. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8764. return 0;
  8765. }
  8766. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8767. if (!lua_interface)
  8768. return 0;
  8769. Spawn* caster = lua_interface->GetSpawn(state);
  8770. Spawn* target = lua_interface->GetSpawn(state, 2);
  8771. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8772. string spell_name = lua_interface->GetStringValue(state, 4);
  8773. if (!caster) {
  8774. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8775. return 0;
  8776. }
  8777. if (!caster->IsEntity()) {
  8778. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8779. return 0;
  8780. }
  8781. if (!target) {
  8782. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8783. return 0;
  8784. }
  8785. if (!target->IsEntity()) {
  8786. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8787. return 0;
  8788. }
  8789. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8790. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8791. return 0;
  8792. }
  8793. int EQ2Emu_lua_AddLootToObject(lua_State* state) {
  8794. if (!lua_interface)
  8795. return 0;
  8796. Spawn* object = lua_interface->GetSpawn(state);
  8797. Spawn* player = lua_interface->GetSpawn(state, 2);
  8798. if (object && player && player->IsPlayer()) {
  8799. int32 coins = lua_interface->GetInt32Value(state, 3);
  8800. vector<Item*>* items = 0;
  8801. int i = 0;
  8802. int32 item_id = 0;
  8803. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  8804. if (items == 0)
  8805. items = new vector<Item*>;
  8806. if (master_item_list.GetItem(item_id))
  8807. items->push_back(master_item_list.GetItem(item_id));
  8808. i++;
  8809. }
  8810. Client* client = 0;
  8811. client = object->GetZone()->GetClientBySpawn(player);
  8812. if (client) {
  8813. ((Player*)player)->AddPendingLootItems(object->GetID(), items);
  8814. }
  8815. safe_delete(items);
  8816. }
  8817. return 0;
  8818. }
  8819. int EQ2Emu_lua_GiveExp(lua_State* state) {
  8820. if (!lua_interface)
  8821. return 0;
  8822. Spawn* player = lua_interface->GetSpawn(state);
  8823. int32 amount = lua_interface->GetInt32Value(state, 2);
  8824. if (player && player->IsPlayer() && amount > 0) {
  8825. ((Player*)player)->AddXP(amount);
  8826. ((Player*)player)->SetCharSheetChanged(true);
  8827. Client* client = player->GetZone()->GetClientBySpawn(player);
  8828. if (client) {
  8829. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  8830. }
  8831. }
  8832. return 0;
  8833. }
  8834. int EQ2Emu_lua_DisplayText(lua_State* state) {
  8835. if (!lua_interface)
  8836. return 0;
  8837. Spawn* player = lua_interface->GetSpawn(state);
  8838. int8 type = lua_interface->GetInt8Value(state, 2);
  8839. string text = lua_interface->GetStringValue(state, 3);
  8840. Client* client = 0;
  8841. if (player && player->IsPlayer())
  8842. client = player->GetZone()->GetClientBySpawn(player);
  8843. if (!client || text.length() == 0) {
  8844. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  8845. return 0;
  8846. }
  8847. client->SimpleMessage(type, text.c_str());
  8848. return 0;
  8849. }
  8850. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  8851. if (!lua_interface)
  8852. return 0;
  8853. Spawn* player = lua_interface->GetSpawn(state);
  8854. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8855. Client* client = 0;
  8856. if (player && player->IsPlayer())
  8857. client = player->GetZone()->GetClientBySpawn(player);
  8858. if (!client || !spawn) {
  8859. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  8860. return 0;
  8861. }
  8862. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  8863. if (!items) {
  8864. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  8865. return 0;
  8866. }
  8867. client->Loot(spawn->GetLootCoins(), items, spawn);
  8868. return 0;
  8869. }
  8870. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  8871. if (!lua_interface)
  8872. return 0;
  8873. Spawn* spawnref = lua_interface->GetSpawn(state);
  8874. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8875. if (spawn_id > 0 && spawnref) {
  8876. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  8877. if (spawns.size() == 0) {
  8878. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8879. return 0;
  8880. }
  8881. Spawn* spawn = 0;
  8882. int16 index = MakeRandomInt(0, spawns.size());
  8883. if (index >= spawns.size() || index < 0)
  8884. index = 0;
  8885. spawn = spawns[index];
  8886. lua_interface->SetSpawnValue(state, spawn);
  8887. return 1;
  8888. }
  8889. else {
  8890. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  8891. }
  8892. return 0;
  8893. }
  8894. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  8895. Spawn* player = lua_interface->GetSpawn(state);
  8896. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  8897. string name = lua_interface->GetStringValue(state, 3);
  8898. float distance = lua_interface->GetFloatValue(state, 4);
  8899. string command = lua_interface->GetStringValue(state, 5);
  8900. string error_text = lua_interface->GetStringValue(state, 6);
  8901. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  8902. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  8903. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  8904. if (distance == 0)
  8905. distance = 10.0f;
  8906. if (command.length() == 0)
  8907. command = name;
  8908. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  8909. if (spawns.size() == 0) {
  8910. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  8911. return 0;
  8912. }
  8913. Spawn* spawn = 0;
  8914. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  8915. spawn = *itr;
  8916. if (spawn) {
  8917. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  8918. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  8919. }
  8920. }
  8921. }
  8922. return 0;
  8923. }
  8924. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  8925. if (!lua_interface)
  8926. return 0;
  8927. Client* client = 0;
  8928. Spawn* player = lua_interface->GetSpawn(state);
  8929. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  8930. if (player && player->IsPlayer() && player->GetZone())
  8931. client = player->GetZone()->GetClientBySpawn(player);
  8932. else{
  8933. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  8934. return 0;
  8935. }
  8936. if (client) {
  8937. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  8938. if (packet) {
  8939. packet->setDataByName("goal_num", goal_num);
  8940. client->QueuePacket(packet->serialize());
  8941. safe_delete(packet);
  8942. }
  8943. }
  8944. return 0;
  8945. }
  8946. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  8947. if (!lua_interface)
  8948. return 0;
  8949. Client* client = 0;
  8950. Spawn* player = lua_interface->GetSpawn(state);
  8951. if (player && player->IsPlayer() && player->GetZone())
  8952. client = player->GetZone()->GetClientBySpawn(player);
  8953. else {
  8954. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  8955. return 0;
  8956. }
  8957. if (client) {
  8958. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  8959. }
  8960. return 0;
  8961. }
  8962. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  8963. if (!lua_interface)
  8964. return 0;
  8965. Client* client = 0;
  8966. Spawn* player = lua_interface->GetSpawn(state);
  8967. float duration = lua_interface->GetFloatValue(state, 2);
  8968. string text = lua_interface->GetStringValue(state, 3);
  8969. string voice = lua_interface->GetStringValue(state, 4);
  8970. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  8971. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  8972. string signal = lua_interface->GetStringValue(state, 7);
  8973. string goal1 = lua_interface->GetStringValue(state, 8);
  8974. string task1 = lua_interface->GetStringValue(state, 9);
  8975. string goal2 = lua_interface->GetStringValue(state, 10);
  8976. string task2 = lua_interface->GetStringValue(state, 11);
  8977. string goal3 = lua_interface->GetStringValue(state, 12);
  8978. string task3 = lua_interface->GetStringValue(state, 13);
  8979. string goal4 = lua_interface->GetStringValue(state, 14);
  8980. string task4 = lua_interface->GetStringValue(state, 15);
  8981. if (!player) {
  8982. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  8983. return 0;
  8984. }
  8985. if (!player->IsPlayer()) {
  8986. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  8987. return 0;
  8988. }
  8989. else
  8990. client = ((Player*)player)->GetClient();
  8991. if (!client) {
  8992. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  8993. return 0;
  8994. }
  8995. if (text.length() == 0) {
  8996. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  8997. return 0;
  8998. }
  8999. if (duration >= 0 && duration < 2)
  9000. duration = 2;
  9001. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9002. if (packet) {
  9003. packet->setDataByName("open_seconds_max", duration);
  9004. packet->setDataByName("text", text.c_str());
  9005. packet->setDataByName("voice", voice.c_str());
  9006. int8 num_goals = 1;
  9007. if (task2.length() > 0)
  9008. num_goals++;
  9009. if (task3.length() > 0)
  9010. num_goals++;
  9011. if (task4.length() > 0)
  9012. num_goals++;
  9013. packet->setArrayLengthByName("num_goals", num_goals);
  9014. for (int8 i = 0; i < num_goals; i++) {
  9015. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9016. }
  9017. if (goal1.length() > 0)
  9018. packet->setArrayDataByName("goal_text", goal1.c_str());
  9019. if (goal2.length() > 0)
  9020. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9021. if (goal3.length() > 0)
  9022. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9023. if (goal4.length() > 0)
  9024. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9025. packet->setSubArrayDataByName("task_text", task1.c_str());
  9026. if (task2.length() > 0)
  9027. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9028. if (task3.length() > 0)
  9029. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9030. if (task4.length() > 0)
  9031. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9032. packet->setDataByName("complete_sound", "click");
  9033. packet->setDataByName("signal", signal.c_str());
  9034. packet->setDataByName("voice_key1", voice_key1);
  9035. packet->setDataByName("voice_key2", voice_key2);
  9036. client->QueuePacket(packet->serialize());
  9037. safe_delete(packet);
  9038. }
  9039. return 0;
  9040. }
  9041. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9042. if (!lua_interface)
  9043. return 0;
  9044. Client* client = 0;
  9045. Spawn* player = lua_interface->GetSpawn(state);
  9046. string window = lua_interface->GetStringValue(state, 2);
  9047. int8 show = lua_interface->GetInt8Value(state, 3);
  9048. if (!player) {
  9049. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9050. return 0;
  9051. }
  9052. if (!player->IsPlayer()) {
  9053. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9054. return 0;
  9055. }
  9056. else
  9057. client = ((Player*)player)->GetClient();
  9058. if (!client) {
  9059. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9060. return 0;
  9061. }
  9062. if (window.length() == 0) {
  9063. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9064. return 0;
  9065. }
  9066. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9067. if (packet) {
  9068. packet->setDataByName("window", window.c_str());
  9069. packet->setDataByName("show", show);
  9070. client->QueuePacket(packet->serialize());
  9071. safe_delete(packet);
  9072. }
  9073. return 0;
  9074. }
  9075. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9076. //See GameEvents.txt for options that can be used for this function
  9077. if (!lua_interface)
  9078. return 0;
  9079. Client* client = 0;
  9080. Spawn* player = lua_interface->GetSpawn(state);
  9081. string event_name = lua_interface->GetStringValue(state, 2);
  9082. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9083. if (!player || !player->IsPlayer()) {
  9084. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9085. return 0;
  9086. }
  9087. if (player->GetZone())
  9088. client = player->GetZone()->GetClientBySpawn(player);
  9089. if (!client) {
  9090. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9091. return 0;
  9092. }
  9093. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9094. if (packet) {
  9095. packet->setDataByName("event_name", event_name.c_str());
  9096. packet->setDataByName("enabled", enabled);
  9097. client->QueuePacket(packet->serialize());
  9098. safe_delete(packet);
  9099. }
  9100. return 0;
  9101. }
  9102. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9103. if (!lua_interface)
  9104. return 0;
  9105. Spawn* player = lua_interface->GetSpawn(state);
  9106. if (player && player->IsPlayer()) {
  9107. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9108. return 1;
  9109. }
  9110. return 0;
  9111. }
  9112. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9113. if (!lua_interface)
  9114. return 0;
  9115. Spawn* player = lua_interface->GetSpawn(state);
  9116. int8 step = lua_interface->GetInt8Value(state, 2);
  9117. if (player && player->IsPlayer() && step > 0) {
  9118. ((Player*)player)->SetTutorialStep(step);
  9119. }
  9120. return 0;
  9121. }
  9122. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9123. if (!lua_interface)
  9124. return 0;
  9125. Client* client = 0;
  9126. Spawn* player = lua_interface->GetSpawn(state);
  9127. string window = lua_interface->GetStringValue(state, 2);
  9128. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9129. if (!player) {
  9130. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9131. return 0;
  9132. }
  9133. if (!player->IsPlayer()) {
  9134. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9135. return 0;
  9136. }
  9137. else
  9138. client = ((Player*)player)->GetClient();
  9139. if (!client) {
  9140. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9141. return 0;
  9142. }
  9143. if (window.length() == 0) {
  9144. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9145. return 0;
  9146. }
  9147. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9148. if (packet) {
  9149. packet->setDataByName("window", window.c_str());
  9150. packet->setDataByName("flash_seconds", flash_seconds);
  9151. client->QueuePacket(packet->serialize());
  9152. safe_delete(packet);
  9153. }
  9154. return 0;
  9155. }
  9156. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9157. if (!lua_interface)
  9158. return 0;
  9159. Spawn* spawn = lua_interface->GetSpawn(state);
  9160. Spawn* target = lua_interface->GetSpawn(state, 2);
  9161. if (spawn && target)
  9162. return spawn->CheckLoS(target);
  9163. return 0;
  9164. }
  9165. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9166. if (!lua_interface)
  9167. return 0;
  9168. Spawn* spawn = lua_interface->GetSpawn(state);
  9169. float x = lua_interface->GetFloatValue(state, 2);
  9170. float y = lua_interface->GetFloatValue(state, 3);
  9171. float z = lua_interface->GetFloatValue(state, 4);
  9172. if (spawn)
  9173. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9174. return 0;
  9175. }
  9176. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9177. if (!lua_interface)
  9178. return 0;
  9179. ZoneServer* zone = lua_interface->GetZone(state);
  9180. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9181. if (zone)
  9182. zone->SetExpansionFlag(xpackFlag);
  9183. return 0;
  9184. }
  9185. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9186. if (!lua_interface)
  9187. return 0;
  9188. ZoneServer* zone = lua_interface->GetZone(state);
  9189. if (zone) {
  9190. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9191. return 1;
  9192. }
  9193. return 0;
  9194. }
  9195. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9196. if (!lua_interface)
  9197. return 0;
  9198. ZoneServer* zone = lua_interface->GetZone(state);
  9199. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9200. if (zone)
  9201. zone->SetHolidayFlag(holidayFlag);
  9202. return 0;
  9203. }
  9204. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9205. if (!lua_interface)
  9206. return 0;
  9207. ZoneServer* zone = lua_interface->GetZone(state);
  9208. if (zone) {
  9209. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9210. return 1;
  9211. }
  9212. return 0;
  9213. }
  9214. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9215. if (!lua_interface)
  9216. return 0;
  9217. Spawn* spawn = lua_interface->GetSpawn(state);
  9218. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9219. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9220. float distance = lua_interface->GetFloatValue(state, 4);
  9221. string in_range_function = lua_interface->GetStringValue(state, 5);
  9222. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9223. if (spawn && distance > 0 && in_range_function.length() > 0)
  9224. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9225. return 0;
  9226. }
  9227. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9228. if (!lua_interface)
  9229. return 0;
  9230. Spawn* spawn = lua_interface->GetSpawn(state);
  9231. Spawn* target = lua_interface->GetSpawn(state, 2);
  9232. if (spawn && target)
  9233. {
  9234. if (spawn->IsPlayer() && target->IsEntity())
  9235. {
  9236. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9237. return 1;
  9238. }
  9239. else if (spawn->IsEntity() && target->IsEntity())
  9240. {
  9241. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9242. return 1;
  9243. }
  9244. }
  9245. return 0;
  9246. }
  9247. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9248. if (!lua_interface)
  9249. return 0;
  9250. Spawn* spawn = lua_interface->GetSpawn(state);
  9251. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9252. if (spawn && spawn->IsEntity())
  9253. {
  9254. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9255. if (spawn->IsPlayer())
  9256. {
  9257. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9258. if (client)
  9259. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9260. }
  9261. }
  9262. return 0;
  9263. }
  9264. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9265. if (!lua_interface)
  9266. return 0;
  9267. Spawn* spawn = lua_interface->GetSpawn(state);
  9268. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9269. if (spawn && spawn->IsEntity())
  9270. {
  9271. ((Entity*)spawn)->SetSeeHideSpell(val);
  9272. if (spawn->IsPlayer())
  9273. {
  9274. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9275. if (client)
  9276. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9277. }
  9278. }
  9279. return 0;
  9280. }
  9281. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9282. {
  9283. if (!lua_interface)
  9284. return 0;
  9285. Spawn* player = lua_interface->GetSpawn(state);
  9286. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9287. string command = lua_interface->GetStringValue(state, 3);
  9288. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9289. if (spawn && player && player->IsPlayer())
  9290. {
  9291. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9292. bool res = false;
  9293. if (cmd)
  9294. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9295. lua_interface->SetBooleanValue(state, res);
  9296. return 1;
  9297. }
  9298. return 0;
  9299. }
  9300. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9301. {
  9302. if (!lua_interface)
  9303. return 0;
  9304. Spawn* spawn = lua_interface->GetSpawn(state);
  9305. string command = lua_interface->GetStringValue(state, 2);
  9306. if (spawn && command.length() > 0)
  9307. spawn->RemovePrimaryEntityCommand(command.c_str());
  9308. return 0;
  9309. }
  9310. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9311. if (!lua_interface)
  9312. return 0;
  9313. Spawn* spawn = lua_interface->GetSpawn(state);
  9314. float distance = lua_interface->GetFloatValue(state, 2);
  9315. string command = lua_interface->GetStringValue(state, 3);
  9316. Spawn* player = lua_interface->GetSpawn(state, 4);
  9317. if (spawn) {
  9318. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9319. }
  9320. return 0;
  9321. }
  9322. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9323. if (!lua_interface)
  9324. return 0;
  9325. Spawn* spawn = lua_interface->GetSpawn(state);
  9326. Spawn* player = lua_interface->GetSpawn(state, 2);
  9327. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9328. if (spawn && player && transport_id && player->IsPlayer()) {
  9329. Client* client = 0;
  9330. if (player && player->IsPlayer())
  9331. client = player->GetZone()->GetClientBySpawn(player);
  9332. if (!client)
  9333. return 0;
  9334. vector<TransportDestination*> destinations;
  9335. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9336. if (destinations.size())
  9337. {
  9338. client->SetTemporaryTransportID(transport_id);
  9339. client->ProcessTeleport(spawn, &destinations, transport_id);
  9340. }
  9341. else
  9342. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9343. }
  9344. return 0;
  9345. }
  9346. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9347. if (!lua_interface)
  9348. return 0;
  9349. Spawn* player = lua_interface->GetSpawn(state);
  9350. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9351. if (player && player->IsPlayer()) {
  9352. Client* client = 0;
  9353. if (player && player->IsPlayer())
  9354. client = player->GetZone()->GetClientBySpawn(player);
  9355. if (!client)
  9356. return 0;
  9357. client->SetTemporaryTransportID(transport_id);
  9358. }
  9359. return 0;
  9360. }
  9361. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9362. if (!lua_interface)
  9363. return 0;
  9364. Spawn* player = lua_interface->GetSpawn(state);
  9365. if (player && player->IsPlayer()) {
  9366. Client* client = 0;
  9367. if (player && player->IsPlayer())
  9368. client = player->GetZone()->GetClientBySpawn(player);
  9369. if (!client)
  9370. return 0;
  9371. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9372. return 1;
  9373. }
  9374. return 0;
  9375. }
  9376. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9377. if (!lua_interface)
  9378. return 0;
  9379. Spawn* spawn = lua_interface->GetSpawn(state);
  9380. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9381. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9382. if (!spawn) {
  9383. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9384. return 0;
  9385. }
  9386. if (!spawn->IsEntity()) {
  9387. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9388. return 0;
  9389. }
  9390. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9391. {
  9392. 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);
  9393. return 0;
  9394. }
  9395. if (spell && spell->targets.size() > 0) {
  9396. ZoneServer* zone = spell->caster->GetZone();
  9397. for (int8 i = 0; i < spell->targets.size(); i++) {
  9398. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9399. if (target->IsEntity()) {
  9400. ((Entity*)target)->GetInfoStruct()->alignment = (sint8)alignment;
  9401. if (target->IsPlayer())
  9402. ((Player*)target)->SetCharSheetChanged(true);
  9403. }
  9404. }
  9405. }
  9406. else {
  9407. ((Entity*)spawn)->GetInfoStruct()->alignment = (sint8)alignment;
  9408. if (spawn->IsPlayer())
  9409. ((Player*)spawn)->SetCharSheetChanged(true);
  9410. }
  9411. return 0;
  9412. }
  9413. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9414. if (!lua_interface)
  9415. return 0;
  9416. Spawn* spawn = lua_interface->GetSpawn(state);
  9417. if (!spawn) {
  9418. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9419. return 0;
  9420. }
  9421. if (!spawn->IsEntity()) {
  9422. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9423. return 0;
  9424. }
  9425. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9426. return 1;
  9427. }
  9428. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9429. if (!lua_interface)
  9430. return 0;
  9431. int32 spell_id = lua_interface->GetInt32Value(state);
  9432. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9433. if (spell_id > 0) {
  9434. if (spell_tier == 0)
  9435. spell_tier = 1;
  9436. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9437. LuaSpell* lua_spell = 0;
  9438. if (lua_interface)
  9439. lua_spell = lua_interface->GetSpell(spell->GetSpellData()->lua_script.c_str());
  9440. if (!lua_spell)
  9441. return 0;
  9442. lua_spell->spell = new Spell(spell);
  9443. lua_interface->AddCustomSpell(lua_spell);
  9444. lua_interface->SetSpellValue(state, lua_spell);
  9445. return 1;
  9446. }
  9447. return 0;
  9448. }
  9449. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9450. if (!lua_interface)
  9451. return 0;
  9452. LuaSpell* spell = lua_interface->GetSpell(state);
  9453. string field = lua_interface->GetStringValue(state, 2);
  9454. if (!spell) {
  9455. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9456. return 0;
  9457. }
  9458. if (!spell->spell || !spell->spell->GetSpellData()) {
  9459. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9460. return 0;
  9461. }
  9462. boost::to_lower(field);
  9463. return spell->spell->GetSpellData(state, field);
  9464. }
  9465. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9466. if (!lua_interface)
  9467. return 0;
  9468. LuaSpell* spell = lua_interface->GetSpell(state);
  9469. string field = lua_interface->GetStringValue(state, 2);
  9470. int8 fieldArg = 3; // field value after the initial set
  9471. if (!spell) {
  9472. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9473. return 0;
  9474. }
  9475. if (!spell->spell || !spell->spell->GetSpellData()) {
  9476. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9477. return 0;
  9478. }
  9479. boost::to_lower(field);
  9480. bool valSet = false;
  9481. spell->spell->SetSpellData(state, field, fieldArg);
  9482. return valSet;
  9483. }
  9484. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9485. if (!lua_interface)
  9486. return 0;
  9487. LuaSpell* spell = lua_interface->GetSpell(state);
  9488. int8 idx = lua_interface->GetInt32Value(state, 2);
  9489. if (!spell) {
  9490. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9491. return 0;
  9492. }
  9493. if (!spell->spell || !spell->spell->GetSpellData()) {
  9494. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9495. return 0;
  9496. }
  9497. if (spell->spell->lua_data.size() <= idx)
  9498. {
  9499. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9500. return 0;
  9501. }
  9502. bool setVal = true;
  9503. LUAData* data = spell->spell->lua_data[idx];
  9504. switch (data->type)
  9505. {
  9506. case 0:
  9507. {
  9508. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9509. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9510. data->int_value = value;
  9511. data->int_value2 = value2;
  9512. break;
  9513. }
  9514. case 1:
  9515. {
  9516. float value = lua_interface->GetFloatValue(state, 3);
  9517. float value2 = lua_interface->GetFloatValue(state, 4);
  9518. data->float_value = value;
  9519. data->float_value2 = value2;
  9520. break;
  9521. }
  9522. case 2:
  9523. {
  9524. bool value = lua_interface->GetBooleanValue(state, 3);
  9525. data->bool_value = value;
  9526. break;
  9527. }
  9528. case 3:
  9529. {
  9530. string value = lua_interface->GetStringValue(state, 3);
  9531. string value2 = lua_interface->GetStringValue(state, 4);
  9532. data->string_value = value;
  9533. data->string_value2 = value2;
  9534. break;
  9535. }
  9536. default:
  9537. setVal = false;
  9538. }
  9539. return setVal;
  9540. }
  9541. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9542. if (!lua_interface)
  9543. return 0;
  9544. LuaSpell* spell = lua_interface->GetSpell(state);
  9545. int8 idx = lua_interface->GetInt32Value(state, 2);
  9546. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9547. if (!spell) {
  9548. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9549. return 0;
  9550. }
  9551. if (!spell->spell || !spell->spell->GetSpellData()) {
  9552. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9553. return 0;
  9554. }
  9555. if (spell->spell->lua_data.size() <= idx)
  9556. {
  9557. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9558. return 0;
  9559. }
  9560. bool setVal = true;
  9561. LUAData* data = spell->spell->lua_data[idx];
  9562. switch (data->type)
  9563. {
  9564. case 0:
  9565. {
  9566. if(!secondfield)
  9567. lua_interface->SetSInt32Value(state, data->int_value);
  9568. else
  9569. lua_interface->SetSInt32Value(state, data->int_value2);
  9570. break;
  9571. }
  9572. case 1:
  9573. {
  9574. if (!secondfield)
  9575. lua_interface->SetFloatValue(state, data->float_value);
  9576. else
  9577. lua_interface->SetFloatValue(state, data->float_value2);
  9578. break;
  9579. }
  9580. case 2:
  9581. {
  9582. lua_interface->SetBooleanValue(state, data->bool_value);
  9583. break;
  9584. }
  9585. case 3:
  9586. {
  9587. if (!secondfield)
  9588. lua_interface->SetStringValue(state, data->string_value.c_str());
  9589. else
  9590. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9591. break;
  9592. }
  9593. default:
  9594. setVal = false;
  9595. }
  9596. return setVal;
  9597. }
  9598. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9599. if (!lua_interface)
  9600. return 0;
  9601. LuaSpell* spell = lua_interface->GetSpell(state);
  9602. int8 idx = lua_interface->GetInt32Value(state, 2);
  9603. string field = lua_interface->GetStringValue(state, 3);
  9604. boost::to_lower(field);
  9605. if (!spell) {
  9606. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9607. return 0;
  9608. }
  9609. if (!spell->spell || !spell->spell->GetSpellData()) {
  9610. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9611. return 0;
  9612. }
  9613. if (spell->spell->effects.size() <= idx)
  9614. {
  9615. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9616. return 0;
  9617. }
  9618. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9619. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9620. if (field == "description")
  9621. effect->description = string(lua_interface->GetStringValue(state, 4));
  9622. else if (field == "bullet")
  9623. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9624. else if (field == "percentage")
  9625. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9626. else // no match
  9627. return 0;
  9628. return 1;
  9629. }
  9630. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9631. if (!lua_interface)
  9632. return 0;
  9633. LuaSpell* spell = lua_interface->GetSpell(state);
  9634. int8 idx = lua_interface->GetInt32Value(state, 2);
  9635. string field = lua_interface->GetStringValue(state, 3);
  9636. boost::to_lower(field);
  9637. if (!spell) {
  9638. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9639. return 0;
  9640. }
  9641. if (!spell->spell || !spell->spell->GetSpellData()) {
  9642. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9643. return 0;
  9644. }
  9645. if (spell->spell->effects.size() <= idx)
  9646. {
  9647. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9648. return 0;
  9649. }
  9650. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9651. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9652. if (field == "description")
  9653. lua_interface->SetStringValue(state, effect->description.c_str());
  9654. else if (field == "bullet")
  9655. lua_interface->SetInt32Value(state, effect->subbullet);
  9656. else if (field == "percentage")
  9657. lua_interface->SetInt32Value(state, effect->percentage);
  9658. else // no match
  9659. return 0;
  9660. return 1;
  9661. }
  9662. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9663. if (!lua_interface)
  9664. return 0;
  9665. LuaSpell* spell = lua_interface->GetSpell(state);
  9666. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9667. Spawn* target = lua_interface->GetSpawn(state, 3);
  9668. if (!target) {
  9669. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9670. return 0;
  9671. }
  9672. if (!target->IsEntity()) {
  9673. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9674. return 0;
  9675. }
  9676. if (!spell) {
  9677. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9678. return 0;
  9679. }
  9680. if (caster && !caster->IsEntity()) {
  9681. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9682. return 0;
  9683. }
  9684. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9685. return 0;
  9686. }
  9687. int EQ2Emu_lua_InWater(lua_State* state) {
  9688. if (!lua_interface)
  9689. return 0;
  9690. Spawn* spawn = lua_interface->GetSpawn(state);
  9691. if (spawn) {
  9692. lua_interface->SetBooleanValue(state, spawn->InWater());
  9693. return 1;
  9694. }
  9695. return 0;
  9696. }
  9697. int EQ2Emu_lua_InLava(lua_State* state) {
  9698. if (!lua_interface)
  9699. return 0;
  9700. Spawn* spawn = lua_interface->GetSpawn(state);
  9701. if (spawn) {
  9702. lua_interface->SetBooleanValue(state, spawn->InLava());
  9703. return 1;
  9704. }
  9705. return 0;
  9706. }
  9707. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9708. if (!lua_interface)
  9709. return 0;
  9710. Spawn* attacker = lua_interface->GetSpawn(state);
  9711. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9712. int8 type = lua_interface->GetInt8Value(state, 3);
  9713. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9714. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9715. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9716. string spell_name = lua_interface->GetStringValue(state, 7);
  9717. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9718. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9719. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9720. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9721. if (!attacker) {
  9722. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9723. return 0;
  9724. }
  9725. if (!attacker->IsEntity()) {
  9726. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9727. return 0;
  9728. }
  9729. if (!victim) {
  9730. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9731. return 0;
  9732. }
  9733. if (!victim->IsEntity()) {
  9734. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9735. return 0;
  9736. }
  9737. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9738. return 0;
  9739. }
  9740. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9741. if (!lua_interface)
  9742. return 0;
  9743. Spawn* spawn = lua_interface->GetSpawn(state);
  9744. if (spawn) {
  9745. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9746. return 1;
  9747. }
  9748. return 0;
  9749. }
  9750. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  9751. if (!lua_interface)
  9752. return 0;
  9753. string category = lua_interface->GetStringValue(state);
  9754. string name = lua_interface->GetStringValue(state, 2);
  9755. Rule *ret = 0;
  9756. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  9757. lua_interface->SetInt32Value(state, ret->GetInt32());
  9758. return 1;
  9759. }
  9760. lua_interface->LogError("%s: LUA GetRuleFlag Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  9761. return 0;
  9762. }