LuaFunctions.cpp 281 KB

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