LuaFunctions.cpp 388 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = spawn->GetZone()->GetClientBySpawn(player);
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlaySound(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. string sound_string = lua_interface->GetStringValue(state, 2);
  183. float x = lua_interface->GetFloatValue(state, 3);
  184. float y = lua_interface->GetFloatValue(state, 4);
  185. float z = lua_interface->GetFloatValue(state, 5);
  186. Spawn* player = lua_interface->GetSpawn(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn && sound_string.length() > 0) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = spawn->GetZone()->GetClientBySpawn(player);
  192. if (client)
  193. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  194. else
  195. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  196. }
  197. return 0;
  198. }
  199. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  200. if (!lua_interface)
  201. return 0;
  202. Spawn* spawn = lua_interface->GetSpawn(state);
  203. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  204. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  205. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  206. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  207. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  208. lua_interface->ResetFunctionStack(state);
  209. if (!spawn) {
  210. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  211. return 0;
  212. }
  213. if (quest_id > 0) {
  214. //Add this quest to the list of required quests for this spawn
  215. spawn->SetQuestsRequired(quest_id, quest_step);
  216. //If private spawn value set
  217. if (private_spawn) {
  218. //Set the spawn to be private when not granted access through this quest
  219. spawn->AddAllowAccessSpawn(spawn);
  220. spawn->SetPrivateQuestSpawn(true);
  221. }
  222. //This value allows access after a quest step, or the whole quest has been completed
  223. if (continued_access)
  224. spawn->SetQuestsRequiredContinuedAccess(true);
  225. //This value will override vis_flags in the vis packet
  226. if (flag_override > 0)
  227. spawn->SetQuestsRequiredOverride(flag_override);
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. Spawn* spawn = lua_interface->GetSpawn(state);
  235. float max_distance = lua_interface->GetFloatValue(state, 2);
  236. string variable = lua_interface->GetStringValue(state, 3);
  237. string value = lua_interface->GetStringValue(state, 4);
  238. lua_interface->ResetFunctionStack(state);
  239. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  240. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  241. return 0;
  242. }
  243. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  244. if (!lua_interface)
  245. return 0;
  246. Client* client = 0;
  247. Spawn* player = lua_interface->GetSpawn(state);
  248. if (!player) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  250. return 0;
  251. }
  252. if (!player->IsPlayer()) {
  253. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  254. return 0;
  255. }
  256. if (player->GetZone())
  257. client = player->GetZone()->GetClientBySpawn(player);
  258. if (!client) {
  259. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  260. return 0;
  261. }
  262. float intensity = lua_interface->GetFloatValue(state, 2);
  263. int8 direction = lua_interface->GetInt8Value(state, 3);
  264. lua_interface->ResetFunctionStack(state);
  265. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  266. if (packet) {
  267. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  268. v1 = *(float *)(a1 + 4);
  269. if ( v1 > 0.0 )
  270. v2 = fminf(v1, 1.0);
  271. else
  272. v2 = 0.1;
  273. */
  274. packet->setDataByName("intensity", intensity);
  275. if ( client->GetVersion() > 546 )
  276. packet->setDataByName("direction", direction);
  277. client->QueuePacket(packet->serialize());
  278. safe_delete(packet);
  279. }
  280. return 0;
  281. }
  282. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  283. if (!lua_interface)
  284. return 0;
  285. Spawn* dead = lua_interface->GetSpawn(state);
  286. Spawn* killer = lua_interface->GetSpawn(state, 2);
  287. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  288. lua_interface->ResetFunctionStack(state);
  289. if (dead && dead->Alive() && dead->GetZone())
  290. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  291. return 0;
  292. }
  293. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  294. if (!lua_interface)
  295. return 0;
  296. Spawn* spawn = lua_interface->GetSpawn(state);
  297. float max_distance = lua_interface->GetFloatValue(state, 2);
  298. bool include_players = lua_interface->GetInt8Value(state, 3);
  299. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  300. lua_interface->ResetFunctionStack(state);
  301. if (max_distance > 0 && spawn && spawn->GetZone())
  302. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  303. return 0;
  304. }
  305. int EQ2Emu_lua_Despawn(lua_State* state) {
  306. if (!lua_interface)
  307. return 0;
  308. Spawn* spawn = lua_interface->GetSpawn(state);
  309. int32 delay = lua_interface->GetInt32Value(state, 2);
  310. lua_interface->ResetFunctionStack(state);
  311. if (spawn && spawn->GetZone())
  312. spawn->GetZone()->Despawn(spawn, delay);
  313. return 0;
  314. }
  315. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  316. if (!lua_interface)
  317. return 0;
  318. Spawn* spawn = lua_interface->GetSpawn(state);
  319. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  320. lua_interface->ResetFunctionStack(state);
  321. if (spawn) {
  322. spawn->info_changed = true;
  323. spawn->SetShowHandIcon(displayHandIcon);
  324. }
  325. return 0;
  326. }
  327. //this function is used to force an update packet to be sent.
  328. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  329. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  330. if (!lua_interface)
  331. return 0;
  332. Spawn* spawn = lua_interface->GetSpawn(state);
  333. lua_interface->ResetFunctionStack(state);
  334. if (spawn) {
  335. spawn->vis_changed = true;
  336. spawn->GetZone()->AddChangedSpawn(spawn);
  337. }
  338. return 0;
  339. }
  340. //this function is used to force an update packet to be sent.
  341. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  342. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. lua_interface->ResetFunctionStack(state);
  347. if (spawn) {
  348. spawn->info_changed = true;
  349. spawn->GetZone()->AddChangedSpawn(spawn);
  350. }
  351. return 0;
  352. }
  353. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  354. if (!lua_interface)
  355. return 0;
  356. Spawn* spawn = lua_interface->GetSpawn(state);
  357. int32 new_state = lua_interface->GetInt32Value(state, 2);
  358. Spawn* player = lua_interface->GetSpawn(state, 3);
  359. lua_interface->ResetFunctionStack(state);
  360. if (spawn) {
  361. if(player)
  362. {
  363. if(player->IsPlayer())
  364. {
  365. Client* client = ((Player*)player)->GetClient();
  366. if(client)
  367. {
  368. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  369. lua_interface->SetBooleanValue(state, true);
  370. return 1;
  371. }
  372. else
  373. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  374. }
  375. else
  376. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  377. }
  378. else
  379. {
  380. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  381. lua_interface->SetBooleanValue(state, true);
  382. return 1;
  383. }
  384. }
  385. lua_interface->SetBooleanValue(state, false);
  386. return 1;
  387. }
  388. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  389. if (!lua_interface)
  390. return 0;
  391. Spawn* spawn = lua_interface->GetSpawn(state);
  392. string variable = lua_interface->GetStringValue(state, 2);
  393. string value = lua_interface->GetStringValue(state, 3);
  394. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  395. bool temporary_flag = true;
  396. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  397. int8 index = 0;
  398. if(num_args >= 5)
  399. {
  400. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  401. index = lua_interface->GetInt8Value(state, 6);
  402. }
  403. lua_interface->ResetFunctionStack(state);
  404. int32 type = commands.GetSpawnSetType(variable);
  405. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  406. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  407. return 0;
  408. }
  409. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  410. if (!lua_interface)
  411. return 0;
  412. Spawn* spawn = lua_interface->GetSpawn(state);
  413. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  414. lua_interface->ResetFunctionStack(state);
  415. if (spawn && spawn_id > 0) {
  416. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  417. if (closest_spawn) {
  418. lua_interface->SetSpawnValue(state, closest_spawn);
  419. return 1;
  420. }
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. int32 position = lua_interface->GetInt32Value(state, 2);
  429. lua_interface->ResetFunctionStack(state);
  430. if (spawnList) {
  431. if (spawnList->size() > position) {
  432. lua_interface->SetSpawnValue(state, spawnList->at(position));
  433. return 1;
  434. }
  435. else {
  436. return 0;
  437. }
  438. return spawnList->size();
  439. }
  440. return 0;
  441. }
  442. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  443. if (!lua_interface)
  444. return 0;
  445. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  446. lua_interface->ResetFunctionStack(state);
  447. if (spawnList) {
  448. return spawnList->size();
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = new vector<Spawn*>();
  456. lua_interface->SetSpawnListValue(state, spawnList);
  457. return 1;
  458. }
  459. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  460. if (!lua_interface)
  461. return 0;
  462. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  463. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  464. lua_interface->ResetFunctionStack(state);
  465. if (spawnList) {
  466. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  467. if (it == spawnList->end())
  468. spawnList->push_back(spawn);
  469. }
  470. return 0;
  471. }
  472. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  473. if (!lua_interface)
  474. return 0;
  475. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  476. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  477. lua_interface->ResetFunctionStack(state);
  478. if (spawnList) {
  479. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  480. if(it != spawnList->end())
  481. spawnList->erase(it);
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* spawn = lua_interface->GetSpawn(state);
  489. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  490. lua_interface->ResetFunctionStack(state);
  491. if (spawn) {
  492. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  493. if (spawns.size() > 0) {
  494. vector<Spawn*>* spawnList = new vector<Spawn*>();
  495. vector<Spawn*>::iterator itr;
  496. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  497. spawnList->push_back(*itr);
  498. }
  499. lua_interface->SetSpawnListValue(state, spawnList);
  500. return 1;
  501. }
  502. }
  503. return 0;
  504. }
  505. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. Spawn* spawn = lua_interface->GetSpawn(state);
  509. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  510. lua_interface->ResetFunctionStack(state);
  511. if (spawn) {
  512. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  513. if (spawns.size() > 0) {
  514. vector<Spawn*>* spawnList = new vector<Spawn*>();
  515. vector<Spawn*>::iterator itr;
  516. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  517. spawnList->push_back(*itr);
  518. }
  519. lua_interface->SetSpawnListValue(state, spawnList);
  520. return 1;
  521. }
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  526. if (!lua_interface)
  527. return 0;
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. lua_interface->ResetFunctionStack(state);
  530. if (spawn) {
  531. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  532. if (spawns.size() > 0) {
  533. lua_createtable(state, spawns.size(), 0);
  534. int newTable = lua_gettop(state);
  535. for (int32 i = 0; i < spawns.size(); i++) {
  536. lua_interface->SetSpawnValue(state, spawns.at(i));
  537. lua_rawseti(state, newTable, i + 1);
  538. }
  539. return 1;
  540. }
  541. }
  542. return 0;
  543. }
  544. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  545. if (!lua_interface)
  546. return 0;
  547. string variable_name = lua_interface->GetStringValue(state);
  548. lua_interface->ResetFunctionStack(state);
  549. Variable* var = variables.FindVariable(variable_name);
  550. if (var) {
  551. lua_interface->SetStringValue(state, var->GetValue());
  552. return 1;
  553. }
  554. return 0;
  555. }
  556. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  557. if (!lua_interface)
  558. return 0;
  559. int32 total_coins = lua_interface->GetInt32Value(state);
  560. lua_interface->ResetFunctionStack(state);
  561. if (total_coins == 0) {
  562. lua_interface->SetStringValue(state, "0 copper");
  563. return 1;
  564. }
  565. char tmp[64] = { 0 };
  566. string message = "";
  567. int32 val = 0;
  568. if (total_coins >= 1000000) {
  569. val = total_coins / 1000000;
  570. total_coins -= 1000000 * val;
  571. sprintf(tmp, " %u Platinum", val);
  572. message.append(tmp);
  573. memset(tmp, 0, 64);
  574. }
  575. if (total_coins >= 10000) {
  576. val = total_coins / 10000;
  577. total_coins -= 10000 * val;
  578. sprintf(tmp, " %u Gold", val);
  579. message.append(tmp);
  580. memset(tmp, 0, 64);
  581. }
  582. if (total_coins >= 100) {
  583. val = total_coins / 100;
  584. total_coins -= 100 * val;
  585. sprintf(tmp, " %u Silver", val);
  586. message.append(tmp);
  587. memset(tmp, 0, 64);
  588. }
  589. if (total_coins > 0) {
  590. sprintf(tmp, " %u Copper", (int32)total_coins);
  591. message.append(tmp);
  592. }
  593. lua_interface->SetStringValue(state, message.c_str());
  594. return 1;
  595. }
  596. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  597. ZoneServer* zone = lua_interface->GetZone(state);
  598. int32 group_id = lua_interface->GetInt32Value(state, 2);
  599. lua_interface->ResetFunctionStack(state);
  600. if (zone) {
  601. Spawn* spawn = zone->GetSpawnGroup(group_id);
  602. if (spawn) {
  603. lua_interface->SetSpawnValue(state, spawn);
  604. return 1;
  605. }
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  610. ZoneServer* zone = lua_interface->GetZone(state);
  611. int32 location_id = lua_interface->GetInt32Value(state, 2);
  612. lua_interface->ResetFunctionStack(state);
  613. if (zone) {
  614. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  615. if (spawn) {
  616. lua_interface->SetSpawnValue(state, spawn);
  617. return 1;
  618. }
  619. }
  620. return 0;
  621. }
  622. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. lua_interface->ResetFunctionStack(state);
  625. if (spawn) {
  626. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  627. return 1;
  628. }
  629. return 0;
  630. }
  631. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  632. Spawn* spawn = lua_interface->GetSpawn(state);
  633. lua_interface->ResetFunctionStack(state);
  634. if (spawn) {
  635. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  636. return 1;
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  645. lua_interface->ResetFunctionStack(state);
  646. if (spawn) {
  647. spawn->SetSpawnGroupID(new_group_id);
  648. lua_interface->SetBooleanValue(state, true);
  649. return 1;
  650. }
  651. lua_interface->SetBooleanValue(state, false);
  652. return 1;
  653. }
  654. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  659. lua_interface->ResetFunctionStack(state);
  660. if (spawn) {
  661. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  662. lua_interface->SetBooleanValue(state, true);
  663. return 1;
  664. }
  665. lua_interface->SetBooleanValue(state, false);
  666. return 1;
  667. }
  668. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  669. Spawn* spawn = lua_interface->GetSpawn(state);
  670. lua_interface->ResetFunctionStack(state);
  671. if (spawn) {
  672. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  673. return 1;
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  678. Spawn* spawn = lua_interface->GetSpawn(state);
  679. lua_interface->ResetFunctionStack(state);
  680. if (spawn) {
  681. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  682. return 1;
  683. }
  684. return 0;
  685. }
  686. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  687. Player* player = (Player*)lua_interface->GetSpawn(state);
  688. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  689. lua_interface->ResetFunctionStack(state);
  690. if (player && player->IsPlayer() && faction_id > 0) {
  691. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  692. return 1;
  693. }
  694. return 0;
  695. }
  696. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  697. if (!lua_interface)
  698. return 0;
  699. Spawn* spawn = lua_interface->GetSpawn(state);
  700. int32 value = lua_interface->GetInt32Value(state, 2);
  701. lua_interface->ResetFunctionStack(state);
  702. if (spawn) {
  703. spawn->SetFactionID(value);
  704. }
  705. return 0;
  706. }
  707. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  708. Spawn* spawn = lua_interface->GetSpawn(state);
  709. lua_interface->ResetFunctionStack(state);
  710. if (spawn) {
  711. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. int EQ2Emu_lua_GetGender(lua_State* state) {
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. lua_interface->ResetFunctionStack(state);
  719. if (spawn) {
  720. lua_interface->SetInt32Value(state, spawn->GetGender());
  721. return 1;
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_GetTarget(lua_State* state) {
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. lua_interface->ResetFunctionStack(state);
  728. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  730. return 1;
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. Spawn* spawn = lua_interface->GetSpawn(state);
  738. string mp3_string = lua_interface->GetStringValue(state, 2);
  739. int32 key1 = lua_interface->GetInt32Value(state, 3);
  740. int32 key2 = lua_interface->GetInt32Value(state, 4);
  741. Spawn* player = lua_interface->GetSpawn(state, 5);
  742. lua_interface->ResetFunctionStack(state);
  743. if (spawn && mp3_string.length() > 0) {
  744. Client* client = 0;
  745. if (player && player->IsPlayer())
  746. client = spawn->GetZone()->GetClientBySpawn(player);
  747. if (client) {
  748. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  749. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  750. }
  751. else
  752. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  753. }
  754. return 0;
  755. }
  756. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  757. if (!lua_interface)
  758. return 0;
  759. Spawn* spawn = lua_interface->GetSpawn(state);
  760. lua_interface->ResetFunctionStack(state);
  761. if (spawn) {
  762. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  763. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  764. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  765. return 3;
  766. }
  767. return 0;
  768. }
  769. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. if (spawn) {
  774. int32 item_id = lua_interface->GetInt32Value(state, 2);
  775. lua_interface->ResetFunctionStack(state);
  776. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  777. return 1;
  778. }
  779. lua_interface->ResetFunctionStack(state);
  780. return 0;
  781. }
  782. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  783. if (!lua_interface)
  784. return 0;
  785. Spawn* spawn = lua_interface->GetSpawn(state);
  786. if (spawn && spawn->IsEntity()) {
  787. int32 item_id = lua_interface->GetInt32Value(state, 2);
  788. int16 charges = lua_interface->GetInt16Value(state, 3);
  789. if (charges == 0)
  790. charges = 1;
  791. ((Entity*)spawn)->AddLootItem(item_id, charges);
  792. }
  793. lua_interface->ResetFunctionStack(state);
  794. return 0;
  795. }
  796. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn && spawn->IsEntity()) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. Item* item = spawn->LootItem(item_id);
  803. safe_delete(item);
  804. }
  805. lua_interface->ResetFunctionStack(state);
  806. return 0;
  807. }
  808. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  809. if (!lua_interface)
  810. return 0;
  811. Spawn* spawn = lua_interface->GetSpawn(state);
  812. if (spawn) {
  813. int32 val = lua_interface->GetInt32Value(state, 2);
  814. spawn->AddLootCoins(val);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* entity = lua_interface->GetSpawn(state);
  823. Spawn* player = lua_interface->GetSpawn(state, 2);
  824. if (entity && player && player->IsPlayer()) {
  825. int32 coins = lua_interface->GetInt32Value(state, 3);
  826. vector<Item*>* items = 0;
  827. int i = 0;
  828. int32 item_id = 0;
  829. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  830. if (items == 0)
  831. items = new vector<Item*>;
  832. if (master_item_list.GetItem(item_id))
  833. items->push_back(master_item_list.GetItem(item_id));
  834. i++;
  835. }
  836. Client* client = 0;
  837. client = player->GetZone()->GetClientBySpawn(player);
  838. if (client)
  839. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  840. if(coins > 0)
  841. entity->AddLootCoins(coins);
  842. safe_delete(items);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. int32 item_id = lua_interface->GetInt32Value(state, 3);
  853. lua_interface->ResetFunctionStack(state);
  854. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  855. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  856. return 1;
  857. }
  858. return 0;
  859. }
  860. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  861. if (!lua_interface)
  862. return 0;
  863. Spawn* entity = lua_interface->GetSpawn(state);
  864. Spawn* player = lua_interface->GetSpawn(state, 2);
  865. lua_interface->ResetFunctionStack(state);
  866. if (entity && player && player->IsPlayer()) {
  867. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  868. return 1;
  869. }
  870. return 0;
  871. }
  872. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  873. if (!lua_interface)
  874. return 0;
  875. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  876. safe_delete(conversation);
  877. lua_interface->ResetFunctionStack(state);
  878. conversation = new vector<ConversationOption>();
  879. lua_interface->SetConversationValue(state, conversation);
  880. return 1;
  881. }
  882. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  883. if (!lua_interface)
  884. return 0;
  885. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  886. if (conversation) {
  887. ConversationOption conv_option;
  888. conv_option.option = lua_interface->GetStringValue(state, 2);
  889. conv_option.function = lua_interface->GetStringValue(state, 3);
  890. if (conv_option.option.length() > 0)
  891. conversation->push_back(conv_option);
  892. }
  893. lua_interface->ResetFunctionStack(state);
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. Spawn* npc = lua_interface->GetSpawn(state);
  900. Spawn* player = lua_interface->GetSpawn(state, 2);
  901. lua_interface->ResetFunctionStack(state);
  902. if (npc && player && player->IsPlayer() && player->GetZone()) {
  903. Client* client = player->GetZone()->GetClientBySpawn(player);
  904. if (client) {
  905. int32 conversation_id = client->GetConversationID(npc, 0);
  906. client->CloseDialog(conversation_id);
  907. }
  908. }
  909. return 0;
  910. }
  911. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. Item* item = lua_interface->GetItem(state);
  915. Spawn* player = lua_interface->GetSpawn(state, 2);
  916. lua_interface->ResetFunctionStack(state);
  917. if (item && player && player->IsPlayer() && player->GetZone()) {
  918. Client* client = player->GetZone()->GetClientBySpawn(player);
  919. if (client) {
  920. int32 conversation_id = client->GetConversationID(0, item);
  921. client->CloseDialog(conversation_id);
  922. }
  923. }
  924. return 0;
  925. }
  926. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  927. if (!lua_interface)
  928. return 0;
  929. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  930. Spawn* spawn = 0;
  931. Item* item = 0;
  932. int8 type = lua_interface->GetInt8Value(state, 2);
  933. if (type == 1 || type == 3)
  934. spawn = lua_interface->GetSpawn(state, 3);
  935. else if (type == 2 || type == 4)
  936. item = lua_interface->GetItem(state, 3);
  937. Spawn* player = lua_interface->GetSpawn(state, 4);
  938. string text = lua_interface->GetStringValue(state, 5);
  939. string mp3 = lua_interface->GetStringValue(state, 6);
  940. int32 key1 = lua_interface->GetInt32Value(state, 7);
  941. int32 key2 = lua_interface->GetInt32Value(state, 8);
  942. lua_interface->ResetFunctionStack(state);
  943. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  944. Client* client = player->GetZone()->GetClientBySpawn(player);
  945. if (client) {
  946. if (spawn) {
  947. // Need to do this so the function works the same as it did before
  948. if (type == 1)
  949. type++;
  950. if (mp3.length() > 0)
  951. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  952. else
  953. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  954. }
  955. else {
  956. if (mp3.length() > 0)
  957. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  958. else
  959. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  960. }
  961. }
  962. }
  963. safe_delete(conversation);
  964. lua_interface->SetConversationValue(state, NULL);
  965. return 0;
  966. }
  967. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  968. if(!lua_interface)
  969. return 0;
  970. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  971. Item* item = lua_interface->GetItem(state, 2);
  972. Spawn* player = lua_interface->GetSpawn(state, 3);
  973. string text = lua_interface->GetStringValue(state, 4);
  974. string mp3 = lua_interface->GetStringValue(state, 5);
  975. int32 key1 = lua_interface->GetInt32Value(state, 6);
  976. int32 key2 = lua_interface->GetInt32Value(state, 7);
  977. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  978. Client* client = player->GetZone()->GetClientBySpawn(player);
  979. if(client){
  980. if(mp3.length() > 0)
  981. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  982. else
  983. client->DisplayConversation(item, conversation, (char*)text.c_str());
  984. }
  985. safe_delete(conversation);
  986. }
  987. return 0;
  988. }*/
  989. int EQ2Emu_lua_StartConversation(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  993. Spawn* source = lua_interface->GetSpawn(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. string text = lua_interface->GetStringValue(state, 4);
  996. string mp3 = lua_interface->GetStringValue(state, 5);
  997. int32 key1 = lua_interface->GetInt32Value(state, 6);
  998. int32 key2 = lua_interface->GetInt32Value(state, 7);
  999. lua_interface->ResetFunctionStack(state);
  1000. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1001. Client* client = source->GetZone()->GetClientBySpawn(player);
  1002. if (mp3.length() > 0)
  1003. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  1004. else
  1005. client->DisplayConversation(source, 1, conversation, text.c_str());
  1006. safe_delete(conversation);
  1007. lua_interface->SetConversationValue(state, NULL);
  1008. }
  1009. else
  1010. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1011. return 0;
  1012. }
  1013. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1014. if (!lua_interface)
  1015. return 0;
  1016. Spawn* spawn = lua_interface->GetSpawn(state);
  1017. float distance = lua_interface->GetFloatValue(state, 2);
  1018. string in_range_function = lua_interface->GetStringValue(state, 3);
  1019. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1020. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1021. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1022. return 0;
  1023. }
  1024. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1025. ZoneServer* zone = lua_interface->GetZone(state);
  1026. float x = lua_interface->GetFloatValue(state, 2);
  1027. float y = lua_interface->GetFloatValue(state, 3);
  1028. float z = lua_interface->GetFloatValue(state, 4);
  1029. float max_variation = lua_interface->GetFloatValue(state, 5);
  1030. string in_range_function = lua_interface->GetStringValue(state, 6);
  1031. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1032. lua_interface->ResetFunctionStack(state);
  1033. if (zone && in_range_function.length() > 0)
  1034. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1038. if (!lua_interface)
  1039. return 0;
  1040. Spawn* spawn = lua_interface->GetSpawn(state);
  1041. if (spawn && spawn->IsEntity()) {
  1042. int32 val = lua_interface->GetInt32Value(state, 2);
  1043. ((Entity*)spawn)->SetLootCoins(val);
  1044. }
  1045. lua_interface->ResetFunctionStack(state);
  1046. return 0;
  1047. }
  1048. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1049. if (!lua_interface)
  1050. return 0;
  1051. Spawn* spawn = lua_interface->GetSpawn(state);
  1052. lua_interface->ResetFunctionStack(state);
  1053. if (spawn && spawn->IsEntity()) {
  1054. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1060. if (!lua_interface)
  1061. return 0;
  1062. Spawn* spawn = lua_interface->GetSpawn(state);
  1063. float x = lua_interface->GetFloatValue(state, 2);
  1064. float y = lua_interface->GetFloatValue(state, 3);
  1065. float z = lua_interface->GetFloatValue(state, 4);
  1066. float speed = lua_interface->GetFloatValue(state, 5);
  1067. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1068. string function = lua_interface->GetStringValue(state, 7);
  1069. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1070. float heading = lua_interface->GetFloatValue(state, 8);
  1071. if (spawn) {
  1072. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1073. spawn->GetZone()->AddMovementNPC(spawn);
  1074. }
  1075. lua_interface->ResetFunctionStack(state);
  1076. return 0;
  1077. }
  1078. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1079. if (!lua_interface)
  1080. return 0;
  1081. Spawn* spawn = lua_interface->GetSpawn(state);
  1082. lua_interface->ResetFunctionStack(state);
  1083. if (spawn) {
  1084. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1085. return 1;
  1086. }
  1087. return 0;
  1088. }
  1089. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1090. if (!lua_interface)
  1091. return 0;
  1092. Spawn* spawn = lua_interface->GetSpawn(state);
  1093. lua_interface->ResetFunctionStack(state);
  1094. if (spawn && spawn->IsPlayer()) {
  1095. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1096. return 1;
  1097. }
  1098. lua_interface->SetInt32Value(state, 0);
  1099. return 1;
  1100. }
  1101. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1102. if (!lua_interface)
  1103. return 0;
  1104. Spawn* spawn = lua_interface->GetSpawn(state);
  1105. Spawn* target = lua_interface->GetSpawn(state, 2);
  1106. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1107. bool reset_action_state = true;
  1108. if(num_args > 2)
  1109. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1110. if (spawn && target) {
  1111. if (spawn->IsEntity())
  1112. // ((Entity*)spawn)->FaceTarget(target);
  1113. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1114. }
  1115. lua_interface->ResetFunctionStack(state);
  1116. return 0;
  1117. }
  1118. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. float x = lua_interface->GetFloatValue(state, 2);
  1123. float y = lua_interface->GetFloatValue(state, 3);
  1124. float z = lua_interface->GetFloatValue(state, 4);
  1125. float speed = lua_interface->GetFloatValue(state, 5);
  1126. string lua_function = lua_interface->GetStringValue(state, 6);
  1127. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1128. if (spawn) {
  1129. if (speed == 0)
  1130. speed = spawn->GetSpeed();
  1131. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1132. }
  1133. lua_interface->ResetFunctionStack(state);
  1134. return 0;
  1135. }
  1136. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1137. if (!lua_interface)
  1138. return 0;
  1139. Spawn* spawn = lua_interface->GetSpawn(state);
  1140. lua_interface->ResetFunctionStack(state);
  1141. if (spawn) {
  1142. spawn->ClearRunningLocations();
  1143. }
  1144. return 0;
  1145. }
  1146. int EQ2Emu_lua_Say(lua_State* state) {
  1147. if (!lua_interface)
  1148. return 0;
  1149. Spawn* spawn = lua_interface->GetSpawn(state);
  1150. string message = lua_interface->GetStringValue(state, 2);
  1151. Spawn* player = lua_interface->GetSpawn(state, 3);
  1152. int32 language = lua_interface->GetInt32Value(state, 4);
  1153. if (spawn && message.length() > 0) {
  1154. Client* client = 0;
  1155. if (player && player->IsPlayer())
  1156. client = spawn->GetZone()->GetClientBySpawn(player);
  1157. if (client)
  1158. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1159. else
  1160. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1161. }
  1162. lua_interface->ResetFunctionStack(state);
  1163. return 0;
  1164. }
  1165. int EQ2Emu_lua_Shout(lua_State* state) {
  1166. if (!lua_interface)
  1167. return 0;
  1168. Spawn* spawn = lua_interface->GetSpawn(state);
  1169. string message = lua_interface->GetStringValue(state, 2);
  1170. Spawn* player = lua_interface->GetSpawn(state, 3);
  1171. float dist = lua_interface->GetFloatValue(state, 4);
  1172. if (spawn && message.length() > 0) {
  1173. Client* client = 0;
  1174. if (player && player->IsPlayer())
  1175. client = spawn->GetZone()->GetClientBySpawn(player);
  1176. if (client)
  1177. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1178. else
  1179. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1180. }
  1181. lua_interface->ResetFunctionStack(state);
  1182. return 0;
  1183. }
  1184. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1185. if (!lua_interface)
  1186. return 0;
  1187. Spawn* spawn = lua_interface->GetSpawn(state);
  1188. string message = lua_interface->GetStringValue(state, 2);
  1189. Spawn* player = lua_interface->GetSpawn(state, 3);
  1190. if (spawn && message.length() > 0) {
  1191. Client* client = 0;
  1192. if (player && player->IsPlayer())
  1193. client = spawn->GetZone()->GetClientBySpawn(player);
  1194. if (client)
  1195. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1196. else
  1197. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1198. }
  1199. lua_interface->ResetFunctionStack(state);
  1200. return 0;
  1201. }
  1202. int EQ2Emu_lua_Emote(lua_State* state) {
  1203. if (!lua_interface)
  1204. return 0;
  1205. Spawn* spawn = lua_interface->GetSpawn(state);
  1206. string message = lua_interface->GetStringValue(state, 2);
  1207. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1208. Spawn* player = lua_interface->GetSpawn(state, 4);
  1209. char* to = 0;
  1210. if (spawn2)
  1211. to = spawn2->GetName();
  1212. if (spawn && message.length() > 0) {
  1213. Client* client = 0;
  1214. if (player && player->IsPlayer())
  1215. client = spawn->GetZone()->GetClientBySpawn(player);
  1216. if (client)
  1217. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1218. else
  1219. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1220. }
  1221. lua_interface->ResetFunctionStack(state);
  1222. return 0;
  1223. }
  1224. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1225. if (!lua_interface)
  1226. return 0;
  1227. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1228. if (!luaspell)
  1229. return 0;
  1230. Spawn* caster = luaspell->caster;
  1231. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1232. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1233. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1234. Spawn* target = lua_interface->GetSpawn(state, 4);
  1235. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1236. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1237. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1238. lua_interface->ResetFunctionStack(state);
  1239. boost::to_lower(heal_type);
  1240. if (caster && caster->IsEntity()) {
  1241. bool success = false;
  1242. luaspell->resisted = false;
  1243. if (target) {
  1244. float distance = caster->GetDistance(target, true);
  1245. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1246. success = true;
  1247. }
  1248. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1249. Spawn* target = 0;
  1250. ZoneServer* zone = luaspell->caster->GetZone();
  1251. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1252. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1253. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1254. float distance = caster->GetDistance(target, true);
  1255. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1256. }
  1257. }
  1258. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1259. success = true;
  1260. }
  1261. if (success) {
  1262. if (caster->GetZone())
  1263. caster->GetZone()->TriggerCharSheetTimer();
  1264. }
  1265. }
  1266. return 0;
  1267. }
  1268. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1269. if (!lua_interface)
  1270. return 0;
  1271. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1272. if (!luaspell)
  1273. return 0;
  1274. Spawn* caster = luaspell->caster;
  1275. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1276. float percentage = lua_interface->GetFloatValue(state, 2);
  1277. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1278. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1279. Spawn* target = lua_interface->GetSpawn(state, 5);
  1280. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1281. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1282. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1283. lua_interface->ResetFunctionStack(state);
  1284. boost::to_lower(heal_type);
  1285. int32 min_heal = 0, max_heal = 0;
  1286. if (caster && caster->IsEntity() && target) {
  1287. if(percentage <= 0.0f)
  1288. {
  1289. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1290. return 0;
  1291. }
  1292. if(heal_type == "power")
  1293. {
  1294. if(current_value)
  1295. {
  1296. if(caster_value)
  1297. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1298. else
  1299. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1300. }
  1301. else
  1302. {
  1303. if(caster_value)
  1304. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1305. else
  1306. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1307. }
  1308. }
  1309. else
  1310. {
  1311. if(current_value)
  1312. {
  1313. if(caster_value)
  1314. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1315. else
  1316. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1317. }
  1318. else
  1319. {
  1320. if(caster_value)
  1321. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1322. else
  1323. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1324. }
  1325. }
  1326. bool success = false;
  1327. luaspell->resisted = false;
  1328. if (target) {
  1329. float distance = caster->GetDistance(target, true);
  1330. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1331. success = true;
  1332. }
  1333. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1334. Spawn* target = 0;
  1335. ZoneServer* zone = luaspell->caster->GetZone();
  1336. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1337. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1338. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1339. float distance = caster->GetDistance(target, true);
  1340. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1341. }
  1342. }
  1343. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1344. success = true;
  1345. }
  1346. if (success) {
  1347. if (caster->GetZone())
  1348. caster->GetZone()->TriggerCharSheetTimer();
  1349. }
  1350. }
  1351. return 0;
  1352. }
  1353. int EQ2Emu_lua_AddItem(lua_State* state) {
  1354. if (!lua_interface)
  1355. return 0;
  1356. Spawn* spawn = lua_interface->GetSpawn(state);
  1357. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1358. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1359. lua_interface->ResetFunctionStack(state);
  1360. // default of 1 quantity to add
  1361. if (quantity == 0)
  1362. quantity = 1;
  1363. if (spawn && spawn->IsPlayer()) {
  1364. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1365. if (client && item_id > 0) {
  1366. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1367. return 1;
  1368. }
  1369. }
  1370. lua_interface->SetBooleanValue(state, false);
  1371. return 1;
  1372. }
  1373. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1374. if (!lua_interface)
  1375. return 0;
  1376. Spawn* spawn = lua_interface->GetSpawn(state);
  1377. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1378. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1379. string location = lua_interface->GetStringValue(state, 4);
  1380. lua_interface->ResetFunctionStack(state);
  1381. if (spawn && spawn->IsPlayer()) {
  1382. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1383. if (client && item_id > 0) {
  1384. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1385. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1386. else
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1388. if (send_messages) {
  1389. Item* item = master_item_list.GetItem(item_id);
  1390. if (item) {
  1391. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1392. string popup_text = "You receive " + item->name;
  1393. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1394. }
  1395. }
  1396. return 1;
  1397. }
  1398. }
  1399. lua_interface->SetBooleanValue(state, false);
  1400. return 1;
  1401. }
  1402. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1403. Spawn* spawn = lua_interface->GetSpawn(state);
  1404. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1405. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1406. lua_interface->ResetFunctionStack(state);
  1407. // default of 1 to remove
  1408. if (quantity == 0)
  1409. quantity = 1;
  1410. Client* client;
  1411. Item* item;
  1412. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1413. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1414. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1415. if (client->RemoveItem(item, quantity)) {
  1416. lua_interface->SetBooleanValue(state, true);
  1417. return 1;
  1418. }
  1419. }
  1420. }
  1421. }
  1422. lua_interface->SetBooleanValue(state, false);
  1423. return 1;
  1424. }
  1425. int EQ2Emu_lua_HasItem(lua_State* state) {
  1426. Spawn* player = lua_interface->GetSpawn(state);
  1427. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1428. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1429. lua_interface->ResetFunctionStack(state);
  1430. if (player && player->IsPlayer()) {
  1431. bool hasItem = false;
  1432. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1433. if (!hasItem)
  1434. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1435. lua_interface->SetBooleanValue(state, hasItem);
  1436. return 1;
  1437. }
  1438. lua_interface->SetBooleanValue(state, false);
  1439. return 1;
  1440. }
  1441. int EQ2Emu_lua_Spawn(lua_State* state) {
  1442. if (!lua_interface)
  1443. return 0;
  1444. ZoneServer* zone = lua_interface->GetZone(state);
  1445. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1446. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1447. float x = lua_interface->GetFloatValue(state, 4);
  1448. float y = lua_interface->GetFloatValue(state, 5);
  1449. float z = lua_interface->GetFloatValue(state, 6);
  1450. float heading = lua_interface->GetFloatValue(state, 7);
  1451. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1452. Spawn* spawn = zone->GetSpawn(spawn_id);
  1453. if (!spawn)
  1454. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1455. else {
  1456. spawn->SetX(x);
  1457. spawn->SetZ(z);
  1458. spawn->SetY(y,true,true);
  1459. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1460. spawn->SetHeading(heading);
  1461. if (restricted_npc)
  1462. spawn->AddAllowAccessSpawn(spawn);
  1463. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1464. bool scriptActive = false;
  1465. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1466. scriptActive = true;
  1467. spawn->SetSpawnScript(string(spawn_script));
  1468. }
  1469. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1470. zone->AddSpawn(spawn);
  1471. if (scriptActive) {
  1472. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1473. }
  1474. lua_interface->ResetFunctionStack(state);
  1475. lua_interface->SetSpawnValue(state, spawn);
  1476. return 1;
  1477. }
  1478. }
  1479. else {
  1480. string output = "Invalid paramaters to LUA Spawn command: \n";
  1481. if (!zone)
  1482. output = output.append("\t").append("Missing zone reference. \n");
  1483. if (spawn_id == 0)
  1484. output = output.append("\t").append("Missing spawn_id.");
  1485. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1486. }
  1487. lua_interface->ResetFunctionStack(state);
  1488. return 0;
  1489. }
  1490. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1491. if (!lua_interface)
  1492. return 0;
  1493. ZoneServer* zone = lua_interface->GetZone(state);
  1494. lua_interface->ResetFunctionStack(state);
  1495. if (zone) {
  1496. lua_interface->SetStringValue(state, zone->GetZoneName());
  1497. return 1;
  1498. }
  1499. return 0;
  1500. }
  1501. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1502. if (!lua_interface)
  1503. return 0;
  1504. ZoneServer* zone = lua_interface->GetZone(state);
  1505. lua_interface->ResetFunctionStack(state);
  1506. if (zone) {
  1507. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1508. return 1;
  1509. }
  1510. return 0;
  1511. }
  1512. int EQ2Emu_lua_GetZone(lua_State* state) {
  1513. if (!lua_interface)
  1514. return 0;
  1515. int32 zone_id = lua_interface->GetInt32Value(state);
  1516. ZoneServer* zone = 0;
  1517. if (zone_id > 0)
  1518. zone = zone_list.Get(zone_id);
  1519. else {
  1520. string zone_name = lua_interface->GetStringValue(state);
  1521. if (zone_name.length() > 0) {
  1522. zone = zone_list.Get(zone_name.c_str());
  1523. }
  1524. else {
  1525. Spawn* spawn = lua_interface->GetSpawn(state);
  1526. if (spawn)
  1527. zone = spawn->GetZone();
  1528. }
  1529. }
  1530. lua_interface->ResetFunctionStack(state);
  1531. if (zone) {
  1532. lua_interface->SetZoneValue(state, zone);
  1533. return 1;
  1534. }
  1535. return 0;
  1536. }
  1537. int EQ2Emu_lua_AddHate(lua_State* state) {
  1538. Spawn* entity = lua_interface->GetSpawn(state);
  1539. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1540. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1541. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1542. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1543. if (entity && entity->IsEntity() && amount != 0) {
  1544. if (luaspell) {
  1545. ZoneServer* zone = luaspell->caster->GetZone();
  1546. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1547. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1548. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1549. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1550. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1551. if (send_packet)
  1552. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1553. }
  1554. }
  1555. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1556. }
  1557. else if (npc && npc->IsNPC() && npc->GetZone())
  1558. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1559. }
  1560. lua_interface->ResetFunctionStack(state);
  1561. return 0;
  1562. }
  1563. int EQ2Emu_lua_Zone(lua_State* state) {
  1564. if (!lua_interface)
  1565. return 0;
  1566. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1567. ZoneServer* zone = lua_interface->GetZone(state);
  1568. Spawn* player = lua_interface->GetSpawn(state, 2);
  1569. Client* client = 0;
  1570. if (player && player->IsPlayer())
  1571. client = player->GetZone()->GetClientBySpawn(player);
  1572. float x = lua_interface->GetFloatValue(state, 3);
  1573. float y = lua_interface->GetFloatValue(state, 4);
  1574. float z = lua_interface->GetFloatValue(state, 5);
  1575. float heading = lua_interface->GetFloatValue(state, 6);
  1576. if (zone && client) {
  1577. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1578. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1579. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1580. {
  1581. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1582. return 0;
  1583. }
  1584. if (x != 0 || y != 0 || z != 0) {
  1585. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1586. player->SetX(x);
  1587. player->SetY(y);
  1588. player->SetZ(z);
  1589. player->SetHeading(heading);
  1590. client->Zone(zone->GetZoneName(), false);
  1591. }
  1592. else
  1593. client->Zone(zone->GetZoneName());
  1594. }
  1595. else
  1596. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1597. lua_interface->ResetFunctionStack(state);
  1598. return 0;
  1599. }
  1600. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1601. if (!lua_interface)
  1602. return 0;
  1603. Spawn* spawn = lua_interface->GetSpawn(state);
  1604. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1605. if (spawn && spawn2)
  1606. spawn->AddAllowAccessSpawn(spawn2);
  1607. lua_interface->ResetFunctionStack(state);
  1608. return 0;
  1609. }
  1610. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1611. if (!lua_interface)
  1612. return 0;
  1613. Spawn* target = lua_interface->GetSpawn(state);
  1614. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1615. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1616. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1617. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1618. lua_interface->ResetFunctionStack(state);
  1619. if (!target) {
  1620. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1621. return 0;
  1622. }
  1623. if (!target->IsEntity()) {
  1624. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1625. return 0;
  1626. }
  1627. if (spell_id <= 0) {
  1628. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1629. return 0;
  1630. }
  1631. if (caster && !caster->IsEntity()) {
  1632. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1633. return 0;
  1634. }
  1635. if (spell_tier == 0)
  1636. spell_tier = 1;
  1637. if (!caster)
  1638. caster = target;
  1639. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1640. return 0;
  1641. }
  1642. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1643. if (!lua_interface)
  1644. return 0;
  1645. Spawn* target = lua_interface->GetSpawn(state);
  1646. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1647. if (!luaspell)
  1648. return 0;
  1649. Spawn* caster = luaspell->caster;
  1650. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1651. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1652. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1653. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1654. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1655. //lua_interface->ResetFunctionStack(state);
  1656. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1657. vector<int16> faction_req;
  1658. vector<int16> race_req;
  1659. int32 class_req = 0;
  1660. int32 i = 0;
  1661. int8 f = 0;
  1662. int8 r = 0;
  1663. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1664. if (class_id < 100) {
  1665. class_req += pow(2.0, double(class_id - 1));
  1666. }
  1667. else if (class_id > 100 && class_id < 1000) {
  1668. race_req.push_back(class_id);
  1669. r++;
  1670. }
  1671. else {
  1672. faction_req.push_back(class_id);
  1673. f++;
  1674. }
  1675. i++;
  1676. }
  1677. lua_interface->ResetFunctionStack(state);
  1678. if (caster && caster->IsEntity()) {
  1679. bool race_match = false;
  1680. bool success = false;
  1681. luaspell->resisted = false;
  1682. if (luaspell->targets.size() > 0) {
  1683. ZoneServer* zone = luaspell->caster->GetZone();
  1684. Spawn* target = 0;
  1685. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1686. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1687. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1688. if (race_req.size() > 0) {
  1689. for (int8 i = 0; i < race_req.size(); i++) {
  1690. if (target->GetLuaRaceId() == race_req[i]) {
  1691. race_match = true;
  1692. }
  1693. }
  1694. }
  1695. else
  1696. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1697. if (race_match == true) {
  1698. float distance = caster->GetDistance(target, true);
  1699. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1700. }
  1701. }
  1702. }
  1703. success = true;
  1704. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1705. }
  1706. else if (target) {
  1707. //check class and race/faction here
  1708. if (race_req.size() > 0) {
  1709. for (int8 i = 0; i < race_req.size(); i++) {
  1710. if (target->GetLuaRaceId() == race_req[i]) {
  1711. race_match = true;
  1712. }
  1713. }
  1714. }
  1715. else
  1716. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1717. if (race_match == true) {
  1718. float distance = caster->GetDistance(target, true);
  1719. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1720. success = true;
  1721. }
  1722. }
  1723. if (success) {
  1724. Spell* spell = luaspell->spell;
  1725. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1726. ((Player*)caster)->InCombat(true);
  1727. if (caster->GetZone())
  1728. caster->GetZone()->TriggerCharSheetTimer();
  1729. }
  1730. }
  1731. }
  1732. return 0;
  1733. }
  1734. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1735. if (!lua_interface)
  1736. return 0;
  1737. Spawn* spawn = lua_interface->GetSpawn(state);
  1738. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1739. lua_interface->ResetFunctionStack(state);
  1740. if (spawn && value != 0) {
  1741. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1742. spawn->SetPower(spawn->GetTotalPower());
  1743. else
  1744. spawn->SetPower(spawn->GetPower() + value);
  1745. }
  1746. return 0;
  1747. }
  1748. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1749. if (!lua_interface)
  1750. return 0;
  1751. Spawn* spawn = lua_interface->GetSpawn(state);
  1752. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1753. lua_interface->ResetFunctionStack(state);
  1754. if (spawn && value != 0) {
  1755. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1756. spawn->SetHP(spawn->GetTotalHP());
  1757. else
  1758. spawn->SetHP(spawn->GetHP() + value);
  1759. }
  1760. return 0;
  1761. }
  1762. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1763. if (!lua_interface)
  1764. return 0;
  1765. Spawn* spawn = lua_interface->GetSpawn(state);
  1766. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1767. lua_interface->ResetFunctionStack(state);
  1768. if (spawn && value != 0) {
  1769. spawn->SetPower(spawn->GetPower() + value);
  1770. if (value > spawn->GetTotalHPBase())
  1771. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1772. }
  1773. return 0;
  1774. }
  1775. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1776. if (!lua_interface)
  1777. return 0;
  1778. Spawn* spawn = lua_interface->GetSpawn(state);
  1779. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1780. lua_interface->ResetFunctionStack(state);
  1781. if (spawn && value != 0) {
  1782. spawn->SetHP(spawn->GetHP() + value);
  1783. if (value > spawn->GetTotalHPBase())
  1784. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1785. }
  1786. return 0;
  1787. }
  1788. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1789. if (!lua_interface)
  1790. return 0;
  1791. Spawn* spawn = lua_interface->GetSpawn(state);
  1792. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1793. lua_interface->ResetFunctionStack(state);
  1794. if (spawn) {
  1795. spawn->SetHP(value);
  1796. if (value > spawn->GetTotalHPBase())
  1797. spawn->SetTotalHP(value);
  1798. }
  1799. return 0;
  1800. }
  1801. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1802. if (!lua_interface)
  1803. return 0;
  1804. Spawn* spawn = lua_interface->GetSpawn(state);
  1805. float value = lua_interface->GetFloatValue(state, 2);
  1806. lua_interface->ResetFunctionStack(state);
  1807. if (spawn && spawn->IsEntity() && value > 0)
  1808. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1809. if (spawn->IsPlayer())
  1810. ((Player*)spawn)->SetCharSheetChanged(true);
  1811. return 0;
  1812. }
  1813. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1814. if (!lua_interface)
  1815. return 0;
  1816. Spawn* spawn = lua_interface->GetSpawn(state);
  1817. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1818. lua_interface->ResetFunctionStack(state);
  1819. if (spawn && spawn->IsEntity() && value > 0)
  1820. ((Entity*)spawn)->SetTotalHPBase(value);
  1821. return 0;
  1822. }
  1823. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1824. if (!lua_interface)
  1825. return 0;
  1826. Spawn* spawn = lua_interface->GetSpawn(state);
  1827. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1828. lua_interface->ResetFunctionStack(state);
  1829. if (spawn && value > 0) {
  1830. spawn->SetPower(value);
  1831. if (value > spawn->GetTotalPowerBase())
  1832. spawn->SetTotalPower(value);
  1833. }
  1834. return 0;
  1835. }
  1836. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1837. if (!lua_interface)
  1838. return 0;
  1839. Spawn* spawn = lua_interface->GetSpawn(state);
  1840. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1841. lua_interface->ResetFunctionStack(state);
  1842. if (spawn && spawn->IsEntity() && value > 0)
  1843. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1844. return 0;
  1845. }
  1846. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1847. if (!lua_interface)
  1848. return 0;
  1849. Spawn* spawn = lua_interface->GetSpawn(state);
  1850. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1851. lua_interface->ResetFunctionStack(state);
  1852. if (spawn && spawn->IsEntity() && value > 0)
  1853. ((Entity*)spawn)->SetTotalPowerBase(value);
  1854. return 0;
  1855. }
  1856. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1857. if (!lua_interface)
  1858. return 0;
  1859. Spawn* spawn = lua_interface->GetSpawn(state);
  1860. float x = lua_interface->GetFloatValue(state, 2);
  1861. float y = lua_interface->GetFloatValue(state, 3);
  1862. float z = lua_interface->GetFloatValue(state, 4);
  1863. float heading = lua_interface->GetFloatValue(state, 5);
  1864. lua_interface->ResetFunctionStack(state);
  1865. if (spawn) {
  1866. spawn->SetX(x);
  1867. spawn->SetY(y);
  1868. spawn->SetZ(z);
  1869. if (heading != 0)
  1870. spawn->SetHeading(heading);
  1871. spawn->SetSpawnOrigX(spawn->GetX());
  1872. spawn->SetSpawnOrigY(spawn->GetY());
  1873. spawn->SetSpawnOrigZ(spawn->GetZ());
  1874. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1875. if (spawn->IsPlayer()) {
  1876. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1877. if (client) {
  1878. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1879. client->QueuePacket(packet);
  1880. }
  1881. }
  1882. }
  1883. return 0;
  1884. }
  1885. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1886. if (!lua_interface)
  1887. return 0;
  1888. Spawn* spawn = lua_interface->GetSpawn(state);
  1889. float value = lua_interface->GetFloatValue(state, 2);
  1890. lua_interface->ResetFunctionStack(state);
  1891. if (spawn) {
  1892. spawn->SetHeading(value);
  1893. if (spawn->IsPlayer()) {
  1894. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1895. if (client) {
  1896. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1897. client->QueuePacket(packet);
  1898. }
  1899. }
  1900. }
  1901. return 0;
  1902. }
  1903. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1904. if (!lua_interface)
  1905. return 0;
  1906. Spawn* spawn = lua_interface->GetSpawn(state);
  1907. int16 value = lua_interface->GetInt16Value(state, 2);
  1908. lua_interface->ResetFunctionStack(state);
  1909. if (spawn)
  1910. spawn->SetModelType(value);
  1911. return 0;
  1912. }
  1913. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1914. if (!lua_interface)
  1915. return 0;
  1916. Spawn* spawn = lua_interface->GetSpawn(state);
  1917. int8 value = lua_interface->GetInt8Value(state, 2);
  1918. lua_interface->ResetFunctionStack(state);
  1919. if (spawn) {
  1920. if (spawn->IsPlayer())
  1921. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1922. else
  1923. spawn->SetAdventureClass(value);
  1924. }
  1925. return 0;
  1926. }
  1927. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1928. if (!lua_interface)
  1929. return 0;
  1930. Spawn* spawn = lua_interface->GetSpawn(state);
  1931. int8 value = lua_interface->GetInt8Value(state, 2);
  1932. lua_interface->ResetFunctionStack(state);
  1933. if (spawn) {
  1934. spawn->SetTradeskillClass(value);
  1935. if (spawn->IsEntity()) {
  1936. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1937. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1938. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1939. }
  1940. if (spawn->IsPlayer())
  1941. ((Player*)spawn)->SetCharSheetChanged(true);
  1942. }
  1943. return 0;
  1944. }
  1945. int EQ2Emu_lua_SetMount(lua_State* state) {
  1946. if (!lua_interface)
  1947. return 0;
  1948. Spawn* spawn = lua_interface->GetSpawn(state);
  1949. int16 value = lua_interface->GetInt16Value(state, 2);
  1950. if (spawn && spawn->IsEntity()) {
  1951. ((Entity*)spawn)->SetMount(value);
  1952. EQ2_Color color;
  1953. color.red = 255;
  1954. color.green = 255;
  1955. color.blue = 255;
  1956. ((Entity*)spawn)->SetMountColor(&color);
  1957. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1958. }
  1959. return 0;
  1960. }
  1961. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1962. if (!lua_interface)
  1963. return 0;
  1964. Spawn* spawn = lua_interface->GetSpawn(state);
  1965. EQ2_Color mount_color;
  1966. EQ2_Color saddle_color;
  1967. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1968. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1969. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1970. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1971. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1972. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1973. if (spawn && spawn->IsEntity()) {
  1974. ((Entity*)spawn)->SetMountColor(&mount_color);
  1975. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1976. }
  1977. return 0;
  1978. }
  1979. int EQ2Emu_lua_GetMount(lua_State* state) {
  1980. if (!lua_interface)
  1981. return 0;
  1982. Spawn* spawn = lua_interface->GetSpawn(state);
  1983. if (spawn && spawn->IsEntity()) {
  1984. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1985. return 1;
  1986. }
  1987. return 0;
  1988. }
  1989. int EQ2Emu_lua_GetRace(lua_State* state) {
  1990. if (!lua_interface)
  1991. return 0;
  1992. Spawn* spawn = lua_interface->GetSpawn(state);
  1993. if (spawn)
  1994. {
  1995. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1996. lua_interface->SetInt32Value(state, spawn->GetRace());
  1997. return 1;
  1998. }
  1999. return 0;
  2000. }
  2001. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2002. if (!lua_interface)
  2003. return 0;
  2004. Spawn* spawn = lua_interface->GetSpawn(state);
  2005. if (spawn) {
  2006. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2007. return 1;
  2008. }
  2009. return 0;
  2010. }
  2011. int EQ2Emu_lua_GetClass(lua_State* state) {
  2012. Spawn* spawn = lua_interface->GetSpawn(state);
  2013. if (spawn) {
  2014. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2015. return 1;
  2016. }
  2017. return 0;
  2018. }
  2019. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2020. Spawn* spawn = lua_interface->GetSpawn(state);
  2021. if (spawn) {
  2022. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2023. return 1;
  2024. }
  2025. return 0;
  2026. }
  2027. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2028. if (!lua_interface)
  2029. return 0;
  2030. Spawn* spawn = lua_interface->GetSpawn(state);
  2031. float value = lua_interface->GetFloatValue(state, 2);
  2032. lua_interface->ResetFunctionStack(state);
  2033. if (spawn) {
  2034. spawn->SetSpeed(value);
  2035. if(spawn->IsEntity())
  2036. ((Entity*)spawn)->SetSpeed(value);
  2037. if (spawn->IsPlayer()) {
  2038. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2039. if (client) {
  2040. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2041. if (packet) {
  2042. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2043. packet->setDataByName("speed", value);
  2044. packet->setDataByName("size", 0.51);
  2045. EQ2Packet* app = packet->serialize();
  2046. client->QueuePacket(app);
  2047. safe_delete(packet);
  2048. }
  2049. }
  2050. }
  2051. }
  2052. return 0;
  2053. }
  2054. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2055. if (!lua_interface)
  2056. return 0;
  2057. Spawn* spawn = lua_interface->GetSpawn(state);
  2058. const int16 type = lua_interface->GetInt16Value(state, 2);
  2059. const float value = lua_interface->GetFloatValue(state, 3);
  2060. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2061. int64 class_req = 0;
  2062. int32 class_id = 0;
  2063. vector<int16> faction_req;
  2064. vector<int16> race_req;
  2065. int32 i = 0;
  2066. int8 f = 0;
  2067. int8 r = 0;
  2068. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2069. if (class_id < 100) {
  2070. class_req += pow(2.0, double(class_id - 1));
  2071. }
  2072. else if (class_id > 100 && class_id < 1000) {
  2073. race_req.push_back(class_id);
  2074. r++;
  2075. }
  2076. else {
  2077. faction_req.push_back(class_id);
  2078. f++;
  2079. }
  2080. i++;
  2081. }
  2082. if (value != 0 && type >= 0) {
  2083. if (luaspell && luaspell->spell && luaspell->caster) {
  2084. ZoneServer* zone = luaspell->caster->GetZone();
  2085. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2086. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2087. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2088. if (target) {
  2089. if (target->IsPlayer()) {
  2090. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2091. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2092. if (((Player*)target)->GetGroupMemberInfo())
  2093. ((Player*)target)->UpdateGroupMemberInfo();
  2094. ((Player*)target)->SetCharSheetChanged(true);
  2095. }
  2096. else if (target->IsNPC())
  2097. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2098. else
  2099. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2100. }
  2101. }
  2102. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2103. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2104. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2105. }
  2106. else if (spawn && spawn->IsEntity()) {
  2107. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2108. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2109. if (spawn->IsPlayer())
  2110. ((Player*)spawn)->SetCharSheetChanged(true);
  2111. }
  2112. else
  2113. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2114. }
  2115. else
  2116. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2117. return 0;
  2118. }
  2119. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2120. if (!lua_interface)
  2121. return 0;
  2122. Spawn* spawn = lua_interface->GetSpawn(state);
  2123. int16 type = lua_interface->GetInt16Value(state, 2);
  2124. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2125. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2126. if (!spawn) {
  2127. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2128. return 0;
  2129. }
  2130. if (!spawn->IsEntity()) {
  2131. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2132. return 0;
  2133. }
  2134. if (value == 0) {
  2135. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2136. return 0;
  2137. }
  2138. if (!luaspell || !luaspell->spell) {
  2139. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2140. return 0;
  2141. }
  2142. int32 class_req = 0;
  2143. vector<int16> faction_req;
  2144. vector<int16> race_req;
  2145. int32 class_id = 0;
  2146. int32 i = 0;
  2147. int8 f = 0;
  2148. int8 r = 0;
  2149. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2150. if (class_id < 100) {
  2151. class_req += pow(2.0, double(class_id - 1));
  2152. }
  2153. else if (class_id > 100 && class_id < 1000) {
  2154. race_req.push_back(class_id);
  2155. r++;
  2156. }
  2157. else {
  2158. faction_req.push_back(class_id);
  2159. f++;
  2160. }
  2161. i++;
  2162. }
  2163. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2164. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2165. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2166. if (spawn->IsPlayer())
  2167. ((Player*)spawn)->SetCharSheetChanged(true);
  2168. return 0;
  2169. }
  2170. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2171. if (!lua_interface)
  2172. return 0;
  2173. Spawn* spawn = lua_interface->GetSpawn(state);
  2174. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2175. if (!spawn) {
  2176. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2177. return 0;
  2178. }
  2179. if (!spawn->IsEntity()) {
  2180. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2181. return 0;
  2182. }
  2183. if (!luaspell || !luaspell->spell) {
  2184. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2185. return 0;
  2186. }
  2187. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2188. if (spawn->IsPlayer())
  2189. ((Player*)spawn)->SetCharSheetChanged(true);
  2190. return 0;
  2191. }
  2192. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2193. if (!lua_interface)
  2194. return 0;
  2195. Spawn* spawn = lua_interface->GetSpawn(state);
  2196. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2197. if (luaspell && luaspell->spell) {
  2198. ZoneServer* zone = luaspell->caster->GetZone();
  2199. Spawn* target = 0;
  2200. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2201. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2202. target = zone->GetSpawnByID(luaspell->targets[i]);
  2203. if (target && target->IsEntity()) {
  2204. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2205. if (target->IsPlayer())
  2206. ((Player*)target)->SetCharSheetChanged(true);
  2207. }
  2208. }
  2209. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2210. }
  2211. else if (spawn && spawn->IsEntity()) {
  2212. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2213. if (spawn->IsPlayer())
  2214. ((Player*)spawn)->SetCharSheetChanged(true);
  2215. }
  2216. return 0;
  2217. }
  2218. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2219. if (!lua_interface)
  2220. return 0;
  2221. Spawn* spawn = lua_interface->GetSpawn(state);
  2222. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2223. float value = lua_interface->GetFloatValue(state, 3);
  2224. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2225. if (value != 0) {
  2226. int32 spell_id = 0;
  2227. if (luaspell && luaspell->spell && luaspell->caster) {
  2228. spell_id = luaspell->spell->GetSpellID();
  2229. ZoneServer* zone = luaspell->caster->GetZone();
  2230. Spawn* target = 0;
  2231. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2232. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2233. target = zone->GetSpawnByID(luaspell->targets[i]);
  2234. if (target && target->Alive()) {
  2235. if (target->IsPlayer()) {
  2236. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2237. Client* client = target->GetZone()->GetClientBySpawn(target);
  2238. if (client) {
  2239. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2240. if (packet)
  2241. client->QueuePacket(packet);
  2242. }
  2243. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2244. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2245. }
  2246. else if (target->IsNPC()) {
  2247. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2248. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2249. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2250. }
  2251. else
  2252. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2253. }
  2254. }
  2255. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2256. }
  2257. else if (spawn) {
  2258. if (spawn->IsPlayer()) {
  2259. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2260. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2261. if (client) {
  2262. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2263. if (packet)
  2264. client->QueuePacket(packet);
  2265. }
  2266. }
  2267. else if (spawn->IsNPC())
  2268. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2269. else
  2270. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2271. }
  2272. }
  2273. else
  2274. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2275. return 0;
  2276. }
  2277. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2278. if (!lua_interface)
  2279. return 0;
  2280. Spawn* spawn = lua_interface->GetSpawn(state);
  2281. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2282. if (spawn && spawn->IsPlayer()) {
  2283. int32 spell_id = 0;
  2284. if (luaspell && luaspell->spell) {
  2285. spell_id = luaspell->spell->GetSpellID();
  2286. ZoneServer* zone = luaspell->caster->GetZone();
  2287. Spawn* target = 0;
  2288. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2289. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2290. target = zone->GetSpawnByID(luaspell->targets[i]);
  2291. if (target) {
  2292. if (target->IsPlayer()) {
  2293. ((Player*)target)->RemoveSkillBonus(spell_id);
  2294. Client* client = target->GetZone()->GetClientBySpawn(target);
  2295. if (client) {
  2296. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2297. if (packet)
  2298. client->QueuePacket(packet);
  2299. }
  2300. }
  2301. else if (target->IsNPC())
  2302. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2303. else
  2304. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2305. }
  2306. }
  2307. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2308. }
  2309. else if (spawn) {
  2310. if (spawn->IsPlayer()) {
  2311. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2312. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2313. if (client) {
  2314. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2315. if (packet)
  2316. client->QueuePacket(packet);
  2317. }
  2318. }
  2319. else if (spawn->IsNPC())
  2320. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2321. else
  2322. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2323. }
  2324. }
  2325. return 0;
  2326. }
  2327. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2328. if (!lua_interface)
  2329. return 0;
  2330. Spawn* spawn = lua_interface->GetSpawn(state);
  2331. int8 type = lua_interface->GetInt32Value(state, 2);
  2332. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2333. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2334. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2335. ZoneServer* zone = luaspell->caster->GetZone();
  2336. Spawn* target = 0;
  2337. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2338. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2339. target = zone->GetSpawnByID(luaspell->targets[i]);
  2340. if (target && target->IsEntity()) {
  2341. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2342. ((Entity*)target)->AddMezSpell(luaspell);
  2343. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2344. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2345. if (target->IsNPC())
  2346. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2347. }
  2348. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2349. ((Entity*)target)->AddStifleSpell(luaspell);
  2350. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2351. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2352. if (target->IsNPC())
  2353. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2354. }
  2355. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2356. ((Entity*)target)->AddDazeSpell(luaspell);
  2357. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2358. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2359. if (target->IsNPC())
  2360. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2361. }
  2362. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2363. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2364. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2365. ((Entity*)target)->AddStunSpell(luaspell);
  2366. if (target->IsNPC())
  2367. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2368. }
  2369. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2370. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2371. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2372. ((Entity*)target)->AddRootSpell(luaspell);
  2373. if (target->IsNPC())
  2374. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2375. }
  2376. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2377. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2378. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2379. ((Entity*)target)->AddFearSpell(luaspell);
  2380. if (target->IsNPC())
  2381. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2382. }
  2383. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2384. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2385. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2386. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2387. }
  2388. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2389. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2390. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2391. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2392. }
  2393. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2394. ((Entity*)target)->AddSnareSpell(luaspell);
  2395. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2396. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2397. if (target->IsNPC())
  2398. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2399. }
  2400. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2401. ((Entity*)target)->AddFlightSpell(luaspell);
  2402. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2403. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2404. }
  2405. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2406. ((Entity*)target)->AddGlideSpell(luaspell);
  2407. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2408. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2409. }
  2410. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2411. ((Entity*)target)->AddSafefallSpell(luaspell);
  2412. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2413. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2414. }
  2415. else
  2416. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2417. }
  2418. else
  2419. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2420. }
  2421. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2422. }
  2423. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2424. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2425. ((Entity*)spawn)->AddMezSpell(luaspell);
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2428. }
  2429. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2430. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2431. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2432. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2433. }
  2434. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2435. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2436. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2437. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2438. }
  2439. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2440. ((Entity*)spawn)->AddStunSpell(luaspell);
  2441. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2442. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2443. }
  2444. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2445. ((Entity*)spawn)->AddRootSpell(luaspell);
  2446. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2447. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2448. }
  2449. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2450. ((Entity*)spawn)->AddFearSpell(luaspell);
  2451. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2452. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2453. }
  2454. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2455. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2456. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2457. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2458. }
  2459. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2460. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2461. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2462. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2463. }
  2464. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2465. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2466. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2467. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2468. }
  2469. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2470. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2471. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2472. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2473. }
  2474. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2475. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2476. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2477. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2478. }
  2479. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2480. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2481. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2482. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2483. }
  2484. else
  2485. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2486. }
  2487. else
  2488. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2489. return 0;
  2490. }
  2491. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2492. if (!lua_interface)
  2493. return 0;
  2494. Spawn* spawn = lua_interface->GetSpawn(state);
  2495. int8 type = lua_interface->GetInt8Value(state, 2);
  2496. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2497. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2498. if (spawn && spawn->IsEntity()) {
  2499. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2500. ZoneServer* zone = luaspell->caster->GetZone();
  2501. Spawn* target = 0;
  2502. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2503. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2504. target = zone->GetSpawnByID(luaspell->targets[i]);
  2505. if (target) {
  2506. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2507. ((Entity*)target)->RemoveMezSpell(luaspell);
  2508. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2509. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2510. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2511. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2512. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2513. ((Entity*)target)->RemoveStunSpell(luaspell);
  2514. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2515. ((Entity*)target)->RemoveRootSpell(luaspell);
  2516. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2517. ((Entity*)target)->RemoveFearSpell(luaspell);
  2518. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2519. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2520. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2521. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2522. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2523. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2524. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2525. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2526. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2527. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2528. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2529. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2530. else
  2531. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2532. }
  2533. }
  2534. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2535. }
  2536. else if (only_remove_spawn) {
  2537. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2538. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2539. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2540. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2541. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2542. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2543. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2544. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2545. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2546. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2547. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2548. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2549. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2550. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2551. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2552. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2553. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2554. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2555. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2556. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2557. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2558. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2559. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2560. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2561. else
  2562. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2563. }
  2564. }
  2565. return 0;
  2566. }
  2567. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2568. if (!lua_interface)
  2569. return 0;
  2570. Spawn* spawn = lua_interface->GetSpawn(state);
  2571. int8 type = lua_interface->GetInt8Value(state, 2);
  2572. bool hasEffect = false;
  2573. if (!spawn)
  2574. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2575. else if (!spawn->IsEntity())
  2576. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2577. else if (type < CONTROL_MAX_EFFECTS)
  2578. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2579. else
  2580. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2581. lua_interface->SetBooleanValue(state, hasEffect);
  2582. return 1;
  2583. }
  2584. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2585. if (!lua_interface)
  2586. return 0;
  2587. Spawn* spawn = lua_interface->GetSpawn(state);
  2588. float distance = 0.0f;
  2589. if (!spawn)
  2590. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2591. else if (!spawn->IsNPC())
  2592. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2593. else
  2594. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2595. lua_interface->SetFloatValue(state, distance);
  2596. return 1;
  2597. }
  2598. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2599. if (!lua_interface)
  2600. return 0;
  2601. Spawn* spawn = lua_interface->GetSpawn(state);
  2602. float distance = 0.0f;
  2603. if (!spawn)
  2604. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2605. else if (!spawn->IsNPC())
  2606. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2607. else
  2608. distance = ((NPC*)spawn)->GetAggroRadius();
  2609. lua_interface->SetFloatValue(state, distance);
  2610. return 1;
  2611. }
  2612. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2613. if (!lua_interface)
  2614. return 0;
  2615. Spawn* spawn = lua_interface->GetSpawn(state);
  2616. float distance = lua_interface->GetFloatValue(state, 2);
  2617. bool override = lua_interface->GetBooleanValue(state, 3);
  2618. bool result = false;
  2619. lua_interface->ResetFunctionStack(state);
  2620. if (!spawn)
  2621. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2622. else if (!spawn->IsNPC())
  2623. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2624. else
  2625. {
  2626. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2627. result = true;
  2628. }
  2629. lua_interface->SetBooleanValue(state, result);
  2630. return 1;
  2631. }
  2632. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2633. if (!lua_interface)
  2634. return 0;
  2635. Spawn* spawn = lua_interface->GetSpawn(state);
  2636. int16 value = lua_interface->GetInt16Value(state, 2);
  2637. if (spawn && spawn->IsEntity()) {
  2638. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2639. if (spawn->IsPlayer())
  2640. ((Player*)spawn)->SetCharSheetChanged(true);
  2641. }
  2642. return 0;
  2643. }
  2644. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2645. if (!lua_interface)
  2646. return 0;
  2647. Spawn* spawn = lua_interface->GetSpawn(state);
  2648. int16 value = lua_interface->GetInt16Value(state, 2);
  2649. if (spawn && spawn->IsEntity()) {
  2650. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2651. if (spawn->IsPlayer())
  2652. ((Player*)spawn)->SetCharSheetChanged(true);
  2653. }
  2654. return 0;
  2655. }
  2656. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2657. if (!lua_interface)
  2658. return 0;
  2659. Spawn* spawn = lua_interface->GetSpawn(state);
  2660. int16 value = lua_interface->GetInt16Value(state, 2);
  2661. if (spawn && spawn->IsEntity()) {
  2662. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2663. if (spawn->IsPlayer())
  2664. ((Player*)spawn)->SetCharSheetChanged(true);
  2665. }
  2666. return 0;
  2667. }
  2668. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2669. if (!lua_interface)
  2670. return 0;
  2671. Spawn* spawn = lua_interface->GetSpawn(state);
  2672. int16 value = lua_interface->GetInt16Value(state, 2);
  2673. if (spawn && spawn->IsEntity()) {
  2674. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2675. if (spawn->IsPlayer())
  2676. ((Player*)spawn)->SetCharSheetChanged(true);
  2677. }
  2678. return 0;
  2679. }
  2680. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2681. if (!lua_interface)
  2682. return 0;
  2683. Spawn* spawn = lua_interface->GetSpawn(state);
  2684. int16 value = lua_interface->GetInt16Value(state, 2);
  2685. if (spawn && spawn->IsEntity()) {
  2686. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2687. if (spawn->IsPlayer())
  2688. ((Player*)spawn)->SetCharSheetChanged(true);
  2689. }
  2690. return 0;
  2691. }
  2692. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2693. if (!lua_interface)
  2694. return 0;
  2695. Spawn* spawn = lua_interface->GetSpawn(state);
  2696. int8 value = lua_interface->GetInt8Value(state, 2);
  2697. if (spawn && spawn->IsEntity()) {
  2698. ((Entity*)spawn)->SetDeity(value);
  2699. if (spawn->IsPlayer())
  2700. ((Player*)spawn)->SetCharSheetChanged(true);
  2701. }
  2702. lua_interface->ResetFunctionStack(state);
  2703. return 0;
  2704. }
  2705. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2706. if (!lua_interface)
  2707. return 0;
  2708. Spawn* spawn = lua_interface->GetSpawn(state);
  2709. if (spawn && spawn->IsEntity()) {
  2710. int8 deity = ((Entity*)spawn)->GetDeity();
  2711. lua_interface->SetInt32Value(state, deity);
  2712. return 1;
  2713. }
  2714. return 0;
  2715. }
  2716. int EQ2Emu_lua_SetInt(lua_State* state) {
  2717. if (!lua_interface)
  2718. return 0;
  2719. Spawn* spawn = lua_interface->GetSpawn(state);
  2720. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2721. if (spawn && spawn->IsEntity()) {
  2722. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2723. if (spawn->IsPlayer())
  2724. ((Player*)spawn)->SetCharSheetChanged(true);
  2725. }
  2726. return 0;
  2727. }
  2728. int EQ2Emu_lua_SetWis(lua_State* state) {
  2729. if (!lua_interface)
  2730. return 0;
  2731. Spawn* spawn = lua_interface->GetSpawn(state);
  2732. float value = lua_interface->GetFloatValue(state, 2);
  2733. if (spawn && spawn->IsEntity()) {
  2734. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2735. if (spawn->IsPlayer())
  2736. ((Player*)spawn)->SetCharSheetChanged(true);
  2737. }
  2738. return 0;
  2739. }
  2740. int EQ2Emu_lua_SetSta(lua_State* state) {
  2741. if (!lua_interface)
  2742. return 0;
  2743. Spawn* spawn = lua_interface->GetSpawn(state);
  2744. float value = lua_interface->GetFloatValue(state, 2);
  2745. if (spawn && spawn->IsEntity()) {
  2746. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2747. if (spawn->IsPlayer())
  2748. ((Player*)spawn)->SetCharSheetChanged(true);
  2749. }
  2750. return 0;
  2751. }
  2752. int EQ2Emu_lua_SetStr(lua_State* state) {
  2753. if (!lua_interface)
  2754. return 0;
  2755. Spawn* spawn = lua_interface->GetSpawn(state);
  2756. float value = lua_interface->GetFloatValue(state, 2);
  2757. if (spawn && spawn->IsEntity()) {
  2758. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2759. if (spawn->IsPlayer())
  2760. ((Player*)spawn)->SetCharSheetChanged(true);
  2761. }
  2762. return 0;
  2763. }
  2764. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2765. if (!lua_interface)
  2766. return 0;
  2767. Spawn* spawn = lua_interface->GetSpawn(state);
  2768. float value = lua_interface->GetFloatValue(state, 2);
  2769. if (spawn && spawn->IsEntity()) {
  2770. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2771. if (spawn->IsPlayer())
  2772. ((Player*)spawn)->SetCharSheetChanged(true);
  2773. }
  2774. return 0;
  2775. }
  2776. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2777. if (!lua_interface)
  2778. return 0;
  2779. Spawn* spawn = lua_interface->GetSpawn(state);
  2780. if (spawn) {
  2781. lua_interface->SetInt32Value(state, spawn->GetHP());
  2782. return 1;
  2783. }
  2784. return 0;
  2785. }
  2786. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2787. if (!lua_interface)
  2788. return 0;
  2789. Spawn* spawn = lua_interface->GetSpawn(state);
  2790. if (spawn) {
  2791. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2792. return 1;
  2793. }
  2794. return 0;
  2795. }
  2796. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2797. if (!lua_interface)
  2798. return 0;
  2799. Spawn* spawn = lua_interface->GetSpawn(state);
  2800. if (spawn) {
  2801. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2802. return 1;
  2803. }
  2804. return 0;
  2805. }
  2806. int EQ2Emu_lua_GetName(lua_State* state) {
  2807. if (!lua_interface)
  2808. return 0;
  2809. Spawn* spawn = lua_interface->GetSpawn(state);
  2810. if (spawn) {
  2811. lua_interface->SetStringValue(state, spawn->GetName());
  2812. return 1;
  2813. }
  2814. return 0;
  2815. }
  2816. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2817. Spawn* spawn = lua_interface->GetSpawn(state);
  2818. if (spawn) {
  2819. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2820. return 1;
  2821. }
  2822. return 0;
  2823. }
  2824. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2825. if (!lua_interface)
  2826. return 0;
  2827. Spawn* spawn = lua_interface->GetSpawn(state);
  2828. if (spawn) {
  2829. lua_interface->SetInt32Value(state, spawn->GetPower());
  2830. return 1;
  2831. }
  2832. return 0;
  2833. }
  2834. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2835. if (!lua_interface)
  2836. return 0;
  2837. Spawn* spawn = lua_interface->GetSpawn(state);
  2838. if (spawn) {
  2839. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2840. return 1;
  2841. }
  2842. return 0;
  2843. }
  2844. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2845. if (!lua_interface)
  2846. return 0;
  2847. Spawn* spawn = lua_interface->GetSpawn(state);
  2848. if (spawn) {
  2849. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2850. return 1;
  2851. }
  2852. return 0;
  2853. }
  2854. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2855. if (!lua_interface)
  2856. return 0;
  2857. Spawn* spawn = lua_interface->GetSpawn(state);
  2858. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2859. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2860. if (spawn && spawn2) {
  2861. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2862. lua_interface->SetFloatValue(state, distance);
  2863. return 1;
  2864. }
  2865. return 0;
  2866. }
  2867. int EQ2Emu_lua_GetX(lua_State* state) {
  2868. if (!lua_interface)
  2869. return 0;
  2870. Spawn* spawn = lua_interface->GetSpawn(state);
  2871. if (spawn) {
  2872. lua_interface->SetFloatValue(state, spawn->GetX());
  2873. return 1;
  2874. }
  2875. return 0;
  2876. }
  2877. int EQ2Emu_lua_GetY(lua_State* state) {
  2878. if (!lua_interface)
  2879. return 0;
  2880. Spawn* spawn = lua_interface->GetSpawn(state);
  2881. if (spawn) {
  2882. lua_interface->SetFloatValue(state, spawn->GetY());
  2883. return 1;
  2884. }
  2885. return 0;
  2886. }
  2887. int EQ2Emu_lua_GetZ(lua_State* state) {
  2888. if (!lua_interface)
  2889. return 0;
  2890. Spawn* spawn = lua_interface->GetSpawn(state);
  2891. if (spawn) {
  2892. lua_interface->SetFloatValue(state, spawn->GetZ());
  2893. return 1;
  2894. }
  2895. return 0;
  2896. }
  2897. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2898. if (!lua_interface)
  2899. return 0;
  2900. Spawn* spawn = lua_interface->GetSpawn(state);
  2901. if (spawn) {
  2902. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2903. return 1;
  2904. }
  2905. return 0;
  2906. }
  2907. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2908. if (!lua_interface)
  2909. return 0;
  2910. Spawn* spawn = lua_interface->GetSpawn(state);
  2911. if (spawn) {
  2912. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2913. return 1;
  2914. }
  2915. return 0;
  2916. }
  2917. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2918. if (!lua_interface)
  2919. return 0;
  2920. Spawn* spawn = lua_interface->GetSpawn(state);
  2921. if (spawn) {
  2922. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2923. return 1;
  2924. }
  2925. return 0;
  2926. }
  2927. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2928. if (!lua_interface)
  2929. return 0;
  2930. Spawn* spawn = lua_interface->GetSpawn(state);
  2931. if (spawn && spawn->IsEntity()) {
  2932. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2933. return 1;
  2934. }
  2935. return 0;
  2936. }
  2937. int EQ2Emu_lua_GetInt(lua_State* state) {
  2938. if (!lua_interface)
  2939. return 0;
  2940. Spawn* spawn = lua_interface->GetSpawn(state);
  2941. if (spawn && spawn->IsEntity()) {
  2942. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2943. return 1;
  2944. }
  2945. return 0;
  2946. }
  2947. int EQ2Emu_lua_GetWis(lua_State* state) {
  2948. if (!lua_interface)
  2949. return 0;
  2950. Spawn* spawn = lua_interface->GetSpawn(state);
  2951. if (spawn && spawn->IsEntity()) {
  2952. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2953. return 1;
  2954. }
  2955. return 0;
  2956. }
  2957. int EQ2Emu_lua_GetSta(lua_State* state) {
  2958. if (!lua_interface)
  2959. return 0;
  2960. Spawn* spawn = lua_interface->GetSpawn(state);
  2961. if (spawn && spawn->IsEntity()) {
  2962. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2963. return 1;
  2964. }
  2965. return 0;
  2966. }
  2967. int EQ2Emu_lua_GetStr(lua_State* state) {
  2968. if (!lua_interface)
  2969. return 0;
  2970. Spawn* spawn = lua_interface->GetSpawn(state);
  2971. if (spawn && spawn->IsEntity()) {
  2972. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2973. return 1;
  2974. }
  2975. return 0;
  2976. }
  2977. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2978. if (!lua_interface)
  2979. return 0;
  2980. Spawn* spawn = lua_interface->GetSpawn(state);
  2981. if (spawn && spawn->IsEntity()) {
  2982. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2983. return 1;
  2984. }
  2985. return 0;
  2986. }
  2987. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2988. if (!lua_interface)
  2989. return 0;
  2990. Spawn* spawn = lua_interface->GetSpawn(state);
  2991. if (spawn && spawn->IsEntity()) {
  2992. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2993. return 1;
  2994. }
  2995. return 0;
  2996. }
  2997. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2998. if (!lua_interface)
  2999. return 0;
  3000. Spawn* spawn = lua_interface->GetSpawn(state);
  3001. if (spawn && spawn->IsEntity()) {
  3002. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3003. return 1;
  3004. }
  3005. return 0;
  3006. }
  3007. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3008. if (!lua_interface)
  3009. return 0;
  3010. Spawn* spawn = lua_interface->GetSpawn(state);
  3011. if (spawn && spawn->IsEntity()) {
  3012. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3013. return 1;
  3014. }
  3015. return 0;
  3016. }
  3017. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3018. if (!lua_interface)
  3019. return 0;
  3020. Spawn* spawn = lua_interface->GetSpawn(state);
  3021. if (spawn && spawn->IsEntity()) {
  3022. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3023. return 1;
  3024. }
  3025. return 0;
  3026. }
  3027. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3028. if (!lua_interface)
  3029. return 0;
  3030. Spawn* spawn = lua_interface->GetSpawn(state);
  3031. if (spawn && spawn->IsEntity()) {
  3032. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3033. return 1;
  3034. }
  3035. return 0;
  3036. }
  3037. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3038. if (!lua_interface)
  3039. return 0;
  3040. Spawn* player = lua_interface->GetSpawn(state);
  3041. if (!player || !player->IsPlayer()) {
  3042. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3043. return 0;
  3044. }
  3045. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3046. if (quest_id <= 0) {
  3047. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3048. return 0;
  3049. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3050. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3051. return 0;
  3052. }
  3053. int32 step = lua_interface->GetInt32Value(state, 3);
  3054. if (step > 0) {
  3055. Client* client = player->GetZone()->GetClientBySpawn(player);
  3056. if (client)
  3057. client->AddPendingQuestUpdate(quest_id, step);
  3058. } else {
  3059. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3060. }
  3061. return 0;
  3062. }
  3063. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3064. Spawn* player = lua_interface->GetSpawn(state);
  3065. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3066. int32 step = lua_interface->GetInt32Value(state, 3);
  3067. int32 progress = lua_interface->GetInt32Value(state, 4);
  3068. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3069. Client* client = player->GetZone()->GetClientBySpawn(player);
  3070. if (client)
  3071. client->AddPendingQuestUpdate(quest_id, step, progress);
  3072. }
  3073. return 0;
  3074. }
  3075. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3076. if (!lua_interface)
  3077. return 0;
  3078. Spawn* player = lua_interface->GetSpawn(state);
  3079. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3080. if (player && player->IsPlayer() && quest_id > 0) {
  3081. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3082. return 1;
  3083. }
  3084. return 0;
  3085. }
  3086. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3087. if (!lua_interface)
  3088. return 0;
  3089. Spawn* player = lua_interface->GetSpawn(state);
  3090. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3091. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3092. if (player && player->IsPlayer() && quest_id > 0) {
  3093. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3094. return 1;
  3095. }
  3096. return 0;
  3097. }
  3098. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3099. if (!lua_interface)
  3100. return 0;
  3101. Spawn* player = lua_interface->GetSpawn(state);
  3102. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3103. if (player && player->IsPlayer() && quest_id > 0) {
  3104. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3105. return 1;
  3106. }
  3107. return 0;
  3108. }
  3109. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3110. if (!lua_interface)
  3111. return 0;
  3112. Quest* quest = lua_interface->GetQuest(state);
  3113. string name = lua_interface->GetStringValue(state, 2);
  3114. string type = lua_interface->GetStringValue(state, 3);
  3115. string zone = lua_interface->GetStringValue(state, 4);
  3116. int16 level = lua_interface->GetInt16Value(state, 5);
  3117. string description = lua_interface->GetStringValue(state, 6);
  3118. bool load = true;
  3119. if (!quest) {
  3120. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3121. load = false;
  3122. }
  3123. if (load && name.length() == 0) {
  3124. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3125. load = false;
  3126. }
  3127. if (load && type.length() == 0) {
  3128. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3129. load = false;
  3130. }
  3131. if (load && zone.length() == 0) {
  3132. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3133. load = false;
  3134. }
  3135. if (load && description.length() == 0) {
  3136. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3137. load = false;
  3138. }
  3139. if (load && level == 0) {
  3140. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3141. load = false;
  3142. }
  3143. if (load)
  3144. quest->RegisterQuest(name, type, zone, level, description);
  3145. return 0;
  3146. }
  3147. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3148. if (!lua_interface)
  3149. return 0;
  3150. Quest* quest = lua_interface->GetQuest(state);
  3151. if (quest) {
  3152. int8 level = lua_interface->GetInt16Value(state, 2);
  3153. quest->SetPrereqLevel(level);
  3154. }
  3155. return 0;
  3156. }
  3157. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3158. if (!lua_interface)
  3159. return 0;
  3160. Quest* quest = lua_interface->GetQuest(state);
  3161. if (quest) {
  3162. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3163. quest->AddPrereqQuest(quest_id);
  3164. }
  3165. return 0;
  3166. }
  3167. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3168. if (!lua_interface)
  3169. return 0;
  3170. Quest* quest = lua_interface->GetQuest(state);
  3171. if (quest) {
  3172. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3173. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3174. if (quantity == 0)
  3175. quantity = 1;
  3176. Item* master_item = master_item_list.GetItem(item_id);
  3177. if (master_item) {
  3178. Item* item = new Item(master_item);
  3179. item->details.count = quantity;
  3180. quest->AddPrereqItem(item);
  3181. }
  3182. }
  3183. return 0;
  3184. }
  3185. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3186. if (!lua_interface)
  3187. return 0;
  3188. Spawn* player = lua_interface->GetSpawn(state);
  3189. if(!player || !player->IsPlayer()) {
  3190. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3191. return 0;
  3192. }
  3193. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3194. if (quest_id > 0) {
  3195. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3196. return 1;
  3197. } else {
  3198. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3199. }
  3200. return 0;
  3201. }
  3202. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3203. if (!lua_interface)
  3204. return 0;
  3205. Quest* quest = lua_interface->GetQuest(state);
  3206. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3207. lua_interface->ResetFunctionStack(state);
  3208. if (quest && spawn_id > 0)
  3209. quest->SetQuestReturnNPC(spawn_id);
  3210. return 0;
  3211. }
  3212. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3213. if (!lua_interface)
  3214. return 0;
  3215. Spawn* spawn = lua_interface->GetSpawn(state);
  3216. int32 time = lua_interface->GetInt32Value(state, 2);
  3217. string function = lua_interface->GetStringValue(state, 3);
  3218. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3219. Spawn* player = lua_interface->GetSpawn(state, 5);
  3220. lua_interface->ResetFunctionStack(state);
  3221. if (!spawn) {
  3222. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3223. return 0;
  3224. }
  3225. if (time <= 0) {
  3226. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3227. return 0;
  3228. }
  3229. if (function.length() == 0) {
  3230. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3231. return 0;
  3232. }
  3233. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3234. if ( time < 10)
  3235. time = 10;
  3236. timer->timer = Timer::GetCurrentTime2() + time;
  3237. timer->function = function;
  3238. timer->spawn = spawn->GetID();
  3239. timer->player = player ? player->GetID() : 0;
  3240. if (max_count == 0)
  3241. max_count = 1;
  3242. timer->max_count = max_count;
  3243. timer->current_count = 0;
  3244. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3245. return 0;
  3246. }
  3247. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3248. if (!lua_interface)
  3249. return 0;
  3250. Spawn* spawn = lua_interface->GetSpawn(state);
  3251. string function = lua_interface->GetStringValue(state, 2);
  3252. lua_interface->ResetFunctionStack(state);
  3253. if (!spawn) {
  3254. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3255. return 0;
  3256. }
  3257. if(!spawn->GetZone()) {
  3258. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3259. return 0;
  3260. }
  3261. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3262. return 0;
  3263. }
  3264. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3265. if (!lua_interface)
  3266. return 0;
  3267. Spawn* player = lua_interface->GetSpawn(state);
  3268. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3269. lua_interface->ResetFunctionStack(state);
  3270. if (player && player->IsPlayer() && quest_id > 0) {
  3271. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3272. return 1;
  3273. }
  3274. return 0;
  3275. }
  3276. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3277. if (!lua_interface)
  3278. return 0;
  3279. Spawn* player = lua_interface->GetSpawn(state);
  3280. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3281. lua_interface->ResetFunctionStack(state);
  3282. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3283. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3284. if (quest)
  3285. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3286. return 1;
  3287. }
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Spawn* player = lua_interface->GetSpawn(state);
  3294. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3295. lua_interface->ResetFunctionStack(state);
  3296. if (player && player->IsPlayer() && quest_id > 0) {
  3297. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3298. return 1;
  3299. }
  3300. return 0;
  3301. }
  3302. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3303. if (!lua_interface)
  3304. return 0;
  3305. Spawn* npc = lua_interface->GetSpawn(state);
  3306. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3307. lua_interface->ResetFunctionStack(state);
  3308. if (npc && !npc->IsPlayer() && quest_id > 0)
  3309. npc->AddProvidedQuest(quest_id);
  3310. return 0;
  3311. }
  3312. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3313. if (!lua_interface)
  3314. return 0;
  3315. Spawn* npc = lua_interface->GetSpawn(state);
  3316. Spawn* player = lua_interface->GetSpawn(state, 2);
  3317. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3318. bool forced = lua_interface->GetBooleanValue(state, 4);
  3319. lua_interface->ResetFunctionStack(state);
  3320. /* NPC is allowed to be null */
  3321. if (player && player->IsPlayer() && quest_id > 0) {
  3322. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3323. if (master_quest) {
  3324. Client* client = player->GetZone()->GetClientBySpawn(player);
  3325. if (!client) {
  3326. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3327. }
  3328. Quest* quest = new Quest(master_quest);
  3329. if (!quest) {
  3330. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3331. }
  3332. if (client && quest) {
  3333. if (npc)
  3334. quest->SetQuestGiver(npc->GetDatabaseID());
  3335. else
  3336. quest->SetQuestGiver(0);
  3337. client->AddPendingQuest(quest, forced);
  3338. }
  3339. }
  3340. else {
  3341. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3342. }
  3343. }
  3344. else {
  3345. lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
  3346. }
  3347. return 0;
  3348. }
  3349. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3350. if (!lua_interface)
  3351. return 0;
  3352. Quest* quest = lua_interface->GetQuest(state);
  3353. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3354. lua_interface->ResetFunctionStack(state);
  3355. if (quest) {
  3356. quest->AddPrereqClass(class_id);
  3357. }
  3358. return 0;
  3359. }
  3360. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3361. if (!lua_interface)
  3362. return 0;
  3363. Quest* quest = lua_interface->GetQuest(state);
  3364. int8 race = lua_interface->GetInt8Value(state, 2);
  3365. lua_interface->ResetFunctionStack(state);
  3366. if (quest) {
  3367. quest->AddPrereqRace(race);
  3368. }
  3369. return 0;
  3370. }
  3371. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3372. if (!lua_interface)
  3373. return 0;
  3374. Quest* quest = lua_interface->GetQuest(state);
  3375. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3376. lua_interface->ResetFunctionStack(state);
  3377. if (quest) {
  3378. quest->AddPrereqModelType(model_type);
  3379. }
  3380. return 0;
  3381. }
  3382. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3383. if (!lua_interface)
  3384. return 0;
  3385. Quest* quest = lua_interface->GetQuest(state);
  3386. int8 level = lua_interface->GetInt8Value(state, 2);
  3387. lua_interface->ResetFunctionStack(state);
  3388. if (!quest) {
  3389. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3390. return 0;
  3391. }
  3392. quest->SetPrereqTSLevel(level);
  3393. return 0;
  3394. }
  3395. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3396. if (!lua_interface)
  3397. return 0;
  3398. Quest* quest = lua_interface->GetQuest(state);
  3399. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3400. lua_interface->ResetFunctionStack(state);
  3401. if (!quest) {
  3402. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3403. return 0;
  3404. }
  3405. quest->AddPrereqTradeskillClass(class_id);
  3406. return 0;
  3407. }
  3408. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3409. if (!lua_interface)
  3410. return 0;
  3411. Quest* quest = lua_interface->GetQuest(state);
  3412. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3413. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3414. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3415. lua_interface->ResetFunctionStack(state);
  3416. if (quest) {
  3417. quest->AddPrereqFaction(faction_id, min, max);
  3418. }
  3419. return 0;
  3420. }
  3421. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3422. if (!lua_interface)
  3423. return 0;
  3424. Quest* quest = lua_interface->GetQuest(state);
  3425. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3426. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3427. lua_interface->ResetFunctionStack(state);
  3428. if (quest) {
  3429. if (quantity == 0)
  3430. quantity = 1;
  3431. Item* master_item = master_item_list.GetItem(item_id);
  3432. if (master_item) {
  3433. Item* item = new Item(master_item);
  3434. item->details.count = quantity;
  3435. quest->AddSelectableRewardItem(item);
  3436. }
  3437. }
  3438. return 0;
  3439. }
  3440. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3441. if (!lua_interface)
  3442. return 0;
  3443. Quest* quest = lua_interface->GetQuest(state);
  3444. if (quest) {
  3445. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3446. vector<Item*>* items = quest->GetRewardItems();
  3447. if (items) {
  3448. vector<Item*>::iterator itr;
  3449. for (itr = items->begin(); itr != items->end(); itr++) {
  3450. if (*itr && (*itr)->details.item_id == item_id) {
  3451. lua_interface->SetBooleanValue(state, true);
  3452. return 1;
  3453. }
  3454. }
  3455. }
  3456. }
  3457. lua_interface->SetBooleanValue(state, false);
  3458. return 1;
  3459. }
  3460. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3461. if (!lua_interface)
  3462. return 0;
  3463. Quest* quest = lua_interface->GetQuest(state);
  3464. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3465. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3466. lua_interface->ResetFunctionStack(state);
  3467. if (quest) {
  3468. if (quantity == 0)
  3469. quantity = 1;
  3470. Item* master_item = master_item_list.GetItem(item_id);
  3471. if (master_item) {
  3472. Item* item = new Item(master_item);
  3473. item->details.count = quantity;
  3474. quest->AddRewardItem(item);
  3475. }
  3476. }
  3477. return 0;
  3478. }
  3479. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3480. if (!lua_interface)
  3481. return 0;
  3482. Quest* quest = lua_interface->GetQuest(state);
  3483. int32 copper = lua_interface->GetInt32Value(state, 2);
  3484. int32 silver = lua_interface->GetInt32Value(state, 3);
  3485. int32 gold = lua_interface->GetInt32Value(state, 4);
  3486. int32 plat = lua_interface->GetInt32Value(state, 5);
  3487. lua_interface->ResetFunctionStack(state);
  3488. if (quest) {
  3489. quest->AddRewardCoins(copper, silver, gold, plat);
  3490. }
  3491. return 0;
  3492. }
  3493. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3494. if (!lua_interface)
  3495. return 0;
  3496. Quest* quest = lua_interface->GetQuest(state);
  3497. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3498. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3499. lua_interface->ResetFunctionStack(state);
  3500. if (quest && faction_id > 0 && amount != 0)
  3501. quest->AddRewardFaction(faction_id, amount);
  3502. return 0;
  3503. }
  3504. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3505. if (!lua_interface)
  3506. return 0;
  3507. Quest* quest = lua_interface->GetQuest(state);
  3508. int32 status = lua_interface->GetInt32Value(state, 2);
  3509. lua_interface->ResetFunctionStack(state);
  3510. if (quest) {
  3511. quest->SetRewardStatus(status);
  3512. }
  3513. return 0;
  3514. }
  3515. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3516. if (!lua_interface)
  3517. return 0;
  3518. Quest* quest = lua_interface->GetQuest(state);
  3519. int32 status = lua_interface->GetInt32Value(state, 2);
  3520. lua_interface->ResetFunctionStack(state);
  3521. if (quest) {
  3522. quest->SetStatusTmpReward(status);
  3523. }
  3524. return 0;
  3525. }
  3526. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3527. if (!lua_interface)
  3528. return 0;
  3529. Quest* quest = lua_interface->GetQuest(state);
  3530. int64 coins = lua_interface->GetInt64Value(state, 2);
  3531. lua_interface->ResetFunctionStack(state);
  3532. if (quest) {
  3533. quest->SetCoinTmpReward(coins);
  3534. }
  3535. return 0;
  3536. }
  3537. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3538. if (!lua_interface)
  3539. return 0;
  3540. Quest* quest = lua_interface->GetQuest(state);
  3541. string comment = lua_interface->GetStringValue(state, 2);
  3542. lua_interface->ResetFunctionStack(state);
  3543. if (quest) {
  3544. quest->SetRewardComment(comment);
  3545. }
  3546. return 0;
  3547. }
  3548. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3549. if (!lua_interface)
  3550. return 0;
  3551. Quest* quest = lua_interface->GetQuest(state);
  3552. int32 exp = lua_interface->GetInt32Value(state, 2);
  3553. lua_interface->ResetFunctionStack(state);
  3554. if (quest) {
  3555. quest->SetRewardXP(exp);
  3556. }
  3557. return 0;
  3558. }
  3559. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3560. Quest* quest = lua_interface->GetQuest(state);
  3561. int32 step = lua_interface->GetInt32Value(state, 2);
  3562. string description = lua_interface->GetStringValue(state, 3);
  3563. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3564. float percentage = lua_interface->GetFloatValue(state, 5);
  3565. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3566. int16 icon = lua_interface->GetInt16Value(state, 7);
  3567. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3568. if (quest) {
  3569. const char* taskgroup = 0;
  3570. if (str_taskgroup.length() > 0)
  3571. taskgroup = str_taskgroup.c_str();
  3572. int32 id = 0;
  3573. vector<int32>* ids = 0;
  3574. int i = 0;
  3575. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3576. if (ids == 0)
  3577. ids = new vector<int32>;
  3578. ids->push_back(id);
  3579. i++;
  3580. }
  3581. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3582. if (quest_step && icon && quantity > 0)
  3583. quest_step->SetIcon(icon);
  3584. if (quest->GetPlayer()) {
  3585. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3586. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3587. }
  3588. }
  3589. lua_interface->ResetFunctionStack(state);
  3590. return 0;
  3591. }
  3592. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3593. {
  3594. if (!lua_interface)
  3595. return 0;
  3596. Quest* quest = lua_interface->GetQuest(state);
  3597. int32 step = lua_interface->GetInt32Value(state, 2);
  3598. string description = lua_interface->GetStringValue(state, 3);
  3599. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3600. float percentage = lua_interface->GetFloatValue(state, 5);
  3601. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3602. int16 icon = lua_interface->GetInt16Value(state, 7);
  3603. if (quest) {
  3604. const char* taskgroup = 0;
  3605. if (str_taskgroup.length() > 0)
  3606. taskgroup = str_taskgroup.c_str();
  3607. int32 id = 0;
  3608. vector<int32>* ids = 0;
  3609. int i = 0;
  3610. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3611. if (ids == 0)
  3612. ids = new vector<int32>;
  3613. ids->push_back(id);
  3614. i++;
  3615. }
  3616. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3617. if (quest_step && icon > 0 && quantity > 0)
  3618. quest_step->SetIcon(icon);
  3619. if (quest->GetPlayer()) {
  3620. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3621. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3622. }
  3623. safe_delete(ids);
  3624. }
  3625. lua_interface->ResetFunctionStack(state);
  3626. return 0;
  3627. }
  3628. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3629. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3630. }
  3631. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3632. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3633. }
  3634. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3635. if (!lua_interface)
  3636. return 0;
  3637. Quest* quest = lua_interface->GetQuest(state);
  3638. int32 step = lua_interface->GetInt32Value(state, 2);
  3639. string description = lua_interface->GetStringValue(state, 3);
  3640. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3641. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3642. int16 icon = lua_interface->GetInt16Value(state, 6);
  3643. if (quest) {
  3644. const char* taskgroup = 0;
  3645. if (str_taskgroup.length() > 0)
  3646. taskgroup = str_taskgroup.c_str();
  3647. int32 npc_id = 0;
  3648. vector<int32>* ids = 0;
  3649. int i = 0;
  3650. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3651. if (ids == 0)
  3652. ids = new vector<int32>;
  3653. ids->push_back(npc_id);
  3654. i++;
  3655. }
  3656. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3657. if (quest_step && icon > 0)
  3658. quest_step->SetIcon(icon);
  3659. if (quest->GetPlayer()) {
  3660. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3661. if(client)
  3662. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3663. }
  3664. safe_delete(ids);
  3665. }
  3666. lua_interface->ResetFunctionStack(state);
  3667. return 0;
  3668. }
  3669. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3670. if (!lua_interface)
  3671. return 0;
  3672. Quest* quest = lua_interface->GetQuest(state);
  3673. int32 step = lua_interface->GetInt32Value(state, 2);
  3674. string description = lua_interface->GetStringValue(state, 3);
  3675. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3676. float percentage = lua_interface->GetFloatValue(state, 5);
  3677. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3678. int16 icon = lua_interface->GetInt16Value(state, 7);
  3679. if (quest) {
  3680. const char* taskgroup = 0;
  3681. if (str_taskgroup.length() > 0)
  3682. taskgroup = str_taskgroup.c_str();
  3683. int32 item_id = 0;
  3684. vector<int32>* ids = 0;
  3685. int i = 0;
  3686. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3687. if (ids == 0)
  3688. ids = new vector<int32>;
  3689. ids->push_back(item_id);
  3690. i++;
  3691. }
  3692. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3693. if (quest_step && icon > 0 && quantity > 0)
  3694. quest_step->SetIcon(icon);
  3695. if (quest->GetPlayer()) {
  3696. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3697. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3698. }
  3699. safe_delete(ids);
  3700. }
  3701. lua_interface->ResetFunctionStack(state);
  3702. return 0;
  3703. }
  3704. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3705. if (!lua_interface)
  3706. return 0;
  3707. Quest* quest = lua_interface->GetQuest(state);
  3708. int32 step = lua_interface->GetInt32Value(state, 2);
  3709. string description = lua_interface->GetStringValue(state, 3);
  3710. float max_variation = lua_interface->GetFloatValue(state, 4);
  3711. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3712. int16 icon = lua_interface->GetInt16Value(state, 6);
  3713. if (quest) {
  3714. const char* taskgroup = 0;
  3715. if (str_taskgroup.length() > 0)
  3716. taskgroup = str_taskgroup.c_str();
  3717. vector<Location>* locations = 0;
  3718. int8 i = 7;
  3719. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3720. while (true) {
  3721. Location loc;
  3722. loc.x = lua_interface->GetFloatValue(state, i);
  3723. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3724. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3725. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3726. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3727. break;
  3728. if (locations == 0)
  3729. locations = new vector<Location>;
  3730. locations->push_back(loc);
  3731. i += 4;
  3732. }
  3733. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3734. if (quest_step && icon > 0)
  3735. quest_step->SetIcon(icon);
  3736. if (quest->GetPlayer()) {
  3737. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3738. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3739. }
  3740. }
  3741. lua_interface->ResetFunctionStack(state);
  3742. return 0;
  3743. }
  3744. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3745. if (!lua_interface)
  3746. return 0;
  3747. Quest* quest = lua_interface->GetQuest(state);
  3748. int32 step = lua_interface->GetInt32Value(state, 2);
  3749. string description = lua_interface->GetStringValue(state, 3);
  3750. float max_variation = lua_interface->GetFloatValue(state, 4);
  3751. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3752. int16 icon = lua_interface->GetInt16Value(state, 6);
  3753. if (quest) {
  3754. const char* taskgroup = 0;
  3755. if (str_taskgroup.length() > 0)
  3756. taskgroup = str_taskgroup.c_str();
  3757. vector<Location>* locations = 0;
  3758. int8 i = 7;
  3759. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3760. while (true) {
  3761. Location loc;
  3762. loc.x = lua_interface->GetFloatValue(state, i);
  3763. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3764. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3765. loc.zone_id = 0;
  3766. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3767. break;
  3768. if (locations == 0)
  3769. locations = new vector<Location>;
  3770. locations->push_back(loc);
  3771. i += 3;
  3772. }
  3773. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3774. if (quest_step && icon > 0)
  3775. quest_step->SetIcon(icon);
  3776. if (quest->GetPlayer()) {
  3777. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3778. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3779. }
  3780. }
  3781. lua_interface->ResetFunctionStack(state);
  3782. return 0;
  3783. }
  3784. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3785. if (!lua_interface)
  3786. return 0;
  3787. Quest* quest = lua_interface->GetQuest(state);
  3788. int32 step = lua_interface->GetInt32Value(state, 2);
  3789. string description = lua_interface->GetStringValue(state, 3);
  3790. float max_variation = lua_interface->GetFloatValue(state, 4);
  3791. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3792. int16 icon = lua_interface->GetInt16Value(state, 6);
  3793. if (quest) {
  3794. const char* taskgroup = 0;
  3795. if (str_taskgroup.length() > 0)
  3796. taskgroup = str_taskgroup.c_str();
  3797. vector<Location>* locations = 0;
  3798. int i = 7;
  3799. while (true) {
  3800. Location loc;
  3801. loc.x = lua_interface->GetFloatValue(state, i);
  3802. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3803. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3804. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3805. break;
  3806. if (locations == 0)
  3807. locations = new vector<Location>;
  3808. locations->push_back(loc);
  3809. i += 3;
  3810. }
  3811. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3812. if (quest_step && icon > 0)
  3813. quest_step->SetIcon(icon);
  3814. if (quest->GetPlayer()) {
  3815. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3816. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3817. }
  3818. }
  3819. lua_interface->ResetFunctionStack(state);
  3820. return 0;
  3821. }
  3822. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3823. Quest* quest = lua_interface->GetQuest(state);
  3824. int32 step = lua_interface->GetInt32Value(state, 2);
  3825. string description = lua_interface->GetStringValue(state, 3);
  3826. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3827. float percentage = lua_interface->GetFloatValue(state, 5);
  3828. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3829. int16 icon = lua_interface->GetInt16Value(state, 7);
  3830. if (quest) {
  3831. const char* taskgroup = 0;
  3832. if (str_taskgroup.length() > 0)
  3833. taskgroup = str_taskgroup.c_str();
  3834. int32 spell_id = 0;
  3835. vector<int32>* ids = 0;
  3836. int i = 0;
  3837. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3838. if (ids == 0)
  3839. ids = new vector<int32>;
  3840. ids->push_back(spell_id);
  3841. i++;
  3842. }
  3843. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3844. if (quest_step && icon > 0 && quantity > 0)
  3845. quest_step->SetIcon(icon);
  3846. if (quest->GetPlayer()) {
  3847. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3848. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3849. }
  3850. safe_delete(ids);
  3851. }
  3852. lua_interface->ResetFunctionStack(state);
  3853. return 0;
  3854. }
  3855. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3856. if (!lua_interface)
  3857. return 0;
  3858. Quest* quest = lua_interface->GetQuest(state);
  3859. int32 step = lua_interface->GetInt32Value(state, 2);
  3860. string description = lua_interface->GetStringValue(state, 3);
  3861. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3862. float percentage = lua_interface->GetFloatValue(state, 5);
  3863. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3864. int16 icon = lua_interface->GetInt16Value(state, 7);
  3865. if (quest) {
  3866. const char* taskgroup = 0;
  3867. if (str_taskgroup.length() > 0)
  3868. taskgroup = str_taskgroup.c_str();
  3869. int32 item_id = 0;
  3870. vector<int32>* ids = 0;
  3871. int i = 0;
  3872. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3873. if (ids == 0)
  3874. ids = new vector<int32>;
  3875. ids->push_back(item_id);
  3876. i++;
  3877. }
  3878. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3879. if (quest_step && icon > 0 && quantity > 0)
  3880. quest_step->SetIcon(icon);
  3881. if (quest->GetPlayer()) {
  3882. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3883. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3884. }
  3885. safe_delete(ids);
  3886. }
  3887. lua_interface->ResetFunctionStack(state);
  3888. return 0;
  3889. }
  3890. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3891. if (!lua_interface)
  3892. return 0;
  3893. Quest* quest = lua_interface->GetQuest(state);
  3894. int32 step = lua_interface->GetInt32Value(state, 2);
  3895. string description = lua_interface->GetStringValue(state, 3);
  3896. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3897. float percentage = lua_interface->GetFloatValue(state, 5);
  3898. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3899. int16 icon = lua_interface->GetInt16Value(state, 7);
  3900. if (quest) {
  3901. const char* taskgroup = 0;
  3902. if (str_taskgroup.length() > 0)
  3903. taskgroup = str_taskgroup.c_str();
  3904. int32 item_id = 0;
  3905. vector<int32>* ids = 0;
  3906. int i = 0;
  3907. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3908. if (ids == 0)
  3909. ids = new vector<int32>;
  3910. ids->push_back(item_id);
  3911. i++;
  3912. }
  3913. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3914. if (quest_step && icon > 0 && quantity > 0)
  3915. quest_step->SetIcon(icon);
  3916. if (quest->GetPlayer()) {
  3917. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3918. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3919. }
  3920. safe_delete(ids);
  3921. }
  3922. lua_interface->ResetFunctionStack(state);
  3923. return 0;
  3924. }
  3925. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3926. if (!lua_interface)
  3927. return 0;
  3928. Quest* quest = lua_interface->GetQuest(state);
  3929. string action = lua_interface->GetStringValue(state, 2);
  3930. lua_interface->ResetFunctionStack(state);
  3931. if (quest) {
  3932. if (action.length() > 0)
  3933. quest->SetCompleteAction(action);
  3934. }
  3935. return 0;
  3936. }
  3937. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3938. if (!lua_interface)
  3939. return 0;
  3940. Quest* quest = lua_interface->GetQuest(state);
  3941. int32 step = lua_interface->GetInt32Value(state, 2);
  3942. string action = lua_interface->GetStringValue(state, 3);
  3943. lua_interface->ResetFunctionStack(state);
  3944. if (quest) {
  3945. if (step > 0 && action.length() > 0)
  3946. quest->AddCompleteAction(step, action);
  3947. }
  3948. return 0;
  3949. }
  3950. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3951. if (!lua_interface)
  3952. return 0;
  3953. Quest* quest = lua_interface->GetQuest(state);
  3954. int32 step = lua_interface->GetInt32Value(state, 2);
  3955. string action = lua_interface->GetStringValue(state, 3);
  3956. lua_interface->ResetFunctionStack(state);
  3957. if (quest) {
  3958. if (step > 0 && action.length() > 0)
  3959. quest->AddProgressAction(step, action);
  3960. }
  3961. return 0;
  3962. }
  3963. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3964. if (!lua_interface)
  3965. return 0;
  3966. Quest* quest = lua_interface->GetQuest(state);
  3967. string description = lua_interface->GetStringValue(state, 2);
  3968. lua_interface->ResetFunctionStack(state);
  3969. if (quest && description.length() > 0)
  3970. quest->SetDescription(description);
  3971. return 0;
  3972. }
  3973. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3974. if (!lua_interface)
  3975. return 0;
  3976. Quest* quest = lua_interface->GetQuest(state);
  3977. string description = lua_interface->GetStringValue(state, 2);
  3978. lua_interface->ResetFunctionStack(state);
  3979. if (quest && description.length() > 0)
  3980. quest->SetCompletedDescription(description);
  3981. return 0;
  3982. }
  3983. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3984. if (!lua_interface)
  3985. return 0;
  3986. Quest* quest = lua_interface->GetQuest(state);
  3987. int32 step = lua_interface->GetInt32Value(state, 2);
  3988. string description = lua_interface->GetStringValue(state, 3);
  3989. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3990. lua_interface->ResetFunctionStack(state);
  3991. if (quest && step > 0 && description.length() > 0) {
  3992. quest->SetTaskGroupDescription(step, description, display_bullets);
  3993. /* if (quest->GetPlayer()) {
  3994. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3995. if (client)
  3996. client->SendQuestUpdateStep(quest, step, false);
  3997. }*/
  3998. }
  3999. return 0;
  4000. }
  4001. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4002. if (!lua_interface)
  4003. return 0;
  4004. Quest* quest = lua_interface->GetQuest(state);
  4005. int32 step = lua_interface->GetInt32Value(state, 2);
  4006. string description = lua_interface->GetStringValue(state, 3);
  4007. lua_interface->ResetFunctionStack(state);
  4008. if (quest && step > 0 && description.length() > 0) {
  4009. quest->SetStepDescription(step, description);
  4010. /*if (quest->GetPlayer()) {
  4011. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4012. if (client)
  4013. client->SendQuestUpdateStepImmediately(quest, step);
  4014. }*/
  4015. }
  4016. return 0;
  4017. }
  4018. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4019. Quest* quest = lua_interface->GetQuest(state);
  4020. string zone = lua_interface->GetStringValue(state, 2);
  4021. lua_interface->ResetFunctionStack(state);
  4022. if (quest && zone.length() > 0)
  4023. quest->SetZone(zone);
  4024. return 0;
  4025. }
  4026. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4027. if (!lua_interface)
  4028. return 0;
  4029. Quest* quest = lua_interface->GetQuest(state);
  4030. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4031. lua_interface->ResetFunctionStack(state);
  4032. if (quest && spawn) {
  4033. if (spawn->IsPlayer()) {
  4034. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4035. if (client)
  4036. {
  4037. client->AddPendingQuestAcceptReward(quest);
  4038. client->AddPendingQuestReward(quest);
  4039. }
  4040. }
  4041. }
  4042. return 0;
  4043. }
  4044. int EQ2Emu_lua_Harvest(lua_State* state) {
  4045. if (!lua_interface)
  4046. return 0;
  4047. Spawn* player = lua_interface->GetSpawn(state);
  4048. Spawn* node = lua_interface->GetSpawn(state, 2);
  4049. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4050. Client* client = player->GetZone()->GetClientBySpawn(player);
  4051. if (client) {
  4052. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4053. ((GroundSpawn*)node)->ProcessHarvest(client);
  4054. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4055. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4056. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4057. }
  4058. }
  4059. }
  4060. else if (player && player->IsPlayer()) {
  4061. Client* client = player->GetZone()->GetClientBySpawn(player);
  4062. if (client)
  4063. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4064. }
  4065. lua_interface->ResetFunctionStack(state);
  4066. return 0;
  4067. }
  4068. int EQ2Emu_lua_Bind(lua_State* state) {
  4069. if (!lua_interface)
  4070. return 0;
  4071. Spawn* spawn = lua_interface->GetSpawn(state);
  4072. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4073. float x = lua_interface->GetFloatValue(state, 3);
  4074. float y = lua_interface->GetFloatValue(state, 4);
  4075. float z = lua_interface->GetFloatValue(state, 5);
  4076. float h = lua_interface->GetFloatValue(state, 6);
  4077. lua_interface->ResetFunctionStack(state);
  4078. if (!spawn) {
  4079. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4080. return 0;
  4081. }
  4082. if (!spawn->IsPlayer()) {
  4083. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4084. return 0;
  4085. }
  4086. if (zone_id == 0) {
  4087. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4088. if (!client) {
  4089. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4090. return 0;
  4091. }
  4092. if (!client->Bind())
  4093. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4094. }
  4095. else {
  4096. Player* player = (Player*)spawn;
  4097. player->GetPlayerInfo()->SetBindZone(zone_id);
  4098. player->GetPlayerInfo()->SetBindX(x);
  4099. player->GetPlayerInfo()->SetBindY(y);
  4100. player->GetPlayerInfo()->SetBindZ(z);
  4101. player->GetPlayerInfo()->SetBindHeading(h);
  4102. }
  4103. return 0;
  4104. }
  4105. int EQ2Emu_lua_Gate(lua_State* state) {
  4106. if (!lua_interface)
  4107. return 0;
  4108. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4109. Spawn* spawn = lua_interface->GetSpawn(state);
  4110. lua_interface->ResetFunctionStack(state);
  4111. if (spawn) {
  4112. if (spawn->IsPlayer()) {
  4113. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4114. if (client) {
  4115. if (!client->Gate((spell != nullptr) ? true : false))
  4116. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4117. }
  4118. }
  4119. }
  4120. return 0;
  4121. }
  4122. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4123. if (!lua_interface)
  4124. return 0;
  4125. bool ret = false;
  4126. Spawn* spawn = lua_interface->GetSpawn(state);
  4127. lua_interface->ResetFunctionStack(state);
  4128. if (spawn) {
  4129. if (spawn->IsPlayer()) {
  4130. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4131. if (client)
  4132. ret = client->BindAllowed();
  4133. }
  4134. }
  4135. lua_interface->SetBooleanValue(state, ret);
  4136. return 1;
  4137. }
  4138. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4139. if (!lua_interface)
  4140. return 0;
  4141. bool ret = false;
  4142. Spawn* spawn = lua_interface->GetSpawn(state);
  4143. lua_interface->ResetFunctionStack(state);
  4144. if (spawn) {
  4145. if (spawn->IsPlayer()) {
  4146. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4147. if (client)
  4148. ret = client->GateAllowed();
  4149. }
  4150. }
  4151. lua_interface->SetBooleanValue(state, ret);
  4152. return 1;
  4153. }
  4154. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4155. Spawn* spawn = lua_interface->GetSpawn(state);
  4156. lua_interface->ResetFunctionStack(state);
  4157. if (spawn) {
  4158. lua_interface->SetBooleanValue(state, spawn->Alive());
  4159. return 1;
  4160. }
  4161. return 0;
  4162. }
  4163. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4164. if (!lua_interface)
  4165. return 0;
  4166. Spawn* spawn = lua_interface->GetSpawn(state);
  4167. lua_interface->ResetFunctionStack(state);
  4168. if (spawn && spawn->IsEntity()) {
  4169. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4170. return 1;
  4171. }
  4172. return 0;
  4173. }
  4174. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4175. Spawn* spawn = lua_interface->GetSpawn(state);
  4176. string message = lua_interface->GetStringValue(state, 2);
  4177. string color_str = lua_interface->GetStringValue(state, 3);
  4178. lua_interface->ResetFunctionStack(state);
  4179. int8 color = CHANNEL_NARRATIVE;
  4180. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4181. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4182. if (client) {
  4183. if (color_str.length() > 0) {
  4184. // leave for backwards compat, but all future should just use the number
  4185. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4186. color = CHANNEL_COLOR_RED;
  4187. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4188. color = CHANNEL_COLOR_YELLOW;
  4189. else
  4190. {
  4191. // use a number to specify the channel as per Commands/Commands.h defines
  4192. color = (int8)atoul(color_str.c_str());
  4193. }
  4194. }
  4195. client->SimpleMessage(color, message.c_str());
  4196. }
  4197. }
  4198. return 0;
  4199. }
  4200. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4201. Spawn* spawn = lua_interface->GetSpawn(state);
  4202. string message = lua_interface->GetStringValue(state, 2);
  4203. int8 red = lua_interface->GetInt8Value(state, 3);
  4204. int8 green = lua_interface->GetInt8Value(state, 4);
  4205. int8 blue = lua_interface->GetInt8Value(state, 5);
  4206. lua_interface->ResetFunctionStack(state);
  4207. if (!spawn) {
  4208. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4209. return 0;
  4210. }
  4211. int32 words = ::CountWordsInString(message.c_str());
  4212. if (words < 5)
  4213. words = 5;
  4214. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4215. if (client)
  4216. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4217. return 0;
  4218. }
  4219. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4220. Spawn* spawn = lua_interface->GetSpawn(state);
  4221. int8 param = lua_interface->GetInt8Value(state, 2);
  4222. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4223. int8 value = lua_interface->GetInt8Value(state, 4);
  4224. lua_interface->ResetFunctionStack(state);
  4225. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4226. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4227. if (client) {
  4228. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4229. switch (param) {
  4230. case 1: {
  4231. packet->setDataByName("parameter1", param_value);
  4232. break;
  4233. }
  4234. case 2: {
  4235. packet->setDataByName("parameter2", param_value);
  4236. break;
  4237. }
  4238. case 3: {
  4239. packet->setDataByName("parameter3", param_value);
  4240. break;
  4241. }
  4242. case 4: {
  4243. packet->setDataByName("parameter4", param_value);
  4244. break;
  4245. }
  4246. case 5: {
  4247. packet->setDataByName("parameter5", param_value);
  4248. break;
  4249. }
  4250. }
  4251. packet->setDataByName("value", value);
  4252. client->QueuePacket(packet->serialize());
  4253. safe_delete(packet);
  4254. }
  4255. }
  4256. return 0;
  4257. }
  4258. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4259. Spawn* spawn = lua_interface->GetSpawn(state);
  4260. lua_interface->ResetFunctionStack(state);
  4261. if (spawn && spawn->IsPlayer()) {
  4262. if (((Player*)spawn)->GetIsTracking())
  4263. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4264. else
  4265. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4266. }
  4267. return 0;
  4268. }
  4269. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4270. Spawn* player = lua_interface->GetSpawn(state);
  4271. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4272. string name = lua_interface->GetStringValue(state, 3);
  4273. float distance = lua_interface->GetFloatValue(state, 4);
  4274. string command = lua_interface->GetStringValue(state, 5);
  4275. string error_text = lua_interface->GetStringValue(state, 6);
  4276. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4277. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4278. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4279. lua_interface->ResetFunctionStack(state);
  4280. if (spawn) {
  4281. if (distance == 0)
  4282. distance = 10.0f;
  4283. if (command.length() == 0)
  4284. command = name;
  4285. if (command.length() < 1 && name.length() < 1)
  4286. {
  4287. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4288. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4289. spawn->RemovePrimaryCommands();
  4290. }
  4291. else
  4292. {
  4293. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4294. }
  4295. }
  4296. return 0;
  4297. }
  4298. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4299. if (!lua_interface)
  4300. return 0;
  4301. Spawn* player = lua_interface->GetSpawn(state);
  4302. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4303. int16 tier = lua_interface->GetInt16Value(state, 3);
  4304. lua_interface->ResetFunctionStack(state);
  4305. if (player && player->IsPlayer()) {
  4306. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4307. return 1;
  4308. }
  4309. return 0;
  4310. }
  4311. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4312. if (!lua_interface)
  4313. return 0;
  4314. Spawn* player = lua_interface->GetSpawn(state);
  4315. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4316. int16 tier = lua_interface->GetInt16Value(state, 3);
  4317. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4318. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4319. bool add_to_hotbar = true;
  4320. if (num_args > 4) {
  4321. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4322. }
  4323. lua_interface->ResetFunctionStack(state);
  4324. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4325. if (player && spell && player->IsPlayer()) {
  4326. Client* client = player->GetClient();
  4327. if (client) {
  4328. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4329. {
  4330. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4331. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4332. client->GetPlayer()->UnlockSpell(spell);
  4333. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4334. }
  4335. else
  4336. {
  4337. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4338. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4339. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4340. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4341. client->GetPlayer()->UnlockSpell(spell);
  4342. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4343. }
  4344. //if (client ) {
  4345. // ((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);
  4346. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4347. if (outapp)
  4348. client->QueuePacket(outapp);
  4349. }
  4350. }
  4351. return 0;
  4352. }
  4353. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4354. if (!lua_interface)
  4355. return 0;
  4356. Spawn* player = lua_interface->GetSpawn(state);
  4357. lua_interface->ResetFunctionStack(state);
  4358. if (player && player->IsPlayer()) {
  4359. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4360. return 1;
  4361. }
  4362. return 0;
  4363. }
  4364. int EQ2Emu_lua_Attack(lua_State* state) {
  4365. if (lua_interface) {
  4366. Spawn* npc = lua_interface->GetSpawn(state);
  4367. Spawn* player = lua_interface->GetSpawn(state, 2);
  4368. lua_interface->ResetFunctionStack(state);
  4369. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4370. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4371. }
  4372. return 0;
  4373. }
  4374. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4375. if (lua_interface) {
  4376. Spawn* target = lua_interface->GetSpawn(state);
  4377. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4378. lua_interface->ResetFunctionStack(state);
  4379. if (target && target->GetZone())
  4380. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4381. }
  4382. return 0;
  4383. }
  4384. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4385. Spawn* player;
  4386. if (lua_interface) {
  4387. player = lua_interface->GetSpawn(state);
  4388. lua_interface->ResetFunctionStack(state);
  4389. if (player && player->IsPlayer()) {
  4390. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4391. return 1;
  4392. }
  4393. }
  4394. return 0;
  4395. }
  4396. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4397. Spawn* player;
  4398. Client* client;
  4399. if (lua_interface) {
  4400. player = lua_interface->GetSpawn(state);
  4401. lua_interface->ResetFunctionStack(state);
  4402. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4403. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4404. client->HandInCollections();
  4405. }
  4406. return 0;
  4407. }
  4408. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4409. Spawn* widget;
  4410. if (lua_interface) {
  4411. widget = lua_interface->GetSpawn(state);
  4412. lua_interface->ResetFunctionStack(state);
  4413. if (widget && widget->IsWidget())
  4414. ((Widget*)widget)->HandleUse(nullptr, "");
  4415. }
  4416. return 0;
  4417. }
  4418. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4419. Spawn* spawn = 0;
  4420. int32 primary_list = 0;
  4421. int32 secondary_list = 0;
  4422. if (lua_interface) {
  4423. spawn = lua_interface->GetSpawn(state);
  4424. primary_list = lua_interface->GetInt32Value(state, 2);
  4425. secondary_list = lua_interface->GetInt32Value(state, 3);
  4426. lua_interface->ResetFunctionStack(state);
  4427. if (!spawn->IsNPC()) {
  4428. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4429. return 0;
  4430. }
  4431. NPC* npc = (NPC*)spawn;
  4432. npc->SetPrimarySpellList(primary_list);
  4433. npc->SetSecondarySpellList(secondary_list);
  4434. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4435. }
  4436. return 0;
  4437. }
  4438. int EQ2Emu_lua_GetPet(lua_State* state) {
  4439. if (!lua_interface)
  4440. return 0;
  4441. Spawn* spawn = lua_interface->GetSpawn(state);
  4442. lua_interface->ResetFunctionStack(state);
  4443. if (spawn) {
  4444. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4445. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4446. return 1;
  4447. }
  4448. }
  4449. return 0;
  4450. }
  4451. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4452. if (!lua_interface)
  4453. return 0;
  4454. Spawn* spawn = lua_interface->GetSpawn(state);
  4455. lua_interface->ResetFunctionStack(state);
  4456. if (spawn) {
  4457. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4458. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4459. return 1;
  4460. }
  4461. }
  4462. return 0;
  4463. }
  4464. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4465. if (!lua_interface)
  4466. return 0;
  4467. Spawn* spawn = lua_interface->GetSpawn(state);
  4468. lua_interface->ResetFunctionStack(state);
  4469. if (spawn) {
  4470. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4471. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4472. return 1;
  4473. }
  4474. }
  4475. return 0;
  4476. }
  4477. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4478. if (!lua_interface)
  4479. return 0;
  4480. Spawn* spawn = lua_interface->GetSpawn(state);
  4481. lua_interface->ResetFunctionStack(state);
  4482. if (spawn) {
  4483. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4484. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4485. return 1;
  4486. }
  4487. }
  4488. return 0;
  4489. }
  4490. int EQ2Emu_lua_Charm(lua_State* state) {
  4491. if (!lua_interface)
  4492. return 0;
  4493. Spawn* owner = lua_interface->GetSpawn(state);
  4494. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4495. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4496. lua_interface->ResetFunctionStack(state);
  4497. if (!luaspell) {
  4498. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4499. return 0;
  4500. }
  4501. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4502. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4503. pet->SetPet(true);
  4504. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4505. ((NPC*)pet)->SetOwner((Entity*)owner);
  4506. // If owner is player and player does not have a summoned pet set the players charsheet
  4507. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4508. Player* player = (Player*)owner;
  4509. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4510. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4511. player->GetInfoStruct()->set_pet_movement(2);
  4512. player->GetInfoStruct()->set_pet_behavior(3);
  4513. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4514. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4515. // Make sure the values get sent to the client
  4516. player->SetCharSheetChanged(true);
  4517. }
  4518. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4519. pet->SetSpawnScript("");
  4520. // Set faction to the same as the owner
  4521. pet->SetFactionID(owner->GetFactionID());
  4522. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4523. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4524. // Clear hate list
  4525. ((NPC*)pet)->Brain()->ClearHate();
  4526. // Set the brain to a pet brain
  4527. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4528. }
  4529. return 0;
  4530. }
  4531. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4532. if (!lua_interface)
  4533. return 0;
  4534. Spawn* spawn = lua_interface->GetSpawn(state);
  4535. lua_interface->ResetFunctionStack(state);
  4536. if (!spawn) {
  4537. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4538. return 0;
  4539. }
  4540. vector<Spawn*> groupMembers;
  4541. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4542. groupMembers = *spawn->GetSpawnGroup();
  4543. }
  4544. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4545. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4546. deque<GroupMemberInfo*>::iterator itr;
  4547. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4548. if (group)
  4549. {
  4550. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4551. deque<GroupMemberInfo*>* members = group->GetMembers();
  4552. GroupMemberInfo* info = 0;
  4553. for (itr = members->begin(); itr != members->end(); itr++) {
  4554. info = *itr;
  4555. if (info->client)
  4556. groupMembers.push_back(info->client->GetPlayer());
  4557. }
  4558. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4559. }
  4560. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4561. }
  4562. else
  4563. return 0;
  4564. lua_createtable(state, groupMembers.size(), 0);
  4565. int newTable = lua_gettop(state);
  4566. for (int32 i = 0; i < groupMembers.size(); i++) {
  4567. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4568. lua_rawseti(state, newTable, i + 1);
  4569. }
  4570. return 1;
  4571. }
  4572. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4573. if (!lua_interface)
  4574. return 0;
  4575. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4576. lua_interface->SetOptionWindowValue(state, option_window);
  4577. return 1;
  4578. }
  4579. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4580. if (!lua_interface)
  4581. return 0;
  4582. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4583. if (option_window) {
  4584. OptionWindowOption option_window_option;
  4585. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4586. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4587. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4588. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4589. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4590. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4591. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4592. option_window->push_back(option_window_option);
  4593. }
  4594. return 0;
  4595. }
  4596. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4597. if (!lua_interface)
  4598. return 0;
  4599. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4600. Spawn* player = lua_interface->GetSpawn(state, 2);
  4601. string window_title = lua_interface->GetStringValue(state, 3);
  4602. string cancel_command = lua_interface->GetStringValue(state, 4);
  4603. Client* client = player->GetZone()->GetClientBySpawn(player);
  4604. if (option_window && window_title.length() > 0 && client) {
  4605. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4606. if (!packet)
  4607. return 0;
  4608. packet->setDataByName("title_text", window_title.c_str());
  4609. if (cancel_command.length() > 0)
  4610. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4611. packet->setArrayLengthByName("num_selections", option_window->size());
  4612. vector<OptionWindowOption>::iterator itr;
  4613. int8 i = 0;
  4614. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4615. OptionWindowOption opt = *itr;
  4616. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4617. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4618. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4619. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4620. if (opt.optionCommand.length() > 0)
  4621. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4622. if (opt.optionConfirmTitle.length() > 0)
  4623. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4624. i++;
  4625. }
  4626. client->QueuePacket(packet->serialize());
  4627. safe_delete(option_window);
  4628. safe_delete(packet);
  4629. }
  4630. return 0;
  4631. }
  4632. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4633. if (!lua_interface)
  4634. return 0;
  4635. Spawn* spawn = lua_interface->GetSpawn(state);
  4636. if (spawn) {
  4637. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4638. return 1;
  4639. }
  4640. else
  4641. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4642. return 0;
  4643. }
  4644. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4645. if (!lua_interface)
  4646. return 0;
  4647. Spawn* spawn = lua_interface->GetSpawn(state);
  4648. if (spawn) {
  4649. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4650. return 1;
  4651. }
  4652. else
  4653. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4654. return 0;
  4655. }
  4656. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4657. if (!lua_interface)
  4658. return 0;
  4659. Spawn* spawn = lua_interface->GetSpawn(state);
  4660. if (spawn) {
  4661. int8 class_id = spawn->GetTradeskillClass();
  4662. // Need to add 42 for the offset in the array
  4663. class_id += 44;
  4664. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4665. return 1;
  4666. }
  4667. else
  4668. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4669. return 0;
  4670. }
  4671. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4672. if (!lua_interface)
  4673. return 0;
  4674. Spawn* spawn = lua_interface->GetSpawn(state);
  4675. int16 level = lua_interface->GetInt8Value(state, 2);
  4676. if (spawn) {
  4677. if (spawn->IsPlayer())
  4678. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4679. else
  4680. spawn->SetTSLevel(level);
  4681. }
  4682. else
  4683. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4684. return 0;
  4685. }
  4686. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4687. if (!lua_interface)
  4688. return 0;
  4689. Spawn* spawn = lua_interface->GetSpawn(state);
  4690. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4691. if (spawn) {
  4692. spawn->SetAttackable(attackable);
  4693. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4694. }
  4695. return 0;
  4696. }
  4697. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4698. // Check to see if we have a valid lua_interface
  4699. if (!lua_interface)
  4700. return 0;
  4701. // Get the spawn that is getting the pet
  4702. Spawn* spawn = lua_interface->GetSpawn(state);
  4703. // Get the DB ID of the pet
  4704. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4705. // The max level the pet can gain
  4706. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4707. // Get the spell that this command was called from
  4708. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4709. // Check to make sure the spawn pointer is valid
  4710. if (!spawn) {
  4711. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4712. return 0;
  4713. }
  4714. // Check to make sure the spawn is an entity
  4715. if (!spawn->IsEntity()) {
  4716. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4717. return 0;
  4718. }
  4719. // Check to make sure the spawn doesn't already have a pet of this type
  4720. if (((Entity*)spawn)->GetPet()) {
  4721. if (spawn->IsPlayer()) {
  4722. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4723. if (client)
  4724. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4725. }
  4726. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4727. return 0;
  4728. }
  4729. // Check to see if the DB ID for the pet is set
  4730. if (pet_id == 0) {
  4731. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4732. return 0;
  4733. }
  4734. // Check to see if the pointer to the spell is valid
  4735. if (!luaspell) {
  4736. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4737. return 0;
  4738. }
  4739. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4740. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4741. if (!pet) {
  4742. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4743. return 0;
  4744. }
  4745. // Check to make sure the pet is an npc
  4746. if (!pet->IsNPC()) {
  4747. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4748. return 0;
  4749. }
  4750. // Spawn the pet at the same location as the owner
  4751. pet->SetX(spawn->GetX());
  4752. pet->SetY(spawn->GetY());
  4753. pet->SetZ(spawn->GetZ());
  4754. pet->SetLocation(spawn->GetLocation());
  4755. pet->SetHeading(spawn->GetHeading());
  4756. spawn->GetZone()->AddSpawn(pet);
  4757. /*
  4758. const char* spawn_script = world.GetSpawnScript(pet_id);
  4759. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4760. spawn->SetSpawnScript(string(spawn_script));
  4761. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4762. }*/
  4763. // Get a random pet name
  4764. string random_pet_name;
  4765. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4766. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4767. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4768. // If player set various values for the char sheet (pet window)
  4769. if (spawn->IsPlayer()) {
  4770. Player* player = (Player*)spawn;
  4771. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4772. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4773. player->GetInfoStruct()->set_pet_movement(2);
  4774. player->GetInfoStruct()->set_pet_behavior(3);
  4775. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4776. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4777. // Make sure the values get sent to the client
  4778. player->SetCharSheetChanged(true);
  4779. }
  4780. // Set the pets name
  4781. pet->SetName(random_pet_name.c_str());
  4782. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4783. if (max_level > 0)
  4784. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4785. else
  4786. pet->SetLevel(spawn->GetLevel());
  4787. // Set the max level this pet can reach
  4788. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4789. // Set the faction of the pet to the same faction as the owner
  4790. pet->SetFactionID(spawn->GetFactionID());
  4791. // Set the spawn as a pet
  4792. pet->SetPet(true);
  4793. // Give a pointer of the owner to the pet
  4794. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4795. // Give a pointer of the pet to the owner
  4796. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4797. // Set the pet type
  4798. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4799. // Set the spell id used to create this pet
  4800. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4801. // Set the spell tier used to create this pet
  4802. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4803. // Set the pets spawn type to 6
  4804. pet->SetSpawnType(6);
  4805. // Set the pets brain
  4806. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4807. // Check to see if the pet has a subtitle
  4808. if (strlen(pet->GetSubTitle()) > 0) {
  4809. // Add the players name to the front of the sub title
  4810. string pet_subtitle;
  4811. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4812. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4813. // Set the pets subtitle to the new one
  4814. pet->SetSubTitle(pet_subtitle.c_str());
  4815. }
  4816. // Add the "Pet Options" entity command to the pet
  4817. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4818. // Set the pet as the return value for this function
  4819. lua_interface->SetSpawnValue(state, pet);
  4820. return 1;
  4821. }
  4822. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4823. if (!lua_interface)
  4824. return 0;
  4825. Spawn* spawn = lua_interface->GetSpawn(state);
  4826. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4827. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4828. if (!spawn) {
  4829. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4830. return 0;
  4831. }
  4832. if (!spawn->IsEntity()) {
  4833. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4834. return 0;
  4835. }
  4836. if (((Entity*)spawn)->GetDeityPet()) {
  4837. if (spawn->IsPlayer()) {
  4838. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4839. if (client)
  4840. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4841. }
  4842. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4843. return 0;
  4844. }
  4845. if (pet_id == 0) {
  4846. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4847. return 0;
  4848. }
  4849. if (!luaspell) {
  4850. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4851. return 0;
  4852. }
  4853. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4854. if (!pet) {
  4855. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4856. return 0;
  4857. }
  4858. if (!pet->IsNPC()) {
  4859. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4860. return 0;
  4861. }
  4862. pet->SetX(spawn->GetX());
  4863. pet->SetY(spawn->GetY());
  4864. pet->SetZ(spawn->GetZ());
  4865. pet->SetLocation(spawn->GetLocation());
  4866. pet->SetHeading(spawn->GetHeading());
  4867. spawn->GetZone()->AddSpawn(pet);
  4868. string random_pet_name;
  4869. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4870. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4871. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4872. pet->SetName(random_pet_name.c_str());
  4873. pet->SetLevel(spawn->GetLevel());
  4874. pet->SetFactionID(spawn->GetFactionID());
  4875. pet->SetPet(true);
  4876. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4877. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4878. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4879. pet->SetSpawnType(6);
  4880. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4881. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4882. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4883. if (strlen(pet->GetSubTitle()) > 0) {
  4884. string pet_subtitle;
  4885. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4886. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4887. pet->SetSubTitle(pet_subtitle.c_str());
  4888. }
  4889. // deity and cosmetic pets are not attackable
  4890. pet->SetAttackable(false);
  4891. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4892. lua_interface->SetSpawnValue(state, pet);
  4893. return 1;
  4894. }
  4895. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4896. if (!lua_interface)
  4897. return 0;
  4898. Spawn* spawn = lua_interface->GetSpawn(state);
  4899. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4900. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4901. if (!spawn) {
  4902. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4903. return 0;
  4904. }
  4905. if (!spawn->IsEntity()) {
  4906. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4907. return 0;
  4908. }
  4909. if (((Entity*)spawn)->GetCosmeticPet()) {
  4910. if (spawn->IsPlayer()) {
  4911. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4912. if (client)
  4913. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4914. }
  4915. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4916. return 0;
  4917. }
  4918. if (pet_id == 0) {
  4919. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4920. return 0;
  4921. }
  4922. if (!luaspell) {
  4923. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4924. return 0;
  4925. }
  4926. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4927. if (!pet) {
  4928. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4929. return 0;
  4930. }
  4931. if (!pet->IsNPC()) {
  4932. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4933. return 0;
  4934. }
  4935. pet->SetX(spawn->GetX());
  4936. pet->SetY(spawn->GetY());
  4937. pet->SetZ(spawn->GetZ());
  4938. pet->SetLocation(spawn->GetLocation());
  4939. pet->SetHeading(spawn->GetHeading());
  4940. spawn->GetZone()->AddSpawn(pet);
  4941. string random_pet_name;
  4942. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4943. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4944. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4945. pet->SetName(random_pet_name.c_str());
  4946. pet->SetLevel(spawn->GetLevel());
  4947. pet->SetFactionID(spawn->GetFactionID());
  4948. pet->SetPet(true);
  4949. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4950. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4951. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4952. pet->SetSpawnType(6);
  4953. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4954. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4955. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4956. if (strlen(pet->GetSubTitle()) > 0) {
  4957. string pet_subtitle;
  4958. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4959. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4960. pet->SetSubTitle(pet_subtitle.c_str());
  4961. }
  4962. pet->SetAttackable(false);
  4963. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4964. lua_interface->SetSpawnValue(state, pet);
  4965. return 1;
  4966. }
  4967. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4968. if (!lua_interface)
  4969. return 0;
  4970. Spawn* spawn = lua_interface->GetSpawn(state);
  4971. if (!spawn) {
  4972. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4973. return 0;
  4974. }
  4975. if (!spawn->IsPet()) {
  4976. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4977. return 0;
  4978. }
  4979. if (!((NPC*)spawn)->IsDismissing())
  4980. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4981. return 0;
  4982. }
  4983. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4984. if (!lua_interface)
  4985. return 0;
  4986. Quest* quest = lua_interface->GetQuest(state);
  4987. if (!quest) {
  4988. 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));
  4989. return 0;
  4990. }
  4991. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4992. if (feather_color > 0)
  4993. quest->SetFeatherColor(feather_color);
  4994. return 0;
  4995. }
  4996. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4997. if (!lua_interface)
  4998. return 0;
  4999. Spawn* spawn = lua_interface->GetSpawn(state);
  5000. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5001. if (!spawn) {
  5002. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5003. return 0;
  5004. }
  5005. if (!spawn2) {
  5006. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5007. return 0;
  5008. }
  5009. spawn->RemoveSpawnAccess(spawn2);
  5010. return 0;
  5011. }
  5012. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5013. if (!lua_interface)
  5014. return 0;
  5015. ZoneServer* zone = lua_interface->GetZone(state);
  5016. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5017. if (!zone) {
  5018. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5019. return 0;
  5020. }
  5021. if (location_id == 0) {
  5022. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5026. if (!location) {
  5027. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5028. return 0;
  5029. }
  5030. Spawn* spawn = 0;
  5031. if (location->entities[0]) {
  5032. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5033. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5034. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5035. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5036. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5037. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5038. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5039. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5040. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5041. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5042. if(spawn && spawn->IsOmittedByDBFlag())
  5043. {
  5044. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5045. safe_delete(spawn);
  5046. spawn = 0;
  5047. return 0;
  5048. }
  5049. if (spawn) {
  5050. const char* script = 0;
  5051. for (int x = 0; x < 3; x++) {
  5052. switch (x) {
  5053. case 0:
  5054. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5055. break;
  5056. case 1:
  5057. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5058. break;
  5059. case 2:
  5060. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5061. break;
  5062. }
  5063. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5064. spawn->SetSpawnScript(string(script));
  5065. break;
  5066. }
  5067. }
  5068. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5069. lua_interface->SetSpawnValue(state, spawn);
  5070. return 1;
  5071. }
  5072. else {
  5073. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5074. safe_delete(spawn);
  5075. }
  5076. }
  5077. return 0;
  5078. }
  5079. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5080. if (!lua_interface)
  5081. return 0;
  5082. Spawn* caster = lua_interface->GetSpawn(state);
  5083. Spawn* target = lua_interface->GetSpawn(state, 2);
  5084. int32 id = lua_interface->GetInt32Value(state, 3);
  5085. string command = lua_interface->GetStringValue(state, 4);
  5086. if (!caster) {
  5087. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5088. return 0;
  5089. }
  5090. if (!target) {
  5091. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5092. return 0;
  5093. }
  5094. if (!caster->IsPlayer()) {
  5095. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5096. return 0;
  5097. }
  5098. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5099. if (!entity_command) {
  5100. 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());
  5101. return 0;
  5102. }
  5103. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5104. if (!client) {
  5105. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5106. return 0;
  5107. }
  5108. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5109. return 0;
  5110. }
  5111. int EQ2Emu_lua_SetLuaBrain(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 SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5117. return 0;
  5118. }
  5119. if (!spawn->IsNPC()) {
  5120. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5121. return 0;
  5122. }
  5123. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5124. return 0;
  5125. }
  5126. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5127. if (!lua_interface)
  5128. return 0;
  5129. Spawn* spawn = lua_interface->GetSpawn(state);
  5130. int16 tick = lua_interface->GetInt16Value(state, 2);
  5131. if (!spawn) {
  5132. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5133. return 0;
  5134. }
  5135. if (!spawn->IsNPC()) {
  5136. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5137. return 0;
  5138. }
  5139. if (tick < 20) {
  5140. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5141. return 0;
  5142. }
  5143. ((NPC*)spawn)->Brain()->SetTick(tick);
  5144. return 0;
  5145. }
  5146. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5147. if (!lua_interface)
  5148. return 0;
  5149. Spawn* spawn = lua_interface->GetSpawn(state);
  5150. Spawn* target = lua_interface->GetSpawn(state, 2);
  5151. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5152. if (!spawn) {
  5153. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5154. return 0;
  5155. }
  5156. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5157. spawn->SetFollowTarget(target, follow_distance);
  5158. return 0;
  5159. }
  5160. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5161. if (!lua_interface)
  5162. return 0;
  5163. Spawn* spawn = lua_interface->GetSpawn(state);
  5164. if (!spawn) {
  5165. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5166. return 0;
  5167. }
  5168. Spawn* target = spawn->GetFollowTarget();
  5169. if (target) {
  5170. lua_interface->SetSpawnValue(state, target);
  5171. return 1;
  5172. }
  5173. return 0;
  5174. }
  5175. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5176. if (!lua_interface)
  5177. return 0;
  5178. Spawn* spawn = lua_interface->GetSpawn(state);
  5179. if (!spawn) {
  5180. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5181. return 0;
  5182. }
  5183. if (spawn->following)
  5184. spawn->following = false;
  5185. else
  5186. spawn->following = true;
  5187. return 0;
  5188. }
  5189. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5190. if (!lua_interface)
  5191. return 0;
  5192. Spawn* spawn = lua_interface->GetSpawn(state);
  5193. if (!spawn) {
  5194. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5195. return 0;
  5196. }
  5197. lua_interface->SetBooleanValue(state, spawn->following);
  5198. return 1;
  5199. }
  5200. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5201. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5202. // I will attempt to explain how this function works for future refrence
  5203. // Fist lets make sure lua_interface is valid, if not return out
  5204. if (!lua_interface)
  5205. return 0;
  5206. // Next we grab the first 2 params same as we usually would
  5207. Spawn* spawn = lua_interface->GetSpawn(state);
  5208. string var = lua_interface->GetStringValue(state, 2);
  5209. // 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
  5210. // 1 = Spawn
  5211. // 2 = Zone
  5212. // 3 = Item
  5213. // 4 = Quest
  5214. // 5 = String
  5215. // 6 = nil (null)
  5216. int8 dataType = 0;
  5217. // Define pointers for each potential type
  5218. Spawn* spawnVal = 0;
  5219. ZoneServer* zone = 0;
  5220. Item* item = 0;
  5221. Quest* quest = 0;
  5222. string val;
  5223. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5224. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5225. // options window are also light user data be we do not handle those.
  5226. // We check with lua_islightuserdata(lua_State*, index)
  5227. if (lua_islightuserdata(state, 3)) {
  5228. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5229. // and convert it to LUAUserData*
  5230. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5231. // Check to make sure the data we got is valid, if not give an error
  5232. if (!data || !data->IsCorrectlyInitialized()) {
  5233. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5234. }
  5235. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5236. else if (data->IsSpawn()) {
  5237. spawnVal = data->spawn;
  5238. dataType = 1;
  5239. }
  5240. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5241. else if (data->IsZone()) {
  5242. zone = data->zone;
  5243. dataType = 2;
  5244. }
  5245. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5246. else if (data->IsItem()) {
  5247. item = data->item;
  5248. dataType = 3;
  5249. }
  5250. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5251. else if (data->IsQuest()) {
  5252. quest = data->quest;
  5253. dataType = 4;
  5254. }
  5255. }
  5256. // Wasn't light user data, check if it is nil(null)
  5257. else if (lua_isnil(state, 3)) {
  5258. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5259. dataType = 6;
  5260. }
  5261. // Wasn't light user data or nil (null), must be a string
  5262. else {
  5263. // Set the string and dataType variable
  5264. val = lua_interface->GetStringValue(state, 3);
  5265. dataType = 5;
  5266. }
  5267. // We now have all the params, lets check to make sure they are valid
  5268. if (!spawn) {
  5269. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5270. return 0;
  5271. }
  5272. if (var.length() == 0) {
  5273. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5274. return 0;
  5275. }
  5276. if (dataType == 0) {
  5277. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5278. return 0;
  5279. }
  5280. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5281. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5282. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5283. switch (dataType) {
  5284. case 1:
  5285. // 1 = Spawn
  5286. spawn->AddTempVariable(var, spawnVal);
  5287. break;
  5288. case 2:
  5289. // 2 = Zone
  5290. spawn->AddTempVariable(var, zone);
  5291. break;
  5292. case 3:
  5293. // 3 = Item
  5294. spawn->AddTempVariable(var, item);
  5295. break;
  5296. case 4:
  5297. // 4 = Quest
  5298. spawn->AddTempVariable(var, quest);
  5299. break;
  5300. case 5:
  5301. // 5 = String
  5302. spawn->AddTempVariable(var, val);
  5303. break;
  5304. case 6:
  5305. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5306. spawn->DeleteTempVariable(var);
  5307. break;
  5308. }
  5309. // And we are done so return out
  5310. return 0;
  5311. }
  5312. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5313. if (!lua_interface)
  5314. return 0;
  5315. Spawn* spawn = lua_interface->GetSpawn(state);
  5316. string var = lua_interface->GetStringValue(state, 2);
  5317. if (!spawn) {
  5318. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. if (var.length() == 0) {
  5322. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5323. return 0;
  5324. }
  5325. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5326. int8 type = spawn->GetTempVariableType(var);
  5327. Spawn* spawn2 = 0;
  5328. ZoneServer* zone = 0;
  5329. Item* item = 0;
  5330. Quest* quest = 0;
  5331. // Set the lua function return value based on the type of data the variable contains
  5332. switch (type) {
  5333. case 1:
  5334. spawn2 = spawn->GetTempVariableSpawn(var);
  5335. if (!spawn2)
  5336. return 0;
  5337. lua_interface->SetSpawnValue(state, spawn2);
  5338. break;
  5339. case 2:
  5340. zone = spawn->GetTempVariableZone(var);
  5341. if (!zone)
  5342. return 0;
  5343. lua_interface->SetZoneValue(state, zone);
  5344. break;
  5345. case 3:
  5346. item = spawn->GetTempVariableItem(var);
  5347. if (!item)
  5348. return 0;
  5349. lua_interface->SetItemValue(state, item);
  5350. break;
  5351. case 4:
  5352. quest = spawn->GetTempVariableQuest(var);
  5353. if (!quest)
  5354. return 0;
  5355. lua_interface->SetQuestValue(state, quest);
  5356. break;
  5357. case 5:
  5358. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5359. break;
  5360. default:
  5361. // Not a valid type then the variable was not set so return out
  5362. return 0;
  5363. }
  5364. // Return value was set so return out
  5365. return 1;
  5366. }
  5367. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5368. {
  5369. if (!lua_interface)
  5370. return 0;
  5371. Quest* quest = lua_interface->GetQuest(state);
  5372. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5373. string description = lua_interface->GetStringValue(state, 3);
  5374. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5375. if (!quest) {
  5376. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5377. lua_interface->SetBooleanValue(state, false);
  5378. return 1;
  5379. }
  5380. if (!spawn) {
  5381. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5382. lua_interface->SetBooleanValue(state, false);
  5383. return 1;
  5384. }
  5385. if (!spawn->IsPlayer()) {
  5386. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5387. lua_interface->SetBooleanValue(state, false);
  5388. return 1;
  5389. }
  5390. if (item_id == 0) {
  5391. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5392. lua_interface->SetBooleanValue(state, false);
  5393. return 1;
  5394. }
  5395. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5396. if (!client) {
  5397. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5398. lua_interface->SetBooleanValue(state, false);
  5399. return 1;
  5400. }
  5401. Item* item = master_item_list.GetItem(item_id);
  5402. if (!item) {
  5403. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5404. lua_interface->SetBooleanValue(state, false);
  5405. return 1;
  5406. }
  5407. Item* firstItem = new Item(item);
  5408. quest->AddTmpRewardItem(firstItem);
  5409. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5410. bool itemsAddedSuccessfully = true;
  5411. if(num_args > 4)
  5412. {
  5413. for(int8 n=5;n<num_args+1;n++)
  5414. {
  5415. int32 new_item = lua_interface->GetInt32Value(state, n);
  5416. Item* tmpItem = master_item_list.GetItem(new_item);
  5417. if(tmpItem)
  5418. {
  5419. Item* newTmpItem = new Item(tmpItem);
  5420. quest->AddTmpRewardItem(newTmpItem);
  5421. }
  5422. else
  5423. itemsAddedSuccessfully = false;
  5424. }
  5425. }
  5426. client->AddPendingQuestAcceptReward(quest);
  5427. client->DisplayQuestComplete(quest, true, description);
  5428. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5429. return 1;
  5430. }
  5431. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5432. if (!lua_interface)
  5433. return 0;
  5434. Quest* quest = lua_interface->GetQuest(state);
  5435. if (!quest) {
  5436. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5437. return 0;
  5438. }
  5439. quest->SetRepeatable(true);
  5440. return 0;
  5441. }
  5442. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5443. if (!lua_interface)
  5444. return 0;
  5445. Spawn* spawn = lua_interface->GetSpawn(state);
  5446. if (!spawn) {
  5447. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5448. return 0;
  5449. }
  5450. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5451. string ret = classes.GetClassNameCase(base_class);
  5452. if (ret.length() > 0) {
  5453. lua_interface->SetStringValue(state, ret.c_str());
  5454. return 1;
  5455. }
  5456. return 0;
  5457. }
  5458. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5459. if (!lua_interface)
  5460. return 0;
  5461. Spawn* player = lua_interface->GetSpawn(state);
  5462. if (player && player->IsPlayer()) {
  5463. Client* client = player->GetClient();
  5464. if (client)
  5465. client->SendWaypoints();
  5466. }
  5467. return 0;
  5468. }
  5469. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5470. if (!lua_interface)
  5471. return 0;
  5472. Spawn* player = lua_interface->GetSpawn(state);
  5473. string name = lua_interface->GetStringValue(state, 2);
  5474. int32 type = lua_interface->GetInt32Value(state, 3);
  5475. if (type == 0)
  5476. type = 2;
  5477. if (name.length() > 0) {
  5478. if (player && player->IsPlayer()) {
  5479. Client* client = player->GetClient();
  5480. if (client)
  5481. client->AddWaypoint(name, type);
  5482. }
  5483. }
  5484. return 0;
  5485. }
  5486. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5487. if (!lua_interface)
  5488. return 0;
  5489. Spawn* player = lua_interface->GetSpawn(state);
  5490. string name = lua_interface->GetStringValue(state, 2);
  5491. if (name.length() > 0) {
  5492. if (player && player->IsPlayer()) {
  5493. Client* client = player->GetClient();
  5494. if (client)
  5495. client->RemoveWaypoint(name);
  5496. }
  5497. }
  5498. return 0;
  5499. }
  5500. int EQ2Emu_lua_AddWard(lua_State* state) {
  5501. if (!lua_interface)
  5502. return 0;
  5503. int32 damage = lua_interface->GetInt32Value(state);
  5504. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5505. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5506. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5507. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5508. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5509. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5510. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5511. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5512. bool ward_was_added = false;
  5513. ZoneServer* zone = spell->caster->GetZone();
  5514. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5515. for (int32 i = 0; i < spell->targets.size(); i++) {
  5516. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5517. if (!target)
  5518. continue;
  5519. if (target->IsEntity()) {
  5520. // If the ward is already active remove it
  5521. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5522. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5523. // Create new ward info
  5524. WardInfo* ward = new WardInfo;
  5525. ward->Spell = spell;
  5526. ward->BaseDamage = damage;
  5527. ward->DamageLeft = damage;
  5528. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5529. ward->keepWard = keepWard;
  5530. ward->WardType = wardType;
  5531. if (damageAbsorptionPercent > 100)
  5532. damageAbsorptionPercent = 100;
  5533. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5534. if (damageAbsorptionMaxHealthPercent > 100)
  5535. damageAbsorptionMaxHealthPercent = 100;
  5536. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5537. ward->RedirectDamagePercent = redirectDamagePercent;
  5538. ward->LastRedirectDamage = 0;
  5539. ward->LastAbsorbedDamage = 0;
  5540. ward->HitCount = 0;
  5541. spell->num_triggers = maxHitCount;
  5542. spell->had_triggers = true;
  5543. spell->cancel_after_all_triggers = false;
  5544. ward->MaxHitCount = maxHitCount;
  5545. if (wardType == WARD_TYPE_MAGICAL)
  5546. ward->DamageType = damageTypes;
  5547. // Add the ward to the entity
  5548. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5549. ward_was_added = true;
  5550. }
  5551. }
  5552. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5553. if (ward_was_added && spell->caster->IsPlayer()) {
  5554. spell->had_dmg_remaining = true;
  5555. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5556. }
  5557. return 0;
  5558. }
  5559. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5560. if (!lua_interface)
  5561. return 0;
  5562. int32 amount = lua_interface->GetInt32Value(state);
  5563. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5564. WardInfo* ward = 0;
  5565. ZoneServer* zone = spell->caster->GetZone();
  5566. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5567. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5568. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5569. ward = target->GetWard(spell->spell->GetSpellID());
  5570. if (target && ward) {
  5571. ward->DamageLeft += amount;
  5572. if (ward->DamageLeft > ward->BaseDamage)
  5573. ward->DamageLeft = ward->BaseDamage;
  5574. for (int32 i = 0; i < spell->targets.size(); i++) {
  5575. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5576. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5577. }
  5578. }
  5579. }
  5580. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5581. if (ward && spell->caster->IsPlayer())
  5582. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5583. return 0;
  5584. }
  5585. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5586. if (!lua_interface)
  5587. return 0;
  5588. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5589. if (!spell) {
  5590. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5591. return 0;
  5592. }
  5593. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5594. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5595. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5596. if (ward) {
  5597. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5598. return 1;
  5599. }
  5600. }
  5601. return 0;
  5602. }
  5603. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5604. if (!lua_interface)
  5605. return 0;
  5606. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5607. if (!spell) {
  5608. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5609. return 0;
  5610. }
  5611. string type = lua_interface->GetStringValue(state, 2);
  5612. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5613. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5614. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5615. if (ward) {
  5616. if (boost::iequals(type, "damageleft"))
  5617. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5618. else if (boost::iequals(type, "basedamage"))
  5619. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5620. else if (boost::iequals(type, "keepward"))
  5621. lua_interface->SetBooleanValue(state, ward->keepWard);
  5622. else if (boost::iequals(type, "wardtype"))
  5623. lua_interface->SetInt32Value(state, ward->WardType);
  5624. else if (boost::iequals(type, "dmgabsorptionpct"))
  5625. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5626. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5627. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5628. else if (boost::iequals(type, "redirectdamagepercent"))
  5629. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5630. else if (boost::iequals(type, "lastredirectdamage"))
  5631. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5632. else if (boost::iequals(type, "lastabsorbeddamage"))
  5633. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5634. else if (boost::iequals(type, "hitcount"))
  5635. lua_interface->SetInt32Value(state, ward->HitCount);
  5636. else if (boost::iequals(type, "maxhitcount"))
  5637. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5638. else
  5639. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5640. return 1;
  5641. }
  5642. }
  5643. return 0;
  5644. }
  5645. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5646. if (!lua_interface)
  5647. return 0;
  5648. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5649. ZoneServer* zone = spell->caster->GetZone();
  5650. Spawn* target = 0;
  5651. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5652. for (int32 i = 0; i < spell->targets.size(); i++) {
  5653. target = zone->GetSpawnByID(spell->targets.at(i));
  5654. if (target && target->IsEntity()) {
  5655. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5656. }
  5657. }
  5658. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5659. return 0;
  5660. }
  5661. int EQ2Emu_lua_Interrupt(lua_State* state)
  5662. {
  5663. if (!lua_interface)
  5664. return 0;
  5665. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5666. Spawn* target = lua_interface->GetSpawn(state, 2);
  5667. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5668. if (!caster)
  5669. {
  5670. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5671. return 0;
  5672. }
  5673. if (!target)
  5674. {
  5675. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5676. return 0;
  5677. }
  5678. if (!spell) {
  5679. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5680. return 0;
  5681. }
  5682. if (!target->IsEntity() && !spell)
  5683. {
  5684. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5685. return 0;
  5686. }
  5687. if (!target && spell) {
  5688. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5689. for (int8 i = 0; i < spell->targets.size(); i++) {
  5690. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5691. if (!target || !target->IsEntity())
  5692. continue;
  5693. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5694. }
  5695. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5696. }
  5697. else
  5698. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5699. return 0;
  5700. }
  5701. int EQ2Emu_lua_Stealth(lua_State* state) {
  5702. if (!lua_interface)
  5703. return 0;
  5704. int8 type = lua_interface->GetInt8Value(state);
  5705. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5706. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5707. if (!spell) {
  5708. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5709. return 0;
  5710. }
  5711. ZoneServer* zone = spell->caster->GetZone();
  5712. if (spawn) {
  5713. if (spawn->IsEntity()) {
  5714. if (type == 1) {
  5715. ((Entity*)spawn)->AddStealthSpell(spell);
  5716. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5717. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5718. }
  5719. else if (type == 2) {
  5720. ((Entity*)spawn)->AddInvisSpell(spell);
  5721. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5722. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5723. }
  5724. return 0;
  5725. }
  5726. else {
  5727. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5728. return 0;
  5729. }
  5730. }
  5731. else {
  5732. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5733. for (int32 i = 0; i < spell->targets.size(); i++) {
  5734. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5735. if (!spawn || !spawn->IsEntity())
  5736. continue;
  5737. if (type == 1) {
  5738. ((Entity*)spawn)->AddStealthSpell(spell);
  5739. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5740. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5741. }
  5742. else if (type == 2) {
  5743. ((Entity*)spawn)->AddInvisSpell(spell);
  5744. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5745. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5746. }
  5747. else {
  5748. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5749. break;
  5750. }
  5751. }
  5752. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5753. }
  5754. return 0;
  5755. }
  5756. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5757. if (!lua_interface)
  5758. return 0;
  5759. Spawn* spawn = lua_interface->GetSpawn(state);
  5760. if (!spawn) {
  5761. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5762. return 0;
  5763. }
  5764. if (spawn->IsEntity()) {
  5765. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5766. return 1;
  5767. }
  5768. else
  5769. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5770. return 0;
  5771. }
  5772. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5773. if (!lua_interface)
  5774. return 0;
  5775. Spawn* spawn = lua_interface->GetSpawn(state);
  5776. if (!spawn) {
  5777. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5778. return 0;
  5779. }
  5780. if (spawn->IsEntity()) {
  5781. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5782. return 1;
  5783. }
  5784. else
  5785. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5786. return 0;
  5787. }
  5788. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5789. if (!lua_interface)
  5790. return 0;
  5791. Spawn* player = lua_interface->GetSpawn(state);
  5792. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5793. lua_interface->ResetFunctionStack(state);
  5794. if (!player->IsPlayer()) {
  5795. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5796. return 0;
  5797. }
  5798. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5799. return 1;
  5800. }
  5801. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5802. if (!lua_interface)
  5803. return 0;
  5804. Spawn* player = lua_interface->GetSpawn(state);
  5805. int8 slot = lua_interface->GetInt8Value(state, 2);
  5806. lua_interface->ResetFunctionStack(state);
  5807. if (!player) {
  5808. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5809. return 0;
  5810. }
  5811. if (!player->IsPlayer()) {
  5812. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5813. return 0;
  5814. }
  5815. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5816. if (!item) {
  5817. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5818. return 0;
  5819. }
  5820. lua_interface->SetItemValue(state, item);
  5821. return 1;
  5822. }
  5823. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5824. if (!lua_interface)
  5825. return 0;
  5826. Spawn* player = lua_interface->GetSpawn(state);
  5827. int32 id = lua_interface->GetInt32Value(state, 2);
  5828. lua_interface->ResetFunctionStack(state);
  5829. if (!player) {
  5830. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5831. return 0;
  5832. }
  5833. if (!player->IsPlayer()) {
  5834. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5835. return 0;
  5836. }
  5837. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5838. if (!item) {
  5839. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5840. return 0;
  5841. }
  5842. lua_interface->SetItemValue(state, item);
  5843. return 1;
  5844. }
  5845. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5846. if (!lua_interface)
  5847. return 0;
  5848. Spawn* spawn = lua_interface->GetSpawn(state);
  5849. int8 slot = lua_interface->GetInt8Value(state, 2);
  5850. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5851. lua_interface->ResetFunctionStack(state);
  5852. if (!spawn) {
  5853. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5854. return 0;
  5855. }
  5856. if (!spawn->IsEntity()) {
  5857. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5858. return 0;
  5859. }
  5860. Item* item = master_item_list.GetItem(item_id);
  5861. if (!item) {
  5862. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. Item* copy = new Item(item);
  5866. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5867. if(result)
  5868. {
  5869. ((Entity*)spawn)->SetEquipment(copy, slot);
  5870. spawn->vis_changed = true;
  5871. if(spawn->IsPlayer())
  5872. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5873. }
  5874. else
  5875. {
  5876. safe_delete(copy);
  5877. }
  5878. lua_interface->SetBooleanValue(state, result);
  5879. return 1;
  5880. }
  5881. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5882. if (!lua_interface)
  5883. return 0;
  5884. Spawn* spawn = lua_interface->GetSpawn(state);
  5885. int8 slot = lua_interface->GetInt8Value(state, 2);
  5886. Item* item = lua_interface->GetItem(state, 3);
  5887. lua_interface->ResetFunctionStack(state);
  5888. if (!spawn) {
  5889. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5890. return 0;
  5891. }
  5892. if (!spawn->IsEntity()) {
  5893. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5894. return 0;
  5895. }
  5896. if (!item) {
  5897. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5898. return 0;
  5899. }
  5900. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5901. if(result)
  5902. {
  5903. ((Entity*)spawn)->SetEquipment(item, slot);
  5904. spawn->vis_changed = true;
  5905. if(spawn->IsPlayer())
  5906. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5907. }
  5908. lua_interface->SetBooleanValue(state, result);
  5909. return 1;
  5910. }
  5911. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5912. if (!lua_interface)
  5913. return 0;
  5914. Spawn* spawn = lua_interface->GetSpawn(state);
  5915. int8 slot = lua_interface->GetInt8Value(state, 2);
  5916. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5917. lua_interface->ResetFunctionStack(state);
  5918. if (!spawn) {
  5919. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5920. return 0;
  5921. }
  5922. if (!spawn->IsEntity()) {
  5923. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5924. return 0;
  5925. }
  5926. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5927. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5928. spawn->vis_changed = true;
  5929. if(spawn->IsPlayer())
  5930. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5931. lua_interface->SetBooleanValue(state, true);
  5932. return 1;
  5933. }
  5934. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5935. if (!lua_interface)
  5936. return 0;
  5937. Spawn* spawn = lua_interface->GetSpawn(state);
  5938. int8 slot = lua_interface->GetInt8Value(state, 2);
  5939. int16 type = lua_interface->GetInt16Value(state, 3);
  5940. int8 r = lua_interface->GetInt8Value(state, 4);
  5941. int8 g = lua_interface->GetInt8Value(state, 5);
  5942. int8 b = lua_interface->GetInt8Value(state, 6);
  5943. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5944. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5945. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5946. lua_interface->ResetFunctionStack(state);
  5947. if (!spawn) {
  5948. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5949. return 0;
  5950. }
  5951. if (!spawn->IsEntity()) {
  5952. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5953. return 0;
  5954. }
  5955. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5956. spawn->vis_changed = true;
  5957. lua_interface->SetBooleanValue(state, true);
  5958. return 1;
  5959. }
  5960. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5961. if (!lua_interface)
  5962. return 0;
  5963. Spawn* player = lua_interface->GetSpawn(state);
  5964. int32 id = lua_interface->GetInt32Value(state, 2);
  5965. int8 count = lua_interface->GetInt8Value(state, 3);
  5966. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5967. lua_interface->ResetFunctionStack(state);
  5968. if (!player) {
  5969. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5970. return 0;
  5971. }
  5972. if (!player->IsPlayer()) {
  5973. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5974. return 0;
  5975. }
  5976. if (!count)
  5977. count = 1;
  5978. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5979. if (!item) {
  5980. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5981. return 0;
  5982. }
  5983. lua_interface->SetItemValue(state, item);
  5984. return 1;
  5985. }
  5986. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5987. if (!lua_interface)
  5988. return 0;
  5989. Spawn* spawn = lua_interface->GetSpawn(state);
  5990. int32 anim = lua_interface->GetInt32Value(state, 2);
  5991. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5992. int8 type = lua_interface->GetInt8Value(state, 4);
  5993. if (!spawn) {
  5994. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5995. return 0;
  5996. }
  5997. if (spawn2) {
  5998. if (spawn2->IsPlayer()) {
  5999. if (type != 1 && type != 2)
  6000. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6001. else
  6002. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6003. return 0;
  6004. }
  6005. else {
  6006. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6007. return 0;
  6008. }
  6009. }
  6010. else
  6011. spawn->GetZone()->PlayAnimation(spawn, anim);
  6012. return 0;
  6013. }
  6014. int EQ2Emu_lua_IsPet(lua_State* state) {
  6015. if (!lua_interface)
  6016. return 0;
  6017. Spawn* spawn = lua_interface->GetSpawn(state);
  6018. if (!spawn) {
  6019. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6020. return 0;
  6021. }
  6022. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6023. return 1;
  6024. }
  6025. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6026. if (!lua_interface)
  6027. return 0;
  6028. Spawn* spawn = lua_interface->GetSpawn(state);
  6029. if (!spawn) {
  6030. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6031. return 0;
  6032. }
  6033. if (!spawn->IsNPC()) {
  6034. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6035. return 0;
  6036. }
  6037. if (((NPC*)spawn)->GetOwner()) {
  6038. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6039. return 1;
  6040. }
  6041. return 0;
  6042. }
  6043. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6044. if (!lua_interface)
  6045. return 0;
  6046. Spawn* spawn = lua_interface->GetSpawn(state);
  6047. Spawn* target = lua_interface->GetSpawn(state, 2);
  6048. if (!spawn) {
  6049. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6050. return 0;
  6051. }
  6052. if (!spawn) {
  6053. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6054. return 0;
  6055. }
  6056. spawn->SetTarget(target);
  6057. return 0;
  6058. }
  6059. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6060. if (!lua_interface)
  6061. return 0;
  6062. Spawn* spawn = lua_interface->GetSpawn(state);
  6063. bool val = lua_interface->GetBooleanValue(state, 2);
  6064. if (!spawn) {
  6065. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6066. return 0;
  6067. }
  6068. if (!spawn->IsEntity()) {
  6069. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6070. return 0;
  6071. }
  6072. ((Entity*)spawn)->InCombat(val);
  6073. if (val) {
  6074. spawn->ClearRunningLocations();
  6075. spawn->CalculateRunningLocation(true);
  6076. }
  6077. return 0;
  6078. }
  6079. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6080. if (!lua_interface)
  6081. return 0;
  6082. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6083. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6084. if (!spawn1) {
  6085. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6086. return 0;
  6087. }
  6088. if (!spawn2) {
  6089. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6090. return 0;
  6091. }
  6092. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6093. return 1;
  6094. }
  6095. int EQ2Emu_lua_Runback(lua_State* state) {
  6096. if (!lua_interface)
  6097. return 0;
  6098. Spawn* spawn = lua_interface->GetSpawn(state);
  6099. if (!spawn) {
  6100. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6101. return 0;
  6102. }
  6103. if (!spawn->IsNPC()) {
  6104. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6105. return 0;
  6106. }
  6107. ((NPC*)spawn)->Runback();
  6108. return 0;
  6109. }
  6110. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6111. if (!lua_interface)
  6112. return 0;
  6113. Spawn* spawn = lua_interface->GetSpawn(state);
  6114. if (!spawn) {
  6115. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6116. return 0;
  6117. }
  6118. if (!spawn->IsNPC()) {
  6119. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6120. return 0;
  6121. }
  6122. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6123. return 1;
  6124. }
  6125. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6126. if (!lua_interface)
  6127. return 0;
  6128. Spawn* spawn = lua_interface->GetSpawn(state);
  6129. if (!spawn) {
  6130. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6131. return 0;
  6132. }
  6133. if (!spawn->IsEntity()) {
  6134. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6135. return 0;
  6136. }
  6137. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6138. return 1;
  6139. }
  6140. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6141. if (!lua_interface)
  6142. return 0;
  6143. Spawn* spawn = lua_interface->GetSpawn(state);
  6144. if (!spawn) {
  6145. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6146. return 0;
  6147. }
  6148. if (!spawn->IsEntity()) {
  6149. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6150. return 0;
  6151. }
  6152. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6153. return 1;
  6154. }
  6155. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6156. if (!lua_interface)
  6157. return 0;
  6158. Spawn* spawn = lua_interface->GetSpawn(state);
  6159. if (!spawn) {
  6160. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6161. return 0;
  6162. }
  6163. if (!spawn->IsEntity()) {
  6164. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6165. return 0;
  6166. }
  6167. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6168. return 1;
  6169. }
  6170. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6171. if (!lua_interface)
  6172. return 0;
  6173. Spawn* spawn = lua_interface->GetSpawn(state);
  6174. if (!spawn) {
  6175. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6176. return 0;
  6177. }
  6178. if (!spawn->IsEntity()) {
  6179. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6180. return 0;
  6181. }
  6182. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6183. return 1;
  6184. }
  6185. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6186. if (!lua_interface)
  6187. return 0;
  6188. Spawn* spawn = lua_interface->GetSpawn(state);
  6189. Spawn* target = lua_interface->GetSpawn(state, 2);
  6190. float distance = lua_interface->GetFloatValue(state, 3);
  6191. if (!spawn) {
  6192. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6193. return 0;
  6194. }
  6195. if (!target) {
  6196. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6197. return 0;
  6198. }
  6199. if (!spawn->IsNPC()) {
  6200. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6201. return 0;
  6202. }
  6203. if (!target->IsEntity()) {
  6204. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6205. return 0;
  6206. }
  6207. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6208. return 1;
  6209. }
  6210. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6211. if (!lua_interface)
  6212. return 0;
  6213. Spawn* spawn = lua_interface->GetSpawn(state);
  6214. Spawn* target = lua_interface->GetSpawn(state, 2);
  6215. float distance = lua_interface->GetFloatValue(state, 3);
  6216. if (!spawn) {
  6217. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6218. return 0;
  6219. }
  6220. if (!target) {
  6221. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6222. return 0;
  6223. }
  6224. if (!spawn->IsNPC()) {
  6225. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6226. return 0;
  6227. }
  6228. if (!target->IsEntity()) {
  6229. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6230. return 0;
  6231. }
  6232. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6233. return 0;
  6234. }
  6235. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6236. if (!lua_interface)
  6237. return 0;
  6238. Spawn* spawn = lua_interface->GetSpawn(state);
  6239. if (!spawn) {
  6240. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6241. return 0;
  6242. }
  6243. if (!spawn->IsNPC()) {
  6244. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6245. return 0;
  6246. }
  6247. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6248. return 1;
  6249. }
  6250. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6251. if (!lua_interface)
  6252. return 0;
  6253. Spawn* spawn = lua_interface->GetSpawn(state);
  6254. if (!spawn) {
  6255. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6256. return 0;
  6257. }
  6258. if (!spawn->IsNPC()) {
  6259. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6260. return 0;
  6261. }
  6262. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6263. return 1;
  6264. }
  6265. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6266. if (!lua_interface)
  6267. return 0;
  6268. Spawn* spawn = lua_interface->GetSpawn(state);
  6269. if (!spawn) {
  6270. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6271. return 0;
  6272. }
  6273. if (!spawn->IsNPC()) {
  6274. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6275. return 0;
  6276. }
  6277. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6278. if (hated) {
  6279. lua_interface->SetSpawnValue(state, hated);
  6280. return 1;
  6281. }
  6282. return 0;
  6283. }
  6284. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6285. if (!lua_interface)
  6286. return 0;
  6287. Spawn* spawn = lua_interface->GetSpawn(state);
  6288. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6289. if (!spawn) {
  6290. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. if (!spawn->IsNPC()) {
  6294. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6295. return 0;
  6296. }
  6297. if (!hated) {
  6298. ((NPC*)spawn)->Brain()->ClearHate();
  6299. return 0;
  6300. }
  6301. else
  6302. {
  6303. if (!hated->IsEntity()) {
  6304. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6305. return 0;
  6306. }
  6307. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6308. return 0;
  6309. }
  6310. return 0;
  6311. }
  6312. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6313. if (!lua_interface)
  6314. return 0;
  6315. Spawn* spawn = lua_interface->GetSpawn(state);
  6316. if (!spawn) {
  6317. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6318. return 0;
  6319. }
  6320. if (!spawn->IsNPC()) {
  6321. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6322. return 0;
  6323. }
  6324. ((NPC*)spawn)->Brain()->ClearEncounter();
  6325. return 0;
  6326. }
  6327. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6328. if (!lua_interface)
  6329. return 0;
  6330. Spawn* spawn = lua_interface->GetSpawn(state);
  6331. if (!spawn) {
  6332. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6333. return 0;
  6334. }
  6335. if (!spawn->IsNPC()) {
  6336. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6337. return 0;
  6338. }
  6339. // Temp list to store hate list
  6340. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6341. if (encounterList->size() == 0) {
  6342. safe_delete(encounterList);
  6343. return 0;
  6344. }
  6345. lua_createtable(state, encounterList->size(), 0);
  6346. int newTable = lua_gettop(state);
  6347. for (int32 i = 0; i < encounterList->size(); i++) {
  6348. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6349. if (temp)
  6350. lua_interface->SetSpawnValue(state, temp);
  6351. lua_rawseti(state, newTable, i + 1);
  6352. }
  6353. safe_delete(encounterList);
  6354. return 1;
  6355. }
  6356. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6357. if (!lua_interface)
  6358. return 0;
  6359. Spawn* spawn = lua_interface->GetSpawn(state);
  6360. if (!spawn) {
  6361. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6362. return 0;
  6363. }
  6364. if (!spawn->IsNPC()) {
  6365. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6366. return 0;
  6367. }
  6368. // Temp list to store hate list
  6369. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6370. if (hateList->size() == 0) {
  6371. safe_delete(hateList);
  6372. return 0;
  6373. }
  6374. lua_createtable(state, hateList->size(), 0);
  6375. int newTable = lua_gettop(state);
  6376. for (int32 i = 0; i < hateList->size(); i++) {
  6377. lua_interface->SetSpawnValue(state, hateList->at(i));
  6378. lua_rawseti(state, newTable, i + 1);
  6379. }
  6380. safe_delete(hateList);
  6381. return 1;
  6382. }
  6383. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6384. if (!lua_interface)
  6385. return 0;
  6386. Spawn* spawn = lua_interface->GetSpawn(state);
  6387. if (!spawn) {
  6388. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6389. return 0;
  6390. }
  6391. if (spawn->IsPlayer()) {
  6392. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6393. lua_interface->SetBooleanValue(state, true);
  6394. else
  6395. lua_interface->SetBooleanValue(state, false);
  6396. return 1;
  6397. }
  6398. else {
  6399. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6400. return 1;
  6401. }
  6402. }
  6403. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6404. if (!lua_interface)
  6405. return 0;
  6406. Quest* quest = lua_interface->GetQuest(state);
  6407. if (!quest) {
  6408. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6409. return 0;
  6410. }
  6411. quest->SetCompletedFlag(true);
  6412. return 0;
  6413. }
  6414. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6415. if (!lua_interface)
  6416. return 0;
  6417. Spawn* spawn = lua_interface->GetSpawn(state);
  6418. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6419. int8 tier = lua_interface->GetInt8Value(state, 3);
  6420. if (!spawn) {
  6421. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6422. return 0;
  6423. }
  6424. if (!spawn->IsEntity()) {
  6425. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6426. return 0;
  6427. }
  6428. if (spellID == 0) {
  6429. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6430. return 0;
  6431. }
  6432. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6433. if (effect) {
  6434. if (tier > 0) {
  6435. // If a tier was passed chec to see if it is the same as the effect
  6436. if (tier == effect->tier)
  6437. lua_interface->SetBooleanValue(state, true);
  6438. else
  6439. lua_interface->SetBooleanValue(state, false);
  6440. return 1;
  6441. }
  6442. else {
  6443. // Have an effect but no tier was passed so return true
  6444. lua_interface->SetBooleanValue(state, true);
  6445. }
  6446. return 1;
  6447. }
  6448. // no effect so return false
  6449. lua_interface->SetBooleanValue(state, false);
  6450. return 1;
  6451. }
  6452. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6453. if (!lua_interface)
  6454. return 0;
  6455. Spawn* spawn = lua_interface->GetSpawn(state);
  6456. int32 id = lua_interface->GetInt32Value(state, 2);
  6457. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6458. Spawn* spawn2 = 0;
  6459. vector<Spawn*> list;
  6460. if (!spawn) {
  6461. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6462. return 0;
  6463. }
  6464. //If zone not provided, use spawn's zone
  6465. if (!zone)
  6466. zone = spawn->GetZone();
  6467. list = zone->GetSpawnsByID(id);
  6468. if (list.size() == 0) {
  6469. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6470. return 0;
  6471. }
  6472. vector<Spawn*>::iterator itr = list.begin();
  6473. for (int8 i = 0; i < list.size(); i++) {
  6474. spawn2 = itr[i];
  6475. if (spawn2)
  6476. spawn2->AddAllowAccessSpawn(spawn);
  6477. }
  6478. return 0;
  6479. }
  6480. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6481. if (!lua_interface)
  6482. return 0;
  6483. Spawn* spawn = lua_interface->GetSpawn(state);
  6484. int32 id = lua_interface->GetInt32Value(state, 2);
  6485. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6486. Spawn* spawn2 = 0;
  6487. if (!spawn) {
  6488. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6489. return 0;
  6490. }
  6491. //If zone not provided, use spawn's zone
  6492. if (!zone)
  6493. zone = spawn->GetZone();
  6494. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6495. vector<Spawn*>::iterator itr = list.begin();
  6496. if (list.size() == 0) {
  6497. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6498. return 0;
  6499. }
  6500. for (int8 i = 0; i < list.size(); i++) {
  6501. spawn2 = itr[i];
  6502. if (spawn2)
  6503. spawn2->RemoveSpawnAccess(spawn);
  6504. }
  6505. return 0;
  6506. }
  6507. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6508. if (!lua_interface)
  6509. return 0;
  6510. Quest* quest = lua_interface->GetQuest(state);
  6511. if (!quest) {
  6512. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6513. return 0;
  6514. }
  6515. quest->SetYellowName(true);
  6516. return 0;
  6517. }
  6518. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6519. if (!lua_interface)
  6520. return 0;
  6521. Spawn* spawn = lua_interface->GetSpawn(state);
  6522. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6523. if (!spawn) {
  6524. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6525. return 0;
  6526. }
  6527. if (!spawn->IsPlayer()) {
  6528. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6529. return 0;
  6530. }
  6531. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6532. return 1;
  6533. }
  6534. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6535. if (!lua_interface)
  6536. return 0;
  6537. Spawn* spawn = lua_interface->GetSpawn(state);
  6538. if (!spawn) {
  6539. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6540. return 0;
  6541. }
  6542. if (!spawn->IsPlayer()) {
  6543. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6544. return 0;
  6545. }
  6546. ZoneServer* zone = spawn->GetZone();
  6547. if (!zone) {
  6548. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6549. return 0;
  6550. }
  6551. Instance_Type iType = zone->GetInstanceType();
  6552. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6553. iType == GROUP_LOCKOUT_INSTANCE ||
  6554. iType == RAID_LOCKOUT_INSTANCE ||
  6555. iType == SOLO_PERSIST_INSTANCE ||
  6556. iType == GROUP_PERSIST_INSTANCE ||
  6557. iType == RAID_PERSIST_INSTANCE) {
  6558. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6559. if (data) {
  6560. // Check to see if the timer has already been set, if it has return out.
  6561. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6562. return 0;
  6563. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6564. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6565. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6566. if (client) {
  6567. string time_msg = "";
  6568. int32 time = data->success_lockout_time;
  6569. int16 hour;
  6570. int8 min;
  6571. int8 sec;
  6572. hour = time / 3600;
  6573. time = time % 3600;
  6574. min = time / 60;
  6575. time = time % 60;
  6576. sec = time;
  6577. if (hour > 0) {
  6578. char temp[10];
  6579. sprintf(temp, " %i", hour);
  6580. time_msg.append(temp);
  6581. time_msg.append(" hour");
  6582. time_msg.append((hour > 1) ? "s" : "");
  6583. }
  6584. if (min > 0) {
  6585. char temp[5];
  6586. sprintf(temp, " %i", min);
  6587. time_msg.append(temp);
  6588. time_msg.append(" minute");
  6589. time_msg.append((min > 1) ? "s" : "");
  6590. }
  6591. // Only add seconds if minutes and hours are 0
  6592. if (hour == 0 && min == 0 && sec > 0) {
  6593. char temp[5];
  6594. sprintf(temp, " %i", sec);
  6595. time_msg.append(temp);
  6596. time_msg.append(" second");
  6597. time_msg.append((sec > 1) ? "s" : "");
  6598. }
  6599. 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());
  6600. }
  6601. }
  6602. else
  6603. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6604. }
  6605. else
  6606. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6607. return 0;
  6608. }
  6609. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6610. if (!lua_interface)
  6611. return 0;
  6612. Spawn* spawn = lua_interface->GetSpawn(state);
  6613. if (!spawn) {
  6614. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6615. return 0;
  6616. }
  6617. if (!spawn->IsPlayer()) {
  6618. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6619. return 0;
  6620. }
  6621. ZoneServer* zone = spawn->GetZone();
  6622. if (!zone) {
  6623. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6624. return 0;
  6625. }
  6626. Instance_Type iType = zone->GetInstanceType();
  6627. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6628. iType == GROUP_LOCKOUT_INSTANCE ||
  6629. iType == RAID_LOCKOUT_INSTANCE ||
  6630. iType == SOLO_PERSIST_INSTANCE ||
  6631. iType == GROUP_PERSIST_INSTANCE ||
  6632. iType == RAID_PERSIST_INSTANCE) {
  6633. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6634. if (data) {
  6635. // Check to see if the timer has already been set, if it has return out.
  6636. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6637. return 0;
  6638. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6639. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6640. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6641. if (client) {
  6642. string time_msg = "";
  6643. int32 time = data->failure_lockout_time;
  6644. int16 hour;
  6645. int8 min;
  6646. int8 sec;
  6647. hour = time / 3600;
  6648. time = time % 3600;
  6649. min = time / 60;
  6650. time = time % 60;
  6651. sec = time;
  6652. if (hour > 0) {
  6653. char temp[10];
  6654. sprintf(temp, " %i", hour);
  6655. time_msg.append(temp);
  6656. time_msg.append(" hour");
  6657. time_msg.append((hour > 1) ? "s" : "");
  6658. }
  6659. if (min > 0) {
  6660. char temp[5];
  6661. sprintf(temp, " %i", min);
  6662. time_msg.append(temp);
  6663. time_msg.append(" minute");
  6664. time_msg.append((min > 1) ? "s" : "");
  6665. }
  6666. // Only add seconds if minutes and hours are 0
  6667. if (hour == 0 && min == 0 && sec > 0) {
  6668. char temp[5];
  6669. sprintf(temp, " %i", sec);
  6670. time_msg.append(temp);
  6671. time_msg.append(" second");
  6672. time_msg.append((sec > 1) ? "s" : "");
  6673. }
  6674. 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());
  6675. }
  6676. }
  6677. else
  6678. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6679. }
  6680. else
  6681. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6682. return 0;
  6683. }
  6684. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6685. if (!lua_interface)
  6686. return 0;
  6687. Spawn* spawn = lua_interface->GetSpawn(state);
  6688. if (!spawn) {
  6689. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6690. return 0;
  6691. }
  6692. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6693. return 1;
  6694. }
  6695. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6696. if (!lua_interface)
  6697. return 0;
  6698. Spawn* player = lua_interface->GetSpawn(state);
  6699. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6700. if (!player) {
  6701. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6702. return 0;
  6703. }
  6704. if (!player->IsPlayer()) {
  6705. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6706. return 0;
  6707. }
  6708. if (!ground) {
  6709. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6710. return 0;
  6711. }
  6712. if (!ground->IsGroundSpawn()) {
  6713. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6714. return 0;
  6715. }
  6716. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6717. if (!groundspawn_entries) {
  6718. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6719. return 0;
  6720. }
  6721. Skill* skill = 0;
  6722. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6723. if (collection_skill == "Collecting")
  6724. skill = ((Player*)player)->GetSkillByName("Gathering");
  6725. else
  6726. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6727. if (!skill) {
  6728. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6729. return 0;
  6730. }
  6731. vector<GroundSpawnEntry*>::iterator itr;
  6732. GroundSpawnEntry* entry = 0;
  6733. bool can_harvest = false;
  6734. sint32 min_skill = -1;
  6735. int16 totalSkill = skill->current_val;
  6736. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6737. if(skillID != 0xFFFFFFFF)
  6738. {
  6739. ((Entity*)player)->MStats.lock();
  6740. totalSkill += ((Entity*)player)->stats[skillID];
  6741. ((Entity*)player)->MStats.unlock();
  6742. }
  6743. // first, iterate through groundspawn_entries, discard tables player cannot use
  6744. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6745. {
  6746. entry = *itr;
  6747. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6748. min_skill = entry->min_skill_level;
  6749. // if player lacks skill, skip table
  6750. if (entry->min_skill_level > totalSkill)
  6751. continue;
  6752. // if bonus, but player lacks level, skip table
  6753. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6754. continue;
  6755. can_harvest = true;
  6756. break;
  6757. }
  6758. lua_interface->SetBooleanValue(state, can_harvest);
  6759. // If false, send the message to the client
  6760. if (!can_harvest) {
  6761. Client* client = player->GetZone()->GetClientBySpawn(player);
  6762. if (client) {
  6763. string msg = "You do not have enough skill to ";
  6764. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6765. msg.append("gather");
  6766. else if (collection_skill == "Mining")
  6767. msg.append("mine");
  6768. else if (collection_skill == "Trapping")
  6769. msg.append("trap");
  6770. else if (collection_skill == "Foresting")
  6771. msg.append("forest");
  6772. else if (collection_skill == "Fishing")
  6773. msg.append("catch");
  6774. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6775. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6776. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6777. }
  6778. }
  6779. return 1;
  6780. }
  6781. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6782. if (!lua_interface)
  6783. return 0;
  6784. Spawn* player = lua_interface->GetSpawn(state);
  6785. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6786. if (!player) {
  6787. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6788. return 0;
  6789. }
  6790. if (!player->IsPlayer()) {
  6791. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6792. return 0;
  6793. }
  6794. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6795. lua_interface->SetBooleanValue(state, ret);
  6796. return 1;
  6797. }
  6798. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6799. // Check to see if we have a valid lua_interface
  6800. if (!lua_interface)
  6801. return 0;
  6802. // Get the spawn that is getting the pet
  6803. Spawn* spawn = lua_interface->GetSpawn(state);
  6804. Spawn* target = lua_interface->GetSpawn(state, 2);
  6805. // Get the DB ID of the pet
  6806. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6807. float x = lua_interface->GetFloatValue(state, 4);
  6808. float y = lua_interface->GetFloatValue(state, 5);
  6809. float z = lua_interface->GetFloatValue(state, 6);
  6810. // Get the spell that this command was called from
  6811. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6812. // Check to make sure the spawn pointer is valid
  6813. if (!spawn) {
  6814. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6815. return 0;
  6816. }
  6817. // Check to make sure the spawn is an entity
  6818. if (!spawn->IsEntity()) {
  6819. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6820. return 0;
  6821. }
  6822. if (!target) {
  6823. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6824. return 0;
  6825. }
  6826. if (!target->IsEntity()) {
  6827. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6828. return 0;
  6829. }
  6830. // Check to see if the DB ID for the pet is set
  6831. if (pet_id == 0) {
  6832. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6833. return 0;
  6834. }
  6835. // Check to see if the pointer to the spell is valid
  6836. if (!luaspell) {
  6837. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6841. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6842. if (!pet) {
  6843. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6844. return 0;
  6845. }
  6846. // Check to make sure the pet is an npc
  6847. if (!pet->IsNPC()) {
  6848. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6849. return 0;
  6850. }
  6851. if (x == 0)
  6852. x = spawn->GetX();
  6853. if (y == 0)
  6854. y = spawn->GetY();
  6855. if (z == 0)
  6856. z = spawn->GetZ();
  6857. // Spawn the pet at the same location as the owner
  6858. pet->SetX(x);
  6859. pet->SetY(y);
  6860. pet->SetZ(z);
  6861. pet->SetLocation(spawn->GetLocation());
  6862. pet->SetHeading(spawn->GetHeading());
  6863. spawn->GetZone()->AddSpawn(pet);
  6864. /*
  6865. const char* spawn_script = world.GetSpawnScript(pet_id);
  6866. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6867. spawn->SetSpawnScript(string(spawn_script));
  6868. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6869. }*/
  6870. // Get a random pet name
  6871. string random_pet_name;
  6872. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6873. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6874. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6875. // Set the pets name
  6876. pet->SetName(random_pet_name.c_str());
  6877. // Set the level of the pet to the owners level
  6878. pet->SetLevel(spawn->GetLevel());
  6879. // Set the faction of the pet to the same faction as the owner
  6880. pet->SetFactionID(spawn->GetFactionID());
  6881. // Set the spawn as a pet
  6882. pet->SetPet(true);
  6883. // Give a pointer of the owner to the pet
  6884. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6885. // Set the pet type
  6886. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6887. // Set the spell id used to create this pet
  6888. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6889. // Set the spell tier used to create this pet
  6890. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6891. // Set the pets spawn type to 6
  6892. pet->SetSpawnType(6);
  6893. // Set the pets brain
  6894. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6895. // Check to see if the pet has a subtitle
  6896. if (strlen(pet->GetSubTitle()) > 0) {
  6897. // Add the players name to the front of the sub title
  6898. string pet_subtitle;
  6899. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6900. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6901. // Set the pets subtitle to the new one
  6902. pet->SetSubTitle(pet_subtitle.c_str());
  6903. }
  6904. // Set the pet as the return value for this function
  6905. lua_interface->SetSpawnValue(state, pet);
  6906. return 1;
  6907. }
  6908. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6909. if (!lua_interface)
  6910. return 0;
  6911. Spawn* spawn = lua_interface->GetSpawn(state);
  6912. Spawn* player = lua_interface->GetSpawn(state, 2);
  6913. float max_distance = lua_interface->GetFloatValue(state, 3);
  6914. string type = lua_interface->GetStringValue(state, 4);
  6915. if (!spawn || (spawn && spawn->IsPlayer())) {
  6916. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6917. return 0;
  6918. }
  6919. if (!player || (player && !player->IsPlayer())) {
  6920. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6921. return 0;
  6922. }
  6923. Client* client = 0;
  6924. if (player->GetZone())
  6925. client = player->GetZone()->GetClientBySpawn(player);
  6926. if (!client) {
  6927. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6928. return 0;
  6929. }
  6930. //Set max_distance to default if not set or not proper value
  6931. if (max_distance <= 0)
  6932. max_distance = 500;
  6933. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6934. if (packet) {
  6935. float unknown2_3 = 0;
  6936. int8 placement_mode = 0;
  6937. if (type == "wall") {
  6938. placement_mode = 2;
  6939. unknown2_3 = 150;
  6940. }
  6941. else if (type == "ceiling")
  6942. placement_mode = 1;
  6943. packet->setDataByName("placement_mode", placement_mode);
  6944. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6945. packet->setDataByName("model_type", spawn->GetModelType());
  6946. packet->setDataByName("unknown", 1); //size
  6947. packet->setDataByName("unknown2", 1); //size 2
  6948. packet->setDataByName("unknown2", .5, 1); //size 3
  6949. packet->setDataByName("unknown2", 3, 2);
  6950. packet->setDataByName("unknown2", unknown2_3, 3);
  6951. packet->setDataByName("max_distance", max_distance);
  6952. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6953. client->QueuePacket(packet->serialize());
  6954. safe_delete(packet);
  6955. }
  6956. return 0;
  6957. }
  6958. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6959. if (!lua_interface)
  6960. return 0;
  6961. Item* item = lua_interface->GetItem(state);
  6962. if (!item) {
  6963. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6964. return 0;
  6965. }
  6966. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6967. return 1;
  6968. }
  6969. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6970. if (!lua_interface)
  6971. return 0;
  6972. Spawn* spawn = lua_interface->GetSpawn(state);
  6973. if (!spawn) {
  6974. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6975. return 0;
  6976. }
  6977. if (spawn->GetZone())
  6978. spawn->GetZone()->AddTransportSpawn(spawn);
  6979. return 0;
  6980. }
  6981. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  6982. if (!lua_interface)
  6983. return 0;
  6984. Spawn* spawn = lua_interface->GetSpawn(state);
  6985. if (!spawn) {
  6986. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6987. return 0;
  6988. }
  6989. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  6990. return 1;
  6991. }
  6992. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6993. if (!lua_interface)
  6994. return 0;
  6995. Skill* skill = lua_interface->GetSkill(state);
  6996. if (!skill) {
  6997. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6998. return 0;
  6999. }
  7000. lua_interface->SetInt32Value(state, skill->current_val);
  7001. return 1;
  7002. }
  7003. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7004. if (!lua_interface)
  7005. return 0;
  7006. Skill* skill = lua_interface->GetSkill(state);
  7007. if (!skill) {
  7008. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7009. return 0;
  7010. }
  7011. lua_interface->SetInt32Value(state, skill->max_val);
  7012. return 1;
  7013. }
  7014. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7015. if (!lua_interface)
  7016. return 0;
  7017. Skill* skill = lua_interface->GetSkill(state);
  7018. if (!skill) {
  7019. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7020. return 0;
  7021. }
  7022. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7023. return 1;
  7024. }
  7025. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7026. if (!lua_interface)
  7027. return 0;
  7028. Skill* skill = lua_interface->GetSkill(state);
  7029. int16 value = lua_interface->GetInt16Value(state, 2);
  7030. if (!skill) {
  7031. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7032. return 0;
  7033. }
  7034. skill->max_val = value;
  7035. if (skill->max_val < skill->current_val)
  7036. skill->current_val = skill->max_val;
  7037. return 0;
  7038. }
  7039. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7040. if (!lua_interface)
  7041. return 0;
  7042. Skill* skill = lua_interface->GetSkill(state);
  7043. int16 value = lua_interface->GetInt16Value(state, 2);
  7044. if (!skill) {
  7045. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7046. return 0;
  7047. }
  7048. if (value > skill->max_val)
  7049. skill->current_val = skill->max_val;
  7050. else
  7051. skill->current_val = value;
  7052. return 0;
  7053. }
  7054. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7055. if (!lua_interface)
  7056. return 0;
  7057. Spawn* player = lua_interface->GetSpawn(state);
  7058. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7059. if (skill_id > 0 && player && player->IsPlayer()) {
  7060. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7061. return 1;
  7062. }
  7063. return 0;
  7064. }
  7065. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7066. if (!lua_interface)
  7067. return 0;
  7068. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7069. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7070. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7071. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7072. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7073. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7074. if (player_spawn && player_spawn->IsPlayer()) {
  7075. Player* player = (Player*)player_spawn;
  7076. bool added = false;
  7077. if (!player->skill_list.HasSkill(skill_id)) {
  7078. player->AddSkill(skill_id, current_val, max_val, true);
  7079. added = true;
  7080. }
  7081. if (!more_to_add) { //need to send update regardless, even if THIS skill wasn't added, otherwise if you have a list and the last item wasn't added but the previous ones were, it wouldn't send the update
  7082. Client* client = player->GetClient();
  7083. if (client) {
  7084. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7085. if (packet)
  7086. client->QueuePacket(packet);
  7087. }
  7088. }
  7089. if (added) {
  7090. lua_interface->SetBooleanValue(state, true);
  7091. return 1;
  7092. }
  7093. }
  7094. else {
  7095. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7096. }
  7097. }
  7098. else {
  7099. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7100. }
  7101. lua_interface->SetBooleanValue(state, false);
  7102. return 1;
  7103. }
  7104. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7105. if (!lua_interface)
  7106. return 0;
  7107. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7108. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7109. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7110. if (skill_id > 0) {
  7111. if (player_spawn && player_spawn->IsPlayer()) {
  7112. Player* player = (Player*)player_spawn;
  7113. if (player->skill_list.HasSkill(skill_id)) {
  7114. player->RemovePlayerSkill(skill_id);
  7115. if (!more_to_remove) {
  7116. Client* client = player->GetClient();
  7117. if (client) {
  7118. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7119. if (packet)
  7120. client->QueuePacket(packet);
  7121. }
  7122. }
  7123. }
  7124. }
  7125. else {
  7126. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7127. }
  7128. }
  7129. else {
  7130. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7131. }
  7132. return 0;
  7133. }
  7134. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7135. if (!lua_interface)
  7136. return 0;
  7137. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7138. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7139. int16 amount = lua_interface->GetInt8Value(state, 3);
  7140. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7141. if (amount > 0 && skill_type < 100) {
  7142. if (player_spawn && player_spawn->IsPlayer()) {
  7143. Player* player = (Player*)player_spawn;
  7144. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7145. if (!more_to_increase) {
  7146. Client* client = player->GetClient();
  7147. if (client) {
  7148. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7149. if (packet)
  7150. client->QueuePacket(packet);
  7151. }
  7152. }
  7153. }
  7154. else {
  7155. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7156. }
  7157. }
  7158. else {
  7159. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7160. }
  7161. return 0;
  7162. }
  7163. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7164. if (!lua_interface)
  7165. return 0;
  7166. Spawn* spawn = lua_interface->GetSpawn(state);
  7167. string name = lua_interface->GetStringValue(state, 2);
  7168. if (!spawn) {
  7169. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7170. return 0;
  7171. }
  7172. if (!spawn->IsEntity()) {
  7173. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7174. return 0;
  7175. }
  7176. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7177. if (skill) {
  7178. lua_interface->SetSkillValue(state, skill);
  7179. return 1;
  7180. }
  7181. return 0;
  7182. }
  7183. int EQ2Emu_lua_AddProc(lua_State* state) {
  7184. if (!lua_interface)
  7185. return 0;
  7186. Spawn* spawn = lua_interface->GetSpawn(state);
  7187. int8 type = lua_interface->GetInt8Value(state, 2);
  7188. float chance = lua_interface->GetFloatValue(state, 3);
  7189. Item* item = lua_interface->GetItem(state, 4);
  7190. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7191. LuaSpell* spell = 0;
  7192. if (!spawn && (!spell || !use_all_spelltargets)) {
  7193. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7194. return 0;
  7195. }
  7196. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7197. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7198. return 0;
  7199. }
  7200. if (!item)
  7201. spell = lua_interface->GetCurrentSpell(state);
  7202. if (!item && !spell) {
  7203. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7204. return 0;
  7205. }
  7206. if (spell && use_all_spelltargets) {
  7207. Spawn* target;
  7208. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7209. for (int8 i = 0; i < spell->targets.size(); i++) {
  7210. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7211. if (!target || !target->IsEntity())
  7212. continue;
  7213. ((Entity*)target)->AddProc(type, chance, item, spell);
  7214. }
  7215. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7216. }
  7217. else
  7218. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7219. return 0;
  7220. }
  7221. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7222. if (!lua_interface)
  7223. return 0;
  7224. Spawn* spawn = lua_interface->GetSpawn(state);
  7225. Item* item = lua_interface->GetItem(state, 2);
  7226. LuaSpell* spell = 0;
  7227. if (!spawn) {
  7228. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7229. return 0;
  7230. }
  7231. if (!spawn->IsEntity()) {
  7232. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7233. return 0;
  7234. }
  7235. if (!item)
  7236. spell = lua_interface->GetCurrentSpell(state);
  7237. if (!item && !spell) {
  7238. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7239. return 0;
  7240. }
  7241. if (spell) {
  7242. Spawn* target;
  7243. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7244. for (int8 i = 0; i < spell->targets.size(); i++) {
  7245. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7246. if (!target || !target->IsEntity())
  7247. continue;
  7248. ((Entity*)target)->RemoveProc(item, spell);
  7249. }
  7250. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7251. spell->caster->RemoveProc(item, spell);
  7252. }
  7253. else
  7254. ((Entity*)spawn)->RemoveProc(item, spell);
  7255. return 0;
  7256. }
  7257. int EQ2Emu_lua_Knockback(lua_State* state) {
  7258. if (!lua_interface)
  7259. return 0;
  7260. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7261. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7262. int32 duration = lua_interface->GetInt32Value(state, 3);
  7263. float vertical = lua_interface->GetFloatValue(state, 4);
  7264. float horizontal = lua_interface->GetFloatValue(state, 5);
  7265. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7266. if (!target_spawn) {
  7267. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7268. return 0;
  7269. }
  7270. if (!spawn) {
  7271. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7272. return 0;
  7273. }
  7274. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7275. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7276. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7277. if (packet) {
  7278. packet->setDataByName("target_x", target_spawn->GetX());
  7279. packet->setDataByName("target_y", target_spawn->GetY());
  7280. packet->setDataByName("target_z", target_spawn->GetZ());
  7281. packet->setDataByName("vertical_movement", vertical);
  7282. packet->setDataByName("horizontal_movement", horizontal);
  7283. if (use_heading)
  7284. packet->setDataByName("use_player_heading", 1);
  7285. client->QueuePacket(packet->serialize());
  7286. }
  7287. safe_delete(packet);
  7288. }
  7289. return 0;
  7290. }
  7291. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7292. if (!lua_interface)
  7293. return 0;
  7294. Spawn* spawn = lua_interface->GetSpawn(state);
  7295. if (!spawn) {
  7296. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7297. return 0;
  7298. }
  7299. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7300. return 1;
  7301. }
  7302. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7303. if (!lua_interface)
  7304. return 0;
  7305. Spawn* caster = lua_interface->GetSpawn(state);
  7306. Spawn* target = lua_interface->GetSpawn(state, 2);
  7307. string name = lua_interface->GetStringValue(state, 3);
  7308. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7309. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7310. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7311. string success_msg = lua_interface->GetStringValue(state, 7);
  7312. string effect_msg = lua_interface->GetStringValue(state, 8);
  7313. if (!caster) {
  7314. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. if (!caster->IsEntity()) {
  7318. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7319. return 0;
  7320. }
  7321. if (!target) {
  7322. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7323. return 0;
  7324. }
  7325. if (!target->IsEntity()) {
  7326. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7327. return 0;
  7328. }
  7329. if (name.length() == 0) {
  7330. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7331. return 0;
  7332. }
  7333. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7334. return 0;
  7335. }
  7336. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7337. if (!lua_interface)
  7338. return 0;
  7339. string name = lua_interface->GetStringValue(state);
  7340. if (name.length() == 0) {
  7341. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7342. return 0;
  7343. }
  7344. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7345. if (!skill) {
  7346. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7347. return 0;
  7348. }
  7349. lua_interface->SetInt32Value(state, skill->skill_id);
  7350. return 1;
  7351. }
  7352. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7353. if (!lua_interface)
  7354. return 0;
  7355. Spawn* spawn = lua_interface->GetSpawn(state);
  7356. if (!spawn) {
  7357. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7358. return 0;
  7359. }
  7360. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7361. return 1;
  7362. }
  7363. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7364. if (!lua_interface)
  7365. return 0;
  7366. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7367. if (!luaspell) {
  7368. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7369. return 0;
  7370. }
  7371. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7372. return 1;
  7373. }
  7374. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7375. if (!lua_interface)
  7376. return 0;
  7377. Spawn* spawn = lua_interface->GetSpawn(state);
  7378. Spawn* target = lua_interface->GetSpawn(state, 2);
  7379. if (!spawn) {
  7380. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7381. return 0;
  7382. }
  7383. if (!spawn->IsEntity()) {
  7384. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7385. return 0;
  7386. }
  7387. if (!target) {
  7388. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7389. return 0;
  7390. }
  7391. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7392. return 1;
  7393. }
  7394. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7395. if (!lua_interface)
  7396. return 0;
  7397. Spawn* spawn = lua_interface->GetSpawn(state);
  7398. Spawn* target = lua_interface->GetSpawn(state, 2);
  7399. if (!spawn) {
  7400. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7401. return 0;
  7402. }
  7403. if (!spawn->IsEntity()) {
  7404. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7405. return 0;
  7406. }
  7407. if (!target) {
  7408. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7409. return 0;
  7410. }
  7411. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7412. return 1;
  7413. }
  7414. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7415. if (!lua_interface)
  7416. return 0;
  7417. Item* item = lua_interface->GetItem(state);
  7418. if (!item) {
  7419. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7420. return 0;
  7421. }
  7422. lua_interface->SetInt32Value(state, item->details.count);
  7423. return 1;
  7424. }
  7425. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7426. if (!lua_interface)
  7427. return 0;
  7428. Item* item = lua_interface->GetItem(state);
  7429. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7430. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7431. if (!item) {
  7432. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7433. return 0;
  7434. }
  7435. if (!owner) {
  7436. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7437. return 0;
  7438. }
  7439. if (!owner->IsPlayer()) {
  7440. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7441. return 0;
  7442. }
  7443. if (item->stack_count < new_count) {
  7444. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7445. return 0;
  7446. }
  7447. if (new_count > 0) {
  7448. item->details.count = new_count;
  7449. item->save_needed = true;
  7450. }
  7451. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7452. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7453. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7454. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7455. else
  7456. {
  7457. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7458. return 0;
  7459. }
  7460. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7461. if (!client)
  7462. return 0;
  7463. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7464. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7465. if (app)
  7466. client->QueuePacket(app);
  7467. return 0;
  7468. }
  7469. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7470. if (!lua_interface)
  7471. return 0;
  7472. int32 time = lua_interface->GetInt32Value(state);
  7473. string function = lua_interface->GetStringValue(state, 2);
  7474. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7475. Spawn* target = lua_interface->GetSpawn(state, 4);
  7476. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7477. if (time == 0) {
  7478. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7479. return 0;
  7480. }
  7481. if (function.length() == 0) {
  7482. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7483. return 0;
  7484. }
  7485. if (!spell) {
  7486. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7487. return 0;
  7488. }
  7489. SpellScriptTimer* timer = new SpellScriptTimer;
  7490. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7491. #ifdef WIN32
  7492. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7493. #else
  7494. bzero(timer, sizeof(SpellScriptTimer));
  7495. #endif*/
  7496. timer->caster = 0;
  7497. timer->deleteWhenDone = false;
  7498. timer->target = 0;
  7499. timer->time = Timer::GetCurrentTime2() + time;
  7500. timer->customFunction = function;
  7501. timer->spell = spell;
  7502. if (caster)
  7503. timer->caster = caster->GetID();
  7504. if (target)
  7505. timer->target = target->GetID();
  7506. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7507. return 0;
  7508. }
  7509. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7510. if (!lua_interface)
  7511. return 0;
  7512. float hp_perc = lua_interface->GetFloatValue(state);
  7513. float power_perc = lua_interface->GetFloatValue(state, 2);
  7514. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7515. Spawn* target = lua_interface->GetSpawn(state, 4);
  7516. string heal_name = lua_interface->GetStringValue(state, 5);
  7517. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7518. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7519. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7520. if (!spell) {
  7521. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7522. return 0;
  7523. }
  7524. Entity* caster = spell->caster;
  7525. if (!caster) {
  7526. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7527. return 0;
  7528. }
  7529. Client* client = 0;
  7530. PendingResurrection* rez = 0;
  7531. ZoneServer* zone = spell->caster->GetZone();
  7532. if (!target) {
  7533. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7534. if (spell->targets.size() > 0) {
  7535. vector<int32> spell_targets = spell->targets;
  7536. for (int8 i = 0; i < spell_targets.size(); i++) {
  7537. target = zone->GetSpawnByID(spell_targets.at(i));
  7538. if (!target)
  7539. continue;
  7540. if (!target->IsPlayer())
  7541. continue;
  7542. client = target->GetZone()->GetClientBySpawn(target);
  7543. if (!client)
  7544. continue;
  7545. rez = client->GetCurrentRez();
  7546. if (rez->active)
  7547. continue;
  7548. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7549. rez->active = true;
  7550. rez->caster = caster;
  7551. rez->expire_timer = new Timer;
  7552. int32 duration = spell->spell->GetSpellDuration();
  7553. rez->expire_timer->Start(duration * 100);
  7554. rez->hp_perc = hp_perc;
  7555. rez->mp_perc = power_perc;
  7556. rez->range = spell->spell->GetSpellData()->range;
  7557. rez->spell_name = spell->spell->GetName();
  7558. if (heal_name.length() > 0)
  7559. rez->heal_name = heal_name;
  7560. else
  7561. rez->heal_name = rez->spell_name;
  7562. rez->no_calcs = no_calcs;
  7563. rez->crit_mod = crit_mod;
  7564. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7565. if (send_window)
  7566. client->SendResurrectionWindow();
  7567. else {
  7568. target->GetZone()->ResurrectSpawn(target, client);
  7569. rez->should_delete = true;
  7570. }
  7571. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7572. }
  7573. }
  7574. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7575. }
  7576. else {
  7577. client = target->GetZone()->GetClientBySpawn(target);
  7578. if (!client)
  7579. return 0;
  7580. rez = client->GetCurrentRez();
  7581. if (rez->active)
  7582. return 0;
  7583. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7584. rez->active = true;
  7585. rez->caster = caster;
  7586. rez->expire_timer = new Timer;
  7587. int32 duration = spell->spell->GetSpellDuration();
  7588. rez->expire_timer->Start(duration * 100);
  7589. rez->hp_perc = hp_perc;
  7590. rez->mp_perc = power_perc;
  7591. rez->range = spell->spell->GetSpellData()->range;
  7592. rez->spell_name = spell->spell->GetName();
  7593. if (heal_name.length() > 0)
  7594. rez->heal_name = heal_name;
  7595. else
  7596. rez->heal_name = rez->spell_name;
  7597. rez->no_calcs = no_calcs;
  7598. rez->crit_mod = crit_mod;
  7599. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7600. if (send_window)
  7601. client->SendResurrectionWindow();
  7602. else {
  7603. target->GetZone()->ResurrectSpawn(target, client);
  7604. rez->should_delete = true;
  7605. }
  7606. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7607. }
  7608. return 0;
  7609. }
  7610. int EQ2Emu_lua_SetVision(lua_State* state) {
  7611. if (!lua_interface)
  7612. return 0;
  7613. Spawn* spawn = lua_interface->GetSpawn(state);
  7614. int8 vision = lua_interface->GetInt8Value(state, 2);
  7615. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7616. if (!spawn) {
  7617. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7618. return 0;
  7619. }
  7620. if (!spawn->IsEntity()) {
  7621. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7622. return 0;
  7623. }
  7624. if (spell && spell->targets.size() > 0) {
  7625. ZoneServer* zone = spell->caster->GetZone();
  7626. for (int8 i = 0; i < spell->targets.size(); i++) {
  7627. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7628. if (target && target->IsEntity()) {
  7629. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7630. if (target->IsPlayer())
  7631. ((Player*)target)->SetCharSheetChanged(true);
  7632. }
  7633. }
  7634. }
  7635. else {
  7636. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7637. if (spawn->IsPlayer())
  7638. ((Player*)spawn)->SetCharSheetChanged(true);
  7639. }
  7640. return 0;
  7641. }
  7642. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7643. if (!lua_interface)
  7644. return 0;
  7645. Spawn* spawn = lua_interface->GetSpawn(state);
  7646. float intensity = lua_interface->GetFloatValue(state, 2);
  7647. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7648. if (!spawn) {
  7649. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7650. return 0;
  7651. }
  7652. if (!spawn->IsEntity()) {
  7653. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7654. return 0;
  7655. }
  7656. if (spell && spell->targets.size() > 0) {
  7657. ZoneServer* zone = spell->caster->GetZone();
  7658. for (int8 i = 0; i < spell->targets.size(); i++) {
  7659. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7660. if (target && target->IsEntity()) {
  7661. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7662. if (target->IsPlayer())
  7663. ((Player*)target)->SetCharSheetChanged(true);
  7664. }
  7665. }
  7666. }
  7667. else {
  7668. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7669. if (spawn->IsPlayer())
  7670. ((Player*)spawn)->SetCharSheetChanged(true);
  7671. }
  7672. return 0;
  7673. }
  7674. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7675. if (!lua_interface)
  7676. return 0;
  7677. Spawn* spawn = lua_interface->GetSpawn(state);
  7678. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7679. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7680. if (!spawn) {
  7681. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7682. return 0;
  7683. }
  7684. if (!spawn->IsEntity()) {
  7685. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7686. return 0;
  7687. }
  7688. if (spell && spell->targets.size() > 0) {
  7689. ZoneServer* zone = spell->caster->GetZone();
  7690. for (int8 i = 0; i < spell->targets.size(); i++) {
  7691. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7692. if (target && target->IsEntity()) {
  7693. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7694. if (target->IsPlayer())
  7695. ((Player*)target)->SetCharSheetChanged(true);
  7696. }
  7697. }
  7698. }
  7699. else {
  7700. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7701. if (spawn->IsPlayer())
  7702. ((Player*)spawn)->SetCharSheetChanged(true);
  7703. }
  7704. return 0;
  7705. }
  7706. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7707. if (!lua_interface)
  7708. return 0;
  7709. Item* item = lua_interface->GetItem(state);
  7710. int8 type = lua_interface->GetInt32Value(state, 2);
  7711. if (!item) {
  7712. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7713. return 0;
  7714. }
  7715. if (type == 1)
  7716. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7717. else if (type == 2)
  7718. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7719. return 1;
  7720. }
  7721. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7722. if (!lua_interface)
  7723. return 0;
  7724. Spawn* target = lua_interface->GetSpawn(state);
  7725. float val = lua_interface->GetFloatValue(state, 2);
  7726. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7727. // Added from Gangrenous post
  7728. if (spell && spell->resisted)
  7729. return 0;
  7730. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7731. if (val > 1.0f)
  7732. val = 1.0f - (val / 100.0f);
  7733. if (spell && spell->spell && spell->targets.size() > 0) {
  7734. ZoneServer* zone = spell->caster->GetZone();
  7735. for (int32 i = 0; i != spell->targets.size(); i++) {
  7736. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7737. if (spawn && spawn->IsEntity()) {
  7738. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7739. if (spawn->IsPlayer())
  7740. ((Player*)spawn)->SetCharSheetChanged(true);
  7741. }
  7742. }
  7743. }
  7744. else {
  7745. if (target && target->IsEntity()) {
  7746. ((Entity*)target)->SetSpeedMultiplier(val);
  7747. if (target->IsPlayer())
  7748. ((Player*)target)->SetCharSheetChanged(true);
  7749. }
  7750. }
  7751. return 0;
  7752. }
  7753. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7754. if (!lua_interface)
  7755. return 0;
  7756. Spawn* spawn = lua_interface->GetSpawn(state);
  7757. int16 model = lua_interface->GetInt16Value(state, 2);
  7758. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7759. if (spell && spell->spell && spell->targets.size() > 0) {
  7760. ZoneServer* zone = spell->caster->GetZone();
  7761. for (int32 i = 0; i < spell->targets.size(); i++) {
  7762. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7763. if (target)
  7764. target->SetIllusionModel(model);
  7765. }
  7766. }
  7767. else {
  7768. if (!spawn) {
  7769. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7770. return 0;
  7771. }
  7772. spawn->SetIllusionModel(model);
  7773. }
  7774. return 0;
  7775. }
  7776. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7777. if (!lua_interface)
  7778. return 0;
  7779. Spawn* spawn = lua_interface->GetSpawn(state);
  7780. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7781. if (spell && spell->spell && spell->targets.size() > 0) {
  7782. ZoneServer* zone = spell->caster->GetZone();
  7783. for (int32 i = 0; i < spell->targets.size(); i++) {
  7784. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7785. if (target)
  7786. target->SetIllusionModel(0);
  7787. }
  7788. }
  7789. else {
  7790. if (!spawn) {
  7791. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7792. return 0;
  7793. }
  7794. spawn->SetIllusionModel(0);
  7795. }
  7796. return 0;
  7797. }
  7798. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7799. if (!lua_interface)
  7800. return 0;
  7801. Spawn* caster = lua_interface->GetSpawn(state);
  7802. Spawn* target = lua_interface->GetSpawn(state, 2);
  7803. float chance = lua_interface->GetFloatValue(state, 3);
  7804. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7805. if (!caster) {
  7806. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7807. return 0;
  7808. }
  7809. if (!caster->IsEntity()) {
  7810. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7811. return 0;
  7812. }
  7813. if (!target) {
  7814. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7815. return 0;
  7816. }
  7817. if (!target->IsEntity()) {
  7818. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7819. return 0;
  7820. }
  7821. if (chance <= 0) {
  7822. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7823. return 0;
  7824. }
  7825. if (!spell) {
  7826. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7827. return 0;
  7828. }
  7829. if (((Entity*)caster)->GetThreatTransfer()) {
  7830. return 0;
  7831. }
  7832. ThreatTransfer* transfer = new ThreatTransfer;
  7833. transfer->Target = target->GetID();
  7834. transfer->Amount = chance;
  7835. transfer->Spell = spell;
  7836. ((Entity*)caster)->SetThreatTransfer(transfer);
  7837. return 0;
  7838. }
  7839. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7840. if (!lua_interface)
  7841. return 0;
  7842. Spawn* spawn = lua_interface->GetSpawn(state);
  7843. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7844. if (!spawn) {
  7845. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7846. return 0;
  7847. }
  7848. if (!spell) {
  7849. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7850. return 0;
  7851. }
  7852. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7853. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7854. ((Entity*)spawn)->SetThreatTransfer(0);
  7855. safe_delete(transfer);
  7856. }
  7857. return 0;
  7858. }
  7859. int EQ2Emu_lua_CureByType(lua_State* state) {
  7860. if (!lua_interface)
  7861. return 0;
  7862. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7863. if (!spell) {
  7864. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7865. return 0;
  7866. }
  7867. int8 cure_count = lua_interface->GetInt8Value(state);
  7868. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7869. string cure_name = lua_interface->GetStringValue(state, 3);
  7870. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7871. Spawn* target = lua_interface->GetSpawn(state, 5);
  7872. if (target) {
  7873. if (!target->IsEntity()) {
  7874. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7875. return 0;
  7876. }
  7877. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7878. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7879. }
  7880. else {
  7881. ZoneServer* zone = spell->caster->GetZone();
  7882. vector<int32> targets = spell->targets;
  7883. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7884. for (int8 i = 0; i < targets.size(); i++) {
  7885. target = zone->GetSpawnByID(targets.at(i));
  7886. if (!target || !target->IsEntity())
  7887. continue;
  7888. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7889. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7890. }
  7891. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7892. }
  7893. return 0;
  7894. }
  7895. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7896. if (!lua_interface)
  7897. return 0;
  7898. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7899. if (!spell) {
  7900. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7901. return 0;
  7902. }
  7903. int8 cure_count = lua_interface->GetInt8Value(state);
  7904. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7905. string cure_name = lua_interface->GetStringValue(state, 3);
  7906. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7907. Spawn* target = lua_interface->GetSpawn(state, 5);
  7908. if (target) {
  7909. if (!target->IsEntity()) {
  7910. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7911. return 0;
  7912. }
  7913. if (((Entity*)target)->GetDetCount() > 0)
  7914. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7915. }
  7916. else {
  7917. ZoneServer* zone = spell->caster->GetZone();
  7918. vector<int32> targets = spell->targets;
  7919. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7920. for (int8 i = 0; i < targets.size(); i++) {
  7921. target = zone->GetSpawnByID(targets.at(i));
  7922. if (!target || !target->IsEntity())
  7923. continue;
  7924. if (((Entity*)target)->GetDetCount() > 0)
  7925. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7926. }
  7927. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7928. }
  7929. return 0;
  7930. }
  7931. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7932. if (!lua_interface)
  7933. return 0;
  7934. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7935. if (!spell) {
  7936. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7937. return 0;
  7938. }
  7939. if (!spell->caster) {
  7940. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7941. return 0;
  7942. }
  7943. if (!spell->caster->GetZone()) {
  7944. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7945. return 0;
  7946. }
  7947. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7948. return 0;
  7949. }
  7950. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7951. if (!lua_interface)
  7952. return 0;
  7953. Spawn* spawn = lua_interface->GetSpawn(state);
  7954. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7955. if (!spell) {
  7956. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7957. return 0;
  7958. }
  7959. if (spawn && spawn->IsEntity())
  7960. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7961. else {
  7962. ZoneServer* zone = spell->caster->GetZone();
  7963. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7964. for (int32 i = 0; i < spell->targets.size(); i++) {
  7965. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7966. if (!spawn || !spawn->IsEntity())
  7967. continue;
  7968. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7969. }
  7970. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7971. }
  7972. return 0;
  7973. }
  7974. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7975. if (!lua_interface)
  7976. return 0;
  7977. Spawn* spawn = lua_interface->GetSpawn(state);
  7978. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7979. if (!spell) {
  7980. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7981. return 0;
  7982. }
  7983. if (spawn && spawn->IsEntity())
  7984. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7985. else {
  7986. ZoneServer* zone = spell->caster->GetZone();
  7987. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7988. for (int32 i = 0; i < spell->targets.size(); i++) {
  7989. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7990. if (!spawn || !spawn->IsEntity())
  7991. continue;
  7992. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7993. }
  7994. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7995. }
  7996. return 0;
  7997. }
  7998. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7999. if (!lua_interface)
  8000. return 0;
  8001. Spawn* caster = lua_interface->GetSpawn(state);
  8002. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8003. if (!caster) {
  8004. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8005. return 0;
  8006. }
  8007. if (!caster->IsPlayer()) {
  8008. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8009. return 0;
  8010. }
  8011. Spawn* target = caster->GetTarget();
  8012. if (!target) {
  8013. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8014. return 0;
  8015. }
  8016. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8017. if (!client) {
  8018. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8019. return 0;
  8020. }
  8021. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8022. if (ho) {
  8023. ho->SetTarget(target->GetID());
  8024. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8025. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8026. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8027. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8028. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8029. deque<GroupMemberInfo*>::iterator itr;
  8030. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8031. if (group)
  8032. {
  8033. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8034. deque<GroupMemberInfo*>* members = group->GetMembers();
  8035. for (itr = members->begin(); itr != members->end(); itr++) {
  8036. if ((*itr)->client)
  8037. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8038. }
  8039. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8040. }
  8041. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8042. }
  8043. else
  8044. safe_delete(ho);
  8045. }
  8046. else {
  8047. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8048. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8049. }
  8050. else
  8051. safe_delete(ho);
  8052. }
  8053. }
  8054. return 0;
  8055. }
  8056. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8057. if (!lua_interface)
  8058. return 0;
  8059. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8060. if (!spell) {
  8061. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8062. return 0;
  8063. }
  8064. int16 triggerCount = lua_interface->GetInt16Value(state);
  8065. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8066. if (!triggerCount) {
  8067. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8068. return 0;
  8069. }
  8070. spell->num_triggers = triggerCount;
  8071. spell->had_triggers = true;
  8072. spell->cancel_after_all_triggers = cancel_after_triggers;
  8073. return 0;
  8074. }
  8075. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8076. if (!lua_interface)
  8077. return 0;
  8078. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8079. if (!spell) {
  8080. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8081. return 0;
  8082. }
  8083. lua_interface->SetInt32Value(state, spell->num_triggers);
  8084. return 1;
  8085. }
  8086. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8087. if (!lua_interface)
  8088. return 0;
  8089. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8090. if (!spell) {
  8091. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8092. return 0;
  8093. }
  8094. int16 remove_count = lua_interface->GetInt16Value(state);
  8095. if (!remove_count)
  8096. remove_count = 1;
  8097. if (remove_count >= spell->num_triggers) {
  8098. spell->num_triggers = 0;
  8099. if (spell->cancel_after_all_triggers)
  8100. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8101. }
  8102. else {
  8103. spell->num_triggers -= remove_count;
  8104. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8105. }
  8106. return 0;
  8107. }
  8108. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8109. if (!lua_interface)
  8110. return 0;
  8111. Spawn* spawn = lua_interface->GetSpawn(state);
  8112. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8113. if (!spawn) {
  8114. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8115. return 0;
  8116. }
  8117. if (!copy_spawn) {
  8118. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8119. return 0;
  8120. }
  8121. spawn->CopySpawnAppearance(copy_spawn);
  8122. return 0;
  8123. }
  8124. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8125. Spawn* spawn = lua_interface->GetSpawn(state);
  8126. int8 type = lua_interface->GetInt8Value(state, 2);
  8127. if (!spawn) {
  8128. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8129. return 0;
  8130. }
  8131. else if (!spawn->IsEntity()) {
  8132. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8133. return 0;
  8134. }
  8135. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8136. return 1;
  8137. }
  8138. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8139. if (!lua_interface)
  8140. return 0;
  8141. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8142. int8 type = lua_interface->GetInt8Value(state);
  8143. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8144. if (!spell) {
  8145. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8146. return 0;
  8147. }
  8148. if (spawn) {
  8149. if (!spawn->IsEntity()) {
  8150. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8151. return 0;
  8152. }
  8153. Entity* entity = ((Entity*)spawn);
  8154. entity->AddImmunity(spell, type);
  8155. }
  8156. else {
  8157. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8158. for (int8 i = 0; i < spell->targets.size(); i++) {
  8159. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8160. if (!spawn || !spawn->IsEntity())
  8161. continue;
  8162. Entity* entity = ((Entity*)spawn);
  8163. entity->AddImmunity(spell, type);
  8164. }
  8165. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8166. }
  8167. return 0;
  8168. }
  8169. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8170. if (!lua_interface)
  8171. return 0;
  8172. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8173. int8 type = lua_interface->GetInt8Value(state);
  8174. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8175. if (!spell) {
  8176. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8177. return 0;
  8178. }
  8179. if (spawn) {
  8180. if (!spawn->IsEntity()) {
  8181. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8182. return 0;
  8183. }
  8184. Entity* entity = ((Entity*)spawn);
  8185. entity->RemoveImmunity(spell, type);
  8186. }
  8187. else {
  8188. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8189. for (int8 i = 0; i < spell->targets.size(); i++) {
  8190. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8191. if (!spawn || !spawn->IsEntity())
  8192. continue;
  8193. Entity* entity = ((Entity*)spawn);
  8194. entity->RemoveImmunity(spell, type);
  8195. }
  8196. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8197. }
  8198. return 0;
  8199. }
  8200. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8201. if (!lua_interface)
  8202. return 0;
  8203. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8204. if (!spell) {
  8205. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8206. return 0;
  8207. }
  8208. float snare = lua_interface->GetFloatValue(state);
  8209. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8210. // convert the val to the speed multipler value (100 - val)
  8211. float val = 100.0 - snare;
  8212. val /= 100.0;
  8213. if (spawn) {
  8214. if (!spawn->IsEntity()) {
  8215. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8216. return 0;
  8217. }
  8218. ((Entity*)spawn)->SetSnareValue(spell, val);
  8219. }
  8220. else {
  8221. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8222. for (int8 i = 0; i < spell->targets.size(); i++) {
  8223. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8224. if (!spawn || !spawn->IsEntity())
  8225. continue;
  8226. ((Entity*)spawn)->SetSnareValue(spell, val);
  8227. }
  8228. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8229. }
  8230. return 0;
  8231. }
  8232. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8233. if (!lua_interface)
  8234. return 0;
  8235. Spawn* spawn = lua_interface->GetSpawn(state);
  8236. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8237. if (!spawn) {
  8238. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8239. return 0;
  8240. }
  8241. if (race_id == 0) {
  8242. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8243. return 0;
  8244. }
  8245. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8246. return 1;
  8247. }
  8248. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8249. if (!lua_interface)
  8250. return 0;
  8251. Spawn* spawn = lua_interface->GetSpawn(state);
  8252. if (!spawn) {
  8253. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8254. return 0;
  8255. }
  8256. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8257. return 1;
  8258. }
  8259. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8260. if (!lua_interface)
  8261. return 0;
  8262. Spawn* spawn = lua_interface->GetSpawn(state);
  8263. if (!spawn) {
  8264. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8265. return 0;
  8266. }
  8267. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8268. return 1;
  8269. }
  8270. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8271. if (!lua_interface)
  8272. return 0;
  8273. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8274. if (!spell) {
  8275. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8276. return 0;
  8277. }
  8278. lua_interface->SetStringValue(state, spell->spell->GetName());
  8279. return 1;
  8280. }
  8281. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8282. if (!lua_interface)
  8283. return 0;
  8284. Quest* quest = lua_interface->GetQuest(state);
  8285. if (!quest) {
  8286. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8287. return 0;
  8288. }
  8289. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8290. return 1;
  8291. }
  8292. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8293. if (!lua_interface)
  8294. return 0;
  8295. Quest* quest = lua_interface->GetQuest(state);
  8296. int32 flags = lua_interface->GetInt32Value(state, 2);
  8297. if (!quest) {
  8298. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8299. return 0;
  8300. }
  8301. quest->SetQuestFlags(flags);
  8302. return 0;
  8303. }
  8304. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8305. if (!lua_interface)
  8306. return 0;
  8307. Quest* quest = lua_interface->GetQuest(state);
  8308. Spawn* player = lua_interface->GetSpawn(state, 2);
  8309. int32 step = lua_interface->GetInt32Value(state, 3);
  8310. int32 duration = lua_interface->GetInt32Value(state, 4);
  8311. string action = lua_interface->GetStringValue(state, 5);
  8312. if (!quest) {
  8313. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8314. return 0;
  8315. }
  8316. if (!player) {
  8317. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8318. return 0;
  8319. }
  8320. if (!player->IsPlayer()) {
  8321. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. if (step == 0) {
  8325. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. if (duration == 0) {
  8329. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8330. return 0;
  8331. }
  8332. if (action.length() == 0) {
  8333. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8334. return 0;
  8335. }
  8336. Client* client = player->GetZone()->GetClientBySpawn(player);
  8337. if (!client) {
  8338. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8339. return 0;
  8340. }
  8341. quest->SetTimerStep(step);
  8342. quest->AddFailedAction(step, action);
  8343. quest->SetStepTimer(duration);
  8344. client->AddQuestTimer(quest->GetQuestID());
  8345. return 0;
  8346. }
  8347. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8348. if (!lua_interface)
  8349. return 0;
  8350. Quest* quest = lua_interface->GetQuest(state);
  8351. Spawn* player = lua_interface->GetSpawn(state, 2);
  8352. if (!quest) {
  8353. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8354. return 0;
  8355. }
  8356. if (!player) {
  8357. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8358. return 0;
  8359. }
  8360. if (!player->IsPlayer()) {
  8361. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8362. return 0;
  8363. }
  8364. Client* client = player->GetZone()->GetClientBySpawn(player);
  8365. if (!client) {
  8366. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8367. return 0;
  8368. }
  8369. quest->SetTimerStep(0);
  8370. quest->SetStepTimer(0);
  8371. client->RemoveQuestTimer(quest->GetQuestID());
  8372. return 0;
  8373. }
  8374. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8375. if (!lua_interface)
  8376. return 0;
  8377. Spawn* player = lua_interface->GetSpawn(state);
  8378. Quest* quest = lua_interface->GetQuest(state, 2);
  8379. int32 step = lua_interface->GetInt32Value(state, 3);
  8380. if (!player) {
  8381. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8382. return 0;
  8383. }
  8384. if (!player->IsPlayer()) {
  8385. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8386. return 0;
  8387. }
  8388. if (!quest) {
  8389. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8390. return 0;
  8391. }
  8392. if (step == 0) {
  8393. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8394. return 0;
  8395. }
  8396. Client* client = player->GetZone()->GetClientBySpawn(player);
  8397. if (!client) {
  8398. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8399. return 0;
  8400. }
  8401. if (quest->RemoveQuestStep(step, client)) {
  8402. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8403. client->GetCurrentZone()->SendQuestUpdates(client);
  8404. }
  8405. else
  8406. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8407. return 0;
  8408. }
  8409. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8410. if (!lua_interface)
  8411. return 0;
  8412. Quest* quest = lua_interface->GetQuest(state, 1);
  8413. int32 step = lua_interface->GetInt32Value(state, 2);
  8414. string desc = lua_interface->GetStringValue(state, 3);
  8415. string task_group = lua_interface->GetStringValue(state, 4);
  8416. if (!quest) {
  8417. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8418. return 0;
  8419. }
  8420. if (step == 0) {
  8421. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8422. return 0;
  8423. }
  8424. QuestStep* quest_step = quest->GetQuestStep(step);
  8425. if (!quest_step) {
  8426. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8427. return 0;
  8428. }
  8429. quest_step->SetStepProgress(0);
  8430. quest_step->SetTaskGroup(task_group);
  8431. quest_step->SetDescription(desc);
  8432. return 0;
  8433. }
  8434. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8435. if (!lua_interface)
  8436. return 0;
  8437. Quest* quest = lua_interface->GetQuest(state);
  8438. int32 step = lua_interface->GetInt32Value(state, 2);
  8439. string action = lua_interface->GetStringValue(state, 3);
  8440. if (!quest) {
  8441. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8442. return 0;
  8443. }
  8444. if (step == 0) {
  8445. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8446. return 0;
  8447. }
  8448. if (action.length() == 0) {
  8449. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8450. return 0;
  8451. }
  8452. quest->AddFailedAction(step, action);
  8453. return 0;
  8454. }
  8455. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8456. if (!lua_interface)
  8457. return 0;
  8458. Spawn* player = lua_interface->GetSpawn(state);
  8459. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8460. int32 step = lua_interface->GetInt32Value(state, 3);
  8461. if (!player) {
  8462. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8463. return 0;
  8464. }
  8465. if (!player->IsPlayer()) {
  8466. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8467. return 0;
  8468. }
  8469. if (quest_id == 0) {
  8470. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8471. return 0;
  8472. }
  8473. if (step == 0) {
  8474. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8475. return 0;
  8476. }
  8477. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8478. if (!quest) {
  8479. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8480. return 0;
  8481. }
  8482. quest->StepFailed(step);
  8483. return 0;
  8484. }
  8485. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8486. if (!lua_interface)
  8487. return 0;
  8488. Spawn* player = lua_interface->GetSpawn(state);
  8489. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8490. if (!player) {
  8491. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8492. return 0;
  8493. }
  8494. if (!player->IsPlayer()) {
  8495. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8496. return 0;
  8497. }
  8498. if (quest_id == 0) {
  8499. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8500. return 0;
  8501. }
  8502. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8503. if (!quest) {
  8504. lua_interface->SetInt32Value(state, 0);
  8505. return 1;
  8506. }
  8507. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8508. return 1;
  8509. }
  8510. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8511. if (!lua_interface)
  8512. return 0;
  8513. string name = lua_interface->GetStringValue(state);
  8514. string value = lua_interface->GetStringValue(state, 2);
  8515. string comment = lua_interface->GetStringValue(state, 3);
  8516. if (name.length() == 0) {
  8517. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8518. return 0;
  8519. }
  8520. if (value.length() == 0) {
  8521. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8522. return 0;
  8523. }
  8524. string varname = string("lua_").append(name);
  8525. Variable* var = variables.FindVariable(varname);
  8526. if (var)
  8527. var->SetValue(value.c_str());
  8528. else {
  8529. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8530. variables.AddVariable(var);
  8531. }
  8532. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8533. return 0;
  8534. }
  8535. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8536. if (!lua_interface)
  8537. return 0;
  8538. string name = lua_interface->GetStringValue(state);
  8539. if (name.length() == 0) {
  8540. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8541. return 0;
  8542. }
  8543. string varname = string("lua_").append(name);
  8544. Variable* var = variables.FindVariable(varname);
  8545. if (var)
  8546. lua_interface->SetStringValue(state, var->GetValue());
  8547. else
  8548. lua_interface->SetStringValue(state, "NULL");
  8549. return 1;
  8550. }
  8551. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8552. if (!lua_interface)
  8553. return 0;
  8554. Spawn* player = lua_interface->GetSpawn(state);
  8555. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8556. if (!player) {
  8557. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8558. return 0;
  8559. }
  8560. if (!player->IsPlayer()) {
  8561. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8562. return 0;
  8563. }
  8564. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8565. return 1;
  8566. }
  8567. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8568. if (!lua_interface)
  8569. return 0;
  8570. Spawn* player = lua_interface->GetSpawn(state);
  8571. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8572. if (!player) {
  8573. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8574. return 0;
  8575. }
  8576. if (!player->IsPlayer()) {
  8577. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8578. return 0;
  8579. }
  8580. Language* language = master_languages_list.GetLanguage(language_id);
  8581. if (language)
  8582. {
  8583. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8584. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8585. }
  8586. return 0;
  8587. }
  8588. int EQ2Emu_lua_IsNight(lua_State* state) {
  8589. if (!lua_interface)
  8590. return 0;
  8591. ZoneServer* zone = lua_interface->GetZone(state);
  8592. if (!zone) {
  8593. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8594. return 0;
  8595. }
  8596. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8597. return 1;
  8598. }
  8599. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8600. if (!lua_interface)
  8601. return 0;
  8602. Spawn* spawn = lua_interface->GetSpawn(state);
  8603. if (!spawn) {
  8604. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8605. return 0;
  8606. }
  8607. if (!spawn->IsWidget()) {
  8608. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8609. return 0;
  8610. }
  8611. ((Widget*)spawn)->SetMultiFloorLift(true);
  8612. if (spawn->GetZone())
  8613. spawn->GetZone()->AddTransportSpawn(spawn);
  8614. return 0;
  8615. }
  8616. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8617. if (!lua_interface)
  8618. return 0;
  8619. Spawn* player = lua_interface->GetSpawn(state);
  8620. int32 path = lua_interface->GetInt32Value(state, 2);
  8621. if (!player) {
  8622. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8623. return 0;
  8624. }
  8625. if (!player->IsPlayer()) {
  8626. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8627. return 0;
  8628. }
  8629. if (path == 0) {
  8630. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8631. return 0;
  8632. }
  8633. Client* client = player->GetZone()->GetClientBySpawn(player);
  8634. if (!client) {
  8635. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8636. return 0;
  8637. }
  8638. client->SendFlightAutoMount(path);
  8639. return 0;
  8640. }
  8641. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8642. if (!lua_interface)
  8643. return 0;
  8644. Spawn* player = lua_interface->GetSpawn(state);
  8645. if (!player) {
  8646. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8647. return 0;
  8648. }
  8649. if (!player->IsPlayer()) {
  8650. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8651. return 0;
  8652. }
  8653. Client* client = player->GetZone()->GetClientBySpawn(player);
  8654. if (!client) {
  8655. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8656. return 0;
  8657. }
  8658. client->EndAutoMount();
  8659. return 0;
  8660. }
  8661. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8662. if (!lua_interface)
  8663. return 0;
  8664. Spawn* player = lua_interface->GetSpawn(state);
  8665. if (!player) {
  8666. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. if (!player->IsPlayer()) {
  8670. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8671. return 0;
  8672. }
  8673. Client* client = player->GetZone()->GetClientBySpawn(player);
  8674. if (!client) {
  8675. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8676. return 0;
  8677. }
  8678. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8679. return 1;
  8680. }
  8681. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8682. if (!lua_interface)
  8683. return 0;
  8684. Spawn* player = lua_interface->GetSpawn(state);
  8685. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8686. int32 value = lua_interface->GetInt32Value(state, 3);
  8687. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8688. if (!player) {
  8689. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8690. return 0;
  8691. }
  8692. if (!player->IsPlayer()) {
  8693. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8694. return 0;
  8695. }
  8696. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8697. return 0;
  8698. }
  8699. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8700. if (!lua_interface)
  8701. return 0;
  8702. Spawn* player = lua_interface->GetSpawn(state);
  8703. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8704. if (!player) {
  8705. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8706. return 0;
  8707. }
  8708. if (!player->IsPlayer()) {
  8709. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8710. return 0;
  8711. }
  8712. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8713. if (!hd)
  8714. return 0;
  8715. lua_interface->SetInt32Value(state, hd->Value);
  8716. lua_interface->SetInt32Value(state, hd->Value2);
  8717. return 2;
  8718. }
  8719. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8720. if (!lua_interface)
  8721. return 0;
  8722. Spawn* spawn = lua_interface->GetSpawn(state);
  8723. int32 grid = lua_interface->GetInt32Value(state, 2);
  8724. if (!spawn) {
  8725. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8726. return 0;
  8727. }
  8728. if (grid == 0) {
  8729. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8730. return 0;
  8731. }
  8732. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8733. return 0;
  8734. }
  8735. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8736. if (!lua_interface)
  8737. return 0;
  8738. Spawn* spawn = lua_interface->GetSpawn(state);
  8739. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8740. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8741. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8742. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8743. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8744. if (!spawn) {
  8745. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8746. return 0;
  8747. }
  8748. //Add this quest to the list of required quests for this spawn
  8749. spawn->SetRequiredHistory(event_id, value1, value2);
  8750. //If private spawn value set
  8751. if (private_spawn) {
  8752. //Set the spawn to be private when not granted access via history
  8753. spawn->AddAllowAccessSpawn(spawn);
  8754. spawn->SetPrivateQuestSpawn(true);
  8755. }
  8756. //This value will override vis_flags in the vis packet
  8757. if (flag_override > 0)
  8758. spawn->SetQuestsRequiredOverride(flag_override);
  8759. return 0;
  8760. }
  8761. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8762. if (!lua_interface)
  8763. return 0;
  8764. Spawn* player = lua_interface->GetSpawn(state);
  8765. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8766. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8767. if (!player) {
  8768. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8769. return 0;
  8770. }
  8771. if (!player->IsPlayer()) {
  8772. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8773. return 0;
  8774. }
  8775. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8776. return 1;
  8777. }
  8778. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8779. if (!lua_interface)
  8780. return 0;
  8781. Spawn* player = lua_interface->GetSpawn(state);
  8782. int8 level = lua_interface->GetInt8Value(state, 2);
  8783. if (!player) {
  8784. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8785. return 0;
  8786. }
  8787. if (!player->IsPlayer()) {
  8788. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8789. return 0;
  8790. }
  8791. if (level == 0) {
  8792. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8793. return 0;
  8794. }
  8795. Client* client = player->GetZone()->GetClientBySpawn(player);
  8796. if (!client) {
  8797. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8798. return 0;
  8799. }
  8800. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8801. return 0;
  8802. }
  8803. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8804. if (!lua_interface)
  8805. return 0;
  8806. Spawn* player = lua_interface->GetSpawn(state);
  8807. int32 amount = lua_interface->GetInt32Value(state, 2);
  8808. if (!player) {
  8809. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8810. return 0;
  8811. }
  8812. if (!player->IsPlayer()) {
  8813. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8814. return 0;
  8815. }
  8816. if (amount == 0) {
  8817. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8818. return 0;
  8819. }
  8820. ((Player*)player)->AddCoins(amount);
  8821. return 0;
  8822. }
  8823. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8824. if (!lua_interface)
  8825. return 0;
  8826. Spawn* player = lua_interface->GetSpawn(state);
  8827. int32 amount = lua_interface->GetInt32Value(state, 2);
  8828. if (!player) {
  8829. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8830. return 0;
  8831. }
  8832. if (!player->IsPlayer()) {
  8833. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8834. return 0;
  8835. }
  8836. if (amount == 0) {
  8837. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8838. return 0;
  8839. }
  8840. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8841. return 1;
  8842. }
  8843. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8844. if (!lua_interface)
  8845. return 0;
  8846. ZoneServer* zone = lua_interface->GetZone(state);
  8847. if (!zone) {
  8848. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8849. return 0;
  8850. }
  8851. vector<Entity*> players = zone->GetPlayers();
  8852. if (players.size() == 0)
  8853. return 0;
  8854. lua_createtable(state, players.size(), 0);
  8855. int newTable = lua_gettop(state);
  8856. for (int32 i = 0; i < players.size(); i++) {
  8857. lua_interface->SetSpawnValue(state, players.at(i));
  8858. lua_rawseti(state, newTable, i + 1);
  8859. }
  8860. return 1;
  8861. }
  8862. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8863. if (!lua_interface)
  8864. return 0;
  8865. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8866. if (!zone) {
  8867. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8868. return 0;
  8869. }
  8870. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8871. //Map of <placement_id, location_id>
  8872. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8873. map<int32, int32>::iterator itr;
  8874. vector<Spawn*> group;
  8875. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8876. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8877. if (!location) {
  8878. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8879. return 0;
  8880. }
  8881. Spawn* spawn = 0;
  8882. if (location->entities[0]) {
  8883. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8884. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8885. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8886. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8887. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8888. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8889. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8890. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8891. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8892. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8893. if(spawn && spawn->IsOmittedByDBFlag())
  8894. {
  8895. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  8896. safe_delete(spawn);
  8897. continue;
  8898. }
  8899. if (spawn) {
  8900. const char* script = 0;
  8901. for (int x = 0; x < 3; x++) {
  8902. switch (x) {
  8903. case 0:
  8904. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8905. break;
  8906. case 1:
  8907. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8908. break;
  8909. case 2:
  8910. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8911. break;
  8912. }
  8913. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8914. spawn->SetSpawnScript(string(script));
  8915. break;
  8916. }
  8917. }
  8918. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8919. lua_interface->SetSpawnValue(state, spawn);
  8920. group.push_back(spawn);
  8921. }
  8922. else {
  8923. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  8924. safe_delete(spawn);
  8925. }
  8926. }
  8927. }
  8928. if (!group.empty()) {
  8929. lua_createtable(state, group.size(), 0);
  8930. int newTable = lua_gettop(state);
  8931. for (int32 i = 0; i < group.size(); i++) {
  8932. lua_interface->SetSpawnValue(state, group[i]);
  8933. lua_rawseti(state, newTable, i + 1);
  8934. }
  8935. }
  8936. else
  8937. lua_pushnil(state);
  8938. return 1;
  8939. }
  8940. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8941. if (!lua_interface)
  8942. return 0;
  8943. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8944. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8945. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8946. if (!spawn) {
  8947. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8948. return 0;
  8949. }
  8950. if (anim_id == 0) {
  8951. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8952. return 0;
  8953. }
  8954. if (leeway == 0)
  8955. leeway = 5000;
  8956. spawn->SetSpawnAnim(anim_id);
  8957. spawn->SetSpawnAnimLeeway(leeway);
  8958. return 0;
  8959. }
  8960. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8961. if (!lua_interface)
  8962. return 0;
  8963. Spawn* player = lua_interface->GetSpawn(state);
  8964. if (!player) {
  8965. return 0;
  8966. }
  8967. Client* client = player->GetZone()->GetClientBySpawn(player);
  8968. if (!client) {
  8969. return 0;
  8970. }
  8971. lua_interface->SetInt32Value(state, client->GetVersion());
  8972. return 1;
  8973. }
  8974. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8975. if (!lua_interface)
  8976. return 0;
  8977. Item* item = lua_interface->GetItem(state);
  8978. if (!item) {
  8979. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8980. return 0;
  8981. }
  8982. lua_interface->SetInt32Value(state, item->details.item_id);
  8983. return 1;
  8984. }
  8985. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8986. if (!lua_interface)
  8987. return 0;
  8988. Spawn* spawn = lua_interface->GetSpawn(state);
  8989. if (!spawn) {
  8990. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8991. return 0;
  8992. }
  8993. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8994. return 1;
  8995. }
  8996. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8997. if (!lua_interface)
  8998. return 0;
  8999. Spawn* spawn = lua_interface->GetSpawn(state);
  9000. if (!spawn) {
  9001. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9002. return 0;
  9003. }
  9004. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9005. return 1;
  9006. }
  9007. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9008. if (!lua_interface)
  9009. return 0;
  9010. Spawn* spawn = lua_interface->GetSpawn(state);
  9011. if (!spawn) {
  9012. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9013. return 0;
  9014. }
  9015. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9016. return 1;
  9017. }
  9018. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9019. if (!lua_interface)
  9020. return 0;
  9021. Spawn* spawn = lua_interface->GetSpawn(state);
  9022. if (!spawn) {
  9023. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9024. return 0;
  9025. }
  9026. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9027. return 1;
  9028. }
  9029. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9030. if (!lua_interface)
  9031. return 0;
  9032. Spawn* spawn = lua_interface->GetSpawn(state);
  9033. float pct = lua_interface->GetFloatValue(state, 2);
  9034. if (!spawn) {
  9035. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9036. return 0;
  9037. }
  9038. if (pct == 0) {
  9039. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9040. return 0;
  9041. }
  9042. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9043. lua_interface->SetInt32Value(state, amount);
  9044. return 1;
  9045. }
  9046. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9047. if (!lua_interface)
  9048. return 0;
  9049. Spawn* spawn = lua_interface->GetSpawn(state);
  9050. float pct = lua_interface->GetFloatValue(state, 2);
  9051. if (!spawn) {
  9052. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9053. return 0;
  9054. }
  9055. if (pct == 0) {
  9056. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9057. return 0;
  9058. }
  9059. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9060. lua_interface->SetInt32Value(state, amount);
  9061. return 1;
  9062. }
  9063. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9064. if (!lua_interface)
  9065. return 0;
  9066. Spawn* spawn = lua_interface->GetSpawn(state);
  9067. if (!spawn) {
  9068. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9069. return 0;
  9070. }
  9071. if (!spawn->IsPlayer()) {
  9072. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9073. return 0;
  9074. }
  9075. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9076. return 1;
  9077. }
  9078. int EQ2Emu_lua_Evac(lua_State* state) {
  9079. if (!lua_interface)
  9080. return 0;
  9081. Spawn* target = lua_interface->GetSpawn(state);
  9082. if (target) {
  9083. float x = target->GetZone()->GetSafeX();
  9084. float y = target->GetZone()->GetSafeY();
  9085. float z = target->GetZone()->GetSafeZ();
  9086. float h = target->GetZone()->GetSafeHeading();
  9087. target->SetX(x);
  9088. target->SetY(y);
  9089. target->SetZ(z);
  9090. target->SetHeading(h);
  9091. target->SetSpawnOrigX(x);
  9092. target->SetSpawnOrigY(y);
  9093. target->SetSpawnOrigZ(z);
  9094. target->SetSpawnOrigHeading(h);
  9095. if (target->IsPlayer()) {
  9096. Client* client = target->GetZone()->GetClientBySpawn(target);
  9097. if (client) {
  9098. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9099. client->SetReloadingZone(true);
  9100. target->SetX(x);
  9101. target->SetY(y);
  9102. target->SetZ(z);
  9103. target->SetHeading(h);
  9104. target->SetSpawnOrigX(x);
  9105. target->SetSpawnOrigY(y);
  9106. target->SetSpawnOrigZ(z);
  9107. target->SetSpawnOrigHeading(h);
  9108. target->SetAppearancePosition(x,y,z);
  9109. client->SetZoningCoords(x,y,z,h);
  9110. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9111. if (packet)
  9112. {
  9113. packet->setDataByName("x", x);
  9114. packet->setDataByName("y", y);
  9115. packet->setDataByName("z", z);
  9116. client->QueuePacket(packet->serialize());
  9117. safe_delete(packet);
  9118. }
  9119. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9120. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9121. }
  9122. }
  9123. }
  9124. else {
  9125. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9126. ZoneServer* zone = spell->caster->GetZone();
  9127. float x = spell->caster->GetZone()->GetSafeX();
  9128. float y = spell->caster->GetZone()->GetSafeY();
  9129. float z = spell->caster->GetZone()->GetSafeZ();
  9130. float h = spell->caster->GetZone()->GetSafeHeading();
  9131. int numargs = lua_interface->GetNumberOfArgs(state);
  9132. if(numargs == 4) {
  9133. x = lua_interface->GetFloatValue(state,1);
  9134. y = lua_interface->GetFloatValue(state,2);
  9135. z = lua_interface->GetFloatValue(state,3);
  9136. h = lua_interface->GetFloatValue(state,4);
  9137. }
  9138. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9139. for (int32 i = 0; i < spell->targets.size(); i++) {
  9140. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9141. if (!target2)
  9142. continue;
  9143. if (target2->IsPlayer()) {
  9144. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9145. if (client) {
  9146. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9147. client->SetReloadingZone(true);
  9148. target2->SetX(x);
  9149. target2->SetY(y);
  9150. target2->SetZ(z);
  9151. target2->SetHeading(h);
  9152. target2->SetSpawnOrigX(x);
  9153. target2->SetSpawnOrigY(y);
  9154. target2->SetSpawnOrigZ(z);
  9155. target2->SetSpawnOrigHeading(h);
  9156. target2->SetAppearancePosition(x,y,z);
  9157. client->SetZoningCoords(x,y,z,h);
  9158. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9159. if (packet)
  9160. {
  9161. packet->setDataByName("x", x);
  9162. packet->setDataByName("y", y);
  9163. packet->setDataByName("z", z);
  9164. client->QueuePacket(packet->serialize());
  9165. safe_delete(packet);
  9166. }
  9167. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9168. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9169. }
  9170. }
  9171. }
  9172. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9173. }
  9174. return 0;
  9175. }
  9176. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9177. if (!lua_interface)
  9178. return 0;
  9179. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9180. if (!luaspell) {
  9181. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9182. return 0;
  9183. }
  9184. int8 tier = luaspell->spell->GetSpellTier();
  9185. lua_interface->SetInt32Value(state, tier);
  9186. return 1;
  9187. }
  9188. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9189. if (!lua_interface)
  9190. return 0;
  9191. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9192. if (!luaspell) {
  9193. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9194. return 0;
  9195. }
  9196. int32 spell_id = luaspell->spell->GetSpellID();
  9197. lua_interface->SetInt32Value(state, spell_id);
  9198. return 1;
  9199. }
  9200. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9201. if (!lua_interface)
  9202. return 0;
  9203. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9204. if (!spawn) {
  9205. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9206. return 0;
  9207. }
  9208. if (!spawn->IsPlayer()) {
  9209. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9210. return 0;
  9211. }
  9212. ZoneServer* zone = spawn->GetZone();
  9213. if (!zone) {
  9214. return 0;
  9215. }
  9216. Client* client = zone->GetClientBySpawn(spawn);
  9217. if (!client) {
  9218. return 0;
  9219. }
  9220. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9221. return 0;
  9222. }
  9223. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9224. if (!lua_interface)
  9225. return 0;
  9226. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9227. if (!spawn) {
  9228. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9229. return 0;
  9230. }
  9231. if (!spawn->IsPlayer()) {
  9232. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9233. return 0;
  9234. }
  9235. ZoneServer* zone = spawn->GetZone();
  9236. if (!zone) {
  9237. return 0;
  9238. }
  9239. Client* client = zone->GetClientBySpawn(spawn);
  9240. if (!client) {
  9241. return 0;
  9242. }
  9243. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9244. return 0;
  9245. }
  9246. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9247. if (!lua_interface)
  9248. return 0;
  9249. Spawn* caster = lua_interface->GetSpawn(state);
  9250. Spawn* target = lua_interface->GetSpawn(state, 2);
  9251. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9252. string spell_name = lua_interface->GetStringValue(state, 4);
  9253. if (!caster) {
  9254. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9255. return 0;
  9256. }
  9257. if (!caster->IsEntity()) {
  9258. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9259. return 0;
  9260. }
  9261. if (!target) {
  9262. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9263. return 0;
  9264. }
  9265. if (!target->IsEntity()) {
  9266. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9267. return 0;
  9268. }
  9269. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9270. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9271. return 0;
  9272. }
  9273. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9274. if (!lua_interface)
  9275. return 0;
  9276. Spawn* player = lua_interface->GetSpawn(state);
  9277. int32 amount = lua_interface->GetInt32Value(state, 2);
  9278. if (player && player->IsPlayer() && amount > 0) {
  9279. ((Player*)player)->AddXP(amount);
  9280. ((Player*)player)->SetCharSheetChanged(true);
  9281. Client* client = player->GetZone()->GetClientBySpawn(player);
  9282. if (client) {
  9283. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9284. }
  9285. }
  9286. return 0;
  9287. }
  9288. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9289. if (!lua_interface)
  9290. return 0;
  9291. Spawn* player = lua_interface->GetSpawn(state);
  9292. int8 type = lua_interface->GetInt8Value(state, 2);
  9293. string text = lua_interface->GetStringValue(state, 3);
  9294. Client* client = 0;
  9295. if (player && player->IsPlayer())
  9296. client = player->GetZone()->GetClientBySpawn(player);
  9297. if (!client || text.length() == 0) {
  9298. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9299. return 0;
  9300. }
  9301. client->SimpleMessage(type, text.c_str());
  9302. return 0;
  9303. }
  9304. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9305. if (!lua_interface)
  9306. return 0;
  9307. Spawn* player = lua_interface->GetSpawn(state);
  9308. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9309. Client* client = 0;
  9310. if (player && player->IsPlayer())
  9311. client = player->GetZone()->GetClientBySpawn(player);
  9312. if (!client || !spawn) {
  9313. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9314. return 0;
  9315. }
  9316. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9317. if (!items) {
  9318. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9319. return 0;
  9320. }
  9321. client->Loot(spawn->GetLootCoins(), items, spawn);
  9322. return 0;
  9323. }
  9324. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9325. if (!lua_interface)
  9326. return 0;
  9327. Spawn* spawnref = lua_interface->GetSpawn(state);
  9328. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9329. if (spawn_id > 0 && spawnref) {
  9330. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9331. if (spawns.size() == 0) {
  9332. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9333. return 0;
  9334. }
  9335. Spawn* spawn = 0;
  9336. int16 index = MakeRandomInt(0, spawns.size());
  9337. if (index >= spawns.size() || index < 0)
  9338. index = 0;
  9339. spawn = spawns[index];
  9340. lua_interface->SetSpawnValue(state, spawn);
  9341. return 1;
  9342. }
  9343. else {
  9344. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9345. }
  9346. return 0;
  9347. }
  9348. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9349. Spawn* player = lua_interface->GetSpawn(state);
  9350. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9351. string name = lua_interface->GetStringValue(state, 3);
  9352. float distance = lua_interface->GetFloatValue(state, 4);
  9353. string command = lua_interface->GetStringValue(state, 5);
  9354. string error_text = lua_interface->GetStringValue(state, 6);
  9355. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9356. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9357. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9358. if (distance == 0)
  9359. distance = 10.0f;
  9360. if (command.length() == 0)
  9361. command = name;
  9362. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9363. if (spawns.size() == 0) {
  9364. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9365. return 0;
  9366. }
  9367. Spawn* spawn = 0;
  9368. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9369. spawn = *itr;
  9370. if (spawn) {
  9371. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9372. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9373. }
  9374. }
  9375. }
  9376. return 0;
  9377. }
  9378. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9379. if (!lua_interface)
  9380. return 0;
  9381. Client* client = 0;
  9382. Spawn* player = lua_interface->GetSpawn(state);
  9383. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9384. if (player && player->IsPlayer() && player->GetZone())
  9385. client = player->GetZone()->GetClientBySpawn(player);
  9386. else{
  9387. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9388. return 0;
  9389. }
  9390. if (client) {
  9391. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9392. if (packet) {
  9393. packet->setDataByName("goal_num", goal_num);
  9394. client->QueuePacket(packet->serialize());
  9395. safe_delete(packet);
  9396. }
  9397. }
  9398. return 0;
  9399. }
  9400. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9401. if (!lua_interface)
  9402. return 0;
  9403. Client* client = 0;
  9404. Spawn* player = lua_interface->GetSpawn(state);
  9405. if (player && player->IsPlayer() && player->GetZone())
  9406. client = player->GetZone()->GetClientBySpawn(player);
  9407. else {
  9408. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9409. return 0;
  9410. }
  9411. if (client) {
  9412. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9413. }
  9414. return 0;
  9415. }
  9416. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9417. if (!lua_interface)
  9418. return 0;
  9419. Client* client = 0;
  9420. Spawn* player = lua_interface->GetSpawn(state);
  9421. float duration = lua_interface->GetFloatValue(state, 2);
  9422. string text = lua_interface->GetStringValue(state, 3);
  9423. string voice = lua_interface->GetStringValue(state, 4);
  9424. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9425. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9426. string signal = lua_interface->GetStringValue(state, 7);
  9427. string goal1 = lua_interface->GetStringValue(state, 8);
  9428. string task1 = lua_interface->GetStringValue(state, 9);
  9429. string goal2 = lua_interface->GetStringValue(state, 10);
  9430. string task2 = lua_interface->GetStringValue(state, 11);
  9431. string goal3 = lua_interface->GetStringValue(state, 12);
  9432. string task3 = lua_interface->GetStringValue(state, 13);
  9433. string goal4 = lua_interface->GetStringValue(state, 14);
  9434. string task4 = lua_interface->GetStringValue(state, 15);
  9435. if (!player) {
  9436. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9437. return 0;
  9438. }
  9439. if (!player->IsPlayer()) {
  9440. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9441. return 0;
  9442. }
  9443. else
  9444. client = ((Player*)player)->GetClient();
  9445. if (!client) {
  9446. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9447. return 0;
  9448. }
  9449. if (text.length() == 0) {
  9450. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9451. return 0;
  9452. }
  9453. if (duration >= 0 && duration < 2)
  9454. duration = 2;
  9455. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9456. if (packet) {
  9457. packet->setDataByName("open_seconds_max", duration);
  9458. packet->setDataByName("text", text.c_str());
  9459. packet->setDataByName("voice", voice.c_str());
  9460. int8 num_goals = 1;
  9461. if (task2.length() > 0)
  9462. num_goals++;
  9463. if (task3.length() > 0)
  9464. num_goals++;
  9465. if (task4.length() > 0)
  9466. num_goals++;
  9467. packet->setArrayLengthByName("num_goals", num_goals);
  9468. for (int8 i = 0; i < num_goals; i++) {
  9469. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9470. }
  9471. if (goal1.length() > 0)
  9472. packet->setArrayDataByName("goal_text", goal1.c_str());
  9473. if (goal2.length() > 0)
  9474. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9475. if (goal3.length() > 0)
  9476. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9477. if (goal4.length() > 0)
  9478. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9479. packet->setSubArrayDataByName("task_text", task1.c_str());
  9480. if (task2.length() > 0)
  9481. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9482. if (task3.length() > 0)
  9483. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9484. if (task4.length() > 0)
  9485. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9486. packet->setDataByName("complete_sound", "click");
  9487. packet->setDataByName("signal", signal.c_str());
  9488. packet->setDataByName("voice_key1", voice_key1);
  9489. packet->setDataByName("voice_key2", voice_key2);
  9490. client->QueuePacket(packet->serialize());
  9491. safe_delete(packet);
  9492. }
  9493. return 0;
  9494. }
  9495. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9496. if (!lua_interface)
  9497. return 0;
  9498. Client* client = 0;
  9499. Spawn* player = lua_interface->GetSpawn(state);
  9500. string window = lua_interface->GetStringValue(state, 2);
  9501. int8 show = lua_interface->GetInt8Value(state, 3);
  9502. if (!player) {
  9503. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9504. return 0;
  9505. }
  9506. if (!player->IsPlayer()) {
  9507. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9508. return 0;
  9509. }
  9510. else
  9511. client = ((Player*)player)->GetClient();
  9512. if (!client) {
  9513. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9514. return 0;
  9515. }
  9516. if (window.length() == 0) {
  9517. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9518. return 0;
  9519. }
  9520. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9521. if (packet) {
  9522. packet->setDataByName("window", window.c_str());
  9523. packet->setDataByName("show", show);
  9524. client->QueuePacket(packet->serialize());
  9525. safe_delete(packet);
  9526. }
  9527. return 0;
  9528. }
  9529. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9530. //See GameEvents.txt for options that can be used for this function
  9531. if (!lua_interface)
  9532. return 0;
  9533. Client* client = 0;
  9534. Spawn* player = lua_interface->GetSpawn(state);
  9535. string event_name = lua_interface->GetStringValue(state, 2);
  9536. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9537. if (!player || !player->IsPlayer()) {
  9538. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9539. return 0;
  9540. }
  9541. if (player->GetZone())
  9542. client = player->GetZone()->GetClientBySpawn(player);
  9543. if (!client) {
  9544. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9545. return 0;
  9546. }
  9547. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9548. if (packet) {
  9549. packet->setDataByName("event_name", event_name.c_str());
  9550. packet->setDataByName("enabled", enabled);
  9551. client->QueuePacket(packet->serialize());
  9552. safe_delete(packet);
  9553. }
  9554. return 0;
  9555. }
  9556. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9557. if (!lua_interface)
  9558. return 0;
  9559. Spawn* player = lua_interface->GetSpawn(state);
  9560. if (player && player->IsPlayer()) {
  9561. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9562. return 1;
  9563. }
  9564. return 0;
  9565. }
  9566. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9567. if (!lua_interface)
  9568. return 0;
  9569. Spawn* player = lua_interface->GetSpawn(state);
  9570. int8 step = lua_interface->GetInt8Value(state, 2);
  9571. if (player && player->IsPlayer() && step > 0) {
  9572. ((Player*)player)->SetTutorialStep(step);
  9573. }
  9574. return 0;
  9575. }
  9576. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9577. if (!lua_interface)
  9578. return 0;
  9579. Client* client = 0;
  9580. Spawn* player = lua_interface->GetSpawn(state);
  9581. string window = lua_interface->GetStringValue(state, 2);
  9582. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9583. if (!player) {
  9584. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9585. return 0;
  9586. }
  9587. if (!player->IsPlayer()) {
  9588. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9589. return 0;
  9590. }
  9591. else
  9592. client = ((Player*)player)->GetClient();
  9593. if (!client) {
  9594. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9595. return 0;
  9596. }
  9597. if (window.length() == 0) {
  9598. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9599. return 0;
  9600. }
  9601. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9602. if (packet) {
  9603. packet->setDataByName("window", window.c_str());
  9604. packet->setDataByName("flash_seconds", flash_seconds);
  9605. client->QueuePacket(packet->serialize());
  9606. safe_delete(packet);
  9607. }
  9608. return 0;
  9609. }
  9610. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9611. if (!lua_interface)
  9612. return 0;
  9613. Spawn* spawn = lua_interface->GetSpawn(state);
  9614. Spawn* target = lua_interface->GetSpawn(state, 2);
  9615. if (spawn && target)
  9616. return spawn->CheckLoS(target);
  9617. return 0;
  9618. }
  9619. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9620. if (!lua_interface)
  9621. return 0;
  9622. Spawn* spawn = lua_interface->GetSpawn(state);
  9623. float x = lua_interface->GetFloatValue(state, 2);
  9624. float y = lua_interface->GetFloatValue(state, 3);
  9625. float z = lua_interface->GetFloatValue(state, 4);
  9626. if (spawn)
  9627. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9628. return 0;
  9629. }
  9630. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9631. if (!lua_interface)
  9632. return 0;
  9633. ZoneServer* zone = lua_interface->GetZone(state);
  9634. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9635. if (zone)
  9636. zone->SetExpansionFlag(xpackFlag);
  9637. return 0;
  9638. }
  9639. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9640. if (!lua_interface)
  9641. return 0;
  9642. ZoneServer* zone = lua_interface->GetZone(state);
  9643. if (zone) {
  9644. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9645. return 1;
  9646. }
  9647. return 0;
  9648. }
  9649. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9650. if (!lua_interface)
  9651. return 0;
  9652. ZoneServer* zone = lua_interface->GetZone(state);
  9653. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9654. if (zone)
  9655. zone->SetHolidayFlag(holidayFlag);
  9656. return 0;
  9657. }
  9658. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9659. if (!lua_interface)
  9660. return 0;
  9661. ZoneServer* zone = lua_interface->GetZone(state);
  9662. if (zone) {
  9663. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9664. return 1;
  9665. }
  9666. return 0;
  9667. }
  9668. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9669. if (!lua_interface)
  9670. return 0;
  9671. Spawn* spawn = lua_interface->GetSpawn(state);
  9672. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9673. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9674. float distance = lua_interface->GetFloatValue(state, 4);
  9675. string in_range_function = lua_interface->GetStringValue(state, 5);
  9676. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9677. if (spawn && distance > 0 && in_range_function.length() > 0)
  9678. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9679. return 0;
  9680. }
  9681. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9682. if (!lua_interface)
  9683. return 0;
  9684. Spawn* spawn = lua_interface->GetSpawn(state);
  9685. Spawn* target = lua_interface->GetSpawn(state, 2);
  9686. if (spawn && target)
  9687. {
  9688. if (spawn->IsPlayer() && target->IsEntity())
  9689. {
  9690. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9691. return 1;
  9692. }
  9693. else if (spawn->IsEntity() && target->IsEntity())
  9694. {
  9695. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9696. return 1;
  9697. }
  9698. }
  9699. return 0;
  9700. }
  9701. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9702. if (!lua_interface)
  9703. return 0;
  9704. Spawn* spawn = lua_interface->GetSpawn(state);
  9705. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9706. if (spawn && spawn->IsEntity())
  9707. {
  9708. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9709. if (spawn->IsPlayer())
  9710. {
  9711. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9712. if (client)
  9713. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9714. }
  9715. }
  9716. return 0;
  9717. }
  9718. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9719. if (!lua_interface)
  9720. return 0;
  9721. Spawn* spawn = lua_interface->GetSpawn(state);
  9722. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9723. if (spawn && spawn->IsEntity())
  9724. {
  9725. ((Entity*)spawn)->SetSeeHideSpell(val);
  9726. if (spawn->IsPlayer())
  9727. {
  9728. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9729. if (client)
  9730. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9731. }
  9732. }
  9733. return 0;
  9734. }
  9735. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9736. {
  9737. if (!lua_interface)
  9738. return 0;
  9739. Spawn* player = lua_interface->GetSpawn(state);
  9740. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9741. string command = lua_interface->GetStringValue(state, 3);
  9742. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9743. lua_interface->ResetFunctionStack(state);
  9744. if (spawn && player && player->IsPlayer())
  9745. {
  9746. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9747. bool res = false;
  9748. if (cmd)
  9749. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9750. lua_interface->SetBooleanValue(state, res);
  9751. return 1;
  9752. }
  9753. return 0;
  9754. }
  9755. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9756. {
  9757. if (!lua_interface)
  9758. return 0;
  9759. Spawn* spawn = lua_interface->GetSpawn(state);
  9760. int32 charID = lua_interface->GetInt32Value(state, 2);
  9761. string command = lua_interface->GetStringValue(state, 3);
  9762. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9763. lua_interface->ResetFunctionStack(state);
  9764. if (spawn && charID)
  9765. {
  9766. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9767. bool res = false;
  9768. if (cmd)
  9769. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9770. lua_interface->SetBooleanValue(state, res);
  9771. return 1;
  9772. }
  9773. return 0;
  9774. }
  9775. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9776. {
  9777. if (!lua_interface)
  9778. return 0;
  9779. Spawn* spawn = lua_interface->GetSpawn(state);
  9780. string command = lua_interface->GetStringValue(state, 2);
  9781. lua_interface->ResetFunctionStack(state);
  9782. if (spawn && command.length() > 0)
  9783. spawn->RemovePrimaryEntityCommand(command.c_str());
  9784. return 0;
  9785. }
  9786. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9787. if (!lua_interface)
  9788. return 0;
  9789. Spawn* spawn = lua_interface->GetSpawn(state);
  9790. float distance = lua_interface->GetFloatValue(state, 2);
  9791. string command = lua_interface->GetStringValue(state, 3);
  9792. Spawn* player = lua_interface->GetSpawn(state, 4);
  9793. lua_interface->ResetFunctionStack(state);
  9794. if (spawn) {
  9795. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9796. }
  9797. return 0;
  9798. }
  9799. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9800. if (!lua_interface)
  9801. return 0;
  9802. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9803. Spawn* spawn = lua_interface->GetSpawn(state);
  9804. Spawn* player = lua_interface->GetSpawn(state, 2);
  9805. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9806. lua_interface->ResetFunctionStack(state);
  9807. if (spawn && player && transport_id && player->IsPlayer()) {
  9808. Client* client = 0;
  9809. if (player && player->IsPlayer())
  9810. client = player->GetZone()->GetClientBySpawn(player);
  9811. if (!client)
  9812. return 0;
  9813. vector<TransportDestination*> destinations;
  9814. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9815. if (destinations.size())
  9816. {
  9817. client->SetTemporaryTransportID(transport_id);
  9818. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9819. }
  9820. else
  9821. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9822. }
  9823. return 0;
  9824. }
  9825. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9826. if (!lua_interface)
  9827. return 0;
  9828. Spawn* player = lua_interface->GetSpawn(state);
  9829. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9830. lua_interface->ResetFunctionStack(state);
  9831. if (player && player->IsPlayer()) {
  9832. Client* client = 0;
  9833. if (player && player->IsPlayer())
  9834. client = player->GetZone()->GetClientBySpawn(player);
  9835. if (!client)
  9836. return 0;
  9837. client->SetTemporaryTransportID(transport_id);
  9838. }
  9839. return 0;
  9840. }
  9841. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9842. if (!lua_interface)
  9843. return 0;
  9844. Spawn* player = lua_interface->GetSpawn(state);
  9845. lua_interface->ResetFunctionStack(state);
  9846. if (player && player->IsPlayer()) {
  9847. Client* client = 0;
  9848. if (player && player->IsPlayer())
  9849. client = player->GetZone()->GetClientBySpawn(player);
  9850. if (!client)
  9851. return 0;
  9852. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9853. return 1;
  9854. }
  9855. return 0;
  9856. }
  9857. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9858. if (!lua_interface)
  9859. return 0;
  9860. Spawn* spawn = lua_interface->GetSpawn(state);
  9861. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9862. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9863. if (!spawn) {
  9864. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9865. return 0;
  9866. }
  9867. if (!spawn->IsEntity()) {
  9868. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9869. return 0;
  9870. }
  9871. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9872. {
  9873. lua_interface->LogError("%s: LUA SetAlignment command error: alignment value beyond supported min: %i and max: %i", lua_interface->GetScriptName(state), SCHAR_MIN, SCHAR_MAX);
  9874. return 0;
  9875. }
  9876. lua_interface->ResetFunctionStack(state);
  9877. if (spell && spell->targets.size() > 0) {
  9878. ZoneServer* zone = spell->caster->GetZone();
  9879. for (int8 i = 0; i < spell->targets.size(); i++) {
  9880. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9881. if (target && target->IsEntity()) {
  9882. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9883. if (target->IsPlayer())
  9884. ((Player*)target)->SetCharSheetChanged(true);
  9885. }
  9886. }
  9887. }
  9888. else {
  9889. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9890. if (spawn->IsPlayer())
  9891. ((Player*)spawn)->SetCharSheetChanged(true);
  9892. }
  9893. return 0;
  9894. }
  9895. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9896. if (!lua_interface)
  9897. return 0;
  9898. Spawn* spawn = lua_interface->GetSpawn(state);
  9899. lua_interface->ResetFunctionStack(state);
  9900. if (!spawn) {
  9901. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9902. return 0;
  9903. }
  9904. if (!spawn->IsEntity()) {
  9905. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9906. return 0;
  9907. }
  9908. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9909. return 1;
  9910. }
  9911. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9912. if (!lua_interface)
  9913. return 0;
  9914. int32 spell_id = lua_interface->GetInt32Value(state);
  9915. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9916. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9917. if (spell_id > 0) {
  9918. if (spell_tier == 0)
  9919. spell_tier = 1;
  9920. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9921. LuaSpell* lua_spell = 0;
  9922. if(custom_lua_script.size() > 0)
  9923. {
  9924. // attempt to load the custom script since it isn't already loaded
  9925. // we will re-obtain the lua_spell further below
  9926. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9927. {
  9928. LogWrite(LUA__WARNING, 0, "LUA", "GetSpell(%u, %u, '%s'), custom lua script not loaded, attempting to load.", spell_id, spell_tier, custom_lua_script.c_str());
  9929. lua_interface->LoadLuaSpell(custom_lua_script);
  9930. }
  9931. }
  9932. else
  9933. custom_lua_script = spell->GetSpellData()->lua_script;
  9934. if (!lua_spell && lua_interface)
  9935. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9936. if (!lua_spell)
  9937. {
  9938. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9939. return 0;
  9940. }
  9941. lua_spell->spell = new Spell(spell);
  9942. lua_interface->AddCustomSpell(lua_spell);
  9943. lua_interface->SetSpellValue(state, lua_spell);
  9944. return 1;
  9945. }
  9946. return 0;
  9947. }
  9948. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9949. if (!lua_interface)
  9950. return 0;
  9951. LuaSpell* spell = lua_interface->GetSpell(state);
  9952. string field = lua_interface->GetStringValue(state, 2);
  9953. if (!spell) {
  9954. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9955. return 0;
  9956. }
  9957. if (!spell->spell || !spell->spell->GetSpellData()) {
  9958. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9959. return 0;
  9960. }
  9961. boost::to_lower(field);
  9962. return spell->spell->GetSpellData(state, field);
  9963. }
  9964. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9965. if (!lua_interface)
  9966. return 0;
  9967. LuaSpell* spell = lua_interface->GetSpell(state);
  9968. string field = lua_interface->GetStringValue(state, 2);
  9969. int8 fieldArg = 3; // field value after the initial set
  9970. if (!spell) {
  9971. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9972. return 0;
  9973. }
  9974. if (!spell->spell || !spell->spell->GetSpellData()) {
  9975. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9976. return 0;
  9977. }
  9978. boost::to_lower(field);
  9979. bool valSet = false;
  9980. spell->spell->SetSpellData(state, field, fieldArg);
  9981. return valSet;
  9982. }
  9983. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9984. if (!lua_interface)
  9985. return 0;
  9986. LuaSpell* spell = lua_interface->GetSpell(state);
  9987. int8 idx = lua_interface->GetInt32Value(state, 2);
  9988. if (!spell) {
  9989. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9990. return 0;
  9991. }
  9992. if (!spell->spell || !spell->spell->GetSpellData()) {
  9993. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9994. return 0;
  9995. }
  9996. if (spell->spell->lua_data.size() <= idx)
  9997. {
  9998. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9999. return 0;
  10000. }
  10001. bool setVal = true;
  10002. LUAData* data = spell->spell->lua_data[idx];
  10003. switch (data->type)
  10004. {
  10005. case 0:
  10006. {
  10007. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10008. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10009. data->int_value = value;
  10010. data->int_value2 = value2;
  10011. break;
  10012. }
  10013. case 1:
  10014. {
  10015. float value = lua_interface->GetFloatValue(state, 3);
  10016. float value2 = lua_interface->GetFloatValue(state, 4);
  10017. data->float_value = value;
  10018. data->float_value2 = value2;
  10019. break;
  10020. }
  10021. case 2:
  10022. {
  10023. bool value = lua_interface->GetBooleanValue(state, 3);
  10024. data->bool_value = value;
  10025. break;
  10026. }
  10027. case 3:
  10028. {
  10029. string value = lua_interface->GetStringValue(state, 3);
  10030. string value2 = lua_interface->GetStringValue(state, 4);
  10031. data->string_value = value;
  10032. data->string_value2 = value2;
  10033. break;
  10034. }
  10035. default:
  10036. setVal = false;
  10037. }
  10038. return setVal;
  10039. }
  10040. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10041. if (!lua_interface)
  10042. return 0;
  10043. LuaSpell* spell = lua_interface->GetSpell(state);
  10044. int8 idx = lua_interface->GetInt32Value(state, 2);
  10045. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10046. if (!spell) {
  10047. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10048. return 0;
  10049. }
  10050. if (!spell->spell || !spell->spell->GetSpellData()) {
  10051. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10052. return 0;
  10053. }
  10054. if (spell->spell->lua_data.size() <= idx)
  10055. {
  10056. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10057. return 0;
  10058. }
  10059. bool setVal = true;
  10060. LUAData* data = spell->spell->lua_data[idx];
  10061. switch (data->type)
  10062. {
  10063. case 0:
  10064. {
  10065. if(!secondfield)
  10066. lua_interface->SetSInt32Value(state, data->int_value);
  10067. else
  10068. lua_interface->SetSInt32Value(state, data->int_value2);
  10069. break;
  10070. }
  10071. case 1:
  10072. {
  10073. if (!secondfield)
  10074. lua_interface->SetFloatValue(state, data->float_value);
  10075. else
  10076. lua_interface->SetFloatValue(state, data->float_value2);
  10077. break;
  10078. }
  10079. case 2:
  10080. {
  10081. lua_interface->SetBooleanValue(state, data->bool_value);
  10082. break;
  10083. }
  10084. case 3:
  10085. {
  10086. if (!secondfield)
  10087. lua_interface->SetStringValue(state, data->string_value.c_str());
  10088. else
  10089. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10090. break;
  10091. }
  10092. default:
  10093. setVal = false;
  10094. }
  10095. return setVal;
  10096. }
  10097. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10098. if (!lua_interface)
  10099. return 0;
  10100. LuaSpell* spell = lua_interface->GetSpell(state);
  10101. int8 idx = lua_interface->GetInt32Value(state, 2);
  10102. string field = lua_interface->GetStringValue(state, 3);
  10103. boost::to_lower(field);
  10104. if (!spell) {
  10105. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10106. return 0;
  10107. }
  10108. if (!spell->spell || !spell->spell->GetSpellData()) {
  10109. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10110. return 0;
  10111. }
  10112. if (spell->spell->effects.size() <= idx)
  10113. {
  10114. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10115. return 0;
  10116. }
  10117. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10118. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10119. if (field == "description")
  10120. effect->description = string(lua_interface->GetStringValue(state, 4));
  10121. else if (field == "bullet")
  10122. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10123. else if (field == "percentage")
  10124. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10125. else // no match
  10126. return 0;
  10127. return 1;
  10128. }
  10129. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10130. if (!lua_interface)
  10131. return 0;
  10132. LuaSpell* spell = lua_interface->GetSpell(state);
  10133. int8 idx = lua_interface->GetInt32Value(state, 2);
  10134. string field = lua_interface->GetStringValue(state, 3);
  10135. boost::to_lower(field);
  10136. if (!spell) {
  10137. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10138. return 0;
  10139. }
  10140. if (!spell->spell || !spell->spell->GetSpellData()) {
  10141. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10142. return 0;
  10143. }
  10144. if (spell->spell->effects.size() <= idx)
  10145. {
  10146. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10147. return 0;
  10148. }
  10149. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10150. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10151. if (field == "description")
  10152. lua_interface->SetStringValue(state, effect->description.c_str());
  10153. else if (field == "bullet")
  10154. lua_interface->SetInt32Value(state, effect->subbullet);
  10155. else if (field == "percentage")
  10156. lua_interface->SetInt32Value(state, effect->percentage);
  10157. else // no match
  10158. return 0;
  10159. return 1;
  10160. }
  10161. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10162. if (!lua_interface)
  10163. return 0;
  10164. LuaSpell* spell = lua_interface->GetSpell(state);
  10165. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10166. Spawn* target = lua_interface->GetSpawn(state, 3);
  10167. if (!target) {
  10168. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10169. return 0;
  10170. }
  10171. if (!target->IsEntity()) {
  10172. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10173. return 0;
  10174. }
  10175. if (!spell) {
  10176. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10177. return 0;
  10178. }
  10179. if (caster && !caster->IsEntity()) {
  10180. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10181. return 0;
  10182. }
  10183. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10184. return 0;
  10185. }
  10186. int EQ2Emu_lua_InWater(lua_State* state) {
  10187. if (!lua_interface)
  10188. return 0;
  10189. Spawn* spawn = lua_interface->GetSpawn(state);
  10190. lua_interface->ResetFunctionStack(state);
  10191. if (spawn) {
  10192. lua_interface->SetBooleanValue(state, spawn->InWater());
  10193. return 1;
  10194. }
  10195. return 0;
  10196. }
  10197. int EQ2Emu_lua_InLava(lua_State* state) {
  10198. if (!lua_interface)
  10199. return 0;
  10200. Spawn* spawn = lua_interface->GetSpawn(state);
  10201. lua_interface->ResetFunctionStack(state);
  10202. if (spawn) {
  10203. lua_interface->SetBooleanValue(state, spawn->InLava());
  10204. return 1;
  10205. }
  10206. return 0;
  10207. }
  10208. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10209. if (!lua_interface)
  10210. return 0;
  10211. Spawn* attacker = lua_interface->GetSpawn(state);
  10212. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10213. int8 type = lua_interface->GetInt8Value(state, 3);
  10214. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10215. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10216. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10217. string spell_name = lua_interface->GetStringValue(state, 7);
  10218. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10219. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10220. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10221. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10222. lua_interface->ResetFunctionStack(state);
  10223. if (!attacker) {
  10224. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10225. return 0;
  10226. }
  10227. if (!attacker->IsEntity()) {
  10228. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10229. return 0;
  10230. }
  10231. if (!victim) {
  10232. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10233. return 0;
  10234. }
  10235. if (!victim->IsEntity()) {
  10236. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10237. return 0;
  10238. }
  10239. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10240. return 0;
  10241. }
  10242. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10243. if (!lua_interface)
  10244. return 0;
  10245. Spawn* spawn = lua_interface->GetSpawn(state);
  10246. lua_interface->ResetFunctionStack(state);
  10247. if (spawn) {
  10248. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10249. return 1;
  10250. }
  10251. return 0;
  10252. }
  10253. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10254. if (!lua_interface)
  10255. return 0;
  10256. Spawn* spawn = lua_interface->GetSpawn(state);
  10257. bool invul = lua_interface->GetBooleanValue(state, 2);
  10258. lua_interface->ResetFunctionStack(state);
  10259. if (spawn) {
  10260. spawn->SetInvulnerable(invul);
  10261. }
  10262. return 0;
  10263. }
  10264. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10265. if (!lua_interface)
  10266. return 0;
  10267. string category = lua_interface->GetStringValue(state);
  10268. string name = lua_interface->GetStringValue(state, 2);
  10269. lua_interface->ResetFunctionStack(state);
  10270. Rule *ret = 0;
  10271. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10272. lua_interface->SetBooleanValue(state, ret->GetBool());
  10273. return 1;
  10274. }
  10275. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10276. return 0;
  10277. }
  10278. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10279. if (!lua_interface)
  10280. return 0;
  10281. string category = lua_interface->GetStringValue(state);
  10282. string name = lua_interface->GetStringValue(state, 2);
  10283. lua_interface->ResetFunctionStack(state);
  10284. Rule *ret = 0;
  10285. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10286. lua_interface->SetInt32Value(state, ret->GetInt32());
  10287. return 1;
  10288. }
  10289. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10290. return 0;
  10291. }
  10292. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10293. if (!lua_interface)
  10294. return 0;
  10295. string category = lua_interface->GetStringValue(state);
  10296. string name = lua_interface->GetStringValue(state, 2);
  10297. lua_interface->ResetFunctionStack(state);
  10298. Rule *ret = 0;
  10299. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10300. lua_interface->SetFloatValue(state, ret->GetFloat());
  10301. return 1;
  10302. }
  10303. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10304. return 0;
  10305. }
  10306. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10307. if (!lua_interface)
  10308. return 0;
  10309. Spawn* spawn = lua_interface->GetSpawn(state);
  10310. string type = lua_interface->GetStringValue(state, 2);
  10311. lua_interface->ResetFunctionStack(state);
  10312. if (spawn) {
  10313. int res = 1;
  10314. boost::to_lower(type);
  10315. if(type == "assigned_aa")
  10316. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10317. else if ( type == "unassigned_aa")
  10318. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10319. else if ( type == "assigned_tradeskill_aa")
  10320. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10321. else if ( type == "unassigned_tradeskill_aa")
  10322. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10323. else if ( type == "assigned_prestige_aa")
  10324. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10325. else if ( type == "unassigned_prestige_aa")
  10326. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10327. else if ( type == "assigned_tradeskill_prestige_aa")
  10328. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10329. else if ( type == "unassigned_tradeskill_prestige_aa")
  10330. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10331. else
  10332. res = 0;
  10333. return res;
  10334. }
  10335. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10336. return 0;
  10337. }
  10338. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10339. if (!lua_interface)
  10340. return 0;
  10341. Spawn* spawn = lua_interface->GetSpawn(state);
  10342. string type = lua_interface->GetStringValue(state, 2);
  10343. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10344. lua_interface->ResetFunctionStack(state);
  10345. if (spawn) {
  10346. boost::to_lower(type);
  10347. if(type == "assigned_aa")
  10348. spawn->SetAssignedAA((sint16)value);
  10349. else if ( type == "unassigned_aa")
  10350. spawn->SetUnassignedAA((sint16)value);
  10351. else if ( type == "assigned_tradeskill_aa")
  10352. spawn->SetTradeskillAA((sint16)value);
  10353. else if ( type == "unassigned_tradeskill_aa")
  10354. spawn->SetUnassignedTradeskillAA((sint16)value);
  10355. else if ( type == "assigned_prestige_aa")
  10356. spawn->SetPrestigeAA((sint16)value);
  10357. else if ( type == "unassigned_prestige_aa")
  10358. spawn->SetUnassignedPrestigeAA((sint16)value);
  10359. else if ( type == "assigned_tradeskill_prestige_aa")
  10360. spawn->SetTradeskillPrestigeAA((sint16)value);
  10361. else if ( type == "unassigned_tradeskill_prestige_aa")
  10362. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10363. if(spawn->IsPlayer())
  10364. ((Player*)spawn)->SetCharSheetChanged(true);
  10365. }
  10366. return 0;
  10367. }
  10368. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10369. if (!lua_interface)
  10370. return 0;
  10371. string titleName = lua_interface->GetStringValue(state);
  10372. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10373. lua_interface->ResetFunctionStack(state);
  10374. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10375. lua_interface->SetSInt32Value(state, index);
  10376. return 1;
  10377. }
  10378. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10379. if (!lua_interface)
  10380. return 0;
  10381. Spawn* spawn = lua_interface->GetSpawn(state);
  10382. string titleName = lua_interface->GetStringValue(state, 2);
  10383. lua_interface->ResetFunctionStack(state);
  10384. if(!spawn->IsPlayer())
  10385. {
  10386. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10387. lua_interface->SetSInt32Value(state, -1);
  10388. return 1;
  10389. }
  10390. Player* player = (Player*)spawn;
  10391. // check if player already has the title, don't need to add twice
  10392. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10393. if ( playerHasTitle)
  10394. {
  10395. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10396. return 1;
  10397. }
  10398. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10399. if(!title)
  10400. {
  10401. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10402. lua_interface->SetSInt32Value(state, -1);
  10403. return 1;
  10404. }
  10405. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10406. if(returnIdx < 0)
  10407. {
  10408. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10409. }
  10410. lua_interface->SetSInt32Value(state, returnIdx);
  10411. player->GetClient()->SendTitleUpdate();
  10412. return 1;
  10413. }
  10414. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10415. if (!lua_interface)
  10416. return 0;
  10417. Spawn* spawn = lua_interface->GetSpawn(state);
  10418. string titleName = lua_interface->GetStringValue(state, 2);
  10419. lua_interface->ResetFunctionStack(state);
  10420. if(!spawn->IsPlayer())
  10421. {
  10422. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10423. return 0;
  10424. }
  10425. Player* player = (Player*)spawn;
  10426. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10427. if(!title)
  10428. {
  10429. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10430. return 0;
  10431. }
  10432. if(title->GetPrefix())
  10433. {
  10434. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title with name '%s' is not valid as a suffix, only prefix", lua_interface->GetScriptName(state), titleName.c_str());
  10435. return 0;
  10436. }
  10437. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10438. player->GetClient()->SendTitleUpdate();
  10439. return 1;
  10440. }
  10441. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10442. if (!lua_interface)
  10443. return 0;
  10444. Spawn* spawn = lua_interface->GetSpawn(state);
  10445. string titleName = lua_interface->GetStringValue(state, 2);
  10446. lua_interface->ResetFunctionStack(state);
  10447. if(!spawn->IsPlayer())
  10448. {
  10449. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10450. return 0;
  10451. }
  10452. Player* player = (Player*)spawn;
  10453. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10454. if(!title)
  10455. {
  10456. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10457. return 0;
  10458. }
  10459. if(!title->GetPrefix())
  10460. {
  10461. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title with name '%s' is not valid as a prefix, only suffix", lua_interface->GetScriptName(state), titleName.c_str());
  10462. return 0;
  10463. }
  10464. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10465. player->GetClient()->SendTitleUpdate();
  10466. return 1;
  10467. }
  10468. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10469. if (!lua_interface)
  10470. return 0;
  10471. Spawn* spawn = lua_interface->GetSpawn(state);
  10472. lua_interface->ResetFunctionStack(state);
  10473. if(!spawn->IsPlayer())
  10474. {
  10475. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10476. return 0;
  10477. }
  10478. Player* player = (Player*)spawn;
  10479. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10480. player->GetClient()->SendTitleUpdate();
  10481. return 1;
  10482. }
  10483. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10484. if (!lua_interface)
  10485. return 0;
  10486. Spawn* spawn = lua_interface->GetSpawn(state);
  10487. lua_interface->ResetFunctionStack(state);
  10488. if(!spawn->IsPlayer())
  10489. {
  10490. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10491. return 0;
  10492. }
  10493. Player* player = (Player*)spawn;
  10494. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10495. player->GetClient()->SendTitleUpdate();
  10496. return 1;
  10497. }
  10498. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10499. if (!lua_interface)
  10500. return 0;
  10501. Spawn* spawn = lua_interface->GetSpawn(state);
  10502. string field = lua_interface->GetStringValue(state, 2);
  10503. lua_interface->ResetFunctionStack(state);
  10504. if(!spawn || !spawn->IsEntity())
  10505. {
  10506. lua_interface->LogError("%s: LUA GetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10507. return 0;
  10508. }
  10509. Entity* ent = (Entity*)spawn;
  10510. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10511. return 1;
  10512. }
  10513. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10514. if (!lua_interface)
  10515. return 0;
  10516. Spawn* spawn = lua_interface->GetSpawn(state);
  10517. string field = lua_interface->GetStringValue(state, 2);
  10518. lua_interface->ResetFunctionStack(state);
  10519. if(!spawn || !spawn->IsEntity())
  10520. {
  10521. lua_interface->LogError("%s: LUA GetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10522. return 0;
  10523. }
  10524. Entity* ent = (Entity*)spawn;
  10525. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10526. return 1;
  10527. }
  10528. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10529. if (!lua_interface)
  10530. return 0;
  10531. Spawn* spawn = lua_interface->GetSpawn(state);
  10532. string field = lua_interface->GetStringValue(state, 2);
  10533. lua_interface->ResetFunctionStack(state);
  10534. if(!spawn || !spawn->IsEntity())
  10535. {
  10536. lua_interface->LogError("%s: LUA GetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10537. return 0;
  10538. }
  10539. Entity* ent = (Entity*)spawn;
  10540. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10541. return 1;
  10542. }
  10543. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10544. if (!lua_interface)
  10545. return 0;
  10546. Spawn* spawn = lua_interface->GetSpawn(state);
  10547. string field = lua_interface->GetStringValue(state, 2);
  10548. lua_interface->ResetFunctionStack(state);
  10549. if(!spawn || !spawn->IsEntity())
  10550. {
  10551. lua_interface->LogError("%s: LUA GetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10552. return 0;
  10553. }
  10554. Entity* ent = (Entity*)spawn;
  10555. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10556. return 1;
  10557. }
  10558. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10559. if (!lua_interface)
  10560. return 0;
  10561. Spawn* spawn = lua_interface->GetSpawn(state);
  10562. string field = lua_interface->GetStringValue(state, 2);
  10563. string value = lua_interface->GetStringValue(state, 3);
  10564. lua_interface->ResetFunctionStack(state);
  10565. if(!spawn || !spawn->IsEntity())
  10566. {
  10567. lua_interface->LogError("%s: LUA SetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10568. return 0;
  10569. }
  10570. Entity* ent = (Entity*)spawn;
  10571. bool set_ = ent->SetInfoStructString(field, value);
  10572. lua_interface->SetBooleanValue(state, set_);
  10573. return 1;
  10574. }
  10575. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10576. if (!lua_interface)
  10577. return 0;
  10578. Spawn* spawn = lua_interface->GetSpawn(state);
  10579. string field = lua_interface->GetStringValue(state, 2);
  10580. int64 value = lua_interface->GetInt64Value(state, 3);
  10581. lua_interface->ResetFunctionStack(state);
  10582. if(!spawn || !spawn->IsEntity())
  10583. {
  10584. lua_interface->LogError("%s: LUA SetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10585. return 0;
  10586. }
  10587. Entity* ent = (Entity*)spawn;
  10588. bool set_ = ent->SetInfoStructUInt(field, value);
  10589. lua_interface->SetBooleanValue(state, set_);
  10590. return 1;
  10591. }
  10592. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10593. if (!lua_interface)
  10594. return 0;
  10595. Spawn* spawn = lua_interface->GetSpawn(state);
  10596. string field = lua_interface->GetStringValue(state, 2);
  10597. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10598. lua_interface->ResetFunctionStack(state);
  10599. if(!spawn || !spawn->IsEntity())
  10600. {
  10601. lua_interface->LogError("%s: LUA SetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10602. return 0;
  10603. }
  10604. Entity* ent = (Entity*)spawn;
  10605. bool set_ = ent->SetInfoStructSInt(field, value);
  10606. lua_interface->SetBooleanValue(state, set_);
  10607. return 1;
  10608. }
  10609. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10610. if (!lua_interface)
  10611. return 0;
  10612. Spawn* spawn = lua_interface->GetSpawn(state);
  10613. string field = lua_interface->GetStringValue(state, 2);
  10614. float value = lua_interface->GetFloatValue(state, 3);
  10615. lua_interface->ResetFunctionStack(state);
  10616. if(!spawn || !spawn->IsEntity())
  10617. {
  10618. lua_interface->LogError("%s: LUA SetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  10619. return 0;
  10620. }
  10621. Entity* ent = (Entity*)spawn;
  10622. bool set_ = ent->SetInfoStructFloat(field, value);
  10623. lua_interface->SetBooleanValue(state, set_);
  10624. return 1;
  10625. }
  10626. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10627. if (!lua_interface)
  10628. return 0;
  10629. Spawn* spawn = lua_interface->GetSpawn(state);
  10630. bool value = lua_interface->GetBooleanValue(state, 2);
  10631. lua_interface->ResetFunctionStack(state);
  10632. if(!spawn || !spawn->IsPlayer())
  10633. {
  10634. lua_interface->LogError("%s: LUA SetCharSheetChanged command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  10635. return 0;
  10636. }
  10637. ((Player*)spawn)->SetCharSheetChanged(value);
  10638. return 0;
  10639. }
  10640. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10641. if (!lua_interface)
  10642. return 0;
  10643. Spawn* spawn = lua_interface->GetSpawn(state);
  10644. std::string fromName = lua_interface->GetStringValue(state, 2);
  10645. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10646. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10647. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10648. int32 copper = lua_interface->GetInt32Value(state, 6);
  10649. int32 silver = lua_interface->GetInt32Value(state, 7);
  10650. int32 gold = lua_interface->GetInt32Value(state, 8);
  10651. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10652. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10653. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10654. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10655. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10656. lua_interface->ResetFunctionStack(state);
  10657. if(!spawn || !spawn->IsPlayer())
  10658. {
  10659. lua_interface->LogError("%s: LUA AddPlayerMail command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  10660. lua_interface->SetBooleanValue(state, false);
  10661. return 1;
  10662. }
  10663. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10664. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10665. lua_interface->SetBooleanValue(state, true);
  10666. return 1;
  10667. }
  10668. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10669. if (!lua_interface)
  10670. return 0;
  10671. int32 char_id = lua_interface->GetInt32Value(state);
  10672. std::string fromName = lua_interface->GetStringValue(state, 2);
  10673. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10674. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10675. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10676. int32 copper = lua_interface->GetInt32Value(state, 6);
  10677. int32 silver = lua_interface->GetInt32Value(state, 7);
  10678. int32 gold = lua_interface->GetInt32Value(state, 8);
  10679. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10680. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10681. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10682. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10683. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10684. lua_interface->ResetFunctionStack(state);
  10685. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10686. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10687. lua_interface->SetBooleanValue(state, true);
  10688. return 1;
  10689. }
  10690. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10691. Spawn* widget;
  10692. if (lua_interface) {
  10693. widget = lua_interface->GetSpawn(state);
  10694. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10695. lua_interface->ResetFunctionStack(state);
  10696. if (widget && widget->IsWidget())
  10697. {
  10698. ((Widget*)widget)->OpenDoor();
  10699. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10700. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10701. }
  10702. else
  10703. lua_interface->LogError("%s: LUA OpenDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  10704. }
  10705. return 0;
  10706. }
  10707. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10708. Spawn* widget;
  10709. if (lua_interface) {
  10710. widget = lua_interface->GetSpawn(state);
  10711. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10712. lua_interface->ResetFunctionStack(state);
  10713. if (widget && widget->IsWidget())
  10714. {
  10715. ((Widget*)widget)->CloseDoor();
  10716. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10717. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10718. }
  10719. else
  10720. lua_interface->LogError("%s: LUA CloseDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  10721. }
  10722. return 0;
  10723. }
  10724. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10725. if (!lua_interface)
  10726. return 0;
  10727. Spawn* widget = lua_interface->GetSpawn(state);
  10728. lua_interface->ResetFunctionStack(state);
  10729. if (widget && widget->IsWidget())
  10730. {
  10731. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10732. return 1;
  10733. }
  10734. return 0;
  10735. }
  10736. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10737. if (!lua_interface)
  10738. return 0;
  10739. sint32 min = lua_interface->GetSInt32Value(state);
  10740. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10741. lua_interface->ResetFunctionStack(state);
  10742. sint32 result = MakeRandomInt(min, max);
  10743. lua_interface->SetSInt32Value(state, result);
  10744. return 1;
  10745. }
  10746. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10747. if (!lua_interface)
  10748. return 0;
  10749. float min = lua_interface->GetFloatValue(state);
  10750. float max = lua_interface->GetFloatValue(state, 2);
  10751. lua_interface->ResetFunctionStack(state);
  10752. float result = MakeRandomFloat(min, max);
  10753. lua_interface->SetFloatValue(state, result);
  10754. return 1;
  10755. }
  10756. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10757. if (!lua_interface)
  10758. return 0;
  10759. Spawn* spawn = lua_interface->GetSpawn(state);
  10760. int32 value = lua_interface->GetInt32Value(state, 2);
  10761. lua_interface->ResetFunctionStack(state);
  10762. if(!spawn)
  10763. {
  10764. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10765. lua_interface->SetBooleanValue(state, false);
  10766. return 1;
  10767. }
  10768. spawn->AddIconValue(value);
  10769. lua_interface->SetBooleanValue(state, true);
  10770. return 1;
  10771. }
  10772. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10773. if (!lua_interface)
  10774. return 0;
  10775. Spawn* spawn = lua_interface->GetSpawn(state);
  10776. int32 value = lua_interface->GetInt32Value(state, 2);
  10777. lua_interface->ResetFunctionStack(state);
  10778. if(!spawn)
  10779. {
  10780. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10781. lua_interface->SetBooleanValue(state, false);
  10782. return 1;
  10783. }
  10784. spawn->RemoveIconValue(value);
  10785. lua_interface->SetBooleanValue(state, true);
  10786. return 1;
  10787. }
  10788. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10789. Spawn* npc = lua_interface->GetSpawn(state);
  10790. lua_interface->ResetFunctionStack(state);
  10791. if (npc && npc->IsNPC()) {
  10792. NPC* shard = (NPC*)npc;
  10793. int32 shardid = shard->GetShardID();
  10794. lua_interface->SetInt32Value(state, shardid);
  10795. return 1;
  10796. }
  10797. lua_interface->SetInt32Value(state, 0);
  10798. return 1;
  10799. }
  10800. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10801. Spawn* npc = lua_interface->GetSpawn(state);
  10802. lua_interface->ResetFunctionStack(state);
  10803. if (npc && npc->IsNPC()) {
  10804. NPC* shard = (NPC*)npc;
  10805. int32 charid = shard->GetShardCharID();
  10806. lua_interface->SetInt32Value(state, charid);
  10807. return 1;
  10808. }
  10809. lua_interface->SetInt32Value(state, 0);
  10810. return 1;
  10811. }
  10812. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10813. Spawn* npc = lua_interface->GetSpawn(state);
  10814. lua_interface->ResetFunctionStack(state);
  10815. if (npc && npc->IsNPC()) {
  10816. NPC* shard = (NPC*)npc;
  10817. int64 timestamp = shard->GetShardCreatedTimestamp();
  10818. lua_interface->SetSInt64Value(state, timestamp);
  10819. return 1;
  10820. }
  10821. lua_interface->SetSInt64Value(state, 0);
  10822. return 1;
  10823. }
  10824. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10825. if (!lua_interface)
  10826. return 0;
  10827. int32 shardid = lua_interface->GetInt32Value(state);
  10828. lua_interface->ResetFunctionStack(state);
  10829. if(shardid < 1)
  10830. lua_interface->SetBooleanValue(state, false);
  10831. else
  10832. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10833. return 1;
  10834. }
  10835. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10836. if (!lua_interface)
  10837. return 0;
  10838. Spawn* spawn = lua_interface->GetSpawn(state);
  10839. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10840. if (spawn) {
  10841. spawn->PauseMovement(delay_in_ms);
  10842. }
  10843. lua_interface->ResetFunctionStack(state);
  10844. return 0;
  10845. }
  10846. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10847. if (!lua_interface)
  10848. return 0;
  10849. Spawn* spawn = lua_interface->GetSpawn(state);
  10850. if (spawn) {
  10851. spawn->StopMovement();
  10852. }
  10853. lua_interface->ResetFunctionStack(state);
  10854. return 0;
  10855. }
  10856. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10857. Player* player = (Player*)lua_interface->GetSpawn(state);
  10858. int8 level = lua_interface->GetInt8Value(state, 2);
  10859. lua_interface->ResetFunctionStack(state);
  10860. if (player && player->IsPlayer() && level > 0) {
  10861. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10862. return 1;
  10863. }
  10864. return 0;
  10865. }
  10866. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10867. Player* player = (Player*)lua_interface->GetSpawn(state);
  10868. int8 level = lua_interface->GetInt8Value(state, 2);
  10869. lua_interface->ResetFunctionStack(state);
  10870. if (player && player->IsPlayer() && level > 0) {
  10871. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10872. return 1;
  10873. }
  10874. return 0;
  10875. }
  10876. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10877. ZoneServer* zone = lua_interface->GetZone(state);
  10878. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10879. lua_interface->ResetFunctionStack(state);
  10880. if (zone) {
  10881. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10882. if (spawn) {
  10883. lua_interface->SetSpawnValue(state, spawn);
  10884. return 1;
  10885. }
  10886. }
  10887. return 0;
  10888. }
  10889. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10890. if (!lua_interface)
  10891. return 0;
  10892. Spawn* spawn = lua_interface->GetSpawn(state);
  10893. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10894. lua_interface->ResetFunctionStack(state);
  10895. bool res = false;
  10896. if(spawn && spawn->IsTransportSpawn())
  10897. {
  10898. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10899. spawn->SetRailID(rail_id);
  10900. res = true;
  10901. }
  10902. else if (!spawn) {
  10903. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10904. }
  10905. else if(!spawn->IsTransportSpawn()) {
  10906. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  10907. }
  10908. lua_interface->SetBooleanValue(state, res);
  10909. return 1;
  10910. }
  10911. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10912. if (!lua_interface)
  10913. return 0;
  10914. ZoneServer* zone = lua_interface->GetZone(state);
  10915. lua_interface->ResetFunctionStack(state);
  10916. if (zone) {
  10917. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10918. return 1;
  10919. }
  10920. return 0;
  10921. }
  10922. int EQ2Emu_lua_IsRunning(lua_State* state) {
  10923. if (!lua_interface)
  10924. return 0;
  10925. Spawn* spawn = lua_interface->GetSpawn(state);
  10926. lua_interface->ResetFunctionStack(state);
  10927. if (spawn) {
  10928. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  10929. return 1;
  10930. }
  10931. return 0;
  10932. }
  10933. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  10934. if (!lua_interface)
  10935. return 0;
  10936. Spawn* player = lua_interface->GetSpawn(state);
  10937. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  10938. bool displayClient = lua_interface->GetInt32Value(state, 3);
  10939. lua_interface->ResetFunctionStack(state);
  10940. if (!player || !player->IsPlayer() || !player->GetClient()) {
  10941. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  10942. }
  10943. else if(!zoneID) {
  10944. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  10945. }
  10946. else
  10947. {
  10948. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  10949. return 1;
  10950. }
  10951. return 0;
  10952. }
  10953. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  10954. if (!lua_interface)
  10955. return 0;
  10956. int16 newYear = lua_interface->GetInt16Value(state, 1);
  10957. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  10958. int16 newHour = lua_interface->GetInt16Value(state, 3);
  10959. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  10960. lua_interface->ResetFunctionStack(state);
  10961. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  10962. world.GetWorldTimeStruct()->year = newYear;
  10963. world.GetWorldTimeStruct()->month = newMonth;
  10964. world.GetWorldTimeStruct()->hour = newHour;
  10965. world.GetWorldTimeStruct()->minute = newMinute;
  10966. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  10967. return 0;
  10968. }
  10969. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  10970. if (!lua_interface)
  10971. return 0;
  10972. lua_interface->ResetFunctionStack(state);
  10973. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10974. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  10975. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10976. return 1;
  10977. }
  10978. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  10979. if (!lua_interface)
  10980. return 0;
  10981. lua_interface->ResetFunctionStack(state);
  10982. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10983. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  10984. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10985. return 1;
  10986. }
  10987. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  10988. if (!lua_interface)
  10989. return 0;
  10990. lua_interface->ResetFunctionStack(state);
  10991. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10992. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  10993. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10994. return 1;
  10995. }
  10996. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  10997. if (!lua_interface)
  10998. return 0;
  10999. lua_interface->ResetFunctionStack(state);
  11000. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11001. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11002. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11003. return 1;
  11004. }
  11005. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11006. if (!lua_interface)
  11007. return 0;
  11008. lua_interface->ResetFunctionStack(state);
  11009. world.SendTimeUpdate();
  11010. return 0;
  11011. }