LuaFunctions.cpp 312 KB

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